X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F10_09firebird_common.t;h=50b74be6c81427ef608b519254b42f59861b1234;hb=d7e0e0e8e9517098567f1a5637771505476ccbc1;hp=cd1014ec438502923249a733c238ff44f1b8cbdc;hpb=567aa05681cd48788d132c016b357dc485d54f35;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/t/10_09firebird_common.t b/t/10_09firebird_common.t index cd1014e..50b74be 100644 --- a/t/10_09firebird_common.t +++ b/t/10_09firebird_common.t @@ -2,16 +2,31 @@ use strict; use warnings; use Test::More; use Scope::Guard (); +use DBIx::Class::Optional::Dependencies; +use DBIx::Class::Schema::Loader::Utils qw/sigwarn_silencer/; use lib qw(t/lib); use dbixcsl_common_tests; -my $dbd_interbase_dsn = $ENV{DBICTEST_FIREBIRD_DSN} || ''; -my $dbd_interbase_user = $ENV{DBICTEST_FIREBIRD_USER} || ''; -my $dbd_interbase_password = $ENV{DBICTEST_FIREBIRD_PASS} || ''; +my %dsns; +for (qw(FIREBIRD FIREBIRD_ODBC FIREBIRD_INTERBASE)) { + next unless $ENV{"DBICTEST_${_}_DSN"}; -my $odbc_dsn = $ENV{DBICTEST_FIREBIRD_ODBC_DSN} || ''; -my $odbc_user = $ENV{DBICTEST_FIREBIRD_ODBC_USER} || ''; -my $odbc_password = $ENV{DBICTEST_FIREBIRD_ODBC_PASS} || ''; + my $dep_group = lc "rdbms_$_"; + if (!DBIx::Class::Optional::Dependencies->req_ok_for($dep_group)) { + diag 'You need to install ' . DBIx::Class::Optional::Dependencies->req_missing_for($dep_group) + . " to test with $_"; + next; + } + + $dsns{$_}{dsn} = $ENV{"DBICTEST_${_}_DSN"}; + $dsns{$_}{user} = $ENV{"DBICTEST_${_}_USER"}; + $dsns{$_}{password} = $ENV{"DBICTEST_${_}_PASS"}; + $dsns{$_}{connect_info_opts} = { on_connect_call => 'use_softcommit' } + if /\AFIREBIRD(?:_INTERBASE)?\z/; +}; + +plan skip_all => 'You need to set the DBICTEST_FIREBIRD_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_ODBC_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_INTERBASE_DSN, _USER and _PASS environment variables' + unless %dsns; my $schema; @@ -43,19 +58,7 @@ my $tester = dbixcsl_common_tests->new( null => '', preserve_case_mode_is_exclusive => 1, quote_char => '"', - warnings => [ qr/'preserve_case' option/ ], - connect_info => [ ($dbd_interbase_dsn ? { - dsn => $dbd_interbase_dsn, - user => $dbd_interbase_user, - password => $dbd_interbase_password, - connect_info_opts => { on_connect_call => 'use_softcommit' }, - } : ()), - ($odbc_dsn ? { - dsn => $odbc_dsn, - user => $odbc_user, - password => $odbc_password, - } : ()), - ], + connect_info => [ map { $dsns{$_} } sort keys %dsns ], data_types => { # based on the Interbase Data Definition Guide # http://www.ibphoenix.com/downloads/60DataDef.zip @@ -104,48 +107,61 @@ my $tester = dbixcsl_common_tests->new( 'char' => { data_type => 'char', size => 1 }, 'char(11)' => { data_type => 'char', size => 11 }, 'varchar(20)' => { data_type => 'varchar', size => 20 }, + 'char(22) character set unicode_fss' => + => { data_type => 'char(x) character set unicode_fss', size => 22 }, + 'varchar(33) character set unicode_fss' => + => { data_type => 'varchar(x) character set unicode_fss', size => 33 }, # Blob types 'blob' => { data_type => 'blob' }, 'blob sub_type text' => { data_type => 'blob sub_type text' }, + 'blob sub_type text character set unicode_fss' + => { data_type => 'blob sub_type text character set unicode_fss' }, }, extra => { - count => 6, + count => 11, + create => [ + q{ + CREATE TABLE "Firebird_Loader_Test1" ( + "Id" INTEGER NOT NULL PRIMARY KEY, + "Foo" INTEGER DEFAULT 42 + ) + }, + 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 + }, + q{ + CREATE VIEW firebird_loader_test2 AS SELECT * FROM "Firebird_Loader_Test1" + }, + ], + pre_drop_ddl => [ + 'DROP VIEW firebird_loader_test2', + 'DROP TRIGGER "Firebird_Loader_Test1_BI"', + 'DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"', + 'DROP TABLE "Firebird_Loader_Test1"', + ], run => sub { $schema = shift; my ($monikers, $classes, $self) = @_; - cleanup_extra(); - my $dbh = $schema->storage->dbh; # create a mixed case table $dbh->do($_) for ( -q{ - CREATE TABLE "Firebird_Loader_Test1" ( - "Id" INTEGER NOT NULL PRIMARY KEY, - "Foo" INTEGER DEFAULT 42 - ) -}, -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 -}, ); - my $guard = Scope::Guard->new(\&cleanup_extra); - - local $schema->_loader->{preserve_case} = 1; - $schema->_loader->_setup; + local $schema->loader->{preserve_case} = 1; + $schema->loader->_setup; $self->rescan_without_warnings($schema); @@ -162,34 +178,49 @@ q{ is $col_info->{sequence}, 'Gen_Firebird_Loader_Test1_Id', 'correct mixed case sequence name'; is eval { $rsrc->column_info('Foo')->{default_value} }, 42, 'default_value detected for mixed case column'; + + # test that views are marked as such + my $view_source = $schema->resultset($monikers->{firebird_loader_test2})->result_source; + isa_ok $view_source, 'DBIx::Class::ResultSource::View', + 'view result source'; + + like $view_source->view_definition, + qr/\A \s* select\b .* \bfrom \s+ (?-i:"Firebird_Loader_Test1") \s* \z/imsx, + 'view definition'; + + # test the fixed up ->_dbh_type_info_type_name for the ODBC driver + if ($schema->storage->_dbi_connect_info->[0] =~ /:ODBC:/i) { + my %truncated_types = ( + 4 => 'INTEGER', + -9 => 'VARCHAR(x) CHARACTER SET UNICODE_FSS', + -10 => 'BLOB SUB_TYPE TEXT CHARACTER SET UNICODE_FSS', + ); + + for my $type_num (keys %truncated_types) { + is $schema->loader->_dbh_type_info_type_name($type_num), + $truncated_types{$type_num}, + "ODBC ->_dbh_type_info_type_name correct for '$truncated_types{$type_num}'"; + } + } + else { + my $tb = Test::More->builder; + $tb->skip('not testing _dbh_type_info_type_name on DBD::InterBase') for 1..3; + } }, }, ); -if (not ($dbd_interbase_dsn || $odbc_dsn)) { - $tester->skip_tests('You need to set the DBICTEST_FIREBIRD_DSN, _USER and _PASS and/or the DBICTEST_FIREBIRD_ODBC_DSN, _USER and _PASS environment variables'); -} -else { +{ # get rid of stupid warning from InterBase/GetInfo.pm - if ($dbd_interbase_dsn) { - local $SIG{__WARN__} = sub { warn @_ - unless $_[0] =~ m|^Use of uninitialized value in sprintf at \S+DBD/InterBase/GetInfo\.pm line \d+\.$| }; + if ($dsns{FIREBIRD_INTERBASE}) { + local $SIG{__WARN__} = sigwarn_silencer( + qr{^(?:Use of uninitialized value|Argument "[0-9_]+" isn't numeric|Missing argument) in sprintf at \S+DBD/InterBase/GetInfo.pm line \d+\.$} + ); require DBD::InterBase; require DBD::InterBase::GetInfo; } + $tester->run_tests(); } -sub cleanup_extra { - $schema->storage->disconnect; - my $dbh = $schema->storage->dbh; - - foreach my $stmt ( - 'DROP TRIGGER "Firebird_Loader_Test1_BI"', - 'DROP GENERATOR "Gen_Firebird_Loader_Test1_Id"', - 'DROP TABLE "Firebird_Loader_Test1"', - ) { - eval { $dbh->do($stmt) }; - } -} # vim:et sts=4 sw=4 tw=0: