sequel 4.45.0 → 4.46.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 +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
data/lib/sequel/dataset/sql.rb
CHANGED
|
@@ -30,7 +30,7 @@ module Sequel
|
|
|
30
30
|
when 0
|
|
31
31
|
return insert_sql({})
|
|
32
32
|
when 1
|
|
33
|
-
case vals = values
|
|
33
|
+
case vals = values[0]
|
|
34
34
|
when Hash
|
|
35
35
|
values = []
|
|
36
36
|
vals.each do |k,v|
|
|
@@ -41,7 +41,7 @@ module Sequel
|
|
|
41
41
|
values = vals
|
|
42
42
|
end
|
|
43
43
|
when 2
|
|
44
|
-
if (v0 = values
|
|
44
|
+
if (v0 = values[0]).is_a?(Array) && ((v1 = values[1]).is_a?(Array) || v1.is_a?(Dataset) || v1.is_a?(LiteralString))
|
|
45
45
|
columns, values = v0, v1
|
|
46
46
|
raise(Error, "Different number of values and columns given to insert_sql") if values.is_a?(Array) and columns.length != values.length
|
|
47
47
|
end
|
|
@@ -124,13 +124,13 @@ module Sequel
|
|
|
124
124
|
when :union
|
|
125
125
|
c = false
|
|
126
126
|
sql = LiteralString.new
|
|
127
|
-
u =
|
|
127
|
+
u = ' UNION ALL SELECT '
|
|
128
128
|
f = empty_from_sql
|
|
129
129
|
values.each do |v|
|
|
130
130
|
if c
|
|
131
131
|
sql << u
|
|
132
132
|
else
|
|
133
|
-
sql << SELECT
|
|
133
|
+
sql << 'SELECT '
|
|
134
134
|
c = true
|
|
135
135
|
end
|
|
136
136
|
expression_list_append(sql, v)
|
|
@@ -174,6 +174,15 @@ module Sequel
|
|
|
174
174
|
return static_sql(opts[:sql]) if opts[:sql]
|
|
175
175
|
check_modification_allowed!
|
|
176
176
|
check_not_limited!(:update)
|
|
177
|
+
|
|
178
|
+
case values
|
|
179
|
+
when LiteralString
|
|
180
|
+
# nothing
|
|
181
|
+
when String
|
|
182
|
+
Sequel::Deprecation.deprecate("Calling Sequel::Dataset#update/update_sql with a plain string", "Use Sequel.lit(#{values.inspect}) to create a literal string and pass that to update/update_sql, or use the auto_literal_strings extension")
|
|
183
|
+
# raise Error, "plain string passed to Dataset#update" # SEQUEL5
|
|
184
|
+
end
|
|
185
|
+
|
|
177
186
|
clone(:values=>values).send(:_update_sql)
|
|
178
187
|
end
|
|
179
188
|
|
|
@@ -232,116 +241,211 @@ module Sequel
|
|
|
232
241
|
def_sql_method(self, :select, %w'with select distinct columns from join where group having compounds order limit lock')
|
|
233
242
|
def_sql_method(self, :update, %w'update table set where')
|
|
234
243
|
|
|
235
|
-
|
|
244
|
+
WILDCARD = LiteralString.new('*').freeze
|
|
245
|
+
COUNT_OF_ALL_AS_COUNT = SQL::Function.new(:count, WILDCARD).as(:count)
|
|
246
|
+
DEFAULT = LiteralString.new('DEFAULT').freeze
|
|
247
|
+
|
|
248
|
+
EXISTS = ['EXISTS '.freeze].freeze
|
|
249
|
+
BITWISE_METHOD_MAP = {:& =>:BITAND, :| => :BITOR, :^ => :BITXOR}#.freeze # SEQUEL5
|
|
250
|
+
COUNT_FROM_SELF_OPTS = [:distinct, :group, :sql, :limit, :offset, :compounds]#.freeze # SEQUEL5
|
|
251
|
+
IS_LITERALS = {nil=>'NULL'.freeze, true=>'TRUE'.freeze, false=>'FALSE'.freeze}.freeze
|
|
252
|
+
QUALIFY_KEYS = [:select, :where, :having, :order, :group]#.freeze # SEQUEL5
|
|
253
|
+
|
|
254
|
+
IS_OPERATORS = ::Sequel::SQL::ComplexExpression::IS_OPERATORS
|
|
255
|
+
LIKE_OPERATORS = ::Sequel::SQL::ComplexExpression::LIKE_OPERATORS
|
|
256
|
+
N_ARITY_OPERATORS = ::Sequel::SQL::ComplexExpression::N_ARITY_OPERATORS
|
|
257
|
+
TWO_ARITY_OPERATORS = ::Sequel::SQL::ComplexExpression::TWO_ARITY_OPERATORS
|
|
258
|
+
REGEXP_OPERATORS = ::Sequel::SQL::ComplexExpression::REGEXP_OPERATORS
|
|
259
|
+
|
|
236
260
|
EMULATED_FUNCTION_MAP = {}
|
|
261
|
+
Sequel::Deprecation.deprecate_constant(self, :EMULATED_FUNCTION_MAP)
|
|
237
262
|
|
|
238
|
-
WILDCARD = LiteralString.new('*').freeze
|
|
239
263
|
ALL = ' ALL'.freeze
|
|
264
|
+
Sequel::Deprecation.deprecate_constant(self, :ALL)
|
|
240
265
|
AND_SEPARATOR = " AND ".freeze
|
|
266
|
+
Sequel::Deprecation.deprecate_constant(self, :AND_SEPARATOR)
|
|
241
267
|
APOS = "'".freeze
|
|
268
|
+
Sequel::Deprecation.deprecate_constant(self, :APOS)
|
|
242
269
|
APOS_RE = /'/.freeze
|
|
270
|
+
Sequel::Deprecation.deprecate_constant(self, :APOS_RE)
|
|
243
271
|
ARRAY_EMPTY = '(NULL)'.freeze
|
|
272
|
+
Sequel::Deprecation.deprecate_constant(self, :ARRAY_EMPTY)
|
|
244
273
|
AS = ' AS '.freeze
|
|
274
|
+
Sequel::Deprecation.deprecate_constant(self, :AS)
|
|
245
275
|
ASC = ' ASC'.freeze
|
|
276
|
+
Sequel::Deprecation.deprecate_constant(self, :ASC)
|
|
246
277
|
BACKSLASH = "\\".freeze
|
|
278
|
+
Sequel::Deprecation.deprecate_constant(self, :BACKSLASH)
|
|
247
279
|
BITCOMP_CLOSE = ") - 1)".freeze
|
|
280
|
+
Sequel::Deprecation.deprecate_constant(self, :BITCOMP_CLOSE)
|
|
248
281
|
BITCOMP_OPEN = "((0 - ".freeze
|
|
249
|
-
|
|
282
|
+
Sequel::Deprecation.deprecate_constant(self, :BITCOMP_OPEN)
|
|
250
283
|
BOOL_FALSE = "'f'".freeze
|
|
284
|
+
Sequel::Deprecation.deprecate_constant(self, :BOOL_FALSE)
|
|
251
285
|
BOOL_TRUE = "'t'".freeze
|
|
286
|
+
Sequel::Deprecation.deprecate_constant(self, :BOOL_TRUE)
|
|
252
287
|
BRACKET_CLOSE = ']'.freeze
|
|
288
|
+
Sequel::Deprecation.deprecate_constant(self, :BRACKET_CLOSE)
|
|
253
289
|
BRACKET_OPEN = '['.freeze
|
|
290
|
+
Sequel::Deprecation.deprecate_constant(self, :BRACKET_OPEN)
|
|
254
291
|
CASE_ELSE = " ELSE ".freeze
|
|
292
|
+
Sequel::Deprecation.deprecate_constant(self, :CASE_ELSE)
|
|
255
293
|
CASE_END = " END)".freeze
|
|
294
|
+
Sequel::Deprecation.deprecate_constant(self, :CASE_END)
|
|
256
295
|
CASE_OPEN = '(CASE'.freeze
|
|
296
|
+
Sequel::Deprecation.deprecate_constant(self, :CASE_OPEN)
|
|
257
297
|
CASE_THEN = " THEN ".freeze
|
|
298
|
+
Sequel::Deprecation.deprecate_constant(self, :CASE_THEN)
|
|
258
299
|
CASE_WHEN = " WHEN ".freeze
|
|
300
|
+
Sequel::Deprecation.deprecate_constant(self, :CASE_WHEN)
|
|
259
301
|
CAST_OPEN = 'CAST('.freeze
|
|
302
|
+
Sequel::Deprecation.deprecate_constant(self, :CAST_OPEN)
|
|
260
303
|
COLON = ':'.freeze
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
304
|
+
Sequel::Deprecation.deprecate_constant(self, :COLON)
|
|
305
|
+
COLUMN_REF_RE1 = /\A((?:(?!__).)+)__((?:(?!___).)+)___(.+)\z/.freeze
|
|
306
|
+
Sequel::Deprecation.deprecate_constant(self, :COLUMN_REF_RE1)
|
|
307
|
+
COLUMN_REF_RE2 = /\A((?:(?!___).)+)___(.+)\z/.freeze
|
|
308
|
+
Sequel::Deprecation.deprecate_constant(self, :COLUMN_REF_RE2)
|
|
309
|
+
COLUMN_REF_RE3 = /\A((?:(?!__).)+)__(.+)\z/.freeze
|
|
310
|
+
Sequel::Deprecation.deprecate_constant(self, :COLUMN_REF_RE3)
|
|
264
311
|
COMMA = ', '.freeze
|
|
265
|
-
|
|
312
|
+
Sequel::Deprecation.deprecate_constant(self, :COMMA)
|
|
313
|
+
COMMA_SEPARATOR = ', '.freeze
|
|
314
|
+
Sequel::Deprecation.deprecate_constant(self, :COMMA_SEPARATOR)
|
|
266
315
|
CONDITION_FALSE = '(1 = 0)'.freeze
|
|
316
|
+
Sequel::Deprecation.deprecate_constant(self, :CONDITION_FALSE)
|
|
267
317
|
CONDITION_TRUE = '(1 = 1)'.freeze
|
|
268
|
-
|
|
269
|
-
COUNT_OF_ALL_AS_COUNT = SQL::Function.new(:count, WILDCARD).as(:count)
|
|
318
|
+
Sequel::Deprecation.deprecate_constant(self, :CONDITION_TRUE)
|
|
270
319
|
DATASET_ALIAS_BASE_NAME = 't'.freeze
|
|
271
|
-
|
|
320
|
+
Sequel::Deprecation.deprecate_constant(self, :DATASET_ALIAS_BASE_NAME)
|
|
321
|
+
DATETIME_SECFRACTION_ARG = RUBY_VERSION >= '1.9.0' ? 1000000 : 86400000000
|
|
322
|
+
Sequel::Deprecation.deprecate_constant(self, :DATETIME_SECFRACTION_ARG)
|
|
272
323
|
DEFAULT_VALUES = " DEFAULT VALUES".freeze
|
|
324
|
+
Sequel::Deprecation.deprecate_constant(self, :DEFAULT_VALUES)
|
|
273
325
|
DELETE = 'DELETE'.freeze
|
|
326
|
+
Sequel::Deprecation.deprecate_constant(self, :DELETE)
|
|
274
327
|
DESC = ' DESC'.freeze
|
|
328
|
+
Sequel::Deprecation.deprecate_constant(self, :DESC)
|
|
275
329
|
DISTINCT = " DISTINCT".freeze
|
|
330
|
+
Sequel::Deprecation.deprecate_constant(self, :DISTINCT)
|
|
276
331
|
DOT = '.'.freeze
|
|
332
|
+
Sequel::Deprecation.deprecate_constant(self, :DOT)
|
|
277
333
|
DOUBLE_APOS = "''".freeze
|
|
334
|
+
Sequel::Deprecation.deprecate_constant(self, :DOUBLE_APOS)
|
|
278
335
|
DOUBLE_QUOTE = '""'.freeze
|
|
336
|
+
Sequel::Deprecation.deprecate_constant(self, :DOUBLE_QUOTE)
|
|
279
337
|
EQUAL = ' = '.freeze
|
|
338
|
+
Sequel::Deprecation.deprecate_constant(self, :EQUAL)
|
|
280
339
|
EMPTY_PARENS = '()'.freeze
|
|
340
|
+
Sequel::Deprecation.deprecate_constant(self, :EMPTY_PARENS)
|
|
281
341
|
ESCAPE = " ESCAPE ".freeze
|
|
342
|
+
Sequel::Deprecation.deprecate_constant(self, :ESCAPE)
|
|
282
343
|
EXTRACT = 'extract('.freeze
|
|
283
|
-
|
|
344
|
+
Sequel::Deprecation.deprecate_constant(self, :EXTRACT)
|
|
284
345
|
FILTER = " FILTER (WHERE ".freeze
|
|
346
|
+
Sequel::Deprecation.deprecate_constant(self, :FILTER)
|
|
285
347
|
FOR_UPDATE = ' FOR UPDATE'.freeze
|
|
348
|
+
Sequel::Deprecation.deprecate_constant(self, :FOR_UPDATE)
|
|
286
349
|
FORMAT_DATE = "'%Y-%m-%d'".freeze
|
|
350
|
+
Sequel::Deprecation.deprecate_constant(self, :FORMAT_DATE)
|
|
287
351
|
FORMAT_DATE_STANDARD = "DATE '%Y-%m-%d'".freeze
|
|
352
|
+
Sequel::Deprecation.deprecate_constant(self, :FORMAT_DATE_STANDARD)
|
|
288
353
|
FORMAT_OFFSET = "%+03i%02i".freeze
|
|
354
|
+
Sequel::Deprecation.deprecate_constant(self, :FORMAT_OFFSET)
|
|
289
355
|
FORMAT_TIMESTAMP_RE = /%[Nz]/.freeze
|
|
356
|
+
Sequel::Deprecation.deprecate_constant(self, :FORMAT_TIMESTAMP_RE)
|
|
290
357
|
FORMAT_USEC = '%N'.freeze
|
|
358
|
+
Sequel::Deprecation.deprecate_constant(self, :FORMAT_USEC)
|
|
291
359
|
FRAME_ALL = "ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING".freeze
|
|
360
|
+
Sequel::Deprecation.deprecate_constant(self, :FRAME_ALL)
|
|
292
361
|
FRAME_ROWS = "ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW".freeze
|
|
362
|
+
Sequel::Deprecation.deprecate_constant(self, :FRAME_ROWS)
|
|
293
363
|
FROM = ' FROM '.freeze
|
|
364
|
+
Sequel::Deprecation.deprecate_constant(self, :FROM)
|
|
294
365
|
FUNCTION_DISTINCT = "DISTINCT ".freeze
|
|
366
|
+
Sequel::Deprecation.deprecate_constant(self, :FUNCTION_DISTINCT)
|
|
295
367
|
GROUP_BY = " GROUP BY ".freeze
|
|
368
|
+
Sequel::Deprecation.deprecate_constant(self, :GROUP_BY)
|
|
296
369
|
HAVING = " HAVING ".freeze
|
|
370
|
+
Sequel::Deprecation.deprecate_constant(self, :HAVING)
|
|
297
371
|
INSERT = "INSERT".freeze
|
|
372
|
+
Sequel::Deprecation.deprecate_constant(self, :INSERT)
|
|
298
373
|
INTO = " INTO ".freeze
|
|
299
|
-
|
|
300
|
-
IS_OPERATORS = ::Sequel::SQL::ComplexExpression::IS_OPERATORS
|
|
374
|
+
Sequel::Deprecation.deprecate_constant(self, :INTO)
|
|
301
375
|
LATERAL = 'LATERAL '.freeze
|
|
302
|
-
|
|
376
|
+
Sequel::Deprecation.deprecate_constant(self, :LATERAL)
|
|
303
377
|
LIMIT = " LIMIT ".freeze
|
|
304
|
-
|
|
378
|
+
Sequel::Deprecation.deprecate_constant(self, :LIMIT)
|
|
305
379
|
NOT_SPACE = 'NOT '.freeze
|
|
380
|
+
Sequel::Deprecation.deprecate_constant(self, :NOT_SPACE)
|
|
306
381
|
NULL = "NULL".freeze
|
|
382
|
+
Sequel::Deprecation.deprecate_constant(self, :NULL)
|
|
307
383
|
NULLS_FIRST = " NULLS FIRST".freeze
|
|
384
|
+
Sequel::Deprecation.deprecate_constant(self, :NULLS_FIRST)
|
|
308
385
|
NULLS_LAST = " NULLS LAST".freeze
|
|
386
|
+
Sequel::Deprecation.deprecate_constant(self, :NULLS_LAST)
|
|
309
387
|
OFFSET = " OFFSET ".freeze
|
|
388
|
+
Sequel::Deprecation.deprecate_constant(self, :OFFSET)
|
|
310
389
|
ON = ' ON '.freeze
|
|
390
|
+
Sequel::Deprecation.deprecate_constant(self, :ON)
|
|
311
391
|
ON_PAREN = " ON (".freeze
|
|
392
|
+
Sequel::Deprecation.deprecate_constant(self, :ON_PAREN)
|
|
312
393
|
ORDER_BY = " ORDER BY ".freeze
|
|
394
|
+
Sequel::Deprecation.deprecate_constant(self, :ORDER_BY)
|
|
313
395
|
ORDER_BY_NS = "ORDER BY ".freeze
|
|
396
|
+
Sequel::Deprecation.deprecate_constant(self, :ORDER_BY_NS)
|
|
314
397
|
OVER = ' OVER '.freeze
|
|
398
|
+
Sequel::Deprecation.deprecate_constant(self, :OVER)
|
|
315
399
|
PAREN_CLOSE = ')'.freeze
|
|
400
|
+
Sequel::Deprecation.deprecate_constant(self, :PAREN_CLOSE)
|
|
316
401
|
PAREN_OPEN = '('.freeze
|
|
402
|
+
Sequel::Deprecation.deprecate_constant(self, :PAREN_OPEN)
|
|
317
403
|
PAREN_SPACE_OPEN = ' ('.freeze
|
|
404
|
+
Sequel::Deprecation.deprecate_constant(self, :PAREN_SPACE_OPEN)
|
|
318
405
|
PARTITION_BY = "PARTITION BY ".freeze
|
|
319
|
-
|
|
406
|
+
Sequel::Deprecation.deprecate_constant(self, :PARTITION_BY)
|
|
320
407
|
QUESTION_MARK = '?'.freeze
|
|
408
|
+
Sequel::Deprecation.deprecate_constant(self, :QUESTION_MARK)
|
|
321
409
|
QUESTION_MARK_RE = /\?/.freeze
|
|
410
|
+
Sequel::Deprecation.deprecate_constant(self, :QUESTION_MARK_RE)
|
|
322
411
|
QUOTE = '"'.freeze
|
|
412
|
+
Sequel::Deprecation.deprecate_constant(self, :QUOTE)
|
|
323
413
|
QUOTE_RE = /"/.freeze
|
|
414
|
+
Sequel::Deprecation.deprecate_constant(self, :QUOTE_RE)
|
|
324
415
|
RETURNING = " RETURNING ".freeze
|
|
416
|
+
Sequel::Deprecation.deprecate_constant(self, :RETURNING)
|
|
325
417
|
SELECT = 'SELECT'.freeze
|
|
418
|
+
Sequel::Deprecation.deprecate_constant(self, :SELECT)
|
|
326
419
|
SET = ' SET '.freeze
|
|
420
|
+
Sequel::Deprecation.deprecate_constant(self, :SET)
|
|
327
421
|
SPACE = ' '.freeze
|
|
422
|
+
Sequel::Deprecation.deprecate_constant(self, :SPACE)
|
|
328
423
|
SQL_WITH = "WITH ".freeze
|
|
424
|
+
Sequel::Deprecation.deprecate_constant(self, :SQL_WITH)
|
|
329
425
|
SPACE_WITH = " WITH ".freeze
|
|
426
|
+
Sequel::Deprecation.deprecate_constant(self, :SPACE_WITH)
|
|
330
427
|
TILDE = '~'.freeze
|
|
428
|
+
Sequel::Deprecation.deprecate_constant(self, :TILDE)
|
|
331
429
|
TIMESTAMP_FORMAT = "'%Y-%m-%d %H:%M:%S%N%z'".freeze
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
430
|
+
Sequel::Deprecation.deprecate_constant(self, :TIMESTAMP_FORMAT)
|
|
431
|
+
STANDARD_TIMESTAMP_FORMAT = "TIMESTAMP '%Y-%m-%d %H:%M:%S%N%z'".freeze
|
|
432
|
+
Sequel::Deprecation.deprecate_constant(self, :STANDARD_TIMESTAMP_FORMAT)
|
|
335
433
|
UNDERSCORE = '_'.freeze
|
|
434
|
+
Sequel::Deprecation.deprecate_constant(self, :UNDERSCORE)
|
|
336
435
|
UPDATE = 'UPDATE'.freeze
|
|
436
|
+
Sequel::Deprecation.deprecate_constant(self, :UPDATE)
|
|
337
437
|
USING = ' USING ('.freeze
|
|
438
|
+
Sequel::Deprecation.deprecate_constant(self, :USING)
|
|
338
439
|
UNION_ALL_SELECT = ' UNION ALL SELECT '.freeze
|
|
440
|
+
Sequel::Deprecation.deprecate_constant(self, :UNION_ALL_SELECT)
|
|
339
441
|
VALUES = " VALUES ".freeze
|
|
442
|
+
Sequel::Deprecation.deprecate_constant(self, :VALUES)
|
|
340
443
|
WHERE = " WHERE ".freeze
|
|
444
|
+
Sequel::Deprecation.deprecate_constant(self, :WHERE)
|
|
341
445
|
WITH_ORDINALITY = " WITH ORDINALITY".freeze
|
|
446
|
+
Sequel::Deprecation.deprecate_constant(self, :WITH_ORDINALITY)
|
|
342
447
|
WITHIN_GROUP = " WITHIN GROUP (ORDER BY ".freeze
|
|
343
|
-
|
|
344
|
-
DATETIME_SECFRACTION_ARG = RUBY_VERSION >= '1.9.0' ? 1000000 : 86400000000
|
|
448
|
+
Sequel::Deprecation.deprecate_constant(self, :WITHIN_GROUP)
|
|
345
449
|
|
|
346
450
|
[:literal, :quote_identifier, :quote_schema_table].each do |meth|
|
|
347
451
|
class_eval(<<-END, __FILE__, __LINE__ + 1)
|
|
@@ -362,18 +466,18 @@ module Sequel
|
|
|
362
466
|
# Append literalization of array to SQL string.
|
|
363
467
|
def array_sql_append(sql, a)
|
|
364
468
|
if a.empty?
|
|
365
|
-
sql <<
|
|
469
|
+
sql << '(NULL)'
|
|
366
470
|
else
|
|
367
|
-
sql <<
|
|
471
|
+
sql << '('
|
|
368
472
|
expression_list_append(sql, a)
|
|
369
|
-
sql <<
|
|
473
|
+
sql << ')'
|
|
370
474
|
end
|
|
371
475
|
end
|
|
372
476
|
|
|
373
477
|
# Append literalization of boolean constant to SQL string.
|
|
374
478
|
def boolean_constant_sql_append(sql, constant)
|
|
375
479
|
if (constant == true || constant == false) && !supports_where_true?
|
|
376
|
-
sql << (constant == true ?
|
|
480
|
+
sql << (constant == true ? '(1 = 1)' : '(1 = 0)')
|
|
377
481
|
else
|
|
378
482
|
literal_append(sql, constant)
|
|
379
483
|
end
|
|
@@ -381,30 +485,30 @@ module Sequel
|
|
|
381
485
|
|
|
382
486
|
# Append literalization of case expression to SQL string.
|
|
383
487
|
def case_expression_sql_append(sql, ce)
|
|
384
|
-
sql <<
|
|
488
|
+
sql << '(CASE'
|
|
385
489
|
if ce.expression?
|
|
386
|
-
sql <<
|
|
490
|
+
sql << ' '
|
|
387
491
|
literal_append(sql, ce.expression)
|
|
388
492
|
end
|
|
389
|
-
w =
|
|
390
|
-
t =
|
|
493
|
+
w = " WHEN "
|
|
494
|
+
t = " THEN "
|
|
391
495
|
ce.conditions.each do |c,r|
|
|
392
496
|
sql << w
|
|
393
497
|
literal_append(sql, c)
|
|
394
498
|
sql << t
|
|
395
499
|
literal_append(sql, r)
|
|
396
500
|
end
|
|
397
|
-
sql <<
|
|
501
|
+
sql << " ELSE "
|
|
398
502
|
literal_append(sql, ce.default)
|
|
399
|
-
sql <<
|
|
503
|
+
sql << " END)"
|
|
400
504
|
end
|
|
401
505
|
|
|
402
506
|
# Append literalization of cast expression to SQL string.
|
|
403
507
|
def cast_sql_append(sql, expr, type)
|
|
404
|
-
sql <<
|
|
508
|
+
sql << 'CAST('
|
|
405
509
|
literal_append(sql, expr)
|
|
406
|
-
sql << AS << db.cast_type_literal(type).to_s
|
|
407
|
-
sql <<
|
|
510
|
+
sql << ' AS ' << db.cast_type_literal(type).to_s
|
|
511
|
+
sql << ')'
|
|
408
512
|
end
|
|
409
513
|
|
|
410
514
|
# Append literalization of column all selection to SQL string.
|
|
@@ -416,21 +520,21 @@ module Sequel
|
|
|
416
520
|
def complex_expression_sql_append(sql, op, args)
|
|
417
521
|
case op
|
|
418
522
|
when *IS_OPERATORS
|
|
419
|
-
r = args
|
|
523
|
+
r = args[1]
|
|
420
524
|
if r.nil? || supports_is_true?
|
|
421
525
|
raise(InvalidOperation, 'Invalid argument used for IS operator') unless val = IS_LITERALS[r]
|
|
422
|
-
sql <<
|
|
423
|
-
literal_append(sql, args
|
|
424
|
-
sql <<
|
|
425
|
-
sql << val <<
|
|
526
|
+
sql << '('
|
|
527
|
+
literal_append(sql, args[0])
|
|
528
|
+
sql << ' ' << op.to_s << ' '
|
|
529
|
+
sql << val << ')'
|
|
426
530
|
elsif op == :IS
|
|
427
531
|
complex_expression_sql_append(sql, :"=", args)
|
|
428
532
|
else
|
|
429
|
-
complex_expression_sql_append(sql, :OR, [SQL::BooleanExpression.new(:"!=", *args), SQL::BooleanExpression.new(:IS, args
|
|
533
|
+
complex_expression_sql_append(sql, :OR, [SQL::BooleanExpression.new(:"!=", *args), SQL::BooleanExpression.new(:IS, args[0], nil)])
|
|
430
534
|
end
|
|
431
535
|
when :IN, :"NOT IN"
|
|
432
|
-
cols = args
|
|
433
|
-
vals = args
|
|
536
|
+
cols = args[0]
|
|
537
|
+
vals = args[1]
|
|
434
538
|
col_array = true if cols.is_a?(Array)
|
|
435
539
|
if vals.is_a?(Array)
|
|
436
540
|
val_array = true
|
|
@@ -454,31 +558,31 @@ module Sequel
|
|
|
454
558
|
# If the columns and values are both arrays, use array_sql instead of
|
|
455
559
|
# literal so that if values is an array of two element arrays, it
|
|
456
560
|
# will be treated as a value list instead of a condition specifier.
|
|
457
|
-
sql <<
|
|
561
|
+
sql << '('
|
|
458
562
|
literal_append(sql, cols)
|
|
459
|
-
sql <<
|
|
563
|
+
sql << ' ' << op.to_s << ' '
|
|
460
564
|
if val_array
|
|
461
565
|
array_sql_append(sql, vals)
|
|
462
566
|
else
|
|
463
567
|
literal_append(sql, vals)
|
|
464
568
|
end
|
|
465
|
-
sql <<
|
|
569
|
+
sql << ')'
|
|
466
570
|
end
|
|
467
571
|
else
|
|
468
|
-
sql <<
|
|
572
|
+
sql << '('
|
|
469
573
|
literal_append(sql, cols)
|
|
470
|
-
sql <<
|
|
574
|
+
sql << ' ' << op.to_s << ' '
|
|
471
575
|
literal_append(sql, vals)
|
|
472
|
-
sql <<
|
|
576
|
+
sql << ')'
|
|
473
577
|
end
|
|
474
578
|
when :LIKE, :'NOT LIKE'
|
|
475
|
-
sql <<
|
|
476
|
-
literal_append(sql, args
|
|
477
|
-
sql <<
|
|
478
|
-
literal_append(sql, args
|
|
479
|
-
sql << ESCAPE
|
|
480
|
-
literal_append(sql,
|
|
481
|
-
sql <<
|
|
579
|
+
sql << '('
|
|
580
|
+
literal_append(sql, args[0])
|
|
581
|
+
sql << ' ' << op.to_s << ' '
|
|
582
|
+
literal_append(sql, args[1])
|
|
583
|
+
sql << " ESCAPE "
|
|
584
|
+
literal_append(sql, "\\")
|
|
585
|
+
sql << ')'
|
|
482
586
|
when :ILIKE, :'NOT ILIKE'
|
|
483
587
|
complex_expression_sql_append(sql, (op == :ILIKE ? :LIKE : :"NOT LIKE"), args.map{|v| Sequel.function(:UPPER, v)})
|
|
484
588
|
when :**
|
|
@@ -487,13 +591,13 @@ module Sequel
|
|
|
487
591
|
if REGEXP_OPERATORS.include?(op) && !supports_regexp?
|
|
488
592
|
raise InvalidOperation, "Pattern matching via regular expressions is not supported on #{db.database_type}"
|
|
489
593
|
end
|
|
490
|
-
sql <<
|
|
491
|
-
literal_append(sql, args
|
|
492
|
-
sql <<
|
|
493
|
-
literal_append(sql, args
|
|
494
|
-
sql <<
|
|
594
|
+
sql << '('
|
|
595
|
+
literal_append(sql, args[0])
|
|
596
|
+
sql << ' ' << op.to_s << ' '
|
|
597
|
+
literal_append(sql, args[1])
|
|
598
|
+
sql << ')'
|
|
495
599
|
when *N_ARITY_OPERATORS
|
|
496
|
-
sql <<
|
|
600
|
+
sql << '('
|
|
497
601
|
c = false
|
|
498
602
|
op_str = " #{op} "
|
|
499
603
|
args.each do |a|
|
|
@@ -501,19 +605,19 @@ module Sequel
|
|
|
501
605
|
literal_append(sql, a)
|
|
502
606
|
c ||= true
|
|
503
607
|
end
|
|
504
|
-
sql <<
|
|
608
|
+
sql << ')'
|
|
505
609
|
when :NOT
|
|
506
|
-
sql <<
|
|
507
|
-
literal_append(sql, args
|
|
610
|
+
sql << 'NOT '
|
|
611
|
+
literal_append(sql, args[0])
|
|
508
612
|
when :NOOP
|
|
509
|
-
literal_append(sql, args
|
|
613
|
+
literal_append(sql, args[0])
|
|
510
614
|
when :'B~'
|
|
511
|
-
sql <<
|
|
512
|
-
literal_append(sql, args
|
|
615
|
+
sql << '~'
|
|
616
|
+
literal_append(sql, args[0])
|
|
513
617
|
when :extract
|
|
514
|
-
sql <<
|
|
515
|
-
literal_append(sql, args
|
|
516
|
-
sql <<
|
|
618
|
+
sql << 'extract(' << args[0].to_s << ' FROM '
|
|
619
|
+
literal_append(sql, args[1])
|
|
620
|
+
sql << ')'
|
|
517
621
|
else
|
|
518
622
|
raise(InvalidOperation, "invalid operator #{op}")
|
|
519
623
|
end
|
|
@@ -553,11 +657,11 @@ module Sequel
|
|
|
553
657
|
name = native_function_name(name)
|
|
554
658
|
end
|
|
555
659
|
|
|
556
|
-
sql << LATERAL if opts[:lateral]
|
|
660
|
+
sql << 'LATERAL ' if opts[:lateral]
|
|
557
661
|
|
|
558
662
|
case name
|
|
559
663
|
when SQL::Identifier
|
|
560
|
-
if supports_quoted_function_names? && opts[:quoted]
|
|
664
|
+
if supports_quoted_function_names? && opts[:quoted]
|
|
561
665
|
literal_append(sql, name)
|
|
562
666
|
else
|
|
563
667
|
sql << name.value.to_s
|
|
@@ -566,7 +670,7 @@ module Sequel
|
|
|
566
670
|
if supports_quoted_function_names? && opts[:quoted] != false
|
|
567
671
|
literal_append(sql, name)
|
|
568
672
|
else
|
|
569
|
-
sql << split_qualifiers(name).join(
|
|
673
|
+
sql << split_qualifiers(name).join('.')
|
|
570
674
|
end
|
|
571
675
|
else
|
|
572
676
|
if supports_quoted_function_names? && opts[:quoted]
|
|
@@ -576,38 +680,38 @@ module Sequel
|
|
|
576
680
|
end
|
|
577
681
|
end
|
|
578
682
|
|
|
579
|
-
sql <<
|
|
683
|
+
sql << '('
|
|
580
684
|
if opts[:*]
|
|
581
|
-
sql <<
|
|
685
|
+
sql << '*'
|
|
582
686
|
else
|
|
583
|
-
sql <<
|
|
687
|
+
sql << "DISTINCT " if opts[:distinct]
|
|
584
688
|
expression_list_append(sql, f.args)
|
|
585
689
|
if order = opts[:order]
|
|
586
|
-
sql <<
|
|
690
|
+
sql << " ORDER BY "
|
|
587
691
|
expression_list_append(sql, order)
|
|
588
692
|
end
|
|
589
693
|
end
|
|
590
|
-
sql <<
|
|
694
|
+
sql << ')'
|
|
591
695
|
|
|
592
696
|
if group = opts[:within_group]
|
|
593
|
-
sql <<
|
|
697
|
+
sql << " WITHIN GROUP (ORDER BY "
|
|
594
698
|
expression_list_append(sql, group)
|
|
595
|
-
sql <<
|
|
699
|
+
sql << ')'
|
|
596
700
|
end
|
|
597
701
|
|
|
598
702
|
if filter = opts[:filter]
|
|
599
|
-
sql << FILTER
|
|
703
|
+
sql << " FILTER (WHERE "
|
|
600
704
|
literal_append(sql, filter_expr(filter, &opts[:filter_block]))
|
|
601
|
-
sql <<
|
|
705
|
+
sql << ')'
|
|
602
706
|
end
|
|
603
707
|
|
|
604
708
|
if window = opts[:over]
|
|
605
|
-
sql << OVER
|
|
709
|
+
sql << ' OVER '
|
|
606
710
|
window_sql_append(sql, window.opts)
|
|
607
711
|
end
|
|
608
712
|
|
|
609
713
|
if opts[:with_ordinality]
|
|
610
|
-
sql <<
|
|
714
|
+
sql << " WITH ORDINALITY"
|
|
611
715
|
end
|
|
612
716
|
end
|
|
613
717
|
|
|
@@ -616,7 +720,7 @@ module Sequel
|
|
|
616
720
|
table = jc.table
|
|
617
721
|
table_alias = jc.table_alias
|
|
618
722
|
table_alias = nil if table == table_alias && !jc.column_aliases
|
|
619
|
-
sql <<
|
|
723
|
+
sql << ' ' << join_type_sql(jc.join_type) << ' '
|
|
620
724
|
identifier_append(sql, table)
|
|
621
725
|
as_sql_append(sql, table_alias, jc.column_aliases) if table_alias
|
|
622
726
|
end
|
|
@@ -624,33 +728,33 @@ module Sequel
|
|
|
624
728
|
# Append literalization of JOIN ON clause to SQL string.
|
|
625
729
|
def join_on_clause_sql_append(sql, jc)
|
|
626
730
|
join_clause_sql_append(sql, jc)
|
|
627
|
-
sql << ON
|
|
731
|
+
sql << ' ON '
|
|
628
732
|
literal_append(sql, filter_expr(jc.on))
|
|
629
733
|
end
|
|
630
734
|
|
|
631
735
|
# Append literalization of JOIN USING clause to SQL string.
|
|
632
736
|
def join_using_clause_sql_append(sql, jc)
|
|
633
737
|
join_clause_sql_append(sql, jc)
|
|
634
|
-
sql << USING
|
|
738
|
+
sql << ' USING ('
|
|
635
739
|
column_list_append(sql, jc.using)
|
|
636
|
-
sql <<
|
|
740
|
+
sql << ')'
|
|
637
741
|
end
|
|
638
742
|
|
|
639
743
|
# Append literalization of negative boolean constant to SQL string.
|
|
640
744
|
def negative_boolean_constant_sql_append(sql, constant)
|
|
641
|
-
sql <<
|
|
745
|
+
sql << 'NOT '
|
|
642
746
|
boolean_constant_sql_append(sql, constant)
|
|
643
747
|
end
|
|
644
748
|
|
|
645
749
|
# Append literalization of ordered expression to SQL string.
|
|
646
750
|
def ordered_expression_sql_append(sql, oe)
|
|
647
751
|
literal_append(sql, oe.expression)
|
|
648
|
-
sql << (oe.descending ? DESC : ASC)
|
|
752
|
+
sql << (oe.descending ? ' DESC' : ' ASC')
|
|
649
753
|
case oe.nulls
|
|
650
754
|
when :first
|
|
651
|
-
sql <<
|
|
755
|
+
sql << " NULLS FIRST"
|
|
652
756
|
when :last
|
|
653
|
-
sql <<
|
|
757
|
+
sql << " NULLS LAST"
|
|
654
758
|
end
|
|
655
759
|
end
|
|
656
760
|
|
|
@@ -658,7 +762,7 @@ module Sequel
|
|
|
658
762
|
def placeholder_literal_string_sql_append(sql, pls)
|
|
659
763
|
args = pls.args
|
|
660
764
|
str = pls.str
|
|
661
|
-
sql <<
|
|
765
|
+
sql << '(' if pls.parens
|
|
662
766
|
if args.is_a?(Hash)
|
|
663
767
|
if args.empty?
|
|
664
768
|
sql << str
|
|
@@ -684,7 +788,7 @@ module Sequel
|
|
|
684
788
|
i = -1
|
|
685
789
|
match_len = args.length - 1
|
|
686
790
|
loop do
|
|
687
|
-
previous, q, str = str.partition(
|
|
791
|
+
previous, q, str = str.partition('?')
|
|
688
792
|
sql << previous
|
|
689
793
|
literal_append(sql, args.at(i+=1)) unless q.empty?
|
|
690
794
|
if str.empty?
|
|
@@ -695,7 +799,7 @@ module Sequel
|
|
|
695
799
|
end
|
|
696
800
|
end
|
|
697
801
|
end
|
|
698
|
-
sql <<
|
|
802
|
+
sql << ')' if pls.parens
|
|
699
803
|
end
|
|
700
804
|
|
|
701
805
|
# Append literalization of qualified identifier to SQL string.
|
|
@@ -703,7 +807,7 @@ module Sequel
|
|
|
703
807
|
# column/qualified. If 2 arguments are given, the 2nd should be an SQL::QualifiedIdentifier.
|
|
704
808
|
def qualified_identifier_sql_append(sql, table, column=(c = table.column; table = table.table; c))
|
|
705
809
|
identifier_append(sql, table)
|
|
706
|
-
sql <<
|
|
810
|
+
sql << '.'
|
|
707
811
|
identifier_append(sql, column)
|
|
708
812
|
end
|
|
709
813
|
|
|
@@ -730,7 +834,7 @@ module Sequel
|
|
|
730
834
|
schema, table = schema_and_table(table)
|
|
731
835
|
if schema
|
|
732
836
|
quote_identifier_append(sql, schema)
|
|
733
|
-
sql <<
|
|
837
|
+
sql << '.'
|
|
734
838
|
end
|
|
735
839
|
quote_identifier_append(sql, table)
|
|
736
840
|
end
|
|
@@ -740,7 +844,7 @@ module Sequel
|
|
|
740
844
|
# should be overridden by subclasses to provide quoting not matching the
|
|
741
845
|
# SQL standard, such as backtick (used by MySQL and SQLite).
|
|
742
846
|
def quoted_identifier_append(sql, name)
|
|
743
|
-
sql <<
|
|
847
|
+
sql << '"' << name.to_s.gsub('"', '""') << '"'
|
|
744
848
|
end
|
|
745
849
|
|
|
746
850
|
# Split the schema information from the table, returning two strings,
|
|
@@ -786,39 +890,39 @@ module Sequel
|
|
|
786
890
|
# Append literalization of subscripts (SQL array accesses) to SQL string.
|
|
787
891
|
def subscript_sql_append(sql, s)
|
|
788
892
|
literal_append(sql, s.f)
|
|
789
|
-
sql <<
|
|
893
|
+
sql << '['
|
|
790
894
|
if s.sub.length == 1 && (range = s.sub.first).is_a?(Range)
|
|
791
895
|
literal_append(sql, range.begin)
|
|
792
|
-
sql <<
|
|
896
|
+
sql << ':'
|
|
793
897
|
e = range.end
|
|
794
898
|
e -= 1 if range.exclude_end? && e.is_a?(Integer)
|
|
795
899
|
literal_append(sql, e)
|
|
796
900
|
else
|
|
797
901
|
expression_list_append(sql, s.sub)
|
|
798
902
|
end
|
|
799
|
-
sql <<
|
|
903
|
+
sql << ']'
|
|
800
904
|
end
|
|
801
905
|
|
|
802
906
|
# Append literalization of windows (for window functions) to SQL string.
|
|
803
907
|
def window_sql_append(sql, opts)
|
|
804
908
|
raise(Error, 'This dataset does not support window functions') unless supports_window_functions?
|
|
805
|
-
sql <<
|
|
909
|
+
sql << '('
|
|
806
910
|
window, part, order, frame = opts.values_at(:window, :partition, :order, :frame)
|
|
807
911
|
space = false
|
|
808
|
-
space_s =
|
|
912
|
+
space_s = ' '
|
|
809
913
|
if window
|
|
810
914
|
literal_append(sql, window)
|
|
811
915
|
space = true
|
|
812
916
|
end
|
|
813
917
|
if part
|
|
814
918
|
sql << space_s if space
|
|
815
|
-
sql <<
|
|
919
|
+
sql << "PARTITION BY "
|
|
816
920
|
expression_list_append(sql, Array(part))
|
|
817
921
|
space = true
|
|
818
922
|
end
|
|
819
923
|
if order
|
|
820
924
|
sql << space_s if space
|
|
821
|
-
sql <<
|
|
925
|
+
sql << "ORDER BY "
|
|
822
926
|
expression_list_append(sql, Array(order))
|
|
823
927
|
space = true
|
|
824
928
|
end
|
|
@@ -827,17 +931,17 @@ module Sequel
|
|
|
827
931
|
# nothing
|
|
828
932
|
when :all
|
|
829
933
|
sql << space_s if space
|
|
830
|
-
sql <<
|
|
934
|
+
sql << "ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING"
|
|
831
935
|
when :rows
|
|
832
936
|
sql << space_s if space
|
|
833
|
-
sql <<
|
|
937
|
+
sql << "ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW"
|
|
834
938
|
when String
|
|
835
939
|
sql << space_s if space
|
|
836
940
|
sql << frame
|
|
837
941
|
else
|
|
838
942
|
raise Error, "invalid window frame clause, should be :all, :rows, a string, or nil"
|
|
839
943
|
end
|
|
840
|
-
sql <<
|
|
944
|
+
sql << ')'
|
|
841
945
|
end
|
|
842
946
|
|
|
843
947
|
protected
|
|
@@ -901,13 +1005,13 @@ module Sequel
|
|
|
901
1005
|
|
|
902
1006
|
# Append aliasing expression to SQL string.
|
|
903
1007
|
def as_sql_append(sql, aliaz, column_aliases=nil)
|
|
904
|
-
sql << AS
|
|
1008
|
+
sql << ' AS '
|
|
905
1009
|
quote_identifier_append(sql, aliaz)
|
|
906
1010
|
if column_aliases
|
|
907
1011
|
raise Error, "#{db.database_type} does not support derived column lists" unless supports_derived_column_lists?
|
|
908
|
-
sql <<
|
|
1012
|
+
sql << '('
|
|
909
1013
|
identifier_list_append(sql, column_aliases)
|
|
910
|
-
sql <<
|
|
1014
|
+
sql << ')'
|
|
911
1015
|
end
|
|
912
1016
|
end
|
|
913
1017
|
|
|
@@ -942,7 +1046,7 @@ module Sequel
|
|
|
942
1046
|
# column names. If the array is empty, a wildcard (*) is returned.
|
|
943
1047
|
def column_list_append(sql, columns)
|
|
944
1048
|
if (columns.nil? || columns.empty?)
|
|
945
|
-
sql <<
|
|
1049
|
+
sql << '*'
|
|
946
1050
|
else
|
|
947
1051
|
expression_list_append(sql, columns)
|
|
948
1052
|
end
|
|
@@ -955,9 +1059,9 @@ module Sequel
|
|
|
955
1059
|
def complex_expression_arg_pairs(args)
|
|
956
1060
|
case args.length
|
|
957
1061
|
when 1
|
|
958
|
-
args
|
|
1062
|
+
args[0]
|
|
959
1063
|
when 2
|
|
960
|
-
yield args
|
|
1064
|
+
yield args[0], args[1]
|
|
961
1065
|
else
|
|
962
1066
|
args.inject{|m, a| yield(m, a)}
|
|
963
1067
|
end
|
|
@@ -985,9 +1089,9 @@ module Sequel
|
|
|
985
1089
|
f = BITWISE_METHOD_MAP[op]
|
|
986
1090
|
complex_expression_arg_pairs_append(sql, args){|a, b| Sequel.function(f, a, b)}
|
|
987
1091
|
when :'B~'
|
|
988
|
-
sql <<
|
|
989
|
-
literal_append(sql, args
|
|
990
|
-
sql <<
|
|
1092
|
+
sql << "((0 - "
|
|
1093
|
+
literal_append(sql, args[0])
|
|
1094
|
+
sql << ") - 1)"
|
|
991
1095
|
end
|
|
992
1096
|
end
|
|
993
1097
|
|
|
@@ -998,21 +1102,21 @@ module Sequel
|
|
|
998
1102
|
|
|
999
1103
|
# The alias to use for datasets, takes a number to make sure the name is unique.
|
|
1000
1104
|
def dataset_alias(number)
|
|
1001
|
-
:"#{
|
|
1105
|
+
:"t#{number}"
|
|
1002
1106
|
end
|
|
1003
1107
|
|
|
1004
1108
|
# The strftime format to use when literalizing the time.
|
|
1005
1109
|
def default_timestamp_format
|
|
1006
|
-
requires_sql_standard_datetimes? ?
|
|
1110
|
+
requires_sql_standard_datetimes? ? "TIMESTAMP '%Y-%m-%d %H:%M:%S%N%z'" : "'%Y-%m-%d %H:%M:%S%N%z'"
|
|
1007
1111
|
end
|
|
1008
1112
|
|
|
1009
1113
|
def delete_delete_sql(sql)
|
|
1010
|
-
sql << DELETE
|
|
1114
|
+
sql << 'DELETE'
|
|
1011
1115
|
end
|
|
1012
1116
|
|
|
1013
1117
|
def delete_from_sql(sql)
|
|
1014
1118
|
if f = @opts[:from]
|
|
1015
|
-
sql << FROM
|
|
1119
|
+
sql << ' FROM '
|
|
1016
1120
|
source_list_append(sql, f)
|
|
1017
1121
|
end
|
|
1018
1122
|
end
|
|
@@ -1037,7 +1141,7 @@ module Sequel
|
|
|
1037
1141
|
# Append literalization of array of expressions to SQL string.
|
|
1038
1142
|
def expression_list_append(sql, columns)
|
|
1039
1143
|
c = false
|
|
1040
|
-
co =
|
|
1144
|
+
co = ', '
|
|
1041
1145
|
columns.each do |col|
|
|
1042
1146
|
sql << co if c
|
|
1043
1147
|
literal_append(sql, col)
|
|
@@ -1048,11 +1152,11 @@ module Sequel
|
|
|
1048
1152
|
# Append literalization of array of grouping elements to SQL string.
|
|
1049
1153
|
def grouping_element_list_append(sql, columns)
|
|
1050
1154
|
c = false
|
|
1051
|
-
co =
|
|
1155
|
+
co = ', '
|
|
1052
1156
|
columns.each do |col|
|
|
1053
1157
|
sql << co if c
|
|
1054
1158
|
if col.is_a?(Array) && col.empty?
|
|
1055
|
-
sql <<
|
|
1159
|
+
sql << '()'
|
|
1056
1160
|
else
|
|
1057
1161
|
literal_append(sql, Array(col))
|
|
1058
1162
|
end
|
|
@@ -1071,9 +1175,9 @@ module Sequel
|
|
|
1071
1175
|
# of hours and minutes.
|
|
1072
1176
|
def format_timestamp(v)
|
|
1073
1177
|
v2 = db.from_application_timestamp(v)
|
|
1074
|
-
fmt = default_timestamp_format.gsub(
|
|
1075
|
-
if m ==
|
|
1076
|
-
format_timestamp_usec(v.is_a?(DateTime) ? v.sec_fraction*(
|
|
1178
|
+
fmt = default_timestamp_format.gsub(/%[Nz]/) do |m|
|
|
1179
|
+
if m == '%N'
|
|
1180
|
+
format_timestamp_usec(v.is_a?(DateTime) ? v.sec_fraction*(RUBY_VERSION >= '1.9.0' ? 1000000 : 86400000000) : v.usec) if supports_timestamp_usecs?
|
|
1077
1181
|
else
|
|
1078
1182
|
if supports_timestamp_timezones?
|
|
1079
1183
|
# Would like to just use %z format, but it doesn't appear to work on Windows
|
|
@@ -1088,13 +1192,13 @@ module Sequel
|
|
|
1088
1192
|
|
|
1089
1193
|
# Return the SQL timestamp fragment to use for the timezone offset.
|
|
1090
1194
|
def format_timestamp_offset(hour, minute)
|
|
1091
|
-
sprintf(
|
|
1195
|
+
sprintf("%+03i%02i", hour, minute)
|
|
1092
1196
|
end
|
|
1093
1197
|
|
|
1094
1198
|
# Return the SQL timestamp fragment to use for the fractional time part.
|
|
1095
1199
|
# Should start with the decimal point. Uses 6 decimal places by default.
|
|
1096
|
-
def format_timestamp_usec(usec)
|
|
1097
|
-
unless
|
|
1200
|
+
def format_timestamp_usec(usec, ts=timestamp_precision)
|
|
1201
|
+
unless ts == 6
|
|
1098
1202
|
usec = usec/(10 ** (6 - ts))
|
|
1099
1203
|
end
|
|
1100
1204
|
sprintf(".%0#{ts}d", usec)
|
|
@@ -1120,7 +1224,7 @@ module Sequel
|
|
|
1120
1224
|
# Append literalization of array of identifiers to SQL string.
|
|
1121
1225
|
def identifier_list_append(sql, args)
|
|
1122
1226
|
c = false
|
|
1123
|
-
comma =
|
|
1227
|
+
comma = ', '
|
|
1124
1228
|
args.each do |a|
|
|
1125
1229
|
sql << comma if c
|
|
1126
1230
|
identifier_append(sql, a)
|
|
@@ -1134,7 +1238,7 @@ module Sequel
|
|
|
1134
1238
|
end
|
|
1135
1239
|
|
|
1136
1240
|
def insert_into_sql(sql)
|
|
1137
|
-
sql << INTO
|
|
1241
|
+
sql << " INTO "
|
|
1138
1242
|
if (f = @opts[:from]) && f.length == 1
|
|
1139
1243
|
identifier_append(sql, unaliased_identifier(f.first))
|
|
1140
1244
|
else
|
|
@@ -1145,9 +1249,9 @@ module Sequel
|
|
|
1145
1249
|
def insert_columns_sql(sql)
|
|
1146
1250
|
columns = opts[:columns]
|
|
1147
1251
|
if columns && !columns.empty?
|
|
1148
|
-
sql <<
|
|
1252
|
+
sql << ' ('
|
|
1149
1253
|
identifier_list_append(sql, columns)
|
|
1150
|
-
sql <<
|
|
1254
|
+
sql << ')'
|
|
1151
1255
|
end
|
|
1152
1256
|
end
|
|
1153
1257
|
|
|
@@ -1158,23 +1262,23 @@ module Sequel
|
|
|
1158
1262
|
end
|
|
1159
1263
|
|
|
1160
1264
|
def insert_insert_sql(sql)
|
|
1161
|
-
sql << INSERT
|
|
1265
|
+
sql << "INSERT"
|
|
1162
1266
|
end
|
|
1163
1267
|
|
|
1164
1268
|
def insert_values_sql(sql)
|
|
1165
1269
|
case values = opts[:values]
|
|
1166
1270
|
when Array
|
|
1167
1271
|
if values.empty?
|
|
1168
|
-
sql <<
|
|
1272
|
+
sql << " DEFAULT VALUES"
|
|
1169
1273
|
else
|
|
1170
|
-
sql << VALUES
|
|
1274
|
+
sql << " VALUES "
|
|
1171
1275
|
literal_append(sql, values)
|
|
1172
1276
|
end
|
|
1173
1277
|
when Dataset
|
|
1174
|
-
sql <<
|
|
1278
|
+
sql << ' '
|
|
1175
1279
|
subselect_sql_append(sql, values)
|
|
1176
1280
|
when LiteralString
|
|
1177
|
-
sql <<
|
|
1281
|
+
sql << ' ' << values
|
|
1178
1282
|
else
|
|
1179
1283
|
raise Error, "Unsupported INSERT values type, should be an Array or Dataset: #{values.inspect}"
|
|
1180
1284
|
end
|
|
@@ -1182,7 +1286,7 @@ module Sequel
|
|
|
1182
1286
|
|
|
1183
1287
|
def insert_returning_sql(sql)
|
|
1184
1288
|
if opts.has_key?(:returning)
|
|
1185
|
-
sql << RETURNING
|
|
1289
|
+
sql << " RETURNING "
|
|
1186
1290
|
column_list_append(sql, Array(opts[:returning]))
|
|
1187
1291
|
end
|
|
1188
1292
|
end
|
|
@@ -1192,7 +1296,7 @@ module Sequel
|
|
|
1192
1296
|
# SQL fragment specifying a JOIN type, converts underscores to
|
|
1193
1297
|
# spaces and upcases.
|
|
1194
1298
|
def join_type_sql(join_type)
|
|
1195
|
-
"#{join_type.to_s.gsub(
|
|
1299
|
+
"#{join_type.to_s.gsub('_', ' ').upcase} JOIN"
|
|
1196
1300
|
end
|
|
1197
1301
|
|
|
1198
1302
|
# Append a literalization of the array to SQL string.
|
|
@@ -1218,18 +1322,18 @@ module Sequel
|
|
|
1218
1322
|
|
|
1219
1323
|
# Append literalization of dataset to SQL string. Does a subselect inside parantheses.
|
|
1220
1324
|
def literal_dataset_append(sql, v)
|
|
1221
|
-
sql << LATERAL if v.opts[:lateral]
|
|
1222
|
-
sql <<
|
|
1325
|
+
sql << 'LATERAL ' if v.opts[:lateral]
|
|
1326
|
+
sql << '('
|
|
1223
1327
|
subselect_sql_append(sql, v)
|
|
1224
|
-
sql <<
|
|
1328
|
+
sql << ')'
|
|
1225
1329
|
end
|
|
1226
1330
|
|
|
1227
1331
|
# SQL fragment for Date, using the ISO8601 format.
|
|
1228
1332
|
def literal_date(v)
|
|
1229
1333
|
if requires_sql_standard_datetimes?
|
|
1230
|
-
v.strftime(
|
|
1334
|
+
v.strftime("DATE '%Y-%m-%d'")
|
|
1231
1335
|
else
|
|
1232
|
-
v.strftime(
|
|
1336
|
+
v.strftime("'%Y-%m-%d'")
|
|
1233
1337
|
end
|
|
1234
1338
|
end
|
|
1235
1339
|
|
|
@@ -1250,7 +1354,7 @@ module Sequel
|
|
|
1250
1354
|
|
|
1251
1355
|
# SQL fragment for false
|
|
1252
1356
|
def literal_false
|
|
1253
|
-
|
|
1357
|
+
"'f'"
|
|
1254
1358
|
end
|
|
1255
1359
|
|
|
1256
1360
|
# SQL fragment for Float
|
|
@@ -1270,7 +1374,7 @@ module Sequel
|
|
|
1270
1374
|
|
|
1271
1375
|
# SQL fragment for nil
|
|
1272
1376
|
def literal_nil
|
|
1273
|
-
NULL
|
|
1377
|
+
"NULL"
|
|
1274
1378
|
end
|
|
1275
1379
|
|
|
1276
1380
|
# Append a literalization of the object to the given SQL string.
|
|
@@ -1293,7 +1397,7 @@ module Sequel
|
|
|
1293
1397
|
|
|
1294
1398
|
# SQL fragment for Sequel::SQLTime, containing just the time part
|
|
1295
1399
|
def literal_sqltime(v)
|
|
1296
|
-
v.strftime("'%H:%M:%S#{format_timestamp_usec(v.usec) if supports_timestamp_usecs?}'")
|
|
1400
|
+
v.strftime("'%H:%M:%S#{format_timestamp_usec(v.usec, sqltime_precision) if supports_timestamp_usecs?}'")
|
|
1297
1401
|
end
|
|
1298
1402
|
|
|
1299
1403
|
# Append literalization of Sequel::SQLTime to SQL string.
|
|
@@ -1303,7 +1407,7 @@ module Sequel
|
|
|
1303
1407
|
|
|
1304
1408
|
# Append literalization of string to SQL string.
|
|
1305
1409
|
def literal_string_append(sql, v)
|
|
1306
|
-
sql <<
|
|
1410
|
+
sql << "'" << v.gsub(/'/, "''") << "'"
|
|
1307
1411
|
end
|
|
1308
1412
|
|
|
1309
1413
|
# Append literalization of symbol to SQL string.
|
|
@@ -1311,7 +1415,7 @@ module Sequel
|
|
|
1311
1415
|
c_table, column, c_alias = split_symbol(v)
|
|
1312
1416
|
if c_table
|
|
1313
1417
|
quote_identifier_append(sql, c_table)
|
|
1314
|
-
sql <<
|
|
1418
|
+
sql << '.'
|
|
1315
1419
|
end
|
|
1316
1420
|
quote_identifier_append(sql, column)
|
|
1317
1421
|
as_sql_append(sql, c_alias) if c_alias
|
|
@@ -1329,7 +1433,7 @@ module Sequel
|
|
|
1329
1433
|
|
|
1330
1434
|
# SQL fragment for true
|
|
1331
1435
|
def literal_true
|
|
1332
|
-
|
|
1436
|
+
"'t'"
|
|
1333
1437
|
end
|
|
1334
1438
|
|
|
1335
1439
|
# What strategy to use for import/multi_insert. While SQL-92 defaults
|
|
@@ -1340,9 +1444,10 @@ module Sequel
|
|
|
1340
1444
|
:separate
|
|
1341
1445
|
end
|
|
1342
1446
|
|
|
1447
|
+
|
|
1343
1448
|
# Get the native function name given the emulated function name.
|
|
1344
1449
|
def native_function_name(emulated_function)
|
|
1345
|
-
|
|
1450
|
+
emulated_function
|
|
1346
1451
|
end
|
|
1347
1452
|
|
|
1348
1453
|
# Returns a qualified column name (including a table name) if the column
|
|
@@ -1372,17 +1477,17 @@ module Sequel
|
|
|
1372
1477
|
end
|
|
1373
1478
|
|
|
1374
1479
|
def select_columns_sql(sql)
|
|
1375
|
-
sql <<
|
|
1480
|
+
sql << ' '
|
|
1376
1481
|
column_list_append(sql, @opts[:select])
|
|
1377
1482
|
end
|
|
1378
1483
|
|
|
1379
1484
|
def select_distinct_sql(sql)
|
|
1380
1485
|
if distinct = @opts[:distinct]
|
|
1381
|
-
sql << DISTINCT
|
|
1486
|
+
sql << " DISTINCT"
|
|
1382
1487
|
unless distinct.empty?
|
|
1383
|
-
sql <<
|
|
1488
|
+
sql << " ON ("
|
|
1384
1489
|
expression_list_append(sql, distinct)
|
|
1385
|
-
sql <<
|
|
1490
|
+
sql << ')'
|
|
1386
1491
|
end
|
|
1387
1492
|
end
|
|
1388
1493
|
end
|
|
@@ -1393,16 +1498,16 @@ module Sequel
|
|
|
1393
1498
|
def select_compounds_sql(sql)
|
|
1394
1499
|
return unless c = @opts[:compounds]
|
|
1395
1500
|
c.each do |type, dataset, all|
|
|
1396
|
-
sql <<
|
|
1397
|
-
sql << ALL if all
|
|
1398
|
-
sql <<
|
|
1501
|
+
sql << ' ' << type.to_s.upcase
|
|
1502
|
+
sql << ' ALL' if all
|
|
1503
|
+
sql << ' '
|
|
1399
1504
|
compound_dataset_sql_append(sql, dataset)
|
|
1400
1505
|
end
|
|
1401
1506
|
end
|
|
1402
1507
|
|
|
1403
1508
|
def select_from_sql(sql)
|
|
1404
1509
|
if f = @opts[:from]
|
|
1405
|
-
sql << FROM
|
|
1510
|
+
sql << ' FROM '
|
|
1406
1511
|
source_list_append(sql, f)
|
|
1407
1512
|
elsif f = empty_from_sql
|
|
1408
1513
|
sql << f
|
|
@@ -1411,19 +1516,19 @@ module Sequel
|
|
|
1411
1516
|
|
|
1412
1517
|
def select_group_sql(sql)
|
|
1413
1518
|
if group = @opts[:group]
|
|
1414
|
-
sql <<
|
|
1519
|
+
sql << " GROUP BY "
|
|
1415
1520
|
if go = @opts[:group_options]
|
|
1416
1521
|
if go == :"grouping sets"
|
|
1417
|
-
sql << go.to_s.upcase <<
|
|
1522
|
+
sql << go.to_s.upcase << '('
|
|
1418
1523
|
grouping_element_list_append(sql, group)
|
|
1419
|
-
sql <<
|
|
1524
|
+
sql << ')'
|
|
1420
1525
|
elsif uses_with_rollup?
|
|
1421
1526
|
expression_list_append(sql, group)
|
|
1422
|
-
sql <<
|
|
1527
|
+
sql << " WITH " << go.to_s.upcase
|
|
1423
1528
|
else
|
|
1424
|
-
sql << go.to_s.upcase <<
|
|
1529
|
+
sql << go.to_s.upcase << '('
|
|
1425
1530
|
expression_list_append(sql, group)
|
|
1426
|
-
sql <<
|
|
1531
|
+
sql << ')'
|
|
1427
1532
|
end
|
|
1428
1533
|
else
|
|
1429
1534
|
expression_list_append(sql, group)
|
|
@@ -1433,7 +1538,7 @@ module Sequel
|
|
|
1433
1538
|
|
|
1434
1539
|
def select_having_sql(sql)
|
|
1435
1540
|
if having = @opts[:having]
|
|
1436
|
-
sql << HAVING
|
|
1541
|
+
sql << " HAVING "
|
|
1437
1542
|
literal_append(sql, having)
|
|
1438
1543
|
end
|
|
1439
1544
|
end
|
|
@@ -1446,10 +1551,10 @@ module Sequel
|
|
|
1446
1551
|
|
|
1447
1552
|
def select_limit_sql(sql)
|
|
1448
1553
|
if l = @opts[:limit]
|
|
1449
|
-
sql << LIMIT
|
|
1554
|
+
sql << " LIMIT "
|
|
1450
1555
|
literal_append(sql, l)
|
|
1451
1556
|
if o = @opts[:offset]
|
|
1452
|
-
sql << OFFSET
|
|
1557
|
+
sql << " OFFSET "
|
|
1453
1558
|
literal_append(sql, o)
|
|
1454
1559
|
end
|
|
1455
1560
|
elsif @opts[:offset]
|
|
@@ -1460,9 +1565,9 @@ module Sequel
|
|
|
1460
1565
|
def select_lock_sql(sql)
|
|
1461
1566
|
case l = @opts[:lock]
|
|
1462
1567
|
when :update
|
|
1463
|
-
sql <<
|
|
1568
|
+
sql << ' FOR UPDATE'
|
|
1464
1569
|
when String
|
|
1465
|
-
sql <<
|
|
1570
|
+
sql << ' ' << l
|
|
1466
1571
|
end
|
|
1467
1572
|
end
|
|
1468
1573
|
|
|
@@ -1470,13 +1575,13 @@ module Sequel
|
|
|
1470
1575
|
# in the adapter, as many databases do not support just a plain offset with
|
|
1471
1576
|
# no limit.
|
|
1472
1577
|
def select_only_offset_sql(sql)
|
|
1473
|
-
sql << OFFSET
|
|
1578
|
+
sql << " OFFSET "
|
|
1474
1579
|
literal_append(sql, @opts[:offset])
|
|
1475
1580
|
end
|
|
1476
1581
|
|
|
1477
1582
|
def select_order_sql(sql)
|
|
1478
1583
|
if o = @opts[:order]
|
|
1479
|
-
sql <<
|
|
1584
|
+
sql << " ORDER BY "
|
|
1480
1585
|
expression_list_append(sql, o)
|
|
1481
1586
|
end
|
|
1482
1587
|
end
|
|
@@ -1484,12 +1589,12 @@ module Sequel
|
|
|
1484
1589
|
alias update_order_sql select_order_sql
|
|
1485
1590
|
|
|
1486
1591
|
def select_select_sql(sql)
|
|
1487
|
-
sql << SELECT
|
|
1592
|
+
sql << 'SELECT'
|
|
1488
1593
|
end
|
|
1489
1594
|
|
|
1490
1595
|
def select_where_sql(sql)
|
|
1491
1596
|
if w = @opts[:where]
|
|
1492
|
-
sql << WHERE
|
|
1597
|
+
sql << " WHERE "
|
|
1493
1598
|
literal_append(sql, w)
|
|
1494
1599
|
end
|
|
1495
1600
|
end
|
|
@@ -1502,20 +1607,20 @@ module Sequel
|
|
|
1502
1607
|
return if !ws || ws.empty?
|
|
1503
1608
|
sql << select_with_sql_base
|
|
1504
1609
|
c = false
|
|
1505
|
-
comma =
|
|
1610
|
+
comma = ', '
|
|
1506
1611
|
ws.each do |w|
|
|
1507
1612
|
sql << comma if c
|
|
1508
1613
|
quote_identifier_append(sql, w[:name])
|
|
1509
1614
|
if args = w[:args]
|
|
1510
|
-
sql <<
|
|
1615
|
+
sql << '('
|
|
1511
1616
|
identifier_list_append(sql, args)
|
|
1512
|
-
sql <<
|
|
1617
|
+
sql << ')'
|
|
1513
1618
|
end
|
|
1514
|
-
sql << AS
|
|
1619
|
+
sql << ' AS '
|
|
1515
1620
|
literal_dataset_append(sql, w[:dataset])
|
|
1516
1621
|
c ||= true
|
|
1517
1622
|
end
|
|
1518
|
-
sql <<
|
|
1623
|
+
sql << ' '
|
|
1519
1624
|
end
|
|
1520
1625
|
alias delete_with_sql select_with_sql
|
|
1521
1626
|
alias insert_with_sql select_with_sql
|
|
@@ -1523,7 +1628,7 @@ module Sequel
|
|
|
1523
1628
|
|
|
1524
1629
|
# The base keyword to use for the SQL WITH clause
|
|
1525
1630
|
def select_with_sql_base
|
|
1526
|
-
|
|
1631
|
+
"WITH "
|
|
1527
1632
|
end
|
|
1528
1633
|
|
|
1529
1634
|
# Whether the symbol cache should be skipped when literalizing the dataset
|
|
@@ -1549,6 +1654,12 @@ module Sequel
|
|
|
1549
1654
|
String.new
|
|
1550
1655
|
end
|
|
1551
1656
|
|
|
1657
|
+
# The precision to use for SQLTime instances (time column values without dates).
|
|
1658
|
+
# Defaults to timestamp_precision.
|
|
1659
|
+
def sqltime_precision
|
|
1660
|
+
timestamp_precision
|
|
1661
|
+
end
|
|
1662
|
+
|
|
1552
1663
|
# SQL to use if this dataset uses static SQL. Since static SQL
|
|
1553
1664
|
# can be a PlaceholderLiteralString in addition to a String,
|
|
1554
1665
|
# we literalize nonstrings. If there is an append_sql for this
|
|
@@ -1580,13 +1691,13 @@ module Sequel
|
|
|
1580
1691
|
end
|
|
1581
1692
|
|
|
1582
1693
|
def update_table_sql(sql)
|
|
1583
|
-
sql <<
|
|
1694
|
+
sql << ' '
|
|
1584
1695
|
source_list_append(sql, @opts[:from])
|
|
1585
1696
|
select_join_sql(sql) if supports_modifying_joins?
|
|
1586
1697
|
end
|
|
1587
1698
|
|
|
1588
1699
|
def update_set_sql(sql)
|
|
1589
|
-
sql << SET
|
|
1700
|
+
sql << ' SET '
|
|
1590
1701
|
values = @opts[:values]
|
|
1591
1702
|
if values.is_a?(Hash)
|
|
1592
1703
|
update_sql_values_hash(sql, values)
|
|
@@ -1597,9 +1708,9 @@ module Sequel
|
|
|
1597
1708
|
|
|
1598
1709
|
def update_sql_values_hash(sql, values)
|
|
1599
1710
|
c = false
|
|
1600
|
-
eq =
|
|
1711
|
+
eq = ' = '
|
|
1601
1712
|
values.each do |k, v|
|
|
1602
|
-
sql <<
|
|
1713
|
+
sql << ', ' if c
|
|
1603
1714
|
if k.is_a?(String) && !k.is_a?(LiteralString)
|
|
1604
1715
|
quote_identifier_append(sql, k)
|
|
1605
1716
|
else
|
|
@@ -1612,7 +1723,7 @@ module Sequel
|
|
|
1612
1723
|
end
|
|
1613
1724
|
|
|
1614
1725
|
def update_update_sql(sql)
|
|
1615
|
-
sql << UPDATE
|
|
1726
|
+
sql << 'UPDATE'
|
|
1616
1727
|
end
|
|
1617
1728
|
end
|
|
1618
1729
|
end
|