sequel 4.45.0 → 4.46.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +108 -0
- data/doc/release_notes/4.46.0.txt +404 -0
- data/doc/security.rdoc +9 -0
- data/doc/sql.rdoc +2 -2
- data/doc/testing.rdoc +1 -1
- data/doc/validations.rdoc +1 -2
- data/lib/sequel/adapters/ado.rb +8 -3
- data/lib/sequel/adapters/ado/access.rb +8 -4
- data/lib/sequel/adapters/ado/mssql.rb +3 -1
- data/lib/sequel/adapters/amalgalite.rb +5 -0
- data/lib/sequel/adapters/cubrid.rb +16 -7
- data/lib/sequel/adapters/do.rb +7 -1
- data/lib/sequel/adapters/do/mysql.rb +8 -4
- data/lib/sequel/adapters/ibmdb.rb +10 -5
- data/lib/sequel/adapters/jdbc.rb +8 -2
- data/lib/sequel/adapters/jdbc/as400.rb +10 -3
- data/lib/sequel/adapters/jdbc/db2.rb +27 -16
- data/lib/sequel/adapters/jdbc/derby.rb +47 -20
- data/lib/sequel/adapters/jdbc/h2.rb +13 -7
- data/lib/sequel/adapters/jdbc/hsqldb.rb +18 -9
- data/lib/sequel/adapters/jdbc/mssql.rb +5 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +3 -2
- data/lib/sequel/adapters/jdbc/oracle.rb +3 -2
- data/lib/sequel/adapters/jdbc/postgresql.rb +4 -3
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +2 -1
- data/lib/sequel/adapters/jdbc/sqlite.rb +10 -3
- data/lib/sequel/adapters/jdbc/sqlserver.rb +23 -0
- data/lib/sequel/adapters/jdbc/transactions.rb +16 -10
- data/lib/sequel/adapters/mock.rb +5 -0
- data/lib/sequel/adapters/mysql.rb +8 -1
- data/lib/sequel/adapters/mysql2.rb +6 -1
- data/lib/sequel/adapters/odbc.rb +20 -8
- data/lib/sequel/adapters/odbc/mssql.rb +6 -3
- data/lib/sequel/adapters/oracle.rb +12 -6
- data/lib/sequel/adapters/postgres.rb +20 -8
- data/lib/sequel/adapters/shared/access.rb +76 -47
- data/lib/sequel/adapters/shared/cubrid.rb +16 -11
- data/lib/sequel/adapters/shared/db2.rb +46 -19
- data/lib/sequel/adapters/shared/firebird.rb +20 -8
- data/lib/sequel/adapters/shared/informix.rb +6 -3
- data/lib/sequel/adapters/shared/mssql.rb +132 -72
- data/lib/sequel/adapters/shared/mysql.rb +112 -65
- data/lib/sequel/adapters/shared/oracle.rb +36 -21
- data/lib/sequel/adapters/shared/postgres.rb +91 -56
- data/lib/sequel/adapters/shared/sqlanywhere.rb +65 -37
- data/lib/sequel/adapters/shared/sqlite.rb +67 -32
- data/lib/sequel/adapters/sqlanywhere.rb +9 -1
- data/lib/sequel/adapters/sqlite.rb +8 -1
- data/lib/sequel/adapters/swift.rb +5 -0
- data/lib/sequel/adapters/swift/mysql.rb +4 -2
- data/lib/sequel/adapters/swift/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +10 -3
- data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +1 -1
- data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +1 -1
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -0
- data/lib/sequel/adapters/utils/pg_types.rb +14 -6
- data/lib/sequel/adapters/utils/replace.rb +4 -2
- data/lib/sequel/connection_pool/single.rb +2 -2
- data/lib/sequel/core.rb +24 -11
- data/lib/sequel/database/connecting.rb +9 -3
- data/lib/sequel/database/dataset_defaults.rb +7 -1
- data/lib/sequel/database/logging.rb +1 -0
- data/lib/sequel/database/misc.rb +5 -2
- data/lib/sequel/database/query.rb +7 -5
- data/lib/sequel/database/schema_generator.rb +1 -0
- data/lib/sequel/database/schema_methods.rb +50 -27
- data/lib/sequel/database/transactions.rb +19 -9
- data/lib/sequel/dataset/actions.rb +15 -6
- data/lib/sequel/dataset/graph.rb +15 -5
- data/lib/sequel/dataset/misc.rb +12 -4
- data/lib/sequel/dataset/mutation.rb +17 -8
- data/lib/sequel/dataset/prepared_statements.rb +3 -2
- data/lib/sequel/dataset/query.rb +84 -38
- data/lib/sequel/dataset/sql.rb +302 -191
- data/lib/sequel/deprecated.rb +26 -17
- data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +2 -2
- data/lib/sequel/extensions/auto_literal_strings.rb +74 -0
- data/lib/sequel/extensions/from_block.rb +1 -0
- data/lib/sequel/extensions/graph_each.rb +1 -1
- data/lib/sequel/extensions/identifier_mangling.rb +2 -2
- data/lib/sequel/extensions/migration.rb +28 -4
- data/lib/sequel/extensions/no_auto_literal_strings.rb +2 -0
- data/lib/sequel/extensions/schema_dumper.rb +4 -4
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +5 -3
- data/lib/sequel/extensions/set_overrides.rb +2 -0
- data/lib/sequel/extensions/split_array_nil.rb +2 -2
- data/lib/sequel/extensions/virtual_row_method_block.rb +44 -0
- data/lib/sequel/model.rb +11 -7
- data/lib/sequel/model/associations.rb +5 -7
- data/lib/sequel/model/base.rb +47 -45
- data/lib/sequel/model/dataset_module.rb +9 -14
- data/lib/sequel/model/plugins.rb +3 -0
- data/lib/sequel/no_core_ext.rb +1 -0
- data/lib/sequel/plugins/blacklist_security.rb +1 -1
- data/lib/sequel/plugins/boolean_subsets.rb +7 -5
- data/lib/sequel/plugins/class_table_inheritance.rb +47 -10
- data/lib/sequel/plugins/dataset_associations.rb +1 -1
- data/lib/sequel/plugins/def_dataset_method.rb +90 -0
- data/lib/sequel/plugins/finder.rb +240 -0
- data/lib/sequel/plugins/inverted_subsets.rb +19 -12
- data/lib/sequel/plugins/many_through_many.rb +1 -1
- data/lib/sequel/plugins/nested_attributes.rb +1 -1
- data/lib/sequel/plugins/schema.rb +1 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +7 -1
- data/lib/sequel/plugins/subset_conditions.rb +11 -3
- data/lib/sequel/plugins/whitelist_security.rb +118 -0
- data/lib/sequel/sql.rb +80 -36
- data/lib/sequel/timezones.rb +2 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/mssql_spec.rb +20 -0
- data/spec/adapters/mysql_spec.rb +1 -1
- data/spec/adapters/oracle_spec.rb +12 -8
- data/spec/adapters/postgres_spec.rb +1 -1
- data/spec/adapters/spec_helper.rb +1 -1
- data/spec/adapters/sqlite_spec.rb +36 -34
- data/spec/core/connection_pool_spec.rb +2 -1
- data/spec/core/database_spec.rb +87 -9
- data/spec/core/dataset_spec.rb +501 -129
- data/spec/core/deprecated_spec.rb +1 -1
- data/spec/core/expression_filters_spec.rb +146 -60
- data/spec/core/mock_adapter_spec.rb +1 -1
- data/spec/core/object_graph_spec.rb +61 -9
- data/spec/core/placeholder_literalizer_spec.rb +20 -2
- data/spec/core/schema_generator_spec.rb +6 -6
- data/spec/core/schema_spec.rb +54 -5
- data/spec/core_extensions_spec.rb +122 -18
- data/spec/deprecation_helper.rb +27 -2
- data/spec/extensions/_deprecated_identifier_mangling_spec.rb +6 -6
- data/spec/extensions/association_proxies_spec.rb +2 -2
- data/spec/extensions/auto_literal_strings_spec.rb +212 -0
- data/spec/extensions/blacklist_security_spec.rb +1 -0
- data/spec/extensions/class_table_inheritance_spec.rb +1037 -39
- data/spec/extensions/column_select_spec.rb +20 -8
- data/spec/extensions/columns_introspection_spec.rb +3 -3
- data/spec/extensions/core_refinements_spec.rb +29 -12
- data/spec/extensions/dataset_associations_spec.rb +12 -12
- data/spec/extensions/def_dataset_method_spec.rb +100 -0
- data/spec/extensions/error_sql_spec.rb +1 -1
- data/spec/extensions/finder_spec.rb +260 -0
- data/spec/extensions/graph_each_spec.rb +2 -2
- data/spec/extensions/identifier_mangling_spec.rb +14 -8
- data/spec/extensions/inverted_subsets_spec.rb +4 -4
- data/spec/extensions/lazy_attributes_spec.rb +7 -0
- data/spec/extensions/many_through_many_spec.rb +38 -14
- data/spec/extensions/nested_attributes_spec.rb +18 -6
- data/spec/extensions/no_auto_literal_strings_spec.rb +1 -1
- data/spec/extensions/pg_enum_spec.rb +16 -1
- data/spec/extensions/pg_interval_spec.rb +11 -2
- data/spec/extensions/pg_loose_count_spec.rb +5 -0
- data/spec/extensions/pg_row_spec.rb +25 -0
- data/spec/extensions/prepared_statements_spec.rb +10 -1
- data/spec/extensions/query_spec.rb +2 -2
- data/spec/extensions/schema_dumper_spec.rb +2 -2
- data/spec/extensions/schema_spec.rb +2 -2
- data/spec/extensions/set_overrides_spec.rb +7 -3
- data/spec/extensions/sql_expr_spec.rb +0 -1
- data/spec/extensions/subset_conditions_spec.rb +6 -6
- data/spec/extensions/table_select_spec.rb +24 -12
- data/spec/extensions/to_dot_spec.rb +4 -4
- data/spec/extensions/whitelist_security_spec.rb +131 -0
- data/spec/integration/dataset_test.rb +9 -5
- data/spec/integration/model_test.rb +2 -0
- data/spec/integration/plugin_test.rb +2 -2
- data/spec/integration/spec_helper.rb +1 -1
- data/spec/model/associations_spec.rb +39 -11
- data/spec/model/base_spec.rb +44 -24
- data/spec/model/class_dataset_methods_spec.rb +18 -16
- data/spec/model/dataset_methods_spec.rb +4 -4
- data/spec/model/eager_loading_spec.rb +84 -24
- data/spec/model/model_spec.rb +97 -63
- data/spec/model/record_spec.rb +21 -13
- metadata +13 -2
@@ -5,28 +5,34 @@ module Sequel
|
|
5
5
|
NAN = 0.0/0.0
|
6
6
|
PLUS_INFINITY = 1.0/0.0
|
7
7
|
MINUS_INFINITY = -1.0/0.0
|
8
|
+
|
8
9
|
NAN_STR = 'NaN'.freeze
|
10
|
+
Sequel::Deprecation.deprecate_constant(self, :NAN_STR)
|
9
11
|
PLUS_INFINITY_STR = 'Infinity'.freeze
|
12
|
+
Sequel::Deprecation.deprecate_constant(self, :PLUS_INFINITY_STR)
|
10
13
|
MINUS_INFINITY_STR = '-Infinity'.freeze
|
14
|
+
Sequel::Deprecation.deprecate_constant(self, :MINUS_INFINITY_STR)
|
11
15
|
TRUE_STR = 't'.freeze
|
16
|
+
Sequel::Deprecation.deprecate_constant(self, :TRUE_STR)
|
12
17
|
DASH_STR = '-'.freeze
|
18
|
+
Sequel::Deprecation.deprecate_constant(self, :DASH_STR)
|
13
19
|
|
14
20
|
TYPE_TRANSLATOR = tt = Class.new do
|
15
|
-
def boolean(s) s ==
|
21
|
+
def boolean(s) s == 't' end
|
16
22
|
def integer(s) s.to_i end
|
17
23
|
def float(s)
|
18
24
|
case s
|
19
|
-
when
|
25
|
+
when 'NaN'
|
20
26
|
NAN
|
21
|
-
when
|
27
|
+
when 'Infinity'
|
22
28
|
PLUS_INFINITY
|
23
|
-
when
|
29
|
+
when '-Infinity'
|
24
30
|
MINUS_INFINITY
|
25
31
|
else
|
26
32
|
s.to_f
|
27
33
|
end
|
28
34
|
end
|
29
|
-
def date(s) ::Date.new(*s.split(
|
35
|
+
def date(s) ::Date.new(*s.split('-').map(&:to_i)) end
|
30
36
|
def bytea(str)
|
31
37
|
str = if str =~ /\A\\x/
|
32
38
|
# PostgreSQL 9.0+ bytea hex format
|
@@ -44,12 +50,14 @@ module Sequel
|
|
44
50
|
# Type OIDs for string types used by PostgreSQL. These types don't
|
45
51
|
# have conversion procs associated with them (since the data is
|
46
52
|
# already in the form of a string).
|
47
|
-
STRING_TYPES = [18, 19, 25, 1042, 1043]
|
53
|
+
STRING_TYPES = [18, 19, 25, 1042, 1043]#.freeze # SEQUEL5
|
48
54
|
|
49
55
|
# Hash with type name strings/symbols and callable values for converting PostgreSQL types.
|
50
56
|
# Non-builtin types that don't have fixed numbers should use this to register
|
51
57
|
# conversion procs.
|
52
58
|
PG_NAMED_TYPES = {} unless defined?(PG_NAMED_TYPES)
|
59
|
+
PG_NAMED__TYPES = PG_NAMED_TYPES
|
60
|
+
Sequel::Deprecation.deprecate_constant(self, :PG_NAMED_TYPES)
|
53
61
|
|
54
62
|
# Hash with integer keys and callable values for converting PostgreSQL types.
|
55
63
|
PG_TYPES = {} unless defined?(PG_TYPES)
|
@@ -3,8 +3,10 @@
|
|
3
3
|
module Sequel
|
4
4
|
class Dataset
|
5
5
|
module Replace
|
6
|
-
INSERT =
|
6
|
+
INSERT = 'INSERT'.freeze
|
7
|
+
Sequel::Deprecation.deprecate_constant(self, :INSERT)
|
7
8
|
REPLACE = 'REPLACE'.freeze
|
9
|
+
Sequel::Deprecation.deprecate_constant(self, :REPLACE)
|
8
10
|
|
9
11
|
# Execute a REPLACE statement on the database (deletes any duplicate
|
10
12
|
# rows before inserting).
|
@@ -31,7 +33,7 @@ module Sequel
|
|
31
33
|
|
32
34
|
# If this is an replace instead of an insert, use replace instead
|
33
35
|
def insert_insert_sql(sql)
|
34
|
-
sql << (@opts[:replace] ? REPLACE : INSERT)
|
36
|
+
sql << (@opts[:replace] ? 'REPLACE' : 'INSERT')
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -16,8 +16,8 @@ class Sequel::SingleConnectionPool < Sequel::ConnectionPool
|
|
16
16
|
|
17
17
|
# Disconnect the connection from the database.
|
18
18
|
def disconnect(opts=nil)
|
19
|
-
return unless @conn
|
20
|
-
disconnect_connection(
|
19
|
+
return unless c = @conn.first
|
20
|
+
disconnect_connection(c)
|
21
21
|
@conn.clear
|
22
22
|
nil
|
23
23
|
end
|
data/lib/sequel/core.rb
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
module Sequel
|
25
25
|
@convert_two_digit_years = true
|
26
26
|
@datetime_class = Time
|
27
|
-
@split_symbols =
|
27
|
+
@split_symbols = :deprecated
|
28
28
|
@single_threaded = false
|
29
29
|
|
30
30
|
class << self
|
@@ -141,8 +141,8 @@ module Sequel
|
|
141
141
|
# it just loads a module that you can extend other classes with. Consult the documentation
|
142
142
|
# for each extension you plan on using for usage.
|
143
143
|
#
|
144
|
-
# Sequel.extension(:
|
145
|
-
# Sequel.extension(:
|
144
|
+
# Sequel.extension(:blank)
|
145
|
+
# Sequel.extension(:core_extensions, :named_timezones)
|
146
146
|
def self.extension(*extensions)
|
147
147
|
extensions.each{|e| Kernel.require "sequel/extensions/#{e}"}
|
148
148
|
end
|
@@ -228,9 +228,6 @@ module Sequel
|
|
228
228
|
Array(files).each{|f| super("#{File.dirname(__FILE__).untaint}/#{"#{subdir}/" if subdir}#{f}")}
|
229
229
|
end
|
230
230
|
|
231
|
-
COLUMN_REF_RE1 = /\A((?:(?!__).)+)__((?:(?!___).)+)___(.+)\z/.freeze
|
232
|
-
COLUMN_REF_RE2 = /\A((?:(?!___).)+)___(.+)\z/.freeze
|
233
|
-
COLUMN_REF_RE3 = /\A((?:(?!__).)+)__(.+)\z/.freeze
|
234
231
|
SPLIT_SYMBOL_CACHE = {}
|
235
232
|
|
236
233
|
# Splits the symbol into three parts, if symbol splitting is enabled.
|
@@ -242,13 +239,22 @@ module Sequel
|
|
242
239
|
# For tables, these parts are the schema, table, and alias.
|
243
240
|
def self.split_symbol(sym)
|
244
241
|
unless v = Sequel.synchronize{SPLIT_SYMBOL_CACHE[sym]}
|
245
|
-
if split_symbols?
|
242
|
+
if split = split_symbols?
|
246
243
|
v = case s = sym.to_s
|
247
|
-
when
|
244
|
+
when /\A((?:(?!__).)+)__((?:(?!___).)+)___(.+)\z/
|
245
|
+
if split == :deprecated
|
246
|
+
Sequel::Deprecation.deprecate("Symbol splitting", "Either set Sequel.split_symbols = true, or change #{sym.inspect} to Sequel.qualify(#{$1.inspect}, #{$2.inspect}).as(#{$3.inspect})")
|
247
|
+
end
|
248
248
|
[$1.freeze, $2.freeze, $3.freeze].freeze
|
249
|
-
when
|
249
|
+
when /\A((?:(?!___).)+)___(.+)\z/
|
250
|
+
if split == :deprecated
|
251
|
+
Sequel::Deprecation.deprecate("Symbol splitting", "Either set Sequel.split_symbols = true, or change #{sym.inspect} to Sequel.identifier(#{$1.inspect}).as(#{$2.inspect})")
|
252
|
+
end
|
250
253
|
[nil, $1.freeze, $2.freeze].freeze
|
251
|
-
when
|
254
|
+
when /\A((?:(?!__).)+)__(.+)\z/
|
255
|
+
if split == :deprecated
|
256
|
+
Sequel::Deprecation.deprecate("Symbol splitting", "Either set Sequel.split_symbols = true, or change #{sym.inspect} to Sequel.qualify(#{$1.inspect}, #{$2.inspect})")
|
257
|
+
end
|
252
258
|
[$1.freeze, $2.freeze, nil].freeze
|
253
259
|
else
|
254
260
|
[nil, s.freeze, nil].freeze
|
@@ -399,7 +405,7 @@ module Sequel
|
|
399
405
|
# <tt>SQL::VirtualRow</tt> instance.
|
400
406
|
#
|
401
407
|
# Sequel.virtual_row{a} # Sequel::SQL::Identifier.new(:a)
|
402
|
-
# Sequel.virtual_row{|o| o.a
|
408
|
+
# Sequel.virtual_row{|o| o.a} # Sequel::SQL::Function.new(:a)
|
403
409
|
def self.virtual_row(&block)
|
404
410
|
vr = VIRTUAL_ROW
|
405
411
|
case block.arity
|
@@ -452,4 +458,11 @@ module Sequel
|
|
452
458
|
|
453
459
|
# Add the database adapter class methods to Sequel via metaprogramming
|
454
460
|
def_adapter_method(*Database::ADAPTERS)
|
461
|
+
|
462
|
+
COLUMN_REF_RE1 = /\A((?:(?!__).)+)__((?:(?!___).)+)___(.+)\z/.freeze
|
463
|
+
Sequel::Deprecation.deprecate_constant(self, :COLUMN_REF_RE1)
|
464
|
+
COLUMN_REF_RE2 = /\A((?:(?!___).)+)___(.+)\z/.freeze
|
465
|
+
Sequel::Deprecation.deprecate_constant(self, :COLUMN_REF_RE2)
|
466
|
+
COLUMN_REF_RE3 = /\A((?:(?!__).)+)__(.+)\z/.freeze
|
467
|
+
Sequel::Deprecation.deprecate_constant(self, :COLUMN_REF_RE3)
|
455
468
|
end
|
@@ -27,7 +27,14 @@ module Sequel
|
|
27
27
|
def self.adapter_class(scheme)
|
28
28
|
return scheme if scheme.is_a?(Class)
|
29
29
|
|
30
|
-
|
30
|
+
if scheme.to_s.include?('-')
|
31
|
+
# :nocov:
|
32
|
+
Sequel::Deprecation.deprecate("Automatically converting '-' to '_' in adapter schemes", "Use '_' instead of '-' in the adapter scheme")
|
33
|
+
# :nocov:
|
34
|
+
end
|
35
|
+
|
36
|
+
scheme = scheme.to_s.gsub('-', '_').to_sym # SEQUEL5: Remove
|
37
|
+
# scheme = scheme.to_sym # SEQUEL5
|
31
38
|
|
32
39
|
load_adapter(scheme)
|
33
40
|
end
|
@@ -204,8 +211,7 @@ module Sequel
|
|
204
211
|
# to be the correct type, so that even if two separate Database objects are
|
205
212
|
# using different adapters you can tell that they are using the same database
|
206
213
|
# type. Even better, you can tell that two Database objects that are using
|
207
|
-
# the same adapter are connecting to different database types
|
208
|
-
# DataObjects).
|
214
|
+
# the same adapter are connecting to different database types.
|
209
215
|
#
|
210
216
|
# Sequel.connect('jdbc:postgres://...').database_type # => :postgres
|
211
217
|
def database_type
|
@@ -9,6 +9,7 @@ module Sequel
|
|
9
9
|
|
10
10
|
# The default class to use for datasets
|
11
11
|
DatasetClass = Sequel::Dataset
|
12
|
+
Sequel::Deprecation.deprecate_constant(self, :DatasetClass)
|
12
13
|
|
13
14
|
# SEQUEL5: Remove
|
14
15
|
@identifier_input_method = nil
|
@@ -98,7 +99,12 @@ module Sequel
|
|
98
99
|
|
99
100
|
# The default dataset class to use for the database
|
100
101
|
def dataset_class_default
|
101
|
-
self.class
|
102
|
+
if self.class == Sequel::Database
|
103
|
+
Sequel::Dataset
|
104
|
+
else
|
105
|
+
Sequel::Deprecation.deprecate("Using self.class.const_get(:DatasetClass) to get the default dataset class", "Modify the database adapter to implement Database#dataset_class_default")
|
106
|
+
self.class.const_get(:DatasetClass)
|
107
|
+
end
|
102
108
|
end
|
103
109
|
|
104
110
|
# Reset the default dataset used by most Database methods that
|
@@ -35,6 +35,7 @@ module Sequel
|
|
35
35
|
# Yield to the block, logging any errors at error level to all loggers,
|
36
36
|
# and all other queries with the duration at warn or info level.
|
37
37
|
def log_yield(sql, args=nil, &block)
|
38
|
+
Sequel::Deprecation.deprecate("Sequel::Database#log_yield", "Update the adapter to use Sequel::Database#log_connection_yield")
|
38
39
|
log_connection_yield(sql, nil, args, &block)
|
39
40
|
end
|
40
41
|
|
data/lib/sequel/database/misc.rb
CHANGED
@@ -151,6 +151,7 @@ module Sequel
|
|
151
151
|
reset_default_dataset
|
152
152
|
adapter_initialize
|
153
153
|
if typecast_value_boolean(@opts.fetch(:identifier_mangling, true))
|
154
|
+
# SEQUEL5: Remove
|
154
155
|
extension(:_deprecated_identifier_mangling)
|
155
156
|
end
|
156
157
|
|
@@ -504,11 +505,13 @@ module Sequel
|
|
504
505
|
|
505
506
|
# Used for checking/removing leading zeroes from strings so they don't get
|
506
507
|
# interpreted as octal.
|
507
|
-
LEADING_ZERO_RE = /\A0+(\d)
|
508
|
+
LEADING_ZERO_RE = /\A0+(\d)/
|
509
|
+
Sequel::Deprecation.deprecate_constant(self, :LEADING_ZERO_RE)
|
510
|
+
|
508
511
|
if RUBY_VERSION >= '1.9'
|
509
512
|
# Typecast the value to an Integer
|
510
513
|
def typecast_value_integer(value)
|
511
|
-
(value.is_a?(String) && value =~
|
514
|
+
(value.is_a?(String) && value =~ /\A0+(\d)/) ? Integer(value, 10) : Integer(value)
|
512
515
|
end
|
513
516
|
else
|
514
517
|
# :nocov:
|
@@ -8,9 +8,11 @@ module Sequel
|
|
8
8
|
# ---------------------
|
9
9
|
|
10
10
|
STRING_DEFAULT_RE = /\A'(.*)'\z/
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
Sequel::Deprecation.deprecate_constant(self, :STRING_DEFAULT_RE)
|
12
|
+
CURRENT_TIMESTAMP_RE = /now|today|CURRENT|getdate|\ADate\(\)\z/i
|
13
|
+
Sequel::Deprecation.deprecate_constant(self, :CURRENT_TIMESTAMP_RE)
|
14
|
+
COLUMN_SCHEMA_DATETIME_TYPES = [:date, :datetime]#.freeze # SEQUEL5
|
15
|
+
COLUMN_SCHEMA_STRING_TYPES = [:string, :blob, :date, :datetime, :time, :enum, :set, :interval]#.freeze # SEQUEL5
|
14
16
|
|
15
17
|
# The prepared statement object hash for this database, keyed by name symbol
|
16
18
|
attr_reader :prepared_statements
|
@@ -248,7 +250,7 @@ module Sequel
|
|
248
250
|
# and return the normalized value.
|
249
251
|
def column_schema_normalize_default(default, type)
|
250
252
|
if column_schema_default_string_type?(type)
|
251
|
-
return unless m =
|
253
|
+
return unless m = /\A'(.*)'\z/.match(default)
|
252
254
|
m[1].gsub("''", "'")
|
253
255
|
else
|
254
256
|
default
|
@@ -260,7 +262,7 @@ module Sequel
|
|
260
262
|
def column_schema_to_ruby_default(default, type)
|
261
263
|
return default unless default.is_a?(String)
|
262
264
|
if COLUMN_SCHEMA_DATETIME_TYPES.include?(type)
|
263
|
-
if
|
265
|
+
if /now|today|CURRENT|getdate|\ADate\(\)\z/i.match(default)
|
264
266
|
if type == :date
|
265
267
|
return Sequel::CURRENT_DATE
|
266
268
|
else
|
@@ -316,6 +316,7 @@ module Sequel
|
|
316
316
|
|
317
317
|
# Alias of CreateTableGenerator for backwards compatibility.
|
318
318
|
Generator = CreateTableGenerator
|
319
|
+
Sequel::Deprecation.deprecate_constant(self, :Generator)
|
319
320
|
|
320
321
|
# Schema::AlterTableGenerator is an internal class that the user is not expected
|
321
322
|
# to instantiate directly. Instances are created by Database#alter_table.
|
@@ -8,25 +8,33 @@ module Sequel
|
|
8
8
|
# ---------------------
|
9
9
|
|
10
10
|
AUTOINCREMENT = 'AUTOINCREMENT'.freeze
|
11
|
+
Sequel::Deprecation.deprecate_constant(self, :AUTOINCREMENT)
|
11
12
|
COMMA_SEPARATOR = ', '.freeze
|
13
|
+
Sequel::Deprecation.deprecate_constant(self, :COMMA_SEPARATOR)
|
12
14
|
NOT_NULL = ' NOT NULL'.freeze
|
15
|
+
Sequel::Deprecation.deprecate_constant(self, :NOT_NULL)
|
13
16
|
NULL = ' NULL'.freeze
|
17
|
+
Sequel::Deprecation.deprecate_constant(self, :NULL)
|
14
18
|
PRIMARY_KEY = ' PRIMARY KEY'.freeze
|
19
|
+
Sequel::Deprecation.deprecate_constant(self, :PRIMARY_KEY)
|
15
20
|
TEMPORARY = 'TEMPORARY '.freeze
|
21
|
+
Sequel::Deprecation.deprecate_constant(self, :TEMPORARY)
|
16
22
|
UNDERSCORE = '_'.freeze
|
23
|
+
Sequel::Deprecation.deprecate_constant(self, :UNDERSCORE)
|
17
24
|
UNIQUE = ' UNIQUE'.freeze
|
25
|
+
Sequel::Deprecation.deprecate_constant(self, :UNIQUE)
|
18
26
|
UNSIGNED = ' UNSIGNED'.freeze
|
27
|
+
Sequel::Deprecation.deprecate_constant(self, :UNSIGNED)
|
28
|
+
DEFAULT_JOIN_TABLE_COLUMN_OPTIONS = {:null=>false}
|
29
|
+
Sequel::Deprecation.deprecate_constant(self, :DEFAULT_JOIN_TABLE_COLUMN_OPTIONS)
|
19
30
|
|
20
31
|
# The order of column modifiers to use when defining a column.
|
21
|
-
COLUMN_DEFINITION_ORDER = [:collate, :default, :null, :unique, :primary_key, :auto_increment, :references]
|
22
|
-
|
23
|
-
# The default options for join table columns.
|
24
|
-
DEFAULT_JOIN_TABLE_COLUMN_OPTIONS = {:null=>false}
|
32
|
+
COLUMN_DEFINITION_ORDER = [:collate, :default, :null, :unique, :primary_key, :auto_increment, :references]#.freeze # SEQUEL5
|
25
33
|
|
26
34
|
# The alter table operations that are combinable.
|
27
35
|
COMBINABLE_ALTER_TABLE_OPS = [:add_column, :drop_column, :rename_column,
|
28
36
|
:set_column_type, :set_column_default, :set_column_null,
|
29
|
-
:add_constraint, :drop_constraint]
|
37
|
+
:add_constraint, :drop_constraint]#.freeze # SEQUEL5
|
30
38
|
|
31
39
|
# Adds a column to the specified table. This method expects a column name,
|
32
40
|
# a datatype and optionally a hash with additional constraints and options:
|
@@ -75,8 +83,13 @@ module Sequel
|
|
75
83
|
# available for index definition.
|
76
84
|
#
|
77
85
|
# See <tt>Schema::AlterTableGenerator</tt> and the {"Migrations and Schema Modification" guide}[rdoc-ref:doc/migration.rdoc].
|
78
|
-
def alter_table(name, generator=nil, &block)
|
79
|
-
generator
|
86
|
+
def alter_table(name, generator=(arg_not_given=true; nil), &block)
|
87
|
+
if generator
|
88
|
+
Sequel::Deprecation.deprecate("Passing a Sequel::Schema::AlterTableGenerator instance as the second argument to Sequel::Database#alter_table ", "Pass a block to Sequel::Database#alter_table instead")
|
89
|
+
else
|
90
|
+
Sequel::Deprecation.deprecate("Passing a second argument to Sequel::Database#alter_table :generator option", "Pass only a single argument to the method") unless arg_not_given
|
91
|
+
generator = alter_table_generator(&block)
|
92
|
+
end
|
80
93
|
remove_cached_schema(name)
|
81
94
|
apply_alter_table_generator(name, generator)
|
82
95
|
nil
|
@@ -128,7 +141,7 @@ module Sequel
|
|
128
141
|
unless v.is_a?(Hash)
|
129
142
|
v = {:table=>v}
|
130
143
|
end
|
131
|
-
v =
|
144
|
+
v[:null] = false unless v.has_key?(:null)
|
132
145
|
foreign_key(key, v)
|
133
146
|
end
|
134
147
|
primary_key(keys) unless options[:no_primary_key]
|
@@ -185,10 +198,13 @@ module Sequel
|
|
185
198
|
# that option names are unquoted, so you should not use untrusted
|
186
199
|
# keys.
|
187
200
|
#
|
188
|
-
# See <tt>Schema::
|
201
|
+
# See <tt>Schema::CreateTableGenerator</tt> and the {"Schema Modification" guide}[rdoc-ref:doc/schema_modification.rdoc].
|
189
202
|
def create_table(name, options=OPTS, &block)
|
190
203
|
remove_cached_schema(name)
|
191
|
-
|
204
|
+
if options.is_a?(Schema::CreateTableGenerator)
|
205
|
+
Sequel::Deprecation.deprecate("Passing a Sequel::Schema::CreateTableGenerator instance as the second argument to Sequel::Database#create_table", "Use the Sequel::Database#create_table :generator option instead")
|
206
|
+
options = {:generator=>options}
|
207
|
+
end
|
192
208
|
if sql = options[:as]
|
193
209
|
raise(Error, "can't provide both :as option and block to create_table") if block
|
194
210
|
create_table_as(name, sql, options)
|
@@ -530,12 +546,12 @@ module Sequel
|
|
530
546
|
# The SQL string specify the autoincrement property, generally used by
|
531
547
|
# primary keys.
|
532
548
|
def auto_increment_sql
|
533
|
-
AUTOINCREMENT
|
549
|
+
'AUTOINCREMENT'
|
534
550
|
end
|
535
551
|
|
536
552
|
# The order of the column definition, as an array of symbols.
|
537
553
|
def column_definition_order
|
538
|
-
|
554
|
+
COLUMN_DEFINITION_ORDER
|
539
555
|
end
|
540
556
|
|
541
557
|
# SQL DDL fragment containing the column creation SQL for the given column.
|
@@ -572,9 +588,9 @@ module Sequel
|
|
572
588
|
|
573
589
|
case null
|
574
590
|
when false
|
575
|
-
sql <<
|
591
|
+
sql << ' NOT NULL'
|
576
592
|
when true
|
577
|
-
sql << NULL
|
593
|
+
sql << ' NULL'
|
578
594
|
end
|
579
595
|
end
|
580
596
|
|
@@ -584,7 +600,7 @@ module Sequel
|
|
584
600
|
if name = column[:primary_key_constraint_name]
|
585
601
|
sql << " CONSTRAINT #{quote_identifier(name)}"
|
586
602
|
end
|
587
|
-
sql <<
|
603
|
+
sql << ' PRIMARY KEY'
|
588
604
|
end
|
589
605
|
end
|
590
606
|
|
@@ -604,13 +620,13 @@ module Sequel
|
|
604
620
|
if name = column[:unique_constraint_name]
|
605
621
|
sql << " CONSTRAINT #{quote_identifier(name)}"
|
606
622
|
end
|
607
|
-
sql << UNIQUE
|
623
|
+
sql << ' UNIQUE'
|
608
624
|
end
|
609
625
|
end
|
610
626
|
|
611
627
|
# SQL for all given columns, used inside a CREATE TABLE block.
|
612
628
|
def column_list_sql(generator)
|
613
|
-
(generator.columns.map{|c| column_definition_sql(c)} + generator.constraints.map{|c| constraint_definition_sql(c)}).join(
|
629
|
+
(generator.columns.map{|c| column_definition_sql(c)} + generator.constraints.map{|c| constraint_definition_sql(c)}).join(', ')
|
614
630
|
end
|
615
631
|
|
616
632
|
# SQL DDL fragment for column foreign key references (column constraints)
|
@@ -622,7 +638,7 @@ module Sequel
|
|
622
638
|
def column_references_sql(column)
|
623
639
|
sql = String.new
|
624
640
|
sql << " REFERENCES #{quote_schema_table(column[:table])}"
|
625
|
-
sql << "(#{Array(column[:key]).map{|x| quote_identifier(x)}.join(
|
641
|
+
sql << "(#{Array(column[:key]).map{|x| quote_identifier(x)}.join(', ')})" if column[:key]
|
626
642
|
sql << " ON DELETE #{on_delete_clause(column[:on_delete])}" if column[:on_delete]
|
627
643
|
sql << " ON UPDATE #{on_update_clause(column[:on_update])}" if column[:on_update]
|
628
644
|
constraint_deferrable_sql_append(sql, column[:deferrable])
|
@@ -636,7 +652,6 @@ module Sequel
|
|
636
652
|
|
637
653
|
# Whether the given alter table operation is combinable.
|
638
654
|
def combinable_alter_table_op?(op)
|
639
|
-
# Use a dynamic lookup for easier overriding in adapters
|
640
655
|
COMBINABLE_ALTER_TABLE_OPS.include?(op[:op])
|
641
656
|
end
|
642
657
|
|
@@ -768,9 +783,8 @@ module Sequel
|
|
768
783
|
|
769
784
|
# Append the column list to the SQL, if a column list is given.
|
770
785
|
def create_view_sql_append_columns(sql, columns)
|
771
|
-
sql = sql.dup
|
772
786
|
if columns
|
773
|
-
sql
|
787
|
+
sql += ' ('
|
774
788
|
schema_utility_dataset.send(:identifier_list_append, sql, columns)
|
775
789
|
sql << ')'
|
776
790
|
end
|
@@ -781,7 +795,7 @@ module Sequel
|
|
781
795
|
# for certain databases.
|
782
796
|
def default_index_name(table_name, columns)
|
783
797
|
schema, table = schema_and_table(table_name)
|
784
|
-
"#{"#{schema}_" if schema}#{table}_#{columns.map{|c| [String, Symbol].any?{|cl| c.is_a?(cl)} ? c : literal(c).gsub(/\W/, '_')}.join(
|
798
|
+
"#{"#{schema}_" if schema}#{table}_#{columns.map{|c| [String, Symbol].any?{|cl| c.is_a?(cl)} ? c : literal(c).gsub(/\W/, '_')}.join('_')}_index"
|
785
799
|
end
|
786
800
|
|
787
801
|
# Get foreign key name for given table and columns.
|
@@ -807,10 +821,19 @@ module Sequel
|
|
807
821
|
end
|
808
822
|
|
809
823
|
# Proxy the filter_expr call to the dataset, used for creating constraints.
|
824
|
+
# Support passing Proc arguments as blocks, as well as treating plain strings
|
825
|
+
# as literal strings, so that previous migrations that used this API do not break.
|
810
826
|
def filter_expr(*args, &block)
|
811
|
-
if args.length == 1
|
812
|
-
|
813
|
-
|
827
|
+
if args.length == 1
|
828
|
+
arg = args.first
|
829
|
+
if arg.is_a?(Proc) && !block
|
830
|
+
block = args.first
|
831
|
+
args = nil
|
832
|
+
elsif arg.is_a?(String)
|
833
|
+
args = [Sequel.lit(*args)]
|
834
|
+
elsif arg.is_a?(Array) && arg.first.is_a?(String)
|
835
|
+
args = [Sequel.lit(*arg)]
|
836
|
+
end
|
814
837
|
end
|
815
838
|
schema_utility_dataset.literal(schema_utility_dataset.send(:filter_expr, *args, &block))
|
816
839
|
end
|
@@ -910,7 +933,7 @@ module Sequel
|
|
910
933
|
|
911
934
|
# SQL DDL fragment for temporary table
|
912
935
|
def temporary_table_sql
|
913
|
-
|
936
|
+
'TEMPORARY '
|
914
937
|
end
|
915
938
|
|
916
939
|
# SQL fragment specifying the type of a given column.
|
@@ -1020,7 +1043,7 @@ module Sequel
|
|
1020
1043
|
type = "double precision" if type.to_s == 'double'
|
1021
1044
|
column[:size] ||= default_string_column_size if type.to_s == 'varchar'
|
1022
1045
|
elements = column[:size] || column[:elements]
|
1023
|
-
"#{type}#{literal(Array(elements)) if elements}#{UNSIGNED if column[:unsigned]}"
|
1046
|
+
"#{type}#{literal(Array(elements)) if elements}#{' UNSIGNED' if column[:unsigned]}"
|
1024
1047
|
end
|
1025
1048
|
|
1026
1049
|
# Whether clob should be used for String :text=>true columns.
|