sqlite3 1.7.3-arm64-darwin → 2.0.0-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +152 -0
  3. data/CONTRIBUTING.md +23 -1
  4. data/FAQ.md +0 -43
  5. data/INSTALLATION.md +13 -5
  6. data/LICENSE +18 -22
  7. data/README.md +75 -4
  8. data/dependencies.yml +10 -11
  9. data/ext/sqlite3/aggregator.c +142 -145
  10. data/ext/sqlite3/aggregator.h +2 -4
  11. data/ext/sqlite3/backup.c +74 -65
  12. data/ext/sqlite3/backup.h +2 -2
  13. data/ext/sqlite3/database.c +535 -482
  14. data/ext/sqlite3/database.h +7 -4
  15. data/ext/sqlite3/exception.c +111 -92
  16. data/ext/sqlite3/exception.h +3 -1
  17. data/ext/sqlite3/extconf.rb +21 -22
  18. data/ext/sqlite3/sqlite3.c +159 -115
  19. data/ext/sqlite3/sqlite3_ruby.h +2 -2
  20. data/ext/sqlite3/statement.c +516 -300
  21. data/ext/sqlite3/statement.h +3 -3
  22. data/ext/sqlite3/timespec.h +20 -0
  23. data/lib/sqlite3/3.0/sqlite3_native.bundle +0 -0
  24. data/lib/sqlite3/3.1/sqlite3_native.bundle +0 -0
  25. data/lib/sqlite3/3.2/sqlite3_native.bundle +0 -0
  26. data/lib/sqlite3/3.3/sqlite3_native.bundle +0 -0
  27. data/lib/sqlite3/constants.rb +171 -47
  28. data/lib/sqlite3/database.rb +105 -165
  29. data/lib/sqlite3/errors.rb +26 -1
  30. data/lib/sqlite3/pragmas.rb +126 -136
  31. data/lib/sqlite3/resultset.rb +14 -97
  32. data/lib/sqlite3/statement.rb +58 -13
  33. data/lib/sqlite3/value.rb +17 -20
  34. data/lib/sqlite3/version.rb +1 -21
  35. data/lib/sqlite3.rb +6 -4
  36. metadata +3 -28
  37. data/API_CHANGES.md +0 -49
  38. data/ChangeLog.cvs +0 -88
  39. data/Gemfile +0 -10
  40. data/LICENSE-DEPENDENCIES +0 -20
  41. data/lib/sqlite3/translator.rb +0 -117
  42. data/test/helper.rb +0 -27
  43. data/test/test_backup.rb +0 -33
  44. data/test/test_collation.rb +0 -82
  45. data/test/test_database.rb +0 -668
  46. data/test/test_database_flags.rb +0 -95
  47. data/test/test_database_readonly.rb +0 -36
  48. data/test/test_database_readwrite.rb +0 -41
  49. data/test/test_deprecated.rb +0 -49
  50. data/test/test_encoding.rb +0 -165
  51. data/test/test_integration.rb +0 -507
  52. data/test/test_integration_aggregate.rb +0 -336
  53. data/test/test_integration_open_close.rb +0 -30
  54. data/test/test_integration_pending.rb +0 -115
  55. data/test/test_integration_resultset.rb +0 -142
  56. data/test/test_integration_statement.rb +0 -194
  57. data/test/test_pragmas.rb +0 -22
  58. data/test/test_result_set.rb +0 -47
  59. data/test/test_sqlite3.rb +0 -30
  60. data/test/test_statement.rb +0 -290
  61. data/test/test_statement_execute.rb +0 -39
@@ -1,507 +0,0 @@
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