extralite-bundle 2.3 → 2.4

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_query.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'helper'
4
+ require 'date'
4
5
 
5
6
  class QueryTest < MiniTest::Test
6
7
  def setup
@@ -267,7 +268,7 @@ class QueryTest < MiniTest::Test
267
268
  end
268
269
 
269
270
  def test_query_each_without_block
270
- query = @db.prepare('select * from t')
271
+ query = @db.prepare('select * from t')
271
272
  iter = query.each
272
273
  assert_kind_of Extralite::Iterator, iter
273
274
 
@@ -294,7 +295,7 @@ class QueryTest < MiniTest::Test
294
295
  end
295
296
 
296
297
  def test_query_each_ary_without_block
297
- query = @db.prepare('select * from t')
298
+ query = @db.prepare('select * from t')
298
299
  iter = query.each_ary
299
300
  assert_kind_of Extralite::Iterator, iter
300
301
 
@@ -322,7 +323,7 @@ class QueryTest < MiniTest::Test
322
323
  end
323
324
 
324
325
  def test_query_each_single_column_without_block
325
- query = @db.prepare('select x from t')
326
+ query = @db.prepare('select x from t')
326
327
  iter = query.each_single_column
327
328
  assert_kind_of Extralite::Iterator, iter
328
329
 
@@ -375,6 +376,9 @@ class QueryTest < MiniTest::Test
375
376
  def test_query_parameter_binding_simple
376
377
  r = @db.prepare('select x, y, z from t where x = ?').bind(1).next
377
378
  assert_equal({ x: 1, y: 2, z: 3 }, r)
379
+
380
+ error = assert_raises(Extralite::ParameterError) { @db.prepare('select ?').bind(Date.today).next }
381
+ assert_equal error.message, 'Cannot bind parameter at position 1 of type Date'
378
382
  end
379
383
 
380
384
  def test_query_parameter_binding_with_index
@@ -404,6 +408,38 @@ class QueryTest < MiniTest::Test
404
408
  assert_equal({ x: 4, y: 5, z: 6 }, r)
405
409
  end
406
410
 
411
+ class Foo; end
412
+
413
+ def test_parameter_binding_from_hash
414
+ assert_equal 42, @db.prepare('select :bar').bind(foo: 41, bar: 42).next_single_column
415
+ assert_equal 42, @db.prepare('select :bar').bind('foo' => 41, 'bar' => 42).next_single_column
416
+ assert_equal 42, @db.prepare('select ?8').bind(7 => 41, 8 => 42).next_single_column
417
+ assert_nil @db.prepare('select :bar').bind(foo: 41).next_single_column
418
+
419
+ error = assert_raises(Extralite::ParameterError) { @db.prepare('select ?').bind(Foo.new => 42).next_single_column }
420
+ assert_equal error.message, 'Cannot bind parameter with a key of type QueryTest::Foo'
421
+
422
+ error = assert_raises(Extralite::ParameterError) { @db.prepare('select ?').bind(%w[a b] => 42).next_single_column }
423
+ assert_equal error.message, 'Cannot bind parameter with a key of type Array'
424
+ end
425
+
426
+ def test_parameter_binding_from_struct
427
+ foo_bar = Struct.new(:":foo", :bar)
428
+ value = foo_bar.new(41, 42)
429
+ assert_equal 41, @db.prepare('select :foo').bind(value).next_single_column
430
+ assert_equal 42, @db.prepare('select :bar').bind(value).next_single_column
431
+ assert_nil @db.prepare('select :baz').bind(value).next_single_column
432
+ end
433
+
434
+ def test_parameter_binding_from_data_class
435
+ skip "Data isn't supported in Ruby < 3.2" if RUBY_VERSION < '3.2'
436
+
437
+ foo_bar = Data.define(:":foo", :bar)
438
+ value = foo_bar.new(":foo": 41, bar: 42)
439
+ assert_equal 42, @db.prepare('select :bar').bind(value).next_single_column
440
+ assert_nil @db.prepare('select :baz').bind(value).next_single_column
441
+ end
442
+
407
443
  def test_query_columns
408
444
  r = @db.prepare("select 'abc' as a, 'def' as b").columns
409
445
  assert_equal [:a, :b], r
@@ -459,7 +495,7 @@ class QueryTest < MiniTest::Test
459
495
  { a: 1, b: '2', c: 3 },
460
496
  { a: '4', b: 5, c: 6 }
461
497
  ], @db.query('select * from foo')
462
- end
498
+ end
463
499
 
464
500
  def test_query_status
465
501
  assert_equal 0, @query.status(Extralite::SQLITE_STMTSTATUS_RUN)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extralite-bundle
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.3'
4
+ version: '2.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-12 00:00:00.000000000 Z
11
+ date: 2023-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -88,12 +88,14 @@ extensions:
88
88
  extra_rdoc_files:
89
89
  - README.md
90
90
  files:
91
+ - ".editorconfig"
91
92
  - ".github/FUNDING.yml"
92
93
  - ".github/workflows/test.yml"
93
94
  - ".gitignore"
94
95
  - ".yardopts"
95
96
  - CHANGELOG.md
96
97
  - Gemfile
98
+ - Gemfile-bundle
97
99
  - Gemfile.lock
98
100
  - LICENSE
99
101
  - README.md
@@ -120,7 +122,9 @@ files:
120
122
  - lib/sequel/adapters/extralite.rb
121
123
  - test/extensions/text.dylib
122
124
  - test/extensions/text.so
125
+ - test/fixtures/image.png
123
126
  - test/helper.rb
127
+ - test/issue-38.rb
124
128
  - test/perf_ary.rb
125
129
  - test/perf_hash.rb
126
130
  - test/perf_prepared.rb