1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_informix';
11 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_INFORMIX_${_}" } qw/DSN USER PASS/};
13 my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
17 my $dbh = $schema->storage->dbh;
19 eval { $dbh->do("DROP TABLE artist") };
20 $dbh->do("CREATE TABLE artist (artistid SERIAL, name VARCHAR(255), charfield CHAR(10), rank INTEGER DEFAULT 13);");
21 eval { $dbh->do("DROP TABLE cd") };
32 eval { $dbh->do("DROP TABLE track") };
36 cd int REFERENCES cd(cdid),
45 my $ars = $schema->resultset('Artist');
46 is ( $ars->count, 0, 'No rows at first' );
48 # test primary key handling
49 my $new = $ars->create({ name => 'foo' });
50 ok($new->artistid, "Auto-PK worked");
52 # test explicit key spec
53 $new = $ars->create ({ name => 'bar', artistid => 66 });
54 is($new->artistid, 66, 'Explicit PK worked');
55 $new->discard_changes;
56 is($new->artistid, 66, 'Explicit PK assigned');
62 push @pop, { name => "Artist_$_" };
64 $ars->populate (\@pop);
67 # test populate with explicit key
71 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
73 $ars->populate (\@pop);
76 # count what we did so far
77 is ($ars->count, 6, 'Simple count works');
80 my $lim = $ars->search( {},
84 order_by => 'artistid'
87 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
88 is( $lim->all, 2, 'Number of ->all objects matches count' );
92 is( $lim->next->artistid, 101, "iterator->next ok" );
93 is( $lim->next->artistid, 102, "iterator->next ok" );
94 is( $lim->next, undef, "next past end of resultset ok" );
100 $schema->txn_do(sub {
101 $ars->create({ name => 'in_savepoint' });
102 die "rolling back savepoint";
105 ok ((not $ars->search({ name => 'in_savepoint' })->first),
106 'savepoint rolled back');
107 $ars->create({ name => 'in_outer_txn' });
108 die "rolling back outer txn";
110 } qr/rolling back outer txn/,
111 'correct exception for rollback';
113 ok ((not $ars->search({ name => 'in_outer_txn' })->first),
114 'outer txn rolled back');
116 ######## test with_deferred_fk_checks
118 $schema->storage->with_deferred_fk_checks(sub {
119 $schema->resultset('Track')->create({
120 trackid => 999, cd => 999, position => 1, title => 'deferred FK track'
122 $schema->resultset('CD')->create({
123 artist => 1, cdid => 999, year => '2003', title => 'deferred FK cd'
126 } 'with_deferred_fk_checks code survived';
128 is eval { $schema->resultset('Track')->find(999)->title }, 'deferred FK track',
129 'code in with_deferred_fk_checks worked';
132 $schema->resultset('Track')->create({
133 trackid => 1, cd => 9999, position => 1, title => 'Track1'
135 } qr/constraint/i, 'with_deferred_fk_checks is off';
141 my $dbh = eval { $schema->storage->_dbh };
142 $dbh->do("DROP TABLE artist") if $dbh;