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,
$self->{_created} = 1;
+ my $make_auto_inc = $self->{auto_inc_cb} || sub {};
my @statements = (
qq{
CREATE TABLE loader_test1 (
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') },
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') },
loader_test11 INTEGER
) $self->{innodb}
},
+ $make_auto_inc->(qw/loader_test10 id10/),
qq{
CREATE TABLE loader_test11 (
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) } .
LOADER_TEST23
LoAdEr_test24
/;
+
+ my @tables_auto_inc = (
+ [ qw/loader_test1 id/ ],
+ [ qw/loader_test2 id/ ],
+ );
my @tables_reltests = qw/
loader_test4
loader_test11
loader_test10
/;
+
+ my @tables_advanced_auto_inc = (
+ [ qw/loader_test10 id10/ ],
+ [ qw/loader_test11 id11/ ],
+ );
my @tables_inline_rels = qw/
loader_test13
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) {
$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);
$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;
}