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.05002';
18 DBIx::Class::Schema::Loader::DBI::SQLAnywhere - DBIx::Class::Schema::Loader::DBI
19 SQL Anywhere Implementation.
23 See L<DBIx::Class::Schema::Loader::Base>.
27 # check for IDENTITY columns
28 sub _columns_info_for {
30 my $result = $self->next::method(@_);
32 while (my ($col, $info) = each %$result) {
33 my $def = $info->{default_value};
34 if (ref $def eq 'SCALAR' && $$def eq 'autoincrement') {
35 delete $info->{default_value};
36 $info->{is_auto_increment} = 1;
44 my ($self, $table) = @_;
45 my $dbh = $self->schema->storage->dbh;
46 local $dbh->{FetchHashKeyName} = 'NAME_lc';
47 my $sth = $dbh->prepare(qq{sp_pkeys ?});
48 $sth->execute($table);
52 while (my $row = $sth->fetchrow_hashref) {
53 push @keydata, lc $row->{column_name};
60 my ($self, $table) = @_;
62 my ($local_cols, $remote_cols, $remote_table, @rels);
63 my $dbh = $self->schema->storage->dbh;
64 my $sth = $dbh->prepare(<<'EOF');
65 select fki.index_name fk_name, fktc.column_name local_column, pkt.table_name remote_table, pktc.column_name remote_column
67 join sysidx pki on fk.primary_table_id = pki.table_id and fk.primary_index_id = pki.index_id
68 join sysidx fki on fk.foreign_table_id = fki.table_id and fk.foreign_index_id = fki.index_id
69 join systab pkt on fk.primary_table_id = pkt.table_id
70 join systab fkt on fk.foreign_table_id = fkt.table_id
71 join sysidxcol pkic on pki.table_id = pkic.table_id and pki.index_id = pkic.index_id
72 join sysidxcol fkic on fki.table_id = fkic.table_id and fki.index_id = fkic.index_id
73 join systabcol pktc on pkic.table_id = pktc.table_id and pkic.column_id = pktc.column_id
74 join systabcol fktc on fkic.table_id = fktc.table_id and fkic.column_id = fktc.column_id
75 where fkt.table_name = ?
77 $sth->execute($table);
79 while (my ($fk, $local_col, $remote_tab, $remote_col) = $sth->fetchrow_array) {
80 push @{$local_cols->{$fk}}, lc $local_col;
81 push @{$remote_cols->{$fk}}, lc $remote_col;
82 $remote_table->{$fk} = lc $remote_tab;
85 foreach my $fk (keys %$remote_table) {
87 local_columns => [ uniq @{ $local_cols->{$fk} } ],
88 remote_columns => [ uniq @{ $remote_cols->{$fk} } ],
89 remote_table => $remote_table->{$fk},
95 sub _table_uniq_info {
96 my ($self, $table) = @_;
98 my $dbh = $self->schema->storage->dbh;
99 my $sth = $dbh->prepare(<<'EOF');
100 select c.constraint_name, tc.column_name
102 join systab t on c.table_object_id = t.object_id
103 join sysidx i on c.ref_object_id = i.object_id
104 join sysidxcol ic on i.table_id = ic.table_id and i.index_id = ic.index_id
105 join systabcol tc on ic.table_id = tc.table_id and ic.column_id = tc.column_id
106 where c.constraint_type = 'U' and t.table_name = ?
108 $sth->execute($table);
111 while (my ($constraint_name, $column) = $sth->fetchrow_array) {
112 push @{$constraints->{$constraint_name}}, lc $column;
115 my @uniqs = map { [ $_ => $constraints->{$_} ] } keys %$constraints;
121 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
122 L<DBIx::Class::Schema::Loader::DBI>
126 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
130 This library is free software; you can redistribute it and/or modify it under
131 the same terms as Perl itself.