1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_informix';
12 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_INFORMIX_${_}" } qw/DSN USER PASS/};
14 my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
18 my $dbh = $schema->storage->dbh;
20 eval { $dbh->do("DROP TABLE artist") };
21 $dbh->do("CREATE TABLE artist (artistid SERIAL, name VARCHAR(255), charfield CHAR(10), rank INTEGER DEFAULT 13);");
22 eval { $dbh->do("DROP TABLE cd") };
33 eval { $dbh->do("DROP TABLE track") };
37 cd int REFERENCES cd(cdid),
46 my $ars = $schema->resultset('Artist');
47 is ( $ars->count, 0, 'No rows at first' );
49 # test primary key handling
50 my $new = $ars->create({ name => 'foo' });
51 ok($new->artistid, "Auto-PK worked");
53 # test explicit key spec
54 $new = $ars->create ({ name => 'bar', artistid => 66 });
55 is($new->artistid, 66, 'Explicit PK worked');
56 $new->discard_changes;
57 is($new->artistid, 66, 'Explicit PK assigned');
63 push @pop, { name => "Artist_$_" };
65 $ars->populate (\@pop);
68 # test populate with explicit key
72 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
74 $ars->populate (\@pop);
77 # count what we did so far
78 is ($ars->count, 6, 'Simple count works');
81 my $lim = $ars->search( {},
85 order_by => 'artistid'
88 is( $lim->count, 2, 'ROWS+OFFSET count ok' );
89 is( $lim->all, 2, 'Number of ->all objects matches count' );
93 is( $lim->next->artistid, 101, "iterator->next ok" );
94 is( $lim->next->artistid, 102, "iterator->next ok" );
95 is( $lim->next, undef, "next past end of resultset ok" );
101 $schema->txn_do(sub {
102 $ars->create({ name => 'in_savepoint' });
103 die "rolling back savepoint";
106 ok ((not $ars->search({ name => 'in_savepoint' })->first),
107 'savepoint rolled back');
108 $ars->create({ name => 'in_outer_txn' });
109 die "rolling back outer txn";
111 } qr/rolling back outer txn/,
112 'correct exception for rollback';
114 ok ((not $ars->search({ name => 'in_outer_txn' })->first),
115 'outer txn rolled back');
117 ######## test with_deferred_fk_checks
119 $schema->storage->with_deferred_fk_checks(sub {
120 $schema->resultset('Track')->create({
121 trackid => 999, cd => 999, position => 1, title => 'deferred FK track'
123 $schema->resultset('CD')->create({
124 artist => 1, cdid => 999, year => '2003', title => 'deferred FK cd'
127 } 'with_deferred_fk_checks code survived';
129 is eval { $schema->resultset('Track')->find(999)->title }, 'deferred FK track',
130 'code in with_deferred_fk_checks worked';
133 $schema->resultset('Track')->create({
134 trackid => 1, cd => 9999, position => 1, title => 'Track1'
136 } qr/constraint/i, 'with_deferred_fk_checks is off';
142 my $dbh = eval { $schema->storage->_dbh };
143 $dbh->do("DROP TABLE artist") if $dbh;