X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI%2FSQLAnywhere.pm;h=8cf364db70e541e8914091a6a1ab53789b2491ac;hb=bc5afe555b3a01ba28368c7f8aeb9c653074417b;hp=e4380a1245467de29ead9e0f9a2d8d33198093e5;hpb=2a8e93e98aace9a187a57a66a8d71fabc6a48a8c;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm index e4380a1..8cf364d 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm @@ -9,7 +9,7 @@ use base qw/ /; use Carp::Clan qw/^DBIx::Class/; -our $VERSION = '0.06000'; +our $VERSION = '0.07000'; =head1 NAME @@ -18,15 +18,21 @@ SQL Anywhere Implementation. =head1 DESCRIPTION -See L. +See L and L. =cut sub _setup { my $self = shift; + $self->next::method(@_); + $self->{db_schema} ||= ($self->schema->storage->dbh->selectrow_array('select user'))[0]; + + if (not defined $self->preserve_case) { + $self->preserve_case(0); + } } sub _tables_list { @@ -45,17 +51,64 @@ EOF return $self->_filter_tables(\@tables, $opts); } -# check for IDENTITY columns sub _columns_info_for { - my $self = shift; + my $self = shift; + my ($table) = @_; + my $result = $self->next::method(@_); - while (my ($col, $info) = each %$result) { + my $dbh = $self->schema->storage->dbh; + + while (my ($column, $info) = each %$result) { my $def = $info->{default_value}; if (ref $def eq 'SCALAR' && $$def eq 'autoincrement') { delete $info->{default_value}; $info->{is_auto_increment} = 1; } + + my ($user_type) = $dbh->selectrow_array(<<'EOF', {}, $table, lc $column); +SELECT ut.type_name +FROM systabcol tc +JOIN systab t ON tc.table_id = t.table_id +JOIN sysusertype ut on tc.user_type = ut.type_id +WHERE t.table_name = ? AND lower(tc.column_name) = ? +EOF + $info->{data_type} = $user_type if defined $user_type; + + if ($info->{data_type} eq 'double') { + $info->{data_type} = 'double precision'; + } + + if ($info->{data_type} =~ /^(?:char|varchar|binary|varbinary)\z/ && ref($info->{size}) eq 'ARRAY') { + $info->{size} = $info->{size}[0]; + } + elsif ($info->{data_type} !~ /^(?:char|varchar|binary|varbinary|numeric|decimal)\z/) { + delete $info->{size}; + } + + my $sth = $dbh->prepare(<<'EOF'); +SELECT tc.width, tc.scale +FROM systabcol tc +JOIN systab t ON t.table_id = tc.table_id +WHERE t.table_name = ? AND lower(tc.column_name) = ? +EOF + $sth->execute($table, lc $column); + my ($width, $scale) = $sth->fetchrow_array; + $sth->finish; + + if ($info->{data_type} =~ /^(?:numeric|decimal)\z/) { + # We do not check for the default precision/scale, because they can be changed as PUBLIC database options. + $info->{size} = [$width, $scale]; + } + elsif ($info->{data_type} =~ /^(?:n(?:varchar|char) | varbit)\z/x) { + $info->{size} = $width; + } + + delete $info->{default_value} if ref($info->{default_value}) eq 'SCALAR' && ${ $info->{default_value} } eq 'NULL'; + + if (eval { lc ${ $info->{default_value} } }||'' eq 'current timestamp') { + ${ $info->{default_value} } = 'CURRENT_TIMESTAMP'; + } } return $result; @@ -153,3 +206,4 @@ the same terms as Perl itself. =cut 1; +# vim:et sw=4 sts=4 tw=0: