extralite 2.7 → 2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,30 +40,30 @@ class DatabaseTest < Minitest::Test
40
40
  assert_equal [], r
41
41
  end
42
42
 
43
- def test_query_ary
44
- r = @db.query_ary('select * from t')
43
+ def test_query_array
44
+ r = @db.query_array('select * from t')
45
45
  assert_equal [[1, 2, 3], [4, 5, 6]], r
46
46
 
47
- r = @db.query_ary('select * from t where x = 2')
47
+ r = @db.query_array('select * from t where x = 2')
48
48
  assert_equal [], r
49
49
  end
50
50
 
51
- def test_query_argv
52
- r = @db.query_argv('select * from t')
51
+ def test_query_splat
52
+ r = @db.query_splat('select * from t')
53
53
  assert_equal [[1, 2, 3], [4, 5, 6]], r
54
54
 
55
- r = @db.query_argv('select * from t where x = 2')
55
+ r = @db.query_splat('select * from t where x = 2')
56
56
  assert_equal [], r
57
57
 
58
58
  # with block
59
59
  r = []
60
- @db.query_argv('select * from t') { |a, b, c| r << [a, b, c] }
60
+ @db.query_splat('select * from t') { |a, b, c| r << [a, b, c] }
61
61
  assert_equal [[1, 2, 3], [4, 5, 6]], r
62
62
  end
63
63
 
64
- def test_query_argv_with_too_many_columns
64
+ def test_query_splat_with_too_many_columns
65
65
  assert_raises(Extralite::Error) {
66
- @db.query_argv('select 1, 2, 3, 4, 5, 6, 7, 8, 9');
66
+ @db.query_splat('select 1, 2, 3, 4, 5, 6, 7, 8, 9');
67
67
  }
68
68
  end
69
69
 
@@ -75,11 +75,11 @@ class DatabaseTest < Minitest::Test
75
75
  assert_nil r
76
76
  end
77
77
 
78
- def test_query_single_argv
79
- r = @db.query_single_argv('select z from t order by Z desc limit 1')
78
+ def test_query_single_splat
79
+ r = @db.query_single_splat('select z from t order by Z desc limit 1')
80
80
  assert_equal 6, r
81
81
 
82
- r = @db.query_single_argv('select z from t where x = 2')
82
+ r = @db.query_single_splat('select z from t where x = 2')
83
83
  assert_nil r
84
84
  end
85
85
 
@@ -99,7 +99,7 @@ class DatabaseTest < Minitest::Test
99
99
  def test_multiple_statements
100
100
  @db.query("insert into t values ('a', 'b', 'c'); insert into t values ('d', 'e', 'f');")
101
101
 
102
- assert_equal [1, 4, 'a', 'd'], @db.query_argv('select x from t order by x')
102
+ assert_equal [1, 4, 'a', 'd'], @db.query_splat('select x from t order by x')
103
103
  end
104
104
 
105
105
  def test_multiple_statements_with_error
@@ -123,13 +123,13 @@ class DatabaseTest < Minitest::Test
123
123
 
124
124
  def test_close
125
125
  assert_equal false, @db.closed?
126
- r = @db.query_single_argv('select 42')
126
+ r = @db.query_single_splat('select 42')
127
127
  assert_equal 42, r
128
128
 
129
129
  assert_equal @db, @db.close
130
130
  assert_equal true, @db.closed?
131
131
 
132
- assert_raises(Extralite::Error) { @db.query_single_argv('select 42') }
132
+ assert_raises(Extralite::Error) { @db.query_single_splat('select 42') }
133
133
  end
134
134
 
135
135
  def test_parameter_binding_simple
@@ -139,7 +139,7 @@ class DatabaseTest < Minitest::Test
139
139
  r = @db.query('select x, y, z from t where z = ?', 6)
140
140
  assert_equal [{ x: 4, y: 5, z: 6 }], r
141
141
 
142
- error = assert_raises(Extralite::ParameterError) { @db.query_single_argv('select ?', Date.today) }
142
+ error = assert_raises(Extralite::ParameterError) { @db.query_single_splat('select ?', Date.today) }
143
143
  assert_equal error.message, 'Cannot bind parameter at position 1 of type Date'
144
144
  end
145
145
 
@@ -173,24 +173,24 @@ class DatabaseTest < Minitest::Test
173
173
  class Foo; end
174
174
 
175
175
  def test_parameter_binding_from_hash
176
- assert_equal 42, @db.query_single_argv('select :bar', foo: 41, bar: 42)
177
- assert_equal 42, @db.query_single_argv('select :bar', 'foo' => 41, 'bar' => 42)
178
- assert_equal 42, @db.query_single_argv('select ?8', 7 => 41, 8 => 42)
179
- assert_nil @db.query_single_argv('select :bar', foo: 41)
176
+ assert_equal 42, @db.query_single_splat('select :bar', foo: 41, bar: 42)
177
+ assert_equal 42, @db.query_single_splat('select :bar', 'foo' => 41, 'bar' => 42)
178
+ assert_equal 42, @db.query_single_splat('select ?8', 7 => 41, 8 => 42)
179
+ assert_nil @db.query_single_splat('select :bar', foo: 41)
180
180
 
181
- error = assert_raises(Extralite::ParameterError) { @db.query_single_argv('select ?', Foo.new => 42) }
181
+ error = assert_raises(Extralite::ParameterError) { @db.query_single_splat('select ?', Foo.new => 42) }
182
182
  assert_equal error.message, 'Cannot bind parameter with a key of type DatabaseTest::Foo'
183
183
 
184
- error = assert_raises(Extralite::ParameterError) { @db.query_single_argv('select ?', %w[a b] => 42) }
184
+ error = assert_raises(Extralite::ParameterError) { @db.query_single_splat('select ?', %w[a b] => 42) }
185
185
  assert_equal error.message, 'Cannot bind parameter with a key of type Array'
186
186
  end
187
187
 
188
188
  def test_parameter_binding_from_struct
189
189
  foo_bar = Struct.new(:':foo', :bar)
190
190
  value = foo_bar.new(41, 42)
191
- assert_equal 41, @db.query_single_argv('select :foo', value)
192
- assert_equal 42, @db.query_single_argv('select :bar', value)
193
- assert_nil @db.query_single_argv('select :baz', value)
191
+ assert_equal 41, @db.query_single_splat('select :foo', value)
192
+ assert_equal 42, @db.query_single_splat('select :bar', value)
193
+ assert_nil @db.query_single_splat('select :baz', value)
194
194
  end
195
195
 
196
196
  def test_parameter_binding_from_data_class
@@ -198,8 +198,8 @@ class DatabaseTest < Minitest::Test
198
198
 
199
199
  foo_bar = Data.define(:':foo', :bar)
200
200
  value = foo_bar.new(':foo': 41, bar: 42)
201
- assert_equal 42, @db.query_single_argv('select :bar', value)
202
- assert_nil @db.query_single_argv('select :baz', value)
201
+ assert_equal 42, @db.query_single_splat('select :bar', value)
202
+ assert_nil @db.query_single_splat('select :baz', value)
203
203
  end
204
204
 
205
205
  def test_parameter_binding_for_blobs
@@ -235,43 +235,43 @@ class DatabaseTest < Minitest::Test
235
235
  end
236
236
 
237
237
  def test_parameter_binding_for_simple_types
238
- assert_nil @db.query_single_argv('select ?', nil)
238
+ assert_nil @db.query_single_splat('select ?', nil)
239
239
 
240
240
  # 32-bit integers
241
- assert_equal(-2** 31, @db.query_single_argv('select ?', -2**31))
242
- assert_equal(2**31 - 1, @db.query_single_argv('select ?', 2**31 - 1))
241
+ assert_equal(-2** 31, @db.query_single_splat('select ?', -2**31))
242
+ assert_equal(2**31 - 1, @db.query_single_splat('select ?', 2**31 - 1))
243
243
 
244
244
  # 64-bit integers
245
- assert_equal(-2 ** 63, @db.query_single_argv('select ?', -2 ** 63))
246
- assert_equal(2**63 - 1, @db.query_single_argv('select ?', 2**63 - 1))
245
+ assert_equal(-2 ** 63, @db.query_single_splat('select ?', -2 ** 63))
246
+ assert_equal(2**63 - 1, @db.query_single_splat('select ?', 2**63 - 1))
247
247
 
248
248
  # floats
249
- assert_equal Float::MIN, @db.query_single_argv('select ?', Float::MIN)
250
- assert_equal Float::MAX, @db.query_single_argv('select ?', Float::MAX)
249
+ assert_equal Float::MIN, @db.query_single_splat('select ?', Float::MIN)
250
+ assert_equal Float::MAX, @db.query_single_splat('select ?', Float::MAX)
251
251
 
252
252
  # boolean
253
- assert_equal 1, @db.query_single_argv('select ?', true)
254
- assert_equal 0, @db.query_single_argv('select ?', false)
253
+ assert_equal 1, @db.query_single_splat('select ?', true)
254
+ assert_equal 0, @db.query_single_splat('select ?', false)
255
255
 
256
256
  # strings and symbols
257
- assert_equal 'foo', @db.query_single_argv('select ?', 'foo')
258
- assert_equal 'foo', @db.query_single_argv('select ?', :foo)
257
+ assert_equal 'foo', @db.query_single_splat('select ?', 'foo')
258
+ assert_equal 'foo', @db.query_single_splat('select ?', :foo)
259
259
  end
260
260
 
261
261
  def test_value_casting
262
- r = @db.query_single_argv("select 'abc'")
262
+ r = @db.query_single_splat("select 'abc'")
263
263
  assert_equal 'abc', r
264
264
 
265
- r = @db.query_single_argv('select 123')
265
+ r = @db.query_single_splat('select 123')
266
266
  assert_equal 123, r
267
267
 
268
- r = @db.query_single_argv('select 12.34')
268
+ r = @db.query_single_splat('select 12.34')
269
269
  assert_equal 12.34, r
270
270
 
271
- r = @db.query_single_argv('select zeroblob(4)')
271
+ r = @db.query_single_splat('select zeroblob(4)')
272
272
  assert_equal "\x00\x00\x00\x00", r
273
273
 
274
- r = @db.query_single_argv('select null')
274
+ r = @db.query_single_splat('select null')
275
275
  assert_nil r
276
276
  end
277
277
 
@@ -283,7 +283,7 @@ class DatabaseTest < Minitest::Test
283
283
  @db.load_extension(File.join(__dir__, 'extensions/text.dylib'))
284
284
  end
285
285
 
286
- r = @db.query_single_argv("select reverse('abcd')")
286
+ r = @db.query_single_splat("select reverse('abcd')")
287
287
  assert_equal 'dcba', r
288
288
  end
289
289
 
@@ -342,13 +342,13 @@ class DatabaseTest < Minitest::Test
342
342
  def test_execute_with_params
343
343
  changes = @db.execute('update t set x = ? where z = ?', 42, 6)
344
344
  assert_equal 1, changes
345
- assert_equal [[1, 2, 3], [42, 5, 6]], @db.query_ary('select * from t order by x')
345
+ assert_equal [[1, 2, 3], [42, 5, 6]], @db.query_array('select * from t order by x')
346
346
  end
347
347
 
348
348
  def test_execute_with_params_array
349
349
  changes = @db.execute('update t set x = ? where z = ?', [42, 6])
350
350
  assert_equal 1, changes
351
- assert_equal [[1, 2, 3], [42, 5, 6]], @db.query_ary('select * from t order by x')
351
+ assert_equal [[1, 2, 3], [42, 5, 6]], @db.query_array('select * from t order by x')
352
352
  end
353
353
 
354
354
  def test_batch_execute
@@ -513,7 +513,7 @@ class DatabaseTest < Minitest::Test
513
513
  ], array
514
514
  end
515
515
 
516
- def test_batch_query_ary_with_array
516
+ def test_batch_query_array_with_array
517
517
  @db.query('create table foo (a, b, c)')
518
518
  assert_equal [], @db.query('select * from foo')
519
519
 
@@ -521,20 +521,20 @@ class DatabaseTest < Minitest::Test
521
521
  [1, '2', 3],
522
522
  ['4', 5, 6]
523
523
  ]
524
- results = @db.batch_query_ary('insert into foo values (?, ?, ?) returning *', data)
524
+ results = @db.batch_query_array('insert into foo values (?, ?, ?) returning *', data)
525
525
  assert_equal [
526
526
  [[1, '2', 3]],
527
527
  [['4', 5, 6]]
528
528
  ], results
529
529
 
530
- results = @db.batch_query_ary('update foo set c = ? returning *', [42, 43])
530
+ results = @db.batch_query_array('update foo set c = ? returning *', [42, 43])
531
531
  assert_equal [
532
532
  [[1, '2', 42], ['4', 5, 42]],
533
533
  [[1, '2', 43], ['4', 5, 43]]
534
534
  ], results
535
535
 
536
536
  array = []
537
- changes = @db.batch_query_ary('update foo set c = ? returning *', [44, 45]) do |rows|
537
+ changes = @db.batch_query_array('update foo set c = ? returning *', [44, 45]) do |rows|
538
538
  array << rows
539
539
  end
540
540
  assert_equal 4, changes
@@ -544,25 +544,25 @@ class DatabaseTest < Minitest::Test
544
544
  ], array
545
545
  end
546
546
 
547
- def test_batch_query_ary_with_enumerable
547
+ def test_batch_query_array_with_enumerable
548
548
  @db.query('create table foo (a integer primary key, b)')
549
549
  assert_equal [], @db.query('select * from foo')
550
550
 
551
- results = @db.batch_query_ary('insert into foo (b) values (?) returning *', 11..13)
551
+ results = @db.batch_query_array('insert into foo (b) values (?) returning *', 11..13)
552
552
  assert_equal [
553
553
  [[1, 11]],
554
554
  [[2, 12]],
555
555
  [[3, 13]]
556
556
  ], results
557
557
 
558
- results = @db.batch_query_ary('update foo set b = ? returning *', [42, 43])
558
+ results = @db.batch_query_array('update foo set b = ? returning *', [42, 43])
559
559
  assert_equal [
560
560
  [[1, 42], [2, 42], [3, 42]],
561
561
  [[1, 43], [2, 43], [3, 43]]
562
562
  ], results
563
563
 
564
564
  array = []
565
- changes = @db.batch_query_ary('update foo set b = ? returning *', [44, 45]) do |rows|
565
+ changes = @db.batch_query_array('update foo set b = ? returning *', [44, 45]) do |rows|
566
566
  array << rows
567
567
  end
568
568
  assert_equal 6, changes
@@ -572,13 +572,13 @@ class DatabaseTest < Minitest::Test
572
572
  ], array
573
573
  end
574
574
 
575
- def test_batch_query_ary_with_proc
575
+ def test_batch_query_array_with_proc
576
576
  @db.query('create table foo (a integer primary key, b)')
577
577
  assert_equal [], @db.query('select * from foo')
578
578
 
579
579
  pr = parameter_source_proc([5, 4, 3])
580
580
  assert_kind_of Proc, pr
581
- results = @db.batch_query_ary('insert into foo (b) values (?) returning *', pr)
581
+ results = @db.batch_query_array('insert into foo (b) values (?) returning *', pr)
582
582
  assert_equal [
583
583
  [[1, 5]],
584
584
  [[2, 4]],
@@ -586,7 +586,7 @@ class DatabaseTest < Minitest::Test
586
586
  ], results
587
587
 
588
588
  pr = parameter_source_proc([42, 43])
589
- results = @db.batch_query_ary('update foo set b = ? returning *', pr)
589
+ results = @db.batch_query_array('update foo set b = ? returning *', pr)
590
590
  assert_equal [
591
591
  [[1, 42], [2, 42], [3, 42]],
592
592
  [[1, 43], [2, 43], [3, 43]]
@@ -594,7 +594,7 @@ class DatabaseTest < Minitest::Test
594
594
 
595
595
  array = []
596
596
  pr = parameter_source_proc([44, 45])
597
- changes = @db.batch_query_ary('update foo set b = ? returning *', pr) do |rows|
597
+ changes = @db.batch_query_array('update foo set b = ? returning *', pr) do |rows|
598
598
  array << rows
599
599
  end
600
600
  assert_equal 6, changes
@@ -604,7 +604,7 @@ class DatabaseTest < Minitest::Test
604
604
  ], array
605
605
  end
606
606
 
607
- def test_batch_query_argv_with_array
607
+ def test_batch_query_splat_with_array
608
608
  @db.query('create table foo (a, b, c)')
609
609
  assert_equal [], @db.query('select * from foo')
610
610
 
@@ -612,20 +612,20 @@ class DatabaseTest < Minitest::Test
612
612
  [1, '2', 3],
613
613
  ['4', 5, 6]
614
614
  ]
615
- results = @db.batch_query_argv('insert into foo values (?, ?, ?) returning c', data)
615
+ results = @db.batch_query_splat('insert into foo values (?, ?, ?) returning c', data)
616
616
  assert_equal [
617
617
  [3],
618
618
  [6]
619
619
  ], results
620
620
 
621
- results = @db.batch_query_argv('update foo set c = ? returning c * 10 + cast(b as integer)', [42, 43])
621
+ results = @db.batch_query_splat('update foo set c = ? returning c * 10 + cast(b as integer)', [42, 43])
622
622
  assert_equal [
623
623
  [422, 425],
624
624
  [432, 435]
625
625
  ], results
626
626
 
627
627
  array = []
628
- changes = @db.batch_query_argv('update foo set c = ? returning c * 10 + cast(b as integer)', [44, 45]) do |rows|
628
+ changes = @db.batch_query_splat('update foo set c = ? returning c * 10 + cast(b as integer)', [44, 45]) do |rows|
629
629
  array << rows
630
630
  end
631
631
  assert_equal 4, changes
@@ -635,25 +635,25 @@ class DatabaseTest < Minitest::Test
635
635
  ], array
636
636
  end
637
637
 
638
- def test_batch_query_argv_with_enumerable
638
+ def test_batch_query_splat_with_enumerable
639
639
  @db.query('create table foo (a integer primary key, b)')
640
640
  assert_equal [], @db.query('select * from foo')
641
641
 
642
- results = @db.batch_query_argv('insert into foo (b) values (?) returning b * 10 + a', 11..13)
642
+ results = @db.batch_query_splat('insert into foo (b) values (?) returning b * 10 + a', 11..13)
643
643
  assert_equal [
644
644
  [111],
645
645
  [122],
646
646
  [133]
647
647
  ], results
648
648
 
649
- results = @db.batch_query_argv('update foo set b = ? returning b * 10 + a', 42..43)
649
+ results = @db.batch_query_splat('update foo set b = ? returning b * 10 + a', 42..43)
650
650
  assert_equal [
651
651
  [421, 422, 423],
652
652
  [431, 432, 433]
653
653
  ], results
654
654
 
655
655
  array = []
656
- changes = @db.batch_query_argv('update foo set b = ? returning b * 10 + a', 44..45) do |rows|
656
+ changes = @db.batch_query_splat('update foo set b = ? returning b * 10 + a', 44..45) do |rows|
657
657
  array << rows
658
658
  end
659
659
  assert_equal 6, changes
@@ -663,13 +663,13 @@ class DatabaseTest < Minitest::Test
663
663
  ], array
664
664
  end
665
665
 
666
- def test_batch_query_argv_with_proc
666
+ def test_batch_query_splat_with_proc
667
667
  @db.query('create table foo (a integer primary key, b)')
668
668
  assert_equal [], @db.query('select * from foo')
669
669
 
670
670
  pr = parameter_source_proc([5, 4, 3])
671
671
  assert_kind_of Proc, pr
672
- results = @db.batch_query_argv('insert into foo (b) values (?) returning b', pr)
672
+ results = @db.batch_query_splat('insert into foo (b) values (?) returning b', pr)
673
673
  assert_equal [
674
674
  [5],
675
675
  [4],
@@ -677,7 +677,7 @@ class DatabaseTest < Minitest::Test
677
677
  ], results
678
678
 
679
679
  pr = parameter_source_proc([42, 43])
680
- results = @db.batch_query_argv('update foo set b = ? returning b * 10 + a', pr)
680
+ results = @db.batch_query_splat('update foo set b = ? returning b * 10 + a', pr)
681
681
  assert_equal [
682
682
  [421, 422, 423],
683
683
  [431, 432, 433]
@@ -685,7 +685,7 @@ class DatabaseTest < Minitest::Test
685
685
 
686
686
  array = []
687
687
  pr = parameter_source_proc([44, 45])
688
- changes = @db.batch_query_argv('update foo set b = ? returning b * 10 + a', pr) do |rows|
688
+ changes = @db.batch_query_splat('update foo set b = ? returning b * 10 + a', pr) do |rows|
689
689
  array << rows
690
690
  end
691
691
  assert_equal 6, changes
@@ -857,7 +857,7 @@ class DatabaseTest < Minitest::Test
857
857
 
858
858
  def test_string_encoding
859
859
  db = Extralite::Database.new(':memory:')
860
- v = db.query_single_argv("select 'foo'")
860
+ v = db.query_single_splat("select 'foo'")
861
861
  assert_equal 'foo', v
862
862
  assert_equal 'UTF-8', v.encoding.name
863
863
  end
@@ -942,24 +942,24 @@ class DatabaseTest < Minitest::Test
942
942
  assert_equal [], db.query('select * from foo')
943
943
 
944
944
  db.execute('insert into foo values (42)')
945
- assert_equal [42], db.query_argv('select x from foo')
945
+ assert_equal [42], db.query_splat('select x from foo')
946
946
 
947
947
  db.savepoint(:a)
948
948
 
949
949
  db.execute('insert into foo values (43)')
950
- assert_equal [42, 43], db.query_argv('select x from foo')
950
+ assert_equal [42, 43], db.query_splat('select x from foo')
951
951
 
952
952
  db.savepoint(:b)
953
953
 
954
954
  db.execute('insert into foo values (44)')
955
- assert_equal [42, 43, 44], db.query_argv('select x from foo')
955
+ assert_equal [42, 43, 44], db.query_splat('select x from foo')
956
956
 
957
957
  db.rollback_to(:b)
958
- assert_equal [42, 43], db.query_argv('select x from foo')
958
+ assert_equal [42, 43], db.query_splat('select x from foo')
959
959
 
960
960
  db.release(:a)
961
961
 
962
- assert_equal [42, 43], db.query_argv('select x from foo')
962
+ assert_equal [42, 43], db.query_splat('select x from foo')
963
963
  end
964
964
  end
965
965
 
@@ -973,8 +973,8 @@ class DatabaseTest < Minitest::Test
973
973
  ], q.to_a
974
974
  end
975
975
 
976
- def test_prepare_argv
977
- q = @db.prepare_argv('select * from t order by x')
976
+ def test_prepare_splat
977
+ q = @db.prepare_splat('select * from t order by x')
978
978
  assert_kind_of Extralite::Query, q
979
979
 
980
980
  buf = []
@@ -982,8 +982,8 @@ class DatabaseTest < Minitest::Test
982
982
  assert_equal [3, 6], buf
983
983
  end
984
984
 
985
- def test_prepare_ary
986
- q = @db.prepare_ary('select * from t order by x')
985
+ def test_prepare_array
986
+ q = @db.prepare_array('select * from t order by x')
987
987
  assert_kind_of Extralite::Query, q
988
988
 
989
989
  assert_equal [
@@ -1000,21 +1000,52 @@ class DatabaseTest < Minitest::Test
1000
1000
  ], q.to_a
1001
1001
  end
1002
1002
 
1003
- def test_prepare_argv_with_transform
1004
- q = @db.prepare_argv('select * from t order by x') { |x, y, z| x * 100 + y * 10 + z }
1003
+ def test_prepare_splat_with_transform
1004
+ q = @db.prepare_splat('select * from t order by x') { |x, y, z| x * 100 + y * 10 + z }
1005
1005
  assert_equal [
1006
1006
  123,
1007
1007
  456
1008
1008
  ], q.to_a
1009
1009
  end
1010
1010
 
1011
- def test_prepare_ary_with_transform
1012
- q = @db.prepare_ary('select * from t order by x') { |r| r * 2 }
1011
+ def test_prepare_array_with_transform
1012
+ q = @db.prepare_array('select * from t order by x') { |r| r * 2 }
1013
1013
  assert_equal [
1014
1014
  [1, 2, 3, 1, 2, 3],
1015
1015
  [4, 5, 6, 4, 5, 6]
1016
1016
  ], q.to_a
1017
1017
  end
1018
+
1019
+ def test_wal_checkpoint
1020
+ fn = Tempfile.new('extralite_test_wal_checkpoint').path
1021
+
1022
+ db = Extralite::Database.new(fn, wal: true)
1023
+
1024
+ db.execute 'create table t (x, y, z)'
1025
+ rows = (1..1000).map { [rand, rand, rand] }
1026
+ db.batch_execute('insert into t values (?, ?, ?)', rows)
1027
+
1028
+ wal_fn = "#{fn}-wal"
1029
+
1030
+ assert File.exist?(wal_fn)
1031
+ assert File.size(wal_fn) > 0
1032
+
1033
+ # invalid mode
1034
+ assert_raises(ArgumentError) { db.wal_checkpoint(:foo) }
1035
+
1036
+ # invalid db name
1037
+ assert_raises(Extralite::Error) { db.wal_checkpoint(:passive, 'foo') }
1038
+
1039
+ r = db.wal_checkpoint(:full)
1040
+ assert File.exist?(wal_fn)
1041
+ assert File.size(wal_fn) > 0
1042
+ assert_equal [19, 19], r
1043
+
1044
+ r = db.wal_checkpoint(:truncate)
1045
+ assert File.exist?(wal_fn)
1046
+ assert File.size(wal_fn) == 0
1047
+ assert_equal [0, 0], r
1048
+ end
1018
1049
  end
1019
1050
 
1020
1051
  class ScenarioTest < Minitest::Test
@@ -1046,7 +1077,7 @@ class ScenarioTest < Minitest::Test
1046
1077
 
1047
1078
  sleep 0.1
1048
1079
  @db.query 'begin deferred'
1049
- result = @db.query_argv('select x from t')
1080
+ result = @db.query_splat('select x from t')
1050
1081
  assert_equal [1, 4], result
1051
1082
 
1052
1083
  assert_raises(Extralite::BusyError) do
@@ -1080,7 +1111,7 @@ class ScenarioTest < Minitest::Test
1080
1111
  @db.query('insert into t values (7, 8, 9)')
1081
1112
  @db.query('commit')
1082
1113
 
1083
- result = @db.query_argv('select x from t')
1114
+ result = @db.query_splat('select x from t')
1084
1115
  assert_equal [1, 4, 7], result
1085
1116
  ensure
1086
1117
  t&.kill
@@ -1109,7 +1140,7 @@ class ScenarioTest < Minitest::Test
1109
1140
  t1.join
1110
1141
  t2.join
1111
1142
 
1112
- assert_equal (1..100).to_a, @db.query_argv('select x from t order by x')
1143
+ assert_equal (1..100).to_a, @db.query_splat('select x from t order by x')
1113
1144
  ensure
1114
1145
  t1&.kill
1115
1146
  t2&.kill
@@ -1153,19 +1184,19 @@ class BackupTest < Minitest::Test
1153
1184
 
1154
1185
  def test_backup
1155
1186
  @src.backup(@dst)
1156
- assert_equal [[1, 2, 3], [4, 5, 6]], @dst.query_ary('select * from t')
1187
+ assert_equal [[1, 2, 3], [4, 5, 6]], @dst.query_array('select * from t')
1157
1188
  end
1158
1189
 
1159
1190
  def test_backup_with_block
1160
1191
  progress = []
1161
1192
  @src.backup(@dst) { |r, t| progress << [r, t] }
1162
- assert_equal [[1, 2, 3], [4, 5, 6]], @dst.query_ary('select * from t')
1193
+ assert_equal [[1, 2, 3], [4, 5, 6]], @dst.query_array('select * from t')
1163
1194
  assert_equal [[2, 2]], progress
1164
1195
  end
1165
1196
 
1166
1197
  def test_backup_with_schema_names
1167
1198
  @src.backup(@dst, 'main', 'temp')
1168
- assert_equal [[1, 2, 3], [4, 5, 6]], @dst.query_ary('select * from temp.t')
1199
+ assert_equal [[1, 2, 3], [4, 5, 6]], @dst.query_array('select * from temp.t')
1169
1200
  end
1170
1201
 
1171
1202
  def test_backup_with_fn
@@ -1173,7 +1204,7 @@ class BackupTest < Minitest::Test
1173
1204
  @src.backup(tmp_fn)
1174
1205
 
1175
1206
  db = Extralite::Database.new(tmp_fn)
1176
- assert_equal [[1, 2, 3], [4, 5, 6]], db.query_ary('select * from t')
1207
+ assert_equal [[1, 2, 3], [4, 5, 6]], db.query_array('select * from t')
1177
1208
  end
1178
1209
  end
1179
1210
 
@@ -1620,7 +1651,7 @@ class RactorTest < Minitest::Test
1620
1651
  r << 42
1621
1652
  r.take # wait for ractor to terminate
1622
1653
 
1623
- assert_equal 42, db.query_single_argv('select x from foo')
1654
+ assert_equal 42, db.query_single_splat('select x from foo')
1624
1655
  end
1625
1656
 
1626
1657
  # Adapted from here: https://github.com/sparklemotion/sqlite3-ruby/pull/365/files
@@ -1681,7 +1712,7 @@ class RactorTest < Minitest::Test
1681
1712
 
1682
1713
  final_check = Ractor.new(fn) do |rfn|
1683
1714
  rdb = Extralite::Database.new(rfn, wal: true)
1684
- count = rdb.query_single_argv('select count(*) from stress_test')
1715
+ count = rdb.query_single_splat('select count(*) from stress_test')
1685
1716
  Ractor.yield count
1686
1717
  end
1687
1718
  count = final_check.take
@@ -1739,15 +1770,15 @@ class DatabaseTransformTest < Minitest::Test
1739
1770
  ], buf
1740
1771
  end
1741
1772
 
1742
- def test_query_ary_transform
1773
+ def test_query_array_transform
1743
1774
  transform = ->(h) { MyModel.new(h) }
1744
1775
 
1745
1776
  sql = 'select a, b from t where a = ?'
1746
- o = @db.query_ary(transform, sql, 1).first
1777
+ o = @db.query_array(transform, sql, 1).first
1747
1778
  assert_kind_of MyModel, o
1748
1779
  assert_equal([1, 2], o.values)
1749
1780
 
1750
- o = @db.query_ary(transform, sql, 4).first
1781
+ o = @db.query_array(transform, sql, 4).first
1751
1782
  assert_kind_of MyModel, o
1752
1783
  assert_equal([4, 5], o.values)
1753
1784
 
@@ -1755,10 +1786,10 @@ class DatabaseTransformTest < Minitest::Test
1755
1786
  assert_equal [
1756
1787
  [1, 2],
1757
1788
  [4, 5]
1758
- ], @db.query_ary(transform, sql).map(&:values)
1789
+ ], @db.query_array(transform, sql).map(&:values)
1759
1790
 
1760
1791
  buf = []
1761
- @db.query_ary(transform, sql) { |r| buf << r.values }
1792
+ @db.query_array(transform, sql) { |r| buf << r.values }
1762
1793
  assert_equal [
1763
1794
  [1, 2],
1764
1795
  [4, 5]
@@ -1778,74 +1809,74 @@ class DatabaseTransformTest < Minitest::Test
1778
1809
  assert_equal({ a: 4, b: 5 }, o.values)
1779
1810
  end
1780
1811
 
1781
- def test_query_ary_single_row_transform
1812
+ def test_query_array_single_row_transform
1782
1813
  transform = ->(h) { MyModel.new(h) }
1783
1814
 
1784
1815
  sql = 'select a, b from t where a = ?'
1785
- o = @db.query_single_ary(transform, sql, 1)
1816
+ o = @db.query_single_array(transform, sql, 1)
1786
1817
  assert_kind_of MyModel, o
1787
1818
  assert_equal([1, 2], o.values)
1788
1819
 
1789
- o = @db.query_single_ary(transform, sql, 4)
1820
+ o = @db.query_single_array(transform, sql, 4)
1790
1821
  assert_kind_of MyModel, o
1791
1822
  assert_equal([4, 5], o.values)
1792
1823
  end
1793
1824
 
1794
- def test_query_argv_single_column_transform
1825
+ def test_query_splat_single_column_transform
1795
1826
  transform = ->(c) { JSON.parse(c, symbolize_names: true) }
1796
1827
  sql = 'select c from t where a = ?'
1797
1828
 
1798
- assert_equal([{ foo: 42, bar: 43 }], @db.query_argv(transform, sql, 1))
1799
- assert_equal([{ foo: 45, bar: 46 }], @db.query_argv(transform, sql, 4))
1829
+ assert_equal([{ foo: 42, bar: 43 }], @db.query_splat(transform, sql, 1))
1830
+ assert_equal([{ foo: 45, bar: 46 }], @db.query_splat(transform, sql, 4))
1800
1831
 
1801
1832
  sql = 'select c from t order by a'
1802
1833
  assert_equal [
1803
1834
  { foo: 42, bar: 43 },
1804
1835
  { foo: 45, bar: 46 }
1805
- ], @db.query_argv(transform, sql)
1836
+ ], @db.query_splat(transform, sql)
1806
1837
 
1807
1838
  buf = []
1808
- @db.query_argv(transform, sql) { |r| buf << r }
1839
+ @db.query_splat(transform, sql) { |r| buf << r }
1809
1840
  assert_equal [
1810
1841
  { foo: 42, bar: 43 },
1811
1842
  { foo: 45, bar: 46 }
1812
1843
  ], buf
1813
1844
  end
1814
1845
 
1815
- def test_query_argv_single_row_single_column
1846
+ def test_query_splat_single_row_single_column
1816
1847
  transform = ->(c) { JSON.parse(c, symbolize_names: true) }
1817
1848
  sql = 'select c from t where a = ?'
1818
1849
 
1819
- assert_equal({ foo: 42, bar: 43 }, @db.query_single_argv(transform, sql, 1))
1820
- assert_equal({ foo: 45, bar: 46 }, @db.query_single_argv(transform, sql, 4))
1850
+ assert_equal({ foo: 42, bar: 43 }, @db.query_single_splat(transform, sql, 1))
1851
+ assert_equal({ foo: 45, bar: 46 }, @db.query_single_splat(transform, sql, 4))
1821
1852
  end
1822
1853
 
1823
- def test_query_argv_multi_column
1854
+ def test_query_splat_multi_column
1824
1855
  transform = ->(a, b, c) { { a: a, b: b, c: JSON.parse(c, symbolize_names: true) } }
1825
1856
  sql = 'select * from t where a = ?'
1826
1857
 
1827
- assert_equal([{ a: 1, b: 2, c: { foo: 42, bar: 43 }}], @db.query_argv(transform, sql, 1))
1828
- assert_equal([{ a: 4, b: 5, c: { foo: 45, bar: 46 }}], @db.query_argv(transform, sql, 4))
1858
+ assert_equal([{ a: 1, b: 2, c: { foo: 42, bar: 43 }}], @db.query_splat(transform, sql, 1))
1859
+ assert_equal([{ a: 4, b: 5, c: { foo: 45, bar: 46 }}], @db.query_splat(transform, sql, 4))
1829
1860
 
1830
1861
  sql = 'select * from t order by a'
1831
1862
  assert_equal [
1832
1863
  { a: 1, b: 2, c: { foo: 42, bar: 43 }},
1833
1864
  { a: 4, b: 5, c: { foo: 45, bar: 46 }}
1834
- ], @db.query_argv(transform, sql)
1865
+ ], @db.query_splat(transform, sql)
1835
1866
 
1836
1867
  buf = []
1837
- @db.query_argv(transform, sql) { |r| buf << r }
1868
+ @db.query_splat(transform, sql) { |r| buf << r }
1838
1869
  assert_equal [
1839
1870
  { a: 1, b: 2, c: { foo: 42, bar: 43 }},
1840
1871
  { a: 4, b: 5, c: { foo: 45, bar: 46 }}
1841
1872
  ], buf
1842
1873
  end
1843
1874
 
1844
- def test_query_argv_single_row_multi_column
1875
+ def test_query_splat_single_row_multi_column
1845
1876
  transform = ->(a, b, c) { { a: a, b: b, c: JSON.parse(c, symbolize_names: true) } }
1846
1877
  sql = 'select * from t where a = ?'
1847
1878
 
1848
- assert_equal({ a: 1, b: 2, c: { foo: 42, bar: 43 }}, @db.query_single_argv(transform, sql, 1))
1849
- assert_equal({ a: 4, b: 5, c: { foo: 45, bar: 46 }}, @db.query_single_argv(transform, sql, 4))
1879
+ assert_equal({ a: 1, b: 2, c: { foo: 42, bar: 43 }}, @db.query_single_splat(transform, sql, 1))
1880
+ assert_equal({ a: 4, b: 5, c: { foo: 45, bar: 46 }}, @db.query_single_splat(transform, sql, 4))
1850
1881
  end
1851
1882
  end