summaryrefslogtreecommitdiff
path: root/t/rt_62370_diconnected_handles_operation.t
blob: 6e735c2211f1581760d4a1a072c163af6181d28f (plain)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/perl

use strict;
BEGIN {
	$|  = 1;
	$^W = 1;
}

use t::lib::Test qw/connect_ok @CALL_FUNCS/;
use Test::More;
use DBD::SQLite;
#use Test::NoWarnings;

my @methods = qw(
	commit rollback
);

plan tests => 2 * (6 + @methods) + 2 * @CALL_FUNCS * (14 + ($DBD::SQLite::sqlite_version_number >= 3006011) * 2);

local $SIG{__WARN__} = sub {};  # to hide warnings/error messages

# DBI methods

for my $autocommit (0, 1) {
	my $dbh = connect_ok( RaiseError => 1, PrintError => 0, AutoCommit => $autocommit );
	$dbh->do('create table foo (id, text)');
	$dbh->do('insert into foo values(?,?)', undef, 1, 'text');
	{
		local $@;
		eval { $dbh->disconnect };
		ok !$@, "disconnected";
	}

	for my $method (@methods) {
		local $@;
		eval { $dbh->$method };
		ok $@, "$method dies with error: $@";
	}

	{
		local $@;
		eval { $dbh->last_insert_id(undef, undef, undef, undef) };
		ok $@, "last_insert_id dies with error: $@";
	}

	{
		local $@;
		eval { $dbh->do('insert into foo (?,?)', undef, 2, 'text2') };
		ok $@, "do dies with error: $@";
	}

	{
		local $@;
		eval { $dbh->selectrow_arrayref('select * from foo') };
		ok $@, "selectrow_arrayref dies with error: $@";
	}

	{ # this should be the last test in this block
		local $@;
		eval { local $dbh->{AutoCommit} };
		ok !$@, "store doesn't cause segfault";
	}
}

# SQLite private methods

for my $call_func (@CALL_FUNCS) {
	for my $autocommit (0, 1) {
		my $dbh = connect_ok( RaiseError => 1, PrintError => 0, AutoCommit => $autocommit );
		$dbh->do('create table foo (id, text)');
		$dbh->do('insert into foo values(?,?)', undef, 1, 'text');
		{
			local $@;
			eval { $dbh->disconnect };
			ok !$@, "disconnected";
		}

		{
			local $@;
			eval { $dbh->$call_func(500, 'busy_timeout') };
			ok $@, "busy timeout dies with error: $@";
		}

		{
			local $@;
			eval { $dbh->$call_func('now', 0, sub { time }, 'create_function') };
			ok $@, "create_function dies with error: $@";
		}

		{
			local $@;
			eval { $dbh->$call_func(1, 'enable_load_extension') };
			ok $@, "enable_load_extension dies with error: $@";
		}

		{
			package count_aggr;

			sub new {
				bless { count => 0 }, shift;
			}

			sub step {
				$_[0]{count}++;
				return;
			}

			sub finalize {
				my $c = $_[0]{count};
				$_[0]{count} = undef;

				return $c;
			}

			package main;

			local $@;
			eval { $dbh->$call_func('newcount', 0, 'count_aggr', 'create_aggregate') };
			ok $@, "create_aggregate dies with error: $@";
		}

		{
			local $@;
			eval { $dbh->$call_func('by_num', sub ($$) {0}, 'create_collation') };
			ok $@, "create_collation dies with error: $@";
		}

		{
			local $@;
			eval { $dbh->$call_func('by_num', sub ($$) {0}, 'create_collation') };
			ok $@, "create_collation dies with error: $@";
		}

		{
			local $@;
			eval { $dbh->$call_func(sub {1}, 'collation_needed') };
			ok $@, "collation_needed dies with error: $@";
		}

		{
			local $@;
			eval { $dbh->$call_func(50, sub {}, 'progress_handler') };
			ok $@, "progress_handler dies with error: $@";
		}

		{
			local $@;
			eval { $dbh->$call_func(sub {}, 'commit_hook') };
			ok $@, "commit hook dies with error: $@";
		}

		{
			local $@;
			eval { $dbh->$call_func(sub {}, 'rollback_hook') };
			ok $@, "rollback hook dies with error: $@";
		}

		{
			local $@;
			eval { $dbh->$call_func(sub {}, 'update_hook') };
			ok $@, "update hook dies with error: $@";
		}

		{
			local $@;
			eval { $dbh->$call_func(undef, 'set_authorizer') };
			ok $@, "set authorizer dies with error: $@";
		}

		if ($DBD::SQLite::sqlite_version_number >= 3006011) {
			local $@;
			eval { $dbh->$call_func('./backup_file', 'backup_from_file') };
			ok $@, "backup from file dies with error: $@";
		}

		if ($DBD::SQLite::sqlite_version_number >= 3006011) {
			local $@;
			eval { $dbh->$call_func('./backup_file', 'backup_to_file') };
			ok $@, "backup to file dies with error: $@";
		}
	}
}