Added initial SQL::Abstract::Limit support and tests
[dbsrgits/DBIx-Class-Historic.git] / t / 13oracle.t
1 use lib qw(lib t/lib);
2 use DBICTest::Schema;
3
4 use Test::More;
5
6 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
7
8 plan skip_all, 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' .
9   'Warning: This test drops and creates a table called \'artist\''
10   unless ($dsn && $user && $pass);
11
12 plan tests => 1;
13
14 DBICTest::Schema->compose_connection('OraTest' => $dsn, $user, $pass);
15
16 my $dbh = OraTest::Artist->storage->dbh;
17
18 eval {
19   $dbh->do("DROP SEQUENCE artist_seq");
20   $dbh->do("DROP TABLE artist");
21 };
22 $dbh->do("CREATE SEQUENCE artist_seq START WITH 1 MAXVALUE 999999 MINVALUE 0");
23 $dbh->do("CREATE TABLE artist (artistid NUMBER(12), name VARCHAR(255))");
24 $dbh->do("ALTER TABLE artist ADD (CONSTRAINT artist_pk PRIMARY KEY (artistid))");
25 $dbh->do(qq{
26   CREATE OR REPLACE TRIGGER artist_insert_trg
27   BEFORE INSERT ON artist
28   FOR EACH ROW
29   BEGIN
30     IF :new.artistid IS NULL THEN
31       SELECT artist_seq.nextval
32       INTO :new.artistid
33       FROM DUAL;
34     END IF;
35   END;
36 });
37
38 OraTest::Artist->load_components('PK::Auto::Oracle');
39
40 my $new = OraTest::Artist->create({ name => 'foo' });
41
42 ok($new->artistid, "Oracle Auto-PK worked");
43
44 $dbh->do("DROP SEQUENCE artist_seq");
45 $dbh->do("DROP TABLE artist");
46
47 1;