Commit | Line | Data |
70350518 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
0567538f |
7 | |
8 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/}; |
9 | |
70350518 |
10 | plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' . |
2660b14e |
11 | 'Warning: This test drops and creates tables called \'artist\', \'cd\' and \'track\'' |
0567538f |
12 | unless ($dsn && $user && $pass); |
13 | |
286f32b3 |
14 | plan tests => 6; |
0567538f |
15 | |
70fe6d6e |
16 | DBICTest::Schema->compose_connection('OraTest' => $dsn, $user, $pass); |
0567538f |
17 | |
a953d8d9 |
18 | my $dbh = OraTest->schema->storage->dbh; |
0567538f |
19 | |
20 | eval { |
21 | $dbh->do("DROP SEQUENCE artist_seq"); |
22 | $dbh->do("DROP TABLE artist"); |
2660b14e |
23 | $dbh->do("DROP TABLE cd"); |
24 | $dbh->do("DROP TABLE track"); |
0567538f |
25 | }; |
26 | $dbh->do("CREATE SEQUENCE artist_seq START WITH 1 MAXVALUE 999999 MINVALUE 0"); |
27 | $dbh->do("CREATE TABLE artist (artistid NUMBER(12), name VARCHAR(255))"); |
2660b14e |
28 | $dbh->do("CREATE TABLE cd (cdid NUMBER(12), artist NUMBER(12), title VARCHAR(255), year VARCHAR(4))"); |
29 | $dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255))"); |
30 | |
0567538f |
31 | $dbh->do("ALTER TABLE artist ADD (CONSTRAINT artist_pk PRIMARY KEY (artistid))"); |
32 | $dbh->do(qq{ |
33 | CREATE OR REPLACE TRIGGER artist_insert_trg |
34 | BEFORE INSERT ON artist |
35 | FOR EACH ROW |
36 | BEGIN |
37 | IF :new.artistid IS NULL THEN |
38 | SELECT artist_seq.nextval |
39 | INTO :new.artistid |
40 | FROM DUAL; |
41 | END IF; |
42 | END; |
43 | }); |
44 | |
843f8ecd |
45 | OraTest::Artist->load_components('PK::Auto'); |
2660b14e |
46 | OraTest::CD->load_components('PK::Auto::Oracle'); |
47 | OraTest::Track->load_components('PK::Auto::Oracle'); |
0567538f |
48 | |
49 | # test primary key handling |
50 | my $new = OraTest::Artist->create({ name => 'foo' }); |
c8f4b52b |
51 | is($new->artistid, 1, "Oracle Auto-PK worked"); |
0567538f |
52 | |
2660b14e |
53 | # test join with row count ambiguity |
54 | my $cd = OraTest::CD->create({ cdid => 1, artist => 1, title => 'EP C', year => '2003' }); |
55 | my $track = OraTest::Track->create({ trackid => 1, cd => 1, position => 1, title => 'Track1' }); |
56 | my $tjoin = OraTest::Track->search({ 'me.title' => 'Track1'}, |
57 | { join => 'cd', |
58 | rows => 2 } |
59 | ); |
60 | |
61 | is($tjoin->next->title, 'Track1', "ambiguous column ok"); |
62 | |
286f32b3 |
63 | # check count distinct with multiple columns |
64 | my $other_track = OraTest::Track->create({ trackid => 2, cd => 1, position => 1, title => 'Track2' }); |
65 | my $tcount = OraTest::Track->search( |
66 | {}, |
67 | { |
70350518 |
68 | select => [{count => {distinct => ['position', 'title']}}], |
69 | as => ['count'] |
286f32b3 |
70 | } |
71 | ); |
72 | |
73 | is($tcount->next->get_column('count'), 2, "multiple column select distinct ok"); |
2660b14e |
74 | |
0567538f |
75 | # test LIMIT support |
76 | for (1..6) { |
77 | OraTest::Artist->create({ name => 'Artist ' . $_ }); |
78 | } |
79 | my $it = OraTest::Artist->search( {}, |
80 | { rows => 3, |
81 | offset => 2, |
82 | order_by => 'artistid' } |
83 | ); |
84 | is( $it->count, 3, "LIMIT count ok" ); |
85 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
86 | $it->next; |
87 | $it->next; |
88 | is( $it->next, undef, "next past end of resultset ok" ); |
89 | |
90 | # clean up our mess |
91 | $dbh->do("DROP SEQUENCE artist_seq"); |
92 | $dbh->do("DROP TABLE artist"); |
2660b14e |
93 | $dbh->do("DROP TABLE cd"); |
94 | $dbh->do("DROP TABLE track"); |
0567538f |
95 | |