File: rt_76395_int_overflow.t

package info (click to toggle)
libdbd-sqlite3-perl 1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,004 kB
  • sloc: ansic: 167,715; perl: 1,788; pascal: 277; makefile: 9
file content (111 lines) | stat: -rw-r--r-- 2,061 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use warnings;
use strict;
use warnings;
use lib "t/lib";
use SQLiteTest;
use Test::More;
use if -d ".git", "Test::FailWarnings";

use DBI;

my @tests = qw(
  -2 -1 0 1 2

  -9223372036854775808
  -9223372036854775807
  -8694837494948124658
  -6848440844435891639
  -5664812265578554454
  -5380388020020483213
  -2564279463598428141
  2442753333597784273
  4790993557925631491
  6773854980030157393
  7627910776496326154
  8297530189347439311
  9223372036854775806
  9223372036854775807

  4294967295
  4294967296

  -4294967296
  -4294967295
  -4294967294

  -2147483649
  -2147483648
  -2147483647
  -2147483646

  2147483646
  2147483647
  2147483648
  2147483649
);

my $dbh = connect_ok();
$dbh->do('
  CREATE TABLE t (
    pk INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    int INTEGER,
    bigint BIGINT
  )
');

for my $val (@tests) {
  for my $col (qw(int bigint)) {
    for my $bindtype (undef, 'DBI::SQL_INTEGER', 'DBI::SQL_BIGINT') {

      my $tdesc = sprintf "value '%s' with %s bindtype on '%s' column",
        $val,
        $bindtype || 'no',
        $col
      ;

      my $sth = $dbh->prepare_cached(
        "INSERT INTO t ( $col ) VALUES ( ? )",
        {},
        3
      );

      my @w;
      local $SIG{__WARN__} = sub { push @w, @_ };

      ok (
        $sth->bind_param(1, $val, ( $bindtype and do { no strict 'refs'; &{$bindtype} } )),
        "Succesfully bound $tdesc",
      );
      is_deeply(
        \@w,
        [],
        "No warnings during bind of $tdesc",
      );

      ok (
        eval { $sth->execute ; 1 },
        "Succesfully inserted $tdesc" . ($@ ? ": $@" : ''),
      );
      is_deeply(
        \@w,
        [],
        "No warnings during insertion of $tdesc",
      );

      my $id;
      ok (
        $id = $dbh->last_insert_id(undef, undef, 't', 'pk'),
        "Got id $id of inserted $tdesc",
      );

      is_deeply(
        $dbh->selectall_arrayref("SELECT $col FROM t WHERE pk = $id"),
        [[ $val ]],
        "Proper roundtrip (insert/select) of $tdesc",
      );

    }
  }
}

done_testing;