Commit | Line | Data |
66afce69 |
1 | package make_dbictest_db2; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use DBI; |
6 | |
7 | eval { require DBD::SQLite }; |
8 | my $class = $@ ? 'SQLite2' : 'SQLite'; |
9 | |
10 | my $fn = './t/dbictest.db'; |
11 | |
12 | unlink($fn); |
13 | our $dsn = "dbi:$class:dbname=$fn"; |
14 | my $dbh = DBI->connect($dsn); |
15 | |
16 | $dbh->do($_) for ( |
17 | q|CREATE TABLE foos ( |
18 | fooid INTEGER PRIMARY KEY, |
19 | footext TEXT |
20 | )|, |
21 | q|CREATE TABLE bar ( |
22 | barid INTEGER PRIMARY KEY, |
b24cb177 |
23 | foo_id INTEGER NOT NULL REFERENCES foos (fooid) |
66afce69 |
24 | )|, |
a0e0a56a |
25 | q|CREATE TABLE bazs ( |
66afce69 |
26 | bazid INTEGER PRIMARY KEY, |
27 | baz_num INTEGER NOT NULL UNIQUE |
28 | )|, |
a0e0a56a |
29 | q|CREATE TABLE quuxs ( |
66afce69 |
30 | quuxid INTEGER PRIMARY KEY, |
a0e0a56a |
31 | baz_id INTEGER NOT NULL UNIQUE, |
32 | FOREIGN KEY (baz_id) REFERENCES bazs (baz_num) |
66afce69 |
33 | )|, |
a0e0a56a |
34 | q|INSERT INTO foos VALUES (1,'Foos text for number 1')|, |
35 | q|INSERT INTO foos VALUES (2,'Foos record associated with the Bar with barid 3')|, |
36 | q|INSERT INTO foos VALUES (3,'Foos text for number 3')|, |
37 | q|INSERT INTO foos VALUES (4,'Foos text for number 4')|, |
66afce69 |
38 | q|INSERT INTO bar VALUES (1,4)|, |
39 | q|INSERT INTO bar VALUES (2,3)|, |
40 | q|INSERT INTO bar VALUES (3,2)|, |
41 | q|INSERT INTO bar VALUES (4,1)|, |
a0e0a56a |
42 | q|INSERT INTO bazs VALUES (1,20)|, |
43 | q|INSERT INTO bazs VALUES (2,19)|, |
44 | q|INSERT INTO quuxs VALUES (1,20)|, |
45 | q|INSERT INTO quuxs VALUES (2,19)|, |
66afce69 |
46 | ); |
47 | |
48 | END { unlink($fn); } |
49 | |
50 | 1; |