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
@@ -151,12 +151,12 @@ module Sequel
151
151
  end
152
152
 
153
153
  # Return the number of matched rows when executing a delete/update statement.
154
- def execute_dui(sql, opts={})
154
+ def execute_dui(sql, opts=OPTS)
155
155
  execute(sql, opts){|c| return affected_rows(c)}
156
156
  end
157
157
 
158
158
  # Return the last inserted id when executing an insert statement.
159
- def execute_insert(sql, opts={})
159
+ def execute_insert(sql, opts=OPTS)
160
160
  execute(sql, opts){|c| return c.insert_id}
161
161
  end
162
162
 
@@ -347,7 +347,7 @@ module Sequel
347
347
  end
348
348
 
349
349
  # Set the :type option to :select if it hasn't been set.
350
- def execute(sql, opts={}, &block)
350
+ def execute(sql, opts=OPTS, &block)
351
351
  super(sql, {:type=>:select}.merge(opts), &block)
352
352
  end
353
353
 
@@ -51,12 +51,12 @@ module Sequel
51
51
  end
52
52
 
53
53
  # Return the number of matched rows when executing a delete/update statement.
54
- def execute_dui(sql, opts={})
54
+ def execute_dui(sql, opts=OPTS)
55
55
  execute(sql, opts){|c| return c.affected_rows}
56
56
  end
57
57
 
58
58
  # Return the last inserted id when executing an insert statement.
59
- def execute_insert(sql, opts={})
59
+ def execute_insert(sql, opts=OPTS)
60
60
  execute(sql, opts){|c| return c.last_id}
61
61
  end
62
62
 
@@ -155,13 +155,13 @@ module Sequel
155
155
  end
156
156
 
157
157
  # Set the :type option to :select if it hasn't been set.
158
- def execute(sql, opts={}, &block)
158
+ def execute(sql, opts=OPTS, &block)
159
159
  super(sql, {:type=>:select}.merge(opts), &block)
160
160
  end
161
161
 
162
162
  # Handle correct quoting of strings using ::Mysql2::Client#escape.
163
163
  def literal_string_append(sql, v)
164
- sql << "'" << db.synchronize{|c| c.escape(v)} << "'"
164
+ sql << APOS << db.synchronize(@opts[:server]){|c| c.escape(v)} << APOS
165
165
  end
166
166
  end
167
167
  end
@@ -33,7 +33,7 @@ module Sequel
33
33
  c.disconnect
34
34
  end
35
35
 
36
- def execute(sql, opts={})
36
+ def execute(sql, opts=OPTS)
37
37
  synchronize(opts[:server]) do |conn|
38
38
  begin
39
39
  r = log_yield(sql){conn.run(sql)}
@@ -47,7 +47,7 @@ module Sequel
47
47
  end
48
48
  end
49
49
 
50
- def execute_dui(sql, opts={})
50
+ def execute_dui(sql, opts=OPTS)
51
51
  synchronize(opts[:server]) do |conn|
52
52
  begin
53
53
  log_yield(sql){conn.do(sql)}
@@ -56,10 +56,6 @@ module Sequel
56
56
  end
57
57
  end
58
58
  end
59
- def do(*a, &block)
60
- Sequel::Deprecation.deprecate('Database#do', 'Please use Database#execute_dui')
61
- execute_dui(*a, &block)
62
- end
63
59
 
64
60
  private
65
61
 
@@ -11,7 +11,7 @@ module Sequel
11
11
  LAST_INSERT_ID_SQL='SELECT SCOPE_IDENTITY()'.freeze
12
12
 
13
13
  # Return the last inserted identity value.
14
- def execute_insert(sql, opts={})
14
+ def execute_insert(sql, opts=OPTS)
15
15
  synchronize(opts[:server]) do |conn|
16
16
  begin
17
17
  log_yield(sql){conn.do(sql)}
@@ -19,17 +19,13 @@ module Sequel
19
19
  c.disconnect
20
20
  end
21
21
 
22
- def execute(sql, opts={})
22
+ def execute(sql, opts=OPTS)
23
23
  synchronize(opts[:server]) do |conn|
24
24
  r = log_yield(sql){conn.execute(sql)}
25
25
  yield(r) if block_given?
26
26
  r
27
27
  end
28
28
  end
29
- def do(*a, &block)
30
- Sequel::Deprecation.deprecate('Database#do', 'Please use Database#execute')
31
- execute(*a, &block)
32
- end
33
29
  end
34
30
 
35
31
  class Dataset < Sequel::Dataset
@@ -61,21 +61,17 @@ module Sequel
61
61
  nil
62
62
  end
63
63
 
64
- def execute(sql, opts={}, &block)
64
+ def execute(sql, opts=OPTS, &block)
65
65
  _execute(nil, sql, opts, &block)
66
66
  end
67
- def do(*a, &block)
68
- Sequel::Deprecation.deprecate('Database#do', 'Please use Database#execute')
69
- execute_dui(*a, &block)
70
- end
71
67
 
72
- def execute_insert(sql, opts={})
68
+ def execute_insert(sql, opts=OPTS)
73
69
  _execute(:insert, sql, opts)
74
70
  end
75
71
 
76
72
  private
77
73
 
78
- def _execute(type, sql, opts={}, &block)
74
+ def _execute(type, sql, opts=OPTS, &block)
79
75
  synchronize(opts[:server]) do |conn|
80
76
  begin
81
77
  return execute_prepared_statement(conn, type, sql, opts, &block) if sql.is_a?(Symbol)
@@ -214,12 +210,12 @@ module Sequel
214
210
  end
215
211
  end
216
212
 
217
- def begin_transaction(conn, opts={})
213
+ def begin_transaction(conn, opts=OPTS)
218
214
  log_yield(TRANSACTION_BEGIN){conn.autocommit = false}
219
215
  set_transaction_isolation(conn, opts)
220
216
  end
221
217
 
222
- def commit_transaction(conn, opts={})
218
+ def commit_transaction(conn, opts=OPTS)
223
219
  log_yield(TRANSACTION_COMMIT){conn.commit}
224
220
  end
225
221
 
@@ -251,11 +247,11 @@ module Sequel
251
247
  super
252
248
  end
253
249
 
254
- def rollback_transaction(conn, opts={})
250
+ def rollback_transaction(conn, opts=OPTS)
255
251
  log_yield(TRANSACTION_ROLLBACK){conn.rollback}
256
252
  end
257
253
 
258
- def schema_parse_table(table, opts={})
254
+ def schema_parse_table(table, opts=OPTS)
259
255
  schema, table = schema_and_table(table)
260
256
  schema ||= opts[:schema]
261
257
  schema_and_table = if ds = opts[:dataset]
@@ -359,17 +355,17 @@ module Sequel
359
355
 
360
356
  # Run execute_select on the database with the given SQL and the stored
361
357
  # bind arguments.
362
- def execute(sql, opts={}, &block)
358
+ def execute(sql, opts=OPTS, &block)
363
359
  super(prepared_sql, {:arguments=>bind_arguments}.merge(opts), &block)
364
360
  end
365
361
 
366
362
  # Same as execute, explicit due to intricacies of alias and super.
367
- def execute_dui(sql, opts={}, &block)
363
+ def execute_dui(sql, opts=OPTS, &block)
368
364
  super(prepared_sql, {:arguments=>bind_arguments}.merge(opts), &block)
369
365
  end
370
366
 
371
367
  # Same as execute, explicit due to intricacies of alias and super.
372
- def execute_insert(sql, opts={}, &block)
368
+ def execute_insert(sql, opts=OPTS, &block)
373
369
  super(prepared_sql, {:arguments=>bind_arguments}.merge(opts), &block)
374
370
  end
375
371
  end
@@ -381,17 +377,17 @@ module Sequel
381
377
 
382
378
  # Execute the stored prepared statement name and the stored bind
383
379
  # arguments instead of the SQL given.
384
- def execute(sql, opts={}, &block)
380
+ def execute(sql, opts=OPTS, &block)
385
381
  super(prepared_statement_name, opts, &block)
386
382
  end
387
383
 
388
384
  # Same as execute, explicit due to intricacies of alias and super.
389
- def execute_dui(sql, opts={}, &block)
385
+ def execute_dui(sql, opts=OPTS, &block)
390
386
  super(prepared_statement_name, opts, &block)
391
387
  end
392
388
 
393
389
  # Same as execute, explicit due to intricacies of alias and super.
394
- def execute_insert(sql, opts={}, &block)
390
+ def execute_insert(sql, opts=OPTS, &block)
395
391
  super(prepared_statement_name, opts, &block)
396
392
  end
397
393
  end
@@ -133,6 +133,9 @@ module Sequel
133
133
  disconnect ||= !status_ok
134
134
  disconnect ||= e.message =~ DISCONNECT_ERROR_RE
135
135
  disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise
136
+ rescue IOError, Errno::EPIPE, Errno::ECONNRESET => e
137
+ disconnect = true
138
+ raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError))
136
139
  ensure
137
140
  block if status_ok && !disconnect
138
141
  end
@@ -270,12 +273,12 @@ module Sequel
270
273
  def disconnect_connection(conn)
271
274
  begin
272
275
  conn.finish
273
- rescue PGError
276
+ rescue PGError, IOError
274
277
  end
275
278
  end
276
279
 
277
280
  # Execute the given SQL with the given args on an available connection.
278
- def execute(sql, opts={}, &block)
281
+ def execute(sql, opts=OPTS, &block)
279
282
  synchronize(opts[:server]){|conn| check_database_errors{_execute(conn, sql, opts, &block)}}
280
283
  end
281
284
 
@@ -304,7 +307,7 @@ module Sequel
304
307
  # If a block is provided, the method continually yields to the block, one yield
305
308
  # per row. If a block is not provided, a single string is returned with all
306
309
  # of the data.
307
- def copy_table(table, opts={})
310
+ def copy_table(table, opts=OPTS)
308
311
  synchronize(opts[:server]) do |conn|
309
312
  conn.execute(copy_table_sql(table, opts))
310
313
  begin
@@ -344,7 +347,7 @@ module Sequel
344
347
  #
345
348
  # If a block is provided and :data option is not, this will yield to the block repeatedly.
346
349
  # The block should return a string, or nil to signal that it is finished.
347
- def copy_into(table, opts={})
350
+ def copy_into(table, opts=OPTS)
348
351
  data = opts[:data]
349
352
  data = Array(data) if data.is_a?(String)
350
353
 
@@ -397,7 +400,7 @@ module Sequel
397
400
  # * the channel the notification was sent to (as a string)
398
401
  # * the backend pid of the notifier (as an integer),
399
402
  # * and the payload of the notification (as a string or nil).
400
- def listen(channels, opts={}, &block)
403
+ def listen(channels, opts=OPTS, &block)
401
404
  check_database_errors do
402
405
  synchronize(opts[:server]) do |conn|
403
406
  begin
@@ -503,7 +506,7 @@ module Sequel
503
506
  # deallocate that statement first and then prepare this statement.
504
507
  # If a block is given, yield the result, otherwise, return the number
505
508
  # of rows changed.
506
- def execute_prepared_statement(conn, name, opts={}, &block)
509
+ def execute_prepared_statement(conn, name, opts=OPTS, &block)
507
510
  ps = prepared_statement(name)
508
511
  sql = ps.prepared_sql
509
512
  ps_name = name.to_s
@@ -613,7 +616,7 @@ module Sequel
613
616
  #
614
617
  # This is untested with the prepared statement/bound variable support,
615
618
  # and unlikely to work with either.
616
- def use_cursor(opts={})
619
+ def use_cursor(opts=OPTS)
617
620
  clone(:cursor=>{:rows_per_fetch=>1000}.merge(opts))
618
621
  end
619
622
 
@@ -636,23 +639,15 @@ module Sequel
636
639
 
637
640
  private
638
641
 
639
- # PostgreSQL most of the time requires type information for each of
640
- # arguments to a prepared statement. Handle this by allowing the
641
- # named argument to have a __* suffix, with the * being the type.
642
- # In the generated SQL, cast the bound argument to that type to
643
- # elminate ambiguity (and PostgreSQL from raising an exception).
644
642
  def prepared_arg(k)
645
- y, type = k.to_s.split("__")
643
+ y = k
646
644
  if i = prepared_args.index(y)
647
645
  i += 1
648
646
  else
649
647
  prepared_args << y
650
648
  i = prepared_args.length
651
649
  end
652
- if type
653
- Sequel::Deprecation.deprecate('Specifying prepared statement argument types via the __type suffix', "If a manual cast is really need, surround the prepared statement argument in Sequel.cast")
654
- end
655
- LiteralString.new("#{prepared_arg_placeholder}#{i}#{"::#{type}" if type}")
650
+ LiteralString.new("#{prepared_arg_placeholder}#{i}")
656
651
  end
657
652
 
658
653
  # Always assume a prepared argument.
@@ -669,12 +664,12 @@ module Sequel
669
664
  private
670
665
 
671
666
  # Execute the given SQL with the stored bind arguments.
672
- def execute(sql, opts={}, &block)
667
+ def execute(sql, opts=OPTS, &block)
673
668
  super(sql, {:arguments=>bind_arguments}.merge(opts), &block)
674
669
  end
675
670
 
676
671
  # Same as execute, explicit due to intricacies of alias and super.
677
- def execute_dui(sql, opts={}, &block)
672
+ def execute_dui(sql, opts=OPTS, &block)
678
673
  super(sql, {:arguments=>bind_arguments}.merge(opts), &block)
679
674
  end
680
675
  end
@@ -694,18 +689,18 @@ module Sequel
694
689
 
695
690
  # Execute the stored prepared statement name and the stored bind
696
691
  # arguments instead of the SQL given.
697
- def execute(sql, opts={}, &block)
692
+ def execute(sql, opts=OPTS, &block)
698
693
  super(prepared_statement_name, opts, &block)
699
694
  end
700
695
 
701
696
  # Same as execute, explicit due to intricacies of alias and super.
702
- def execute_dui(sql, opts={}, &block)
697
+ def execute_dui(sql, opts=OPTS, &block)
703
698
  super(prepared_statement_name, opts, &block)
704
699
  end
705
700
  end
706
701
 
707
702
  # Execute the given type of statement with the hash of values.
708
- def call(type, bind_vars={}, *values, &block)
703
+ def call(type, bind_vars=OPTS, *values, &block)
709
704
  ps = to_prepared_statement(type, values)
710
705
  ps.extend(BindArgumentMethods)
711
706
  ps.call(bind_vars, &block)
@@ -776,12 +771,12 @@ module Sequel
776
771
 
777
772
  # Use the driver's escape_bytea
778
773
  def literal_blob_append(sql, v)
779
- sql << APOS << db.synchronize{|c| c.escape_bytea(v)} << APOS
774
+ sql << APOS << db.synchronize(@opts[:server]){|c| c.escape_bytea(v)} << APOS
780
775
  end
781
776
 
782
777
  # Use the driver's escape_string
783
778
  def literal_string_append(sql, v)
784
- sql << APOS << db.synchronize{|c| c.escape_string(v)} << APOS
779
+ sql << APOS << db.synchronize(@opts[:server]){|c| c.escape_string(v)} << APOS
785
780
  end
786
781
 
787
782
  # For each row in the result set, yield a hash with column name symbol
@@ -800,7 +795,7 @@ module Sequel
800
795
  end
801
796
  end
802
797
 
803
- if SEQUEL_POSTGRES_USES_PG
798
+ if SEQUEL_POSTGRES_USES_PG && !ENV['NO_SEQUEL_PG']
804
799
  begin
805
800
  require 'sequel_pg'
806
801
  rescue LoadError
@@ -14,7 +14,7 @@ module Sequel
14
14
  :cubrid
15
15
  end
16
16
 
17
- def indexes(table, opts={})
17
+ def indexes(table, opts=OPTS)
18
18
  m = output_identifier_meth
19
19
  m2 = input_identifier_meth
20
20
  indexes = {}
@@ -61,11 +61,11 @@ module Sequel
61
61
  end
62
62
  end
63
63
 
64
- def tables(opts={})
64
+ def tables(opts=OPTS)
65
65
  _tables('CLASS')
66
66
  end
67
67
 
68
- def views(opts={})
68
+ def views(opts=OPTS)
69
69
  _tables('VCLASS')
70
70
  end
71
71
 
@@ -30,7 +30,7 @@ module Sequel
30
30
  alias_method :server_version, :db2_version
31
31
 
32
32
  # Use SYSIBM.SYSCOLUMNS to get the information on the tables.
33
- def schema_parse_table(table, opts = {})
33
+ def schema_parse_table(table, opts = OPTS)
34
34
  m = output_identifier_meth(opts[:dataset])
35
35
  im = input_identifier_meth(opts[:dataset])
36
36
  metadata_dataset.with_sql("SELECT * FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = #{literal(im.call(table))} ORDER BY COLNO").
@@ -61,7 +61,7 @@ module Sequel
61
61
  end
62
62
 
63
63
  # Use SYSCAT.INDEXES to get the indexes for the table
64
- def indexes(table, opts = {})
64
+ def indexes(table, opts = OPTS)
65
65
  m = output_identifier_meth
66
66
  indexes = {}
67
67
  metadata_dataset.
@@ -35,16 +35,16 @@ module Sequel
35
35
  self << restart_sequence_sql(*args)
36
36
  end
37
37
 
38
- def sequences(opts={})
38
+ def sequences(opts=OPTS)
39
39
  ds = self[:"rdb$generators"].server(opts[:server]).filter(:"rdb$system_flag" => 0).select(:"rdb$generator_name")
40
40
  block_given? ? yield(ds) : ds.map{|r| ds.send(:output_identifier, r[:"rdb$generator_name"])}
41
41
  end
42
42
 
43
- def tables(opts={})
43
+ def tables(opts=OPTS)
44
44
  tables_or_views(0, opts)
45
45
  end
46
46
 
47
- def views(opts={})
47
+ def views(opts=OPTS)
48
48
  tables_or_views(1, opts)
49
49
  end
50
50
 
@@ -70,7 +70,7 @@ module Sequel
70
70
  AUTO_INCREMENT
71
71
  end
72
72
 
73
- def create_sequence_sql(name, opts={})
73
+ def create_sequence_sql(name, opts=OPTS)
74
74
  "CREATE SEQUENCE #{quote_identifier(name)}"
75
75
  end
76
76
 
@@ -82,7 +82,7 @@ module Sequel
82
82
  create_statements.each{|sql| execute_ddl(sql)}
83
83
  end
84
84
 
85
- def create_table_sql_list(name, generator, options={})
85
+ def create_table_sql_list(name, generator, options=OPTS)
86
86
  statements = [create_table_sql(name, generator, options)]
87
87
  drop_seq_statement = nil
88
88
  generator.columns.each do |c|
@@ -111,7 +111,7 @@ module Sequel
111
111
  [drop_seq_statement, statements]
112
112
  end
113
113
 
114
- def create_trigger_sql(table, name, definition, opts={})
114
+ def create_trigger_sql(table, name, definition, opts=OPTS)
115
115
  events = opts[:events] ? Array(opts[:events]) : [:insert, :update, :delete]
116
116
  whence = opts[:after] ? 'AFTER' : 'BEFORE'
117
117
  inactive = opts[:inactive] ? 'INACTIVE' : 'ACTIVE'
@@ -133,7 +133,7 @@ module Sequel
133
133
  super
134
134
  end
135
135
 
136
- def restart_sequence_sql(name, opts={})
136
+ def restart_sequence_sql(name, opts=OPTS)
137
137
  seq_name = quote_identifier(name)
138
138
  "ALTER SEQUENCE #{seq_name} RESTART WITH #{opts[:restart_position]}"
139
139
  end