I think we are done here
[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 Config;
8
9 use lib qw(t/lib);
10 use DBICTest;
11
12 # savepoints test
13 {
14   my $schema = DBICTest->init_schema(auto_savepoint => 1);
15
16   my $ars = $schema->resultset('Artist');
17
18   # test two-phase commit and inner transaction rollback from nested transactions
19   $schema->txn_do(sub {
20     $ars->create({ name => 'in_outer_transaction' });
21     $schema->txn_do(sub {
22       $ars->create({ name => 'in_inner_transaction' });
23     });
24     ok($ars->search({ name => 'in_inner_transaction' })->first,
25       'commit from inner transaction visible in outer transaction');
26     throws_ok {
27       $schema->txn_do(sub {
28         $ars->create({ name => 'in_inner_transaction_rolling_back' });
29         die 'rolling back inner transaction';
30       });
31     } qr/rolling back inner transaction/, 'inner transaction rollback executed';
32     $ars->create({ name => 'in_outer_transaction2' });
33   });
34
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,
42     undef,
43     'rollback from inner transaction';
44 }
45
46 my $schema = DBICTest->init_schema();
47
48 # make sure the side-effects of RT#67581 do not result in data loss
49 my $row;
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'
53 ;
54 $row->discard_changes;
55 is ($row->rank, 'abc', 'proper rank inserted into database');
56
57 # and make sure we do not lose actual bigints
58 {
59   package DBICTest::BigIntArtist;
60   use base 'DBICTest::Schema::Artist';
61   __PACKAGE__->table('artist');
62   __PACKAGE__->add_column(bigint => { data_type => 'bigint' });
63 }
64 $schema->register_class(BigIntArtist => 'DBICTest::BigIntArtist');
65 $schema->storage->dbh_do(sub {
66   $_[1]->do('ALTER TABLE artist ADD COLUMN bigint BIGINT');
67 });
68
69 # test upper/lower boundaries for sqlite and some values inbetween
70 # range is -(2**63) .. 2**63 - 1
71 for my $bi (qw/
72   -9223372036854775808
73   -9223372036854775807
74   -8694837494948124658
75   -6848440844435891639
76   -5664812265578554454
77   -5380388020020483213
78   -2564279463598428141
79   2442753333597784273
80   4790993557925631491
81   6773854980030157393
82   7627910776496326154
83   8297530189347439311
84   9223372036854775806
85   9223372036854775807
86 /) {
87   $row = $schema->resultset('BigIntArtist')->create({ bigint => $bi });
88   is ($row->bigint, $bi, "value in object correct ($bi)");
89
90   TODO: {
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;
93
94     $row->discard_changes;
95     is ($row->bigint, $bi, "value in database correct ($bi)");
96   }
97 }
98
99 done_testing;
100
101 # vim:sts=2 sw=2: