sequel 4.47.0 → 4.48.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +134 -0
  3. data/Rakefile +1 -1
  4. data/doc/release_notes/4.48.0.txt +293 -0
  5. data/lib/sequel/adapters/ado/access.rb +2 -1
  6. data/lib/sequel/adapters/do/postgres.rb +5 -2
  7. data/lib/sequel/adapters/ibmdb.rb +24 -7
  8. data/lib/sequel/adapters/jdbc.rb +36 -22
  9. data/lib/sequel/adapters/jdbc/db2.rb +12 -3
  10. data/lib/sequel/adapters/jdbc/derby.rb +4 -5
  11. data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
  12. data/lib/sequel/adapters/jdbc/postgresql.rb +43 -18
  13. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
  14. data/lib/sequel/adapters/jdbc/sqlserver.rb +11 -4
  15. data/lib/sequel/adapters/mock.rb +24 -19
  16. data/lib/sequel/adapters/mysql.rb +17 -16
  17. data/lib/sequel/adapters/mysql2.rb +4 -5
  18. data/lib/sequel/adapters/oracle.rb +5 -9
  19. data/lib/sequel/adapters/postgres.rb +89 -102
  20. data/lib/sequel/adapters/shared/db2.rb +22 -6
  21. data/lib/sequel/adapters/shared/mssql.rb +5 -4
  22. data/lib/sequel/adapters/shared/mysql.rb +75 -24
  23. data/lib/sequel/adapters/shared/postgres.rb +196 -94
  24. data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
  25. data/lib/sequel/adapters/shared/sqlite.rb +72 -82
  26. data/lib/sequel/adapters/sqlanywhere.rb +4 -1
  27. data/lib/sequel/adapters/sqlite.rb +5 -3
  28. data/lib/sequel/adapters/swift/postgres.rb +5 -2
  29. data/lib/sequel/adapters/tinytds.rb +0 -5
  30. data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
  31. data/lib/sequel/adapters/utils/pg_types.rb +2 -76
  32. data/lib/sequel/core.rb +2 -2
  33. data/lib/sequel/database/connecting.rb +5 -5
  34. data/lib/sequel/database/dataset.rb +6 -3
  35. data/lib/sequel/database/misc.rb +1 -1
  36. data/lib/sequel/database/query.rb +3 -0
  37. data/lib/sequel/database/schema_methods.rb +1 -1
  38. data/lib/sequel/dataset/actions.rb +18 -10
  39. data/lib/sequel/dataset/graph.rb +1 -1
  40. data/lib/sequel/dataset/misc.rb +1 -0
  41. data/lib/sequel/dataset/prepared_statements.rb +3 -3
  42. data/lib/sequel/dataset/query.rb +19 -8
  43. data/lib/sequel/extensions/core_extensions.rb +4 -1
  44. data/lib/sequel/extensions/duplicate_columns_handler.rb +1 -1
  45. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +3 -0
  46. data/lib/sequel/extensions/filter_having.rb +2 -0
  47. data/lib/sequel/extensions/freeze_datasets.rb +2 -0
  48. data/lib/sequel/extensions/from_block.rb +1 -1
  49. data/lib/sequel/extensions/graph_each.rb +2 -2
  50. data/lib/sequel/extensions/hash_aliases.rb +2 -0
  51. data/lib/sequel/extensions/identifier_mangling.rb +0 -7
  52. data/lib/sequel/extensions/meta_def.rb +2 -0
  53. data/lib/sequel/extensions/migration.rb +6 -6
  54. data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
  55. data/lib/sequel/extensions/pagination.rb +1 -1
  56. data/lib/sequel/extensions/pg_array.rb +207 -130
  57. data/lib/sequel/extensions/pg_hstore.rb +38 -20
  58. data/lib/sequel/extensions/pg_inet.rb +18 -6
  59. data/lib/sequel/extensions/pg_interval.rb +19 -12
  60. data/lib/sequel/extensions/pg_json.rb +25 -14
  61. data/lib/sequel/extensions/pg_json_ops.rb +2 -2
  62. data/lib/sequel/extensions/pg_range.rb +133 -100
  63. data/lib/sequel/extensions/pg_range_ops.rb +4 -3
  64. data/lib/sequel/extensions/pg_row.rb +68 -39
  65. data/lib/sequel/extensions/pg_row_ops.rb +11 -5
  66. data/lib/sequel/extensions/query_literals.rb +2 -0
  67. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +2 -0
  68. data/lib/sequel/extensions/s.rb +1 -1
  69. data/lib/sequel/extensions/schema_dumper.rb +24 -24
  70. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +3 -1
  71. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +83 -0
  72. data/lib/sequel/extensions/set_overrides.rb +2 -2
  73. data/lib/sequel/extensions/string_agg.rb +0 -1
  74. data/lib/sequel/extensions/symbol_aref.rb +0 -4
  75. data/lib/sequel/model.rb +25 -57
  76. data/lib/sequel/model/associations.rb +14 -5
  77. data/lib/sequel/model/base.rb +96 -32
  78. data/lib/sequel/plugins/association_pks.rb +73 -46
  79. data/lib/sequel/plugins/association_proxies.rb +1 -1
  80. data/lib/sequel/plugins/auto_validations.rb +6 -2
  81. data/lib/sequel/plugins/boolean_readers.rb +1 -1
  82. data/lib/sequel/plugins/caching.rb +19 -13
  83. data/lib/sequel/plugins/class_table_inheritance.rb +19 -10
  84. data/lib/sequel/plugins/column_conflicts.rb +7 -2
  85. data/lib/sequel/plugins/column_select.rb +1 -1
  86. data/lib/sequel/plugins/csv_serializer.rb +8 -8
  87. data/lib/sequel/plugins/defaults_setter.rb +10 -0
  88. data/lib/sequel/plugins/eager_each.rb +1 -1
  89. data/lib/sequel/plugins/force_encoding.rb +2 -2
  90. data/lib/sequel/plugins/hook_class_methods.rb +9 -12
  91. data/lib/sequel/plugins/identifier_columns.rb +2 -0
  92. data/lib/sequel/plugins/instance_filters.rb +3 -1
  93. data/lib/sequel/plugins/instance_hooks.rb +17 -9
  94. data/lib/sequel/plugins/json_serializer.rb +17 -10
  95. data/lib/sequel/plugins/lazy_attributes.rb +8 -7
  96. data/lib/sequel/plugins/modification_detection.rb +3 -0
  97. data/lib/sequel/plugins/nested_attributes.rb +5 -1
  98. data/lib/sequel/plugins/pg_array_associations.rb +5 -0
  99. data/lib/sequel/plugins/prepared_statements.rb +1 -0
  100. data/lib/sequel/plugins/rcte_tree.rb +4 -4
  101. data/lib/sequel/plugins/serialization.rb +3 -10
  102. data/lib/sequel/plugins/single_table_inheritance.rb +2 -2
  103. data/lib/sequel/plugins/split_values.rb +6 -5
  104. data/lib/sequel/plugins/static_cache.rb +31 -25
  105. data/lib/sequel/plugins/subset_conditions.rb +3 -1
  106. data/lib/sequel/plugins/table_select.rb +1 -1
  107. data/lib/sequel/plugins/touch.rb +2 -1
  108. data/lib/sequel/plugins/validation_class_methods.rb +5 -6
  109. data/lib/sequel/plugins/validation_helpers.rb +2 -4
  110. data/lib/sequel/plugins/xml_serializer.rb +4 -4
  111. data/lib/sequel/sql.rb +2 -2
  112. data/lib/sequel/version.rb +1 -1
  113. data/spec/adapters/db2_spec.rb +115 -14
  114. data/spec/adapters/mysql_spec.rb +78 -28
  115. data/spec/adapters/oracle_spec.rb +24 -24
  116. data/spec/adapters/postgres_spec.rb +38 -24
  117. data/spec/adapters/sqlanywhere_spec.rb +88 -86
  118. data/spec/adapters/sqlite_spec.rb +29 -24
  119. data/spec/core/connection_pool_spec.rb +17 -0
  120. data/spec/core/database_spec.rb +6 -0
  121. data/spec/core/dataset_spec.rb +46 -36
  122. data/spec/core/schema_spec.rb +16 -0
  123. data/spec/core/spec_helper.rb +1 -0
  124. data/spec/core_extensions_spec.rb +6 -2
  125. data/spec/extensions/active_model_spec.rb +1 -1
  126. data/spec/extensions/arbitrary_servers_spec.rb +1 -1
  127. data/spec/extensions/association_pks_spec.rb +34 -2
  128. data/spec/extensions/auto_literal_strings_spec.rb +5 -1
  129. data/spec/extensions/auto_validations_spec.rb +2 -0
  130. data/spec/extensions/boolean_readers_spec.rb +1 -1
  131. data/spec/extensions/boolean_subsets_spec.rb +1 -1
  132. data/spec/extensions/class_table_inheritance_spec.rb +48 -2
  133. data/spec/extensions/column_conflicts_spec.rb +11 -0
  134. data/spec/extensions/connection_validator_spec.rb +1 -1
  135. data/spec/extensions/dataset_associations_spec.rb +8 -8
  136. data/spec/extensions/defaults_setter_spec.rb +1 -1
  137. data/spec/extensions/filter_having_spec.rb +5 -3
  138. data/spec/extensions/hash_aliases_spec.rb +3 -1
  139. data/spec/extensions/identifier_columns_spec.rb +3 -1
  140. data/spec/extensions/implicit_subquery_spec.rb +4 -2
  141. data/spec/extensions/json_serializer_spec.rb +18 -0
  142. data/spec/extensions/lazy_attributes_spec.rb +3 -3
  143. data/spec/extensions/meta_def_spec.rb +9 -0
  144. data/spec/extensions/migration_spec.rb +3 -3
  145. data/spec/extensions/nested_attributes_spec.rb +14 -3
  146. data/spec/extensions/no_auto_literal_strings_spec.rb +8 -4
  147. data/spec/extensions/pg_array_associations_spec.rb +29 -18
  148. data/spec/extensions/pg_array_spec.rb +44 -25
  149. data/spec/extensions/pg_hstore_spec.rb +10 -0
  150. data/spec/extensions/pg_inet_spec.rb +26 -0
  151. data/spec/extensions/pg_interval_spec.rb +20 -0
  152. data/spec/extensions/pg_json_spec.rb +24 -0
  153. data/spec/extensions/pg_range_spec.rb +98 -14
  154. data/spec/extensions/pg_row_spec.rb +14 -4
  155. data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
  156. data/spec/extensions/query_literals_spec.rb +3 -1
  157. data/spec/extensions/schema_dumper_spec.rb +96 -98
  158. data/spec/extensions/sequel_3_dataset_methods_spec.rb +10 -6
  159. data/spec/extensions/sequel_4_dataset_methods_spec.rb +121 -0
  160. data/spec/extensions/single_table_inheritance_spec.rb +1 -1
  161. data/spec/extensions/spec_helper.rb +7 -1
  162. data/spec/extensions/static_cache_spec.rb +75 -24
  163. data/spec/extensions/string_agg_spec.rb +1 -1
  164. data/spec/extensions/touch_spec.rb +9 -0
  165. data/spec/extensions/validation_helpers_spec.rb +9 -3
  166. data/spec/extensions/whitelist_security_spec.rb +26 -0
  167. data/spec/integration/dataset_test.rb +45 -44
  168. data/spec/integration/plugin_test.rb +20 -0
  169. data/spec/integration/prepared_statement_test.rb +3 -0
  170. data/spec/integration/schema_test.rb +21 -1
  171. data/spec/integration/transaction_test.rb +40 -40
  172. data/spec/model/class_dataset_methods_spec.rb +14 -4
  173. data/spec/model/dataset_methods_spec.rb +12 -3
  174. data/spec/model/model_spec.rb +8 -0
  175. metadata +6 -4
  176. data/spec/adapters/firebird_spec.rb +0 -405
  177. data/spec/adapters/informix_spec.rb +0 -100
@@ -117,17 +117,17 @@ describe "An Oracle database" do
117
117
 
118
118
  it "should return the correct record count" do
119
119
  @d.count.must_equal 0
120
- @d << {:name => 'abc', :value => 123}
121
- @d << {:name => 'abc', :value => 456}
122
- @d << {:name => 'def', :value => 789}
120
+ @d.insert(:name => 'abc', :value => 123)
121
+ @d.insert(:name => 'abc', :value => 456)
122
+ @d.insert(:name => 'def', :value => 789)
123
123
  @d.count.must_equal 3
124
124
  end
125
125
 
126
126
  it "should return the correct records" do
127
127
  @d.to_a.must_equal []
128
- @d << {:name => 'abc', :value => 123}
129
- @d << {:name => 'abc', :value => 456}
130
- @d << {:name => 'def', :value => 789}
128
+ @d.insert(:name => 'abc', :value => 123)
129
+ @d.insert(:name => 'abc', :value => 456)
130
+ @d.insert(:name => 'def', :value => 789)
131
131
 
132
132
  @d.order(:value).to_a.must_equal [
133
133
  {:date_created=>nil, :name => 'abc', :value => 123},
@@ -214,9 +214,9 @@ describe "An Oracle database" do
214
214
  end
215
215
 
216
216
  it "should update records correctly" do
217
- @d << {:name => 'abc', :value => 123}
218
- @d << {:name => 'abc', :value => 456}
219
- @d << {:name => 'def', :value => 789}
217
+ @d.insert(:name => 'abc', :value => 123)
218
+ @d.insert(:name => 'abc', :value => 456)
219
+ @d.insert(:name => 'def', :value => 789)
220
220
  @d.filter(:name => 'abc').update(:value => 530)
221
221
 
222
222
  @d[:name => 'def'][:value].must_equal 789
@@ -224,17 +224,17 @@ describe "An Oracle database" do
224
224
  end
225
225
 
226
226
  it "should translate values correctly" do
227
- @d << {:name => 'abc', :value => 456}
228
- @d << {:name => 'def', :value => 789}
227
+ @d.insert(:name => 'abc', :value => 456)
228
+ @d.insert(:name => 'def', :value => 789)
229
229
  @d.filter{value > 500}.update(:date_created => Sequel.lit("to_timestamp('2009-09-09', 'YYYY-MM-DD')"))
230
230
 
231
231
  @d[:name => 'def'][:date_created].strftime('%F').must_equal '2009-09-09'
232
232
  end
233
233
 
234
234
  it "should delete records correctly" do
235
- @d << {:name => 'abc', :value => 123}
236
- @d << {:name => 'abc', :value => 456}
237
- @d << {:name => 'def', :value => 789}
235
+ @d.insert(:name => 'abc', :value => 123)
236
+ @d.insert(:name => 'abc', :value => 456)
237
+ @d.insert(:name => 'def', :value => 789)
238
238
  @d.filter(:name => 'abc').delete
239
239
 
240
240
  @d.count.must_equal 1
@@ -248,7 +248,7 @@ describe "An Oracle database" do
248
248
 
249
249
  it "should support transactions" do
250
250
  DB.transaction do
251
- @d << {:name => 'abc', :value => 1}
251
+ @d.insert(:name => 'abc', :value => 1)
252
252
  end
253
253
 
254
254
  @d.count.must_equal 1
@@ -257,15 +257,15 @@ describe "An Oracle database" do
257
257
  it "should return correct result" do
258
258
  @d1 = DB[:books]
259
259
  @d1.delete
260
- @d1 << {:id => 1, :title => 'aaa', :category_id => 100}
261
- @d1 << {:id => 2, :title => 'bbb', :category_id => 100}
262
- @d1 << {:id => 3, :title => 'ccc', :category_id => 101}
263
- @d1 << {:id => 4, :title => 'ddd', :category_id => 102}
260
+ @d1.insert(:id => 1, :title => 'aaa', :category_id => 100)
261
+ @d1.insert(:id => 2, :title => 'bbb', :category_id => 100)
262
+ @d1.insert(:id => 3, :title => 'ccc', :category_id => 101)
263
+ @d1.insert(:id => 4, :title => 'ddd', :category_id => 102)
264
264
 
265
265
  @d2 = DB[:categories]
266
266
  @d2.delete
267
- @d2 << {:id => 100, :cat_name => 'ruby'}
268
- @d2 << {:id => 101, :cat_name => 'rails'}
267
+ @d2.insert(:id => 100, :cat_name => 'ruby')
268
+ @d2.insert(:id => 101, :cat_name => 'rails')
269
269
 
270
270
  @d1.join(:categories, :id => :category_id).select(Sequel[:books][:id], :title, :cat_name).order(Sequel[:books][:id]).to_a.must_equal [
271
271
  {:id => 1, :title => 'aaa', :cat_name => 'ruby'},
@@ -294,9 +294,9 @@ describe "An Oracle database" do
294
294
  it "should allow columns to be renamed" do
295
295
  @d1 = DB[:books]
296
296
  @d1.delete
297
- @d1 << {:id => 1, :title => 'aaa', :category_id => 100}
298
- @d1 << {:id => 2, :title => 'bbb', :category_id => 100}
299
- @d1 << {:id => 3, :title => 'bbb', :category_id => 100}
297
+ @d1.insert(:id => 1, :title => 'aaa', :category_id => 100)
298
+ @d1.insert(:id => 2, :title => 'bbb', :category_id => 100)
299
+ @d1.insert(:id => 3, :title => 'bbb', :category_id => 100)
300
300
 
301
301
  @d1.select(Sequel.as(:title, :name)).order_by(:id).to_a.must_equal [
302
302
  { :name => 'aaa' },
@@ -4,6 +4,7 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
4
4
 
5
5
  uses_pg = Sequel::Postgres::USES_PG if DB.adapter_scheme == :postgres
6
6
  uses_pg_or_jdbc = uses_pg || DB.adapter_scheme == :jdbc
7
+ # SEQUEL5: Remove native handling
7
8
 
8
9
  def DB.sqls
9
10
  (@sqls ||= [])
@@ -445,16 +446,16 @@ describe "A PostgreSQL dataset" do
445
446
  end
446
447
 
447
448
  it "should support regexps" do
448
- @d << {:name => 'abc', :value => 1}
449
- @d << {:name => 'bcd', :value => 2}
449
+ @d.insert(:name => 'abc', :value => 1)
450
+ @d.insert(:name => 'bcd', :value => 2)
450
451
  @d.filter(:name => /bc/).count.must_equal 2
451
452
  @d.filter(:name => /^bc/).count.must_equal 1
452
453
  end
453
454
 
454
455
  it "should support NULLS FIRST and NULLS LAST" do
455
- @d << {:name => 'abc'}
456
- @d << {:name => 'bcd'}
457
- @d << {:name => 'bcd', :value => 2}
456
+ @d.insert(:name => 'abc')
457
+ @d.insert(:name => 'bcd')
458
+ @d.insert(:name => 'bcd', :value => 2)
458
459
  @d.order(Sequel.asc(:value, :nulls=>:first), :name).select_map(:name).must_equal %w[abc bcd bcd]
459
460
  @d.order(Sequel.asc(:value, :nulls=>:last), :name).select_map(:name).must_equal %w[bcd abc bcd]
460
461
  @d.order(Sequel.asc(:value, :nulls=>:first), :name).reverse.select_map(:name).must_equal %w[bcd bcd abc]
@@ -681,12 +682,12 @@ describe "A PostgreSQL dataset" do
681
682
  end
682
683
 
683
684
  it "should truncate with options" do
684
- @d << { :name => 'abc', :value => 1}
685
+ @d.insert( :name => 'abc', :value => 1)
685
686
  @d.count.must_equal 1
686
687
  @d.truncate(:cascade => true)
687
688
  @d.count.must_equal 0
688
689
  if @d.db.server_version > 80400
689
- @d << { :name => 'abc', :value => 1}
690
+ @d.insert( :name => 'abc', :value => 1)
690
691
  @d.truncate(:cascade => true, :only=>true, :restart=>true)
691
692
  @d.count.must_equal 0
692
693
  end
@@ -802,7 +803,7 @@ describe "A PostgreSQL dataset with a timestamp field" do
802
803
 
803
804
  cspecify "should store milliseconds in time fields for Time objects", [:do], [:swift] do
804
805
  t = Time.now
805
- @d << {:time=>t}
806
+ @d.insert(:time=>t)
806
807
  t2 = @d.get(:time)
807
808
  @d.literal(t2).must_equal @d.literal(t)
808
809
  t2.strftime('%Y-%m-%d %H:%M:%S').must_equal t.strftime('%Y-%m-%d %H:%M:%S')
@@ -811,7 +812,7 @@ describe "A PostgreSQL dataset with a timestamp field" do
811
812
 
812
813
  cspecify "should store milliseconds in time fields for DateTime objects", [:do], [:swift] do
813
814
  t = DateTime.now
814
- @d << {:time=>t}
815
+ @d.insert(:time=>t)
815
816
  t2 = @d.get(:time)
816
817
  @d.literal(t2).must_equal @d.literal(t)
817
818
  t2.strftime('%Y-%m-%d %H:%M:%S').must_equal t.strftime('%Y-%m-%d %H:%M:%S')
@@ -820,7 +821,7 @@ describe "A PostgreSQL dataset with a timestamp field" do
820
821
 
821
822
  if DB.adapter_scheme == :postgres
822
823
  it "should handle infinite timestamps if convert_infinite_timestamps is set" do
823
- @d << {:time=>Sequel.cast('infinity', DateTime)}
824
+ @d.insert(:time=>Sequel.cast('infinity', DateTime))
824
825
  @db.convert_infinite_timestamps = :nil
825
826
  @db[:test3].get(:time).must_be_nil
826
827
  @db.convert_infinite_timestamps = :string
@@ -863,7 +864,7 @@ describe "A PostgreSQL dataset with a timestamp field" do
863
864
  end
864
865
 
865
866
  it "should handle infinite dates if convert_infinite_timestamps is set" do
866
- @d << {:date=>Sequel.cast('infinity', Date)}
867
+ @d.insert(:date=>Sequel.cast('infinity', Date))
867
868
  @db.convert_infinite_timestamps = :nil
868
869
  @db[:test3].get(:date).must_be_nil
869
870
  @db.convert_infinite_timestamps = :string
@@ -916,12 +917,12 @@ describe "A PostgreSQL database" do
916
917
 
917
918
  it "should support column operations" do
918
919
  @db.create_table!(:test2){text :name; integer :value}
919
- @db[:test2] << {}
920
+ @db[:test2].insert({})
920
921
  @db[:test2].columns.must_equal [:name, :value]
921
922
 
922
923
  @db.add_column :test2, :xyz, :text, :default => '000'
923
924
  @db[:test2].columns.must_equal [:name, :value, :xyz]
924
- @db[:test2] << {:name => 'mmm', :value => 111}
925
+ @db[:test2].insert(:name => 'mmm', :value => 111)
925
926
  @db[:test2].first[:xyz].must_equal '000'
926
927
 
927
928
  @db[:test2].columns.must_equal [:name, :value, :xyz]
@@ -931,7 +932,7 @@ describe "A PostgreSQL database" do
931
932
 
932
933
  @db[:test2].delete
933
934
  @db.add_column :test2, :xyz, :text, :default => '000'
934
- @db[:test2] << {:name => 'mmm', :value => 111, :xyz => 'qqqq'}
935
+ @db[:test2].insert(:name => 'mmm', :value => 111, :xyz => 'qqqq')
935
936
 
936
937
  @db[:test2].columns.must_equal [:name, :value, :xyz]
937
938
  @db.rename_column :test2, :xyz, :zyx
@@ -940,7 +941,7 @@ describe "A PostgreSQL database" do
940
941
 
941
942
  @db.add_column :test2, :xyz, :float
942
943
  @db[:test2].delete
943
- @db[:test2] << {:name => 'mmm', :value => 111, :xyz => 56.78}
944
+ @db[:test2].insert(:name => 'mmm', :value => 111, :xyz => 56.78)
944
945
  @db.set_column_type :test2, :xyz, :integer
945
946
 
946
947
  @db[:test2].first[:xyz].must_equal 57
@@ -1517,19 +1518,19 @@ if DB.server_version >= 80300
1517
1518
 
1518
1519
  it "should search by indexed column" do
1519
1520
  record = {:title => "oopsla conference", :body => "test"}
1520
- @ds << record
1521
+ @ds.insert(record)
1521
1522
  @ds.full_text_search(:title, "oopsla").all.must_include(record)
1522
1523
  end
1523
1524
 
1524
1525
  it "should join multiple coumns with spaces to search by last words in row" do
1525
1526
  record = {:title => "multiple words", :body => "are easy to search"}
1526
- @ds << record
1527
+ @ds.insert(record)
1527
1528
  @ds.full_text_search([:title, :body], "words").all.must_include(record)
1528
1529
  end
1529
1530
 
1530
1531
  it "should return rows with a NULL in one column if a match in another column" do
1531
1532
  record = {:title => "multiple words", :body =>nil}
1532
- @ds << record
1533
+ @ds.insert(record)
1533
1534
  @ds.full_text_search([:title, :body], "words").all.must_include(record)
1534
1535
  end
1535
1536
  end
@@ -1781,7 +1782,7 @@ if DB.adapter_scheme == :postgres
1781
1782
  before(:all) do
1782
1783
  deprecated do
1783
1784
  @db = DB
1784
- @old_cp = @db.conversion_procs[1013]
1785
+ @cp = @db.conversion_procs.dup
1785
1786
  @db.conversion_procs.delete(1013)
1786
1787
  Sequel::Postgres::PG_NAMED_TYPES[:oidvector] = lambda{|v| v.reverse}
1787
1788
  @db.reset_conversion_procs
@@ -1791,8 +1792,7 @@ if DB.adapter_scheme == :postgres
1791
1792
  after(:all) do
1792
1793
  deprecated do
1793
1794
  Sequel::Postgres::PG_NAMED_TYPES.delete(:oidvector)
1794
- @db.conversion_procs.delete(30)
1795
- @db.conversion_procs[1013] = @old_cp
1795
+ @db.conversion_procs.replace(@cp)
1796
1796
  @db.drop_table?(:foo)
1797
1797
  @db.drop_enum(:foo_enum) rescue nil
1798
1798
  end
@@ -1961,6 +1961,18 @@ if uses_pg_or_jdbc && DB.server_version >= 90000
1961
1961
  buf.must_equal ["1,2\n"]
1962
1962
  @db[:test_copy].select_order_map(:x).must_equal [1, 3]
1963
1963
  end
1964
+
1965
+ it "should not swallow error raised by block" do
1966
+ begin
1967
+ @db.copy_table(:test_copy){|b| raise ArgumentError, "foo"}
1968
+ rescue => e
1969
+ end
1970
+
1971
+ e.must_be_kind_of Sequel::DatabaseDisconnectError
1972
+ e.wrapped_exception.must_be_kind_of ArgumentError
1973
+ e.message.must_include "foo"
1974
+ end
1975
+
1964
1976
  end
1965
1977
  end
1966
1978
 
@@ -3375,7 +3387,7 @@ describe 'PostgreSQL interval types' do
3375
3387
  @native = DB.adapter_scheme == :postgres || DB.adapter_scheme == :jdbc
3376
3388
  end
3377
3389
  after(:all) do
3378
- Sequel::Postgres::PG_TYPES.delete(1186)
3390
+ Sequel::Postgres::PG__TYPES.delete(1186) # SEQUEL5: Remove
3379
3391
  end
3380
3392
  after do
3381
3393
  @db.drop_table?(:items)
@@ -3487,16 +3499,18 @@ describe 'PostgreSQL row-valued/composite types' do
3487
3499
  Integer :id
3488
3500
  column :employees, 'person[]'
3489
3501
  end
3502
+ oids = @db.conversion_procs.keys
3490
3503
  @db.register_row_type(:address)
3491
3504
  @db.register_row_type(Sequel.qualify(:public, :person))
3492
3505
  @db.register_row_type(Sequel[:public][:company])
3506
+ @new_oids = @db.conversion_procs.keys - oids
3493
3507
 
3494
3508
  @native = DB.adapter_scheme == :postgres || DB.adapter_scheme == :jdbc
3495
3509
  end
3496
3510
  after(:all) do
3497
- @db.drop_table?(:company, :person, :address)
3511
+ @new_oids.each{|oid| @db.conversion_procs.delete(oid)}
3498
3512
  @db.row_types.clear
3499
- @db.reset_conversion_procs if @native
3513
+ @db.drop_table?(:company, :person, :address)
3500
3514
  end
3501
3515
  after do
3502
3516
  [:company, :person, :address].each{|t| @db[t].delete}
@@ -6,73 +6,66 @@ if DB.table_exists?(:test)
6
6
  DB.drop_table(:test)
7
7
  end
8
8
 
9
- describe "Convert smallint to boolean" do
9
+ describe "convert_smallint_to_bool" do
10
10
  before do
11
11
  @db = DB
12
+ @ds = @db[:booltest]
13
+ @db.send(:remove_instance_variable, :@convert_smallint_to_bool) if @db.instance_variable_defined?(:@convert_smallint_to_bool)
12
14
  end
13
15
  after do
14
- Sequel::SqlAnywhere.convert_smallint_to_bool = true
15
- @db.convert_smallint_to_bool = true
16
+ deprecated do
17
+ Sequel::SqlAnywhere.convert_smallint_to_bool = true
18
+ end
19
+ @db.send(:remove_instance_variable, :@convert_smallint_to_bool) if @db.instance_variable_defined?(:@convert_smallint_to_bool)
16
20
  end
17
21
 
22
+ # SEQUEL5: Remove
18
23
  describe "Sequel::SqlAnywhere.convert_smallint_to_bool" do
19
24
  before do
20
25
  @db.create_table!(:booltest){column :b, 'smallint'; column :i, 'integer'}
21
- @ds = @db[:booltest]
22
26
  end
23
27
  after do
24
28
  @db.drop_table(:booltest)
25
29
  end
26
30
 
27
- it "should consider smallint datatypes as boolean if set, but if not, as larger smallints" do
31
+ deprecated "should consider smallint datatypes as boolean if set, but if not, as larger smallints" do
28
32
  @db.create_table!(:booltest){column :b, 'smallint'; column :i, 'integer'}
29
33
  @db.schema(:booltest, :reload=>true).first.last[:type].must_equal :boolean
30
34
  @db.schema(:booltest, :reload=>true).first.last[:db_type].must_match /smallint/i
31
35
 
32
36
  Sequel::SqlAnywhere.convert_smallint_to_bool = false
33
- @db2 = Sequel.connect(DB.url)
34
- @db2.schema(:booltest, :reload=>true).first.last[:type].must_equal :integer
35
- @db2.schema(:booltest, :reload=>true).first.last[:db_type].must_match /smallint/i
36
-
37
- @db.schema(:booltest, :reload=>true).first.last[:type].must_equal :boolean
37
+ @db.send(:remove_instance_variable, :@convert_smallint_to_bool) if @db.instance_variable_defined?(:@convert_smallint_to_bool)
38
+ @db.schema(:booltest, :reload=>true).first.last[:type].must_equal :integer
38
39
  @db.schema(:booltest, :reload=>true).first.last[:db_type].must_match /smallint/i
39
-
40
- @db2.disconnect
41
40
  end
42
41
 
43
- describe "datasets" do
44
- it "should return smallints as bools and integers as integers when set" do
45
- @ds.delete
46
- @ds << {:b=>true, :i=>10}
47
- @ds.all.must_equal [{:b=>true, :i=>10}]
48
- @ds.delete
49
- @ds << {:b=>false, :i=>0}
50
- @ds.all.must_equal [{:b=>false, :i=>0}]
51
- @ds.delete
52
- @ds << {:b=>true, :i=>1}
53
- @ds.all.must_equal [{:b=>true, :i=>1}]
54
- end
55
-
56
- it "should return all smallints as integers when unset" do
57
- Sequel::SqlAnywhere.convert_smallint_to_bool = false
58
- @db2 = Sequel.connect(DB.url)
59
- @ds2 = @db2[:booltest]
60
- @ds2.delete
61
- @ds2 << {:b=>true, :i=>10}
62
- @ds2.all.must_equal [{:b=>1, :i=>10}]
63
- @ds2.delete
64
- @ds2 << {:b=>false, :i=>0}
65
- @ds2.all.must_equal [{:b=>0, :i=>0}]
66
-
67
- @ds2.delete
68
- @ds2 << {:b=>1, :i=>10}
69
- @ds2.all.must_equal [{:b=>1, :i=>10}]
70
- @ds2.delete
71
- @ds2 << {:b=>0, :i=>0}
72
- @ds2.all.must_equal [{:b=>0, :i=>0}]
42
+ it "should return smallints as bools and integers as integers when set" do
43
+ @ds.delete
44
+ @ds.insert(:b=>true, :i=>10)
45
+ @ds.all.must_equal [{:b=>true, :i=>10}]
46
+ @ds.delete
47
+ @ds.insert(:b=>false, :i=>0)
48
+ @ds.all.must_equal [{:b=>false, :i=>0}]
49
+ @ds.delete
50
+ @ds.insert(:b=>true, :i=>1)
51
+ @ds.all.must_equal [{:b=>true, :i=>1}]
52
+ end
73
53
 
74
- @db2.disconnect
75
- end
54
+ deprecated "should return all smallints as integers when unset" do
55
+ Sequel::SqlAnywhere.convert_smallint_to_bool = false
56
+ @ds.delete
57
+ @ds.insert(:b=>true, :i=>10)
58
+ @ds.all.must_equal [{:b=>1, :i=>10}]
59
+ @ds.delete
60
+ @ds.insert(:b=>false, :i=>0)
61
+ @ds.all.must_equal [{:b=>0, :i=>0}]
62
+
63
+ @ds.delete
64
+ @ds.insert(:b=>1, :i=>10)
65
+ @ds.all.must_equal [{:b=>1, :i=>10}]
66
+ @ds.delete
67
+ @ds.insert(:b=>0, :i=>0)
68
+ @ds.all.must_equal [{:b=>0, :i=>0}]
76
69
  end
77
70
  end
78
71
 
@@ -92,47 +85,39 @@ describe "Convert smallint to boolean" do
92
85
  @db.schema(:booltest, :reload=>true).first.last[:db_type].must_match /smallint/i
93
86
  end
94
87
 
95
- describe "datasets" do
96
- it "should return smallints as bools and integers as integers when set" do
97
- @ds = @db[:booltest]
98
- @ds.delete
99
- @ds << {:b=>true, :i=>10}
100
- @ds.all.must_equal [{:b=>true, :i=>10}]
101
- @ds.delete
102
- @ds << {:b=>false, :i=>0}
103
- @ds.all.must_equal [{:b=>false, :i=>0}]
104
- @ds.delete
105
- @ds << {:b=>true, :i=>1}
106
- @ds.all.must_equal [{:b=>true, :i=>1}]
107
- end
108
-
109
- it "should return all smallints as integers when unset" do
110
- @db2 = Sequel.connect(DB.url)
111
- @db2.convert_smallint_to_bool = false
112
- @ds2 = @db2[:booltest]
113
- @ds2.delete
114
- @ds2 << {:b=>true, :i=>10}
115
- @ds2.all.must_equal [{:b=>1, :i=>10}]
116
- @ds2.delete
117
- @ds2 << {:b=>false, :i=>0}
118
- @ds2.all.must_equal [{:b=>0, :i=>0}]
119
-
120
- @ds2.delete
121
- @ds2 << {:b=>1, :i=>10}
122
- @ds2.all.must_equal [{:b=>1, :i=>10}]
123
- @ds2.delete
124
- @ds2 << {:b=>0, :i=>0}
125
- @ds2.all.must_equal [{:b=>0, :i=>0}]
88
+ it "should return smallints as bools and integers as integers when set" do
89
+ @ds.delete
90
+ @ds.insert(:b=>true, :i=>10)
91
+ @ds.all.must_equal [{:b=>true, :i=>10}]
92
+ @ds.delete
93
+ @ds.insert(:b=>false, :i=>0)
94
+ @ds.all.must_equal [{:b=>false, :i=>0}]
95
+ @ds.delete
96
+ @ds.insert(:b=>true, :i=>1)
97
+ @ds.all.must_equal [{:b=>true, :i=>1}]
98
+ end
126
99
 
127
- @db2.disconnect
128
- end
100
+ it "should return all smallints as integers when unset" do
101
+ @db.convert_smallint_to_bool = false
102
+ @ds.delete
103
+ @ds.insert(:b=>true, :i=>10)
104
+ @ds.all.must_equal [{:b=>1, :i=>10}]
105
+ @ds.delete
106
+ @ds.insert(:b=>false, :i=>0)
107
+ @ds.all.must_equal [{:b=>0, :i=>0}]
108
+
109
+ @ds.delete
110
+ @ds.insert(:b=>1, :i=>10)
111
+ @ds.all.must_equal [{:b=>1, :i=>10}]
112
+ @ds.delete
113
+ @ds.insert(:b=>0, :i=>0)
114
+ @ds.all.must_equal [{:b=>0, :i=>0}]
129
115
  end
130
116
  end
131
117
 
132
118
  describe "Dataset#convert_smallint_to_bool" do
133
119
  before do
134
120
  @db.create_table!(:booltest){column :b, 'smallint'; column :i, 'integer'}
135
- @ds = @db[:booltest]
136
121
  end
137
122
  after do
138
123
  @db.drop_table(:booltest)
@@ -140,30 +125,47 @@ describe "Convert smallint to boolean" do
140
125
 
141
126
  it "should return smallints as bools and integers as integers when set" do
142
127
  @ds.delete
143
- @ds << {:b=>true, :i=>10}
128
+ @ds.insert(:b=>true, :i=>10)
144
129
  @ds.all.must_equal [{:b=>true, :i=>10}]
145
130
  @ds.delete
146
- @ds << {:b=>false, :i=>0}
131
+ @ds.insert(:b=>false, :i=>0)
147
132
  @ds.all.must_equal [{:b=>false, :i=>0}]
148
133
  @ds.delete
149
- @ds << {:b=>true, :i=>1}
134
+ @ds.insert(:b=>true, :i=>1)
150
135
  @ds.all.must_equal [{:b=>true, :i=>1}]
151
136
  end
152
137
 
153
- it "should return all smallints as integers when unset" do
138
+ deprecated "should return all smallints as integers when unset" do
154
139
  @ds.convert_smallint_to_bool = false
155
140
  @ds.delete
156
- @ds << {:b=>true, :i=>10}
141
+ @ds.insert(:b=>true, :i=>10)
142
+ @ds.all.must_equal [{:b=>1, :i=>10}]
143
+ @ds.delete
144
+ @ds.insert(:b=>false, :i=>0)
145
+ @ds.all.must_equal [{:b=>0, :i=>0}]
146
+
147
+ @ds.delete
148
+ @ds.insert(:b=>1, :i=>10)
149
+ @ds.all.must_equal [{:b=>1, :i=>10}]
150
+ @ds.delete
151
+ @ds.insert(:b=>0, :i=>0)
152
+ @ds.all.must_equal [{:b=>0, :i=>0}]
153
+ end
154
+
155
+ it "should support with_convert_smallint_to_bool for returning modified dataset with setting changed" do
156
+ @ds = @ds.with_convert_smallint_to_bool(false)
157
+ @ds.delete
158
+ @ds.insert(:b=>true, :i=>10)
157
159
  @ds.all.must_equal [{:b=>1, :i=>10}]
158
160
  @ds.delete
159
- @ds << {:b=>false, :i=>0}
161
+ @ds.insert(:b=>false, :i=>0)
160
162
  @ds.all.must_equal [{:b=>0, :i=>0}]
161
163
 
162
164
  @ds.delete
163
- @ds << {:b=>1, :i=>10}
165
+ @ds.insert(:b=>1, :i=>10)
164
166
  @ds.all.must_equal [{:b=>1, :i=>10}]
165
167
  @ds.delete
166
- @ds << {:b=>0, :i=>0}
168
+ @ds.insert(:b=>0, :i=>0)
167
169
  @ds.all.must_equal [{:b=>0, :i=>0}]
168
170
  end
169
171
  end