sequel 4.44.0 → 4.45.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +110 -0
  3. data/README.rdoc +8 -9
  4. data/doc/active_record.rdoc +2 -3
  5. data/doc/model_plugins.rdoc +1 -1
  6. data/doc/opening_databases.rdoc +0 -46
  7. data/doc/release_notes/4.45.0.txt +370 -0
  8. data/lib/sequel/adapters/cubrid.rb +2 -0
  9. data/lib/sequel/adapters/do.rb +2 -0
  10. data/lib/sequel/adapters/jdbc/as400.rb +2 -0
  11. data/lib/sequel/adapters/jdbc/cubrid.rb +2 -0
  12. data/lib/sequel/adapters/jdbc/firebirdsql.rb +2 -0
  13. data/lib/sequel/adapters/jdbc/informix-sqli.rb +2 -0
  14. data/lib/sequel/adapters/jdbc/jdbcprogress.rb +2 -0
  15. data/lib/sequel/adapters/jdbc/mysql.rb +1 -0
  16. data/lib/sequel/adapters/jdbc/postgresql.rb +5 -0
  17. data/lib/sequel/adapters/mysql.rb +1 -0
  18. data/lib/sequel/adapters/mysql2.rb +1 -0
  19. data/lib/sequel/adapters/odbc/oracle.rb +11 -0
  20. data/lib/sequel/adapters/odbc/progress.rb +2 -0
  21. data/lib/sequel/adapters/postgres.rb +0 -2
  22. data/lib/sequel/adapters/shared/cubrid.rb +2 -0
  23. data/lib/sequel/adapters/shared/firebird.rb +2 -0
  24. data/lib/sequel/adapters/shared/informix.rb +2 -0
  25. data/lib/sequel/adapters/shared/mssql.rb +47 -7
  26. data/lib/sequel/adapters/shared/mysql.rb +16 -1
  27. data/lib/sequel/adapters/shared/postgres.rb +9 -1
  28. data/lib/sequel/adapters/shared/progress.rb +2 -0
  29. data/lib/sequel/adapters/shared/sqlanywhere.rb +1 -1
  30. data/lib/sequel/adapters/swift.rb +2 -0
  31. data/lib/sequel/ast_transformer.rb +13 -6
  32. data/lib/sequel/core.rb +13 -16
  33. data/lib/sequel/database/connecting.rb +25 -10
  34. data/lib/sequel/database/dataset.rb +6 -1
  35. data/lib/sequel/database/dataset_defaults.rb +9 -2
  36. data/lib/sequel/database/misc.rb +10 -3
  37. data/lib/sequel/database/schema_methods.rb +4 -0
  38. data/lib/sequel/dataset/mutation.rb +8 -20
  39. data/lib/sequel/dataset/prepared_statements.rb +2 -0
  40. data/lib/sequel/dataset/query.rb +32 -7
  41. data/lib/sequel/dataset/sql.rb +13 -3
  42. data/lib/sequel/deprecated.rb +9 -1
  43. data/lib/sequel/exceptions.rb +37 -8
  44. data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +117 -0
  45. data/lib/sequel/extensions/date_arithmetic.rb +1 -0
  46. data/lib/sequel/extensions/identifier_mangling.rb +3 -2
  47. data/lib/sequel/extensions/pg_hstore.rb +1 -5
  48. data/lib/sequel/extensions/schema_dumper.rb +3 -1
  49. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +2 -2
  50. data/lib/sequel/extensions/string_agg.rb +1 -0
  51. data/lib/sequel/model.rb +23 -10
  52. data/lib/sequel/model/associations.rb +17 -5
  53. data/lib/sequel/model/base.rb +115 -62
  54. data/lib/sequel/model/dataset_module.rb +10 -3
  55. data/lib/sequel/model/exceptions.rb +7 -5
  56. data/lib/sequel/plugins/association_pks.rb +13 -1
  57. data/lib/sequel/plugins/association_proxies.rb +8 -1
  58. data/lib/sequel/plugins/before_after_save.rb +1 -0
  59. data/lib/sequel/plugins/class_table_inheritance.rb +7 -3
  60. data/lib/sequel/plugins/columns_updated.rb +42 -0
  61. data/lib/sequel/plugins/composition.rb +10 -5
  62. data/lib/sequel/plugins/error_splitter.rb +1 -1
  63. data/lib/sequel/plugins/hook_class_methods.rb +39 -5
  64. data/lib/sequel/plugins/instance_hooks.rb +58 -5
  65. data/lib/sequel/plugins/lazy_attributes.rb +10 -5
  66. data/lib/sequel/plugins/nested_attributes.rb +10 -5
  67. data/lib/sequel/plugins/prepared_statements.rb +7 -0
  68. data/lib/sequel/plugins/prepared_statements_associations.rb +2 -0
  69. data/lib/sequel/plugins/prepared_statements_with_pk.rb +2 -0
  70. data/lib/sequel/plugins/schema.rb +2 -0
  71. data/lib/sequel/plugins/scissors.rb +2 -0
  72. data/lib/sequel/plugins/serialization.rb +10 -5
  73. data/lib/sequel/plugins/split_values.rb +5 -1
  74. data/lib/sequel/plugins/static_cache.rb +2 -2
  75. data/lib/sequel/plugins/tactical_eager_loading.rb +1 -1
  76. data/lib/sequel/plugins/validation_contexts.rb +49 -0
  77. data/lib/sequel/plugins/validation_helpers.rb +1 -0
  78. data/lib/sequel/sql.rb +1 -1
  79. data/lib/sequel/version.rb +1 -1
  80. data/spec/adapters/mssql_spec.rb +31 -0
  81. data/spec/adapters/mysql_spec.rb +20 -2
  82. data/spec/adapters/postgres_spec.rb +43 -12
  83. data/spec/adapters/spec_helper.rb +5 -8
  84. data/spec/core/database_spec.rb +47 -12
  85. data/spec/core/dataset_mutation_spec.rb +22 -22
  86. data/spec/core/dataset_spec.rb +88 -20
  87. data/spec/core/deprecated_spec.rb +1 -1
  88. data/spec/core/expression_filters_spec.rb +1 -1
  89. data/spec/core/mock_adapter_spec.rb +0 -3
  90. data/spec/core/placeholder_literalizer_spec.rb +1 -1
  91. data/spec/core/schema_spec.rb +8 -1
  92. data/spec/core/spec_helper.rb +6 -1
  93. data/spec/core_extensions_spec.rb +4 -0
  94. data/spec/deprecation_helper.rb +17 -0
  95. data/spec/extensions/_deprecated_identifier_mangling_spec.rb +314 -0
  96. data/spec/extensions/association_pks_spec.rb +61 -13
  97. data/spec/extensions/association_proxies_spec.rb +3 -3
  98. data/spec/extensions/class_table_inheritance_spec.rb +39 -0
  99. data/spec/extensions/columns_updated_spec.rb +35 -0
  100. data/spec/extensions/composition_spec.rb +6 -1
  101. data/spec/extensions/hook_class_methods_spec.rb +114 -26
  102. data/spec/extensions/identifier_mangling_spec.rb +107 -73
  103. data/spec/extensions/instance_hooks_spec.rb +78 -14
  104. data/spec/extensions/lazy_attributes_spec.rb +8 -2
  105. data/spec/extensions/many_through_many_spec.rb +2 -2
  106. data/spec/extensions/mssql_optimistic_locking_spec.rb +1 -1
  107. data/spec/extensions/nested_attributes_spec.rb +8 -2
  108. data/spec/extensions/pg_array_spec.rb +18 -4
  109. data/spec/extensions/prepared_statements_associations_spec.rb +48 -39
  110. data/spec/extensions/prepared_statements_with_pk_spec.rb +13 -11
  111. data/spec/extensions/query_spec.rb +1 -1
  112. data/spec/extensions/schema_dumper_spec.rb +34 -6
  113. data/spec/extensions/schema_spec.rb +13 -7
  114. data/spec/extensions/scissors_spec.rb +3 -1
  115. data/spec/extensions/sequel_3_dataset_methods_spec.rb +4 -4
  116. data/spec/extensions/serialization_spec.rb +7 -1
  117. data/spec/extensions/set_overrides_spec.rb +2 -2
  118. data/spec/extensions/shared_caching_spec.rb +19 -15
  119. data/spec/extensions/spec_helper.rb +7 -3
  120. data/spec/extensions/split_values_spec.rb +45 -10
  121. data/spec/extensions/string_agg_spec.rb +2 -2
  122. data/spec/extensions/subset_conditions_spec.rb +3 -3
  123. data/spec/extensions/tactical_eager_loading_spec.rb +1 -1
  124. data/spec/extensions/validation_contexts_spec.rb +31 -0
  125. data/spec/guards_helper.rb +2 -0
  126. data/spec/integration/associations_test.rb +22 -20
  127. data/spec/integration/dataset_test.rb +25 -2
  128. data/spec/integration/model_test.rb +1 -1
  129. data/spec/integration/plugin_test.rb +11 -16
  130. data/spec/integration/prepared_statement_test.rb +40 -32
  131. data/spec/integration/spec_helper.rb +5 -8
  132. data/spec/model/association_reflection_spec.rb +4 -0
  133. data/spec/model/associations_spec.rb +37 -10
  134. data/spec/model/base_spec.rb +6 -0
  135. data/spec/model/hooks_spec.rb +56 -35
  136. data/spec/model/model_spec.rb +21 -5
  137. data/spec/model/record_spec.rb +14 -11
  138. data/spec/model/spec_helper.rb +7 -1
  139. data/spec/sequel_warning.rb +11 -0
  140. metadata +13 -3
@@ -1,5 +1,7 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ Sequel::Deprecation.deprecate("The prepared_statements_associations plugin", "Stop using the plugin, it is probably unneeded and making the application slower")
4
+
3
5
  module Sequel
4
6
  module Plugins
5
7
  # The prepared_statements_associations plugin modifies the regular association
@@ -1,5 +1,7 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ Sequel::Deprecation.deprecate("The prepared_statements_with_pk plugin", "Stop using the plugin, it is probably unneeded and making the application slower")
4
+
3
5
  module Sequel
4
6
  module Plugins
5
7
  # The prepared_statements_with_pk plugin allows Dataset#with_pk for model datasets
@@ -1,5 +1,7 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ Sequel::Deprecation.deprecate("The schema plugin", "Switch to defining your schema using Database schema methods before creating your model classes")
4
+
3
5
  module Sequel
4
6
  module Plugins
5
7
  # Sequel's built in schema plugin allows you to define your schema
@@ -1,5 +1,7 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ Sequel::Deprecation.deprecate("The scissors plugin", "Running with scissors is dangerous")
4
+
3
5
  module Sequel
4
6
  module Plugins
5
7
  # The scissors plugin adds class methods for update, delete, and destroy.
@@ -120,9 +120,14 @@ module Sequel
120
120
  # called to serialize the column.
121
121
  attr_reader :serialization_map
122
122
 
123
- # Module to store the serialized column accessor methods, so they can
124
- # call be overridden and call super to get the serialization behavior
125
- attr_accessor :serialization_module
123
+ def serialization_module
124
+ Sequel::Deprecation.deprecate('Sequel::Model.serialization_module', 'There is no replacement')
125
+ @serialization_module
126
+ end
127
+ def serialization_module=(v)
128
+ Sequel::Deprecation.deprecate('Sequel::Model.serialization_module=', 'There is no replacement')
129
+ @serialization_module = v
130
+ end
126
131
 
127
132
  Plugins.inherited_instance_variables(self, :@deserialization_map=>:dup, :@serialization_map=>:dup)
128
133
 
@@ -159,8 +164,8 @@ module Sequel
159
164
  # Add serializated attribute acessor methods to the serialization_module
160
165
  def define_serialized_attribute_accessor(serializer, deserializer, *columns)
161
166
  m = self
162
- include(self.serialization_module ||= Module.new) unless serialization_module
163
- serialization_module.class_eval do
167
+ include(@serialization_module ||= Module.new) unless @serialization_module
168
+ @serialization_module.class_eval do
164
169
  columns.each do |column|
165
170
  m.serialization_map[column] = serializer
166
171
  m.deserialization_map[column] = deserializer
@@ -47,7 +47,11 @@ module Sequel
47
47
  # If there isn't an entry in the values hash, but there is a noncolumn_values
48
48
  # hash, look in that hash for the value.
49
49
  def [](k)
50
- super || (@noncolumn_values[k] if !@values.has_key?(k) && @noncolumn_values)
50
+ if (res = super).nil?
51
+ @noncolumn_values[k] if !@values.has_key?(k) && @noncolumn_values
52
+ else
53
+ res
54
+ end
51
55
  end
52
56
 
53
57
  # Check all entries in the values hash. If any of the keys are not columns,
@@ -225,13 +225,13 @@ module Sequel
225
225
  module InstanceMethods
226
226
  # Disallowing destroying the object unless the :frozen=>false option was used.
227
227
  def before_destroy
228
- return false unless model.static_cache_allow_modifications?
228
+ cancel_action("modifying model objects that use the static_cache plugin is not allowed") unless model.static_cache_allow_modifications?
229
229
  super
230
230
  end
231
231
 
232
232
  # Disallowing saving the object unless the :frozen=>false option was used.
233
233
  def before_save
234
- return false unless model.static_cache_allow_modifications?
234
+ cancel_action("modifying model objects that use the static_cache plugin is not allowed") unless model.static_cache_allow_modifications?
235
235
  super
236
236
  end
237
237
  end
@@ -91,7 +91,7 @@ module Sequel
91
91
  # If there the association is not in the associations cache and the object
92
92
  # was reteived via Dataset#all, eagerly load the association for all model
93
93
  # objects retrieved with the current object.
94
- def load_associated_objects(opts, dynamic_opts=nil, &block)
94
+ def load_associated_objects(opts, dynamic_opts=OPTS, &block)
95
95
  dynamic_opts = load_association_objects_options(dynamic_opts, &block)
96
96
  name = opts[:name]
97
97
  if (!associations.include?(name) || dynamic_opts[:eager_reload]) && retrieved_by && !frozen? && !dynamic_opts[:callback] && !dynamic_opts[:reload]
@@ -0,0 +1,49 @@
1
+ # frozen-string-literal: true
2
+
3
+ module Sequel
4
+ module Plugins
5
+ # The validation_contexts plugin adds support for a validation_context method inside a validate
6
+ # method. You pass in the validation context to use via the :validation_context option to
7
+ # Sequel::Model#save && Sequel::Model#valid?:
8
+ #
9
+ # class Album < Sequel::Model
10
+ # plugin :validation_contexts
11
+ # def validate
12
+ # super
13
+ # errors.add(:status_id, 'not 1') if status_id != 1 && validation_context == :initial
14
+ # errors.add(:status_id, 'not 2') if status_id != 2 && validation_context == :approve
15
+ # end
16
+ # end
17
+ #
18
+ # Album.new(:status_id=>1).valid?(:validation_context=>:initial) # => true
19
+ # Album.new(:status_id=>2).valid?(:validation_context=>:initial) # => false
20
+ #
21
+ # Album.new(:status_id=>1).valid?(:validation_context=>:approve) # => false
22
+ # Album.new(:status_id=>2).valid?(:validation_context=>:approve) # => true
23
+ #
24
+ # There is no validation context used by default, so validation_context will be
25
+ # +nil+ if one is not specified. If you want to differentiate between creating new
26
+ # objects and updating existing objects, just use +new?+.
27
+ #
28
+ # Once this plugin is loaded into a model, after you freeze an instance
29
+ # of that model, you can no longer specify a validation context when
30
+ # validating the instance.
31
+ module ValidationContexts
32
+ module InstanceMethods
33
+ # The validation context to use for the current validation.
34
+ # Set via the :validation_context option passed to save/valid?.
35
+ attr_reader :validation_context
36
+
37
+ private
38
+
39
+ # Set validation context before running validations
40
+ def _valid?(opts)
41
+ @validation_context = opts[:validation_context] if opts[:validation_context]
42
+ super
43
+ ensure
44
+ @validation_context = nil if @validation_context
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -244,6 +244,7 @@ module Sequel
244
244
  atts.each do |a|
245
245
  arr = Array(a)
246
246
  next if arr.any?{|x| errors.on(x)}
247
+ # SEQUEL5: Default only_if_modified to true
247
248
  next if opts[:only_if_modified] && !new? && !arr.any?{|x| changed_columns.include?(x)}
248
249
  ds = opts[:dataset] || model.dataset
249
250
  ds = if where
data/lib/sequel/sql.rb CHANGED
@@ -428,7 +428,7 @@ module Sequel
428
428
  # Sequel.deep_qualify(:table, Sequel.+(:column, 1)) # "table"."column" + 1
429
429
  # Sequel.deep_qualify(:table, Sequel.like(:a, 'b')) # "table"."a" LIKE 'b' ESCAPE '\'
430
430
  def deep_qualify(qualifier, expr)
431
- Sequel::Qualifier.new(Sequel, qualifier).transform(expr)
431
+ Sequel::Qualifier.new(qualifier).transform(expr)
432
432
  end
433
433
 
434
434
  # Return a delayed evaluation that uses the passed block. This is used
@@ -5,7 +5,7 @@ module Sequel
5
5
  MAJOR = 4
6
6
  # The minor version of Sequel. Bumped for every non-patch level
7
7
  # release, generally around once a month.
8
- MINOR = 44
8
+ MINOR = 45
9
9
  # The tiny version of Sequel. Usually 0, only bumped for bugfix
10
10
  # releases that fix regressions from previous versions.
11
11
  TINY = 0
@@ -264,6 +264,37 @@ describe "Offset support" do
264
264
  end
265
265
  end
266
266
 
267
+ describe "Update/Delete on limited datasets" do
268
+ before do
269
+ @db = DB
270
+ @db.create_table!(:i){Integer :id}
271
+ @ds = @db[:i]
272
+ @ds.import [:id], [[1], [2]]
273
+ end
274
+ after do
275
+ @db.drop_table?(:i)
276
+ end
277
+
278
+ it "should handle deletes and updates on limited datasets" do
279
+ @ds.limit(1).update(:id=>Sequel[:id]+10)
280
+ [[2, 11], [1, 12]].must_include @ds.select_order_map(:id)
281
+ @ds.limit(1).delete
282
+ [[1], [2]].must_include @ds.select_order_map(:id)
283
+ end
284
+
285
+ it "should raise error for updates on ordered, limited datasets" do
286
+ end
287
+
288
+ it "should raise error for updates and deletes on datasets with offsets or limits with orders" do
289
+ proc{@ds.offset(1).delete}.must_raise Sequel::InvalidOperation
290
+ proc{@ds.offset(1).update(:id=>Sequel[:id]+10)}.must_raise Sequel::InvalidOperation
291
+ proc{@ds.limit(1, 1).delete}.must_raise Sequel::InvalidOperation
292
+ proc{@ds.limit(1, 1).update(:id=>Sequel[:id]+10)}.must_raise Sequel::InvalidOperation
293
+ proc{@ds.order(:id).limit(1).update(:id=>Sequel[:id]+10)}.must_raise Sequel::InvalidOperation
294
+ proc{@ds.order(:id).limit(1).delete}.must_raise Sequel::InvalidOperation
295
+ end if false # SEQUEL5
296
+ end if DB.dataset.send(:is_2012_or_later?)
297
+
267
298
  describe "Common Table Expressions" do
268
299
  before do
269
300
  @db = DB
@@ -202,10 +202,23 @@ describe "A MySQL dataset" do
202
202
  @d.order(:name).update_sql(:value => 1).must_equal 'UPDATE `items` SET `value` = 1 ORDER BY `name`'
203
203
  end
204
204
 
205
- it "should support LIMIT clause in UPDATE statements" do
206
- @d.limit(10).update_sql(:value => 1).must_equal 'UPDATE `items` SET `value` = 1 LIMIT 10'
205
+ it "should support updating a limited dataset" do
206
+ @d.import [:value], [[2], [3]]
207
+ @d.limit(1).update(:value => 4).must_equal 1
208
+ [[2,4], [3,4]].must_include @d.select_order_map(:value)
207
209
  end
208
210
 
211
+ it "should support updating a ordered, limited dataset" do
212
+ @d.import [:value], [[2], [3]]
213
+ @d.order(:value).limit(1).update(:value => 4).must_equal 1
214
+ @d.select_order_map(:value).must_equal [3,4]
215
+ end
216
+
217
+ it "should raise error for updating a dataset with an offset" do
218
+ proc{@d.offset(1).update(:value => 4)}.must_raise Sequel::InvalidOperation
219
+ proc{@d.order(:value).offset(1).update(:value => 4)}.must_raise Sequel::InvalidOperation
220
+ end if false # SEQUEL5
221
+
209
222
  it "should support regexps" do
210
223
  @d << {:name => 'abc', :value => 1}
211
224
  @d << {:name => 'bcd', :value => 2}
@@ -338,6 +351,11 @@ describe "A MySQL database" do
338
351
  it "should handle the creation and dropping of an InnoDB table with foreign keys" do
339
352
  DB.create_table!(:test_innodb, :engine=>:InnoDB){primary_key :id; foreign_key :fk, :test_innodb, :key=>:id}
340
353
  end
354
+
355
+ it "should handle qualified tables in #indexes" do
356
+ DB.create_table!(:test_innodb){primary_key :id; String :name; index :name, :unique=>true, :name=>:test_innodb_name_idx}
357
+ DB.indexes(Sequel.qualify(DB.get{database{}}, :test_innodb)).must_equal(:test_innodb_name_idx=>{:unique=>true, :columns=>[:name]})
358
+ end
341
359
  end
342
360
 
343
361
  describe "A MySQL database" do
@@ -1041,11 +1041,11 @@ describe "A PostgreSQL database" do
1041
1041
  end
1042
1042
 
1043
1043
  it "should support indexes with index type" do
1044
- @db.create_table(:posts){varchar :title, :size => 5; index :title, :type => 'hash'}
1044
+ @db.create_table(:posts){point :p; index :p, :type => 'gist'}
1045
1045
  check_sqls do
1046
1046
  @db.sqls.must_equal [
1047
- 'CREATE TABLE "posts" ("title" varchar(5))',
1048
- 'CREATE INDEX "posts_title_index" ON "posts" USING hash ("title")'
1047
+ 'CREATE TABLE "posts" ("p" point)',
1048
+ 'CREATE INDEX "posts_p_index" ON "posts" USING gist ("p")'
1049
1049
  ]
1050
1050
  end
1051
1051
  end
@@ -1739,36 +1739,33 @@ if DB.adapter_scheme == :postgres
1739
1739
  end
1740
1740
  end
1741
1741
 
1742
- describe "Postgres::PG_NAMED_TYPES" do
1742
+ describe "Database#add_named_conversion_proc" do
1743
1743
  before(:all) do
1744
1744
  @db = DB
1745
1745
  @old_cp = @db.conversion_procs[1013]
1746
1746
  @db.conversion_procs.delete(1013)
1747
- Sequel::Postgres::PG_NAMED_TYPES[:oidvector] = lambda{|v| v.reverse}
1748
- @db.reset_conversion_procs
1749
- @db.register_array_type('oidvector')
1747
+ @db.add_named_conversion_proc(:oidvector, &:reverse)
1750
1748
  end
1751
1749
  after(:all) do
1752
- Sequel::Postgres::PG_NAMED_TYPES.delete(:oidvector)
1753
1750
  @db.conversion_procs.delete(30)
1754
1751
  @db.conversion_procs[1013] = @old_cp
1755
1752
  @db.drop_table?(:foo)
1756
- @db.drop_enum(:foo_enum)
1753
+ @db.drop_enum(:foo_enum) rescue nil
1757
1754
  end
1758
1755
 
1759
- it "should look up conversion procs by name" do
1756
+ it "should work for scalar types" do
1760
1757
  @db.create_table!(:foo){oidvector :bar}
1761
1758
  @db[:foo].insert(Sequel.cast('21', :oidvector))
1762
1759
  @db[:foo].get(:bar).must_equal '12'
1763
1760
  end
1764
1761
 
1765
- it "should handle array types of named types" do
1762
+ it "should work for array types" do
1766
1763
  @db.create_table!(:foo){column :bar, 'oidvector[]'}
1767
1764
  @db[:foo].insert(Sequel.pg_array(['21'], :oidvector))
1768
1765
  @db[:foo].get(:bar).must_equal ['12']
1769
1766
  end
1770
1767
 
1771
- it "should work with conversion procs on enums" do
1768
+ it "should work with for enums" do
1772
1769
  @db.drop_enum(:foo_enum) rescue nil
1773
1770
  @db.create_enum(:foo_enum, %w(foo bar))
1774
1771
  @db.add_named_conversion_proc(:foo_enum){|string| string.reverse}
@@ -1777,6 +1774,40 @@ if DB.adapter_scheme == :postgres
1777
1774
  @db[:foo].get(:bar).must_equal 'foo'.reverse
1778
1775
  end
1779
1776
  end
1777
+
1778
+ describe "Postgres::PG_NAMED_TYPES" do
1779
+ before(:all) do
1780
+ deprecated do
1781
+ @db = DB
1782
+ @old_cp = @db.conversion_procs[1013]
1783
+ @db.conversion_procs.delete(1013)
1784
+ Sequel::Postgres::PG_NAMED_TYPES[:oidvector] = lambda{|v| v.reverse}
1785
+ @db.reset_conversion_procs
1786
+ @db.register_array_type('oidvector')
1787
+ end
1788
+ end
1789
+ after(:all) do
1790
+ deprecated do
1791
+ Sequel::Postgres::PG_NAMED_TYPES.delete(:oidvector)
1792
+ @db.conversion_procs.delete(30)
1793
+ @db.conversion_procs[1013] = @old_cp
1794
+ @db.drop_table?(:foo)
1795
+ @db.drop_enum(:foo_enum) rescue nil
1796
+ end
1797
+ end
1798
+
1799
+ deprecated "should look up conversion procs by name" do
1800
+ @db.create_table!(:foo){oidvector :bar}
1801
+ @db[:foo].insert(Sequel.cast('21', :oidvector))
1802
+ @db[:foo].get(:bar).must_equal '12'
1803
+ end
1804
+
1805
+ deprecated "should handle array types of named types" do
1806
+ @db.create_table!(:foo){column :bar, 'oidvector[]'}
1807
+ @db[:foo].insert(Sequel.pg_array(['21'], :oidvector))
1808
+ @db[:foo].get(:bar).must_equal ['12']
1809
+ end
1810
+ end
1780
1811
  end
1781
1812
 
1782
1813
  if uses_pg_or_jdbc && DB.server_version >= 90000
@@ -20,11 +20,8 @@ Sequel.split_symbols = false if ENV['SEQUEL_NO_SPLIT_SYMBOLS']
20
20
  Sequel::Database.extension :duplicate_column_handler if ENV['SEQUEL_DUPLICATE_COLUMN_HANDLER']
21
21
  Sequel::Database.extension :columns_introspection if ENV['SEQUEL_COLUMNS_INTROSPECTION']
22
22
  Sequel::Model.cache_associations = false if ENV['SEQUEL_NO_CACHE_ASSOCIATIONS']
23
- if ENV['SEQUEL_MODEL_PREPARED_STATEMENTS']
24
- Sequel::Model.plugin :prepared_statements
25
- Sequel::Model.plugin :prepared_statements_associations
26
- end
27
- Sequel.cache_anonymous_models = false
23
+ Sequel::Model.plugin :prepared_statements if ENV['SEQUEL_MODEL_PREPARED_STATEMENTS']
24
+ Sequel::Model.cache_anonymous_models = false
28
25
 
29
26
  class Sequel::Database
30
27
  def log_duration(duration, message)
@@ -48,10 +45,10 @@ IDENTIFIER_MANGLING = !ENV['SEQUEL_NO_MANGLE'] unless defined?(IDENTIFIER_MANGLI
48
45
  unless defined?(DB)
49
46
  env_var = "SEQUEL_#{SEQUEL_ADAPTER_TEST.to_s.upcase}_URL"
50
47
  env_var = ENV.has_key?(env_var) ? env_var : 'SEQUEL_INTEGRATION_URL'
51
- opts = {}
52
- opts[:identifier_mangling] = false unless IDENTIFIER_MANGLING
53
- DB = Sequel.connect(ENV[env_var], opts)
48
+ # SEQUEL5: Remove :identifier_mangling=>false
49
+ DB = Sequel.connect(ENV[env_var], :identifier_mangling=>false)
54
50
  DB.extension(:freeze_datasets) if ENV['SEQUEL_FREEZE_DATASETS']
51
+ DB.extension(:identifier_mangling) if IDENTIFIER_MANGLING
55
52
  end
56
53
 
57
54
  if dch = ENV['SEQUEL_DUPLICATE_COLUMNS_HANDLER']
@@ -5,11 +5,23 @@ describe "A new Database" do
5
5
  @db = Sequel::Database.new(1 => 2, :logger => 3)
6
6
  end
7
7
  after do
8
- Sequel.quote_identifiers = false
9
- Sequel.identifier_input_method = nil
10
- Sequel.identifier_output_method = nil
8
+ deprecated do
9
+ Sequel.quote_identifiers = false
10
+ Sequel.identifier_input_method = nil
11
+ Sequel.identifier_output_method = nil
12
+ end
11
13
  end
12
14
 
15
+ deprecated "should allow dup/clone" do
16
+ @db.dup.must_be_kind_of @db.class
17
+ @db.clone.must_be_kind_of @db.class
18
+ end
19
+
20
+ it "should not allow dup/clone" do
21
+ proc{@db.dup}.must_raise Sequel::Error
22
+ proc{@db.clone}.must_raise Sequel::Error
23
+ end if false # SEQUEL5
24
+
13
25
  it "should receive options" do
14
26
  @db.opts[1].must_equal 2
15
27
  @db.opts[:logger].must_equal 3
@@ -328,7 +340,7 @@ describe "Database#dataset" do
328
340
  e.sql.must_equal 'SELECT * FROM miu'
329
341
  end
330
342
 
331
- it "should provide a filtered #from dataset if a block is given" do
343
+ deprecated "should provide a filtered #from dataset if a block is given" do
332
344
  d = @db.from(:mau){x.sql_number > 100}
333
345
  d.must_be_kind_of(Sequel::Dataset)
334
346
  d.sql.must_equal 'SELECT * FROM mau WHERE (x > 100)'
@@ -1375,7 +1387,7 @@ end
1375
1387
 
1376
1388
  describe "A single threaded database" do
1377
1389
  after do
1378
- Sequel::Database.single_threaded = false
1390
+ Sequel.single_threaded = false
1379
1391
  end
1380
1392
 
1381
1393
  it "should use a SingleConnectionPool instead of a ConnectionPool" do
@@ -1388,14 +1400,17 @@ describe "A single threaded database" do
1388
1400
  db.pool.must_be_kind_of(Sequel::SingleConnectionPool)
1389
1401
  end
1390
1402
 
1391
- it "should be constructable using Database.single_threaded = true" do
1403
+ deprecated "should be constructable using Database.single_threaded = true" do
1392
1404
  Sequel::Database.single_threaded = true
1405
+ Sequel.single_threaded.must_equal true
1406
+ Sequel::Database.single_threaded.must_equal true
1393
1407
  db = Sequel::Database.new{123}
1394
1408
  db.pool.must_be_kind_of(Sequel::SingleConnectionPool)
1395
1409
  end
1396
1410
 
1397
1411
  it "should be constructable using Sequel.single_threaded = true" do
1398
1412
  Sequel.single_threaded = true
1413
+ Sequel.single_threaded.must_equal true
1399
1414
  db = Sequel::Database.new{123}
1400
1415
  db.pool.must_be_kind_of(Sequel::SingleConnectionPool)
1401
1416
  end
@@ -1440,7 +1455,7 @@ end
1440
1455
 
1441
1456
  describe "A database" do
1442
1457
  after do
1443
- Sequel::Database.single_threaded = false
1458
+ Sequel.single_threaded = false
1444
1459
  end
1445
1460
 
1446
1461
  it "should have single_threaded? respond to true if in single threaded mode" do
@@ -1453,7 +1468,7 @@ describe "A database" do
1453
1468
  db = Sequel::Database.new
1454
1469
  db.wont_be :single_threaded?
1455
1470
 
1456
- Sequel::Database.single_threaded = true
1471
+ Sequel.single_threaded = true
1457
1472
 
1458
1473
  db = Sequel::Database.new{123}
1459
1474
  db.must_be :single_threaded?
@@ -1719,8 +1734,28 @@ describe "Database#remove_servers" do
1719
1734
  end
1720
1735
  end
1721
1736
 
1737
+ describe "Database#add_servers and #remove_servers when not sharded" do
1738
+ deprecated "should do nothing" do
1739
+ db = Sequel.mock
1740
+ db.opts[:servers].must_be_nil
1741
+ db.add_servers(:foo=>{}).must_be_nil
1742
+ db.opts[:servers].must_be_nil
1743
+ db.remove_servers(:foo).must_be_nil
1744
+ db.opts[:servers].must_be_nil
1745
+ end
1746
+
1747
+ it "should raise Error" do
1748
+ db = Sequel.mock
1749
+ db.opts[:servers].must_be_nil
1750
+ proc{db.add_servers(:foo=>{})}.must_raise Sequel::Error
1751
+ db.opts[:servers].must_be_nil
1752
+ proc{db.remove_servers(:foo)}.must_raise Sequel::Error
1753
+ db.opts[:servers].must_be_nil
1754
+ end if false # SEQUEL5
1755
+ end
1756
+
1722
1757
  describe "Database#each_server with do/jdbc adapter connection string without :adapter option" do
1723
- it "should yield a separate database object for each server" do
1758
+ deprecated "should yield a separate database object for each server" do
1724
1759
  require 'sequel/adapters/mock'
1725
1760
  klass = Class.new(Sequel::Database)
1726
1761
  def klass.adapter_class(v)
@@ -1740,7 +1775,7 @@ describe "Database#each_server with do/jdbc adapter connection string without :a
1740
1775
  hosts.sort.must_equal [1, 3]
1741
1776
  end
1742
1777
 
1743
- it "should raise if not given a block" do
1778
+ deprecated "should raise if not given a block" do
1744
1779
  proc{Sequel.mock.each_server}.must_raise(Sequel::Error)
1745
1780
  end
1746
1781
  end
@@ -1750,7 +1785,7 @@ describe "Database#each_server" do
1750
1785
  @db = Sequel.mock(:host=>1, :database=>2, :servers=>{:server1=>{:host=>3}, :server2=>{:host=>4}})
1751
1786
  end
1752
1787
 
1753
- it "should yield a separate database object for each server" do
1788
+ deprecated "should yield a separate database object for each server" do
1754
1789
  hosts = []
1755
1790
  @db.each_server do |db|
1756
1791
  db.must_be_kind_of(Sequel::Database)
@@ -1762,7 +1797,7 @@ describe "Database#each_server" do
1762
1797
  hosts.sort.must_equal [1, 3, 4]
1763
1798
  end
1764
1799
 
1765
- it "should disconnect and remove entry from Sequel::DATABASES after use" do
1800
+ deprecated "should disconnect and remove entry from Sequel::DATABASES after use" do
1766
1801
  dbs = []
1767
1802
  dcs = []
1768
1803
  @db.each_server do |db|