sequel 3.48.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/lib/sequel/dataset/sql.rb
CHANGED
|
@@ -40,8 +40,6 @@ module Sequel
|
|
|
40
40
|
when 1
|
|
41
41
|
case vals = values.at(0)
|
|
42
42
|
when Hash
|
|
43
|
-
vals = @opts[:defaults].merge(vals) if @opts[:defaults]
|
|
44
|
-
vals = vals.merge(@opts[:overrides]) if @opts[:overrides]
|
|
45
43
|
values = []
|
|
46
44
|
vals.each do |k,v|
|
|
47
45
|
columns << k
|
|
@@ -163,7 +161,7 @@ module Sequel
|
|
|
163
161
|
#
|
|
164
162
|
# Raises an +Error+ if the dataset is grouped or includes more
|
|
165
163
|
# than one table.
|
|
166
|
-
def update_sql(values =
|
|
164
|
+
def update_sql(values = OPTS)
|
|
167
165
|
return static_sql(opts[:sql]) if opts[:sql]
|
|
168
166
|
check_modification_allowed!
|
|
169
167
|
clone(:values=>values)._update_sql
|
|
@@ -202,6 +200,7 @@ module Sequel
|
|
|
202
200
|
CASE_THEN = " THEN ".freeze
|
|
203
201
|
CASE_WHEN = " WHEN ".freeze
|
|
204
202
|
CAST_OPEN = 'CAST('.freeze
|
|
203
|
+
COLON = ':'.freeze
|
|
205
204
|
COLUMN_REF_RE1 = Sequel::COLUMN_REF_RE1
|
|
206
205
|
COLUMN_REF_RE2 = Sequel::COLUMN_REF_RE2
|
|
207
206
|
COLUMN_REF_RE3 = Sequel::COLUMN_REF_RE3
|
|
@@ -285,80 +284,6 @@ module Sequel
|
|
|
285
284
|
V190 = '1.9.0'.freeze
|
|
286
285
|
WHERE = " WHERE ".freeze
|
|
287
286
|
|
|
288
|
-
PUBLIC_APPEND_METHODS = (<<-END).split.map{|x| x.to_sym}
|
|
289
|
-
literal
|
|
290
|
-
aliased_expression_sql
|
|
291
|
-
array_sql
|
|
292
|
-
boolean_constant_sql
|
|
293
|
-
case_expression_sql
|
|
294
|
-
cast_sql
|
|
295
|
-
column_all_sql
|
|
296
|
-
complex_expression_sql
|
|
297
|
-
constant_sql
|
|
298
|
-
delayed_evaluation_sql
|
|
299
|
-
function_sql
|
|
300
|
-
join_clause_sql
|
|
301
|
-
join_on_clause_sql
|
|
302
|
-
join_using_clause_sql
|
|
303
|
-
negative_boolean_constant_sql
|
|
304
|
-
ordered_expression_sql
|
|
305
|
-
placeholder_literal_string_sql
|
|
306
|
-
qualified_identifier_sql
|
|
307
|
-
quote_identifier
|
|
308
|
-
quote_schema_table
|
|
309
|
-
quoted_identifier
|
|
310
|
-
subscript_sql
|
|
311
|
-
window_sql
|
|
312
|
-
window_function_sql
|
|
313
|
-
END
|
|
314
|
-
PRIVATE_APPEND_METHODS = (<<-END).split.map{|x| x.to_sym}
|
|
315
|
-
as_sql
|
|
316
|
-
column_list
|
|
317
|
-
compound_dataset_sql
|
|
318
|
-
expression_list
|
|
319
|
-
literal_array
|
|
320
|
-
literal_blob
|
|
321
|
-
literal_dataset
|
|
322
|
-
literal_expression
|
|
323
|
-
literal_hash
|
|
324
|
-
literal_other
|
|
325
|
-
literal_string
|
|
326
|
-
literal_symbol
|
|
327
|
-
source_list
|
|
328
|
-
subselect_sql
|
|
329
|
-
table_ref
|
|
330
|
-
END
|
|
331
|
-
|
|
332
|
-
# For each of the methods in the given array, define a method with
|
|
333
|
-
# that name that returns a string with the SQL fragment that the
|
|
334
|
-
# related *_append method would add.
|
|
335
|
-
#
|
|
336
|
-
# Do not call this method with untrusted input, as that can result in
|
|
337
|
-
# arbitrary code execution.
|
|
338
|
-
def self.def_append_methods(meths)
|
|
339
|
-
Sequel::Deprecation.deprecate('Dataset.def_append_methods', "There is no replacement planned")
|
|
340
|
-
meths.each do |meth|
|
|
341
|
-
class_eval(<<-END, __FILE__, __LINE__ + 1)
|
|
342
|
-
def #{meth}(*args, &block)
|
|
343
|
-
s = ''
|
|
344
|
-
#{meth}_append(s, *args, &block)
|
|
345
|
-
s
|
|
346
|
-
end
|
|
347
|
-
END
|
|
348
|
-
end
|
|
349
|
-
end
|
|
350
|
-
(PUBLIC_APPEND_METHODS + PRIVATE_APPEND_METHODS - [:literal, :quote_identifier, :quote_schema_table]).each do |meth|
|
|
351
|
-
class_eval(<<-END, __FILE__, __LINE__ + 1)
|
|
352
|
-
def #{meth}(*args, &block)
|
|
353
|
-
Sequel::Deprecation.deprecate('Dataset##{meth}', "Please switch to Dataset##{meth}_append")
|
|
354
|
-
s = ''
|
|
355
|
-
#{meth}_append(s, *args, &block)
|
|
356
|
-
s
|
|
357
|
-
end
|
|
358
|
-
END
|
|
359
|
-
end
|
|
360
|
-
private(*PRIVATE_APPEND_METHODS)
|
|
361
|
-
|
|
362
287
|
[:literal, :quote_identifier, :quote_schema_table].each do |meth|
|
|
363
288
|
class_eval(<<-END, __FILE__, __LINE__ + 1)
|
|
364
289
|
def #{meth}(*args, &block)
|
|
@@ -622,17 +547,18 @@ module Sequel
|
|
|
622
547
|
literal_append(sql, args[i]) unless i == len
|
|
623
548
|
end
|
|
624
549
|
unless str.length == args.length || str.length == args.length + 1
|
|
625
|
-
|
|
550
|
+
raise Error, "Mismatched number of placeholders (#{str.length}) and placeholder arguments (#{args.length}) when using placeholder array"
|
|
626
551
|
end
|
|
627
552
|
else
|
|
628
553
|
i = -1
|
|
554
|
+
match_len = args.length - 1
|
|
629
555
|
loop do
|
|
630
556
|
previous, q, str = str.partition(QUESTION_MARK)
|
|
631
557
|
sql << previous
|
|
632
558
|
literal_append(sql, args.at(i+=1)) unless q.empty?
|
|
633
559
|
if str.empty?
|
|
634
|
-
unless i
|
|
635
|
-
|
|
560
|
+
unless i == match_len
|
|
561
|
+
raise Error, "Mismatched number of placeholders (#{i+1}) and placeholder arguments (#{args.length}) when using placeholder array"
|
|
636
562
|
end
|
|
637
563
|
break
|
|
638
564
|
end
|
|
@@ -693,7 +619,7 @@ module Sequel
|
|
|
693
619
|
# Note that this function does not handle tables with more than one
|
|
694
620
|
# level of qualification (e.g. database.schema.table on Microsoft
|
|
695
621
|
# SQL Server).
|
|
696
|
-
def schema_and_table(table_name, sch=
|
|
622
|
+
def schema_and_table(table_name, sch=nil)
|
|
697
623
|
sch = sch.to_s if sch
|
|
698
624
|
case table_name
|
|
699
625
|
when Symbol
|
|
@@ -730,7 +656,15 @@ module Sequel
|
|
|
730
656
|
def subscript_sql_append(sql, s)
|
|
731
657
|
literal_append(sql, s.f)
|
|
732
658
|
sql << BRACKET_OPEN
|
|
733
|
-
|
|
659
|
+
if s.sub.length == 1 && (range = s.sub.first).is_a?(Range)
|
|
660
|
+
literal_append(sql, range.begin)
|
|
661
|
+
sql << COLON
|
|
662
|
+
e = range.end
|
|
663
|
+
e -= 1 if range.exclude_end? && e.is_a?(Integer)
|
|
664
|
+
literal_append(sql, e)
|
|
665
|
+
else
|
|
666
|
+
expression_list_append(sql, s.sub)
|
|
667
|
+
end
|
|
734
668
|
sql << BRACKET_CLOSE
|
|
735
669
|
end
|
|
736
670
|
|
|
@@ -949,14 +883,10 @@ module Sequel
|
|
|
949
883
|
end
|
|
950
884
|
end
|
|
951
885
|
|
|
952
|
-
# An expression for how to handle an empty array lookup
|
|
886
|
+
# An expression for how to handle an empty array lookup.
|
|
953
887
|
def empty_array_value(op, cols)
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
SQL::BooleanExpression.from_value_pairs(c.zip(c), :AND, op == :IN)
|
|
957
|
-
else
|
|
958
|
-
{1 => ((op == :IN) ? 0 : 1)}
|
|
959
|
-
end
|
|
888
|
+
c = Array(cols)
|
|
889
|
+
SQL::BooleanExpression.from_value_pairs(c.zip(c), :AND, op == :IN)
|
|
960
890
|
end
|
|
961
891
|
|
|
962
892
|
# Format the timestamp based on the default_timestamp_format, with a couple
|
|
@@ -1008,12 +938,6 @@ module Sequel
|
|
|
1008
938
|
end
|
|
1009
939
|
end
|
|
1010
940
|
|
|
1011
|
-
# REMOVE40
|
|
1012
|
-
def table_ref_append(sql, v)
|
|
1013
|
-
Sequel::Deprecation.deprecate('Dataset#table_ref_append', "Please switch to Dataset#identifier_append")
|
|
1014
|
-
identifier_append(sql, v)
|
|
1015
|
-
end
|
|
1016
|
-
|
|
1017
941
|
# Append all identifiers in args interspersed by commas.
|
|
1018
942
|
def identifier_list_append(sql, args)
|
|
1019
943
|
c = false
|
|
@@ -1467,8 +1391,6 @@ module Sequel
|
|
|
1467
1391
|
values = opts[:values]
|
|
1468
1392
|
sql << SET
|
|
1469
1393
|
if values.is_a?(Hash)
|
|
1470
|
-
values = opts[:defaults].merge(values) if opts[:defaults]
|
|
1471
|
-
values = values.merge(opts[:overrides]) if opts[:overrides]
|
|
1472
1394
|
c = false
|
|
1473
1395
|
eq = EQUAL
|
|
1474
1396
|
values.each do |k, v|
|
data/lib/sequel/deprecated.rb
CHANGED
|
@@ -54,21 +54,5 @@ module Sequel
|
|
|
54
54
|
end
|
|
55
55
|
nil
|
|
56
56
|
end
|
|
57
|
-
|
|
58
|
-
# Return a module that includes deprecation warnings for all public
|
|
59
|
-
# instance methods in the given module, such that including the returned
|
|
60
|
-
# module will not result in the given module being included.
|
|
61
|
-
def self.deprecated_module(mod, &block)
|
|
62
|
-
Module.new do
|
|
63
|
-
include mod.dup
|
|
64
|
-
mod.public_instance_methods.each do |meth|
|
|
65
|
-
msg = block.call(meth)
|
|
66
|
-
define_method(meth) do |*a, &blk|
|
|
67
|
-
Sequel::Deprecation.deprecate(*msg)
|
|
68
|
-
super(*a, &blk)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
57
|
end
|
|
74
58
|
end
|
data/lib/sequel/exceptions.rb
CHANGED
|
@@ -54,9 +54,6 @@ module Sequel
|
|
|
54
54
|
# method, and the dataset does not yield any rows.
|
|
55
55
|
class NoMatchingRow < Error; end
|
|
56
56
|
|
|
57
|
-
# Error raised when the adapter adapter hasn't implemented a method such as +tables+:
|
|
58
|
-
class NotImplemented < Error; end
|
|
59
|
-
|
|
60
57
|
# Error raised when the connection pool cannot acquire a database connection
|
|
61
58
|
# before the timeout.
|
|
62
59
|
class PoolTimeout < Error; end
|
|
@@ -27,7 +27,7 @@ module Sequel
|
|
|
27
27
|
if (pcs = probable_columns) && pcs.all?
|
|
28
28
|
@columns = pcs
|
|
29
29
|
else
|
|
30
|
-
|
|
30
|
+
super
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -77,17 +77,6 @@ module Sequel
|
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
class Dataset
|
|
81
|
-
alias columns_without_introspection columns
|
|
82
|
-
|
|
83
|
-
# Enable column introspection for every dataset.
|
|
84
|
-
def self.introspect_all_columns
|
|
85
|
-
Sequel::Deprecation.deprecate('Sequel::Dataset.introspect_all_columns', "Please use Database.extension :columns_introspection to load the extension into all databases")
|
|
86
|
-
include ColumnsIntrospection
|
|
87
|
-
remove_method(:columns) if instance_methods(false).map{|x| x.to_s}.include?('columns')
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
80
|
Dataset.register_extension(:columns_introspection, Sequel::ColumnsIntrospection)
|
|
92
81
|
end
|
|
93
82
|
|
|
@@ -144,7 +144,7 @@ module Sequel
|
|
|
144
144
|
# Create constraint validation methods that don't take an argument
|
|
145
145
|
%w'presence unique'.each do |v|
|
|
146
146
|
class_eval(<<-END, __FILE__, __LINE__+1)
|
|
147
|
-
def #{v}(columns, opts=
|
|
147
|
+
def #{v}(columns, opts=OPTS)
|
|
148
148
|
@generator.validation({:type=>:#{v}, :columns=>Array(columns)}.merge(opts))
|
|
149
149
|
end
|
|
150
150
|
END
|
|
@@ -153,7 +153,7 @@ module Sequel
|
|
|
153
153
|
# Create constraint validation methods that take an argument
|
|
154
154
|
%w'exact_length min_length max_length length_range format like ilike includes'.each do |v|
|
|
155
155
|
class_eval(<<-END, __FILE__, __LINE__+1)
|
|
156
|
-
def #{v}(arg, columns, opts=
|
|
156
|
+
def #{v}(arg, columns, opts=OPTS)
|
|
157
157
|
@generator.validation({:type=>:#{v}, :columns=>Array(columns), :arg=>arg}.merge(opts))
|
|
158
158
|
end
|
|
159
159
|
END
|
|
@@ -244,7 +244,7 @@ module Sequel
|
|
|
244
244
|
# the related metadata, it could make it impossible to save
|
|
245
245
|
# rows, since a validation for a nonexistent column will be
|
|
246
246
|
# created.
|
|
247
|
-
def drop_constraint_validations_for(opts=
|
|
247
|
+
def drop_constraint_validations_for(opts=OPTS)
|
|
248
248
|
ds = from(constraint_validations_table)
|
|
249
249
|
if table = opts[:table]
|
|
250
250
|
ds = ds.where(:table=>constraint_validations_literal_table(table))
|
|
@@ -208,9 +208,6 @@ class Symbol
|
|
|
208
208
|
include Sequel::SQL::StringMethods
|
|
209
209
|
include Sequel::SQL::SubscriptMethods
|
|
210
210
|
include Sequel::SQL::ComplexExpressionMethods
|
|
211
|
-
if RUBY_VERSION < '1.9.0'
|
|
212
|
-
include Sequel::Deprecation.deprecated_module(Sequel::SQL::InequalityMethods){|meth| ["Symbol##{meth}", "Please use Sequel.expr(symbol).#{meth} instead, or Sequel.extension(:ruby18_symbol_extensions) to continue using it"]}
|
|
213
|
-
end
|
|
214
211
|
|
|
215
212
|
# Returns receiver wrapped in an <tt>Sequel::SQL::Identifier</tt>. Usually used to
|
|
216
213
|
# prevent splitting the symbol.
|
|
@@ -232,10 +229,4 @@ class Symbol
|
|
|
232
229
|
def sql_function(*args)
|
|
233
230
|
Sequel::SQL::Function.new(self, *args)
|
|
234
231
|
end
|
|
235
|
-
if RUBY_VERSION < '1.9.0'
|
|
236
|
-
def [](*args)
|
|
237
|
-
Sequel::Deprecation.deprecate('Symbol#[]', 'Please use Sequel.function instead, or Sequel.extension(:ruby18_symbol_extensions) to continue using it')
|
|
238
|
-
Sequel::SQL::Function.new(self, *args)
|
|
239
|
-
end
|
|
240
|
-
end
|
|
241
232
|
end
|
|
@@ -122,8 +122,7 @@ module Sequel
|
|
|
122
122
|
end
|
|
123
123
|
false
|
|
124
124
|
else
|
|
125
|
-
|
|
126
|
-
raise NotImplemented, "date arithmetic is not implemented on #{db.database_type}"
|
|
125
|
+
raise Error, "date arithmetic is not implemented on #{db.database_type}"
|
|
127
126
|
end
|
|
128
127
|
|
|
129
128
|
if cast
|
|
@@ -17,6 +17,17 @@
|
|
|
17
17
|
|
|
18
18
|
module Sequel
|
|
19
19
|
module GraphEach
|
|
20
|
+
# Call graph_each for graphed datasets that are not being eager graphed.
|
|
21
|
+
def each
|
|
22
|
+
if @opts[:graph] && !@opts[:eager_graph]
|
|
23
|
+
graph_each{|r| yield r}
|
|
24
|
+
else
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
20
31
|
# Fetch the rows, split them into component table parts,
|
|
21
32
|
# tranform and run the row_proc on each part (if applicable),
|
|
22
33
|
# and yield a hash of the parts.
|
|
@@ -369,7 +369,7 @@ module Sequel
|
|
|
369
369
|
|
|
370
370
|
# Return whether the migrator is current (i.e. it does not need to make
|
|
371
371
|
# any changes). Takes the same arguments as #run.
|
|
372
|
-
def self.is_current?(db, directory, opts=
|
|
372
|
+
def self.is_current?(db, directory, opts=OPTS)
|
|
373
373
|
migrator_class(directory).new(db, directory, opts).is_current?
|
|
374
374
|
end
|
|
375
375
|
|
|
@@ -386,7 +386,7 @@ module Sequel
|
|
|
386
386
|
# Sequel::Migrator.run(DB, "migrations", :target=>15, :current=>10)
|
|
387
387
|
# Sequel::Migrator.run(DB, "app1/migrations", :column=> :app2_version)
|
|
388
388
|
# Sequel::Migrator.run(DB, "app2/migrations", :column => :app2_version, :table=>:schema_info2)
|
|
389
|
-
def self.run(db, directory, opts=
|
|
389
|
+
def self.run(db, directory, opts=OPTS)
|
|
390
390
|
migrator_class(directory).new(db, directory, opts).run
|
|
391
391
|
end
|
|
392
392
|
|
|
@@ -432,7 +432,7 @@ module Sequel
|
|
|
432
432
|
attr_reader :target
|
|
433
433
|
|
|
434
434
|
# Setup the state for the migrator
|
|
435
|
-
def initialize(db, directory, opts=
|
|
435
|
+
def initialize(db, directory, opts=OPTS)
|
|
436
436
|
raise(Error, "Must supply a valid migration path") unless File.directory?(directory)
|
|
437
437
|
@db = db
|
|
438
438
|
@directory = directory
|
|
@@ -502,7 +502,7 @@ module Sequel
|
|
|
502
502
|
attr_reader :migrations
|
|
503
503
|
|
|
504
504
|
# Set up all state for the migrator instance
|
|
505
|
-
def initialize(db, directory, opts=
|
|
505
|
+
def initialize(db, directory, opts=OPTS)
|
|
506
506
|
super
|
|
507
507
|
@target = opts[:target] || latest_migration_version
|
|
508
508
|
@current = opts[:current] || current_migration_version
|
|
@@ -628,7 +628,7 @@ module Sequel
|
|
|
628
628
|
attr_reader :migration_tuples
|
|
629
629
|
|
|
630
630
|
# Set up all state for the migrator instance
|
|
631
|
-
def initialize(db, directory, opts=
|
|
631
|
+
def initialize(db, directory, opts=OPTS)
|
|
632
632
|
super
|
|
633
633
|
@target = opts[:target]
|
|
634
634
|
@applied_migrations = get_applied_migrations
|
|
@@ -30,6 +30,15 @@
|
|
|
30
30
|
module Sequel
|
|
31
31
|
class Dataset
|
|
32
32
|
module Nullifiable
|
|
33
|
+
# Return a cloned nullified dataset.
|
|
34
|
+
def nullify
|
|
35
|
+
clone.nullify!
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Nullify the current dataset
|
|
39
|
+
def nullify!
|
|
40
|
+
extend NullDataset
|
|
41
|
+
end
|
|
33
42
|
end
|
|
34
43
|
|
|
35
44
|
module NullDataset
|
|
@@ -65,7 +74,7 @@ module Sequel
|
|
|
65
74
|
end
|
|
66
75
|
|
|
67
76
|
# Return 0 without sending a database query.
|
|
68
|
-
def update(v=
|
|
77
|
+
def update(v=OPTS)
|
|
69
78
|
0
|
|
70
79
|
end
|
|
71
80
|
|
|
@@ -82,20 +91,9 @@ module Sequel
|
|
|
82
91
|
# make them noops. There's nothing we can do if the db
|
|
83
92
|
# is accessed directly to make a change, though.
|
|
84
93
|
(%w'_ddl _dui _insert' << '').each do |m|
|
|
85
|
-
class_eval("private; def execute#{m}(sql, opts=
|
|
94
|
+
class_eval("private; def execute#{m}(sql, opts=OPTS) end", __FILE__, __LINE__)
|
|
86
95
|
end
|
|
87
96
|
end
|
|
88
|
-
|
|
89
|
-
# Return a cloned nullified dataset.
|
|
90
|
-
def nullify
|
|
91
|
-
clone.nullify!
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# Nullify the current dataset
|
|
95
|
-
def nullify!
|
|
96
|
-
Sequel::Deprecation.deprecate('Loading the null_dataset extension globally', "Please use Database/Dataset#extension to load the extension into this dataset") unless is_a?(Nullifiable)
|
|
97
|
-
extend NullDataset
|
|
98
|
-
end
|
|
99
97
|
end
|
|
100
98
|
|
|
101
99
|
Dataset.register_extension(:null_dataset, Dataset::Nullifiable)
|
|
@@ -16,32 +16,29 @@
|
|
|
16
16
|
|
|
17
17
|
module Sequel
|
|
18
18
|
module DatasetPagination
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
class Dataset
|
|
22
19
|
# Returns a paginated dataset. The returned dataset is limited to
|
|
23
20
|
# the page size at the correct offset, and extended with the Pagination
|
|
24
21
|
# module. If a record count is not provided, does a count of total
|
|
25
22
|
# number of records for this dataset.
|
|
26
23
|
def paginate(page_no, page_size, record_count=nil)
|
|
27
|
-
Sequel::Deprecation.deprecate('Loading the pagination extension globally', "Please use Database/Dataset#extension to load the extension into this dataset") unless is_a?(DatasetPagination)
|
|
28
24
|
raise(Error, "You cannot paginate a dataset that already has a limit") if @opts[:limit]
|
|
29
25
|
paginated = limit(page_size, (page_no - 1) * page_size)
|
|
30
|
-
paginated.extend(Pagination)
|
|
26
|
+
paginated.extend(Dataset::Pagination)
|
|
31
27
|
paginated.set_pagination_info(page_no, page_size, record_count || count)
|
|
32
28
|
end
|
|
33
29
|
|
|
34
30
|
# Yields a paginated dataset for each page and returns the receiver. Does
|
|
35
31
|
# a count to find the total number of records for this dataset.
|
|
36
32
|
def each_page(page_size)
|
|
37
|
-
Sequel::Deprecation.deprecate('Loading the pagination extension globally', "Please use Database/Dataset#extension to load the extension into this dataset") unless is_a?(DatasetPagination)
|
|
38
33
|
raise(Error, "You cannot paginate a dataset that already has a limit") if @opts[:limit]
|
|
39
34
|
record_count = count
|
|
40
35
|
total_pages = (record_count / page_size.to_f).ceil
|
|
41
36
|
(1..total_pages).each{|page_no| yield paginate(page_no, page_size, record_count)}
|
|
42
37
|
self
|
|
43
38
|
end
|
|
39
|
+
end
|
|
44
40
|
|
|
41
|
+
class Dataset
|
|
45
42
|
# Holds methods that only relate to paginated datasets. Paginated dataset
|
|
46
43
|
# have pages starting at 1 (page 1 is offset 0, page 1 is offset page_size).
|
|
47
44
|
module Pagination
|