Some cleanups and code dedup of Top and FetchFirst limit dialects
[dbsrgits/DBIx-Class.git] / t / 752sqlite.t
CommitLineData
86a51471 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
632d1e0f 6use Test::Warn;
67b35a45 7use Config;
8
86a51471 9use lib qw(t/lib);
10use DBICTest;
11
67b35a45 12# savepoints test
13{
14 my $schema = DBICTest->init_schema(auto_savepoint => 1);
86a51471 15
67b35a45 16 my $ars = $schema->resultset('Artist');
86a51471 17
67b35a45 18 # test two-phase commit and inner transaction rollback from nested transactions
86a51471 19 $schema->txn_do(sub {
67b35a45 20 $ars->create({ name => 'in_outer_transaction' });
86a51471 21 $schema->txn_do(sub {
67b35a45 22 $ars->create({ name => 'in_inner_transaction' });
86a51471 23 });
67b35a45 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}
632d1e0f 45
67b35a45 46my $schema = DBICTest->init_schema();
86a51471 47
632d1e0f 48# make sure the side-effects of RT#67581 do not result in data loss
49my $row;
67b35a45 50warnings_exist { $row = $schema->resultset('Artist')->create ({ name => 'alpha rank', rank => 'abc' }) }
632d1e0f 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;
55is ($row->rank, 'abc', 'proper rank inserted into database');
56
67b35a45 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
71for 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
86a51471 99done_testing;
100
101# vim:sts=2 sw=2: