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>.
33 sub _is_case_sensitive { 1 }
38 $self->next::method(@_);
39 $self->{db_schema} ||= $self->_build_db_schema;
40 $self->_set_quote_char_and_name_sep;
46 my $dbh = $self->schema->storage->dbh;
47 my $DBMS_VERSION = @{$dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2];
48 if ($DBMS_VERSION =~ /^Microsoft /i) {
49 my $subclass = 'DBIx::Class::Schema::Loader::DBI::MSSQL';
50 if ($self->load_optional_class($subclass) && !$self->isa($subclass)) {
51 bless $self, $subclass;
58 my ($self, $table) = @_;
60 my $dbh = $self->schema->storage->dbh;
61 my $columns = $dbh->selectcol_arrayref(qq{SELECT name FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE name = '$table' AND type = 'U')});
67 my ($self, $table) = @_;
69 my $dbh = $self->schema->storage->dbh;
70 my $sth = $dbh->prepare(qq{sp_pkeys '$table'});
75 while (my $row = $sth->fetchrow_hashref) {
76 push @keydata, $row->{column_name};
83 my ($self, $table) = @_;
85 my ($local_cols, $remote_cols, $remote_table, @rels);
86 my $dbh = $self->schema->storage->dbh;
88 local $dbh->{FetchHashKeyName} = 'NAME_lc';
90 # hide "Object does not exist in this database." when trying to fetch fkeys
91 $dbh->{syb_err_handler} = sub { return 0 if $_[0] == 17461; };
92 my $sth = $dbh->prepare(qq{sp_fkeys \@fktable_name = '$table'});
95 while (my $row = $sth->fetchrow_hashref) {
96 my $fk = $row->{fk_name} ||
97 'fk_'.$row->{fktable_qualifier}.'_'.$row->{fktable_owner}.'_'
98 .$row->{fktable_name}.'_'.$row->{fkcolumn_name};
100 push @{$local_cols->{$fk}}, $row->{fkcolumn_name};
101 push @{$remote_cols->{$fk}}, $row->{pkcolumn_name};
102 $remote_table->{$fk} = $row->{pktable_name};
105 foreach my $fk (keys %$remote_table) {
107 local_columns => \@{$local_cols->{$fk}},
108 remote_columns => \@{$remote_cols->{$fk}},
109 remote_table => $remote_table->{$fk},
116 sub _table_uniq_info {
117 my ($self, $table) = @_;
119 my $dbh = $self->schema->storage->dbh;
120 my $sth = $dbh->prepare(qq{sp_helpconstraint \@objname='$table', \@nomsg='nomsg'});
124 while (my $row = $sth->fetchrow_hashref) {
125 if (exists $row->{constraint_type}) {
126 my $type = $row->{constraint_type} || '';
127 if ($type =~ /^unique/i) {
128 my $name = $row->{constraint_name};
129 push @{$constraints->{$name}},
130 ( split /,/, $row->{constraint_keys} );
133 my $def = $row->{definition} || next;
134 next unless $def =~ /^unique/i;
135 my $name = $row->{name};
136 my ($keys) = $def =~ /\((.*)\)/;
138 my @keys = split /,/ => $keys;
139 push @{$constraints->{$name}}, @keys;
143 my @uniqs = map { [ $_ => $constraints->{$_} ] } keys %$constraints;
147 sub _extra_column_info {
148 my ($self, $info) = @_;
151 my ($table, $column) = @$info{qw/TABLE_NAME COLUMN_NAME/};
153 my $dbh = $self->schema->storage->dbh;
154 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'});
157 if ($sth->fetchrow_array) {
158 $extra_info{is_auto_increment} = 1;
166 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
167 L<DBIx::Class::Schema::Loader::DBI>
171 Justin Hunter C<justin.d.hunter@gmail.com>