1 package DBIx::Class::Schema::Loader::DBI::SQLAnywhere;
5 use namespace::autoclean;
8 DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault
9 DBIx::Class::Schema::Loader::DBI
11 use Carp::Clan qw/^DBIx::Class/;
12 use List::MoreUtils 'uniq';
14 our $VERSION = '0.05003';
18 DBIx::Class::Schema::Loader::DBI::SQLAnywhere - DBIx::Class::Schema::Loader::DBI
19 SQL Anywhere Implementation.
23 See L<DBIx::Class::Schema::Loader::Base>.
30 $self->{db_schema} ||=
31 ($self->schema->storage->dbh->selectrow_array('select user'))[0];
37 my $dbh = $self->schema->storage->dbh;
38 my $sth = $dbh->prepare(<<'EOF');
39 select t.table_name from systab t
40 join sysuser u on u.user_id = t.creator
43 $sth->execute($self->db_schema);
45 my @tables = map @$_, @{ $sth->fetchall_arrayref };
47 return $self->_filter_tables(@tables);
50 # check for IDENTITY columns
51 sub _columns_info_for {
53 my $result = $self->next::method(@_);
55 while (my ($col, $info) = each %$result) {
56 my $def = $info->{default_value};
57 if (ref $def eq 'SCALAR' && $$def eq 'autoincrement') {
58 delete $info->{default_value};
59 $info->{is_auto_increment} = 1;
67 my ($self, $table) = @_;
68 my $dbh = $self->schema->storage->dbh;
69 local $dbh->{FetchHashKeyName} = 'NAME_lc';
70 my $sth = $dbh->prepare(qq{sp_pkeys ?});
71 $sth->execute($table);
75 while (my $row = $sth->fetchrow_hashref) {
76 push @keydata, lc $row->{column_name};
83 my ($self, $table) = @_;
85 my ($local_cols, $remote_cols, $remote_table, @rels);
86 my $dbh = $self->schema->storage->dbh;
87 my $sth = $dbh->prepare(<<'EOF');
88 select fki.index_name fk_name, fktc.column_name local_column, pkt.table_name remote_table, pktc.column_name remote_column
90 join sysidx pki on fk.primary_table_id = pki.table_id and fk.primary_index_id = pki.index_id
91 join sysidx fki on fk.foreign_table_id = fki.table_id and fk.foreign_index_id = fki.index_id
92 join systab pkt on fk.primary_table_id = pkt.table_id
93 join systab fkt on fk.foreign_table_id = fkt.table_id
94 join sysidxcol pkic on pki.table_id = pkic.table_id and pki.index_id = pkic.index_id
95 join sysidxcol fkic on fki.table_id = fkic.table_id and fki.index_id = fkic.index_id
96 join systabcol pktc on pkic.table_id = pktc.table_id and pkic.column_id = pktc.column_id
97 join systabcol fktc on fkic.table_id = fktc.table_id and fkic.column_id = fktc.column_id
98 where fkt.table_name = ?
100 $sth->execute($table);
102 while (my ($fk, $local_col, $remote_tab, $remote_col) = $sth->fetchrow_array) {
103 push @{$local_cols->{$fk}}, lc $local_col;
104 push @{$remote_cols->{$fk}}, lc $remote_col;
105 $remote_table->{$fk} = lc $remote_tab;
108 foreach my $fk (keys %$remote_table) {
110 local_columns => [ uniq @{ $local_cols->{$fk} } ],
111 remote_columns => [ uniq @{ $remote_cols->{$fk} } ],
112 remote_table => $remote_table->{$fk},
118 sub _table_uniq_info {
119 my ($self, $table) = @_;
121 my $dbh = $self->schema->storage->dbh;
122 my $sth = $dbh->prepare(<<'EOF');
123 select c.constraint_name, tc.column_name
125 join systab t on c.table_object_id = t.object_id
126 join sysidx i on c.ref_object_id = i.object_id
127 join sysidxcol ic on i.table_id = ic.table_id and i.index_id = ic.index_id
128 join systabcol tc on ic.table_id = tc.table_id and ic.column_id = tc.column_id
129 where c.constraint_type = 'U' and t.table_name = ?
131 $sth->execute($table);
134 while (my ($constraint_name, $column) = $sth->fetchrow_array) {
135 push @{$constraints->{$constraint_name}}, lc $column;
138 my @uniqs = map { [ $_ => $constraints->{$_} ] } keys %$constraints;
144 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
145 L<DBIx::Class::Schema::Loader::DBI>
149 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
153 This library is free software; you can redistribute it and/or modify it under
154 the same terms as Perl itself.