sequel 3.48.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +114 -0
- data/Rakefile +10 -7
- data/doc/association_basics.rdoc +25 -23
- data/doc/code_order.rdoc +7 -0
- data/doc/core_extensions.rdoc +0 -10
- data/doc/object_model.rdoc +4 -1
- data/doc/querying.rdoc +3 -3
- data/doc/release_notes/4.0.0.txt +262 -0
- data/doc/security.rdoc +0 -28
- data/doc/testing.rdoc +8 -14
- data/lib/sequel/adapters/ado.rb +7 -11
- data/lib/sequel/adapters/ado/access.rb +8 -8
- data/lib/sequel/adapters/ado/mssql.rb +4 -4
- data/lib/sequel/adapters/amalgalite.rb +6 -6
- data/lib/sequel/adapters/cubrid.rb +7 -7
- data/lib/sequel/adapters/db2.rb +5 -9
- data/lib/sequel/adapters/dbi.rb +2 -6
- data/lib/sequel/adapters/do.rb +4 -4
- data/lib/sequel/adapters/firebird.rb +4 -4
- data/lib/sequel/adapters/ibmdb.rb +8 -8
- data/lib/sequel/adapters/informix.rb +2 -10
- data/lib/sequel/adapters/jdbc.rb +17 -17
- data/lib/sequel/adapters/jdbc/as400.rb +2 -2
- data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
- data/lib/sequel/adapters/jdbc/db2.rb +1 -1
- data/lib/sequel/adapters/jdbc/derby.rb +1 -1
- data/lib/sequel/adapters/jdbc/h2.rb +2 -2
- data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
- data/lib/sequel/adapters/jdbc/informix.rb +1 -1
- data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
- data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
- data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
- data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
- data/lib/sequel/adapters/mock.rb +7 -7
- data/lib/sequel/adapters/mysql.rb +3 -3
- data/lib/sequel/adapters/mysql2.rb +4 -4
- data/lib/sequel/adapters/odbc.rb +2 -6
- data/lib/sequel/adapters/odbc/mssql.rb +1 -1
- data/lib/sequel/adapters/openbase.rb +1 -5
- data/lib/sequel/adapters/oracle.rb +13 -17
- data/lib/sequel/adapters/postgres.rb +20 -25
- data/lib/sequel/adapters/shared/cubrid.rb +3 -3
- data/lib/sequel/adapters/shared/db2.rb +2 -2
- data/lib/sequel/adapters/shared/firebird.rb +7 -7
- data/lib/sequel/adapters/shared/mssql.rb +9 -9
- data/lib/sequel/adapters/shared/mysql.rb +29 -13
- data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
- data/lib/sequel/adapters/shared/oracle.rb +22 -13
- data/lib/sequel/adapters/shared/postgres.rb +61 -46
- data/lib/sequel/adapters/shared/sqlite.rb +9 -9
- data/lib/sequel/adapters/sqlite.rb +17 -11
- data/lib/sequel/adapters/swift.rb +3 -3
- data/lib/sequel/adapters/swift/mysql.rb +1 -1
- data/lib/sequel/adapters/swift/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +8 -8
- data/lib/sequel/ast_transformer.rb +3 -1
- data/lib/sequel/connection_pool.rb +4 -2
- data/lib/sequel/connection_pool/sharded_single.rb +2 -2
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
- data/lib/sequel/connection_pool/threaded.rb +7 -7
- data/lib/sequel/core.rb +4 -67
- data/lib/sequel/database.rb +1 -0
- data/lib/sequel/database/connecting.rb +2 -8
- data/lib/sequel/database/dataset.rb +2 -7
- data/lib/sequel/database/dataset_defaults.rb +0 -18
- data/lib/sequel/database/features.rb +4 -4
- data/lib/sequel/database/misc.rb +6 -8
- data/lib/sequel/database/query.rb +5 -61
- data/lib/sequel/database/schema_generator.rb +22 -20
- data/lib/sequel/database/schema_methods.rb +48 -20
- data/lib/sequel/database/transactions.rb +7 -17
- data/lib/sequel/dataset.rb +2 -0
- data/lib/sequel/dataset/actions.rb +23 -91
- data/lib/sequel/dataset/features.rb +1 -4
- data/lib/sequel/dataset/graph.rb +3 -47
- data/lib/sequel/dataset/misc.rb +4 -33
- data/lib/sequel/dataset/prepared_statements.rb +3 -1
- data/lib/sequel/dataset/query.rb +116 -240
- data/lib/sequel/dataset/sql.rb +19 -97
- data/lib/sequel/deprecated.rb +0 -16
- data/lib/sequel/exceptions.rb +0 -3
- data/lib/sequel/extensions/_pretty_table.rb +1 -1
- data/lib/sequel/extensions/columns_introspection.rb +1 -12
- data/lib/sequel/extensions/constraint_validations.rb +3 -3
- data/lib/sequel/extensions/core_extensions.rb +0 -9
- data/lib/sequel/extensions/date_arithmetic.rb +1 -2
- data/lib/sequel/extensions/graph_each.rb +11 -0
- data/lib/sequel/extensions/migration.rb +5 -5
- data/lib/sequel/extensions/null_dataset.rb +11 -13
- data/lib/sequel/extensions/pagination.rb +3 -6
- data/lib/sequel/extensions/pg_array.rb +6 -4
- data/lib/sequel/extensions/pg_array_ops.rb +35 -1
- data/lib/sequel/extensions/pg_json.rb +12 -2
- data/lib/sequel/extensions/pg_json_ops.rb +266 -0
- data/lib/sequel/extensions/pg_range.rb +2 -2
- data/lib/sequel/extensions/pg_range_ops.rb +0 -8
- data/lib/sequel/extensions/pg_row.rb +2 -2
- data/lib/sequel/extensions/pretty_table.rb +0 -4
- data/lib/sequel/extensions/query.rb +3 -8
- data/lib/sequel/extensions/schema_caching.rb +0 -7
- data/lib/sequel/extensions/schema_dumper.rb +10 -17
- data/lib/sequel/extensions/select_remove.rb +0 -4
- data/lib/sequel/extensions/set_overrides.rb +28 -0
- data/lib/sequel/extensions/to_dot.rb +6 -10
- data/lib/sequel/model.rb +6 -7
- data/lib/sequel/model/associations.rb +127 -182
- data/lib/sequel/model/base.rb +88 -211
- data/lib/sequel/model/errors.rb +0 -13
- data/lib/sequel/model/plugins.rb +2 -2
- data/lib/sequel/no_core_ext.rb +0 -1
- data/lib/sequel/plugins/after_initialize.rb +11 -17
- data/lib/sequel/plugins/association_autoreloading.rb +1 -47
- data/lib/sequel/plugins/association_dependencies.rb +2 -2
- data/lib/sequel/plugins/auto_validations.rb +2 -8
- data/lib/sequel/plugins/blacklist_security.rb +32 -2
- data/lib/sequel/plugins/caching.rb +1 -1
- data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/composition.rb +10 -8
- data/lib/sequel/plugins/constraint_validations.rb +2 -2
- data/lib/sequel/plugins/dataset_associations.rb +4 -0
- data/lib/sequel/plugins/defaults_setter.rb +8 -6
- data/lib/sequel/plugins/dirty.rb +6 -6
- data/lib/sequel/plugins/force_encoding.rb +13 -8
- data/lib/sequel/plugins/hook_class_methods.rb +1 -7
- data/lib/sequel/plugins/json_serializer.rb +13 -74
- data/lib/sequel/plugins/lazy_attributes.rb +2 -4
- data/lib/sequel/plugins/list.rb +1 -1
- data/lib/sequel/plugins/many_through_many.rb +4 -11
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
- data/lib/sequel/plugins/nested_attributes.rb +1 -1
- data/lib/sequel/plugins/optimistic_locking.rb +3 -5
- data/lib/sequel/plugins/pg_array_associations.rb +453 -0
- data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
- data/lib/sequel/plugins/prepared_statements.rb +1 -1
- data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
- data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
- data/lib/sequel/plugins/rcte_tree.rb +1 -1
- data/lib/sequel/plugins/serialization.rb +5 -4
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +7 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/touch.rb +2 -2
- data/lib/sequel/plugins/tree.rb +1 -1
- data/lib/sequel/plugins/typecast_on_load.rb +19 -4
- data/lib/sequel/plugins/validation_class_methods.rb +0 -30
- data/lib/sequel/plugins/validation_helpers.rb +13 -31
- data/lib/sequel/plugins/xml_serializer.rb +18 -57
- data/lib/sequel/sql.rb +20 -22
- data/lib/sequel/version.rb +2 -2
- data/spec/adapters/db2_spec.rb +14 -23
- data/spec/adapters/firebird_spec.rb +25 -29
- data/spec/adapters/informix_spec.rb +11 -14
- data/spec/adapters/mssql_spec.rb +71 -77
- data/spec/adapters/mysql_spec.rb +165 -172
- data/spec/adapters/oracle_spec.rb +36 -39
- data/spec/adapters/postgres_spec.rb +175 -100
- data/spec/adapters/spec_helper.rb +13 -11
- data/spec/adapters/sqlite_spec.rb +36 -44
- data/spec/core/connection_pool_spec.rb +2 -1
- data/spec/core/database_spec.rb +55 -55
- data/spec/core/dataset_spec.rb +45 -249
- data/spec/core/deprecated_spec.rb +0 -8
- data/spec/core/expression_filters_spec.rb +23 -5
- data/spec/core/object_graph_spec.rb +4 -66
- data/spec/core/schema_spec.rb +35 -12
- data/spec/core/spec_helper.rb +3 -2
- data/spec/core_extensions_spec.rb +17 -19
- data/spec/extensions/arbitrary_servers_spec.rb +2 -3
- data/spec/extensions/association_dependencies_spec.rb +14 -14
- data/spec/extensions/auto_validations_spec.rb +7 -0
- data/spec/extensions/blacklist_security_spec.rb +5 -5
- data/spec/extensions/blank_spec.rb +2 -0
- data/spec/extensions/class_table_inheritance_spec.rb +2 -2
- data/spec/extensions/columns_introspection_spec.rb +2 -29
- data/spec/extensions/composition_spec.rb +10 -17
- data/spec/extensions/core_refinements_spec.rb +5 -1
- data/spec/extensions/dataset_associations_spec.rb +18 -0
- data/spec/extensions/date_arithmetic_spec.rb +2 -2
- data/spec/extensions/defaults_setter_spec.rb +9 -9
- data/spec/extensions/dirty_spec.rb +0 -5
- data/spec/extensions/eval_inspect_spec.rb +2 -0
- data/spec/extensions/force_encoding_spec.rb +2 -18
- data/spec/extensions/hash_aliases_spec.rb +8 -0
- data/spec/extensions/hook_class_methods_spec.rb +39 -58
- data/spec/extensions/inflector_spec.rb +2 -0
- data/spec/extensions/instance_filters_spec.rb +8 -8
- data/spec/extensions/json_serializer_spec.rb +1 -41
- data/spec/extensions/list_spec.rb +1 -1
- data/spec/extensions/many_through_many_spec.rb +106 -109
- data/spec/extensions/migration_spec.rb +2 -0
- data/spec/extensions/named_timezones_spec.rb +1 -0
- data/spec/extensions/pg_array_associations_spec.rb +603 -0
- data/spec/extensions/pg_array_ops_spec.rb +25 -0
- data/spec/extensions/pg_array_spec.rb +9 -1
- data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
- data/spec/extensions/pg_hstore_spec.rb +1 -0
- data/spec/extensions/pg_json_ops_spec.rb +131 -0
- data/spec/extensions/pg_json_spec.rb +10 -4
- data/spec/extensions/pg_range_ops_spec.rb +2 -5
- data/spec/extensions/pg_range_spec.rb +6 -2
- data/spec/extensions/pg_row_ops_spec.rb +2 -0
- data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
- data/spec/extensions/rcte_tree_spec.rb +15 -15
- data/spec/extensions/schema_dumper_spec.rb +0 -1
- data/spec/extensions/schema_spec.rb +9 -9
- data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
- data/spec/extensions/serialization_spec.rb +18 -29
- data/spec/extensions/set_overrides_spec.rb +4 -0
- data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
- data/spec/extensions/single_table_inheritance_spec.rb +4 -4
- data/spec/extensions/spec_helper.rb +8 -9
- data/spec/extensions/sql_expr_spec.rb +2 -0
- data/spec/extensions/string_date_time_spec.rb +2 -0
- data/spec/extensions/string_stripper_spec.rb +2 -0
- data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
- data/spec/extensions/thread_local_timezones_spec.rb +2 -0
- data/spec/extensions/timestamps_spec.rb +1 -1
- data/spec/extensions/to_dot_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +24 -24
- data/spec/extensions/tree_spec.rb +7 -7
- data/spec/extensions/typecast_on_load_spec.rb +8 -1
- data/spec/extensions/update_primary_key_spec.rb +10 -10
- data/spec/extensions/validation_class_methods_spec.rb +10 -39
- data/spec/extensions/validation_helpers_spec.rb +29 -47
- data/spec/extensions/xml_serializer_spec.rb +1 -23
- data/spec/integration/associations_test.rb +231 -40
- data/spec/integration/database_test.rb +1 -1
- data/spec/integration/dataset_test.rb +64 -64
- data/spec/integration/eager_loader_test.rb +28 -28
- data/spec/integration/migrator_test.rb +1 -1
- data/spec/integration/model_test.rb +2 -2
- data/spec/integration/plugin_test.rb +21 -21
- data/spec/integration/prepared_statement_test.rb +7 -7
- data/spec/integration/schema_test.rb +115 -110
- data/spec/integration/spec_helper.rb +17 -27
- data/spec/integration/timezone_test.rb +1 -1
- data/spec/integration/transaction_test.rb +10 -10
- data/spec/integration/type_test.rb +2 -2
- data/spec/model/association_reflection_spec.rb +2 -28
- data/spec/model/associations_spec.rb +239 -188
- data/spec/model/base_spec.rb +27 -68
- data/spec/model/dataset_methods_spec.rb +4 -4
- data/spec/model/eager_loading_spec.rb +160 -172
- data/spec/model/hooks_spec.rb +62 -79
- data/spec/model/model_spec.rb +36 -51
- data/spec/model/plugins_spec.rb +5 -19
- data/spec/model/record_spec.rb +125 -151
- data/spec/model/spec_helper.rb +8 -6
- data/spec/model/validations_spec.rb +4 -17
- data/spec/spec_config.rb +2 -10
- metadata +50 -56
- data/lib/sequel/deprecated_core_extensions.rb +0 -135
- data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
- data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
- data/lib/sequel/plugins/identity_map.rb +0 -260
- data/lib/sequel_core.rb +0 -2
- data/lib/sequel_model.rb +0 -2
- data/spec/extensions/association_autoreloading_spec.rb +0 -102
- data/spec/extensions/identity_map_spec.rb +0 -337
- data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
- data/spec/extensions/pg_statement_cache_spec.rb +0 -208
- data/spec/rcov.opts +0 -8
- 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
|
-
|
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
|
-
|
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)
|
data/lib/sequel/sql.rb
CHANGED
@@ -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
|
|
data/lib/sequel/version.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Sequel
|
2
2
|
# The major version of Sequel. Only bumped for major changes.
|
3
|
-
MAJOR =
|
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 =
|
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
|
data/spec/adapters/db2_spec.rb
CHANGED
@@ -1,23 +1,14 @@
|
|
1
|
-
|
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
|
-
|
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 =
|
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
|
-
|
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 =
|
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
|
-
|
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 =
|
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 =
|
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
|
127
|
+
end if DB.adapter_scheme == :ibmdb
|
137
128
|
|
138
129
|
describe "Simple Dataset operations in transactions" do
|
139
130
|
before do
|
140
|
-
|
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 =
|
135
|
+
@ds = DB[:items_insert_in_transaction]
|
145
136
|
end
|
146
137
|
after do
|
147
|
-
|
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
|
-
|
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
|
-
|
1
|
+
SEQUEL_ADAPTER_TEST = :firebird
|
2
2
|
|
3
|
-
|
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
|
5
|
+
def DB.sqls
|
10
6
|
(@sqls ||= [])
|
11
7
|
end
|
12
8
|
logger = Object.new
|
13
9
|
def logger.method_missing(m, msg)
|
14
|
-
|
10
|
+
DB.sqls.push(msg)
|
15
11
|
end
|
16
|
-
|
12
|
+
DB.loggers = [logger]
|
17
13
|
|
18
|
-
|
14
|
+
DB.create_table! :test do
|
19
15
|
varchar :name, :size => 50
|
20
16
|
integer :val, :index => true
|
21
17
|
end
|
22
18
|
|
23
|
-
|
19
|
+
DB.create_table! :test2 do
|
24
20
|
integer :val
|
25
21
|
timestamp :time_stamp
|
26
22
|
end
|
27
23
|
|
28
|
-
|
24
|
+
DB.create_table! :test3 do
|
29
25
|
integer :val
|
30
26
|
timestamp :time_stamp
|
31
27
|
end
|
32
28
|
|
33
|
-
|
29
|
+
DB.create_table! :test5 do
|
34
30
|
primary_key :xid
|
35
31
|
integer :val
|
36
32
|
end
|
37
33
|
|
38
|
-
|
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 =
|
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 =
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
208
|
+
DB.ret_commit
|
213
209
|
@d.count.should == 1
|
214
|
-
|
210
|
+
DB.ret_commit
|
215
211
|
@d.count.should == 2
|
216
212
|
proc do
|
217
|
-
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
402
|
+
@ds = DB[:test6]
|
407
403
|
@ds.delete
|
408
404
|
end
|
409
405
|
|