From: Rafael Kitover Date: Fri, 5 Mar 2010 19:31:39 +0000 (-0500) Subject: Firebird: mixed case support (wip) X-Git-Tag: 0.06000~64 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=243c6ebce7ae31cd4234b3125b177d4d0c86bcc7;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Firebird: mixed case support (wip) --- diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index 2b7f72f..99e2fbe 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -46,8 +46,11 @@ sub new { } # Set up the default quoting character and name seperators - $self->{_quoter} = $self->_build_quoter; + $self->{_quoter} = $self->_build_quoter; $self->{_namesep} = $self->_build_namesep; + $self->schema->storage->sql_maker->quote_char($self->{_quoter}); + $self->schema->storage->sql_maker->name_sep($self->{_namesep}); + # For our usage as regex matches, concatenating multiple quoter # values works fine (e.g. s/\Q<>\E// if quoter was [ '<', '>' ]) if( ref $self->{_quoter} eq 'ARRAY') { @@ -178,7 +181,7 @@ sub _table_columns { my $sth = $self->_sth_for($table, undef, \'1 = 0'); $sth->execute; - my $retval = \@{$sth->{NAME_lc}}; + my $retval = $self->_is_case_sensitive ? \@{$sth->{NAME}} : \@{$sth->{NAME_lc}}; $sth->finish; $retval; @@ -305,7 +308,7 @@ sub _columns_info_for { my %result; my $sth = $self->_sth_for($table, undef, \'1 = 0'); $sth->execute; - my @columns = @{$sth->{NAME_lc}}; + my @columns = @{ $self->_is_case_sensitive ? $sth->{NAME} : $sth->{NAME_lc} }; for my $i ( 0 .. $#columns ){ my $column_info = {}; $column_info->{data_type} = $sth->{TYPE}->[$i]; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm b/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm index 11b4ca2..978f1ab 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm @@ -17,10 +17,12 @@ Firebird Implementation. =head1 DESCRIPTION -See L. +See L for available options. =cut +sub _is_case_sensitive { 1 } + sub _table_pk_info { my ($self, $table) = @_; @@ -39,7 +41,7 @@ EOF while (my ($col) = $sth->fetchrow_array) { s/^\s+//, s/\s+\z// for $col; - push @keydata, lc $col; + push @keydata, $col; } return \@keydata; @@ -65,8 +67,8 @@ EOF while (my ($fk, $local_col, $remote_tab, $remote_col) = $sth->fetchrow_array) { s/^\s+//, s/\s+\z// for $fk, $local_col, $remote_tab, $remote_col; - push @{$local_cols->{$fk}}, lc $local_col; - push @{$remote_cols->{$fk}}, lc $remote_col; + push @{$local_cols->{$fk}}, $local_col; + push @{$remote_cols->{$fk}}, $remote_col; $remote_table->{$fk} = $remote_tab; } @@ -97,7 +99,7 @@ EOF while (my ($constraint_name, $column) = $sth->fetchrow_array) { s/^\s+//, s/\s+\z// for $constraint_name, $column; - push @{$constraints->{$constraint_name}}, lc $column; + push @{$constraints->{$constraint_name}}, $column; } my @uniqs = map { [ $_ => $constraints->{$_} ] } keys %$constraints; @@ -121,12 +123,16 @@ EOF $sth->execute($table); while (my ($trigger) = $sth->fetchrow_array) { - my @trig_cols = $trigger =~ /new\."?(\w+)/ig; + my @trig_cols = map { + /^"([^"]+)/ ? $1 : uc($1) + } $trigger =~ /new\.("?\w+"?)/ig; + + my ($quoted, $generator) = $trigger =~ +/(?:gen_id\s* \( \s* |next \s* value \s* for \s*)(")?(\w+)/ix; - my ($generator) = $trigger =~ -/(?:gen_id\s* \( \s* |next \s* value \s* for \s*)"?(\w+)/ix; + $generator = uc $generator unless $quoted; - if (first { lc($_) eq lc($column) } @trig_cols) { + if ((first { $_ eq $column } @trig_cols) && $generator) { $extra_info{is_auto_increment} = 1; $extra_info{sequence} = $generator; } @@ -147,7 +153,7 @@ FROM rdb$relation_fields rf WHERE rf.rdb$relation_name = ? AND rf.rdb$field_name = ? EOF - $sth->execute($table, uc $column); + $sth->execute($table, $column); my ($default_src) = $sth->fetchrow_array; if ($default_src && (my ($def) = $default_src =~ /^DEFAULT \s+ (\S+)/ix)) { diff --git a/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm b/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm index 406904c..a0a1785 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm @@ -27,14 +27,6 @@ See L. =cut -sub _setup { - my $self = shift; - - $self->next::method(@_); - $self->{db_schema} ||= $self->_build_db_schema; - $self->_set_quote_char_and_name_sep; -} - sub _table_pk_info { my ($self, $table) = @_; my $dbh = $self->schema->storage->dbh; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm b/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm index 68f7be9..145eef9 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm @@ -29,14 +29,6 @@ See L. sub _is_case_sensitive { 1 } -sub _setup { - my $self = shift; - - $self->next::method(@_); - $self->{db_schema} ||= $self->_build_db_schema; - $self->_set_quote_char_and_name_sep; -} - sub _rebless { my $self = shift; diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Common.pm b/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Common.pm index c0cae3b..676efd8 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Common.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Common.pm @@ -23,14 +23,14 @@ See L. sub _build_quoter { '"' } sub _build_namesep { '.' } -sub _set_quote_char_and_name_sep { +sub _setup { my $self = shift; - $self->schema->storage->sql_maker->quote_char([qw/[ ]/]) - unless $self->schema->storage->sql_maker->quote_char; + $self->next::method(@_); - $self->schema->storage->sql_maker->name_sep('.') - unless $self->schema->storage->sql_maker->name_sep; + $self->schema->storage->sql_maker->quote_char([qw/[ ]/]); + $self->schema->storage->sql_maker->name_sep('.'); + $self->{db_schema} ||= $self->_build_db_schema; } sub _build_db_schema { diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm index 092ed5c..2fe5824 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm @@ -184,6 +184,7 @@ sub _remote_relname { # name, to make filter accessors work, but strip trailing _id if(scalar keys %{$cond} == 1) { my ($col) = values %{$cond}; + $col = lc $col; $col =~ s/_id$//; $remote_relname = $self->_inflect_singular($col); } @@ -266,7 +267,7 @@ sub _relnames_and_method { my $remote_moniker = $rel->{remote_source}; my $remote_obj = $self->{schema}->source( $remote_moniker ); my $remote_class = $self->{schema}->class( $remote_moniker ); - my $remote_relname = $self->_remote_relname( $remote_obj->from, $cond); + my $remote_relname = lc $self->_remote_relname( $remote_obj->from, $cond); my $local_cols = $rel->{local_columns}; my $local_table = $self->{schema}->source($local_moniker)->from; @@ -276,7 +277,7 @@ sub _relnames_and_method { my $local_relname; my $old_multirel_name; #< TODO: remove me if ( $counters->{$remote_moniker} > 1) { - my $colnames = q{_} . join(q{_}, @$local_cols); + my $colnames = lc(q{_} . join(q{_}, @$local_cols)); $remote_relname .= $colnames if keys %$cond > 1; $local_relname = lc($local_table) . $colnames; diff --git a/t/18firebird_common.t b/t/18firebird_common.t index 6143e9d..b48160c 100644 --- a/t/18firebird_common.t +++ b/t/18firebird_common.t @@ -1,6 +1,7 @@ use strict; use lib qw(t/lib); use dbixcsl_common_tests; +use dbixcsl_firebird_extra_tests; my $dsn = $ENV{DBICTEST_FIREBIRD_DSN} || ''; my $user = $ENV{DBICTEST_FIREBIRD_USER} || ''; @@ -32,6 +33,8 @@ my $tester = dbixcsl_common_tests->new( ); }, null => '', + extra => dbixcsl_firebird_extra_tests->extra, + uppercase_identifiers => 1, dsn => $dsn, user => $user, password => $password, diff --git a/t/18firebird_odbc_common.t b/t/18firebird_odbc_common.t index 323b6f2..311dc9d 100644 --- a/t/18firebird_odbc_common.t +++ b/t/18firebird_odbc_common.t @@ -1,6 +1,7 @@ use strict; use lib qw(t/lib); use dbixcsl_common_tests; +use dbixcsl_firebird_extra_tests; my $dsn = $ENV{DBICTEST_FIREBIRD_ODBC_DSN} || ''; my $user = $ENV{DBICTEST_FIREBIRD_ODBC_USER} || ''; @@ -32,7 +33,8 @@ my $tester = dbixcsl_common_tests->new( ); }, null => '', - date_datatype => 'TIMESTAMP', + extra => dbixcsl_firebird_extra_tests->extra, + uppercase_identifiers => 1, dsn => $dsn, user => $user, password => $password, diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index e1ee1ce..145e1db 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -205,6 +205,9 @@ sub test_schema { my $schema_class = shift; my $conn = $schema_class->clone; + + ($self->{before_tests_run} || sub {})->($conn); + my $monikers = {}; my $classes = {}; foreach my $source_name ($schema_class->sources) { @@ -249,13 +252,13 @@ sub test_schema { isa_ok( $rsobj35, "DBIx::Class::ResultSet" ); my @columns_lt2 = $class2->columns; - is_deeply( \@columns_lt2, [ qw/id dat dat2/ ], "Column Ordering" ); + is_deeply( [ map lc, @columns_lt2 ], [ qw/id dat dat2/ ], "Column Ordering" ); my %uniq1 = $class1->unique_constraints; my $uniq1_test = 0; foreach my $ucname (keys %uniq1) { my $cols_arrayref = $uniq1{$ucname}; - if(@$cols_arrayref == 1 && $cols_arrayref->[0] eq 'dat') { + if(@$cols_arrayref == 1 && lc($cols_arrayref->[0]) eq 'dat') { $uniq1_test = 1; last; } @@ -269,8 +272,8 @@ sub test_schema { foreach my $ucname (keys %uniq2) { my $cols_arrayref = $uniq2{$ucname}; if(@$cols_arrayref == 2 - && $cols_arrayref->[0] eq 'dat2' - && $cols_arrayref->[1] eq 'dat') { + && lc($cols_arrayref->[0]) eq 'dat2' + && lc($cols_arrayref->[1]) eq 'dat') { $uniq2_test = 2; last; } @@ -328,8 +331,8 @@ sub test_schema { or skip "Pre-requisite test failed"; is( $rsobj1->loader_test1_rsmeth, 'all is still well', 'Result set method' ); } - - ok( $class1->column_info('id')->{is_auto_increment}, 'is_auto_increment detection' ); + + ok( $self->_dbic_column_info($class1, 'id')->{is_auto_increment}, 'is_auto_increment detection' ); my $obj = $rsobj1->find(1); is( $obj->id, 1, "Find got the right row" ); @@ -337,35 +340,35 @@ sub test_schema { is( $rsobj2->count, 4, "Count" ); my $saved_id; eval { - my $new_obj1 = $rsobj1->create({ dat => 'newthing' }); + my $new_obj1 = $self->_dbic_create($rsobj1, { dat => 'newthing' }); $saved_id = $new_obj1->id; }; ok(!$@, "Inserting new record using a PK::Auto key didn't die") or diag $@; ok($saved_id, "Got PK::Auto-generated id"); - my $new_obj1 = $rsobj1->search({ dat => 'newthing' })->first; + my $new_obj1 = $self->_dbic_search($rsobj1, { dat => 'newthing' })->first; ok($new_obj1, "Found newly inserted PK::Auto record"); is($new_obj1->id, $saved_id, "Correct PK::Auto-generated id"); - my ($obj2) = $rsobj2->search({ dat => 'bbb' })->first; + my ($obj2) = $self->_dbic_search($rsobj2, { dat => 'bbb' })->first; is( $obj2->id, 2 ); is( - $class35->column_info('a_varchar')->{default_value}, 'foo', + $self->_dbic_column_info($class35, 'a_varchar')->{default_value}, 'foo', 'constant character default', ); is( - $class35->column_info('an_int')->{default_value}, 42, + $self->_dbic_column_info($class35, 'an_int')->{default_value}, 42, 'constant integer default', ); is( - $class35->column_info('a_double')->{default_value}, 10.555, + $self->_dbic_column_info($class35, 'a_double')->{default_value}, 10.555, 'constant numeric default', ); - my $function_default = $class35->column_info('a_function')->{default_value}; + my $function_default = $self->_dbic_column_info($class35, 'a_function')->{default_value}; isa_ok( $function_default, 'SCALAR', 'default_value for function default' ); is_deeply( @@ -501,7 +504,7 @@ sub test_schema { my $obj4 = $rsobj4->find(123); isa_ok( $obj4->fkid_singular, $class3); - ok($class4->column_info('fkid')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class4, 'fkid')->{is_foreign_key}, 'Foreign key detected'); my $obj3 = $rsobj3->find(1); my $rs_rel4 = $obj3->search_related('loader_test4zes'); @@ -509,8 +512,8 @@ sub test_schema { # find on multi-col pk my $obj5 = - eval { $rsobj5->find({id1 => 1, iD2 => 1}) } || - eval { $rsobj5->find({id1 => 1, id2 => 1}) }; + eval { $self->_dbic_find($rsobj5, {id1 => 1, iD2 => 1}) } || + eval { $self->_dbic_find($rsobj5, {id1 => 1, id2 => 1}) }; die $@ if $@; is( $obj5->id2, 1, "Find on multi-col PK" ); @@ -520,18 +523,18 @@ sub test_schema { isa_ok( $obj6->loader_test2, $class2); isa_ok( $obj6->loader_test5, $class5); - ok($class6->column_info('loader_test2_id')->{is_foreign_key}, 'Foreign key detected'); - ok($class6->column_info('id')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class6, 'loader_test2_id')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class6, 'id')->{is_foreign_key}, 'Foreign key detected'); - my $id2_info = eval { $class6->column_info('id2') } || - $class6->column_info('Id2'); + my $id2_info = eval { $self->_dbic_column_info($class6, 'id2') } || + $self->_dbic_column_info($class6, 'Id2'); ok($id2_info->{is_foreign_key}, 'Foreign key detected'); # fk that references a non-pk key (UNIQUE) my $obj8 = $rsobj8->find(1); isa_ok( $obj8->loader_test7, $class7); - ok($class8->column_info('loader_test7')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class8, 'loader_test7')->{is_foreign_key}, 'Foreign key detected'); # test double-fk 17 ->-> 16 my $obj17 = $rsobj17->find(33); @@ -540,13 +543,13 @@ sub test_schema { isa_ok($rs_rel16_one, $class16); is($rs_rel16_one->dat, 'y16', "Multiple FKs to same table"); - ok($class17->column_info('loader16_one')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class17, 'loader16_one')->{is_foreign_key}, 'Foreign key detected'); my $rs_rel16_two = $obj17->loader16_two; isa_ok($rs_rel16_two, $class16); is($rs_rel16_two->dat, 'z16', "Multiple FKs to same table"); - ok($class17->column_info('loader16_two')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class17, 'loader16_two')->{is_foreign_key}, 'Foreign key detected'); my $obj16 = $rsobj16->find(2); my $rs_rel17 = $obj16->search_related('loader_test17_loader16_ones'); @@ -554,12 +557,12 @@ sub test_schema { is($rs_rel17->first->id, 3, "search_related with multiple FKs from same table"); # XXX test m:m 18 <- 20 -> 19 - ok($class20->column_info('parent')->{is_foreign_key}, 'Foreign key detected'); - ok($class20->column_info('child')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class20, 'parent')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class20, 'child')->{is_foreign_key}, 'Foreign key detected'); # XXX test double-fk m:m 21 <- 22 -> 21 - ok($class22->column_info('parent')->{is_foreign_key}, 'Foreign key detected'); - ok($class22->column_info('child')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class22, 'parent')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class22, 'child')->{is_foreign_key}, 'Foreign key detected'); # test double multi-col fk 26 -> 25 my $obj26 = $rsobj26->find(33); @@ -568,9 +571,9 @@ sub test_schema { isa_ok($rs_rel25_one, $class25); is($rs_rel25_one->dat, 'x25', "Multiple multi-col FKs to same table"); - ok($class26->column_info('id')->{is_foreign_key}, 'Foreign key detected'); - ok($class26->column_info('rel1')->{is_foreign_key}, 'Foreign key detected'); - ok($class26->column_info('rel2')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class26, 'id')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class26, 'rel1')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class26, 'rel2')->{is_foreign_key}, 'Foreign key detected'); my $rs_rel25_two = $obj26->loader_test25_id_rel2; isa_ok($rs_rel25_two, $class25); @@ -585,26 +588,26 @@ sub test_schema { my $obj27 = $rsobj27->find(1); my $obj28 = $obj27->loader_test28; isa_ok($obj28, $class28); - is($obj28->get_column('id'), 1, "One-to-one relationship with PRIMARY FK"); + is($self->_dbic_get_column($obj28, 'id'), 1, "One-to-one relationship with PRIMARY FK"); - ok($class28->column_info('id')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class28, 'id')->{is_foreign_key}, 'Foreign key detected'); my $obj29 = $obj27->loader_test29; isa_ok($obj29, $class29); is($obj29->id, 1, "One-to-one relationship with UNIQUE FK"); - ok($class29->column_info('fk')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class29, 'fk')->{is_foreign_key}, 'Foreign key detected'); $obj27 = $rsobj27->find(2); is($obj27->loader_test28, undef, "Undef for missing one-to-one row"); is($obj27->loader_test29, undef, "Undef for missing one-to-one row"); # test outer join for nullable referring columns: - is $class32->column_info('rel2')->{is_nullable}, 1, + is $self->_dbic_column_info($class32, 'rel2')->{is_nullable}, 1, 'is_nullable detection'; - ok($class32->column_info('rel1')->{is_foreign_key}, 'Foreign key detected'); - ok($class32->column_info('rel2')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class32, 'rel1')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class32, 'rel2')->{is_foreign_key}, 'Foreign key detected'); my $obj32 = $rsobj32->find(1,{prefetch=>[qw/rel1 rel2/]}); my $obj34 = $rsobj34->find( @@ -613,9 +616,9 @@ sub test_schema { isa_ok($obj32,$class32); isa_ok($obj34,$class34); - ok($class34->column_info('id')->{is_foreign_key}, 'Foreign key detected'); - ok($class34->column_info('rel1')->{is_foreign_key}, 'Foreign key detected'); - ok($class34->column_info('rel2')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class34, 'id')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class34, 'rel1')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class34, 'rel2')->{is_foreign_key}, 'Foreign key detected'); my $rs_rel31_one = $obj32->rel1; my $rs_rel31_two = $obj32->rel2; @@ -640,29 +643,29 @@ sub test_schema { isa_ok( $rsobj10, "DBIx::Class::ResultSet" ); isa_ok( $rsobj11, "DBIx::Class::ResultSet" ); - ok($class10->column_info('loader_test11')->{is_foreign_key}, 'Foreign key detected'); - ok($class11->column_info('loader_test10')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class10, 'loader_test11')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class11, 'loader_test10')->{is_foreign_key}, 'Foreign key detected'); - my $obj10 = $rsobj10->create({ subject => 'xyzzy' }); + my $obj10 = $self->_dbic_create($rsobj10, { subject => 'xyzzy' }); $obj10->update(); ok( defined $obj10, 'Create row' ); - my $obj11 = $rsobj11->create({ loader_test10 => $obj10->id() }); + my $obj11 = $self->_dbic_create($rsobj11, { loader_test10 => $obj10->id() }); $obj11->update(); ok( defined $obj11, 'Create related row' ); eval { my $obj10_2 = $obj11->loader_test10; - $obj10_2->loader_test11( $obj11->id11() ); - $obj10_2->update(); + $self->_dbic_update($obj10_2, { loader_test11 => $obj11->id11 }); }; + diag $@ if $@; ok(!$@, "Setting up circular relationship"); SKIP: { skip 'Previous eval block failed', 3 if $@; - my $results = $rsobj10->search({ subject => 'xyzzy' }); + my $results = $self->_dbic_search($rsobj10, { subject => 'xyzzy' }); is( $results->count(), 1, 'No duplicate row created' ); my $obj10_3 = $results->first(); @@ -686,9 +689,9 @@ sub test_schema { isa_ok( $rsobj12, "DBIx::Class::ResultSet" ); isa_ok( $rsobj13, "DBIx::Class::ResultSet" ); - ok($class13->column_info('id')->{is_foreign_key}, 'Foreign key detected'); - ok($class13->column_info('loader_test12')->{is_foreign_key}, 'Foreign key detected'); - ok($class13->column_info('dat')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class13, 'id')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class13, 'loader_test12')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class13, 'dat')->{is_foreign_key}, 'Foreign key detected'); my $obj13 = $rsobj13->find(1); isa_ok( $obj13->id, $class12 ); @@ -713,7 +716,7 @@ sub test_schema { isa_ok( $rsobj14, "DBIx::Class::ResultSet" ); isa_ok( $rsobj15, "DBIx::Class::ResultSet" ); - ok($class15->column_info('loader_test14')->{is_foreign_key}, 'Foreign key detected'); + ok($self->_dbic_column_info($class15, 'loader_test14')->{is_foreign_key}, 'Foreign key detected'); my $obj15 = $rsobj15->find(1); isa_ok( $obj15->loader_test14, $class14 ); @@ -725,18 +728,18 @@ sub test_schema { my $class35 = $classes->{loader_test35}; my $class36 = $classes->{loader_test36}; - ok($class35->column_info('an_int')->{is_numeric}, 'custom_column_info'); + ok($self->_dbic_column_info($class35, 'an_int')->{is_numeric}, 'custom_column_info'); - is($class36->column_info('a_date')->{locale},'de_DE','datetime_locale'); - is($class36->column_info('a_date')->{timezone},'Europe/Berlin','datetime_timezone'); + is($self->_dbic_column_info($class36, 'a_date')->{locale},'de_DE','datetime_locale'); + is($self->_dbic_column_info($class36, 'a_date')->{timezone},'Europe/Berlin','datetime_timezone'); - ok($class36->column_info('b_char_as_data')->{inflate_datetime},'custom_column_info'); - is($class36->column_info('b_char_as_data')->{locale},'de_DE','datetime_locale'); - is($class36->column_info('b_char_as_data')->{timezone},'Europe/Berlin','datetime_timezone'); + ok($self->_dbic_column_info($class36, 'b_char_as_data')->{inflate_datetime},'custom_column_info'); + is($self->_dbic_column_info($class36, 'b_char_as_data')->{locale},'de_DE','datetime_locale'); + is($self->_dbic_column_info($class36, 'b_char_as_data')->{timezone},'Europe/Berlin','datetime_timezone'); - ok($class36->column_info('c_char_as_data')->{inflate_date},'custom_column_info'); - is($class36->column_info('c_char_as_data')->{locale},'de_DE','datetime_locale'); - is($class36->column_info('c_char_as_data')->{timezone},'Europe/Berlin','datetime_timezone'); + ok($self->_dbic_column_info($class36, 'c_char_as_data')->{inflate_date},'custom_column_info'); + is($self->_dbic_column_info($class36, 'c_char_as_data')->{locale},'de_DE','datetime_locale'); + is($self->_dbic_column_info($class36, 'c_char_as_data')->{timezone},'Europe/Berlin','datetime_timezone'); } # rescan and norewrite test @@ -808,7 +811,7 @@ sub test_schema { my $obj30 = $rsobj30->find(123); isa_ok( $obj30->loader_test2, $class2); - ok($rsobj30->result_source->column_info('loader_test2')->{is_foreign_key}, + ok($self->_dbic_column_info($rsobj30->result_source, 'loader_test2')->{is_foreign_key}, 'Foreign key detected'); } @@ -1383,7 +1386,8 @@ sub drop_tables { my $dbh = $self->dbconnect(0); - $dbh->do("DROP TABLE $_") for @{ $self->{extra}->{drop} || [] }; + $dbh->do($_) for @{ $self->{extra}{pre_drop_ddl} || [] }; + $dbh->do("DROP TABLE $_") for @{ $self->{extra}{drop} || [] }; my $drop_auto_inc = $self->{auto_inc_drop_cb} || sub {}; @@ -1410,6 +1414,52 @@ sub drop_tables { $dbh->disconnect; } +sub _dbic_column_info { + my ($self, $class, $colname) = @_; + + return $self->{uppercase_identifiers} ? $class->column_info(uc $colname) : $class->column_info($colname); +} + +sub _dbic_get_column { + my ($self, $obj, $colname) = @_; + + return $self->{uppercase_identifiers} ? $obj->get_column(uc $colname) : $obj->get_column($colname); +} + +sub _dbic_update { + my ($self, $obj, $data) = @_; + + return $self->_wrap_dbic_method_with_hash($obj, 'update', $data); +} + +sub _dbic_create { + my ($self, $rs, $data) = @_; + + return $self->_wrap_dbic_method_with_hash($rs, 'create', $data); +} + +sub _dbic_search { + my ($self, $rs, $cond) = @_; + + return $self->_wrap_dbic_method_with_hash($rs, 'search', $cond); +} + +sub _dbic_find { + my ($self, $rs, $cond) = @_; + + return $self->_wrap_dbic_method_with_hash($rs, 'find', $cond); +} + +sub _wrap_dbic_method_with_hash { + my ($self, $obj, $method, $hash) = @_; + + return $obj->$method($hash) unless $self->{uppercase_identifiers}; + + my %hash; + @hash{map uc, keys %$hash} = values %$hash; + $obj->$method(\%hash) +} + sub DESTROY { my $self = shift; unless ($ENV{SCHEMA_LOADER_TESTS_NOCLEANUP}) { diff --git a/t/lib/dbixcsl_firebird_extra_tests.pm b/t/lib/dbixcsl_firebird_extra_tests.pm new file mode 100644 index 0000000..464b92e --- /dev/null +++ b/t/lib/dbixcsl_firebird_extra_tests.pm @@ -0,0 +1,54 @@ +package dbixcsl_firebird_extra_tests; + +use strict; +use warnings; +use Test::More; +use Test::Exception; + +sub extra { +{ + create => [ +# test a mixed case table + q{ + CREATE TABLE "Firebird_Loader_Test1" ( + "Id" INTEGER NOT NULL PRIMARY KEY + ) + }, + q{ + CREATE GENERATOR "Gen_Firebird_Loader_Test1_Id" + }, + q{ + CREATE TRIGGER "Firebird_Loader_Test1_BI" for "Firebird_Loader_Test1" + ACTIVE BEFORE INSERT POSITION 0 + AS + BEGIN + IF (NEW."Id" IS NULL) THEN + NEW."Id" = GEN_ID("Gen_Firebird_Loader_Test1_Id",1); + END + }, + ], + pre_drop_ddl => [ + q{DROP TRIGGER "Firebird_Loader_Test1_BI"}, + q{DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"}, + ], + drop => [ + q{"Firebird_Loader_Test1"} + ], + count => 5, + run => sub { + my ($schema, $monikers, $classes) = @_; + + ok ((my $rsrc = eval { $schema->resultset($monikers->{Firebird_Loader_Test1})->result_source }), + 'got rsrc for mixed case table'); + + ok ((my $col_info = eval { $rsrc->column_info('Id') }), + 'got column_info for column Id'); + + is $col_info->{accessor}, 'id', 'column Id has lowercase accessor "id"'; + + is $col_info->{is_auto_increment}, 1, 'is_auto_increment detected for mixed case trigger'; + + is $col_info->{sequence}, 'Gen_Firebird_Loader_Test1_Id', 'correct mixed case sequence name'; + }, +}} + +1; diff --git a/t/lib/dbixcsl_mssql_extra_tests.pm b/t/lib/dbixcsl_mssql_extra_tests.pm index e4767f9..4102203 100644 --- a/t/lib/dbixcsl_mssql_extra_tests.pm +++ b/t/lib/dbixcsl_mssql_extra_tests.pm @@ -5,9 +5,6 @@ use warnings; use Test::More; use Test::Exception; -# for cleanup in END -my $storage; - sub extra { +{ create => [ q{ @@ -26,9 +23,13 @@ sub extra { +{ SELECT * FROM mssql_loader_test3 }, ], + pre_drop_ddl => [ + 'CREATE TABLE mssql_loader_test3 (id INT IDENTITY NOT NULL PRIMARY KEY)', + 'DROP VIEW mssql_loader_test4', + ], drop => [ - "[mssql_loader_test1.dot]", - "mssql_loader_test3" + '[mssql_loader_test1.dot]', + 'mssql_loader_test3' ], count => 8, run => sub { @@ -59,9 +60,7 @@ sub extra { +{ q{'INT IDENTITY' column has is_auto_increment => 1}; # Test that a bad view (where underlying table is gone) is ignored. - $storage = $schema->storage; - - my $dbh = $storage->dbh; + my $dbh = $schema->storage->dbh; $dbh->do("DROP TABLE mssql_loader_test3"); my @warnings; @@ -79,17 +78,4 @@ sub extra { +{ }, }} -# Clean up the bad view -END { - local $@; - eval { - my $dbh = $storage->dbh; - $dbh->do($_) for ( -"CREATE TABLE mssql_loader_test3 (id INT IDENTITY NOT NULL PRIMARY KEY)", -"DROP VIEW mssql_loader_test4", -"DROP TABLE mssql_loader_test3", - ); - }; -} - 1;