6 use DBIx::Class::Optional::Dependencies ();
10 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_informix')
11 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_informix');
13 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_INFORMIX_${_}" } qw/DSN USER PASS/};
15 #warn "$dsn $user $pass";
17 plan skip_all => 'Set $ENV{DBICTEST_INFORMIX_DSN}, _USER and _PASS to run this test'
20 my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
24 my $dbh = $schema->storage->dbh;
26 eval { $dbh->do("DROP TABLE artist") };
27 $dbh->do("CREATE TABLE artist (artistid SERIAL, name VARCHAR(255), charfield CHAR(10), rank INTEGER DEFAULT 13);");
28 eval { $dbh->do("DROP TABLE cd") };
39 eval { $dbh->do("DROP TABLE track") };
43 cd int REFERENCES cd(cdid),
52 my $ars = $schema->resultset('Artist');
53 is ( $ars->count, 0, 'No rows at first' );
55 # test primary key handling
56 my $new = $ars->create({ name => 'foo' });
57 ok($new->artistid, "Auto-PK worked");
59 # test explicit key spec
60 $new = $ars->create ({ name => 'bar', artistid => 66 });
61 is($new->artistid, 66, 'Explicit PK worked');
62 $new->discard_changes;
63 is($new->artistid, 66, 'Explicit PK assigned');
69 push @pop, { name => "Artist_$_" };
71 $ars->populate (\@pop);
74 # test populate with explicit key
78 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
80 $ars->populate (\@pop);
83 # count what we did so far
84 is ($ars->count, 6, 'Simple count works');
87 my $lim = $ars->search( {},
91 order_by => 'artistid'
94 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
95 is( $lim->all, 2, 'Number of ->all objects matches count' );
99 is( $lim->next->artistid, 101, "iterator->next ok" );
100 is( $lim->next->artistid, 102, "iterator->next ok" );
101 is( $lim->next, undef, "next past end of resultset ok" );
105 $schema->txn_do(sub {
107 $schema->txn_do(sub {
108 $ars->create({ name => 'in_savepoint' });
109 die "rolling back savepoint";
112 ok ((not $ars->search({ name => 'in_savepoint' })->first),
113 'savepoint rolled back');
114 $ars->create({ name => 'in_outer_txn' });
115 die "rolling back outer txn";
117 } qr/rolling back outer txn/,
118 'correct exception for rollback';
120 ok ((not $ars->search({ name => 'in_outer_txn' })->first),
121 'outer txn rolled back');
123 ######## test with_deferred_fk_checks
125 $schema->storage->with_deferred_fk_checks(sub {
126 $schema->resultset('Track')->create({
127 trackid => 999, cd => 999, position => 1, title => 'deferred FK track'
129 $schema->resultset('CD')->create({
130 artist => 1, cdid => 999, year => '2003', title => 'deferred FK cd'
133 } 'with_deferred_fk_checks code survived';
135 is eval { $schema->resultset('Track')->find(999)->title }, 'deferred FK track',
136 'code in with_deferred_fk_checks worked';
139 $schema->resultset('Track')->create({
140 trackid => 1, cd => 9999, position => 1, title => 'Track1'
142 } qr/constraint/i, 'with_deferred_fk_checks is off';
148 my $dbh = eval { $schema->storage->_dbh };
149 $dbh->do("DROP TABLE artist") if $dbh;