sequel 3.47.0 → 3.48.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (243) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +230 -0
  3. data/README.rdoc +31 -40
  4. data/Rakefile +1 -14
  5. data/doc/active_record.rdoc +29 -29
  6. data/doc/association_basics.rdoc +4 -13
  7. data/doc/cheat_sheet.rdoc +8 -6
  8. data/doc/code_order.rdoc +89 -0
  9. data/doc/core_extensions.rdoc +3 -3
  10. data/doc/dataset_basics.rdoc +7 -8
  11. data/doc/dataset_filtering.rdoc +7 -2
  12. data/doc/mass_assignment.rdoc +2 -3
  13. data/doc/migration.rdoc +8 -8
  14. data/doc/model_hooks.rdoc +11 -7
  15. data/doc/object_model.rdoc +2 -2
  16. data/doc/opening_databases.rdoc +5 -14
  17. data/doc/prepared_statements.rdoc +5 -9
  18. data/doc/querying.rdoc +23 -28
  19. data/doc/reflection.rdoc +11 -0
  20. data/doc/release_notes/3.48.0.txt +477 -0
  21. data/doc/schema_modification.rdoc +12 -5
  22. data/doc/security.rdoc +2 -2
  23. data/doc/sharding.rdoc +1 -2
  24. data/doc/sql.rdoc +10 -13
  25. data/doc/testing.rdoc +8 -4
  26. data/doc/transactions.rdoc +2 -2
  27. data/doc/validations.rdoc +40 -17
  28. data/doc/virtual_rows.rdoc +2 -2
  29. data/lib/sequel/adapters/ado.rb +25 -20
  30. data/lib/sequel/adapters/ado/access.rb +1 -0
  31. data/lib/sequel/adapters/ado/mssql.rb +1 -0
  32. data/lib/sequel/adapters/db2.rb +9 -7
  33. data/lib/sequel/adapters/dbi.rb +16 -16
  34. data/lib/sequel/adapters/do.rb +17 -18
  35. data/lib/sequel/adapters/do/mysql.rb +1 -0
  36. data/lib/sequel/adapters/do/postgres.rb +2 -0
  37. data/lib/sequel/adapters/do/sqlite.rb +1 -0
  38. data/lib/sequel/adapters/firebird.rb +5 -7
  39. data/lib/sequel/adapters/ibmdb.rb +23 -20
  40. data/lib/sequel/adapters/informix.rb +8 -2
  41. data/lib/sequel/adapters/jdbc.rb +39 -35
  42. data/lib/sequel/adapters/jdbc/as400.rb +1 -0
  43. data/lib/sequel/adapters/jdbc/cubrid.rb +1 -0
  44. data/lib/sequel/adapters/jdbc/db2.rb +1 -0
  45. data/lib/sequel/adapters/jdbc/derby.rb +1 -0
  46. data/lib/sequel/adapters/jdbc/firebird.rb +1 -0
  47. data/lib/sequel/adapters/jdbc/h2.rb +1 -0
  48. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -0
  49. data/lib/sequel/adapters/jdbc/informix.rb +1 -0
  50. data/lib/sequel/adapters/jdbc/jtds.rb +1 -0
  51. data/lib/sequel/adapters/jdbc/mssql.rb +1 -0
  52. data/lib/sequel/adapters/jdbc/mysql.rb +1 -0
  53. data/lib/sequel/adapters/jdbc/oracle.rb +1 -0
  54. data/lib/sequel/adapters/jdbc/postgresql.rb +2 -0
  55. data/lib/sequel/adapters/jdbc/progress.rb +1 -0
  56. data/lib/sequel/adapters/jdbc/sqlite.rb +1 -0
  57. data/lib/sequel/adapters/jdbc/sqlserver.rb +1 -0
  58. data/lib/sequel/adapters/mock.rb +30 -31
  59. data/lib/sequel/adapters/mysql.rb +6 -7
  60. data/lib/sequel/adapters/mysql2.rb +5 -6
  61. data/lib/sequel/adapters/odbc.rb +22 -20
  62. data/lib/sequel/adapters/odbc/mssql.rb +1 -0
  63. data/lib/sequel/adapters/openbase.rb +4 -1
  64. data/lib/sequel/adapters/oracle.rb +10 -8
  65. data/lib/sequel/adapters/postgres.rb +12 -10
  66. data/lib/sequel/adapters/shared/access.rb +6 -0
  67. data/lib/sequel/adapters/shared/cubrid.rb +2 -0
  68. data/lib/sequel/adapters/shared/db2.rb +2 -0
  69. data/lib/sequel/adapters/shared/firebird.rb +2 -0
  70. data/lib/sequel/adapters/shared/informix.rb +2 -0
  71. data/lib/sequel/adapters/shared/mssql.rb +14 -8
  72. data/lib/sequel/adapters/shared/mysql.rb +6 -0
  73. data/lib/sequel/adapters/shared/oracle.rb +2 -0
  74. data/lib/sequel/adapters/shared/postgres.rb +14 -4
  75. data/lib/sequel/adapters/shared/progress.rb +1 -0
  76. data/lib/sequel/adapters/shared/sqlite.rb +4 -3
  77. data/lib/sequel/adapters/sqlite.rb +6 -7
  78. data/lib/sequel/adapters/swift.rb +20 -21
  79. data/lib/sequel/adapters/swift/mysql.rb +1 -0
  80. data/lib/sequel/adapters/swift/postgres.rb +2 -0
  81. data/lib/sequel/adapters/swift/sqlite.rb +1 -0
  82. data/lib/sequel/adapters/tinytds.rb +5 -6
  83. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +68 -0
  84. data/lib/sequel/connection_pool.rb +1 -1
  85. data/lib/sequel/core.rb +57 -50
  86. data/lib/sequel/database/connecting.rb +9 -10
  87. data/lib/sequel/database/dataset.rb +11 -6
  88. data/lib/sequel/database/dataset_defaults.rb +61 -69
  89. data/lib/sequel/database/features.rb +21 -0
  90. data/lib/sequel/database/misc.rb +23 -3
  91. data/lib/sequel/database/query.rb +13 -7
  92. data/lib/sequel/database/schema_methods.rb +6 -6
  93. data/lib/sequel/database/transactions.rb +1 -0
  94. data/lib/sequel/dataset/actions.rb +51 -38
  95. data/lib/sequel/dataset/features.rb +1 -0
  96. data/lib/sequel/dataset/graph.rb +9 -33
  97. data/lib/sequel/dataset/misc.rb +30 -5
  98. data/lib/sequel/dataset/mutation.rb +2 -3
  99. data/lib/sequel/dataset/prepared_statements.rb +1 -1
  100. data/lib/sequel/dataset/query.rb +91 -27
  101. data/lib/sequel/dataset/sql.rb +40 -6
  102. data/lib/sequel/deprecated.rb +74 -0
  103. data/lib/sequel/deprecated_core_extensions.rb +135 -0
  104. data/lib/sequel/extensions/columns_introspection.rb +1 -5
  105. data/lib/sequel/extensions/core_extensions.rb +10 -3
  106. data/lib/sequel/extensions/date_arithmetic.rb +1 -0
  107. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +33 -0
  108. data/lib/sequel/extensions/filter_having.rb +58 -0
  109. data/lib/sequel/extensions/graph_each.rb +63 -0
  110. data/lib/sequel/extensions/hash_aliases.rb +44 -0
  111. data/lib/sequel/extensions/looser_typecasting.rb +14 -3
  112. data/lib/sequel/extensions/migration.rb +2 -3
  113. data/lib/sequel/extensions/named_timezones.rb +14 -1
  114. data/lib/sequel/extensions/null_dataset.rb +7 -1
  115. data/lib/sequel/extensions/pagination.rb +15 -5
  116. data/lib/sequel/extensions/pg_auto_parameterize.rb +1 -0
  117. data/lib/sequel/extensions/pg_hstore_ops.rb +48 -14
  118. data/lib/sequel/extensions/pg_json.rb +7 -7
  119. data/lib/sequel/extensions/pg_range_ops.rb +8 -2
  120. data/lib/sequel/extensions/pg_statement_cache.rb +1 -0
  121. data/lib/sequel/extensions/pretty_table.rb +13 -4
  122. data/lib/sequel/extensions/query.rb +21 -4
  123. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +22 -0
  124. data/lib/sequel/extensions/schema_caching.rb +10 -7
  125. data/lib/sequel/extensions/schema_dumper.rb +35 -48
  126. data/lib/sequel/extensions/select_remove.rb +13 -4
  127. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +117 -0
  128. data/lib/sequel/extensions/set_overrides.rb +43 -0
  129. data/lib/sequel/extensions/to_dot.rb +6 -0
  130. data/lib/sequel/model.rb +12 -6
  131. data/lib/sequel/model/associations.rb +80 -38
  132. data/lib/sequel/model/base.rb +137 -52
  133. data/lib/sequel/model/errors.rb +7 -2
  134. data/lib/sequel/plugins/active_model.rb +13 -0
  135. data/lib/sequel/plugins/after_initialize.rb +43 -0
  136. data/lib/sequel/plugins/association_proxies.rb +63 -7
  137. data/lib/sequel/plugins/auto_validations.rb +56 -16
  138. data/lib/sequel/plugins/blacklist_security.rb +63 -0
  139. data/lib/sequel/plugins/class_table_inheritance.rb +9 -0
  140. data/lib/sequel/plugins/constraint_validations.rb +50 -8
  141. data/lib/sequel/plugins/dataset_associations.rb +2 -0
  142. data/lib/sequel/plugins/hook_class_methods.rb +7 -1
  143. data/lib/sequel/plugins/identity_map.rb +4 -0
  144. data/lib/sequel/plugins/json_serializer.rb +32 -13
  145. data/lib/sequel/plugins/optimistic_locking.rb +1 -1
  146. data/lib/sequel/plugins/rcte_tree.rb +4 -4
  147. data/lib/sequel/plugins/scissors.rb +33 -0
  148. data/lib/sequel/plugins/serialization.rb +1 -1
  149. data/lib/sequel/plugins/single_table_inheritance.rb +6 -0
  150. data/lib/sequel/plugins/tree.rb +5 -1
  151. data/lib/sequel/plugins/validation_class_methods.rb +2 -1
  152. data/lib/sequel/plugins/validation_helpers.rb +15 -11
  153. data/lib/sequel/plugins/xml_serializer.rb +12 -3
  154. data/lib/sequel/sql.rb +12 -2
  155. data/lib/sequel/timezones.rb +1 -1
  156. data/lib/sequel/version.rb +1 -1
  157. data/lib/sequel_core.rb +1 -0
  158. data/lib/sequel_model.rb +1 -0
  159. data/spec/adapters/mssql_spec.rb +24 -57
  160. data/spec/adapters/postgres_spec.rb +27 -55
  161. data/spec/adapters/spec_helper.rb +1 -1
  162. data/spec/adapters/sqlite_spec.rb +1 -1
  163. data/spec/bin_spec.rb +251 -0
  164. data/spec/core/database_spec.rb +46 -32
  165. data/spec/core/dataset_spec.rb +233 -181
  166. data/spec/core/deprecated_spec.rb +78 -0
  167. data/spec/core/expression_filters_spec.rb +3 -4
  168. data/spec/core/mock_adapter_spec.rb +9 -9
  169. data/spec/core/object_graph_spec.rb +9 -19
  170. data/spec/core/schema_spec.rb +3 -1
  171. data/spec/core/spec_helper.rb +19 -0
  172. data/spec/core_extensions_spec.rb +80 -30
  173. data/spec/extensions/after_initialize_spec.rb +24 -0
  174. data/spec/extensions/association_proxies_spec.rb +37 -1
  175. data/spec/extensions/auto_validations_spec.rb +20 -4
  176. data/spec/extensions/blacklist_security_spec.rb +87 -0
  177. data/spec/extensions/boolean_readers_spec.rb +2 -1
  178. data/spec/extensions/class_table_inheritance_spec.rb +7 -0
  179. data/spec/extensions/columns_introspection_spec.rb +3 -3
  180. data/spec/extensions/constraint_validations_plugin_spec.rb +83 -5
  181. data/spec/extensions/core_refinements_spec.rb +7 -7
  182. data/spec/extensions/dataset_associations_spec.rb +2 -2
  183. data/spec/extensions/date_arithmetic_spec.rb +1 -1
  184. data/spec/extensions/defaults_setter_spec.rb +2 -1
  185. data/spec/extensions/empty_array_ignore_nulls_spec.rb +24 -0
  186. data/spec/extensions/filter_having_spec.rb +40 -0
  187. data/spec/extensions/graph_each_spec.rb +109 -0
  188. data/spec/extensions/hash_aliases_spec.rb +16 -0
  189. data/spec/extensions/hook_class_methods_spec.rb +2 -2
  190. data/spec/extensions/identity_map_spec.rb +3 -3
  191. data/spec/extensions/json_serializer_spec.rb +19 -19
  192. data/spec/extensions/lazy_attributes_spec.rb +1 -0
  193. data/spec/extensions/list_spec.rb +13 -13
  194. data/spec/extensions/looser_typecasting_spec.rb +10 -3
  195. data/spec/extensions/many_through_many_spec.rb +1 -1
  196. data/spec/extensions/migration_spec.rb +7 -7
  197. data/spec/extensions/named_timezones_spec.rb +6 -0
  198. data/spec/extensions/nested_attributes_spec.rb +2 -2
  199. data/spec/extensions/null_dataset_spec.rb +1 -1
  200. data/spec/extensions/pagination_spec.rb +2 -2
  201. data/spec/extensions/pg_hstore_ops_spec.rb +75 -0
  202. data/spec/extensions/pg_range_ops_spec.rb +4 -2
  203. data/spec/extensions/pg_row_plugin_spec.rb +1 -1
  204. data/spec/extensions/pretty_table_spec.rb +1 -1
  205. data/spec/extensions/query_literals_spec.rb +1 -1
  206. data/spec/extensions/query_spec.rb +3 -3
  207. data/spec/extensions/schema_caching_spec.rb +3 -3
  208. data/spec/extensions/schema_dumper_spec.rb +27 -2
  209. data/spec/extensions/schema_spec.rb +2 -2
  210. data/spec/extensions/scissors_spec.rb +26 -0
  211. data/spec/extensions/select_remove_spec.rb +1 -1
  212. data/spec/extensions/sequel_3_dataset_methods_spec.rb +102 -0
  213. data/spec/extensions/set_overrides_spec.rb +45 -0
  214. data/spec/extensions/single_table_inheritance_spec.rb +10 -0
  215. data/spec/extensions/spec_helper.rb +24 -1
  216. data/spec/extensions/static_cache_spec.rb +1 -1
  217. data/spec/extensions/string_stripper_spec.rb +2 -1
  218. data/spec/extensions/to_dot_spec.rb +1 -1
  219. data/spec/extensions/typecast_on_load_spec.rb +3 -2
  220. data/spec/extensions/update_primary_key_spec.rb +2 -2
  221. data/spec/extensions/validation_class_methods_spec.rb +19 -19
  222. data/spec/extensions/validation_helpers_spec.rb +30 -21
  223. data/spec/extensions/xml_serializer_spec.rb +5 -5
  224. data/spec/integration/associations_test.rb +10 -30
  225. data/spec/integration/dataset_test.rb +20 -24
  226. data/spec/integration/eager_loader_test.rb +5 -5
  227. data/spec/integration/model_test.rb +3 -3
  228. data/spec/integration/plugin_test.rb +7 -39
  229. data/spec/integration/schema_test.rb +4 -38
  230. data/spec/integration/spec_helper.rb +2 -1
  231. data/spec/model/association_reflection_spec.rb +70 -5
  232. data/spec/model/associations_spec.rb +11 -11
  233. data/spec/model/base_spec.rb +25 -8
  234. data/spec/model/class_dataset_methods_spec.rb +143 -0
  235. data/spec/model/dataset_methods_spec.rb +1 -1
  236. data/spec/model/eager_loading_spec.rb +25 -25
  237. data/spec/model/hooks_spec.rb +1 -1
  238. data/spec/model/model_spec.rb +22 -7
  239. data/spec/model/plugins_spec.rb +1 -6
  240. data/spec/model/record_spec.rb +37 -29
  241. data/spec/model/spec_helper.rb +23 -1
  242. data/spec/model/validations_spec.rb +15 -17
  243. metadata +32 -3
@@ -28,15 +28,10 @@ module Sequel
28
28
  @convert_two_digit_years = true
29
29
  @datetime_class = Time
30
30
  @empty_array_handle_nulls = true
31
- @virtual_row_instance_eval = true
32
- @require_thread = nil
33
-
34
- # Mutex used to protect file loading/requireing
35
- @require_mutex = Mutex.new
36
-
31
+
37
32
  # Whether Sequel is being run in single threaded mode
38
33
  @single_threaded = false
39
-
34
+
40
35
  class << self
41
36
  # Sequel converts two digit years in <tt>Date</tt>s and <tt>DateTime</tt>s by default,
42
37
  # so 01/02/03 is interpreted at January 2nd, 2003, and 12/13/99 is interpreted
@@ -79,29 +74,30 @@ module Sequel
79
74
  #
80
75
  # This may not handle NULLs correctly, but can be much faster on
81
76
  # some databases.
82
- attr_accessor :empty_array_handle_nulls
77
+ attr_reader :empty_array_handle_nulls
78
+
79
+ def empty_array_handle_nulls=(v)
80
+ Sequel::Deprecation.deprecate('Sequel.empty_array_handle_nulls=', 'Please switch to loading the empty_array_ignore_nulls plugin if you wish empty array handling to ignore nulls')
81
+ @empty_array_handle_nulls = v
82
+ end
83
83
 
84
- # For backwards compatibility, has no effect.
85
- attr_accessor :virtual_row_instance_eval
86
-
87
- # Alias to the standard version of require
88
- alias k_require require
84
+ # REMOVE40
85
+ def virtual_row_instance_eval
86
+ Sequel::Deprecation.deprecate('Sequel.virtual_row_instance_eval', 'It has no effect, so you can safely stop calling it.')
87
+ end
88
+ def virtual_row_instance_eval=(v)
89
+ Sequel::Deprecation.deprecate('Sequel.virtual_row_instance_eval=', 'It has no effect, so you can safely stop calling it.')
90
+ end
91
+ def k_require(*a)
92
+ Sequel::Deprecation.deprecate('Sequel.k_require', 'Please switch to Kernel.require')
93
+ Kernel.require(*a)
94
+ end
89
95
 
90
96
  private
91
97
 
92
98
  # Make thread safe requiring reentrant to prevent deadlocks.
93
99
  def check_requiring_thread
94
- return yield if @single_threaded
95
- t = Thread.current
96
- return(yield) if @require_thread == t
97
- @require_mutex.synchronize do
98
- begin
99
- @require_thread = t
100
- yield
101
- ensure
102
- @require_thread = nil
103
- end
104
- end
100
+ Sequel::Deprecation.deprecate('Sequel.check_requiring_thread', 'It has no effect, so you can safely stop calling it.')
105
101
  end
106
102
  end
107
103
 
@@ -119,7 +115,7 @@ module Sequel
119
115
  when Hash
120
116
  true
121
117
  when Array
122
- !obj.empty? && !obj.is_a?(SQL::ValueList) && obj.all?{|i| (Array === i) && (i.length == 2)}
118
+ !obj.empty? && !obj.is_a?(SQL::ValueList) && obj.all?{|i| i.is_a?(Array) && (i.length == 2)}
123
119
  else
124
120
  false
125
121
  end
@@ -152,7 +148,7 @@ module Sequel
152
148
  def self.core_extensions?
153
149
  false
154
150
  end
155
-
151
+
156
152
  # Convert the +exception+ to the given class. The given class should be
157
153
  # <tt>Sequel::Error</tt> or a subclass. Returns an instance of +klass+ with
158
154
  # the message and backtrace of +exception+.
@@ -175,7 +171,7 @@ module Sequel
175
171
  # Sequel.extension(:schema_dumper)
176
172
  # Sequel.extension(:pagination, :query)
177
173
  def self.extension(*extensions)
178
- extensions.each{|e| tsk_require "sequel/extensions/#{e}"}
174
+ extensions.each{|e| Kernel.require "sequel/extensions/#{e}"}
179
175
  end
180
176
 
181
177
  # Set the method to call on identifiers going into the database. This affects
@@ -192,7 +188,7 @@ module Sequel
192
188
  def self.identifier_input_method=(value)
193
189
  Database.identifier_input_method = value
194
190
  end
195
-
191
+
196
192
  # Set the method to call on identifiers coming out of the database. This affects
197
193
  # the literalization of identifiers by calling this method on them when they are
198
194
  # retrieved from the database. Sequel downcases identifiers retrieved for most
@@ -209,12 +205,24 @@ module Sequel
209
205
  Database.identifier_output_method = value
210
206
  end
211
207
 
208
+ # The exception classed raised if there is an error parsing JSON.
209
+ # This can be overridden to use an alternative json implementation.
210
+ def self.json_parser_error_class
211
+ JSON::ParserError
212
+ end
213
+
214
+ # Convert given object to json and return the result.
215
+ # This can be overridden to use an alternative json implementation.
216
+ def self.object_to_json(obj, *args)
217
+ obj.to_json(*args)
218
+ end
219
+
212
220
  # Parse the string as JSON and return the result.
213
- # This is solely for internal use, it should not be used externally.
214
- def self.parse_json(json) # :nodoc:
221
+ # This can be overridden to use an alternative json implementation.
222
+ def self.parse_json(json)
215
223
  JSON.parse(json, :create_additions=>false)
216
224
  end
217
-
225
+
218
226
  # Set whether to quote identifiers for all databases by default. By default,
219
227
  # Sequel quotes identifiers in all SQL strings, so to turn that off:
220
228
  #
@@ -235,7 +243,7 @@ module Sequel
235
243
  end
236
244
  end
237
245
  end
238
-
246
+
239
247
  # Require all given +files+ which should be in the same or a subdirectory of
240
248
  # this file. If a +subdir+ is given, assume all +files+ are in that subdir.
241
249
  # This is used to ensure that the files loaded are from the same version of
@@ -243,7 +251,7 @@ module Sequel
243
251
  def self.require(files, subdir=nil)
244
252
  Array(files).each{|f| super("#{File.dirname(__FILE__).untaint}/#{"#{subdir}/" if subdir}#{f}")}
245
253
  end
246
-
254
+
247
255
  # Set whether Sequel is being used in single threaded mode. By default,
248
256
  # Sequel uses a thread-safe connection pool, which isn't as fast as the
249
257
  # single threaded connection pool, and also has some additional thread
@@ -377,14 +385,14 @@ module Sequel
377
385
  end
378
386
  end
379
387
 
380
- # Same as Sequel.require, but wrapped in a mutex in order to be thread safe.
388
+ # REMOVE40
381
389
  def self.ts_require(*args)
382
- check_requiring_thread{require(*args)}
390
+ Sequel::Deprecation.deprecate('Sequel.ts_require', 'Please switch to Sequel.require')
391
+ require(*args)
383
392
  end
384
-
385
- # Same as Kernel.require, but wrapped in a mutex in order to be thread safe.
386
393
  def self.tsk_require(*args)
387
- check_requiring_thread{k_require(*args)}
394
+ Sequel::Deprecation.deprecate('Sequel.tsk_require', 'Please switch to Kernel.require')
395
+ Kernel.require(*args)
388
396
  end
389
397
 
390
398
  # If the supplied block takes a single argument,
@@ -403,21 +411,20 @@ module Sequel
403
411
  block.call(vr)
404
412
  end
405
413
  end
406
-
414
+
407
415
  ### Private Class Methods ###
408
416
 
409
417
  # Helper method that the database adapter class methods that are added to Sequel via
410
418
  # metaprogramming use to parse arguments.
411
- def self.adapter_method(adapter, *args, &block) # :nodoc:
412
- raise(::Sequel::Error, "Wrong number of arguments, 0-2 arguments valid") if args.length > 2
413
- opts = {:adapter=>adapter.to_sym}
414
- opts[:database] = args.shift if args.length >= 1 && !(args[0].is_a?(Hash))
415
- if Hash === (arg = args[0])
416
- opts.merge!(arg)
417
- elsif !arg.nil?
419
+ def self.adapter_method(adapter, *args, &block)
420
+ options = args.last.is_a?(Hash) ? args.pop : {}
421
+ opts = {:adapter => adapter.to_sym}
422
+ opts[:database] = args.shift if args.first.is_a?(String)
423
+ if args.any?
418
424
  raise ::Sequel::Error, "Wrong format of arguments, either use (), (String), (Hash), or (String, Hash)"
419
425
  end
420
- connect(opts, &block)
426
+
427
+ connect(opts.merge(options), &block)
421
428
  end
422
429
 
423
430
  # Method that adds a database adapter class method to Sequel that calls
@@ -432,11 +439,11 @@ module Sequel
432
439
  end
433
440
 
434
441
  private_class_method :adapter_method, :def_adapter_method
435
-
436
- require(%w"sql connection_pool exceptions dataset database timezones ast_transformer version")
442
+
443
+ require(%w"deprecated sql connection_pool exceptions dataset database timezones ast_transformer version")
437
444
  if !defined?(::SEQUEL_NO_CORE_EXTENSIONS) && !ENV.has_key?('SEQUEL_NO_CORE_EXTENSIONS')
438
445
  # :nocov:
439
- extension(:core_extensions)
446
+ require(:deprecated_core_extensions)
440
447
  # :nocov:
441
448
  end
442
449
 
@@ -8,8 +8,12 @@ module Sequel
8
8
  # Array of supported database adapters
9
9
  ADAPTERS = %w'ado amalgalite cubrid db2 dbi do firebird ibmdb informix jdbc mock mysql mysql2 odbc openbase oracle postgres sqlite swift tinytds'.collect{|x| x.to_sym}
10
10
 
11
- # Whether to use the single threaded connection pool by default
12
- @@single_threaded = false
11
+ @single_threaded = false
12
+
13
+ class << self
14
+ # Whether to use the single threaded connection pool by default
15
+ attr_accessor :single_threaded
16
+ end
13
17
 
14
18
  # The Database subclass for the given adapter scheme.
15
19
  # Raises Sequel::AdapterNotFound if the adapter
@@ -22,7 +26,7 @@ module Sequel
22
26
  unless klass = ADAPTER_MAP[scheme]
23
27
  # attempt to load the adapter file
24
28
  begin
25
- Sequel.tsk_require "sequel/adapters/#{scheme}"
29
+ require "sequel/adapters/#{scheme}"
26
30
  rescue LoadError => e
27
31
  raise Sequel.convert_exception_class(e, AdapterNotFound)
28
32
  end
@@ -37,7 +41,7 @@ module Sequel
37
41
 
38
42
  # Returns the scheme symbol for the Database class.
39
43
  def self.adapter_scheme
40
- @scheme if defined?(@scheme)
44
+ @scheme
41
45
  end
42
46
 
43
47
  # Connects to a database. See Sequel.connect.
@@ -86,12 +90,6 @@ module Sequel
86
90
  db
87
91
  end
88
92
 
89
- # Sets the default single_threaded mode for new databases.
90
- # See Sequel.single_threaded=.
91
- def self.single_threaded=(value)
92
- @@single_threaded = value
93
- end
94
-
95
93
  # Sets the adapter scheme for the Database class. Call this method in
96
94
  # descendants of Database to allow connection using a URL. For example the
97
95
  # following:
@@ -142,6 +140,7 @@ module Sequel
142
140
 
143
141
  # Connects to the database. This method should be overridden by descendants.
144
142
  def connect(server)
143
+ Sequel::Deprecation.deprecate('Database#connect default implementation and Sequel::NotImplemented', 'All database instance can be assumed to implement connect.')
145
144
  raise NotImplemented, "#connect should be overridden by adapters"
146
145
  end
147
146
 
@@ -17,15 +17,20 @@ module Sequel
17
17
  #
18
18
  # DB[:items].sql #=> "SELECT * FROM items"
19
19
  def [](*args)
20
- (String === args.first) ? fetch(*args) : from(*args)
20
+ args.first.is_a?(String) ? fetch(*args) : from(*args)
21
21
  end
22
22
 
23
23
  # Returns a blank dataset for this database.
24
24
  #
25
25
  # DB.dataset # SELECT *
26
26
  # DB.dataset.from(:items) # SELECT * FROM items
27
- def dataset(opts=nil)
28
- @dataset_class.new(self, opts)
27
+ def dataset(opts=(no_arg_given=true; nil))
28
+ # REMOVE40
29
+ if no_arg_given
30
+ @dataset_class.new(self)
31
+ else
32
+ @dataset_class.new(self, opts)
33
+ end
29
34
  end
30
35
 
31
36
  # Fetches records for an arbitrary SQL statement. If a block is given,
@@ -42,7 +47,7 @@ module Sequel
42
47
  #
43
48
  # DB.fetch('SELECT * FROM items WHERE name = ?', my_name).all
44
49
  def fetch(sql, *args, &block)
45
- ds = dataset.with_sql(sql, *args)
50
+ ds = @default_dataset.with_sql(sql, *args)
46
51
  ds.each(&block) if block
47
52
  ds
48
53
  end
@@ -53,7 +58,7 @@ module Sequel
53
58
  # DB.from(:items) # SELECT * FROM items
54
59
  # DB.from(:items){id > 2} # SELECT * FROM items WHERE (id > 2)
55
60
  def from(*args, &block)
56
- ds = dataset.from(*args)
61
+ ds = @default_dataset.from(*args)
57
62
  block ? ds.filter(&block) : ds
58
63
  end
59
64
 
@@ -63,7 +68,7 @@ module Sequel
63
68
  # DB.select{server_version{}} # SELECT server_version()
64
69
  # DB.select(:id).from(:items) # SELECT id FROM items
65
70
  def select(*args, &block)
66
- dataset.select(*args, &block)
71
+ @default_dataset.select(*args, &block)
67
72
  end
68
73
  end
69
74
  end
@@ -8,52 +8,54 @@ module Sequel
8
8
  # The default class to use for datasets
9
9
  DatasetClass = Sequel::Dataset
10
10
 
11
- # The identifier input method to use by default
12
- @@identifier_input_method = nil
11
+ @identifier_input_method = nil
12
+ @identifier_output_method = nil
13
+ @quote_identifiers = nil
13
14
 
14
- # The identifier output method to use by default
15
- @@identifier_output_method = nil
15
+ class << self
16
+ # The identifier input method to use by default for all databases (default: adapter default)
17
+ attr_reader :identifier_input_method
16
18
 
17
- # Whether to quote identifiers (columns and tables) by default
18
- @@quote_identifiers = nil
19
+ # The identifier output method to use by default for all databases (default: adapter default)
20
+ attr_reader :identifier_output_method
19
21
 
20
- # The method to call on identifiers going into the database
21
- def self.identifier_input_method
22
- @@identifier_input_method
22
+ # Whether to quote identifiers (columns and tables) by default for all databases (default: adapter default)
23
+ attr_accessor :quote_identifiers
23
24
  end
24
-
25
- # Set the method to call on identifiers going into the database
26
- # See Sequel.identifier_input_method=.
25
+
26
+ # Change the default identifier input method to use for all databases,
27
27
  def self.identifier_input_method=(v)
28
- @@identifier_input_method = v || ""
29
- end
30
-
31
- # The method to call on identifiers coming from the database
32
- def self.identifier_output_method
33
- @@identifier_output_method
34
- end
35
-
36
- # Set the method to call on identifiers coming from the database
37
- # See Sequel.identifier_output_method=.
38
- def self.identifier_output_method=(v)
39
- @@identifier_output_method = v || ""
28
+ @identifier_input_method = v.nil? ? false : v
40
29
  end
41
30
 
42
- # Sets the default quote_identifiers mode for new databases.
43
- # See Sequel.quote_identifiers=.
44
- def self.quote_identifiers=(value)
45
- @@quote_identifiers = value
46
- end
31
+ # Change the default identifier output method to use for all databases,
32
+ def self.identifier_output_method=(v)
33
+ @identifier_output_method = v.nil? ? false : v
34
+ end
47
35
 
48
36
  # The class to use for creating datasets. Should respond to
49
37
  # new with the Database argument as the first argument, and
50
38
  # an optional options hash.
51
39
  attr_reader :dataset_class
52
40
 
53
- # The default schema to use, generally should be nil. This sets
54
- # the default schema used for some schema modification and
55
- # introspection queries, but does not effect most dataset code.
56
- attr_accessor :default_schema
41
+ # The identifier input method to use by default for this database (default: adapter default)
42
+ attr_reader :identifier_input_method
43
+
44
+ # The identifier output method to use by default for this database (default: adapter default)
45
+ attr_reader :identifier_output_method
46
+
47
+ # REMOVE40
48
+ def _default_schema
49
+ @default_schema
50
+ end
51
+ def default_schema
52
+ Sequel::Deprecation.deprecate('Database#default_schema', 'Use qualified tables instead')
53
+ @default_schema
54
+ end
55
+ def default_schema=(v)
56
+ Sequel::Deprecation.deprecate('Database#default_schema=', 'Use qualified tables instead') if v
57
+ @default_schema = v
58
+ end
57
59
 
58
60
  # If the database has any dataset modules associated with it,
59
61
  # use a subclass of the given class that includes the modules
@@ -64,6 +66,7 @@ module Sequel
64
66
  @dataset_modules.each{|m| c.send(:include, m)}
65
67
  end
66
68
  @dataset_class = c
69
+ reset_default_dataset
67
70
  end
68
71
 
69
72
  # Equivalent to extending all datasets produced by the database with a
@@ -90,7 +93,6 @@ module Sequel
90
93
  # end
91
94
  def extend_datasets(mod=nil, &block)
92
95
  raise(Error, "must provide either mod or block, not both") if mod && block
93
- reset_schema_utility_dataset
94
96
  mod = Module.new(&block) if block
95
97
  if @dataset_modules.empty?
96
98
  @dataset_modules = [mod]
@@ -99,42 +101,17 @@ module Sequel
99
101
  @dataset_modules << mod
100
102
  end
101
103
  @dataset_class.send(:include, mod)
104
+ reset_default_dataset
102
105
  end
103
106
 
104
- # The method to call on identifiers going into the database
105
- def identifier_input_method
106
- case @identifier_input_method
107
- when nil
108
- @identifier_input_method = @opts.fetch(:identifier_input_method, (@@identifier_input_method.nil? ? identifier_input_method_default : @@identifier_input_method))
109
- @identifier_input_method == "" ? nil : @identifier_input_method
110
- when ""
111
- nil
112
- else
113
- @identifier_input_method
114
- end
115
- end
116
-
117
107
  # Set the method to call on identifiers going into the database:
118
108
  #
119
109
  # DB[:items] # SELECT * FROM items
120
110
  # DB.identifier_input_method = :upcase
121
111
  # DB[:items] # SELECT * FROM ITEMS
122
112
  def identifier_input_method=(v)
123
- reset_schema_utility_dataset
124
- @identifier_input_method = v || ""
125
- end
126
-
127
- # The method to call on identifiers coming from the database
128
- def identifier_output_method
129
- case @identifier_output_method
130
- when nil
131
- @identifier_output_method = @opts.fetch(:identifier_output_method, (@@identifier_output_method.nil? ? identifier_output_method_default : @@identifier_output_method))
132
- @identifier_output_method == "" ? nil : @identifier_output_method
133
- when ""
134
- nil
135
- else
136
- @identifier_output_method
137
- end
113
+ reset_default_dataset
114
+ @identifier_input_method = v
138
115
  end
139
116
 
140
117
  # Set the method to call on identifiers coming from the database:
@@ -143,8 +120,8 @@ module Sequel
143
120
  # DB.identifier_output_method = :upcase
144
121
  # DB[:items].first # {:ID=>1, :NAME=>'foo'}
145
122
  def identifier_output_method=(v)
146
- reset_schema_utility_dataset
147
- @identifier_output_method = v || ""
123
+ reset_default_dataset
124
+ @identifier_output_method = v
148
125
  end
149
126
 
150
127
  # Set whether to quote identifiers (columns and tables) for this database:
@@ -153,14 +130,13 @@ module Sequel
153
130
  # DB.quote_identifiers = true
154
131
  # DB[:items] # SELECT * FROM "items"
155
132
  def quote_identifiers=(v)
156
- reset_schema_utility_dataset
133
+ reset_default_dataset
157
134
  @quote_identifiers = v
158
135
  end
159
136
 
160
137
  # Returns true if the database quotes identifiers.
161
138
  def quote_identifiers?
162
- return @quote_identifiers unless @quote_identifiers.nil?
163
- @quote_identifiers = @opts.fetch(:quote_identifiers, (@@quote_identifiers.nil? ? quote_identifiers_default : @@quote_identifiers))
139
+ @quote_identifiers
164
140
  end
165
141
 
166
142
  private
@@ -169,12 +145,19 @@ module Sequel
169
145
  def dataset_class_default
170
146
  self.class.const_get(:DatasetClass)
171
147
  end
172
-
173
- # The default value for default_schema.
148
+
149
+ # REMOVE40
174
150
  def default_schema_default
175
151
  nil
176
152
  end
177
153
 
154
+ # Reset the default dataset used by most Database methods that
155
+ # create datasets. Usually done after changes to the identifier
156
+ # mangling methods.
157
+ def reset_default_dataset
158
+ @default_dataset = dataset
159
+ end
160
+
178
161
  # The method to apply to identifiers going into the database by default.
179
162
  # Should be overridden in subclasses for databases that fold unquoted
180
163
  # identifiers to lower case instead of uppercase, such as
@@ -196,5 +179,14 @@ module Sequel
196
179
  def quote_identifiers_default
197
180
  true
198
181
  end
182
+
183
+ # Reset the identifier mangling options. Overrides any already set on
184
+ # the instance. Only for internal use by shared adapters.
185
+ def reset_identifier_mangling
186
+ @quote_identifiers = @opts.fetch(:quote_identifiers){(qi = Database.quote_identifiers).nil? ? quote_identifiers_default : qi}
187
+ @identifier_input_method = @opts.fetch(:identifier_input_method){(iim = Database.identifier_input_method).nil? ? identifier_input_method_default : (iim if iim)}
188
+ @identifier_output_method = @opts.fetch(:identifier_output_method){(iom = Database.identifier_output_method).nil? ? identifier_output_method_default : (iom if iom)}
189
+ reset_default_dataset
190
+ end
199
191
  end
200
192
  end