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
@@ -210,7 +210,7 @@ module Sequel
210
210
  end
211
211
 
212
212
  # Execute the given SQL on the database.
213
- def execute(sql, opts={}, &block)
213
+ def execute(sql, opts=OPTS, &block)
214
214
  if sql.is_a?(Symbol)
215
215
  execute_prepared_statement(sql, opts, &block)
216
216
  else
@@ -222,7 +222,7 @@ module Sequel
222
222
 
223
223
  # Execute the given SQL on the database, returning the last inserted
224
224
  # identity value.
225
- def execute_insert(sql, opts={})
225
+ def execute_insert(sql, opts=OPTS)
226
226
  synchronize(opts[:server]) do |c|
227
227
  if sql.is_a?(Symbol)
228
228
  execute_prepared_statement(sql, opts)
@@ -304,14 +304,14 @@ module Sequel
304
304
 
305
305
  # IBM_DB uses an autocommit setting instead of sending SQL queries.
306
306
  # So starting a transaction just turns autocommit off.
307
- def begin_transaction(conn, opts={})
307
+ def begin_transaction(conn, opts=OPTS)
308
308
  log_yield(TRANSACTION_BEGIN){conn.autocommit = false}
309
309
  set_transaction_isolation(conn, opts)
310
310
  end
311
311
 
312
312
  # This commits transaction in progress on the
313
313
  # connection and sets autocommit back on.
314
- def commit_transaction(conn, opts={})
314
+ def commit_transaction(conn, opts=OPTS)
315
315
  log_yield(TRANSACTION_COMMIT){conn.commit}
316
316
  end
317
317
 
@@ -355,7 +355,7 @@ module Sequel
355
355
 
356
356
  # This rolls back the transaction in progress on the
357
357
  # connection and sets autocommit back on.
358
- def rollback_transaction(conn, opts={})
358
+ def rollback_transaction(conn, opts=OPTS)
359
359
  log_yield(TRANSACTION_ROLLBACK){conn.rollback}
360
360
  end
361
361
 
@@ -392,17 +392,17 @@ module Sequel
392
392
 
393
393
  private
394
394
  # Execute the prepared statement with arguments instead of the given SQL.
395
- def execute(sql, opts={}, &block)
395
+ def execute(sql, opts=OPTS, &block)
396
396
  super(prepared_statement_name, {:arguments=>bind_arguments}.merge(opts), &block)
397
397
  end
398
398
 
399
399
  # Execute the prepared statment with arguments instead of the given SQL.
400
- def execute_dui(sql, opts={}, &block)
400
+ def execute_dui(sql, opts=OPTS, &block)
401
401
  super(prepared_statement_name, {:arguments=>bind_arguments}.merge(opts), &block)
402
402
  end
403
403
 
404
404
  # Execute the prepared statement with arguments instead of the given SQL.
405
- def execute_insert(sql, opts={}, &block)
405
+ def execute_insert(sql, opts=OPTS, &block)
406
406
  super(prepared_statement_name, {:arguments=>bind_arguments}.merge(opts), &block)
407
407
  end
408
408
 
@@ -14,21 +14,13 @@ module Sequel
14
14
  end
15
15
 
16
16
  # Returns number of rows affected
17
- def execute_dui(sql, opts={})
17
+ def execute_dui(sql, opts=OPTS)
18
18
  synchronize(opts[:server]){|c| log_yield(sql){c.immediate(sql)}}
19
19
  end
20
- def do(*a, &block)
21
- Sequel::Deprecation.deprecate('Database#do', 'Please use Database#execute_dui')
22
- execute_dui(*a, &block)
23
- end
24
20
 
25
- def execute(sql, opts={})
21
+ def execute(sql, opts=OPTS)
26
22
  synchronize(opts[:server]){|c| yield log_yield(sql){c.cursor(sql)}}
27
23
  end
28
- def query(*a, &block)
29
- Sequel::Deprecation.deprecate('Database#query', 'Please use Database#execute')
30
- execute(*a, &block)
31
- end
32
24
  end
33
25
 
34
26
  class Dataset < Sequel::Dataset
@@ -179,7 +179,7 @@ module Sequel
179
179
 
180
180
  # Execute the given stored procedure with the give name. If a block is
181
181
  # given, the stored procedure should return rows.
182
- def call_sproc(name, opts = {})
182
+ def call_sproc(name, opts = OPTS)
183
183
  args = opts[:args] || []
184
184
  sql = "{call #{name}(#{args.map{'?'}.join(',')})}"
185
185
  synchronize(opts[:server]) do |conn|
@@ -252,7 +252,7 @@ module Sequel
252
252
 
253
253
  # Execute the given SQL. If a block is given, if should be a SELECT
254
254
  # statement or something else that returns rows.
255
- def execute(sql, opts={}, &block)
255
+ def execute(sql, opts=OPTS, &block)
256
256
  return call_sproc(sql, opts, &block) if opts[:sproc]
257
257
  return execute_prepared_statement(sql, opts, &block) if [Symbol, Dataset].any?{|c| sql.is_a?(c)}
258
258
  synchronize(opts[:server]) do |conn|
@@ -277,18 +277,18 @@ module Sequel
277
277
 
278
278
  # Execute the given DDL SQL, which should not return any
279
279
  # values or rows.
280
- def execute_ddl(sql, opts={})
280
+ def execute_ddl(sql, opts=OPTS)
281
281
  execute(sql, {:type=>:ddl}.merge(opts))
282
282
  end
283
283
 
284
284
  # Execute the given INSERT SQL, returning the last inserted
285
285
  # row id.
286
- def execute_insert(sql, opts={})
286
+ def execute_insert(sql, opts=OPTS)
287
287
  execute(sql, {:type=>:insert}.merge(opts))
288
288
  end
289
289
 
290
290
  # Use the JDBC metadata to get the index information for the table.
291
- def indexes(table, opts={})
291
+ def indexes(table, opts=OPTS)
292
292
  m = output_identifier_meth
293
293
  im = input_identifier_meth
294
294
  schema, table = schema_and_table(table)
@@ -311,7 +311,7 @@ module Sequel
311
311
  end
312
312
 
313
313
  # All tables in this database
314
- def tables(opts={})
314
+ def tables(opts=OPTS)
315
315
  get_tables('TABLE', opts)
316
316
  end
317
317
 
@@ -319,14 +319,14 @@ module Sequel
319
319
  # using the :uri, :url, or :database options. You don't
320
320
  # need to worry about this if you use Sequel.connect
321
321
  # with the JDBC connectrion strings.
322
- def uri(opts={})
322
+ def uri(opts=OPTS)
323
323
  opts = @opts.merge(opts)
324
324
  ur = opts[:uri] || opts[:url] || opts[:database]
325
325
  ur =~ /^\Ajdbc:/ ? ur : "jdbc:#{ur}"
326
326
  end
327
327
 
328
328
  # All views in this database
329
- def views(opts={})
329
+ def views(opts=OPTS)
330
330
  get_tables('VIEW', opts)
331
331
  end
332
332
 
@@ -387,7 +387,7 @@ module Sequel
387
387
  # statement, use that statement instead of creating another.
388
388
  # Otherwise, prepare a new statement for the connection, bind the
389
389
  # variables, and execute it.
390
- def execute_prepared_statement(name, opts={})
390
+ def execute_prepared_statement(name, opts=OPTS)
391
391
  args = opts[:arguments]
392
392
  if name.is_a?(Dataset)
393
393
  ps = name
@@ -561,7 +561,7 @@ module Sequel
561
561
  end
562
562
 
563
563
  # Parse the table schema for the given table.
564
- def schema_parse_table(table, opts={})
564
+ def schema_parse_table(table, opts=OPTS)
565
565
  m = output_identifier_meth(opts[:dataset])
566
566
  im = input_identifier_meth(opts[:dataset])
567
567
  ds = dataset
@@ -585,7 +585,7 @@ module Sequel
585
585
  ts << [m.call(h[:column_name]), s]
586
586
  end
587
587
  if schemas.length > 1
588
- Sequel::Deprecation.deprecate('Schema parsing in the jdbc adapter resulted in columns being returned for a table with the same name in multiple schemas. This will raise an Error starting in Sequel 4. Please explicitly qualify your table with a schema.')
588
+ raise Error, 'Schema parsing in the jdbc adapter resulted in columns being returned for a table with the same name in multiple schemas. Please explicitly qualify your table with a schema.'
589
589
  end
590
590
  ts
591
591
  end
@@ -623,17 +623,17 @@ module Sequel
623
623
 
624
624
  # Execute the prepared SQL using the stored type and
625
625
  # arguments derived from the hash passed to call.
626
- def execute(sql, opts={}, &block)
626
+ def execute(sql, opts=OPTS, &block)
627
627
  super(self, {:arguments=>bind_arguments}.merge(opts), &block)
628
628
  end
629
629
 
630
630
  # Same as execute, explicit due to intricacies of alias and super.
631
- def execute_dui(sql, opts={}, &block)
631
+ def execute_dui(sql, opts=OPTS, &block)
632
632
  super(self, {:arguments=>bind_arguments}.merge(opts), &block)
633
633
  end
634
634
 
635
635
  # Same as execute, explicit due to intricacies of alias and super.
636
- def execute_insert(sql, opts={}, &block)
636
+ def execute_insert(sql, opts=OPTS, &block)
637
637
  super(self, {:arguments=>bind_arguments, :type=>:insert}.merge(opts), &block)
638
638
  end
639
639
  end
@@ -646,17 +646,17 @@ module Sequel
646
646
  private
647
647
 
648
648
  # Execute the database stored procedure with the stored arguments.
649
- def execute(sql, opts={}, &block)
649
+ def execute(sql, opts=OPTS, &block)
650
650
  super(@sproc_name, {:args=>@sproc_args, :sproc=>true}.merge(opts), &block)
651
651
  end
652
652
 
653
653
  # Same as execute, explicit due to intricacies of alias and super.
654
- def execute_dui(sql, opts={}, &block)
654
+ def execute_dui(sql, opts=OPTS, &block)
655
655
  super(@sproc_name, {:args=>@sproc_args, :sproc=>true}.merge(opts), &block)
656
656
  end
657
657
 
658
658
  # Same as execute, explicit due to intricacies of alias and super.
659
- def execute_insert(sql, opts={}, &block)
659
+ def execute_insert(sql, opts=OPTS, &block)
660
660
  super(@sproc_name, {:args=>@sproc_args, :sproc=>true, :type=>:insert}.merge(opts), &block)
661
661
  end
662
662
  end
@@ -20,7 +20,7 @@ module Sequel
20
20
  end
21
21
 
22
22
  # TODO: Fix for AS400
23
- def last_insert_id(conn, opts={})
23
+ def last_insert_id(conn, opts=OPTS)
24
24
  nil
25
25
  end
26
26
 
@@ -32,7 +32,7 @@ module Sequel
32
32
  private
33
33
 
34
34
  # Use JDBC connection's setAutoCommit to false to start transactions
35
- def begin_transaction(conn, opts={})
35
+ def begin_transaction(conn, opts=OPTS)
36
36
  set_transaction_isolation(conn, opts)
37
37
  super
38
38
  end
@@ -16,7 +16,7 @@ module Sequel
16
16
  private
17
17
 
18
18
  # Get the last inserted id using LAST_INSERT_ID().
19
- def last_insert_id(conn, opts={})
19
+ def last_insert_id(conn, opts=OPTS)
20
20
  if stmt = opts[:stmt]
21
21
  rs = stmt.getGeneratedKeys
22
22
  begin
@@ -38,7 +38,7 @@ module Sequel
38
38
  end
39
39
  end
40
40
 
41
- def last_insert_id(conn, opts={})
41
+ def last_insert_id(conn, opts=OPTS)
42
42
  statement(conn) do |stmt|
43
43
  sql = IDENTITY_VAL_LOCAL
44
44
  rs = log_yield(sql){stmt.executeQuery(sql)}
@@ -117,7 +117,7 @@ module Sequel
117
117
  end
118
118
 
119
119
  # Use IDENTITY_VAL_LOCAL() to get the last inserted id.
120
- def last_insert_id(conn, opts={})
120
+ def last_insert_id(conn, opts=OPTS)
121
121
  statement(conn) do |stmt|
122
122
  sql = 'SELECT IDENTITY_VAL_LOCAL() FROM sysibm.sysdummy1'
123
123
  rs = log_yield(sql){stmt.executeQuery(sql)}
@@ -48,7 +48,7 @@ module Sequel
48
48
 
49
49
  # If the :prepare option is given and we aren't in a savepoint,
50
50
  # prepare the transaction for a two-phase commit.
51
- def commit_transaction(conn, opts={})
51
+ def commit_transaction(conn, opts=OPTS)
52
52
  if (s = opts[:prepare]) && _trans(conn)[:savepoint_level] <= 1
53
53
  log_connection_execute(conn, "PREPARE COMMIT #{s}")
54
54
  else
@@ -115,7 +115,7 @@ module Sequel
115
115
  end
116
116
 
117
117
  # Use IDENTITY() to get the last inserted id.
118
- def last_insert_id(conn, opts={})
118
+ def last_insert_id(conn, opts=OPTS)
119
119
  statement(conn) do |stmt|
120
120
  sql = 'SELECT IDENTITY();'
121
121
  rs = log_yield(sql){stmt.executeQuery(sql)}
@@ -65,7 +65,7 @@ module Sequel
65
65
  end
66
66
 
67
67
  # Use IDENTITY() to get the last inserted id.
68
- def last_insert_id(conn, opts={})
68
+ def last_insert_id(conn, opts=OPTS)
69
69
  statement(conn) do |stmt|
70
70
  sql = 'CALL IDENTITY()'
71
71
  rs = log_yield(sql){stmt.executeQuery(sql)}
@@ -13,7 +13,7 @@ module Sequel
13
13
  private
14
14
 
15
15
  # TODO: implement
16
- def last_insert_id(conn, opts={})
16
+ def last_insert_id(conn, opts=OPTS)
17
17
  nil
18
18
  end
19
19
  end
@@ -22,7 +22,7 @@ module Sequel
22
22
  private
23
23
 
24
24
  # Get the last inserted id using SCOPE_IDENTITY().
25
- def last_insert_id(conn, opts={})
25
+ def last_insert_id(conn, opts=OPTS)
26
26
  statement(conn) do |stmt|
27
27
  sql = opts[:prepared] ? ATAT_IDENTITY : SCOPE_IDENTITY
28
28
  rs = log_yield(sql){stmt.executeQuery(sql)}
@@ -33,7 +33,7 @@ module Sequel
33
33
 
34
34
  # Call the generic JDBC version instead of MSSQL version,
35
35
  # since the JDBC version handles primary keys.
36
- def schema_parse_table(table, opts={})
36
+ def schema_parse_table(table, opts=OPTS)
37
37
  jdbc_schema_parse_table(table, opts)
38
38
  end
39
39
 
@@ -27,7 +27,7 @@ module Sequel
27
27
  end
28
28
 
29
29
  # Get the last inserted id using LAST_INSERT_ID().
30
- def last_insert_id(conn, opts={})
30
+ def last_insert_id(conn, opts=OPTS)
31
31
  if stmt = opts[:stmt]
32
32
  rs = stmt.getGeneratedKeys
33
33
  begin
@@ -27,6 +27,10 @@ module Sequel
27
27
  false
28
28
  end
29
29
 
30
+ def disconnect_error?(exception, opts)
31
+ super || exception.message =~ /\AClosed Connection/
32
+ end
33
+
30
34
  def last_insert_id(conn, opts)
31
35
  unless sequence = opts[:sequence]
32
36
  if t = opts[:table]
@@ -105,7 +109,7 @@ module Sequel
105
109
  end
106
110
 
107
111
  def convert_type_oracle_timestamptz(v)
108
- convert_type_oracle_timestamp(db.synchronize{|c| v.timestampValue(c)})
112
+ convert_type_oracle_timestamp(db.synchronize(@opts[:server]){|c| v.timestampValue(c)})
109
113
  end
110
114
 
111
115
  def convert_type_proc(v)
@@ -21,7 +21,7 @@ module Sequel
21
21
  end
22
22
 
23
23
  # See Sequel::Postgres::Adapter#copy_into
24
- def copy_into(table, opts={})
24
+ def copy_into(table, opts=OPTS)
25
25
  data = opts[:data]
26
26
  data = Array(data) if data.is_a?(String)
27
27
 
@@ -58,7 +58,7 @@ module Sequel
58
58
  end
59
59
 
60
60
  # See Sequel::Postgres::Adapter#copy_table
61
- def copy_table(table, opts={})
61
+ def copy_table(table, opts=OPTS)
62
62
  synchronize(opts[:server]) do |conn|
63
63
  copy_manager = org.postgresql.copy.CopyManager.new(conn)
64
64
  copier = copy_manager.copy_out(copy_table_sql(table, opts))
@@ -181,7 +181,7 @@ module Sequel
181
181
 
182
182
  # Literalize strings similar to the native postgres adapter
183
183
  def literal_string_append(sql, v)
184
- sql << APOS << db.synchronize{|c| c.escape_string(v)} << APOS
184
+ sql << APOS << db.synchronize(@opts[:server]){|c| c.escape_string(v)} << APOS
185
185
  end
186
186
  end
187
187
  end
@@ -13,7 +13,7 @@ module Sequel
13
13
 
14
14
  # Swallow pointless exceptions when the foreign key list pragma
15
15
  # doesn't return any rows.
16
- def foreign_key_list(table, opts={})
16
+ def foreign_key_list(table, opts=OPTS)
17
17
  super
18
18
  rescue Sequel::DatabaseError => e
19
19
  raise unless e.message =~ FOREIGN_KEY_ERROR_RE
@@ -22,7 +22,7 @@ module Sequel
22
22
 
23
23
  # Swallow pointless exceptions when the index list pragma
24
24
  # doesn't return any rows.
25
- def indexes(table, opts={})
25
+ def indexes(table, opts=OPTS)
26
26
  super
27
27
  rescue Sequel::DatabaseError => e
28
28
  raise unless e.message =~ FOREIGN_KEY_ERROR_RE
@@ -37,7 +37,7 @@ module Sequel
37
37
  end
38
38
 
39
39
  # Use last_insert_rowid() to get the last inserted id.
40
- def last_insert_id(conn, opts={})
40
+ def last_insert_id(conn, opts=OPTS)
41
41
  statement(conn) do |stmt|
42
42
  rs = stmt.executeQuery(LAST_INSERT_ROWID)
43
43
  rs.next
@@ -44,7 +44,7 @@ module Sequel
44
44
  end
45
45
 
46
46
  # Use JDBC connection's setAutoCommit to false to start transactions
47
- def begin_transaction(conn, opts={})
47
+ def begin_transaction(conn, opts=OPTS)
48
48
  if supports_savepoints?
49
49
  th = _trans(conn)
50
50
  if sps = th[:savepoints]
@@ -62,7 +62,7 @@ module Sequel
62
62
  end
63
63
 
64
64
  # Use JDBC connection's commit method to commit transactions
65
- def commit_transaction(conn, opts={})
65
+ def commit_transaction(conn, opts=OPTS)
66
66
  if supports_savepoints?
67
67
  sps = _trans(conn)[:savepoints]
68
68
  if sps.empty?
@@ -92,7 +92,7 @@ module Sequel
92
92
  end
93
93
 
94
94
  # Use JDBC connection's rollback method to rollback transactions
95
- def rollback_transaction(conn, opts={})
95
+ def rollback_transaction(conn, opts=OPTS)
96
96
  if supports_savepoints?
97
97
  sps = _trans(conn)[:savepoints]
98
98
  if sps.empty?
@@ -142,18 +142,18 @@ module Sequel
142
142
  # Store the sql used for later retrieval with #sqls, and return
143
143
  # the appropriate value using either the #autoid, #fetch, or
144
144
  # #numrows methods.
145
- def execute(sql, opts={}, &block)
145
+ def execute(sql, opts=OPTS, &block)
146
146
  synchronize(opts[:server]){|c| _execute(c, sql, opts, &block)}
147
147
  end
148
148
  alias execute_ddl execute
149
149
 
150
150
  # Store the sql used, and return the value of the #numrows method.
151
- def execute_dui(sql, opts={})
151
+ def execute_dui(sql, opts=OPTS)
152
152
  execute(sql, opts.merge(:meth=>:numrows))
153
153
  end
154
154
 
155
155
  # Store the sql used, and return the value of the #autoid method.
156
- def execute_insert(sql, opts={})
156
+ def execute_insert(sql, opts=OPTS)
157
157
  execute(sql, opts.merge(:meth=>:autoid))
158
158
  end
159
159
 
@@ -186,7 +186,7 @@ module Sequel
186
186
  end
187
187
  end
188
188
 
189
- def _execute(c, sql, opts={}, &block)
189
+ def _execute(c, sql, opts=OPTS, &block)
190
190
  sql += " -- args: #{opts[:arguments].inspect}" if opts[:arguments]
191
191
  sql += " -- #{@opts[:append]}" if @opts[:append]
192
192
  sql += " -- #{c.server.is_a?(Symbol) ? c.server : c.server.inspect}" if c.server != :default
@@ -362,15 +362,15 @@ module Sequel
362
362
 
363
363
  private
364
364
 
365
- def execute(sql, opts={}, &block)
365
+ def execute(sql, opts=OPTS, &block)
366
366
  super(sql, opts.merge(:dataset=>self), &block)
367
367
  end
368
368
 
369
- def execute_dui(sql, opts={}, &block)
369
+ def execute_dui(sql, opts=OPTS, &block)
370
370
  super(sql, opts.merge(:dataset=>self), &block)
371
371
  end
372
372
 
373
- def execute_insert(sql, opts={}, &block)
373
+ def execute_insert(sql, opts=OPTS, &block)
374
374
  super(sql, opts.merge(:dataset=>self), &block)
375
375
  end
376
376
  end