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
@@ -103,9 +103,6 @@ module Sequel
103
103
  #
104
104
  # album.from_xml(xml, :associations=>{:artist=>{:fields=>%w'id name', :associations=>:tags}})
105
105
  #
106
- # If the xml is trusted and should be allowed to set all column and association
107
- # values, you can use the :all_columns and :all_associations options.
108
- #
109
106
  # Usage:
110
107
  #
111
108
  # # Add XML output capability to all model subclass instances (called before loading subclasses)
@@ -130,10 +127,7 @@ module Sequel
130
127
 
131
128
  # Return an array of instances of this class based on
132
129
  # the provided XML.
133
- def array_from_xml(xml, opts={})
134
- if opts[:all_associations] || opts[:all_columns]
135
- Sequel::Deprecation.deprecate("The array_from_xml :all_associations and :all_columns", 'You need to explicitly specify the associations and columns via the :associations and :fields options')
136
- end
130
+ def array_from_xml(xml, opts=OPTS)
137
131
  node = Nokogiri::XML(xml).children.first
138
132
  unless node
139
133
  raise Error, "Malformed XML used"
@@ -143,24 +137,21 @@ module Sequel
143
137
 
144
138
  # Return an instance of this class based on the provided
145
139
  # XML.
146
- def from_xml(xml, opts={})
147
- if opts[:all_associations] || opts[:all_columns]
148
- Sequel::Deprecation.deprecate("The from_xml :all_associations and :all_columns", 'You need to explicitly specify the associations and columns via the :associations and :fields options')
149
- end
140
+ def from_xml(xml, opts=OPTS)
150
141
  from_xml_node(Nokogiri::XML(xml).children.first, opts)
151
142
  end
152
143
 
153
144
  # Return an instance of this class based on the given
154
145
  # XML node, which should be Nokogiri::XML::Node instance.
155
146
  # This should probably not be used directly by user code.
156
- def from_xml_node(parent, opts={})
147
+ def from_xml_node(parent, opts=OPTS)
157
148
  new.from_xml_node(parent, opts)
158
149
  end
159
150
 
160
151
  # Return an appropriate Nokogiri::XML::Builder instance
161
152
  # used to create the XML. This should probably not be used
162
153
  # directly by user code.
163
- def xml_builder(opts={})
154
+ def xml_builder(opts=OPTS)
164
155
  if opts[:builder]
165
156
  opts[:builder]
166
157
  else
@@ -177,7 +168,7 @@ module Sequel
177
168
  # Return a proc (or any other object that responds to []),
178
169
  # used for formatting XML tag names when serializing to XML.
179
170
  # This should probably not be used directly by user code.
180
- def xml_deserialize_name_proc(opts={})
171
+ def xml_deserialize_name_proc(opts=OPTS)
181
172
  if opts[:name_proc]
182
173
  opts[:name_proc]
183
174
  elsif opts[:underscore]
@@ -190,7 +181,7 @@ module Sequel
190
181
  # Return a proc (or any other object that responds to []),
191
182
  # used for formatting XML tag names when serializing to XML.
192
183
  # This should probably not be used directly by user code.
193
- def xml_serialize_name_proc(opts={})
184
+ def xml_serialize_name_proc(opts=OPTS)
194
185
  pr = if opts[:name_proc]
195
186
  opts[:name_proc]
196
187
  elsif opts[:dasherize]
@@ -216,10 +207,7 @@ module Sequel
216
207
  # :underscore :: Sets the :name_proc option to one that calls +underscore+
217
208
  # on the input string. Requires that you load the inflector
218
209
  # extension or another library that adds String#underscore.
219
- def from_xml(xml, opts={})
220
- if opts[:all_associations] || opts[:all_columns]
221
- Sequel::Deprecation.deprecate("The from_xml :all_associations and :all_columns", 'You need to explicitly specify the associations and columns via the :associations and :fields options')
222
- end
210
+ def from_xml(xml, opts=OPTS)
223
211
  from_xml_node(Nokogiri::XML(xml).children.first, opts)
224
212
  end
225
213
 
@@ -228,22 +216,12 @@ module Sequel
228
216
  # By default, just calls set with a hash created from the content of the node.
229
217
  #
230
218
  # Options:
231
- # :all_associations :: Indicates that all associations supported by the model should be tried.
232
- # This option also cascades to associations if used. It is better to use the
233
- # :associations option instead of this option. This option only exists for
234
- # backwards compatibility.
235
- # :all_columns :: Overrides the setting logic allowing all setter methods be used,
236
- # even if access to the setter method is restricted.
237
- # This option cascades to associations if used, and can be reset in those associations
238
- # using the :all_columns=>false or :fields options. This option is considered a
239
- # security risk, and only exists for backwards compatibility. It is better to use
240
- # the :fields option appropriately instead of this option, or no option at all.
241
219
  # :associations :: Indicates that the associations cache should be updated by creating
242
220
  # a new associated object using data from the hash. Should be a Symbol
243
221
  # for a single association, an array of symbols for multiple associations,
244
222
  # or a hash with symbol keys and dependent association option hash values.
245
223
  # :fields :: Changes the behavior to call set_fields using the provided fields, instead of calling set.
246
- def from_xml_node(parent, opts={})
224
+ def from_xml_node(parent, opts=OPTS)
247
225
  unless parent
248
226
  raise Error, "Malformed XML used"
249
227
  end
@@ -251,14 +229,7 @@ module Sequel
251
229
  raise Error, "XML consisting of just text nodes used"
252
230
  end
253
231
 
254
- unless assocs = opts[:associations]
255
- if opts[:all_associations]
256
- assocs = {}
257
- model.associations.each{|v| assocs[v] = {:all_associations=>true}}
258
- end
259
- end
260
-
261
- if assocs
232
+ if assocs = opts[:associations]
262
233
  assocs = case assocs
263
234
  when Symbol
264
235
  {assocs=>{}}
@@ -272,18 +243,13 @@ module Sequel
272
243
  raise Error, ":associations should be Symbol, Array, or Hash if present"
273
244
  end
274
245
 
275
- if opts[:all_columns]
276
- assocs.each_value do |assoc_opts|
277
- assoc_opts[:all_columns] = true unless assoc_opts.has_key?(:fields) || assoc_opts.has_key?(:all_columns)
278
- end
279
- end
280
-
281
246
  assocs_hash = {}
282
247
  assocs.each{|k,v| assocs_hash[k.to_s] = v}
283
248
  assocs_present = []
284
249
  end
285
250
 
286
251
  hash = {}
252
+ populate_associations = {}
287
253
  name_proc = model.xml_deserialize_name_proc(opts)
288
254
  parent.children.each do |node|
289
255
  next if node.is_a?(Nokogiri::XML::Text)
@@ -303,7 +269,7 @@ module Sequel
303
269
  raise Error, "Association #{assoc} is not defined for #{model}"
304
270
  end
305
271
 
306
- associations[assoc] = if r.returns_array?
272
+ populate_associations[assoc] = if r.returns_array?
307
273
  node.children.reject{|c| c.is_a?(Nokogiri::XML::Text)}.map{|c| r.associated_class.from_xml_node(c, assoc_opts)}
308
274
  else
309
275
  r.associated_class.from_xml_node(node, assoc_opts)
@@ -313,19 +279,14 @@ module Sequel
313
279
 
314
280
  if fields = opts[:fields]
315
281
  set_fields(hash, fields, opts)
316
- elsif opts[:all_columns]
317
- meths = methods.collect{|x| x.to_s}.grep(Model::SETTER_METHOD_REGEXP) - Model::RESTRICTED_SETTER_METHODS
318
- hash.each do |k, v|
319
- if meths.include?(setter_meth = "#{k}=")
320
- send(setter_meth, v)
321
- else
322
- raise Error, "Entry in XML does not have a matching setter method: #{k}"
323
- end
324
- end
325
282
  else
326
283
  set(hash)
327
284
  end
328
285
 
286
+ populate_associations.each do |assoc, values|
287
+ associations[assoc] = values
288
+ end
289
+
329
290
  self
330
291
  end
331
292
 
@@ -367,7 +328,7 @@ module Sequel
367
328
  # an array of objects using Model.to_xml or Dataset#to_xml.
368
329
  # :types :: Set to true to include type information for
369
330
  # all of the columns, pulled from the db_schema.
370
- def to_xml(opts={})
331
+ def to_xml(opts=OPTS)
371
332
  vals = values
372
333
  types = opts[:types]
373
334
  inc = opts[:include]
@@ -406,7 +367,7 @@ module Sequel
406
367
 
407
368
  # Handle associated objects and virtual attributes when creating
408
369
  # the xml.
409
- def to_xml_include(node, i, opts={})
370
+ def to_xml_include(node, i, opts=OPTS)
410
371
  name_proc = model.xml_serialize_name_proc(opts)
411
372
  objs = send(i)
412
373
  if objs.is_a?(Array) && objs.all?{|x| x.is_a?(Sequel::Model)}
@@ -426,7 +387,7 @@ module Sequel
426
387
  # this dataset. Takes all of the options available to Model#to_xml,
427
388
  # as well as the :array_root_name option for specifying the name of
428
389
  # the root node that contains the nodes for all of the instances.
429
- def to_xml(opts={})
390
+ def to_xml(opts=OPTS)
430
391
  raise(Sequel::Error, "Dataset#to_xml") unless row_proc
431
392
  x = model.xml_builder(opts)
432
393
  name_proc = model.xml_serialize_name_proc(opts)
@@ -93,15 +93,6 @@ module Sequel
93
93
  # Do not call this method with untrusted input, as that can result in
94
94
  # arbitrary code execution.
95
95
  def to_s_method(meth, args=:self) # :nodoc:
96
- # REMOVE40
97
- class_eval(<<-END, __FILE__, __LINE__+1)
98
- def to_s(ds)
99
- Sequel::Deprecation.deprecate('SQL::Expression#to_s', "Please switch to using Dataset#literal to literalize expressions")
100
- s = ''
101
- to_s_append(ds, s)
102
- s
103
- end
104
- END
105
96
  class_eval("def to_s_append(ds, sql) ds.#{meth}_append(sql, #{args}) end", __FILE__, __LINE__)
106
97
  end
107
98
  end
@@ -331,7 +322,7 @@ module Sequel
331
322
  #
332
323
  # Sequel.asc(:a) # a ASC
333
324
  # Sequel.asc(:b, :nulls=>:last) # b ASC NULLS LAST
334
- def asc(arg, opts={})
325
+ def asc(arg, opts=OPTS)
335
326
  SQL::OrderedExpression.new(arg, false, opts)
336
327
  end
337
328
 
@@ -392,6 +383,16 @@ module Sequel
392
383
  SQL::EmulatedFunction.new(:char_length, arg)
393
384
  end
394
385
 
386
+ # Do a deep qualification of the argument using the qualifier. This recurses into
387
+ # nested structures.
388
+ #
389
+ # Sequel.deep_qualify(:table, :column) # "table"."column"
390
+ # Sequel.deep_qualify(:table, Sequel.+(:column, 1)) # "table"."column" + 1
391
+ # Sequel.deep_qualify(:table, Sequel.like(:a, 'b')) # "table"."a" LIKE 'b' ESCAPE '\'
392
+ def deep_qualify(qualifier, expr)
393
+ Sequel::Qualifier.new(Sequel, qualifier).transform(expr)
394
+ end
395
+
395
396
  # Return a delayed evaluation that uses the passed block. This is used
396
397
  # to delay evaluations of the code to runtime. For example, with
397
398
  # the following code:
@@ -422,7 +423,7 @@ module Sequel
422
423
  #
423
424
  # Sequel.desc(:a) # b DESC
424
425
  # Sequel.desc(:b, :nulls=>:first) # b DESC NULLS FIRST
425
- def desc(arg, opts={})
426
+ def desc(arg, opts=OPTS)
426
427
  SQL::OrderedExpression.new(arg, true, opts)
427
428
  end
428
429
 
@@ -624,6 +625,8 @@ module Sequel
624
625
  # Sequel.subscript(:array, 1) # array[1]
625
626
  # Sequel.subscript(:array, 1, 2) # array[1, 2]
626
627
  # Sequel.subscript(:array, [1, 2]) # array[1, 2]
628
+ # Sequel.subscript(:array, 1..2) # array[1:2]
629
+ # Sequel.subscript(:array, 1...3) # array[1:2]
627
630
  def subscript(exp, *subs)
628
631
  SQL::Subscript.new(exp, subs.flatten)
629
632
  end
@@ -743,10 +746,6 @@ module Sequel
743
746
  end
744
747
  end
745
748
 
746
- # Only exists for backwards compatibility, ignore it.
747
- module NoBooleanInputMethods
748
- end
749
-
750
749
  # This module includes the standard mathematical methods (+, -, *, and /)
751
750
  # that are defined on objects that can be used in a numeric context in SQL
752
751
  # (+Symbol+, +LiteralString+, and +SQL::GenericExpression+).
@@ -828,7 +827,7 @@ module Sequel
828
827
  # :nulls :: Set to :first to use NULLS FIRST (so NULL values are ordered
829
828
  # before other values), or :last to use NULLS LAST (so NULL values
830
829
  # are ordered after other values).
831
- def asc(opts={})
830
+ def asc(opts=OPTS)
832
831
  OrderedExpression.new(self, false, opts)
833
832
  end
834
833
 
@@ -838,7 +837,7 @@ module Sequel
838
837
  # :nulls :: Set to :first to use NULLS FIRST (so NULL values are ordered
839
838
  # before other values), or :last to use NULLS LAST (so NULL values
840
839
  # are ordered after other values).
841
- def desc(opts={})
840
+ def desc(opts=OPTS)
842
841
  OrderedExpression.new(self, true, opts)
843
842
  end
844
843
  end
@@ -908,6 +907,8 @@ module Sequel
908
907
  # :array.sql_subscript(1) # array[1]
909
908
  # :array.sql_subscript(1, 2) # array[1, 2]
910
909
  # :array.sql_subscript([1, 2]) # array[1, 2]
910
+ # :array.sql_subscript(:array, 1..2) # array[1:2]
911
+ # :array.sql_subscript(:array, 1...3) # array[1:2]
911
912
  def sql_subscript(*sub)
912
913
  Subscript.new(self, sub.flatten)
913
914
  end
@@ -1361,7 +1362,7 @@ module Sequel
1361
1362
  # Options:
1362
1363
  #
1363
1364
  # :nulls :: Can be :first/:last for NULLS FIRST/LAST.
1364
- def initialize(expression, descending = true, opts={})
1365
+ def initialize(expression, descending = true, opts=OPTS)
1365
1366
  @expression, @descending, @nulls = expression, descending, opts[:nulls]
1366
1367
  end
1367
1368
 
@@ -1502,9 +1503,6 @@ module Sequel
1502
1503
  class ValueList < ::Array
1503
1504
  end
1504
1505
 
1505
- # Deprecated name for +ValueList+, used for backwards compatibility
1506
- SQLArray = ValueList
1507
-
1508
1506
  # The purpose of the +VirtualRow+ class is to allow the easy creation of SQL identifiers and functions
1509
1507
  # without relying on methods defined on +Symbol+. This is useful if another library defines
1510
1508
  # the methods defined by Sequel, if you are running on ruby 1.9, or if you are not using the
@@ -1654,7 +1652,7 @@ module Sequel
1654
1652
  attr_reader :opts
1655
1653
 
1656
1654
  # Set the options to the options given
1657
- def initialize(opts={})
1655
+ def initialize(opts=OPTS)
1658
1656
  @opts = opts
1659
1657
  end
1660
1658
 
@@ -1,9 +1,9 @@
1
1
  module Sequel
2
2
  # The major version of Sequel. Only bumped for major changes.
3
- MAJOR = 3
3
+ MAJOR = 4
4
4
  # The minor version of Sequel. Bumped for every non-patch level
5
5
  # release, generally around once a month.
6
- MINOR = 48
6
+ MINOR = 0
7
7
  # The tiny version of Sequel. Usually 0, only bumped for bugfix
8
8
  # releases that fix regressions from previous versions.
9
9
  TINY = 0
@@ -1,23 +1,14 @@
1
- #!/usr/bin/env ruby
2
- #Author: Roy L Zuo (roylzuo at gmail dot com)
3
- #Description:
1
+ SEQUEL_ADAPTER_TEST = :db2
4
2
 
5
3
  require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
6
4
 
7
- require ENV['SEQUEL_DB2_SPEC_REQUIRE'] if ENV['SEQUEL_DB2_SPEC_REQUIRE']
8
-
9
- unless defined?(DB2_DB)
10
- DB2_DB = Sequel.connect(ENV['SEQUEL_DB2_SPEC_DB']||DB2_URL)
11
- end
12
-
13
- if DB2_DB.table_exists?(:test)
14
- DB2_DB.drop_table :test
5
+ if DB.table_exists?(:test)
6
+ DB.drop_table(:test)
15
7
  end
16
- INTEGRATION_DB = DB2_DB unless defined?(INTEGRATION_DB)
17
8
 
18
9
  describe Sequel::Database do
19
10
  before do
20
- @db = DB2_DB
11
+ @db = DB
21
12
  @db.create_table(:test){String :a}
22
13
  @ds = @db[:test]
23
14
  end
@@ -40,20 +31,20 @@ end
40
31
  describe "Simple Dataset operations" do
41
32
  before(:all) do
42
33
  Sequel::DB2.use_clob_as_blob = false
43
- DB2_DB.create_table!(:items) do
34
+ DB.create_table!(:items) do
44
35
  Integer :id, :primary_key => true
45
36
  Integer :number
46
37
  column :bin_string, 'varchar(20) for bit data'
47
38
  column :bin_blob, 'blob'
48
39
  end
49
- @ds = DB2_DB[:items]
40
+ @ds = DB[:items]
50
41
  end
51
42
  after(:each) do
52
43
  @ds.delete
53
44
  end
54
45
  after(:all) do
55
46
  Sequel::DB2.use_clob_as_blob = true
56
- DB2_DB.drop_table(:items)
47
+ DB.drop_table(:items)
57
48
  end
58
49
 
59
50
  specify "should insert with a primary key specified" do
@@ -70,7 +61,7 @@ end
70
61
 
71
62
  describe Sequel::Database do
72
63
  before do
73
- @db = DB2_DB
64
+ @db = DB
74
65
  end
75
66
  after do
76
67
  @db.drop_table(:items)
@@ -87,7 +78,7 @@ end
87
78
 
88
79
  describe "Sequel::IBMDB.convert_smallint_to_bool" do
89
80
  before do
90
- @db = DB2_DB
81
+ @db = DB
91
82
  @db.create_table!(:booltest){column :b, 'smallint'; column :i, 'integer'}
92
83
  @ds = @db[:booltest]
93
84
  end
@@ -133,22 +124,22 @@ describe "Sequel::IBMDB.convert_smallint_to_bool" do
133
124
  @ds << {:b=>0, :i=>0}
134
125
  @ds.all.should == [{:b=>0, :i=>0}]
135
126
  end
136
- end if DB2_DB.adapter_scheme == :ibmdb
127
+ end if DB.adapter_scheme == :ibmdb
137
128
 
138
129
  describe "Simple Dataset operations in transactions" do
139
130
  before do
140
- DB2_DB.create_table!(:items_insert_in_transaction) do
131
+ DB.create_table!(:items_insert_in_transaction) do
141
132
  Integer :id, :primary_key => true
142
133
  integer :number
143
134
  end
144
- @ds = DB2_DB[:items_insert_in_transaction]
135
+ @ds = DB[:items_insert_in_transaction]
145
136
  end
146
137
  after do
147
- DB2_DB.drop_table(:items_insert_in_transaction)
138
+ DB.drop_table(:items_insert_in_transaction)
148
139
  end
149
140
 
150
141
  specify "should insert correctly with a primary key specified inside a transaction" do
151
- DB2_DB.transaction do
142
+ DB.transaction do
152
143
  @ds.insert(:id=>100, :number=>20)
153
144
  @ds.count.should == 1
154
145
  @ds.order(:id).all.should == [{:id=>100, :number=>20}]
@@ -1,41 +1,37 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
1
+ SEQUEL_ADAPTER_TEST = :firebird
2
2
 
3
- unless defined?(FIREBIRD_DB)
4
- FIREBIRD_URL = 'firebird://sysdba:masterkey@localhost/reality_spec' unless defined? FIREBIRD_URL
5
- FIREBIRD_DB = Sequel.connect(ENV['SEQUEL_FB_SPEC_DB']||FIREBIRD_URL)
6
- end
7
- INTEGRATION_DB = FIREBIRD_DB unless defined?(INTEGRATION_DB)
3
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
8
4
 
9
- def FIREBIRD_DB.sqls
5
+ def DB.sqls
10
6
  (@sqls ||= [])
11
7
  end
12
8
  logger = Object.new
13
9
  def logger.method_missing(m, msg)
14
- FIREBIRD_DB.sqls.push(msg)
10
+ DB.sqls.push(msg)
15
11
  end
16
- FIREBIRD_DB.loggers = [logger]
12
+ DB.loggers = [logger]
17
13
 
18
- FIREBIRD_DB.create_table! :test do
14
+ DB.create_table! :test do
19
15
  varchar :name, :size => 50
20
16
  integer :val, :index => true
21
17
  end
22
18
 
23
- FIREBIRD_DB.create_table! :test2 do
19
+ DB.create_table! :test2 do
24
20
  integer :val
25
21
  timestamp :time_stamp
26
22
  end
27
23
 
28
- FIREBIRD_DB.create_table! :test3 do
24
+ DB.create_table! :test3 do
29
25
  integer :val
30
26
  timestamp :time_stamp
31
27
  end
32
28
 
33
- FIREBIRD_DB.create_table! :test5 do
29
+ DB.create_table! :test5 do
34
30
  primary_key :xid
35
31
  integer :val
36
32
  end
37
33
 
38
- FIREBIRD_DB.create_table! :test6 do
34
+ DB.create_table! :test6 do
39
35
  primary_key :xid
40
36
  blob :val
41
37
  String :val2
@@ -45,7 +41,7 @@ end
45
41
 
46
42
  describe "A Firebird database" do
47
43
  before do
48
- @db = FIREBIRD_DB
44
+ @db = DB
49
45
  end
50
46
 
51
47
  specify "should provide disconnect functionality" do
@@ -62,7 +58,7 @@ end
62
58
 
63
59
  describe "A Firebird dataset" do
64
60
  before do
65
- @d = FIREBIRD_DB[:test]
61
+ @d = DB[:test]
66
62
  @d.delete # remove all records
67
63
  @d.quote_identifiers = true
68
64
  end
@@ -176,7 +172,7 @@ describe "A Firebird dataset" do
176
172
  end
177
173
 
178
174
  specify "should support transactions" do
179
- FIREBIRD_DB.transaction do
175
+ DB.transaction do
180
176
  @d << {:name => 'abc', :val => 1}
181
177
  end
182
178
 
@@ -184,14 +180,14 @@ describe "A Firebird dataset" do
184
180
  end
185
181
 
186
182
  specify "should have #transaction yield the connection" do
187
- FIREBIRD_DB.transaction do |conn|
183
+ DB.transaction do |conn|
188
184
  conn.should_not == nil
189
185
  end
190
186
  end
191
187
 
192
188
  specify "should correctly rollback transactions" do
193
189
  proc do
194
- FIREBIRD_DB.transaction do
190
+ DB.transaction do
195
191
  @d << {:name => 'abc', :val => 1}
196
192
  raise RuntimeError, 'asdf'
197
193
  end
@@ -201,7 +197,7 @@ describe "A Firebird dataset" do
201
197
  end
202
198
 
203
199
  specify "should handle returning inside of the block by committing" do
204
- def FIREBIRD_DB.ret_commit
200
+ def DB.ret_commit
205
201
  transaction do
206
202
  self[:test] << {:name => 'abc'}
207
203
  return
@@ -209,12 +205,12 @@ describe "A Firebird dataset" do
209
205
  end
210
206
  end
211
207
  @d.count.should == 0
212
- FIREBIRD_DB.ret_commit
208
+ DB.ret_commit
213
209
  @d.count.should == 1
214
- FIREBIRD_DB.ret_commit
210
+ DB.ret_commit
215
211
  @d.count.should == 2
216
212
  proc do
217
- FIREBIRD_DB.transaction do
213
+ DB.transaction do
218
214
  raise RuntimeError, 'asdf'
219
215
  end
220
216
  end.should raise_error(RuntimeError)
@@ -223,7 +219,7 @@ describe "A Firebird dataset" do
223
219
  end
224
220
 
225
221
  specify "should quote and upcase reserved keywords" do
226
- @d = FIREBIRD_DB[:testing]
222
+ @d = DB[:testing]
227
223
  @d.quote_identifiers = true
228
224
  @d.select(:select).sql.should == \
229
225
  'SELECT "SELECT" FROM "TESTING"'
@@ -232,7 +228,7 @@ end
232
228
 
233
229
  describe "A Firebird dataset with a timestamp field" do
234
230
  before do
235
- @d = FIREBIRD_DB[:test3]
231
+ @d = DB[:test3]
236
232
  @d.delete
237
233
  end
238
234
 
@@ -246,7 +242,7 @@ end
246
242
 
247
243
  describe "A Firebird database" do
248
244
  before do
249
- @db = FIREBIRD_DB
245
+ @db = DB
250
246
  @db.drop_table?(:posts)
251
247
  @db.sqls.clear
252
248
  end
@@ -369,7 +365,7 @@ end
369
365
 
370
366
  describe "Postgres::Dataset#insert" do
371
367
  before do
372
- @ds = FIREBIRD_DB[:test5]
368
+ @ds = DB[:test5]
373
369
  @ds.delete
374
370
  end
375
371
 
@@ -395,7 +391,7 @@ describe "Postgres::Dataset#insert" do
395
391
  end
396
392
 
397
393
  specify "should return nil if the table has no primary key" do
398
- ds = FIREBIRD_DB[:test]
394
+ ds = DB[:test]
399
395
  ds.delete
400
396
  ds.insert(:name=>'a').should == nil
401
397
  end
@@ -403,7 +399,7 @@ end
403
399
 
404
400
  describe "Postgres::Dataset#insert" do
405
401
  before do
406
- @ds = FIREBIRD_DB[:test6]
402
+ @ds = DB[:test6]
407
403
  @ds.delete
408
404
  end
409
405