1 package DBIx::Class::Schema::Loader::DBI::Sybase;
6 DBIx::Class::Schema::Loader::DBI
7 DBIx::Class::Schema::Loader::DBI::Sybase::Common
9 use Carp::Clan qw/^DBIx::Class/;
12 our $VERSION = '0.04999_06';
16 DBIx::Class::Schema::Loader::DBI::Sybase - DBIx::Class::Schema::Loader::DBI Sybase Implementation.
21 use base qw/DBIx::Class::Schema::Loader/;
23 __PACKAGE__->loader_options( debug => 1 );
29 See L<DBIx::Class::Schema::Loader::Base>.
36 $self->next::method(@_);
37 $self->{db_schema} ||= $self->_build_db_schema;
38 $self->_set_quote_char_and_name_sep;
44 my $dbh = $self->schema->storage->dbh;
45 my $DBMS_VERSION = @{$dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2];
46 if ($DBMS_VERSION =~ /^Microsoft /i) {
47 my $subclass = 'DBIx::Class::Schema::Loader::DBI::MSSQL';
48 if ($self->load_optional_class($subclass) && !$self->isa($subclass)) {
49 bless $self, $subclass;
56 my ($self, $table) = @_;
58 my $dbh = $self->schema->storage->dbh;
59 my $columns = $dbh->selectcol_arrayref(qq{SELECT name FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE name = '$table' AND type = 'U')});
65 my ($self, $table) = @_;
67 my $dbh = $self->schema->storage->dbh;
68 my $sth = $dbh->prepare(qq{sp_pkeys '$table'});
73 while (my $row = $sth->fetchrow_hashref) {
74 push @keydata, $row->{column_name};
81 my ($self, $table) = @_;
83 my ($local_cols, $remote_cols, $remote_table, @rels);
84 my $dbh = $self->schema->storage->dbh;
85 # hide "Object does not exist in this database." when trying to fetch fkeys
86 $dbh->{syb_err_handler} = sub { return 0 if $_[0] == 17461; };
87 my $sth = $dbh->prepare(qq{sp_fkeys \@FKTABLE_NAME = '$table'});
90 while (my $row = $sth->fetchrow_hashref) {
91 next unless $row->{FK_NAME};
92 my $fk = $row->{FK_NAME};
93 push @{$local_cols->{$fk}}, $row->{FKCOLUMN_NAME};
94 push @{$remote_cols->{$fk}}, $row->{PKCOLUMN_NAME};
95 $remote_table->{$fk} = $row->{PKTABLE_NAME};
98 foreach my $fk (keys %$remote_table) {
100 local_columns => \@{$local_cols->{$fk}},
101 remote_columns => \@{$remote_cols->{$fk}},
102 remote_table => $remote_table->{$fk},
109 sub _table_uniq_info {
110 my ($self, $table) = @_;
112 my $dbh = $self->schema->storage->dbh;
113 my $sth = $dbh->prepare(qq{sp_helpconstraint \@objname='$table', \@nomsg='nomsg'});
117 while (my $row = $sth->fetchrow_hashref) {
118 if (exists $row->{constraint_type}) {
119 my $type = $row->{constraint_type} || '';
120 if ($type =~ /^unique/i) {
121 my $name = $row->{constraint_name};
122 push @{$constraints->{$name}},
123 ( split /,/, $row->{constraint_keys} );
126 my $def = $row->{definition} || next;
127 next unless $def =~ /^unique/i;
128 my $name = $row->{name};
129 my ($keys) = $def =~ /\((.*)\)/;
131 my @keys = split /,/ => $keys;
132 push @{$constraints->{$name}}, @keys;
136 my @uniqs = map { [ $_ => $constraints->{$_} ] } keys %$constraints;
140 sub _extra_column_info {
141 my ($self, $info) = @_;
144 my ($table, $column) = @$info{qw/TABLE_NAME COLUMN_NAME/};
146 my $dbh = $self->schema->storage->dbh;
147 my $sth = $dbh->prepare(qq{SELECT name FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE name = '$table') AND (status & 0x80) = 0x80 AND name = '$column'});
150 if ($sth->fetchrow_array) {
151 $extra_info{is_auto_increment} = 1;
159 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
160 L<DBIx::Class::Schema::Loader::DBI>
164 Justin Hunter C<justin.d.hunter@gmail.com>