sqlite3 1.5.0-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sqlite3 might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/API_CHANGES.md +49 -0
- data/CHANGELOG.md +425 -0
- data/CONTRIBUTING.md +24 -0
- data/ChangeLog.cvs +88 -0
- data/Gemfile +3 -0
- data/LICENSE +27 -0
- data/LICENSE-DEPENDENCIES +20 -0
- data/README.md +233 -0
- data/ext/sqlite3/aggregator.c +274 -0
- data/ext/sqlite3/aggregator.h +12 -0
- data/ext/sqlite3/backup.c +168 -0
- data/ext/sqlite3/backup.h +15 -0
- data/ext/sqlite3/database.c +853 -0
- data/ext/sqlite3/database.h +17 -0
- data/ext/sqlite3/exception.c +98 -0
- data/ext/sqlite3/exception.h +8 -0
- data/ext/sqlite3/extconf.rb +252 -0
- data/ext/sqlite3/sqlite3.c +163 -0
- data/ext/sqlite3/sqlite3_ruby.h +48 -0
- data/ext/sqlite3/statement.c +442 -0
- data/ext/sqlite3/statement.h +16 -0
- data/faq/faq.md +431 -0
- data/faq/faq.rb +145 -0
- data/faq/faq.yml +426 -0
- data/lib/sqlite3/2.6/sqlite3_native.bundle +0 -0
- data/lib/sqlite3/2.7/sqlite3_native.bundle +0 -0
- data/lib/sqlite3/3.0/sqlite3_native.bundle +0 -0
- data/lib/sqlite3/3.1/sqlite3_native.bundle +0 -0
- data/lib/sqlite3/constants.rb +50 -0
- data/lib/sqlite3/database.rb +741 -0
- data/lib/sqlite3/errors.rb +35 -0
- data/lib/sqlite3/pragmas.rb +595 -0
- data/lib/sqlite3/resultset.rb +187 -0
- data/lib/sqlite3/statement.rb +145 -0
- data/lib/sqlite3/translator.rb +118 -0
- data/lib/sqlite3/value.rb +57 -0
- data/lib/sqlite3/version.rb +23 -0
- data/lib/sqlite3.rb +15 -0
- data/test/helper.rb +27 -0
- data/test/test_backup.rb +33 -0
- data/test/test_collation.rb +82 -0
- data/test/test_database.rb +545 -0
- data/test/test_database_flags.rb +95 -0
- data/test/test_database_readonly.rb +36 -0
- data/test/test_database_readwrite.rb +41 -0
- data/test/test_deprecated.rb +44 -0
- data/test/test_encoding.rb +155 -0
- data/test/test_integration.rb +507 -0
- data/test/test_integration_aggregate.rb +336 -0
- data/test/test_integration_open_close.rb +30 -0
- data/test/test_integration_pending.rb +115 -0
- data/test/test_integration_resultset.rb +142 -0
- data/test/test_integration_statement.rb +194 -0
- data/test/test_result_set.rb +37 -0
- data/test/test_sqlite3.rb +30 -0
- data/test/test_statement.rb +263 -0
- data/test/test_statement_execute.rb +35 -0
- metadata +190 -0
@@ -0,0 +1,507 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TC_Database_Integration < SQLite3::TestCase
|
4
|
+
def setup
|
5
|
+
@db = SQLite3::Database.new(":memory:")
|
6
|
+
@db.transaction do
|
7
|
+
@db.execute "create table foo ( a integer primary key, b text )"
|
8
|
+
@db.execute "insert into foo ( b ) values ( 'foo' )"
|
9
|
+
@db.execute "insert into foo ( b ) values ( 'bar' )"
|
10
|
+
@db.execute "insert into foo ( b ) values ( 'baz' )"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
@db.close
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_table_info_with_type_translation_active
|
19
|
+
assert_nothing_raised { @db.table_info("foo") }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_table_info_with_defaults_for_version_3_3_8_and_higher
|
23
|
+
@db.transaction do
|
24
|
+
@db.execute "create table defaults_test ( a string default NULL, b string default 'Hello', c string default '--- []\n' )"
|
25
|
+
data = @db.table_info( "defaults_test" )
|
26
|
+
assert_equal({"name" => "a", "type" => "string", "dflt_value" => nil, "notnull" => 0, "cid" => 0, "pk" => 0},
|
27
|
+
data[0])
|
28
|
+
assert_equal({"name" => "b", "type" => "string", "dflt_value" => "Hello", "notnull" => 0, "cid" => 1, "pk" => 0},
|
29
|
+
data[1])
|
30
|
+
assert_equal({"name" => "c", "type" => "string", "dflt_value" => "--- []\n", "notnull" => 0, "cid" => 2, "pk" => 0},
|
31
|
+
data[2])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_table_info_without_defaults_for_version_3_3_8_and_higher
|
36
|
+
@db.transaction do
|
37
|
+
@db.execute "create table no_defaults_test ( a integer default 1, b integer )"
|
38
|
+
data = @db.table_info( "no_defaults_test" )
|
39
|
+
assert_equal({"name" => "a", "type" => "integer", "dflt_value" => "1", "notnull" => 0, "cid" => 0, "pk" => 0},
|
40
|
+
data[0])
|
41
|
+
assert_equal({"name" => "b", "type" => "integer", "dflt_value" => nil, "notnull" => 0, "cid" => 1, "pk" => 0},
|
42
|
+
data[1])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_complete_fail
|
47
|
+
assert !@db.complete?( "select * from foo" )
|
48
|
+
end
|
49
|
+
def test_complete_success
|
50
|
+
assert @db.complete?( "select * from foo;" )
|
51
|
+
end
|
52
|
+
|
53
|
+
# FIXME: do people really need UTF16 sql statements?
|
54
|
+
#def test_complete_fail_utf16
|
55
|
+
# assert !@db.complete?( "select * from foo".to_utf16(false), true )
|
56
|
+
#end
|
57
|
+
|
58
|
+
# FIXME: do people really need UTF16 sql statements?
|
59
|
+
#def test_complete_success_utf16
|
60
|
+
# assert @db.complete?( "select * from foo;".to_utf16(true), true )
|
61
|
+
#end
|
62
|
+
|
63
|
+
def test_errmsg
|
64
|
+
assert_equal "not an error", @db.errmsg
|
65
|
+
end
|
66
|
+
|
67
|
+
# FIXME: do people really need UTF16 error messages?
|
68
|
+
#def test_errmsg_utf16
|
69
|
+
# msg = Iconv.conv('UTF-16', 'UTF-8', 'not an error')
|
70
|
+
# assert_equal msg, @db.errmsg(true)
|
71
|
+
#end
|
72
|
+
|
73
|
+
def test_errcode
|
74
|
+
assert_equal 0, @db.errcode
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_trace
|
78
|
+
result = nil
|
79
|
+
@db.trace { |sql| result = sql }
|
80
|
+
@db.execute "select * from foo"
|
81
|
+
assert_equal "select * from foo", result
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_authorizer_okay
|
85
|
+
@db.authorizer { |type,a,b,c,d| 0 }
|
86
|
+
rows = @db.execute "select * from foo"
|
87
|
+
assert_equal 3, rows.length
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_authorizer_error
|
91
|
+
@db.authorizer { |type,a,b,c,d| 1 }
|
92
|
+
assert_raise( SQLite3::AuthorizationException ) do
|
93
|
+
@db.execute "select * from foo"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_authorizer_silent
|
98
|
+
@db.authorizer { |type,a,b,c,d| 2 }
|
99
|
+
rows = @db.execute "select * from foo"
|
100
|
+
assert rows.empty?
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_prepare_invalid_syntax
|
104
|
+
assert_raise( SQLite3::SQLException ) do
|
105
|
+
@db.prepare "select from foo"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_prepare_invalid_column
|
110
|
+
assert_raise( SQLite3::SQLException ) do
|
111
|
+
@db.prepare "select k from foo"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_prepare_invalid_table
|
116
|
+
assert_raise( SQLite3::SQLException ) do
|
117
|
+
@db.prepare "select * from barf"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_prepare_no_block
|
122
|
+
stmt = @db.prepare "select * from foo"
|
123
|
+
assert stmt.respond_to?(:execute)
|
124
|
+
stmt.close
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_prepare_with_block
|
128
|
+
called = false
|
129
|
+
@db.prepare "select * from foo" do |stmt|
|
130
|
+
called = true
|
131
|
+
assert stmt.respond_to?(:execute)
|
132
|
+
end
|
133
|
+
assert called
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_execute_no_block_no_bind_no_match
|
137
|
+
rows = @db.execute( "select * from foo where a > 100" )
|
138
|
+
assert rows.empty?
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_execute_with_block_no_bind_no_match
|
142
|
+
called = false
|
143
|
+
@db.execute( "select * from foo where a > 100" ) do |row|
|
144
|
+
called = true
|
145
|
+
end
|
146
|
+
assert !called
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_execute_no_block_with_bind_no_match
|
150
|
+
rows = @db.execute( "select * from foo where a > ?", 100 )
|
151
|
+
assert rows.empty?
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_execute_with_block_with_bind_no_match
|
155
|
+
called = false
|
156
|
+
@db.execute( "select * from foo where a > ?", 100 ) do |row|
|
157
|
+
called = true
|
158
|
+
end
|
159
|
+
assert !called
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_execute_no_block_no_bind_with_match
|
163
|
+
rows = @db.execute( "select * from foo where a = 1" )
|
164
|
+
assert_equal 1, rows.length
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_execute_with_block_no_bind_with_match
|
168
|
+
called = 0
|
169
|
+
@db.execute( "select * from foo where a = 1" ) do |row|
|
170
|
+
called += 1
|
171
|
+
end
|
172
|
+
assert_equal 1, called
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_execute_no_block_with_bind_with_match
|
176
|
+
rows = @db.execute( "select * from foo where a = ?", 1 )
|
177
|
+
assert_equal 1, rows.length
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_execute_with_block_with_bind_with_match
|
181
|
+
called = 0
|
182
|
+
@db.execute( "select * from foo where a = ?", 1 ) do |row|
|
183
|
+
called += 1
|
184
|
+
end
|
185
|
+
assert_equal 1, called
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_execute2_no_block_no_bind_no_match
|
189
|
+
columns, *rows = @db.execute2( "select * from foo where a > 100" )
|
190
|
+
assert rows.empty?
|
191
|
+
assert_equal [ "a", "b" ], columns
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_execute2_with_block_no_bind_no_match
|
195
|
+
called = 0
|
196
|
+
@db.execute2( "select * from foo where a > 100" ) do |row|
|
197
|
+
assert [ "a", "b" ], row unless called == 0
|
198
|
+
called += 1
|
199
|
+
end
|
200
|
+
assert_equal 1, called
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_execute2_no_block_with_bind_no_match
|
204
|
+
columns, *rows = @db.execute2( "select * from foo where a > ?", 100 )
|
205
|
+
assert rows.empty?
|
206
|
+
assert_equal [ "a", "b" ], columns
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_execute2_with_block_with_bind_no_match
|
210
|
+
called = 0
|
211
|
+
@db.execute2( "select * from foo where a > ?", 100 ) do |row|
|
212
|
+
assert_equal [ "a", "b" ], row unless called == 0
|
213
|
+
called += 1
|
214
|
+
end
|
215
|
+
assert_equal 1, called
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_execute2_no_block_no_bind_with_match
|
219
|
+
columns, *rows = @db.execute2( "select * from foo where a = 1" )
|
220
|
+
assert_equal 1, rows.length
|
221
|
+
assert_equal [ "a", "b" ], columns
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_execute2_with_block_no_bind_with_match
|
225
|
+
called = 0
|
226
|
+
@db.execute2( "select * from foo where a = 1" ) do |row|
|
227
|
+
assert_equal [ 1, "foo" ], row unless called == 0
|
228
|
+
called += 1
|
229
|
+
end
|
230
|
+
assert_equal 2, called
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_execute2_no_block_with_bind_with_match
|
234
|
+
columns, *rows = @db.execute2( "select * from foo where a = ?", 1 )
|
235
|
+
assert_equal 1, rows.length
|
236
|
+
assert_equal [ "a", "b" ], columns
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_execute2_with_block_with_bind_with_match
|
240
|
+
called = 0
|
241
|
+
@db.execute2( "select * from foo where a = ?", 1 ) do
|
242
|
+
called += 1
|
243
|
+
end
|
244
|
+
assert_equal 2, called
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_execute_batch_empty
|
248
|
+
assert_nothing_raised { @db.execute_batch "" }
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_execute_batch_no_bind
|
252
|
+
@db.transaction do
|
253
|
+
@db.execute_batch <<-SQL
|
254
|
+
create table bar ( a, b, c );
|
255
|
+
insert into bar values ( 'one', 2, 'three' );
|
256
|
+
insert into bar values ( 'four', 5, 'six' );
|
257
|
+
insert into bar values ( 'seven', 8, 'nine' );
|
258
|
+
SQL
|
259
|
+
end
|
260
|
+
rows = @db.execute( "select * from bar" )
|
261
|
+
assert_equal 3, rows.length
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_execute_batch_with_bind
|
265
|
+
@db.execute_batch( <<-SQL, [1] )
|
266
|
+
create table bar ( a, b, c );
|
267
|
+
insert into bar values ( 'one', 2, ? );
|
268
|
+
insert into bar values ( 'four', 5, ? );
|
269
|
+
insert into bar values ( 'seven', 8, ? );
|
270
|
+
SQL
|
271
|
+
rows = @db.execute( "select * from bar" ).map { |a,b,c| c }
|
272
|
+
assert_equal [1, 1, 1], rows
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_query_no_block_no_bind_no_match
|
276
|
+
result = @db.query( "select * from foo where a > 100" )
|
277
|
+
assert_nil result.next
|
278
|
+
result.close
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_query_with_block_no_bind_no_match
|
282
|
+
r = nil
|
283
|
+
@db.query( "select * from foo where a > 100" ) do |result|
|
284
|
+
assert_nil result.next
|
285
|
+
r = result
|
286
|
+
end
|
287
|
+
assert r.closed?
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_query_no_block_with_bind_no_match
|
291
|
+
result = @db.query( "select * from foo where a > ?", 100 )
|
292
|
+
assert_nil result.next
|
293
|
+
result.close
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_query_with_block_with_bind_no_match
|
297
|
+
r = nil
|
298
|
+
@db.query( "select * from foo where a > ?", 100 ) do |result|
|
299
|
+
assert_nil result.next
|
300
|
+
r = result
|
301
|
+
end
|
302
|
+
assert r.closed?
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_query_no_block_no_bind_with_match
|
306
|
+
result = @db.query( "select * from foo where a = 1" )
|
307
|
+
assert_not_nil result.next
|
308
|
+
assert_nil result.next
|
309
|
+
result.close
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_query_with_block_no_bind_with_match
|
313
|
+
r = nil
|
314
|
+
@db.query( "select * from foo where a = 1" ) do |result|
|
315
|
+
assert_not_nil result.next
|
316
|
+
assert_nil result.next
|
317
|
+
r = result
|
318
|
+
end
|
319
|
+
assert r.closed?
|
320
|
+
end
|
321
|
+
|
322
|
+
def test_query_no_block_with_bind_with_match
|
323
|
+
result = @db.query( "select * from foo where a = ?", 1 )
|
324
|
+
assert_not_nil result.next
|
325
|
+
assert_nil result.next
|
326
|
+
result.close
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_query_with_block_with_bind_with_match
|
330
|
+
r = nil
|
331
|
+
@db.query( "select * from foo where a = ?", 1 ) do |result|
|
332
|
+
assert_not_nil result.next
|
333
|
+
assert_nil result.next
|
334
|
+
r = result
|
335
|
+
end
|
336
|
+
assert r.closed?
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_get_first_row_no_bind_no_match
|
340
|
+
result = @db.get_first_row( "select * from foo where a=100" )
|
341
|
+
assert_nil result
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_get_first_row_no_bind_with_match
|
345
|
+
result = @db.get_first_row( "select * from foo where a=1" )
|
346
|
+
assert_equal [ 1, "foo" ], result
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_get_first_row_with_bind_no_match
|
350
|
+
result = @db.get_first_row( "select * from foo where a=?", 100 )
|
351
|
+
assert_nil result
|
352
|
+
end
|
353
|
+
|
354
|
+
def test_get_first_row_with_bind_with_match
|
355
|
+
result = @db.get_first_row( "select * from foo where a=?", 1 )
|
356
|
+
assert_equal [ 1, "foo" ], result
|
357
|
+
end
|
358
|
+
|
359
|
+
def test_get_first_value_no_bind_no_match
|
360
|
+
result = @db.get_first_value( "select b, a from foo where a=100" )
|
361
|
+
assert_nil result
|
362
|
+
@db.results_as_hash = true
|
363
|
+
result = @db.get_first_value( "select b, a from foo where a=100" )
|
364
|
+
assert_nil result
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_get_first_value_no_bind_with_match
|
368
|
+
result = @db.get_first_value( "select b, a from foo where a=1" )
|
369
|
+
assert_equal "foo", result
|
370
|
+
@db.results_as_hash = true
|
371
|
+
result = @db.get_first_value( "select b, a from foo where a=1" )
|
372
|
+
assert_equal "foo", result
|
373
|
+
end
|
374
|
+
|
375
|
+
def test_get_first_value_with_bind_no_match
|
376
|
+
result = @db.get_first_value( "select b, a from foo where a=?", 100 )
|
377
|
+
assert_nil result
|
378
|
+
@db.results_as_hash = true
|
379
|
+
result = @db.get_first_value( "select b, a from foo where a=?", 100 )
|
380
|
+
assert_nil result
|
381
|
+
end
|
382
|
+
|
383
|
+
def test_get_first_value_with_bind_with_match
|
384
|
+
result = @db.get_first_value( "select b, a from foo where a=?", 1 )
|
385
|
+
assert_equal "foo", result
|
386
|
+
@db.results_as_hash = true
|
387
|
+
result = @db.get_first_value( "select b, a from foo where a=?", 1 )
|
388
|
+
assert_equal "foo", result
|
389
|
+
end
|
390
|
+
|
391
|
+
def test_last_insert_row_id
|
392
|
+
@db.execute "insert into foo ( b ) values ( 'test' )"
|
393
|
+
assert_equal 4, @db.last_insert_row_id
|
394
|
+
@db.execute "insert into foo ( b ) values ( 'again' )"
|
395
|
+
assert_equal 5, @db.last_insert_row_id
|
396
|
+
end
|
397
|
+
|
398
|
+
def test_changes
|
399
|
+
@db.execute "insert into foo ( b ) values ( 'test' )"
|
400
|
+
assert_equal 1, @db.changes
|
401
|
+
@db.execute "delete from foo where 1=1"
|
402
|
+
assert_equal 4, @db.changes
|
403
|
+
end
|
404
|
+
|
405
|
+
def test_total_changes
|
406
|
+
assert_equal 3, @db.total_changes
|
407
|
+
@db.execute "insert into foo ( b ) values ( 'test' )"
|
408
|
+
@db.execute "delete from foo where 1=1"
|
409
|
+
assert_equal 8, @db.total_changes
|
410
|
+
end
|
411
|
+
|
412
|
+
def test_transaction_nest
|
413
|
+
assert_raise( SQLite3::SQLException ) do
|
414
|
+
@db.transaction do
|
415
|
+
@db.transaction do
|
416
|
+
end
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
def test_transaction_rollback
|
422
|
+
@db.transaction
|
423
|
+
@db.execute_batch <<-SQL
|
424
|
+
insert into foo (b) values ( 'test1' );
|
425
|
+
insert into foo (b) values ( 'test2' );
|
426
|
+
insert into foo (b) values ( 'test3' );
|
427
|
+
insert into foo (b) values ( 'test4' );
|
428
|
+
SQL
|
429
|
+
assert_equal 7, @db.get_first_value("select count(*) from foo").to_i
|
430
|
+
@db.rollback
|
431
|
+
assert_equal 3, @db.get_first_value("select count(*) from foo").to_i
|
432
|
+
end
|
433
|
+
|
434
|
+
def test_transaction_commit
|
435
|
+
@db.transaction
|
436
|
+
@db.execute_batch <<-SQL
|
437
|
+
insert into foo (b) values ( 'test1' );
|
438
|
+
insert into foo (b) values ( 'test2' );
|
439
|
+
insert into foo (b) values ( 'test3' );
|
440
|
+
insert into foo (b) values ( 'test4' );
|
441
|
+
SQL
|
442
|
+
assert_equal 7, @db.get_first_value("select count(*) from foo").to_i
|
443
|
+
@db.commit
|
444
|
+
assert_equal 7, @db.get_first_value("select count(*) from foo").to_i
|
445
|
+
end
|
446
|
+
|
447
|
+
def test_transaction_rollback_in_block
|
448
|
+
assert_raise( SQLite3::SQLException ) do
|
449
|
+
@db.transaction do
|
450
|
+
@db.rollback
|
451
|
+
end
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_transaction_commit_in_block
|
456
|
+
assert_raise( SQLite3::SQLException ) do
|
457
|
+
@db.transaction do
|
458
|
+
@db.commit
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
def test_transaction_active
|
464
|
+
assert !@db.transaction_active?
|
465
|
+
@db.transaction
|
466
|
+
assert @db.transaction_active?
|
467
|
+
@db.commit
|
468
|
+
assert !@db.transaction_active?
|
469
|
+
end
|
470
|
+
|
471
|
+
def test_transaction_implicit_rollback
|
472
|
+
assert !@db.transaction_active?
|
473
|
+
@db.transaction
|
474
|
+
@db.execute('create table bar (x CHECK(1 = 0))')
|
475
|
+
assert @db.transaction_active?
|
476
|
+
assert_raises( SQLite3::ConstraintException ) do
|
477
|
+
@db.execute("insert or rollback into bar (x) VALUES ('x')")
|
478
|
+
end
|
479
|
+
assert !@db.transaction_active?
|
480
|
+
end
|
481
|
+
|
482
|
+
def test_interrupt
|
483
|
+
@db.create_function( "abort", 1 ) do |func,x|
|
484
|
+
@db.interrupt
|
485
|
+
func.result = x
|
486
|
+
end
|
487
|
+
|
488
|
+
assert_raise( SQLite3::InterruptException ) do
|
489
|
+
@db.execute "select abort(a) from foo"
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
def test_create_function
|
494
|
+
@db.create_function( "munge", 1 ) do |func,x|
|
495
|
+
func.result = ">>>#{x}<<<"
|
496
|
+
end
|
497
|
+
|
498
|
+
value = @db.get_first_value( "select munge(b) from foo where a=1" )
|
499
|
+
assert_match( />>>.*<<</, value )
|
500
|
+
end
|
501
|
+
|
502
|
+
def test_bind_array_parameter
|
503
|
+
result = @db.get_first_value( "select b from foo where a=? and b=?",
|
504
|
+
[ 1, "foo" ] )
|
505
|
+
assert_equal "foo", result
|
506
|
+
end
|
507
|
+
end
|