14 my $schema = DBICTest->init_schema(auto_savepoint => 1);
16 my $ars = $schema->resultset('Artist');
18 # test two-phase commit and inner transaction rollback from nested transactions
20 $ars->create({ name => 'in_outer_transaction' });
22 $ars->create({ name => 'in_inner_transaction' });
24 ok($ars->search({ name => 'in_inner_transaction' })->first,
25 'commit from inner transaction visible in outer transaction');
28 $ars->create({ name => 'in_inner_transaction_rolling_back' });
29 die 'rolling back inner transaction';
31 } qr/rolling back inner transaction/, 'inner transaction rollback executed';
32 $ars->create({ name => 'in_outer_transaction2' });
35 ok($ars->search({ name => 'in_outer_transaction' })->first,
36 'commit from outer transaction');
37 ok($ars->search({ name => 'in_outer_transaction2' })->first,
38 'second commit from outer transaction');
39 ok($ars->search({ name => 'in_inner_transaction' })->first,
40 'commit from inner transaction');
41 is $ars->search({ name => 'in_inner_transaction_rolling_back' })->first,
43 'rollback from inner transaction';
46 my $schema = DBICTest->init_schema();
48 # make sure the side-effects of RT#67581 do not result in data loss
50 warnings_exist { $row = $schema->resultset('Artist')->create ({ name => 'alpha rank', rank => 'abc' }) }
51 [qr/Non-numeric value supplied for column 'rank' despite the numeric datatype/],
52 'proper warning on string insertion into an numeric column'
54 $row->discard_changes;
55 is ($row->rank, 'abc', 'proper rank inserted into database');
57 # and make sure we do not lose actual bigints
59 package DBICTest::BigIntArtist;
60 use base 'DBICTest::Schema::Artist';
61 __PACKAGE__->table('artist');
62 __PACKAGE__->add_column(bigint => { data_type => 'bigint' });
64 $schema->register_class(BigIntArtist => 'DBICTest::BigIntArtist');
65 $schema->storage->dbh_do(sub {
66 $_[1]->do('ALTER TABLE artist ADD COLUMN bigint BIGINT');
69 # test upper/lower boundaries for sqlite and some values inbetween
70 # range is -(2**63) .. 2**63 - 1
87 $row = $schema->resultset('BigIntArtist')->create({ bigint => $bi });
88 is ($row->bigint, $bi, "value in object correct ($bi)");
91 local $TODO = 'This perl does not seem to have 64bit int support - DBI roundtrip of large int will fail'
92 unless $Config{ivsize} >= 8;
94 $row->discard_changes;
95 is ($row->bigint, $bi, "value in database correct ($bi)");
99 $schema->storage->dbh_do(sub {
102 my ($fk_enabled) = $dbh->selectrow_array('PRAGMA foreign_keys');
103 if (! defined $fk_enabled) {
105 skip 'SQLite not compiled with foreign key enforcement', 2;
108 $schema->storage->connect_call_use_foreign_keys;
111 $schema->storage->with_deferred_fk_checks(sub {
112 $schema->resultset('Track')->create({
113 trackid => 999, cd => 999, position => 1, title => 'deferred FK track'
115 $schema->resultset('CD')->create({
116 artist => 1, cdid => 999, year => '2003', title => 'deferred FK cd'
119 } 'with_deferred_fk_checks code survived';
121 is eval { $schema->resultset('Track')->find(999)->title }, 'deferred FK track',
122 'code in with_deferred_fk_checks worked';
125 $schema->resultset('Track')->create({
126 trackid => 1, cd => 9999, position => 1, title => 'Track1'
128 } qr/constraint/i, 'with_deferred_fk_checks is off';
130 ok $dbh->selectrow_array('PRAGMA foreign_keys'), 'foreign key checks reenabled';