Firebird: mixed case support (wip)
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / lib / dbixcsl_common_tests.pm
index 03d7ecd..145e1db 100644 (file)
@@ -38,6 +38,12 @@ sub new {
     # Optional extra tables and tests
     $self->{extra} ||= {};
 
+    $self->{date_datatype} ||= 'DATE';
+
+    # Not all DBS do SQL-standard CURRENT_TIMESTAMP
+    $self->{default_function} ||= "CURRENT_TIMESTAMP";
+    $self->{default_function_def} ||= "TIMESTAMP DEFAULT $self->{default_function}";
+
     return bless $self => $class;
 }
 
@@ -53,10 +59,33 @@ sub _monikerize {
     return undef;
 }
 
+sub _custom_column_info {
+    my ( $table_name, $column_name, $column_info ) = @_;
+
+    $table_name = lc ( $table_name );
+    $column_name = lc ( $column_name );
+
+    if ( $table_name eq 'loader_test35' 
+        and $column_name eq 'an_int' 
+    ){
+        return { is_numeric => 1 }
+    }
+    # Set inflate_datetime or  inflate_date to check 
+    #   datetime_timezone and datetime_locale
+    if ( $table_name eq 'loader_test36' ){
+        return { inflate_datetime => 1 } if 
+            ( $column_name eq 'b_char_as_data' );
+        return { inflate_date => 1 } if 
+            ( $column_name eq 'c_char_as_data' );
+    }
+
+    return;
+}
+
 sub run_tests {
     my $self = shift;
 
-    plan tests => 140 + ($self->{extra}->{count} || 0);
+    plan tests => 157 + ($self->{extra}->{count} || 0);
 
     $self->create();
 
@@ -70,7 +99,6 @@ sub run_tests {
     # First, with in-memory classes
     my $schema_class = $self->setup_schema(@connect_info);
     $self->test_schema($schema_class);
-    $self->drop_tables;
 }
 
 # defined in sub create
@@ -88,7 +116,7 @@ sub setup_schema {
 
     my %loader_opts = (
         constraint              =>
-           qr/^(?:\S+\.)?(?:$self->{vendor}_)?loader_test[0-9]+(?!.*_)/i,
+           qr/^(?:\S+\.)?(?:(?:$self->{vendor}|extra)_)?loader_test[0-9]+(?!.*_)/i,
         relationships           => 1,
         additional_classes      => 'TestAdditional',
         additional_base_classes => 'TestAdditionalBase',
@@ -98,9 +126,12 @@ sub setup_schema {
         inflect_plural          => { loader_test4 => 'loader_test4zes' },
         inflect_singular        => { fkid => 'fkid_singular' },
         moniker_map             => \&_monikerize,
+        custom_column_info      => \&_custom_column_info,
         debug                   => $debug,
         use_namespaces          => 0,
         dump_directory          => $DUMP_DIR,
+        datetime_timezone       => 'Europe/Berlin',
+        datetime_locale         => 'de_DE'
     );
 
     $loader_opts{db_schema} = $self->{db_schema} if $self->{db_schema};
@@ -121,7 +152,7 @@ sub setup_schema {
        my $file_count;
        find sub { return if -d; $file_count++ }, $DUMP_DIR;
 
-       my $expected_count = 34;
+       my $expected_count = 36;
 
        $expected_count += grep /CREATE (?:TABLE|VIEW)/i,
            @{ $self->{extra}{create} || [] };
@@ -144,6 +175,8 @@ sub setup_schema {
 
        $warn_count++ for grep /^Bad table or view/, @loader_warnings;
 
+       $warn_count++ for grep /stripping trailing _id/, @loader_warnings;
+
        my $vendor = $self->{vendor};
        $warn_count++ for grep /${vendor}_\S+ has no primary key/,
            @loader_warnings;
@@ -159,7 +192,7 @@ sub setup_schema {
            $warn_count++;
             is(scalar(@loader_warnings), $warn_count, "Expected loader warning")
                 or diag @loader_warnings;
-            is(grep(/loader_test9 has no primary key/, @loader_warnings), 1,
+            is(grep(/loader_test9 has no primary key/i, @loader_warnings), 1,
                  "Missing PK warning");
         }
     }
@@ -172,12 +205,22 @@ 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) {
         my $table_name = $schema_class->source($source_name)->from;
+
+        $table_name = $$table_name if ref $table_name;
+
         $monikers->{$table_name} = $source_name;
         $classes->{$table_name} = $schema_class . q{::} . $source_name;
+
+        # some DBs (Firebird) uppercase everything
+        $monikers->{lc $table_name} = $source_name;
+        $classes->{lc $table_name} = $schema_class . q{::} . $source_name;
     }
 
     my $moniker1 = $monikers->{loader_test1s};
@@ -190,27 +233,32 @@ sub test_schema {
     my $rsobj2   = $conn->resultset($moniker2);
     check_no_duplicate_unique_constraints($class2);
 
-    my $moniker23 = $monikers->{LOADER_TEST23};
-    my $class23   = $classes->{LOADER_TEST23};
+    my $moniker23 = $monikers->{LOADER_TEST23} || $monikers->{loader_test23};
+    my $class23   = $classes->{LOADER_TEST23}  || $classes->{loader_test23};
     my $rsobj23   = $conn->resultset($moniker1);
 
-    my $moniker24 = $monikers->{LoAdEr_test24};
-    my $class24   = $classes->{LoAdEr_test24};
+    my $moniker24 = $monikers->{LoAdEr_test24} || $monikers->{loader_test24};
+    my $class24   = $classes->{LoAdEr_test24}  || $classes->{loader_test24};
     my $rsobj24   = $conn->resultset($moniker2);
 
+    my $moniker35 = $monikers->{loader_test35};
+    my $class35   = $classes->{loader_test35};
+    my $rsobj35   = $conn->resultset($moniker35);
+
     isa_ok( $rsobj1, "DBIx::Class::ResultSet" );
     isa_ok( $rsobj2, "DBIx::Class::ResultSet" );
     isa_ok( $rsobj23, "DBIx::Class::ResultSet" );
     isa_ok( $rsobj24, "DBIx::Class::ResultSet" );
+    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;
         }
@@ -224,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;
         }
@@ -283,9 +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_incrment detection' );
-    is($class2->column_info('dat2')->{default_value}, 'foo', 'Correct default value');
+
+    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" );
@@ -293,21 +340,44 @@ 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(
+        $self->_dbic_column_info($class35, 'a_varchar')->{default_value}, 'foo',
+        'constant character default',
+    );
+
+    is(
+        $self->_dbic_column_info($class35, 'an_int')->{default_value}, 42,
+        'constant integer default',
+    );
+
+    is(
+        $self->_dbic_column_info($class35, 'a_double')->{default_value}, 10.555,
+        'constant numeric default',
+    );
+
+    my $function_default = $self->_dbic_column_info($class35, 'a_function')->{default_value};
+
+    isa_ok( $function_default, 'SCALAR', 'default_value for function default' );
+    is_deeply(
+        $function_default, \$self->{default_function},
+        'default_value for function default is correct'
+    );
+
     SKIP: {
-        skip $self->{skip_rels}, 96 if $self->{skip_rels};
+        skip $self->{skip_rels}, 99 if $self->{skip_rels};
 
         my $moniker3 = $monikers->{loader_test3};
         my $class3   = $classes->{loader_test3};
@@ -401,6 +471,10 @@ sub test_schema {
         my $class34   = $classes->{loader_test34};
         my $rsobj34   = $conn->resultset($moniker34);
 
+        my $moniker36 = $monikers->{loader_test36};
+        my $class36   = $classes->{loader_test36};
+        my $rsobj36   = $conn->resultset($moniker36);
+        
         isa_ok( $rsobj3, "DBIx::Class::ResultSet" );
         isa_ok( $rsobj4, "DBIx::Class::ResultSet" );
         isa_ok( $rsobj5, "DBIx::Class::ResultSet" );
@@ -424,12 +498,13 @@ sub test_schema {
         isa_ok( $rsobj32, "DBIx::Class::ResultSet" );
         isa_ok( $rsobj33, "DBIx::Class::ResultSet" );
         isa_ok( $rsobj34, "DBIx::Class::ResultSet" );
+        isa_ok( $rsobj36, "DBIx::Class::ResultSet" );
 
         # basic rel test
         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');
@@ -437,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" );
@@ -448,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);
@@ -468,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');
@@ -482,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);
@@ -496,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);
@@ -513,55 +588,48 @@ 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:
-        SKIP: {
-          skip "unreliable column info from db driver",11 unless 
-            ($class32->column_info('rel2')->{is_nullable});
-
-          ok($class32->column_info('rel1')->{is_foreign_key}, 'Foreign key detected');
-          ok($class32->column_info('rel2')->{is_foreign_key}, 'Foreign key detected');
-          
-          my $obj32 = $rsobj32->find(1,{prefetch=>[qw/rel1 rel2/]});
-          my $obj34 = $rsobj34->find(
-            1,{prefetch=>[qw/loader_test33_id_rel1 loader_test33_id_rel2/]}
-          );
-          my $skip_outerjoin;
-          isa_ok($obj32,$class32) or $skip_outerjoin = 1;
-          isa_ok($obj34,$class34) or $skip_outerjoin = 1;
-
-          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');
-
-          SKIP: {
-            skip "Pre-requisite test failed", 4 if $skip_outerjoin;
-            my $rs_rel31_one = $obj32->rel1;
-            my $rs_rel31_two = $obj32->rel2;
-            isa_ok($rs_rel31_one, $class31);
-            is($rs_rel31_two, undef);
-
-            my $rs_rel33_one = $obj34->loader_test33_id_rel1;
-            my $rs_rel33_two = $obj34->loader_test33_id_rel2;
-
-            isa_ok($rs_rel33_one,$class33);
-            is($rs_rel33_two, undef);
-
-          }
-        }
+        is $self->_dbic_column_info($class32, 'rel2')->{is_nullable}, 1,
+          'is_nullable detection';
+
+        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(
+          1,{prefetch=>[qw/loader_test33_id_rel1 loader_test33_id_rel2/]}
+        );
+        isa_ok($obj32,$class32);
+        isa_ok($obj34,$class34);
+
+        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;
+        isa_ok($rs_rel31_one, $class31);
+        is($rs_rel31_two, undef);
+
+        my $rs_rel33_one = $obj34->loader_test33_id_rel1;
+        my $rs_rel33_two = $obj34->loader_test33_id_rel2;
+
+        isa_ok($rs_rel33_one,$class33);
+        is($rs_rel33_two, undef);
 
         # from Chisel's tests...
         my $moniker10 = $monikers->{loader_test10};
@@ -572,32 +640,32 @@ sub test_schema {
         my $class11   = $classes->{loader_test11};
         my $rsobj11   = $conn->resultset($moniker11);
 
-        isa_ok( $rsobj10, "DBIx::Class::ResultSet" ); 
+        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();
@@ -607,7 +675,7 @@ sub test_schema {
         }
 
         SKIP: {
-            skip 'This vendor cannot do inline relationship definitions', 8
+            skip 'This vendor cannot do inline relationship definitions', 9
                 if $self->{no_inline_rels};
 
             my $moniker12 = $monikers->{loader_test12};
@@ -621,14 +689,17 @@ 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 );
             isa_ok( $obj13->loader_test12, $class12);
             isa_ok( $obj13->dat, $class12);
+
+            my $obj12 = $rsobj12->find(1);
+            isa_ok( $obj12->loader_test13, $class13 );
         }
 
         SKIP: {
@@ -645,13 +716,32 @@ 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 );
         }
     }
 
+    # test custom_column_info and datetime_timezone/datetime_locale
+    {
+        my $class35 = $classes->{loader_test35};
+        my $class36 = $classes->{loader_test36};
+
+        ok($self->_dbic_column_info($class35, 'an_int')->{is_numeric}, 'custom_column_info');
+
+        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($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($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
     SKIP: {
         my @statements_rescan = (
@@ -695,6 +785,7 @@ sub test_schema {
         }
 
         $dbh->disconnect;
+        $conn->storage->disconnect; # needed for Firebird
 
         sleep 1;
 
@@ -720,11 +811,13 @@ 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');
     }
 
     $self->{extra}->{run}->($conn, $monikers, $classes) if $self->{extra}->{run};
+
+    $conn->storage->disconnect;
 }
 
 sub check_no_duplicate_unique_constraints {
@@ -743,17 +836,25 @@ sub check_no_duplicate_unique_constraints {
 sub dbconnect {
     my ($self, $complain) = @_;
 
-    my $dbh = DBI->connect(
-         $self->{dsn}, $self->{user},
-         $self->{password},
-         {
-             RaiseError => $complain,
-             PrintError => $complain,
-             AutoCommit => 1,
-         }
-    );
+    require DBIx::Class::Storage::DBI;
+    my $storage = DBIx::Class::Storage::DBI->new;
 
-    die "Failed to connect to database: $DBI::errstr" if !$dbh;
+    $complain = defined $complain ? $complain : 1;
+
+    $storage->connect_info([
+        @{ $self }{qw/dsn user password/},
+        {
+            unsafe => 1,
+            RaiseError => $complain,
+            ShowErrorStatement => $complain,
+            PrintError => 0,
+        },
+    ]);
+
+    my $dbh = eval { $storage->dbh };
+    die "Failed to connect to database: $@" if !$dbh;
+
+    $self->{storage} = $storage; # storage DESTROY disconnects
 
     return $dbh;
 }
@@ -781,7 +882,7 @@ sub create {
             CREATE TABLE loader_test2 (
                 id $self->{auto_inc_pk},
                 dat VARCHAR(32) NOT NULL,
-                dat2 VARCHAR(32) NOT NULL DEFAULT 'foo',
+                dat2 VARCHAR(32) NOT NULL,
                 UNIQUE (dat2, dat)
             ) $self->{innodb}
         },
@@ -805,6 +906,25 @@ sub create {
                 DaT VARCHAR(32) NOT NULL UNIQUE
             ) $self->{innodb}
         },
+
+        qq{
+            CREATE TABLE loader_test35 (
+                id INTEGER NOT NULL PRIMARY KEY,
+                a_varchar VARCHAR(100) DEFAULT 'foo',
+                an_int INTEGER DEFAULT 42,
+                a_double DOUBLE PRECISION DEFAULT 10.555,
+                a_function $self->{default_function_def}
+            ) $self->{innodb}
+        },
+
+        qq{
+            CREATE TABLE loader_test36 (
+                id INTEGER NOT NULL PRIMARY KEY,
+                a_date $self->{date_datatype},
+                b_char_as_data VARCHAR(100),
+                c_char_as_data VARCHAR(100)
+            ) $self->{innodb}
+        },
     );
 
     @statements_reltests = (
@@ -1079,7 +1199,7 @@ sub create {
         qq{
             CREATE TABLE loader_test11 (
                 id11 $self->{auto_inc_pk},
-                message VARCHAR(8) DEFAULT 'foo',
+                a_message VARCHAR(8) DEFAULT 'foo',
                 loader_test10 INTEGER $self->{null},
                 FOREIGN KEY (loader_test10) REFERENCES loader_test10 (id10)
             ) $self->{innodb}
@@ -1103,7 +1223,7 @@ sub create {
         qq{
             CREATE TABLE loader_test11 (
                 id11 $self->{auto_inc_pk},
-                message VARCHAR(8) DEFAULT 'foo',
+                a_message VARCHAR(8) DEFAULT 'foo',
                 loader_test10 INTEGER $self->{null},
                 FOREIGN KEY (loader_test10) REFERENCES loader_test10 (id10)
             ) $self->{innodb}
@@ -1201,6 +1321,8 @@ sub drop_tables {
         loader_test2
         LOADER_TEST23
         LoAdEr_test24
+        loader_test35
+        loader_test36
     /;
     
     my @tables_auto_inc = (
@@ -1264,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 {};
 
@@ -1291,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}) {