Fix serious DBD::SQLite numeric datatype mismatch regression
[dbsrgits/DBIx-Class.git] / t / 752sqlite.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Test::Exception;
6 use Test::Warn;
7 use lib qw(t/lib);
8 use DBICTest;
9
10 my $schema = DBICTest->init_schema(auto_savepoint => 1);
11
12 my $ars = $schema->resultset('Artist');
13
14 # test two-phase commit and inner transaction rollback from nested transactions
15 $schema->txn_do(sub {
16   $ars->create({ name => 'in_outer_transaction' });
17   $schema->txn_do(sub {
18     $ars->create({ name => 'in_inner_transaction' });
19   });
20   ok($ars->search({ name => 'in_inner_transaction' })->first,
21     'commit from inner transaction visible in outer transaction');
22   throws_ok {
23     $schema->txn_do(sub {
24       $ars->create({ name => 'in_inner_transaction_rolling_back' });
25       die 'rolling back inner transaction';
26     });
27   } qr/rolling back inner transaction/, 'inner transaction rollback executed';
28   $ars->create({ name => 'in_outer_transaction2' });
29 });
30
31 ok($ars->search({ name => 'in_outer_transaction' })->first,
32   'commit from outer transaction');
33 ok($ars->search({ name => 'in_outer_transaction2' })->first,
34   'second commit from outer transaction');
35 ok($ars->search({ name => 'in_inner_transaction' })->first,
36   'commit from inner transaction');
37 is $ars->search({ name => 'in_inner_transaction_rolling_back' })->first,
38   undef,
39   'rollback from inner transaction';
40
41 # make sure the side-effects of RT#67581 do not result in data loss
42 my $row;
43 warnings_exist { $row = $ars->create ({ name => 'alpha rank', rank => 'abc' }) }
44   [qr/Non-numeric value supplied for column 'rank' despite the numeric datatype/],
45   'proper warning on string insertion into an numeric column'
46 ;
47 $row->discard_changes;
48 is ($row->rank, 'abc', 'proper rank inserted into database');
49
50 done_testing;
51
52 # vim:sts=2 sw=2: