sequel 3.48.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +114 -0
  3. data/Rakefile +10 -7
  4. data/doc/association_basics.rdoc +25 -23
  5. data/doc/code_order.rdoc +7 -0
  6. data/doc/core_extensions.rdoc +0 -10
  7. data/doc/object_model.rdoc +4 -1
  8. data/doc/querying.rdoc +3 -3
  9. data/doc/release_notes/4.0.0.txt +262 -0
  10. data/doc/security.rdoc +0 -28
  11. data/doc/testing.rdoc +8 -14
  12. data/lib/sequel/adapters/ado.rb +7 -11
  13. data/lib/sequel/adapters/ado/access.rb +8 -8
  14. data/lib/sequel/adapters/ado/mssql.rb +4 -4
  15. data/lib/sequel/adapters/amalgalite.rb +6 -6
  16. data/lib/sequel/adapters/cubrid.rb +7 -7
  17. data/lib/sequel/adapters/db2.rb +5 -9
  18. data/lib/sequel/adapters/dbi.rb +2 -6
  19. data/lib/sequel/adapters/do.rb +4 -4
  20. data/lib/sequel/adapters/firebird.rb +4 -4
  21. data/lib/sequel/adapters/ibmdb.rb +8 -8
  22. data/lib/sequel/adapters/informix.rb +2 -10
  23. data/lib/sequel/adapters/jdbc.rb +17 -17
  24. data/lib/sequel/adapters/jdbc/as400.rb +2 -2
  25. data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
  26. data/lib/sequel/adapters/jdbc/db2.rb +1 -1
  27. data/lib/sequel/adapters/jdbc/derby.rb +1 -1
  28. data/lib/sequel/adapters/jdbc/h2.rb +2 -2
  29. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
  30. data/lib/sequel/adapters/jdbc/informix.rb +1 -1
  31. data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
  32. data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
  33. data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
  34. data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
  35. data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
  36. data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
  37. data/lib/sequel/adapters/mock.rb +7 -7
  38. data/lib/sequel/adapters/mysql.rb +3 -3
  39. data/lib/sequel/adapters/mysql2.rb +4 -4
  40. data/lib/sequel/adapters/odbc.rb +2 -6
  41. data/lib/sequel/adapters/odbc/mssql.rb +1 -1
  42. data/lib/sequel/adapters/openbase.rb +1 -5
  43. data/lib/sequel/adapters/oracle.rb +13 -17
  44. data/lib/sequel/adapters/postgres.rb +20 -25
  45. data/lib/sequel/adapters/shared/cubrid.rb +3 -3
  46. data/lib/sequel/adapters/shared/db2.rb +2 -2
  47. data/lib/sequel/adapters/shared/firebird.rb +7 -7
  48. data/lib/sequel/adapters/shared/mssql.rb +9 -9
  49. data/lib/sequel/adapters/shared/mysql.rb +29 -13
  50. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
  51. data/lib/sequel/adapters/shared/oracle.rb +22 -13
  52. data/lib/sequel/adapters/shared/postgres.rb +61 -46
  53. data/lib/sequel/adapters/shared/sqlite.rb +9 -9
  54. data/lib/sequel/adapters/sqlite.rb +17 -11
  55. data/lib/sequel/adapters/swift.rb +3 -3
  56. data/lib/sequel/adapters/swift/mysql.rb +1 -1
  57. data/lib/sequel/adapters/swift/sqlite.rb +1 -1
  58. data/lib/sequel/adapters/tinytds.rb +8 -8
  59. data/lib/sequel/ast_transformer.rb +3 -1
  60. data/lib/sequel/connection_pool.rb +4 -2
  61. data/lib/sequel/connection_pool/sharded_single.rb +2 -2
  62. data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
  63. data/lib/sequel/connection_pool/threaded.rb +7 -7
  64. data/lib/sequel/core.rb +4 -67
  65. data/lib/sequel/database.rb +1 -0
  66. data/lib/sequel/database/connecting.rb +2 -8
  67. data/lib/sequel/database/dataset.rb +2 -7
  68. data/lib/sequel/database/dataset_defaults.rb +0 -18
  69. data/lib/sequel/database/features.rb +4 -4
  70. data/lib/sequel/database/misc.rb +6 -8
  71. data/lib/sequel/database/query.rb +5 -61
  72. data/lib/sequel/database/schema_generator.rb +22 -20
  73. data/lib/sequel/database/schema_methods.rb +48 -20
  74. data/lib/sequel/database/transactions.rb +7 -17
  75. data/lib/sequel/dataset.rb +2 -0
  76. data/lib/sequel/dataset/actions.rb +23 -91
  77. data/lib/sequel/dataset/features.rb +1 -4
  78. data/lib/sequel/dataset/graph.rb +3 -47
  79. data/lib/sequel/dataset/misc.rb +4 -33
  80. data/lib/sequel/dataset/prepared_statements.rb +3 -1
  81. data/lib/sequel/dataset/query.rb +116 -240
  82. data/lib/sequel/dataset/sql.rb +19 -97
  83. data/lib/sequel/deprecated.rb +0 -16
  84. data/lib/sequel/exceptions.rb +0 -3
  85. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  86. data/lib/sequel/extensions/columns_introspection.rb +1 -12
  87. data/lib/sequel/extensions/constraint_validations.rb +3 -3
  88. data/lib/sequel/extensions/core_extensions.rb +0 -9
  89. data/lib/sequel/extensions/date_arithmetic.rb +1 -2
  90. data/lib/sequel/extensions/graph_each.rb +11 -0
  91. data/lib/sequel/extensions/migration.rb +5 -5
  92. data/lib/sequel/extensions/null_dataset.rb +11 -13
  93. data/lib/sequel/extensions/pagination.rb +3 -6
  94. data/lib/sequel/extensions/pg_array.rb +6 -4
  95. data/lib/sequel/extensions/pg_array_ops.rb +35 -1
  96. data/lib/sequel/extensions/pg_json.rb +12 -2
  97. data/lib/sequel/extensions/pg_json_ops.rb +266 -0
  98. data/lib/sequel/extensions/pg_range.rb +2 -2
  99. data/lib/sequel/extensions/pg_range_ops.rb +0 -8
  100. data/lib/sequel/extensions/pg_row.rb +2 -2
  101. data/lib/sequel/extensions/pretty_table.rb +0 -4
  102. data/lib/sequel/extensions/query.rb +3 -8
  103. data/lib/sequel/extensions/schema_caching.rb +0 -7
  104. data/lib/sequel/extensions/schema_dumper.rb +10 -17
  105. data/lib/sequel/extensions/select_remove.rb +0 -4
  106. data/lib/sequel/extensions/set_overrides.rb +28 -0
  107. data/lib/sequel/extensions/to_dot.rb +6 -10
  108. data/lib/sequel/model.rb +6 -7
  109. data/lib/sequel/model/associations.rb +127 -182
  110. data/lib/sequel/model/base.rb +88 -211
  111. data/lib/sequel/model/errors.rb +0 -13
  112. data/lib/sequel/model/plugins.rb +2 -2
  113. data/lib/sequel/no_core_ext.rb +0 -1
  114. data/lib/sequel/plugins/after_initialize.rb +11 -17
  115. data/lib/sequel/plugins/association_autoreloading.rb +1 -47
  116. data/lib/sequel/plugins/association_dependencies.rb +2 -2
  117. data/lib/sequel/plugins/auto_validations.rb +2 -8
  118. data/lib/sequel/plugins/blacklist_security.rb +32 -2
  119. data/lib/sequel/plugins/caching.rb +1 -1
  120. data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
  121. data/lib/sequel/plugins/composition.rb +10 -8
  122. data/lib/sequel/plugins/constraint_validations.rb +2 -2
  123. data/lib/sequel/plugins/dataset_associations.rb +4 -0
  124. data/lib/sequel/plugins/defaults_setter.rb +8 -6
  125. data/lib/sequel/plugins/dirty.rb +6 -6
  126. data/lib/sequel/plugins/force_encoding.rb +13 -8
  127. data/lib/sequel/plugins/hook_class_methods.rb +1 -7
  128. data/lib/sequel/plugins/json_serializer.rb +13 -74
  129. data/lib/sequel/plugins/lazy_attributes.rb +2 -4
  130. data/lib/sequel/plugins/list.rb +1 -1
  131. data/lib/sequel/plugins/many_through_many.rb +4 -11
  132. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
  133. data/lib/sequel/plugins/nested_attributes.rb +1 -1
  134. data/lib/sequel/plugins/optimistic_locking.rb +3 -5
  135. data/lib/sequel/plugins/pg_array_associations.rb +453 -0
  136. data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
  137. data/lib/sequel/plugins/prepared_statements.rb +1 -1
  138. data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
  139. data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
  140. data/lib/sequel/plugins/rcte_tree.rb +1 -1
  141. data/lib/sequel/plugins/serialization.rb +5 -4
  142. data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
  143. data/lib/sequel/plugins/sharding.rb +7 -1
  144. data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
  145. data/lib/sequel/plugins/timestamps.rb +1 -1
  146. data/lib/sequel/plugins/touch.rb +2 -2
  147. data/lib/sequel/plugins/tree.rb +1 -1
  148. data/lib/sequel/plugins/typecast_on_load.rb +19 -4
  149. data/lib/sequel/plugins/validation_class_methods.rb +0 -30
  150. data/lib/sequel/plugins/validation_helpers.rb +13 -31
  151. data/lib/sequel/plugins/xml_serializer.rb +18 -57
  152. data/lib/sequel/sql.rb +20 -22
  153. data/lib/sequel/version.rb +2 -2
  154. data/spec/adapters/db2_spec.rb +14 -23
  155. data/spec/adapters/firebird_spec.rb +25 -29
  156. data/spec/adapters/informix_spec.rb +11 -14
  157. data/spec/adapters/mssql_spec.rb +71 -77
  158. data/spec/adapters/mysql_spec.rb +165 -172
  159. data/spec/adapters/oracle_spec.rb +36 -39
  160. data/spec/adapters/postgres_spec.rb +175 -100
  161. data/spec/adapters/spec_helper.rb +13 -11
  162. data/spec/adapters/sqlite_spec.rb +36 -44
  163. data/spec/core/connection_pool_spec.rb +2 -1
  164. data/spec/core/database_spec.rb +55 -55
  165. data/spec/core/dataset_spec.rb +45 -249
  166. data/spec/core/deprecated_spec.rb +0 -8
  167. data/spec/core/expression_filters_spec.rb +23 -5
  168. data/spec/core/object_graph_spec.rb +4 -66
  169. data/spec/core/schema_spec.rb +35 -12
  170. data/spec/core/spec_helper.rb +3 -2
  171. data/spec/core_extensions_spec.rb +17 -19
  172. data/spec/extensions/arbitrary_servers_spec.rb +2 -3
  173. data/spec/extensions/association_dependencies_spec.rb +14 -14
  174. data/spec/extensions/auto_validations_spec.rb +7 -0
  175. data/spec/extensions/blacklist_security_spec.rb +5 -5
  176. data/spec/extensions/blank_spec.rb +2 -0
  177. data/spec/extensions/class_table_inheritance_spec.rb +2 -2
  178. data/spec/extensions/columns_introspection_spec.rb +2 -29
  179. data/spec/extensions/composition_spec.rb +10 -17
  180. data/spec/extensions/core_refinements_spec.rb +5 -1
  181. data/spec/extensions/dataset_associations_spec.rb +18 -0
  182. data/spec/extensions/date_arithmetic_spec.rb +2 -2
  183. data/spec/extensions/defaults_setter_spec.rb +9 -9
  184. data/spec/extensions/dirty_spec.rb +0 -5
  185. data/spec/extensions/eval_inspect_spec.rb +2 -0
  186. data/spec/extensions/force_encoding_spec.rb +2 -18
  187. data/spec/extensions/hash_aliases_spec.rb +8 -0
  188. data/spec/extensions/hook_class_methods_spec.rb +39 -58
  189. data/spec/extensions/inflector_spec.rb +2 -0
  190. data/spec/extensions/instance_filters_spec.rb +8 -8
  191. data/spec/extensions/json_serializer_spec.rb +1 -41
  192. data/spec/extensions/list_spec.rb +1 -1
  193. data/spec/extensions/many_through_many_spec.rb +106 -109
  194. data/spec/extensions/migration_spec.rb +2 -0
  195. data/spec/extensions/named_timezones_spec.rb +1 -0
  196. data/spec/extensions/pg_array_associations_spec.rb +603 -0
  197. data/spec/extensions/pg_array_ops_spec.rb +25 -0
  198. data/spec/extensions/pg_array_spec.rb +9 -1
  199. data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
  200. data/spec/extensions/pg_hstore_spec.rb +1 -0
  201. data/spec/extensions/pg_json_ops_spec.rb +131 -0
  202. data/spec/extensions/pg_json_spec.rb +10 -4
  203. data/spec/extensions/pg_range_ops_spec.rb +2 -5
  204. data/spec/extensions/pg_range_spec.rb +6 -2
  205. data/spec/extensions/pg_row_ops_spec.rb +2 -0
  206. data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
  207. data/spec/extensions/rcte_tree_spec.rb +15 -15
  208. data/spec/extensions/schema_dumper_spec.rb +0 -1
  209. data/spec/extensions/schema_spec.rb +9 -9
  210. data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
  211. data/spec/extensions/serialization_spec.rb +18 -29
  212. data/spec/extensions/set_overrides_spec.rb +4 -0
  213. data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
  214. data/spec/extensions/single_table_inheritance_spec.rb +4 -4
  215. data/spec/extensions/spec_helper.rb +8 -9
  216. data/spec/extensions/sql_expr_spec.rb +2 -0
  217. data/spec/extensions/string_date_time_spec.rb +2 -0
  218. data/spec/extensions/string_stripper_spec.rb +2 -0
  219. data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
  220. data/spec/extensions/thread_local_timezones_spec.rb +2 -0
  221. data/spec/extensions/timestamps_spec.rb +1 -1
  222. data/spec/extensions/to_dot_spec.rb +1 -1
  223. data/spec/extensions/touch_spec.rb +24 -24
  224. data/spec/extensions/tree_spec.rb +7 -7
  225. data/spec/extensions/typecast_on_load_spec.rb +8 -1
  226. data/spec/extensions/update_primary_key_spec.rb +10 -10
  227. data/spec/extensions/validation_class_methods_spec.rb +10 -39
  228. data/spec/extensions/validation_helpers_spec.rb +29 -47
  229. data/spec/extensions/xml_serializer_spec.rb +1 -23
  230. data/spec/integration/associations_test.rb +231 -40
  231. data/spec/integration/database_test.rb +1 -1
  232. data/spec/integration/dataset_test.rb +64 -64
  233. data/spec/integration/eager_loader_test.rb +28 -28
  234. data/spec/integration/migrator_test.rb +1 -1
  235. data/spec/integration/model_test.rb +2 -2
  236. data/spec/integration/plugin_test.rb +21 -21
  237. data/spec/integration/prepared_statement_test.rb +7 -7
  238. data/spec/integration/schema_test.rb +115 -110
  239. data/spec/integration/spec_helper.rb +17 -27
  240. data/spec/integration/timezone_test.rb +1 -1
  241. data/spec/integration/transaction_test.rb +10 -10
  242. data/spec/integration/type_test.rb +2 -2
  243. data/spec/model/association_reflection_spec.rb +2 -28
  244. data/spec/model/associations_spec.rb +239 -188
  245. data/spec/model/base_spec.rb +27 -68
  246. data/spec/model/dataset_methods_spec.rb +4 -4
  247. data/spec/model/eager_loading_spec.rb +160 -172
  248. data/spec/model/hooks_spec.rb +62 -79
  249. data/spec/model/model_spec.rb +36 -51
  250. data/spec/model/plugins_spec.rb +5 -19
  251. data/spec/model/record_spec.rb +125 -151
  252. data/spec/model/spec_helper.rb +8 -6
  253. data/spec/model/validations_spec.rb +4 -17
  254. data/spec/spec_config.rb +2 -10
  255. metadata +50 -56
  256. data/lib/sequel/deprecated_core_extensions.rb +0 -135
  257. data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
  258. data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
  259. data/lib/sequel/plugins/identity_map.rb +0 -260
  260. data/lib/sequel_core.rb +0 -2
  261. data/lib/sequel_model.rb +0 -2
  262. data/spec/extensions/association_autoreloading_spec.rb +0 -102
  263. data/spec/extensions/identity_map_spec.rb +0 -337
  264. data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
  265. data/spec/extensions/pg_statement_cache_spec.rb +0 -208
  266. data/spec/rcov.opts +0 -8
  267. data/spec/spec_config.rb.example +0 -10
@@ -75,7 +75,7 @@ module Sequel
75
75
 
76
76
  # Return the array of foreign key info hashes using the foreign_key_list PRAGMA,
77
77
  # including information for the :on_update and :on_delete entries.
78
- def foreign_key_list(table, opts={})
78
+ def foreign_key_list(table, opts=OPTS)
79
79
  m = output_identifier_meth
80
80
  h = {}
81
81
  metadata_dataset.with_sql("PRAGMA foreign_key_list(?)", input_identifier_meth.call(table)).each do |row|
@@ -90,7 +90,7 @@ module Sequel
90
90
  end
91
91
 
92
92
  # Use the index_list and index_info PRAGMAs to determine the indexes on the table.
93
- def indexes(table, opts={})
93
+ def indexes(table, opts=OPTS)
94
94
  m = output_identifier_meth
95
95
  im = input_identifier_meth
96
96
  indexes = {}
@@ -121,7 +121,7 @@ module Sequel
121
121
 
122
122
  # Set the integer_booleans option using the passed in :integer_boolean option.
123
123
  def set_integer_booleans
124
- @integer_booleans = typecast_value_boolean(@opts[:integer_booleans])
124
+ @integer_booleans = @opts.has_key?(:integer_booleans) ? typecast_value_boolean(@opts[:integer_booleans]) : true
125
125
  end
126
126
 
127
127
  # The version of the server as an integer, where 3.6.19 = 30619.
@@ -161,7 +161,7 @@ module Sequel
161
161
  # SQLite supports timezones in timestamps, since it just stores them as strings,
162
162
  # but it breaks the usage of SQLite's datetime functions.
163
163
  def use_timestamp_timezones?
164
- defined?(@use_timestamp_timezones) ? @use_timestamp_timezones : (@use_timestamp_timezones = true)
164
+ defined?(@use_timestamp_timezones) ? @use_timestamp_timezones : (@use_timestamp_timezones = false)
165
165
  end
166
166
 
167
167
  # A symbol signifying the value of the synchronous PRAGMA.
@@ -180,7 +180,7 @@ module Sequel
180
180
  #
181
181
  # Options:
182
182
  # * :server - Set the server to use.
183
- def tables(opts={})
183
+ def tables(opts=OPTS)
184
184
  tables_and_views(TABLES_FILTER, opts)
185
185
  end
186
186
 
@@ -200,7 +200,7 @@ module Sequel
200
200
  #
201
201
  # Options:
202
202
  # * :server - Set the server to use.
203
- def views(opts={})
203
+ def views(opts=OPTS)
204
204
  tables_and_views(VIEWS_FILTER, opts)
205
205
  end
206
206
 
@@ -282,7 +282,7 @@ module Sequel
282
282
  end
283
283
 
284
284
  # A name to use for the backup table
285
- def backup_table_name(table, opts={})
285
+ def backup_table_name(table, opts=OPTS)
286
286
  table = table.gsub('`', '')
287
287
  (opts[:times]||1000).times do |i|
288
288
  table_name = "#{table}_backup#{i}"
@@ -346,7 +346,7 @@ module Sequel
346
346
  # Duplicate an existing table by creating a new table, copying all records
347
347
  # from the existing table into the new table, deleting the existing table
348
348
  # and renaming the new table to the existing table's name.
349
- def duplicate_table(table, opts={})
349
+ def duplicate_table(table, opts=OPTS)
350
350
  remove_cached_schema(table)
351
351
  def_columns = defined_columns_for(table)
352
352
  old_columns = def_columns.map{|c| c[:name]}
@@ -435,7 +435,7 @@ module Sequel
435
435
  row.delete(:cid)
436
436
  row[:allow_null] = row.delete(:notnull).to_i == 0
437
437
  row[:default] = row.delete(:dflt_value)
438
- row[:primary_key] = row.delete(:pk).to_i == 1
438
+ row[:primary_key] = row.delete(:pk).to_i > 0
439
439
  row[:default] = nil if blank_object?(row[:default]) || row[:default] == 'NULL'
440
440
  row[:db_type] = row.delete(:type)
441
441
  row[:type] = schema_column_type(row[:db_type])
@@ -118,19 +118,19 @@ module Sequel
118
118
  end
119
119
 
120
120
  # Run the given SQL with the given arguments and yield each row.
121
- def execute(sql, opts={}, &block)
121
+ def execute(sql, opts=OPTS, &block)
122
122
  _execute(:select, sql, opts, &block)
123
123
  end
124
124
 
125
125
  # Run the given SQL with the given arguments and return the number of changed rows.
126
- def execute_dui(sql, opts={})
126
+ def execute_dui(sql, opts=OPTS)
127
127
  _execute(:update, sql, opts)
128
128
  end
129
129
 
130
130
  # Drop any prepared statements on the connection when executing DDL. This is because
131
131
  # prepared statements lock the table in such a way that you can't drop or alter the
132
132
  # table while a prepared statement that references it still exists.
133
- def execute_ddl(sql, opts={})
133
+ def execute_ddl(sql, opts=OPTS)
134
134
  synchronize(opts[:server]) do |conn|
135
135
  conn.prepared_statements.values.each{|cps, s| cps.close}
136
136
  conn.prepared_statements.clear
@@ -139,7 +139,7 @@ module Sequel
139
139
  end
140
140
 
141
141
  # Run the given SQL with the given arguments and return the last inserted row id.
142
- def execute_insert(sql, opts={})
142
+ def execute_insert(sql, opts=OPTS)
143
143
  _execute(:insert, sql, opts)
144
144
  end
145
145
 
@@ -203,10 +203,16 @@ module Sequel
203
203
 
204
204
  def prepared_statement_argument(arg)
205
205
  case arg
206
- when Date, DateTime, Time, TrueClass, FalseClass
206
+ when Date, DateTime, Time
207
207
  literal(arg)[1...-1]
208
208
  when SQL::Blob
209
209
  arg.to_blob
210
+ when true, false
211
+ if integer_booleans
212
+ arg ? 1 : 0
213
+ else
214
+ literal(arg)[1...-1]
215
+ end
210
216
  else
211
217
  arg
212
218
  end
@@ -301,17 +307,17 @@ module Sequel
301
307
 
302
308
  # Run execute_select on the database with the given SQL and the stored
303
309
  # bind arguments.
304
- def execute(sql, opts={}, &block)
310
+ def execute(sql, opts=OPTS, &block)
305
311
  super(sql, {:arguments=>bind_arguments}.merge(opts), &block)
306
312
  end
307
313
 
308
314
  # Same as execute, explicit due to intricacies of alias and super.
309
- def execute_dui(sql, opts={}, &block)
315
+ def execute_dui(sql, opts=OPTS, &block)
310
316
  super(sql, {:arguments=>bind_arguments}.merge(opts), &block)
311
317
  end
312
318
 
313
319
  # Same as execute, explicit due to intricacies of alias and super.
314
- def execute_insert(sql, opts={}, &block)
320
+ def execute_insert(sql, opts=OPTS, &block)
315
321
  super(sql, {:arguments=>bind_arguments}.merge(opts), &block)
316
322
  end
317
323
  end
@@ -323,17 +329,17 @@ module Sequel
323
329
 
324
330
  # Execute the stored prepared statement name and the stored bind
325
331
  # arguments instead of the SQL given.
326
- def execute(sql, opts={}, &block)
332
+ def execute(sql, opts=OPTS, &block)
327
333
  super(prepared_statement_name, opts, &block)
328
334
  end
329
335
 
330
336
  # Same as execute, explicit due to intricacies of alias and super.
331
- def execute_dui(sql, opts={}, &block)
337
+ def execute_dui(sql, opts=OPTS, &block)
332
338
  super(prepared_statement_name, opts, &block)
333
339
  end
334
340
 
335
341
  # Same as execute, explicit due to intricacies of alias and super.
336
- def execute_insert(sql, opts={}, &block)
342
+ def execute_insert(sql, opts=OPTS, &block)
337
343
  super(prepared_statement_name, opts, &block)
338
344
  end
339
345
  end
@@ -45,7 +45,7 @@ module Sequel
45
45
  end
46
46
 
47
47
  # Execute the given SQL, yielding a Swift::Result if a block is given.
48
- def execute(sql, opts={})
48
+ def execute(sql, opts=OPTS)
49
49
  synchronize(opts[:server]) do |conn|
50
50
  begin
51
51
  res = log_yield(sql){conn.execute(sql)}
@@ -59,7 +59,7 @@ module Sequel
59
59
 
60
60
  # Execute the SQL on the this database, returning the number of affected
61
61
  # rows.
62
- def execute_dui(sql, opts={})
62
+ def execute_dui(sql, opts=OPTS)
63
63
  synchronize(opts[:server]) do |conn|
64
64
  begin
65
65
  log_yield(sql){conn.execute(sql).affected_rows}
@@ -71,7 +71,7 @@ module Sequel
71
71
 
72
72
  # Execute the SQL on this database, returning the primary key of the
73
73
  # table being inserted to.
74
- def execute_insert(sql, opts={})
74
+ def execute_insert(sql, opts=OPTS)
75
75
  synchronize(opts[:server]) do |conn|
76
76
  begin
77
77
  log_yield(sql){conn.execute(sql).insert_id}
@@ -39,7 +39,7 @@ module Sequel
39
39
 
40
40
  # Use Swift's escape method for quoting.
41
41
  def literal_string_append(sql, s)
42
- sql << APOS << db.synchronize{|c| c.escape(s)} << APOS
42
+ sql << APOS << db.synchronize(@opts[:server]){|c| c.escape(s)} << APOS
43
43
  end
44
44
  end
45
45
  end
@@ -27,7 +27,7 @@ module Sequel
27
27
 
28
28
  # Use Swift's escape method for quoting.
29
29
  def literal_string_append(sql, s)
30
- sql << APOS << db.synchronize{|c| c.escape(s)} << APOS
30
+ sql << APOS << db.synchronize(@opts[:server]){|c| c.escape(s)} << APOS
31
31
  end
32
32
  end
33
33
  end
@@ -28,7 +28,7 @@ module Sequel
28
28
  # +sql+. The value of such a method is returned to the caller.
29
29
  # Otherwise, if a block is given, it is yielded the result object.
30
30
  # If no block is given and a :return is not present, +nil+ is returned.
31
- def execute(sql, opts={})
31
+ def execute(sql, opts=OPTS)
32
32
  synchronize(opts[:server]) do |c|
33
33
  begin
34
34
  m = opts[:return]
@@ -70,18 +70,18 @@ module Sequel
70
70
  end
71
71
 
72
72
  # Return the number of rows modified by the given +sql+.
73
- def execute_dui(sql, opts={})
73
+ def execute_dui(sql, opts=OPTS)
74
74
  execute(sql, opts.merge(:return=>:do))
75
75
  end
76
76
 
77
77
  # Return the value of the autogenerated primary key (if any)
78
78
  # for the row inserted by the given +sql+.
79
- def execute_insert(sql, opts={})
79
+ def execute_insert(sql, opts=OPTS)
80
80
  execute(sql, opts.merge(:return=>:insert))
81
81
  end
82
82
 
83
83
  # Execute the DDL +sql+ on the database and return nil.
84
- def execute_ddl(sql, opts={})
84
+ def execute_ddl(sql, opts=OPTS)
85
85
  execute(sql, opts.merge(:return=>:each))
86
86
  nil
87
87
  end
@@ -211,17 +211,17 @@ module Sequel
211
211
 
212
212
  # Run execute_select on the database with the given SQL and the stored
213
213
  # bind arguments.
214
- def execute(sql, opts={}, &block)
214
+ def execute(sql, opts=OPTS, &block)
215
215
  super(prepared_sql, {:arguments=>bind_arguments}.merge(opts), &block)
216
216
  end
217
217
 
218
218
  # Same as execute, explicit due to intricacies of alias and super.
219
- def execute_dui(sql, opts={}, &block)
219
+ def execute_dui(sql, opts=OPTS, &block)
220
220
  super(prepared_sql, {:arguments=>bind_arguments}.merge(opts), &block)
221
221
  end
222
222
 
223
223
  # Same as execute, explicit due to intricacies of alias and super.
224
- def execute_insert(sql, opts={}, &block)
224
+ def execute_insert(sql, opts=OPTS, &block)
225
225
  super(prepared_sql, {:arguments=>bind_arguments}.merge(opts), &block)
226
226
  end
227
227
  end
@@ -257,7 +257,7 @@ module Sequel
257
257
  # Properly escape the given string +v+.
258
258
  def literal_string_append(sql, v)
259
259
  sql << (mssql_unicode_strings ? UNICODE_STRING_START : APOS)
260
- sql << db.synchronize{|c| c.escape(v)}.gsub(BACKSLASH_CRLF_RE, BACKSLASH_CRLF_REPLACE) << APOS
260
+ sql << db.synchronize(@opts[:server]){|c| c.escape(v)}.gsub(BACKSLASH_CRLF_RE, BACKSLASH_CRLF_REPLACE) << APOS
261
261
  end
262
262
  end
263
263
  end
@@ -157,8 +157,10 @@ module Sequel
157
157
  # an instance of one of the +UNBIND_KEY_CLASSES+.
158
158
  def bind_key(obj)
159
159
  case obj
160
- when Symbol, String
160
+ when Symbol
161
161
  obj
162
+ when String
163
+ obj.to_sym
162
164
  when SQL::Identifier
163
165
  bind_key(obj.value)
164
166
  when SQL::QualifiedIdentifier
@@ -21,6 +21,8 @@
21
21
  # remove_servers(Array of Symbols) :: no longer recognize all shards/servers
22
22
  # specified by the array of symbols.
23
23
  class Sequel::ConnectionPool
24
+ OPTS = Sequel::OPTS
25
+
24
26
  # The default server to use
25
27
  DEFAULT_SERVER = :default
26
28
 
@@ -37,7 +39,7 @@ class Sequel::ConnectionPool
37
39
  # option is provided is provided, use that pool class, otherwise
38
40
  # use a new instance of an appropriate pool subclass based on the
39
41
  # <tt>:single_threaded</tt> and <tt>:servers</tt> options.
40
- def get_pool(db, opts = {})
42
+ def get_pool(db, opts = OPTS)
41
43
  case v = connection_pool_class(opts)
42
44
  when Class
43
45
  v.new(db, opts)
@@ -70,7 +72,7 @@ class Sequel::ConnectionPool
70
72
  # :after_connect :: The proc called after each new connection is made, with the
71
73
  # connection object, useful for customizations that you want to apply to all
72
74
  # connections.
73
- def initialize(db, opts={})
75
+ def initialize(db, opts=OPTS)
74
76
  @db = db
75
77
  @after_connect = opts[:after_connect]
76
78
  end
@@ -9,7 +9,7 @@ class Sequel::ShardedSingleConnectionPool < Sequel::ConnectionPool
9
9
  # Sequel uses Hash.new(:default). You can use a hash with a default proc
10
10
  # that raises an error if you want to catch all cases where a nonexistent
11
11
  # server is used.
12
- def initialize(db, opts={})
12
+ def initialize(db, opts=OPTS)
13
13
  super
14
14
  @conns = {}
15
15
  @servers = opts.fetch(:servers_hash, Hash.new(:default))
@@ -38,7 +38,7 @@ class Sequel::ShardedSingleConnectionPool < Sequel::ConnectionPool
38
38
  # #hold, the connection is reestablished. Options:
39
39
  # * :server - Should be a symbol specifing the server to disconnect from,
40
40
  # or an array of symbols to specify multiple servers.
41
- def disconnect(opts={})
41
+ def disconnect(opts=OPTS)
42
42
  (opts[:server] ? Array(opts[:server]) : servers).each{|s| disconnect_server(s)}
43
43
  end
44
44
 
@@ -13,7 +13,7 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
13
13
  # Sequel uses Hash.new(:default). You can use a hash with a default proc
14
14
  # that raises an error if you want to catch all cases where a nonexistent
15
15
  # server is used.
16
- def initialize(db, opts = {})
16
+ def initialize(db, opts = OPTS)
17
17
  super
18
18
  @available_connections = {}
19
19
  @connections_to_remove = []
@@ -86,7 +86,7 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
86
86
  # creates new connections to the database. Options:
87
87
  # * :server - Should be a symbol specifing the server to disconnect from,
88
88
  # or an array of symbols to specify multiple servers.
89
- def disconnect(opts={})
89
+ def disconnect(opts=OPTS)
90
90
  sync do
91
91
  (opts[:server] ? Array(opts[:server]) : @servers.keys).each do |s|
92
92
  disconnect_server(s)
@@ -217,10 +217,10 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
217
217
  # The calling code should already have the mutex before calling this.
218
218
  def next_available(server)
219
219
  case @connection_handling
220
- when :queue
221
- available_connections(server).shift
222
- else
220
+ when :stack
223
221
  available_connections(server).pop
222
+ else
223
+ available_connections(server).shift
224
224
  end
225
225
  end
226
226
 
@@ -14,15 +14,15 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
14
14
 
15
15
  # The following additional options are respected:
16
16
  # * :connection_handling - Set how to handle available connections. By default,
17
- # uses a a stack for performance. Can be set to :queue to use a queue, which reduces
18
- # the chances of connections becoming stale.
17
+ # uses a a queue for fairness. Can be set to :stack to use a stack, which may
18
+ # offer better performance.
19
19
  # * :max_connections - The maximum number of connections the connection pool
20
20
  # will open (default 4)
21
21
  # * :pool_sleep_time - The amount of time to sleep before attempting to acquire
22
22
  # a connection again (default 0.001)
23
23
  # * :pool_timeout - The amount of seconds to wait to acquire a connection
24
24
  # before raising a PoolTimeoutError (default 5)
25
- def initialize(db, opts = {})
25
+ def initialize(db, opts = OPTS)
26
26
  super
27
27
  @max_size = Integer(opts[:max_connections] || 4)
28
28
  raise(Sequel::Error, ':max_connections must be positive') if @max_size < 1
@@ -64,7 +64,7 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
64
64
  #
65
65
  # Once a connection is requested using #hold, the connection pool
66
66
  # creates new connections to the database.
67
- def disconnect(opts={})
67
+ def disconnect(opts=OPTS)
68
68
  sync do
69
69
  @available_connections.each{|conn| db.disconnect_connection(conn)}
70
70
  @available_connections.clear
@@ -163,10 +163,10 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
163
163
  # have the mutex before calling this.
164
164
  def next_available
165
165
  case @connection_handling
166
- when :queue
167
- @available_connections.shift
168
- else
166
+ when :stack
169
167
  @available_connections.pop
168
+ else
169
+ @available_connections.shift
170
170
  end
171
171
  end
172
172
 
@@ -17,17 +17,11 @@
17
17
  #
18
18
  # Sequel.sqlite('blog.db'){|db| puts db[:users].count}
19
19
  #
20
- # Sequel currently adds methods to the Array, Hash, String and Symbol classes by
21
- # default. You can either require 'sequel/no_core_ext' or set the
22
- # +SEQUEL_NO_CORE_EXTENSIONS+ constant or environment variable before requiring
23
- # sequel to have Sequel not add methods to those classes.
24
- #
25
20
  # For a more expanded introduction, see the {README}[link:files/README_rdoc.html].
26
21
  # For a quicker introduction, see the {cheat sheet}[link:files/doc/cheat_sheet_rdoc.html].
27
22
  module Sequel
28
23
  @convert_two_digit_years = true
29
24
  @datetime_class = Time
30
- @empty_array_handle_nulls = true
31
25
 
32
26
  # Whether Sequel is being run in single threaded mode
33
27
  @single_threaded = false
@@ -54,51 +48,6 @@ module Sequel
54
48
  # they often implement them differently (e.g. + using seconds on +Time+ and
55
49
  # days on +DateTime+).
56
50
  attr_accessor :datetime_class
57
-
58
- # Sets whether or not to attempt to handle NULL values correctly when given
59
- # an empty array. By default:
60
- #
61
- # DB[:a].filter(:b=>[])
62
- # # SELECT * FROM a WHERE (b != b)
63
- # DB[:a].exclude(:b=>[])
64
- # # SELECT * FROM a WHERE (b = b)
65
- #
66
- # However, some databases (e.g. MySQL) will perform very poorly
67
- # with this type of query. You can set this to false to get the
68
- # following behavior:
69
- #
70
- # DB[:a].filter(:b=>[])
71
- # # SELECT * FROM a WHERE 1 = 0
72
- # DB[:a].exclude(:b=>[])
73
- # # SELECT * FROM a WHERE 1 = 1
74
- #
75
- # This may not handle NULLs correctly, but can be much faster on
76
- # some databases.
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
-
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
95
-
96
- private
97
-
98
- # Make thread safe requiring reentrant to prevent deadlocks.
99
- def check_requiring_thread
100
- Sequel::Deprecation.deprecate('Sequel.check_requiring_thread', 'It has no effect, so you can safely stop calling it.')
101
- end
102
51
  end
103
52
 
104
53
  # Returns true if the passed object could be a specifier of conditions, false otherwise.
@@ -121,6 +70,9 @@ module Sequel
121
70
  end
122
71
  end
123
72
 
73
+ # Frozen hash used as the default options hash for most options.
74
+ OPTS = {}.freeze
75
+
124
76
  # Creates a new database object based on the supplied connection string
125
77
  # and optional arguments. The specified scheme determines the database
126
78
  # class used, and the rest of the string specifies the connection options.
@@ -368,7 +320,7 @@ module Sequel
368
320
  # to uncommit the changes on DB3. For that kind of support, you need to
369
321
  # have two-phase commit/prepared transactions (which Sequel supports on
370
322
  # some databases).
371
- def self.transaction(dbs, opts={}, &block)
323
+ def self.transaction(dbs, opts=OPTS, &block)
372
324
  unless opts[:rollback]
373
325
  rescue_rollback = true
374
326
  opts = opts.merge(:rollback=>:reraise)
@@ -385,16 +337,6 @@ module Sequel
385
337
  end
386
338
  end
387
339
 
388
- # REMOVE40
389
- def self.ts_require(*args)
390
- Sequel::Deprecation.deprecate('Sequel.ts_require', 'Please switch to Sequel.require')
391
- require(*args)
392
- end
393
- def self.tsk_require(*args)
394
- Sequel::Deprecation.deprecate('Sequel.tsk_require', 'Please switch to Kernel.require')
395
- Kernel.require(*args)
396
- end
397
-
398
340
  # If the supplied block takes a single argument,
399
341
  # yield an <tt>SQL::VirtualRow</tt> instance to the block
400
342
  # argument. Otherwise, evaluate the block in the context of a
@@ -441,11 +383,6 @@ module Sequel
441
383
  private_class_method :adapter_method, :def_adapter_method
442
384
 
443
385
  require(%w"deprecated sql connection_pool exceptions dataset database timezones ast_transformer version")
444
- if !defined?(::SEQUEL_NO_CORE_EXTENSIONS) && !ENV.has_key?('SEQUEL_NO_CORE_EXTENSIONS')
445
- # :nocov:
446
- require(:deprecated_core_extensions)
447
- # :nocov:
448
- end
449
386
 
450
387
  # Add the database adapter class methods to Sequel via metaprogramming
451
388
  def_adapter_method(*Database::ADAPTERS)