From: Rafael Kitover Date: Mon, 10 May 2010 17:40:39 +0000 (-0400) Subject: SQLAnywhere: fixup reals, implement preserve_case X-Git-Tag: 0.07000~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dd87d4c4612dbc0120da1e1826cb3f09c15fbcdb;p=dbsrgits%2FDBIx-Class-Schema-Loader.git SQLAnywhere: fixup reals, implement preserve_case --- diff --git a/TODO b/TODO index 6db4250..abb7495 100644 --- a/TODO +++ b/TODO @@ -92,7 +92,6 @@ - table/column comments - introspect on_update/on_delete/is_deferrable - introspect view SQL - - preserve_case mode - domains - Firebird - table/column comments diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm index cc54ea7..fb73578 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm @@ -29,10 +29,6 @@ sub _setup { $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 { @@ -59,14 +55,14 @@ sub _columns_info_for { my $dbh = $self->schema->storage->dbh; - while (my ($column, $info) = each %$result) { + while (my ($col, $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); + my ($user_type) = $dbh->selectrow_array(<<'EOF', {}, $table, $col); SELECT ut.type_name FROM systabcol tc JOIN systab t ON tc.table_id = t.table_id @@ -90,9 +86,9 @@ 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) = ? +WHERE t.table_name = ? AND tc.column_name = ? EOF - $sth->execute($table, lc $column); + $sth->execute($table, $col); my ($width, $scale) = $sth->fetchrow_array; $sth->finish; @@ -103,6 +99,9 @@ EOF elsif ($info->{data_type} =~ /^(?:n(?:varchar|char) | varbit)\z/x) { $info->{size} = $width; } + elsif ($info->{data_type} eq 'float') { + $info->{data_type} = 'real'; + } delete $info->{default_value} if ref($info->{default_value}) eq 'SCALAR' && ${ $info->{default_value} } eq 'NULL'; @@ -124,7 +123,7 @@ sub _table_pk_info { my @keydata; while (my $row = $sth->fetchrow_hashref) { - push @keydata, lc $row->{column_name}; + push @keydata, $self->_lc($row->{column_name}); } return \@keydata; @@ -150,9 +149,9 @@ EOF $sth->execute($table); while (my ($fk, $local_col, $remote_tab, $remote_col) = $sth->fetchrow_array) { - push @{$local_cols->{$fk}}, lc $local_col; - push @{$remote_cols->{$fk}}, lc $remote_col; - $remote_table->{$fk} = lc $remote_tab; + push @{$local_cols->{$fk}}, $self->_lc($local_col); + push @{$remote_cols->{$fk}}, $self->_lc($remote_col); + $remote_table->{$fk} = $remote_tab; } foreach my $fk (keys %$remote_table) { @@ -182,7 +181,7 @@ EOF my $constraints; while (my ($constraint_name, $column) = $sth->fetchrow_array) { - push @{$constraints->{$constraint_name}}, lc $column; + push @{$constraints->{$constraint_name}}, $self->_lc($column); } my @uniqs = map { [ $_ => $constraints->{$_} ] } keys %$constraints; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm index f77dc4c..af8c3a0 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -82,7 +82,7 @@ sub _columns_info_for { } while (my ($col, $info) = each %$result) { - if (eval { ${ $info->{default_value} } eq 'CURRENT_TIMESTAMP' }) { + if (eval { ${ $info->{default_value} } }||'' eq 'CURRENT_TIMESTAMP') { ${ $info->{default_value} } = 'current_timestamp'; } } diff --git a/t/17sybase_asa_common.t b/t/17sybase_asa_common.t index db6eed3..0b7a241 100644 --- a/t/17sybase_asa_common.t +++ b/t/17sybase_asa_common.t @@ -30,25 +30,25 @@ my $tester = dbixcsl_common_tests->new( password => $odbc_password, } : ()), ], + loader_options => { preserve_case => 1 }, data_types => { # http://infocenter.sybase.com/help/topic/com.sybase.help.sqlanywhere.11.0.1/dbreference_en11/rf-datatypes.html # # Numeric types - # XXX rewrite low-precision floats to 'real' 'bit' => { data_type => 'bit' }, 'tinyint' => { data_type => 'tinyint' }, 'smallint' => { data_type => 'smallint' }, 'int' => { data_type => 'integer' }, 'integer' => { data_type => 'integer' }, 'bigint' => { data_type => 'bigint' }, - 'float' => { data_type => 'float' }, - 'real' => { data_type => 'float' }, + 'float' => { data_type => 'real' }, + 'real' => { data_type => 'real' }, 'double' => { data_type => 'double precision' }, 'double precision' => { data_type => 'double precision' }, - 'float(2)' => { data_type => 'float' }, - 'float(24)' => { data_type => 'float' }, + 'float(2)' => { data_type => 'real' }, + 'float(24)' => { data_type => 'real' }, 'float(25)' => { data_type => 'double precision' }, 'float(53)' => { data_type => 'double precision' }, diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index c6de223..782d985 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -135,7 +135,7 @@ sub run_only_extra_tests { my $file_count = grep /CREATE (?:TABLE|VIEW)/i, @{ $self->{extra}{create} || [] }; $file_count++; # schema - $file_count++ if $self->{data_type_tests}{ddl}; + $file_count++ for @{ $self->{data_type_tests}{table_names} || [] }; my $schema_class = $self->setup_schema($info, $file_count); my ($monikers, $classes) = $self->monikers_and_classes($schema_class); @@ -219,7 +219,8 @@ sub setup_schema { my $standard_sources = not defined $expected_count; if ($standard_sources) { - $expected_count = 36 + ($self->{data_type_tests}{test_count} ? 1 : 0); + $expected_count = 36; + $expected_count++ for @{ $self->{data_type_tests}{table_names} || [] }; $expected_count += grep /CREATE (?:TABLE|VIEW)/i, @{ $self->{extra}{create} || [] }; @@ -1676,9 +1677,14 @@ sub setup_data_type_tests { my $tests = $self->{data_type_tests} = {}; # split types into tables based on overrides - my @types = keys %$types; - my @split_off_types = grep /$DATA_TYPE_MULTI_TABLE_OVERRIDES{lc($self->{vendor})}/i, @types; - my @first_table_types = grep !/$DATA_TYPE_MULTI_TABLE_OVERRIDES{lc($self->{vendor})}/i, @types; + my (@types, @split_off_types, @first_table_types); + { + no warnings 'uninitialized'; + + @types = keys %$types; + @split_off_types = grep /$DATA_TYPE_MULTI_TABLE_OVERRIDES{lc($self->{vendor})}/i, @types; + @first_table_types = grep !/$DATA_TYPE_MULTI_TABLE_OVERRIDES{lc($self->{vendor})}/i, @types; + } @types = +{ map +($_, $types->{$_}), @first_table_types }, map +{ $_, $types->{$_} }, @split_off_types;