From: Johannes Plunien Date: Wed, 7 Nov 2007 17:20:53 +0000 (+0000) Subject: fixed sequence auto nextval tests X-Git-Tag: v0.08240~533^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=39b8d119b31781e2a87f07abf54501a2695333fe;p=dbsrgits%2FDBIx-Class.git fixed sequence auto nextval tests --- diff --git a/t/72pg.t b/t/72pg.t index 7b99451..c517600 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -27,7 +27,7 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/}; plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test' . ' (note: creates and drops tables named artist and casecheck!)' unless ($dsn && $user); -plan tests => 16; +plan tests => 32; DBICTest::Schema->load_classes( 'Casecheck' ); my $schema = DBICTest::Schema->connect($dsn, $user, $pass); @@ -46,8 +46,13 @@ SKIP: { my $dbh = $schema->storage->dbh; $schema->source("Artist")->name("testschema.artist"); +$schema->source("SequenceTest")->name("testschema.sequence_test"); $dbh->do("CREATE SCHEMA testschema;"); $dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));"); +$dbh->do("CREATE TABLE testschema.sequence_test (pkid1 integer, pkid2 integer, nonpkid integer, name VARCHAR(100), CONSTRAINT pk PRIMARY KEY(pkid1, pkid2));"); +$dbh->do("CREATE SEQUENCE pkid1_seq START 1 MAXVALUE 999999 MINVALUE 0"); +$dbh->do("CREATE SEQUENCE pkid2_seq START 10 MAXVALUE 999999 MINVALUE 0"); +$dbh->do("CREATE SEQUENCE nonpkid_seq START 20 MAXVALUE 999999 MINVALUE 0"); ok ( $dbh->do('CREATE TABLE testschema.casecheck (id serial PRIMARY KEY, "name" VARCHAR(1), "NAME" VARCHAR(2), "UC_NAME" VARCHAR(3));'), 'Creation of casecheck table'); # This is in Core now, but it's here just to test that it doesn't break @@ -176,10 +181,24 @@ SKIP: { }); } +# test auto increment using sequences WITHOUT triggers +for (1..5) { + my $st = $schema->resultset('SequenceTest')->create({ name => 'foo' }); + is($st->pkid1, $_, "Oracle Auto-PK without trigger: First primary key"); + is($st->pkid2, $_ + 9, "Oracle Auto-PK without trigger: Second primary key"); + is($st->nonpkid, $_ + 19, "Oracle Auto-PK without trigger: Non-primary key"); +} +my $st = $schema->resultset('SequenceTest')->create({ name => 'foo', pkid1 => 55 }); +is($st->pkid1, 55, "Oracle Auto-PK without trigger: First primary key set manually"); + END { if($dbh) { $dbh->do("DROP TABLE testschema.artist;"); $dbh->do("DROP TABLE testschema.casecheck;"); + $dbh->do("DROP TABLE testschema.sequence_test;"); + $dbh->do("DROP SEQUENCE pkid1_seq"); + $dbh->do("DROP SEQUENCE pkid2_seq"); + $dbh->do("DROP SEQUENCE nonpkid_seq"); $dbh->do("DROP SCHEMA testschema;"); } } diff --git a/t/73oracle.t b/t/73oracle.t index 4570d70..94f435e 100644 --- a/t/73oracle.t +++ b/t/73oracle.t @@ -8,10 +8,11 @@ use DBICTest; my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/}; plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' . - 'Warning: This test drops and creates tables called \'artist\', \'cd\' and \'track\'' + 'Warning: This test drops and creates tables called \'artist\', \'cd\', \'track\' and \'sequence_test\''. + ' as well as following sequences: \'pkid1_seq\', \'pkid2_seq\' and \'nonpkid_seq\'' unless ($dsn && $user && $pass); -plan tests => 10; +plan tests => 23; my $schema = DBICTest::Schema->connect($dsn, $user, $pass); @@ -19,25 +20,25 @@ my $dbh = $schema->storage->dbh; eval { $dbh->do("DROP SEQUENCE artist_seq"); - $dbh->do("DROP SEQUENCE artist_oracle_seq"); - $dbh->do("DROP SEQUENCE artist_oracle_otherid_seq"); - $dbh->do("DROP SEQUENCE artist_oracle_nonpriid_seq"); + $dbh->do("DROP SEQUENCE pkid1_seq"); + $dbh->do("DROP SEQUENCE pkid2_seq"); + $dbh->do("DROP SEQUENCE nonpkid_seq"); $dbh->do("DROP TABLE artist"); - $dbh->do("DROP TABLE artist_oracle"); + $dbh->do("DROP TABLE sequence_test"); $dbh->do("DROP TABLE cd"); $dbh->do("DROP TABLE track"); }; $dbh->do("CREATE SEQUENCE artist_seq START WITH 1 MAXVALUE 999999 MINVALUE 0"); -$dbh->do("CREATE SEQUENCE artist_oracle_seq START WITH 1 MAXVALUE 999999 MINVALUE 0"); -$dbh->do("CREATE SEQUENCE artist_oracle_otherid_seq START WITH 10 MAXVALUE 999999 MINVALUE 0"); -$dbh->do("CREATE SEQUENCE artist_oracle_nonpriid_seq START WITH 20 MAXVALUE 999999 MINVALUE 0"); +$dbh->do("CREATE SEQUENCE pkid1_seq START WITH 1 MAXVALUE 999999 MINVALUE 0"); +$dbh->do("CREATE SEQUENCE pkid2_seq START WITH 10 MAXVALUE 999999 MINVALUE 0"); +$dbh->do("CREATE SEQUENCE nonpkid_seq START WITH 20 MAXVALUE 999999 MINVALUE 0"); $dbh->do("CREATE TABLE artist (artistid NUMBER(12), name VARCHAR(255))"); -$dbh->do("CREATE TABLE artist_oracle (artistid NUMBER(12), otherid NUMBER(12), nonpriid NUMBER(12), name VARCHAR(255))"); +$dbh->do("CREATE TABLE sequence_test (pkid1 NUMBER(12), pkid2 NUMBER(12), nonpkid NUMBER(12), name VARCHAR(255))"); $dbh->do("CREATE TABLE cd (cdid NUMBER(12), artist NUMBER(12), title VARCHAR(255), year VARCHAR(4))"); $dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE)"); $dbh->do("ALTER TABLE artist ADD (CONSTRAINT artist_pk PRIMARY KEY (artistid))"); -$dbh->do("ALTER TABLE artist_oracle ADD (CONSTRAINT artist_oracle_pk PRIMARY KEY (artistid))"); +$dbh->do("ALTER TABLE sequence_test ADD (CONSTRAINT sequence_test_constraint PRIMARY KEY (pkid1, pkid2))"); $dbh->do(qq{ CREATE OR REPLACE TRIGGER artist_insert_trg BEFORE INSERT ON artist @@ -105,21 +106,24 @@ is( $it->next, undef, "next past end of resultset ok" ); } # test auto increment using sequences WITHOUT triggers -$new = $schema->resultset('ArtistOracle')->create({ name => 'foo' }); -is($new->artistid, 1, "Oracle Auto-PK without trigger: First primary key"); -is($new->otherid, 10, "Oracle Auto-PK without trigger: Second primary key"); -is($new->nonpriid, 20, "Oracle Auto-PK without trigger: Non-primary key"); - +for (1..5) { + my $st = $schema->resultset('SequenceTest')->create({ name => 'foo' }); + is($st->pkid1, $_, "Oracle Auto-PK without trigger: First primary key"); + is($st->pkid2, $_ + 9, "Oracle Auto-PK without trigger: Second primary key"); + is($st->nonpkid, $_ + 19, "Oracle Auto-PK without trigger: Non-primary key"); +} +my $st = $schema->resultset('SequenceTest')->create({ name => 'foo', pkid1 => 55 }); +is($st->pkid1, 55, "Oracle Auto-PK without trigger: First primary key set manually"); # clean up our mess END { if($dbh) { $dbh->do("DROP SEQUENCE artist_seq"); - $dbh->do("DROP SEQUENCE artist_oracle_seq"); - $dbh->do("DROP SEQUENCE artist_oracle_otherid_seq"); - $dbh->do("DROP SEQUENCE artist_oracle_nonpriid_seq"); + $dbh->do("DROP SEQUENCE pkid1_seq"); + $dbh->do("DROP SEQUENCE pkid2_seq"); + $dbh->do("DROP SEQUENCE nonpkid_seq"); $dbh->do("DROP TABLE artist"); - $dbh->do("DROP TABLE artist_oracle"); + $dbh->do("DROP TABLE sequence_test"); $dbh->do("DROP TABLE cd"); $dbh->do("DROP TABLE track"); }