sequel 3.28.0 → 3.29.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +119 -3
- data/Rakefile +5 -3
- data/bin/sequel +1 -5
- data/doc/model_hooks.rdoc +9 -1
- data/doc/opening_databases.rdoc +49 -40
- data/doc/prepared_statements.rdoc +27 -6
- data/doc/release_notes/3.28.0.txt +2 -2
- data/doc/release_notes/3.29.0.txt +459 -0
- data/doc/sharding.rdoc +7 -1
- data/doc/testing.rdoc +18 -9
- data/doc/transactions.rdoc +41 -1
- data/lib/sequel/adapters/ado.rb +28 -17
- data/lib/sequel/adapters/ado/mssql.rb +18 -6
- data/lib/sequel/adapters/amalgalite.rb +11 -7
- data/lib/sequel/adapters/db2.rb +122 -70
- data/lib/sequel/adapters/dbi.rb +15 -15
- data/lib/sequel/adapters/do.rb +5 -36
- data/lib/sequel/adapters/do/mysql.rb +0 -5
- data/lib/sequel/adapters/do/postgres.rb +0 -5
- data/lib/sequel/adapters/do/sqlite.rb +0 -5
- data/lib/sequel/adapters/firebird.rb +3 -6
- data/lib/sequel/adapters/ibmdb.rb +24 -16
- data/lib/sequel/adapters/informix.rb +2 -4
- data/lib/sequel/adapters/jdbc.rb +47 -11
- data/lib/sequel/adapters/jdbc/as400.rb +5 -24
- data/lib/sequel/adapters/jdbc/db2.rb +0 -5
- data/lib/sequel/adapters/jdbc/derby.rb +217 -0
- data/lib/sequel/adapters/jdbc/firebird.rb +0 -5
- data/lib/sequel/adapters/jdbc/h2.rb +10 -12
- data/lib/sequel/adapters/jdbc/hsqldb.rb +166 -0
- data/lib/sequel/adapters/jdbc/informix.rb +0 -5
- data/lib/sequel/adapters/jdbc/jtds.rb +0 -5
- data/lib/sequel/adapters/jdbc/mysql.rb +0 -10
- data/lib/sequel/adapters/jdbc/oracle.rb +70 -3
- data/lib/sequel/adapters/jdbc/postgresql.rb +0 -11
- data/lib/sequel/adapters/jdbc/sqlite.rb +0 -5
- data/lib/sequel/adapters/jdbc/sqlserver.rb +0 -5
- data/lib/sequel/adapters/jdbc/transactions.rb +56 -7
- data/lib/sequel/adapters/mock.rb +315 -0
- data/lib/sequel/adapters/mysql.rb +64 -51
- data/lib/sequel/adapters/mysql2.rb +15 -9
- data/lib/sequel/adapters/odbc.rb +13 -6
- data/lib/sequel/adapters/odbc/db2.rb +0 -4
- data/lib/sequel/adapters/odbc/mssql.rb +0 -5
- data/lib/sequel/adapters/openbase.rb +2 -4
- data/lib/sequel/adapters/oracle.rb +333 -51
- data/lib/sequel/adapters/postgres.rb +80 -27
- data/lib/sequel/adapters/shared/access.rb +0 -6
- data/lib/sequel/adapters/shared/db2.rb +13 -15
- data/lib/sequel/adapters/shared/firebird.rb +6 -6
- data/lib/sequel/adapters/shared/mssql.rb +23 -18
- data/lib/sequel/adapters/shared/mysql.rb +6 -6
- data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +6 -0
- data/lib/sequel/adapters/shared/oracle.rb +185 -30
- data/lib/sequel/adapters/shared/postgres.rb +35 -18
- data/lib/sequel/adapters/shared/progress.rb +0 -6
- data/lib/sequel/adapters/shared/sqlite.rb +116 -37
- data/lib/sequel/adapters/sqlite.rb +16 -8
- data/lib/sequel/adapters/swift.rb +5 -5
- data/lib/sequel/adapters/swift/mysql.rb +0 -5
- data/lib/sequel/adapters/swift/postgres.rb +0 -5
- data/lib/sequel/adapters/swift/sqlite.rb +6 -4
- data/lib/sequel/adapters/tinytds.rb +13 -10
- data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +8 -0
- data/lib/sequel/core.rb +40 -0
- data/lib/sequel/database/connecting.rb +1 -2
- data/lib/sequel/database/dataset.rb +3 -3
- data/lib/sequel/database/dataset_defaults.rb +58 -0
- data/lib/sequel/database/misc.rb +62 -2
- data/lib/sequel/database/query.rb +113 -49
- data/lib/sequel/database/schema_methods.rb +7 -2
- data/lib/sequel/dataset/actions.rb +37 -19
- data/lib/sequel/dataset/features.rb +24 -0
- data/lib/sequel/dataset/graph.rb +7 -6
- data/lib/sequel/dataset/misc.rb +11 -3
- data/lib/sequel/dataset/mutation.rb +2 -3
- data/lib/sequel/dataset/prepared_statements.rb +6 -4
- data/lib/sequel/dataset/query.rb +46 -15
- data/lib/sequel/dataset/sql.rb +28 -4
- data/lib/sequel/extensions/named_timezones.rb +5 -0
- data/lib/sequel/extensions/thread_local_timezones.rb +1 -1
- data/lib/sequel/model.rb +2 -1
- data/lib/sequel/model/associations.rb +115 -33
- data/lib/sequel/model/base.rb +91 -31
- data/lib/sequel/plugins/class_table_inheritance.rb +4 -4
- data/lib/sequel/plugins/dataset_associations.rb +100 -0
- data/lib/sequel/plugins/force_encoding.rb +6 -6
- data/lib/sequel/plugins/identity_map.rb +1 -1
- data/lib/sequel/plugins/many_through_many.rb +6 -10
- data/lib/sequel/plugins/prepared_statements.rb +12 -1
- data/lib/sequel/plugins/prepared_statements_associations.rb +1 -1
- data/lib/sequel/plugins/rcte_tree.rb +29 -15
- data/lib/sequel/plugins/serialization.rb +6 -1
- data/lib/sequel/plugins/sharding.rb +0 -5
- data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
- data/lib/sequel/plugins/typecast_on_load.rb +9 -12
- data/lib/sequel/plugins/update_primary_key.rb +1 -1
- data/lib/sequel/timezones.rb +42 -42
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/mssql_spec.rb +29 -29
- data/spec/adapters/mysql_spec.rb +86 -104
- data/spec/adapters/oracle_spec.rb +48 -76
- data/spec/adapters/postgres_spec.rb +98 -33
- data/spec/adapters/spec_helper.rb +0 -5
- data/spec/adapters/sqlite_spec.rb +24 -21
- data/spec/core/connection_pool_spec.rb +9 -15
- data/spec/core/core_sql_spec.rb +20 -31
- data/spec/core/database_spec.rb +491 -227
- data/spec/core/dataset_spec.rb +638 -1051
- data/spec/core/expression_filters_spec.rb +0 -1
- data/spec/core/mock_adapter_spec.rb +378 -0
- data/spec/core/object_graph_spec.rb +48 -114
- data/spec/core/schema_generator_spec.rb +3 -3
- data/spec/core/schema_spec.rb +51 -114
- data/spec/core/spec_helper.rb +3 -90
- data/spec/extensions/class_table_inheritance_spec.rb +1 -1
- data/spec/extensions/dataset_associations_spec.rb +199 -0
- data/spec/extensions/instance_hooks_spec.rb +71 -0
- data/spec/extensions/named_timezones_spec.rb +22 -2
- data/spec/extensions/nested_attributes_spec.rb +3 -0
- data/spec/extensions/schema_spec.rb +1 -1
- data/spec/extensions/serialization_modification_detection_spec.rb +1 -0
- data/spec/extensions/serialization_spec.rb +5 -8
- data/spec/extensions/spec_helper.rb +4 -0
- data/spec/extensions/thread_local_timezones_spec.rb +22 -2
- data/spec/extensions/typecast_on_load_spec.rb +1 -6
- data/spec/integration/associations_test.rb +123 -12
- data/spec/integration/dataset_test.rb +140 -47
- data/spec/integration/eager_loader_test.rb +19 -21
- data/spec/integration/model_test.rb +80 -1
- data/spec/integration/plugin_test.rb +179 -128
- data/spec/integration/prepared_statement_test.rb +92 -91
- data/spec/integration/schema_test.rb +42 -23
- data/spec/integration/spec_helper.rb +25 -31
- data/spec/integration/timezone_test.rb +38 -12
- data/spec/integration/transaction_test.rb +161 -34
- data/spec/integration/type_test.rb +3 -3
- data/spec/model/association_reflection_spec.rb +83 -7
- data/spec/model/associations_spec.rb +393 -676
- data/spec/model/base_spec.rb +186 -116
- data/spec/model/dataset_methods_spec.rb +7 -27
- data/spec/model/eager_loading_spec.rb +343 -867
- data/spec/model/hooks_spec.rb +160 -79
- data/spec/model/model_spec.rb +118 -165
- data/spec/model/plugins_spec.rb +7 -13
- data/spec/model/record_spec.rb +138 -207
- data/spec/model/spec_helper.rb +10 -73
- metadata +14 -8
@@ -9,7 +9,6 @@ describe "Simple Dataset operations" do
|
|
9
9
|
end
|
10
10
|
@ds = @db[:items]
|
11
11
|
@ds.insert(:number=>10)
|
12
|
-
clear_sqls
|
13
12
|
end
|
14
13
|
after do
|
15
14
|
@db.drop_table(:items)
|
@@ -35,7 +34,29 @@ describe "Simple Dataset operations" do
|
|
35
34
|
@ds.filter(:id=>2).first[:number].should == 20
|
36
35
|
end
|
37
36
|
|
38
|
-
|
37
|
+
specify "should have insert work correctly with static SQL" do
|
38
|
+
@db["INSERT INTO #{@ds.literal(:items)} (#{@ds.literal(:number)}) VALUES (20)"].insert
|
39
|
+
@ds.filter(:id=>2).first[:number].should == 20
|
40
|
+
end
|
41
|
+
|
42
|
+
specify "should join correctly" do
|
43
|
+
@ds.join(:items___b, :id=>:id).select_all(:items).all.should == [{:id=>1, :number=>10}]
|
44
|
+
end
|
45
|
+
|
46
|
+
specify "should correctly deal with qualified columns and subselects" do
|
47
|
+
@ds.from_self(:alias=>:a).select(:a__id, :number.qualify(:a)).all.should == [{:id=>1, :number=>10}]
|
48
|
+
@ds.join(@ds.as(:a), :id=>:id).select(:a__id, :number.qualify(:a)).all.should == [{:id=>1, :number=>10}]
|
49
|
+
end
|
50
|
+
|
51
|
+
specify "should graph correctly" do
|
52
|
+
@ds.graph(:items, {:id=>:id}, :table_alias=>:b).all.should == [{:items=>{:id=>1, :number=>10}, :b=>{:id=>1, :number=>10}}]
|
53
|
+
end
|
54
|
+
|
55
|
+
specify "should graph correctly with a subselect" do
|
56
|
+
@ds.from_self(:alias=>:items).graph(@ds.from_self, {:id=>:id}, :table_alias=>:b).all.should == [{:items=>{:id=>1, :number=>10}, :b=>{:id=>1, :number=>10}}]
|
57
|
+
end
|
58
|
+
|
59
|
+
cspecify "should have insert work correctly when inserting a row with all NULL values", :hsqldb do
|
39
60
|
@db.create_table!(:items) do
|
40
61
|
String :name
|
41
62
|
Integer :number
|
@@ -89,6 +110,13 @@ describe "Simple Dataset operations" do
|
|
89
110
|
@ds.order(:id).limit(2, 1).all.should == [{:id=>2, :number=>20}]
|
90
111
|
end
|
91
112
|
|
113
|
+
specify "should provide correct columns when using a limit and offset" do
|
114
|
+
ds = @ds.order(:id).limit(1, 1)
|
115
|
+
ds.all
|
116
|
+
ds.columns.should == [:id, :number]
|
117
|
+
@ds.order(:id).limit(1, 1).columns.should == [:id, :number]
|
118
|
+
end
|
119
|
+
|
92
120
|
specify "should fetch correctly with a limit and offset for different combinations of from and join tables" do
|
93
121
|
@db.create_table!(:items2){primary_key :id2; Integer :number2}
|
94
122
|
@db[:items2].insert(:number2=>10)
|
@@ -106,7 +134,7 @@ describe "Simple Dataset operations" do
|
|
106
134
|
@db.drop_table(:items2)
|
107
135
|
end
|
108
136
|
|
109
|
-
cspecify "should fetch correctly with a limit and offset without an order", :db2, :mssql do
|
137
|
+
cspecify "should fetch correctly with a limit and offset without an order", :db2, :mssql, :oracle do
|
110
138
|
@ds.limit(2, 1).all.should == []
|
111
139
|
end
|
112
140
|
|
@@ -145,7 +173,6 @@ describe Sequel::Dataset do
|
|
145
173
|
Integer :value
|
146
174
|
end
|
147
175
|
@d = INTEGRATION_DB[:test]
|
148
|
-
clear_sqls
|
149
176
|
end
|
150
177
|
after do
|
151
178
|
INTEGRATION_DB.drop_table(:test)
|
@@ -237,7 +264,11 @@ describe Sequel::Database do
|
|
237
264
|
INTEGRATION_DB.drop_table(t) rescue nil
|
238
265
|
INTEGRATION_DB.table_exists?(t).should == false
|
239
266
|
INTEGRATION_DB.create_table(t){Integer :a}
|
240
|
-
|
267
|
+
begin
|
268
|
+
INTEGRATION_DB.table_exists?(t).should == true
|
269
|
+
ensure
|
270
|
+
INTEGRATION_DB.drop_table(t)
|
271
|
+
end
|
241
272
|
end
|
242
273
|
end
|
243
274
|
|
@@ -301,15 +332,14 @@ end
|
|
301
332
|
|
302
333
|
describe "Simple Dataset operations in transactions" do
|
303
334
|
before do
|
304
|
-
INTEGRATION_DB.create_table!(:
|
335
|
+
INTEGRATION_DB.create_table!(:items) do
|
305
336
|
primary_key :id
|
306
337
|
integer :number
|
307
338
|
end
|
308
|
-
@ds = INTEGRATION_DB[:
|
309
|
-
clear_sqls
|
339
|
+
@ds = INTEGRATION_DB[:items]
|
310
340
|
end
|
311
341
|
after do
|
312
|
-
INTEGRATION_DB.drop_table(:
|
342
|
+
INTEGRATION_DB.drop_table(:items)
|
313
343
|
end
|
314
344
|
|
315
345
|
cspecify "should insert correctly with a primary key specified inside a transaction", :db2, :mssql do
|
@@ -343,7 +373,6 @@ describe "Dataset UNION, EXCEPT, and INTERSECT" do
|
|
343
373
|
@ds2 = INTEGRATION_DB[:i2]
|
344
374
|
@ds2.insert(:number=>10)
|
345
375
|
@ds2.insert(:number=>30)
|
346
|
-
clear_sqls
|
347
376
|
end
|
348
377
|
|
349
378
|
specify "should give the correct results for simple UNION, EXCEPT, and INTERSECT" do
|
@@ -409,7 +438,7 @@ end
|
|
409
438
|
|
410
439
|
if INTEGRATION_DB.dataset.supports_cte?
|
411
440
|
describe "Common Table Expressions" do
|
412
|
-
before do
|
441
|
+
before(:all) do
|
413
442
|
@db = INTEGRATION_DB
|
414
443
|
@db.create_table!(:i1){Integer :id; Integer :parent_id}
|
415
444
|
@ds = @db[:i1]
|
@@ -420,7 +449,7 @@ if INTEGRATION_DB.dataset.supports_cte?
|
|
420
449
|
@ds.insert(:id=>5, :parent_id=>3)
|
421
450
|
@ds.insert(:id=>6, :parent_id=>5)
|
422
451
|
end
|
423
|
-
after do
|
452
|
+
after(:all) do
|
424
453
|
@db.drop_table(:i1)
|
425
454
|
end
|
426
455
|
|
@@ -441,6 +470,24 @@ if INTEGRATION_DB.dataset.supports_cte?
|
|
441
470
|
@ds.inner_join(@db[:t].with(:t, @ds.filter(:parent_id=>nil)), :id => :id).select(:i1__id).order(:i1__id).map(:id).should == [1,2]
|
442
471
|
@db[:t].with(:t, @ds).inner_join(@db[:s].with(:s, @ds.filter(:parent_id=>nil)), :id => :id).select(:t__id).order(:t__id).map(:id).should == [1,2]
|
443
472
|
end
|
473
|
+
|
474
|
+
specify "should support a subselect in the FROM clause with a CTE" do
|
475
|
+
@ds.from(@db[:t].with(:t, @ds)).select_order_map(:id).should == [1,2,3,4,5,6]
|
476
|
+
@db[:t].with(:t, @ds).from_self.select_order_map(:id).should == [1,2,3,4,5,6]
|
477
|
+
end
|
478
|
+
|
479
|
+
specify "should support using a CTE inside a CTE" do
|
480
|
+
@db[:s].with(:s, @db[:t].with(:t, @ds)).select_order_map(:id).should == [1,2,3,4,5,6]
|
481
|
+
@db[:s].with_recursive(:s, @db[:t].with(:t, @ds), @db[:t2].with(:t2, @ds)).select_order_map(:id).should == [1,1,2,2,3,3,4,4,5,5,6,6]
|
482
|
+
end
|
483
|
+
|
484
|
+
specify "should support using a CTE inside UNION/EXCEPT/INTERSECT" do
|
485
|
+
@ds.union(@db[:t].with(:t, @ds)).select_order_map(:id).should == [1,2,3,4,5,6]
|
486
|
+
if @ds.supports_intersect_except?
|
487
|
+
@ds.intersect(@db[:t].with(:t, @ds)).select_order_map(:id).should == [1,2,3,4,5,6]
|
488
|
+
@ds.except(@db[:t].with(:t, @ds)).select_order_map(:id).should == []
|
489
|
+
end
|
490
|
+
end
|
444
491
|
end
|
445
492
|
end
|
446
493
|
|
@@ -532,7 +579,7 @@ end
|
|
532
579
|
|
533
580
|
if INTEGRATION_DB.dataset.supports_window_functions?
|
534
581
|
describe "Window Functions" do
|
535
|
-
before do
|
582
|
+
before(:all) do
|
536
583
|
@db = INTEGRATION_DB
|
537
584
|
@db.create_table!(:i1){Integer :id; Integer :group_id; Integer :amount}
|
538
585
|
@ds = @db[:i1].order(:id)
|
@@ -543,7 +590,7 @@ if INTEGRATION_DB.dataset.supports_window_functions?
|
|
543
590
|
@ds.insert(:id=>5, :group_id=>2, :amount=>10000)
|
544
591
|
@ds.insert(:id=>6, :group_id=>2, :amount=>100000)
|
545
592
|
end
|
546
|
-
after do
|
593
|
+
after(:all) do
|
547
594
|
@db.drop_table(:i1)
|
548
595
|
end
|
549
596
|
|
@@ -602,7 +649,7 @@ describe Sequel::SQL::Constants do
|
|
602
649
|
@db.drop_table(:constants) if @db.table_exists?(:constants)
|
603
650
|
end
|
604
651
|
|
605
|
-
cspecify "should have working CURRENT_DATE", [:odbc, :mssql], [:jdbc, :sqlite] do
|
652
|
+
cspecify "should have working CURRENT_DATE", [:odbc, :mssql], [:jdbc, :sqlite], :oracle do
|
606
653
|
@db.create_table!(:constants){Date :d}
|
607
654
|
@ds.insert(:d=>Sequel::CURRENT_DATE)
|
608
655
|
d = @c2[@ds.get(:d)]
|
@@ -613,26 +660,27 @@ describe Sequel::SQL::Constants do
|
|
613
660
|
cspecify "should have working CURRENT_TIME", [:do, :mysql], [:jdbc, :sqlite], [:mysql2] do
|
614
661
|
@db.create_table!(:constants){Time :t, :only_time=>true}
|
615
662
|
@ds.insert(:t=>Sequel::CURRENT_TIME)
|
616
|
-
(Time.now - @c[@ds.get(:t)]).should be_within(
|
663
|
+
(Time.now - @c[@ds.get(:t)]).should be_within(2).of(0)
|
617
664
|
end
|
618
665
|
|
619
666
|
cspecify "should have working CURRENT_TIMESTAMP", [:jdbc, :sqlite] do
|
620
667
|
@db.create_table!(:constants){DateTime :ts}
|
621
668
|
@ds.insert(:ts=>Sequel::CURRENT_TIMESTAMP)
|
622
|
-
(Time.now - @c[@ds.get(:ts)]).should be_within(
|
669
|
+
(Time.now - @c[@ds.get(:ts)]).should be_within(2).of(0)
|
623
670
|
end
|
624
671
|
end
|
625
672
|
|
626
673
|
describe "Sequel::Dataset#import and #multi_insert" do
|
627
|
-
before do
|
674
|
+
before(:all) do
|
628
675
|
@db = INTEGRATION_DB
|
629
676
|
@db.create_table!(:imp){Integer :i}
|
630
|
-
@db.create_table!(:exp2){Integer :i}
|
631
677
|
@ids = @db[:imp].order(:i)
|
632
|
-
@eds = @db[:exp2]
|
633
678
|
end
|
634
|
-
|
635
|
-
@
|
679
|
+
before do
|
680
|
+
@ids.delete
|
681
|
+
end
|
682
|
+
after(:all) do
|
683
|
+
@db.drop_table(:imp)
|
636
684
|
end
|
637
685
|
|
638
686
|
it "should import with multi_insert and an array of hashes" do
|
@@ -646,9 +694,11 @@ describe "Sequel::Dataset#import and #multi_insert" do
|
|
646
694
|
end
|
647
695
|
|
648
696
|
it "should import with a dataset" do
|
649
|
-
@
|
650
|
-
@
|
697
|
+
@db.create_table!(:exp2){Integer :i}
|
698
|
+
@db[:exp2].import([:i], [[10], [20]])
|
699
|
+
@ids.import([:i], @db[:exp2])
|
651
700
|
@ids.all.should == [{:i=>10}, {:i=>20}]
|
701
|
+
@db.drop_table(:exp2)
|
652
702
|
end
|
653
703
|
|
654
704
|
it "should have import work with the :slice_size option" do
|
@@ -664,12 +714,15 @@ describe "Sequel::Dataset#import and #multi_insert" do
|
|
664
714
|
end
|
665
715
|
|
666
716
|
describe "Sequel::Dataset convenience methods" do
|
667
|
-
before do
|
717
|
+
before(:all) do
|
668
718
|
@db = INTEGRATION_DB
|
669
719
|
@db.create_table!(:a){Integer :a; Integer :b}
|
670
720
|
@ds = @db[:a].order(:a)
|
671
721
|
end
|
672
|
-
|
722
|
+
before do
|
723
|
+
@ds.delete
|
724
|
+
end
|
725
|
+
after(:all) do
|
673
726
|
@db.drop_table(:a)
|
674
727
|
end
|
675
728
|
|
@@ -723,12 +776,15 @@ describe "Sequel::Dataset convenience methods" do
|
|
723
776
|
end
|
724
777
|
|
725
778
|
describe "Sequel::Dataset main SQL methods" do
|
726
|
-
before do
|
779
|
+
before(:all) do
|
727
780
|
@db = INTEGRATION_DB
|
728
781
|
@db.create_table!(:a){Integer :a; Integer :b}
|
729
782
|
@ds = @db[:a].order(:a)
|
730
783
|
end
|
731
|
-
|
784
|
+
before do
|
785
|
+
@ds.delete
|
786
|
+
end
|
787
|
+
after(:all) do
|
732
788
|
@db.drop_table(:a)
|
733
789
|
end
|
734
790
|
|
@@ -791,14 +847,17 @@ describe "Sequel::Dataset main SQL methods" do
|
|
791
847
|
end
|
792
848
|
|
793
849
|
describe "Sequel::Dataset convenience methods" do
|
794
|
-
before do
|
850
|
+
before(:all) do
|
795
851
|
@db = INTEGRATION_DB
|
796
852
|
@db.create_table!(:a){Integer :a; Integer :b; Integer :c; Integer :d}
|
797
853
|
@ds = @db[:a].order(:a)
|
854
|
+
end
|
855
|
+
before do
|
856
|
+
@ds.delete
|
798
857
|
@ds.insert(1, 2, 3, 4)
|
799
858
|
@ds.insert(5, 6, 7, 8)
|
800
859
|
end
|
801
|
-
after do
|
860
|
+
after(:all) do
|
802
861
|
@db.drop_table(:a)
|
803
862
|
end
|
804
863
|
|
@@ -822,6 +881,7 @@ describe "Sequel::Dataset convenience methods" do
|
|
822
881
|
specify "should have working #select_map" do
|
823
882
|
@ds.select_map(:a).should == [1, 5]
|
824
883
|
@ds.select_map(:b).should == [2, 6]
|
884
|
+
@ds.select_map([:a]).should == [[1], [5]]
|
825
885
|
@ds.select_map([:a, :b]).should == [[1, 2], [5, 6]]
|
826
886
|
|
827
887
|
@ds.select_map(:a___e).should == [1, 5]
|
@@ -838,6 +898,7 @@ describe "Sequel::Dataset convenience methods" do
|
|
838
898
|
@ds.select_order_map(:a__b.desc).should == [6, 2]
|
839
899
|
@ds.select_order_map(:a__b___e.desc).should == [6, 2]
|
840
900
|
@ds.select_order_map(:b.qualify(:a).as(:e)).should == [2, 6]
|
901
|
+
@ds.select_order_map([:a]).should == [[1], [5]]
|
841
902
|
@ds.select_order_map([:a.desc, :b]).should == [[5, 6], [1, 2]]
|
842
903
|
|
843
904
|
@ds.select_order_map(:a___e).should == [1, 5]
|
@@ -862,12 +923,15 @@ describe "Sequel::Dataset convenience methods" do
|
|
862
923
|
end
|
863
924
|
|
864
925
|
describe "Sequel::Dataset DSL support" do
|
865
|
-
before do
|
926
|
+
before(:all) do
|
866
927
|
@db = INTEGRATION_DB
|
867
928
|
@db.create_table!(:a){Integer :a; Integer :b}
|
868
929
|
@ds = @db[:a].order(:a)
|
869
930
|
end
|
870
|
-
|
931
|
+
before do
|
932
|
+
@ds.delete
|
933
|
+
end
|
934
|
+
after(:all) do
|
871
935
|
@db.drop_table(:a)
|
872
936
|
end
|
873
937
|
|
@@ -879,31 +943,36 @@ describe "Sequel::Dataset DSL support" do
|
|
879
943
|
@ds.get{a / b}.to_i.should == 2
|
880
944
|
end
|
881
945
|
|
882
|
-
|
946
|
+
cspecify "should work with bitwise shift operators", :derby do
|
883
947
|
@ds.insert(3, 2)
|
884
948
|
@ds.get{a.sql_number << b}.to_i.should == 12
|
885
949
|
@ds.get{a.sql_number >> b}.to_i.should == 0
|
950
|
+
@ds.get{a.sql_number << b << 1}.to_i.should == 24
|
886
951
|
@ds.delete
|
887
952
|
@ds.insert(3, 1)
|
888
953
|
@ds.get{a.sql_number << b}.to_i.should == 6
|
889
954
|
@ds.get{a.sql_number >> b}.to_i.should == 1
|
955
|
+
@ds.get{a.sql_number >> b >> 1}.to_i.should == 0
|
890
956
|
end
|
891
957
|
|
892
|
-
|
958
|
+
cspecify "should work with bitwise AND and OR operators", :derby do
|
893
959
|
@ds.insert(3, 5)
|
894
960
|
@ds.get{a.sql_number | b}.to_i.should == 7
|
895
961
|
@ds.get{a.sql_number & b}.to_i.should == 1
|
962
|
+
@ds.get{a.sql_number | b | 8}.to_i.should == 15
|
963
|
+
@ds.get{a.sql_number & b & 8}.to_i.should == 0
|
896
964
|
end
|
897
965
|
|
898
|
-
|
966
|
+
specify "should work with the bitwise compliment operator" do
|
899
967
|
@ds.insert(-3, 3)
|
900
968
|
@ds.get{~a.sql_number}.to_i.should == 2
|
901
969
|
@ds.get{~b.sql_number}.to_i.should == -4
|
902
970
|
end
|
903
971
|
|
904
|
-
|
972
|
+
cspecify "should work with the bitwise xor operator", :derby do
|
905
973
|
@ds.insert(3, 5)
|
906
974
|
@ds.get{a.sql_number ^ b}.to_i.should == 6
|
975
|
+
@ds.get{a.sql_number ^ b ^ 1}.to_i.should == 7
|
907
976
|
end
|
908
977
|
|
909
978
|
specify "should work with inequality operators" do
|
@@ -1077,12 +1146,15 @@ describe "SQL Extract Function" do
|
|
1077
1146
|
end
|
1078
1147
|
|
1079
1148
|
describe "Dataset string methods" do
|
1080
|
-
before do
|
1149
|
+
before(:all) do
|
1081
1150
|
@db = INTEGRATION_DB
|
1082
1151
|
@db.create_table!(:a){String :a; String :b}
|
1083
1152
|
@ds = @db[:a].order(:a)
|
1084
1153
|
end
|
1085
|
-
|
1154
|
+
before do
|
1155
|
+
@ds.delete
|
1156
|
+
end
|
1157
|
+
after(:all) do
|
1086
1158
|
@db.drop_table(:a)
|
1087
1159
|
end
|
1088
1160
|
|
@@ -1097,15 +1169,15 @@ describe "Dataset string methods" do
|
|
1097
1169
|
end
|
1098
1170
|
|
1099
1171
|
it "#grep should work with :all_patterns and :all_columns options" do
|
1100
|
-
@ds.insert('foo bar', '')
|
1172
|
+
@ds.insert('foo bar', ' ')
|
1101
1173
|
@ds.insert('foo d', 'bar')
|
1102
|
-
@ds.insert('foo e', '')
|
1103
|
-
@ds.insert('', 'bar')
|
1174
|
+
@ds.insert('foo e', ' ')
|
1175
|
+
@ds.insert(' ', 'bar')
|
1104
1176
|
@ds.insert('foo f', 'baz')
|
1105
1177
|
@ds.insert('foo baz', 'bar baz')
|
1106
1178
|
@ds.insert('foo boo', 'boo foo')
|
1107
1179
|
|
1108
|
-
@ds.grep([:a, :b], %w'%foo% %bar%', :all_patterns=>true).all.should == [{:a=>'foo bar', :b=>''}, {:a=>'foo baz', :b=>'bar baz'}, {:a=>'foo d', :b=>'bar'}]
|
1180
|
+
@ds.grep([:a, :b], %w'%foo% %bar%', :all_patterns=>true).all.should == [{:a=>'foo bar', :b=>' '}, {:a=>'foo baz', :b=>'bar baz'}, {:a=>'foo d', :b=>'bar'}]
|
1109
1181
|
@ds.grep([:a, :b], %w'%foo% %bar% %blob%', :all_patterns=>true).all.should == []
|
1110
1182
|
|
1111
1183
|
@ds.grep([:a, :b], %w'%bar% %foo%', :all_columns=>true).all.should == [{:a=>"foo baz", :b=>"bar baz"}, {:a=>"foo boo", :b=>"boo foo"}, {:a=>"foo d", :b=>"bar"}]
|
@@ -1120,6 +1192,19 @@ describe "Dataset string methods" do
|
|
1120
1192
|
@ds.filter(:a.like('foo')).all.should == [{:a=>'foo', :b=>'bar'}]
|
1121
1193
|
@ds.filter(:a.like('bar')).all.should == []
|
1122
1194
|
@ds.filter(:a.like('foo', 'bar')).all.should == [{:a=>'foo', :b=>'bar'}]
|
1195
|
+
@ds.exclude(:a.like('foo')).all.should == []
|
1196
|
+
@ds.exclude(:a.like('bar')).all.should == [{:a=>'foo', :b=>'bar'}]
|
1197
|
+
@ds.exclude(:a.like('foo', 'bar')).all.should == []
|
1198
|
+
end
|
1199
|
+
|
1200
|
+
it "#like should be case sensitive" do
|
1201
|
+
@ds.insert('foo', 'bar')
|
1202
|
+
@ds.filter(:a.like('Foo')).all.should == []
|
1203
|
+
@ds.filter(:a.like('baR')).all.should == []
|
1204
|
+
@ds.filter(:a.like('FOO', 'BAR')).all.should == []
|
1205
|
+
@ds.exclude(:a.like('Foo')).all.should == [{:a=>'foo', :b=>'bar'}]
|
1206
|
+
@ds.exclude(:a.like('baR')).all.should == [{:a=>'foo', :b=>'bar'}]
|
1207
|
+
@ds.exclude(:a.like('FOO', 'BAR')).all.should == [{:a=>'foo', :b=>'bar'}]
|
1123
1208
|
end
|
1124
1209
|
|
1125
1210
|
it "#ilike should return matching rows, in a case insensitive manner" do
|
@@ -1127,6 +1212,9 @@ describe "Dataset string methods" do
|
|
1127
1212
|
@ds.filter(:a.ilike('Foo')).all.should == [{:a=>'foo', :b=>'bar'}]
|
1128
1213
|
@ds.filter(:a.ilike('baR')).all.should == []
|
1129
1214
|
@ds.filter(:a.ilike('FOO', 'BAR')).all.should == [{:a=>'foo', :b=>'bar'}]
|
1215
|
+
@ds.exclude(:a.ilike('Foo')).all.should == []
|
1216
|
+
@ds.exclude(:a.ilike('baR')).all.should == [{:a=>'foo', :b=>'bar'}]
|
1217
|
+
@ds.exclude(:a.ilike('FOO', 'BAR')).all.should == []
|
1130
1218
|
end
|
1131
1219
|
|
1132
1220
|
it "should work with strings created with sql_string_join" do
|
@@ -1137,7 +1225,7 @@ describe "Dataset string methods" do
|
|
1137
1225
|
end
|
1138
1226
|
|
1139
1227
|
describe "Dataset identifier methods" do
|
1140
|
-
before do
|
1228
|
+
before(:all) do
|
1141
1229
|
class ::String
|
1142
1230
|
def uprev
|
1143
1231
|
upcase.reverse
|
@@ -1145,10 +1233,12 @@ describe "Dataset identifier methods" do
|
|
1145
1233
|
end
|
1146
1234
|
@db = INTEGRATION_DB
|
1147
1235
|
@db.create_table!(:a){Integer :ab}
|
1236
|
+
@db[:a].insert(1)
|
1237
|
+
end
|
1238
|
+
before do
|
1148
1239
|
@ds = @db[:a].order(:ab)
|
1149
|
-
@ds.insert(1)
|
1150
1240
|
end
|
1151
|
-
after do
|
1241
|
+
after(:all) do
|
1152
1242
|
@db.drop_table(:a)
|
1153
1243
|
end
|
1154
1244
|
|
@@ -1166,12 +1256,15 @@ describe "Dataset identifier methods" do
|
|
1166
1256
|
end
|
1167
1257
|
|
1168
1258
|
describe "Dataset defaults and overrides" do
|
1169
|
-
before do
|
1259
|
+
before(:all) do
|
1170
1260
|
@db = INTEGRATION_DB
|
1171
1261
|
@db.create_table!(:a){Integer :a}
|
1172
1262
|
@ds = @db[:a].order(:a)
|
1173
1263
|
end
|
1174
|
-
|
1264
|
+
before do
|
1265
|
+
@ds.delete
|
1266
|
+
end
|
1267
|
+
after(:all) do
|
1175
1268
|
@db.drop_table(:a)
|
1176
1269
|
end
|
1177
1270
|
|