extralite-bundle 2.4 → 2.5

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_query.rb CHANGED
@@ -478,7 +478,25 @@ class QueryTest < MiniTest::Test
478
478
  assert_equal [[1, 2, 3], [4, 5, 6], [42, 8, 9]], @db.query_ary('select * from t order by z')
479
479
  end
480
480
 
481
- def test_query_execute_multi
481
+ def test_query_execute_with_mixed_params
482
+ @db.execute 'delete from t'
483
+ q = @db.prepare('insert into t values (?, ?, ?)')
484
+
485
+ q.execute(1, [2], 3)
486
+ q.execute([4, 5], 6)
487
+ q.execute([7], 8, [9])
488
+
489
+ assert_equal [[1, 2, 3], [4, 5, 6], [7, 8, 9]], @db.query_ary('select * from t order by z')
490
+ end
491
+
492
+ def test_query_chverons
493
+ q = @db.prepare('update t set x = ? where z = ?')
494
+ assert_equal q, (q << [42, 9])
495
+ assert_equal [[1, 2, 3], [4, 5, 6], [42, 8, 9]], @db.query_ary('select * from t order by z')
496
+ end
497
+
498
+
499
+ def test_query_batch_execute
482
500
  @db.query('create table foo (a, b, c)')
483
501
  assert_equal [], @db.query('select * from foo')
484
502
 
@@ -488,7 +506,7 @@ class QueryTest < MiniTest::Test
488
506
  ]
489
507
 
490
508
  p = @db.prepare('insert into foo values (?, ?, ?)')
491
- changes = p.execute_multi(records)
509
+ changes = p.batch_execute(records)
492
510
 
493
511
  assert_equal 2, changes
494
512
  assert_equal [
@@ -497,6 +515,328 @@ class QueryTest < MiniTest::Test
497
515
  ], @db.query('select * from foo')
498
516
  end
499
517
 
518
+ def test_query_batch_execute_with_each_interface
519
+ @db.query('create table foo (a)')
520
+ assert_equal [], @db.query('select * from foo')
521
+
522
+ p = @db.prepare('insert into foo values (?)')
523
+ changes = p.batch_execute(1..3)
524
+
525
+ assert_equal 3, changes
526
+ assert_equal [
527
+ { a: 1 },
528
+ { a: 2 },
529
+ { a: 3 }
530
+ ], @db.query('select * from foo')
531
+ end
532
+
533
+ def test_query_batch_execute_with_proc
534
+ source = [42, 43, 44]
535
+
536
+ @db.query('create table foo (a)')
537
+ assert_equal [], @db.query('select * from foo')
538
+
539
+ p = @db.prepare('insert into foo values (?)')
540
+ pr = proc { source.shift }
541
+ changes = p.batch_execute(pr)
542
+
543
+ assert_equal 3, changes
544
+ assert_equal [
545
+ { a: 42 },
546
+ { a: 43 },
547
+ { a: 44 }
548
+ ], @db.query('select * from foo')
549
+ end
550
+
551
+ def test_query_batch_query_with_array
552
+ @db.query('create table foo (a integer primary key, b)')
553
+ assert_equal [], @db.query('select * from foo')
554
+
555
+ data = [5, 4, 3]
556
+ results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
557
+ assert_equal [
558
+ [[1, 5]],
559
+ [[2, 4]],
560
+ [[3, 3]]
561
+ ], results
562
+
563
+ q = @db.prepare('update foo set b = ? returning *')
564
+
565
+ results = q.batch_query([42, 43])
566
+ assert_equal [
567
+ [{ a: 1, b: 42 }, { a: 2, b: 42 }, { a: 3, b: 42 }],
568
+ [{ a: 1, b: 43 }, { a: 2, b: 43 }, { a: 3, b: 43 }]
569
+ ], results
570
+
571
+ array = []
572
+ changes = q.batch_query([44, 45]) do |rows|
573
+ array << rows
574
+ end
575
+ assert_equal 6, changes
576
+ assert_equal [
577
+ [{ a: 1, b: 44 }, { a: 2, b: 44 }, { a: 3, b: 44 }],
578
+ [{ a: 1, b: 45 }, { a: 2, b: 45 }, { a: 3, b: 45 }]
579
+ ], array
580
+ end
581
+
582
+ def test_query_batch_query_with_enumerable
583
+ @db.query('create table foo (a integer primary key, b)')
584
+ assert_equal [], @db.query('select * from foo')
585
+
586
+ data = [5, 4, 3]
587
+ results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
588
+ assert_equal [
589
+ [[1, 5]],
590
+ [[2, 4]],
591
+ [[3, 3]]
592
+ ], results
593
+
594
+ q = @db.prepare('update foo set b = ? returning *')
595
+
596
+ results = q.batch_query(42..43)
597
+ assert_equal [
598
+ [{ a: 1, b: 42 }, { a: 2, b: 42 }, { a: 3, b: 42 }],
599
+ [{ a: 1, b: 43 }, { a: 2, b: 43 }, { a: 3, b: 43 }]
600
+ ], results
601
+
602
+ array = []
603
+ changes = q.batch_query(44..45) do |rows|
604
+ array << rows
605
+ end
606
+ assert_equal 6, changes
607
+ assert_equal [
608
+ [{ a: 1, b: 44 }, { a: 2, b: 44 }, { a: 3, b: 44 }],
609
+ [{ a: 1, b: 45 }, { a: 2, b: 45 }, { a: 3, b: 45 }]
610
+ ], array
611
+ end
612
+
613
+ def parameter_source_proc(values)
614
+ proc { values.shift }
615
+ end
616
+
617
+ def test_query_batch_query_with_proc
618
+ @db.query('create table foo (a integer primary key, b)')
619
+ assert_equal [], @db.query('select * from foo')
620
+
621
+ data = [5, 4, 3]
622
+ results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
623
+ assert_equal [
624
+ [[1, 5]],
625
+ [[2, 4]],
626
+ [[3, 3]]
627
+ ], results
628
+
629
+ q = @db.prepare('update foo set b = ? returning *')
630
+
631
+ pr = parameter_source_proc([42, 43])
632
+ results = q.batch_query(pr)
633
+ assert_equal [
634
+ [{ a: 1, b: 42 }, { a: 2, b: 42 }, { a: 3, b: 42 }],
635
+ [{ a: 1, b: 43 }, { a: 2, b: 43 }, { a: 3, b: 43 }]
636
+ ], results
637
+
638
+ array = []
639
+ pr = parameter_source_proc([44, 45])
640
+ changes = q.batch_query(pr) do |rows|
641
+ array << rows
642
+ end
643
+ assert_equal 6, changes
644
+ assert_equal [
645
+ [{ a: 1, b: 44 }, { a: 2, b: 44 }, { a: 3, b: 44 }],
646
+ [{ a: 1, b: 45 }, { a: 2, b: 45 }, { a: 3, b: 45 }]
647
+ ], array
648
+ end
649
+
650
+ def test_query_batch_query_ary_with_array
651
+ @db.query('create table foo (a integer primary key, b)')
652
+ assert_equal [], @db.query('select * from foo')
653
+
654
+ data = [5, 4, 3]
655
+ results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
656
+ assert_equal [
657
+ [[1, 5]],
658
+ [[2, 4]],
659
+ [[3, 3]]
660
+ ], results
661
+
662
+ q = @db.prepare('update foo set b = ? returning *')
663
+
664
+ results = q.batch_query_ary([42, 43])
665
+ assert_equal [
666
+ [[1, 42], [2, 42], [3, 42]],
667
+ [[1, 43], [2, 43], [3, 43]]
668
+ ], results
669
+
670
+ array = []
671
+ changes = q.batch_query_ary([44, 45]) do |rows|
672
+ array << rows
673
+ end
674
+ assert_equal 6, changes
675
+ assert_equal [
676
+ [[1, 44], [2, 44], [3, 44]],
677
+ [[1, 45], [2, 45], [3, 45]]
678
+ ], array
679
+ end
680
+
681
+ def test_query_batch_query_ary_with_enumerable
682
+ @db.query('create table foo (a integer primary key, b)')
683
+ assert_equal [], @db.query('select * from foo')
684
+
685
+ data = [5, 4, 3]
686
+ results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
687
+ assert_equal [
688
+ [[1, 5]],
689
+ [[2, 4]],
690
+ [[3, 3]]
691
+ ], results
692
+
693
+ q = @db.prepare('update foo set b = ? returning *')
694
+
695
+ results = q.batch_query_ary(42..43)
696
+ assert_equal [
697
+ [[1, 42], [2, 42], [3, 42]],
698
+ [[1, 43], [2, 43], [3, 43]]
699
+ ], results
700
+
701
+ array = []
702
+ changes = q.batch_query_ary(44..45) do |rows|
703
+ array << rows
704
+ end
705
+ assert_equal 6, changes
706
+ assert_equal [
707
+ [[1, 44], [2, 44], [3, 44]],
708
+ [[1, 45], [2, 45], [3, 45]]
709
+ ], array
710
+ end
711
+
712
+ def test_query_batch_query_ary_with_proc
713
+ @db.query('create table foo (a integer primary key, b)')
714
+ assert_equal [], @db.query('select * from foo')
715
+
716
+ data = [5, 4, 3]
717
+ results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
718
+ assert_equal [
719
+ [[1, 5]],
720
+ [[2, 4]],
721
+ [[3, 3]]
722
+ ], results
723
+
724
+ q = @db.prepare('update foo set b = ? returning *')
725
+
726
+ pr = parameter_source_proc([42, 43])
727
+ results = q.batch_query_ary(pr)
728
+ assert_equal [
729
+ [[1, 42], [2, 42], [3, 42]],
730
+ [[1, 43], [2, 43], [3, 43]]
731
+ ], results
732
+
733
+ array = []
734
+ pr = parameter_source_proc([44, 45])
735
+ changes = q.batch_query_ary(pr) do |rows|
736
+ array << rows
737
+ end
738
+ assert_equal 6, changes
739
+ assert_equal [
740
+ [[1, 44], [2, 44], [3, 44]],
741
+ [[1, 45], [2, 45], [3, 45]]
742
+ ], array
743
+ end
744
+
745
+ def test_query_batch_query_single_column_with_array
746
+ @db.query('create table foo (a integer primary key, b)')
747
+ assert_equal [], @db.query('select * from foo')
748
+
749
+ data = [5, 4, 3]
750
+ results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
751
+ assert_equal [
752
+ [[1, 5]],
753
+ [[2, 4]],
754
+ [[3, 3]]
755
+ ], results
756
+
757
+ q = @db.prepare('update foo set b = ? returning b * 10 + a')
758
+
759
+ results = q.batch_query_single_column([42, 43])
760
+ assert_equal [
761
+ [421, 422, 423],
762
+ [431, 432, 433]
763
+ ], results
764
+
765
+ array = []
766
+ changes = q.batch_query_single_column([44, 45]) do |rows|
767
+ array << rows
768
+ end
769
+ assert_equal 6, changes
770
+ assert_equal [
771
+ [441, 442, 443],
772
+ [451, 452, 453]
773
+ ], array
774
+ end
775
+
776
+ def test_query_batch_query_single_column_with_enumerable
777
+ @db.query('create table foo (a integer primary key, b)')
778
+ assert_equal [], @db.query('select * from foo')
779
+
780
+ data = [5, 4, 3]
781
+ results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
782
+ assert_equal [
783
+ [[1, 5]],
784
+ [[2, 4]],
785
+ [[3, 3]]
786
+ ], results
787
+
788
+ q = @db.prepare('update foo set b = ? returning b * 10 + a')
789
+
790
+ results = q.batch_query_single_column(42..43)
791
+ assert_equal [
792
+ [421, 422, 423],
793
+ [431, 432, 433]
794
+ ], results
795
+
796
+ array = []
797
+ changes = q.batch_query_single_column(44..45) do |rows|
798
+ array << rows
799
+ end
800
+ assert_equal 6, changes
801
+ assert_equal [
802
+ [441, 442, 443],
803
+ [451, 452, 453]
804
+ ], array
805
+ end
806
+
807
+ def test_query_batch_query_single_column_with_proc
808
+ @db.query('create table foo (a integer primary key, b)')
809
+ assert_equal [], @db.query('select * from foo')
810
+
811
+ data = [5, 4, 3]
812
+ results = @db.batch_query_ary('insert into foo (b) values (?) returning *', data)
813
+ assert_equal [
814
+ [[1, 5]],
815
+ [[2, 4]],
816
+ [[3, 3]]
817
+ ], results
818
+
819
+ q = @db.prepare('update foo set b = ? returning b * 10 + a')
820
+
821
+ pr = parameter_source_proc([42, 43])
822
+ results = q.batch_query_single_column(pr)
823
+ assert_equal [
824
+ [421, 422, 423],
825
+ [431, 432, 433]
826
+ ], results
827
+
828
+ array = []
829
+ pr = parameter_source_proc([44, 45])
830
+ changes = q.batch_query_single_column(pr) do |rows|
831
+ array << rows
832
+ end
833
+ assert_equal 6, changes
834
+ assert_equal [
835
+ [441, 442, 443],
836
+ [451, 452, 453]
837
+ ], array
838
+ end
839
+
500
840
  def test_query_status
501
841
  assert_equal 0, @query.status(Extralite::SQLITE_STMTSTATUS_RUN)
502
842
  @query.to_a
@@ -552,4 +892,24 @@ class QueryTest < MiniTest::Test
552
892
  q = @db.prepare('select x from t')
553
893
  assert_match /^\#\<Extralite::Query:0x[0-9a-f]+ #{q.sql.inspect}\>$/, q.inspect
554
894
  end
895
+
896
+ def test_query_clone
897
+ q1 = @db.prepare('select x from t')
898
+ q2 = q1.clone
899
+
900
+ assert_kind_of Extralite::Query, q2
901
+ assert_equal @db, q2.database
902
+ assert_equal q1.sql, q2.sql
903
+ refute_equal q1, q2
904
+ end
905
+
906
+ def test_query_dup
907
+ q1 = @db.prepare('select x from t')
908
+ q2 = q1.dup
909
+
910
+ assert_kind_of Extralite::Query, q2
911
+ assert_equal @db, q2.database
912
+ assert_equal q1.sql, q2.sql
913
+ refute_equal q1, q2
914
+ end
555
915
  end
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.4'
4
+ version: '2.5'
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-12-24 00:00:00.000000000 Z
11
+ date: 2024-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -90,6 +90,7 @@ extra_rdoc_files:
90
90
  files:
91
91
  - ".editorconfig"
92
92
  - ".github/FUNDING.yml"
93
+ - ".github/workflows/test-bundle.yml"
93
94
  - ".github/workflows/test.yml"
94
95
  - ".gitignore"
95
96
  - ".yardopts"
@@ -125,6 +126,8 @@ files:
125
126
  - test/fixtures/image.png
126
127
  - test/helper.rb
127
128
  - test/issue-38.rb
129
+ - test/issue-54.rb
130
+ - test/issue-59.rb
128
131
  - test/perf_ary.rb
129
132
  - test/perf_hash.rb
130
133
  - test/perf_prepared.rb
@@ -154,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
157
  requirements:
155
158
  - - ">="
156
159
  - !ruby/object:Gem::Version
157
- version: '2.7'
160
+ version: '3.0'
158
161
  required_rubygems_version: !ruby/object:Gem::Requirement
159
162
  requirements:
160
163
  - - ">="