sequel 3.47.0 → 3.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -36,6 +36,17 @@ module Sequel
36
36
  supports_create_table_if_not_exists?
37
37
  end
38
38
 
39
+ # Whether the database supports Database#foreign_key_list for
40
+ # parsing foreign keys.
41
+ def supports_foreign_key_parsing?
42
+ [:access, :mssql, :mysql, :postgres, :sqlite].include?(database_type)
43
+ end
44
+
45
+ # Whether the database supports Database#indexes for parsing indexes.
46
+ def supports_index_parsing?
47
+ [:access, :cubrid, :db2, :mssql, :mysql, :postgres, :sqlite].include?(database_type) || adapter_scheme == :jdbc
48
+ end
49
+
39
50
  # Whether the database and adapter support prepared transactions
40
51
  # (two-phase commit), false by default.
41
52
  def supports_prepared_transactions?
@@ -58,6 +69,16 @@ module Sequel
58
69
  respond_to?(:schema_parse_table, true)
59
70
  end
60
71
 
72
+ # Whether the database supports Database#tables for getting list of tables.
73
+ def supports_table_listing?
74
+ [:access, :cubrid, :db2, :firebird, :mssql, :mysql, :oracle, :postgres, :sqlite].include?(database_type) || adapter_scheme == :jdbc
75
+ end
76
+ #
77
+ # Whether the database supports Database#views for getting list of views.
78
+ def supports_view_listing?
79
+ supports_table_listing?
80
+ end
81
+
61
82
  # Whether the database and adapter support transaction isolation levels, false by default.
62
83
  def supports_transaction_isolation_levels?
63
84
  false
@@ -24,6 +24,14 @@ module Sequel
24
24
  :time=>Sequel::SQLTime, :boolean=>[TrueClass, FalseClass].freeze, :float=>Float, :decimal=>BigDecimal,
25
25
  :blob=>Sequel::SQL::Blob}.freeze
26
26
 
27
+ # Module to be included in shared adapters so that when the DatabaseMethods are
28
+ # included in the database, the identifier mangling defaults are reset correctly.
29
+ module ResetIdentifierMangling
30
+ def extended(obj)
31
+ obj.send(:reset_identifier_mangling)
32
+ end
33
+ end
34
+
27
35
  # Nested hook Proc; each new hook Proc just wraps the previous one.
28
36
  @initialize_hook = Proc.new {|db| }
29
37
 
@@ -91,7 +99,6 @@ module Sequel
91
99
  # options hash.
92
100
  #
93
101
  # Accepts the following options:
94
- # :default_schema :: The default schema to use, see #default_schema.
95
102
  # :default_string_column_size :: The default size of string columns, 255 by default.
96
103
  # :identifier_input_method :: A string method symbol to call on identifiers going into the database
97
104
  # :identifier_output_method :: A string method symbol to call on identifiers coming from the database
@@ -112,7 +119,7 @@ module Sequel
112
119
  @opts[:servers] = {} if @opts[:servers].is_a?(String)
113
120
  @opts[:adapter_class] = self.class
114
121
 
115
- @opts[:single_threaded] = @single_threaded = typecast_value_boolean(@opts.fetch(:single_threaded, @@single_threaded))
122
+ @opts[:single_threaded] = @single_threaded = typecast_value_boolean(@opts.fetch(:single_threaded, Database.single_threaded))
116
123
  @schemas = {}
117
124
  @default_schema = @opts.fetch(:default_schema, default_schema_default)
118
125
  @default_string_column_size = @opts[:default_string_column_size] || DEFAULT_STRING_COLUMN_SIZE
@@ -129,6 +136,9 @@ module Sequel
129
136
  self.sql_log_level = @opts[:sql_log_level] ? @opts[:sql_log_level].to_sym : :info
130
137
  @pool = ConnectionPool.get_pool(self, @opts)
131
138
 
139
+ reset_identifier_mangling
140
+ adapter_initialize
141
+
132
142
  unless typecast_value_boolean(@opts[:keep_reference]) == false
133
143
  Sequel.synchronize{::Sequel::DATABASES.push(self)}
134
144
  end
@@ -295,6 +305,10 @@ module Sequel
295
305
 
296
306
  private
297
307
 
308
+ # Per adapter initialization method, empty by default.
309
+ def adapter_initialize
310
+ end
311
+
298
312
  # Returns true when the object is considered blank.
299
313
  # The only objects that are blank are nil, false,
300
314
  # strings with all whitespace, and ones that respond
@@ -479,7 +493,13 @@ module Sequel
479
493
 
480
494
  # Typecast the value to a String
481
495
  def typecast_value_string(value)
482
- value.to_s
496
+ case value
497
+ when Hash, Array
498
+ Sequel::Deprecation.deprecate('Automatically typecasting a hash or array to string for a string column', 'Either typecast the input manually or use the looser_typecasting extension')
499
+ value.to_s
500
+ else
501
+ value.to_s
502
+ end
483
503
  end
484
504
 
485
505
  # Typecast the value to a Time
@@ -39,6 +39,7 @@ module Sequel
39
39
  # Executes the given SQL on the database. This method should be overridden in descendants.
40
40
  # This method should not be called directly by user code.
41
41
  def execute(sql, opts={})
42
+ Sequel::Deprecation.deprecate('Database#execute default implementation and Sequel::NotImplemented', 'All database instances can be assumed to implement execute')
42
43
  raise NotImplemented, "#execute should be overridden by adapters"
43
44
  end
44
45
 
@@ -78,6 +79,7 @@ module Sequel
78
79
  # :on_delete :: The action to take ON DELETE
79
80
  # :on_update :: The action to take ON UPDATE
80
81
  def foreign_key_list(table, opts={})
82
+ Sequel::Deprecation.deprecate('Database#foreign_key_list default implementation and Sequel::NotImplemented', 'Use Database#supports_foreign_key_parsing? to check for support')
81
83
  raise NotImplemented, "#foreign_key_list should be overridden by adapters"
82
84
  end
83
85
 
@@ -87,7 +89,7 @@ module Sequel
87
89
  # # => 1
88
90
  # DB.get{server_version{}} # SELECT server_version()
89
91
  def get(*args, &block)
90
- dataset.get(*args, &block)
92
+ @default_dataset.get(*args, &block)
91
93
  end
92
94
 
93
95
  # Return a hash containing index information for the table. Hash keys are index name symbols.
@@ -100,6 +102,7 @@ module Sequel
100
102
  # DB.indexes(:artists)
101
103
  # # => {:artists_name_ukey=>{:columns=>[:name], :unique=>true}}
102
104
  def indexes(table, opts={})
105
+ Sequel::Deprecation.deprecate('Database#indexes default implementation and Sequel::NotImplemented', 'Use Database#supports_index_parsing? to check for support')
103
106
  raise NotImplemented, "#indexes should be overridden by adapters"
104
107
  end
105
108
 
@@ -219,6 +222,7 @@ module Sequel
219
222
  #
220
223
  # DB.tables # => [:albums, :artists]
221
224
  def tables(opts={})
225
+ Sequel::Deprecation.deprecate('Database#tables default implementation and Sequel::NotImplemented', 'Use Database#supports_table_listing? to check for support')
222
226
  raise NotImplemented, "#tables should be overridden by adapters"
223
227
  end
224
228
 
@@ -226,6 +230,7 @@ module Sequel
226
230
  #
227
231
  # DB.views # => [:gold_albums, :artists_with_many_albums]
228
232
  def views(opts={})
233
+ Sequel::Deprecation.deprecate('Database#views default implementation and Sequel::NotImplemented', 'Use Database#supports_view_listing? to check for support')
229
234
  raise NotImplemented, "#views should be overridden by adapters"
230
235
  end
231
236
 
@@ -234,7 +239,7 @@ module Sequel
234
239
  # Should raise an error if the table doesn't not exist,
235
240
  # and not raise an error if the table does exist.
236
241
  def _table_exists?(ds)
237
- ds.get(Sequel::NULL)
242
+ ds.get(SQL::AliasedExpression.new(Sequel::NULL, :nil))
238
243
  end
239
244
 
240
245
  # Whether the type should be treated as a string type when parsing the
@@ -312,11 +317,12 @@ module Sequel
312
317
  # for this database. Used when parsing metadata so that column symbols are
313
318
  # returned as expected.
314
319
  def metadata_dataset
315
- return @metadata_dataset if defined?(@metadata_dataset) && @metadata_dataset
316
- ds = dataset
317
- ds.identifier_input_method = identifier_input_method_default
318
- ds.identifier_output_method = identifier_output_method_default
319
- @metadata_dataset = ds
320
+ @metadata_dataset ||= (
321
+ ds = dataset;
322
+ ds.identifier_input_method = identifier_input_method_default;
323
+ ds.identifier_output_method = identifier_output_method_default;
324
+ ds
325
+ )
320
326
  end
321
327
 
322
328
  # Return a Method object for the dataset's output_identifier_method.
@@ -646,7 +646,7 @@ module Sequel
646
646
  # for certain databases.
647
647
  def default_index_name(table_name, columns)
648
648
  schema, table = schema_and_table(table_name)
649
- "#{"#{schema}_" if schema and schema != default_schema}#{table}_#{columns.map{|c| [String, Symbol].any?{|cl| c.is_a?(cl)} ? c : literal(c).gsub(/\W/, '_')}.join(UNDERSCORE)}_index"
649
+ "#{"#{schema}_" if schema and schema != _default_schema}#{table}_#{columns.map{|c| [String, Symbol].any?{|cl| c.is_a?(cl)} ? c : literal(c).gsub(/\W/, '_')}.join(UNDERSCORE)}_index"
650
650
  end
651
651
 
652
652
  # Get foreign key name for given table and columns.
@@ -752,12 +752,12 @@ module Sequel
752
752
  "ALTER TABLE #{quote_schema_table(name)} RENAME TO #{quote_schema_table(new_name)}"
753
753
  end
754
754
 
755
- # Remove the cached schema_utility_dataset, because the identifier
756
- # quoting has changed.
755
+ # REMOVE40
757
756
  def reset_schema_utility_dataset
758
- @schema_utility_dataset = nil
757
+ Sequel::Deprecation.deprecate('Database#reset_schema_utility_dataset', 'Switch to Database#reset_default_dataset')
758
+ reset_default_dataset
759
759
  end
760
-
760
+
761
761
  # Split the schema information from the table
762
762
  def schema_and_table(table_name)
763
763
  schema_utility_dataset.schema_and_table(table_name)
@@ -770,7 +770,7 @@ module Sequel
770
770
 
771
771
  # The dataset to use for proxying certain schema methods.
772
772
  def schema_utility_dataset
773
- @schema_utility_dataset ||= dataset
773
+ @default_dataset
774
774
  end
775
775
 
776
776
  # Split the schema information from the table
@@ -74,6 +74,7 @@ module Sequel
74
74
  # and :remote_write (9.2+).
75
75
  def transaction(opts={}, &block)
76
76
  if opts[:disconnect] == :retry
77
+ Sequel::Deprecation.deprecate('Database#transaction :disconnect=>:retry option', 'Please switch to :retry_on=>Sequel::DatabaseDisconnectError.')
77
78
  raise(Error, 'cannot specify both :disconnect=>:retry and :retry_on') if opts[:retry_on]
78
79
  return transaction(opts.merge(:retry_on=>Sequel::DatabaseDisconnectError, :disconnect=>nil), &block)
79
80
  end
@@ -14,6 +14,7 @@ module Sequel
14
14
  map max min multi_insert paged_each range select_hash select_hash_groups select_map select_order_map
15
15
  set single_record single_value sum to_csv to_hash to_hash_groups truncate update
16
16
  METHS
17
+ # REMOVE40 []= insert_multiple set to_csv
17
18
 
18
19
  # Inserts the given argument into the database. Returns self so it
19
20
  # can be used safely when chaining:
@@ -39,6 +40,7 @@ module Sequel
39
40
  # DB[:table][:id=>1] = {:id=>2} # UPDATE table SET id = 2 WHERE id = 1
40
41
  # # => 1 # number of rows affected
41
42
  def []=(conditions, values)
43
+ Sequel::Deprecation.deprecate('Dataset#[]=', 'Please load the sequel_3_dataset_methods extension to continue using it')
42
44
  filter(conditions).update(values)
43
45
  end
44
46
 
@@ -66,7 +68,7 @@ module Sequel
66
68
  # DB[:table].avg{function(column)} # SELECT avg(function(column)) FROM table LIMIT 1
67
69
  # # => 1
68
70
  def avg(column=Sequel.virtual_row(&Proc.new))
69
- aggregate_dataset.get{avg(column)}
71
+ aggregate_dataset.get{avg(column).as(:avg)}
70
72
  end
71
73
 
72
74
  # Returns the columns in the result set in order as an array of symbols.
@@ -101,24 +103,24 @@ module Sequel
101
103
  # treated as a virtual row, and the result is used as the argument to
102
104
  # count.
103
105
  #
104
- # DB[:table].count # SELECT COUNT(*) AS count FROM table LIMIT 1
106
+ # DB[:table].count # SELECT count(*) AS count FROM table LIMIT 1
105
107
  # # => 3
106
- # DB[:table].count(:column) # SELECT COUNT(column) AS count FROM table LIMIT 1
108
+ # DB[:table].count(:column) # SELECT count(column) AS count FROM table LIMIT 1
107
109
  # # => 2
108
- # DB[:table].count{foo(column)} # SELECT COUNT(foo(column)) AS count FROM table LIMIT 1
110
+ # DB[:table].count{foo(column)} # SELECT count(foo(column)) AS count FROM table LIMIT 1
109
111
  # # => 1
110
112
  def count(arg=(no_arg=true), &block)
111
113
  if no_arg
112
114
  if block
113
115
  arg = Sequel.virtual_row(&block)
114
- aggregate_dataset.get{COUNT(arg).as(count)}
116
+ aggregate_dataset.get{count(arg).as(count)}
115
117
  else
116
- aggregate_dataset.get{COUNT(:*){}.as(count)}.to_i
118
+ aggregate_dataset.get{count(:*){}.as(count)}.to_i
117
119
  end
118
120
  elsif block
119
121
  raise Error, 'cannot provide both argument and block to Dataset#count'
120
122
  else
121
- aggregate_dataset.get{COUNT(arg).as(count)}
123
+ aggregate_dataset.get{count(arg).as(count)}
122
124
  end
123
125
  end
124
126
 
@@ -144,11 +146,11 @@ module Sequel
144
146
  # Note that this method is not safe to use on many adapters if you are
145
147
  # running additional queries inside the provided block. If you are
146
148
  # running queries inside the block, you should use +all+ instead of +each+
147
- # for the outer queries, or use a separate thread or shard inside +each+:
149
+ # for the outer queries, or use a separate thread or shard inside +each+.
148
150
  def each
149
151
  if @opts[:graph]
150
152
  graph_each{|r| yield r}
151
- elsif defined?(@row_proc) && (row_proc = @row_proc)
153
+ elsif row_proc = @row_proc
152
154
  fetch_rows(select_sql){|r| yield row_proc.call(r)}
153
155
  else
154
156
  fetch_rows(select_sql){|r| yield r}
@@ -169,6 +171,7 @@ module Sequel
169
171
  # This method should probably should not be called by user code, use +each+
170
172
  # instead.
171
173
  def fetch_rows(sql)
174
+ Sequel::Deprecation.deprecate('Dataset#fetch_rows default implementation and Sequel::NotImplemented', 'All dataset instances can be assumed to implement fetch_rows')
172
175
  raise NotImplemented, NOTIMPL_MSG
173
176
  end
174
177
 
@@ -214,7 +217,7 @@ module Sequel
214
217
  ds.single_record
215
218
  else
216
219
  args = (args.size == 1) ? args.first : args
217
- if Integer === args
220
+ if args.is_a?(Integer)
218
221
  ds.limit(args).all
219
222
  else
220
223
  ds.filter(args).single_record
@@ -263,7 +266,7 @@ module Sequel
263
266
 
264
267
  if column.is_a?(Array)
265
268
  if r = ds.single_record
266
- r.values_at(*column.map{|c| hash_key_symbol(c)})
269
+ r.values_at(*hash_key_symbols(column))
267
270
  end
268
271
  else
269
272
  ds.single_value
@@ -373,6 +376,7 @@ module Sequel
373
376
  # # INSERT INTO table (x, y) VALUES (1, 2)
374
377
  # # INSERT INTO table (x, y) VALUES (2, 4)
375
378
  def insert_multiple(array, &block)
379
+ Sequel::Deprecation.deprecate('Dataset#insert_multiple', 'Please load the sequel_3_dataset_methods extension to continue using it')
376
380
  if block
377
381
  array.map{|i| insert(block.call(i))}
378
382
  else
@@ -388,7 +392,7 @@ module Sequel
388
392
  # DB[:table].interval{function(column)} # SELECT (max(function(column)) - min(function(column))) FROM table LIMIT 1
389
393
  # # => 7
390
394
  def interval(column=Sequel.virtual_row(&Proc.new))
391
- aggregate_dataset.get{max(column) - min(column)}
395
+ aggregate_dataset.get{(max(column) - min(column)).as(:interval)}
392
396
  end
393
397
 
394
398
  # Reverses the order and then runs #first with the given arguments and block. Note that this
@@ -442,7 +446,7 @@ module Sequel
442
446
  # DB[:table].max{function(column)} # SELECT max(function(column)) FROM table LIMIT 1
443
447
  # # => 7
444
448
  def max(column=Sequel.virtual_row(&Proc.new))
445
- aggregate_dataset.get{max(column)}
449
+ aggregate_dataset.get{max(column).as(:max)}
446
450
  end
447
451
 
448
452
  # Returns the minimum value for the given column/expression.
@@ -453,7 +457,7 @@ module Sequel
453
457
  # DB[:table].min{function(column)} # SELECT min(function(column)) FROM table LIMIT 1
454
458
  # # => 0
455
459
  def min(column=Sequel.virtual_row(&Proc.new))
456
- aggregate_dataset.get{min(column)}
460
+ aggregate_dataset.get{min(column).as(:min)}
457
461
  end
458
462
 
459
463
  # This is a front end for import that allows you to submit an array of
@@ -621,6 +625,7 @@ module Sequel
621
625
  # Alias for update, but not aliased directly so subclasses
622
626
  # don't have to override both methods.
623
627
  def set(*args)
628
+ Sequel::Deprecation.deprecate('Dataset#set', 'Please switch to Dataset#update or load the sequel_3_dataset_methods extension to continue using it')
624
629
  update(*args)
625
630
  end
626
631
 
@@ -649,7 +654,7 @@ module Sequel
649
654
  # DB[:table].sum{function(column)} # SELECT sum(function(column)) FROM table LIMIT 1
650
655
  # # => 10
651
656
  def sum(column=Sequel.virtual_row(&Proc.new))
652
- aggregate_dataset.get{sum(column)}
657
+ aggregate_dataset.get{sum(column).as(:sum)}
653
658
  end
654
659
 
655
660
  # Returns a string in CSV format containing the dataset records. By
@@ -666,6 +671,7 @@ module Sequel
666
671
  # # 1,Jim
667
672
  # # 2,Bob
668
673
  def to_csv(include_column_titles = true)
674
+ Sequel::Deprecation.deprecate('Dataset#to_csv', 'Please load the sequel_3_dataset_methods extension to continue using it')
669
675
  n = naked
670
676
  cols = n.columns
671
677
  csv = ''
@@ -824,17 +830,8 @@ module Sequel
824
830
 
825
831
  # Internals of +select_hash+ and +select_hash_groups+
826
832
  def _select_hash(meth, key_column, value_column)
827
- if key_column.is_a?(Array)
828
- if value_column.is_a?(Array)
829
- select(*(key_column + value_column)).send(meth, key_column.map{|c| hash_key_symbol(c)}, value_column.map{|c| hash_key_symbol(c)})
830
- else
831
- select(*(key_column + [value_column])).send(meth, key_column.map{|c| hash_key_symbol(c)}, hash_key_symbol(value_column))
832
- end
833
- elsif value_column.is_a?(Array)
834
- select(key_column, *value_column).send(meth, hash_key_symbol(key_column), value_column.map{|c| hash_key_symbol(c)})
835
- else
836
- select(key_column, value_column).send(meth, hash_key_symbol(key_column), hash_key_symbol(value_column))
837
- end
833
+ select(*(key_column.is_a?(Array) ? key_column : [key_column]) + (value_column.is_a?(Array) ? value_column : [value_column])).
834
+ send(meth, hash_key_symbols(key_column), hash_key_symbols(value_column))
838
835
  end
839
836
 
840
837
  # Internals of +select_map+ and +select_order_map+
@@ -846,7 +843,7 @@ module Sequel
846
843
  ds = ds.select(*select_cols)
847
844
  ds = ds.order(*columns.map{|c| unaliased_identifier(c)}) if order
848
845
  if column.is_a?(Array) || (columns.length > 1)
849
- ds._select_map_multiple(select_cols.map{|c| hash_key_symbol(c)})
846
+ ds._select_map_multiple(hash_key_symbols(select_cols))
850
847
  else
851
848
  ds._select_map_single
852
849
  end
@@ -881,28 +878,44 @@ module Sequel
881
878
 
882
879
  # Return a plain symbol given a potentially qualified or aliased symbol,
883
880
  # specifying the symbol that is likely to be used as the hash key
884
- # for the column when records are returned.
885
- def hash_key_symbol(s, recursing=false)
881
+ # for the column when records are returned. Return nil if no hash key
882
+ # can be determined
883
+ def _hash_key_symbol(s, recursing=false)
886
884
  case s
887
885
  when Symbol
888
886
  _, c, a = split_symbol(s)
889
887
  (a || c).to_sym
890
888
  when SQL::Identifier, SQL::Wrapper
891
- hash_key_symbol(s.value, true)
889
+ _hash_key_symbol(s.value, true)
892
890
  when SQL::QualifiedIdentifier
893
- hash_key_symbol(s.column, true)
891
+ _hash_key_symbol(s.column, true)
894
892
  when SQL::AliasedExpression
895
- hash_key_symbol(s.aliaz, true)
893
+ _hash_key_symbol(s.aliaz, true)
896
894
  when String
897
- if recursing
898
- s.to_sym
899
- else
900
- raise(Error, "#{s.inspect} is not supported, should be a Symbol, SQL::Identifier, SQL::QualifiedIdentifier, or SQL::AliasedExpression")
901
- end
895
+ s.to_sym if recursing
896
+ end
897
+ end
898
+
899
+ # Return a plain symbol given a potentially qualified or aliased symbol,
900
+ # specifying the symbol that is likely to be used as the hash key
901
+ # for the column when records are returned. Raise Error if the hash key
902
+ # symbol cannot be returned.
903
+ def hash_key_symbol(s)
904
+ if v = _hash_key_symbol(s)
905
+ v
906
+ elsif block_given?
907
+ yield
902
908
  else
903
- raise(Error, "#{s.inspect} is not supported, should be a Symbol, SQL::Identifier, SQL::QualifiedIdentifier, or SQL::AliasedExpression")
909
+ raise(Error, "#{s.inspect} is not supported, should be a Symbol, SQL::Identifier, SQL::QualifiedIdentifier, or SQL::AliasedExpression")
904
910
  end
905
911
  end
912
+
913
+ # If s is an array, return an array with the given hash key symbols.
914
+ # Otherwise, return a hash key symbol for the given expression
915
+ # If a hash key symbol cannot be determined, raise an error.
916
+ def hash_key_symbols(s)
917
+ s.is_a?(Array) ? s.map{|c| hash_key_symbol(c)} : hash_key_symbol(s)
918
+ end
906
919
 
907
920
  # Modify the identifier returned from the database based on the
908
921
  # identifier_output_method.