From: Dagfinn Ilmari Mannsåker Date: Sat, 2 Feb 2008 21:27:07 +0000 (+0000) Subject: Fix auto-inc column cration for the Oracle tests X-Git-Tag: 0.04006~22 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c1ac681dbbeebed9341c71bc0999149f514f094b;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Fix auto-inc column cration for the Oracle tests --- diff --git a/Changes b/Changes index f662a1b..dbcb64f 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader Not yet released - Add support for load_namespaces-style class layout. - Fix test skip count for main skip_rels block + - Fix auto-inc column cration for the Oracle tests 0.04004 Thu Nov 15, 2007 - Fix Win32 test skip counts for good (RT #30568, Kenichi Ishigaki) diff --git a/t/14ora_common.t b/t/14ora_common.t index ad63787..2cd05b5 100644 --- a/t/14ora_common.t +++ b/t/14ora_common.t @@ -8,7 +8,25 @@ my $password = $ENV{DBICTEST_ORA_PASS} || ''; my $tester = dbixcsl_common_tests->new( vendor => 'Oracle', - auto_inc_pk => 'SERIAL NOT NULL PRIMARY KEY', + auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY', + auto_inc_cb => sub { + my ($table, $col) = @_; + return ( + qq{ CREATE SEQUENCE ${table}_${col}_seq START WITH 1 INCREMENT BY 1}, + qq{ + CREATE OR REPLACE TRIGGER ${table}_${col}_trigger + BEFORE INSERT ON ${table} + FOR EACH ROW + BEGIN + SELECT ${table}_${col}_seq.nextval INTO :NEW.${col} FROM dual; + END; + } + ); + }, + auto_inc_drop_cb => sub { + my ($table, $col) = @_; + return qq{ DROP SEQUENCE ${table}_${col}_seq }; + }, dsn => $dsn, user => $user, password => $password, diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 7ad4eb9..75d6090 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -526,6 +526,7 @@ sub create { $self->{_created} = 1; + my $make_auto_inc = $self->{auto_inc_cb} || sub {}; my @statements = ( qq{ CREATE TABLE loader_test1 ( @@ -533,6 +534,7 @@ sub create { dat VARCHAR(32) NOT NULL UNIQUE ) $self->{innodb} }, + $make_auto_inc->(qw/loader_test1 id/), q{ INSERT INTO loader_test1 (dat) VALUES('foo') }, q{ INSERT INTO loader_test1 (dat) VALUES('bar') }, @@ -546,6 +548,7 @@ sub create { UNIQUE (dat2, dat) ) $self->{innodb} }, + $make_auto_inc->(qw/loader_test2 id/), q{ INSERT INTO loader_test2 (dat, dat2) VALUES('aaa', 'zzz') }, q{ INSERT INTO loader_test2 (dat, dat2) VALUES('bbb', 'yyy') }, @@ -768,6 +771,7 @@ sub create { loader_test11 INTEGER ) $self->{innodb} }, + $make_auto_inc->(qw/loader_test10 id10/), qq{ CREATE TABLE loader_test11 ( @@ -777,6 +781,7 @@ sub create { FOREIGN KEY (loader_test10) REFERENCES loader_test10 (id10) ) $self->{innodb} }, + $make_auto_inc->(qw/loader_test11 id11/), (q{ ALTER TABLE loader_test10 ADD CONSTRAINT } . q{ loader_test11_fk FOREIGN KEY (loader_test11) } . @@ -866,6 +871,11 @@ sub drop_tables { LOADER_TEST23 LoAdEr_test24 /; + + my @tables_auto_inc = ( + [ qw/loader_test1 id/ ], + [ qw/loader_test2 id/ ], + ); my @tables_reltests = qw/ loader_test4 @@ -890,6 +900,11 @@ sub drop_tables { loader_test11 loader_test10 /; + + my @tables_advanced_auto_inc = ( + [ qw/loader_test10 id10/ ], + [ qw/loader_test11 id11/ ], + ); my @tables_inline_rels = qw/ loader_test13 @@ -904,13 +919,15 @@ sub drop_tables { my @tables_rescan = qw/ loader_test30 /; my $drop_fk_mysql = - q{ALTER TABLE loader_test10 DROP FOREIGN KEY loader_test11_fk;}; + q{ALTER TABLE loader_test10 DROP FOREIGN KEY loader_test11_fk}; my $drop_fk = - q{ALTER TABLE loader_test10 DROP CONSTRAINT loader_test11_fk;}; + q{ALTER TABLE loader_test10 DROP CONSTRAINT loader_test11_fk}; my $dbh = $self->dbconnect(0); + my $drop_auto_inc = $self->{auto_inc_drop_cb} || sub {}; + unless($self->{skip_rels}) { $dbh->do("DROP TABLE $_") for (@tables_reltests); unless($self->{vendor} =~ /sqlite/i) { @@ -921,6 +938,7 @@ sub drop_tables { $dbh->do($drop_fk); } $dbh->do("DROP TABLE $_") for (@tables_advanced); + $dbh->do($_) for map { $drop_auto_inc->(@$_) } @tables_advanced_auto_inc; } unless($self->{no_inline_rels}) { $dbh->do("DROP TABLE $_") for (@tables_inline_rels); @@ -931,6 +949,7 @@ sub drop_tables { $dbh->do("DROP TABLE $_") for (@tables_rescan); } $dbh->do("DROP TABLE $_") for (@tables); + $dbh->do($_) for map { $drop_auto_inc->(@$_) } @tables_auto_inc; $dbh->disconnect; }