9 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_INFORMIX_${_}" } qw/DSN USER PASS/};
11 #warn "$dsn $user $pass";
13 plan skip_all => 'Set $ENV{DBICTEST_INFORMIX_DSN}, _USER and _PASS to run this test'
16 my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
20 my $dbh = $schema->storage->dbh;
22 eval { $dbh->do("DROP TABLE artist") };
23 $dbh->do("CREATE TABLE artist (artistid SERIAL, name VARCHAR(255), charfield CHAR(10), rank INTEGER DEFAULT 13);");
24 eval { $dbh->do("DROP TABLE cd") };
35 eval { $dbh->do("DROP TABLE track") };
39 cd int REFERENCES cd(cdid),
48 my $ars = $schema->resultset('Artist');
49 is ( $ars->count, 0, 'No rows at first' );
51 # test primary key handling
52 my $new = $ars->create({ name => 'foo' });
53 ok($new->artistid, "Auto-PK worked");
55 # test explicit key spec
56 $new = $ars->create ({ name => 'bar', artistid => 66 });
57 is($new->artistid, 66, 'Explicit PK worked');
58 $new->discard_changes;
59 is($new->artistid, 66, 'Explicit PK assigned');
65 push @pop, { name => "Artist_$_" };
67 $ars->populate (\@pop);
70 # test populate with explicit key
74 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
76 $ars->populate (\@pop);
79 # count what we did so far
80 is ($ars->count, 6, 'Simple count works');
83 my $lim = $ars->search( {},
87 order_by => 'artistid'
90 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
91 is( $lim->all, 2, 'Number of ->all objects matches count' );
95 is( $lim->next->artistid, 101, "iterator->next ok" );
96 is( $lim->next->artistid, 102, "iterator->next ok" );
97 is( $lim->next, undef, "next past end of resultset ok" );
101 $schema->txn_do(sub {
103 $schema->txn_do(sub {
104 $ars->create({ name => 'in_savepoint' });
105 die "rolling back savepoint";
108 ok ((not $ars->search({ name => 'in_savepoint' })->first),
109 'savepoint rolled back');
110 $ars->create({ name => 'in_outer_txn' });
111 die "rolling back outer txn";
113 } qr/rolling back outer txn/,
114 'correct exception for rollback';
116 ok ((not $ars->search({ name => 'in_outer_txn' })->first),
117 'outer txn rolled back');
119 ######## test with_deferred_fk_checks
121 $schema->storage->with_deferred_fk_checks(sub {
122 $schema->resultset('Track')->create({
123 trackid => 999, cd => 999, position => 1, title => 'deferred FK track'
125 $schema->resultset('CD')->create({
126 artist => 1, cdid => 999, year => '2003', title => 'deferred FK cd'
129 } 'with_deferred_fk_checks code survived';
131 is eval { $schema->resultset('Track')->find(999)->title }, 'deferred FK track',
132 'code in with_deferred_fk_checks worked';
135 $schema->resultset('Track')->create({
136 trackid => 1, cd => 9999, position => 1, title => 'Track1'
138 } qr/constraint/i, 'with_deferred_fk_checks is off';
144 my $dbh = eval { $schema->storage->_dbh };
145 $dbh->do("DROP TABLE artist") if $dbh;