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
|
@@ -40,10 +40,14 @@ module Sequel
|
|
|
40
40
|
include UnmodifiedIdentifiers::DatabaseMethods
|
|
41
41
|
|
|
42
42
|
AUTO_INCREMENT = 'AUTO_INCREMENT'.freeze
|
|
43
|
-
|
|
44
|
-
COLUMN_DEFINITION_ORDER = [:collate, :null, :default, :unique, :primary_key, :auto_increment, :references]
|
|
43
|
+
Sequel::Deprecation.deprecate_constant(self, :AUTO_INCREMENT)
|
|
45
44
|
PRIMARY = 'PRIMARY'.freeze
|
|
45
|
+
Sequel::Deprecation.deprecate_constant(self, :PRIMARY)
|
|
46
46
|
MYSQL_TIMESTAMP_RE = /\ACURRENT_(?:DATE|TIMESTAMP)?\z/
|
|
47
|
+
Sequel::Deprecation.deprecate_constant(self, :MYSQL_TIMESTAMP_RE)
|
|
48
|
+
|
|
49
|
+
CAST_TYPES = {String=>:CHAR, Integer=>:SIGNED, Time=>:DATETIME, DateTime=>:DATETIME, Numeric=>:DECIMAL, BigDecimal=>:DECIMAL, File=>:BINARY}#.freeze # SEQUEL5
|
|
50
|
+
COLUMN_DEFINITION_ORDER = [:collate, :null, :default, :unique, :primary_key, :auto_increment, :references]#.freeze # SEQUEL5
|
|
47
51
|
|
|
48
52
|
include Sequel::Database::SplitAlterTable
|
|
49
53
|
|
|
@@ -121,7 +125,7 @@ module Sequel
|
|
|
121
125
|
|
|
122
126
|
metadata_dataset.with_sql(sql).each do |r|
|
|
123
127
|
name = r[:Key_name]
|
|
124
|
-
next if name == PRIMARY
|
|
128
|
+
next if name == 'PRIMARY'
|
|
125
129
|
name = m.call(name)
|
|
126
130
|
remove_indexes << name if r[:Sub_part] && ! opts[:partial]
|
|
127
131
|
i = indexes[name] ||= {:columns=>[], :unique=>r[:Non_unique] != 1}
|
|
@@ -290,7 +294,7 @@ module Sequel
|
|
|
290
294
|
# Handle MySQL specific default format.
|
|
291
295
|
def column_schema_normalize_default(default, type)
|
|
292
296
|
if column_schema_default_string_type?(type)
|
|
293
|
-
return if [:date, :datetime, :time].include?(type) &&
|
|
297
|
+
return if [:date, :datetime, :time].include?(type) && /\ACURRENT_(?:DATE|TIMESTAMP)?\z/.match(default)
|
|
294
298
|
default = "'#{default.gsub("'", "''").gsub('\\', '\\\\')}'"
|
|
295
299
|
end
|
|
296
300
|
super(default, type)
|
|
@@ -327,7 +331,7 @@ module Sequel
|
|
|
327
331
|
|
|
328
332
|
# Use MySQL specific AUTO_INCREMENT text.
|
|
329
333
|
def auto_increment_sql
|
|
330
|
-
AUTO_INCREMENT
|
|
334
|
+
'AUTO_INCREMENT'
|
|
331
335
|
end
|
|
332
336
|
|
|
333
337
|
# MySQL needs to set transaction isolation before begining a transaction
|
|
@@ -576,55 +580,98 @@ module Sequel
|
|
|
576
580
|
# Dataset methods shared by datasets that use MySQL databases.
|
|
577
581
|
module DatasetMethods
|
|
578
582
|
BOOL_TRUE = '1'.freeze
|
|
583
|
+
Sequel::Deprecation.deprecate_constant(self, :BOOL_TRUE)
|
|
579
584
|
BOOL_FALSE = '0'.freeze
|
|
585
|
+
Sequel::Deprecation.deprecate_constant(self, :BOOL_FALSE)
|
|
580
586
|
COMMA_SEPARATOR = ', '.freeze
|
|
587
|
+
Sequel::Deprecation.deprecate_constant(self, :COMMA_SEPARATOR)
|
|
581
588
|
FOR_SHARE = ' LOCK IN SHARE MODE'.freeze
|
|
589
|
+
Sequel::Deprecation.deprecate_constant(self, :FOR_SHARE)
|
|
582
590
|
SQL_CALC_FOUND_ROWS = ' SQL_CALC_FOUND_ROWS'.freeze
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
591
|
+
Sequel::Deprecation.deprecate_constant(self, :SQL_CALC_FOUND_ROWS)
|
|
592
|
+
APOS = "'".freeze
|
|
593
|
+
Sequel::Deprecation.deprecate_constant(self, :APOS)
|
|
594
|
+
APOS_RE = /'/.freeze
|
|
595
|
+
Sequel::Deprecation.deprecate_constant(self, :APOS_RE)
|
|
596
|
+
DOUBLE_APOS = "''".freeze
|
|
597
|
+
Sequel::Deprecation.deprecate_constant(self, :DOUBLE_APOS)
|
|
598
|
+
SPACE = ' '.freeze
|
|
599
|
+
Sequel::Deprecation.deprecate_constant(self, :SPACE)
|
|
600
|
+
PAREN_CLOSE = ')'.freeze
|
|
601
|
+
Sequel::Deprecation.deprecate_constant(self, :PAREN_CLOSE)
|
|
602
|
+
PAREN_OPEN = '('.freeze
|
|
603
|
+
Sequel::Deprecation.deprecate_constant(self, :PAREN_OPEN)
|
|
604
|
+
NOT_SPACE = 'NOT '.freeze
|
|
605
|
+
Sequel::Deprecation.deprecate_constant(self, :NOT_SPACE)
|
|
606
|
+
FROM = ' FROM '.freeze
|
|
607
|
+
Sequel::Deprecation.deprecate_constant(self, :FROM)
|
|
608
|
+
COMMA = ', '.freeze
|
|
609
|
+
Sequel::Deprecation.deprecate_constant(self, :COMMA)
|
|
610
|
+
LIMIT = " LIMIT ".freeze
|
|
611
|
+
Sequel::Deprecation.deprecate_constant(self, :LIMIT)
|
|
612
|
+
GROUP_BY = " GROUP BY ".freeze
|
|
613
|
+
Sequel::Deprecation.deprecate_constant(self, :GROUP_BY)
|
|
614
|
+
ESCAPE = " ESCAPE ".freeze
|
|
615
|
+
Sequel::Deprecation.deprecate_constant(self, :ESCAPE)
|
|
616
|
+
BACKSLASH = "\\".freeze
|
|
617
|
+
Sequel::Deprecation.deprecate_constant(self, :BACKSLASH)
|
|
596
618
|
REGEXP = 'REGEXP'.freeze
|
|
619
|
+
Sequel::Deprecation.deprecate_constant(self, :REGEXP)
|
|
597
620
|
LIKE = 'LIKE'.freeze
|
|
621
|
+
Sequel::Deprecation.deprecate_constant(self, :LIKE)
|
|
598
622
|
BINARY = 'BINARY '.freeze
|
|
623
|
+
Sequel::Deprecation.deprecate_constant(self, :BINARY)
|
|
599
624
|
CONCAT = "CONCAT".freeze
|
|
625
|
+
Sequel::Deprecation.deprecate_constant(self, :CONCAT)
|
|
600
626
|
CAST_BITCOMP_OPEN = "CAST(~".freeze
|
|
627
|
+
Sequel::Deprecation.deprecate_constant(self, :CAST_BITCOMP_OPEN)
|
|
601
628
|
CAST_BITCOMP_CLOSE = " AS SIGNED INTEGER)".freeze
|
|
629
|
+
Sequel::Deprecation.deprecate_constant(self, :CAST_BITCOMP_CLOSE)
|
|
602
630
|
STRAIGHT_JOIN = 'STRAIGHT_JOIN'.freeze
|
|
631
|
+
Sequel::Deprecation.deprecate_constant(self, :STRAIGHT_JOIN)
|
|
603
632
|
NATURAL_LEFT_JOIN = 'NATURAL LEFT JOIN'.freeze
|
|
633
|
+
Sequel::Deprecation.deprecate_constant(self, :NATURAL_LEFT_JOIN)
|
|
604
634
|
BACKTICK = '`'.freeze
|
|
635
|
+
Sequel::Deprecation.deprecate_constant(self, :BACKTICK)
|
|
605
636
|
BACKTICK_RE = /`/.freeze
|
|
637
|
+
Sequel::Deprecation.deprecate_constant(self, :BACKTICK_RE)
|
|
606
638
|
DOUBLE_BACKTICK = '``'.freeze
|
|
639
|
+
Sequel::Deprecation.deprecate_constant(self, :DOUBLE_BACKTICK)
|
|
607
640
|
EMPTY_COLUMNS = " ()".freeze
|
|
641
|
+
Sequel::Deprecation.deprecate_constant(self, :EMPTY_COLUMNS)
|
|
608
642
|
EMPTY_VALUES = " VALUES ()".freeze
|
|
643
|
+
Sequel::Deprecation.deprecate_constant(self, :EMPTY_VALUES)
|
|
609
644
|
IGNORE = " IGNORE".freeze
|
|
645
|
+
Sequel::Deprecation.deprecate_constant(self, :IGNORE)
|
|
610
646
|
ON_DUPLICATE_KEY_UPDATE = " ON DUPLICATE KEY UPDATE ".freeze
|
|
647
|
+
Sequel::Deprecation.deprecate_constant(self, :ON_DUPLICATE_KEY_UPDATE)
|
|
611
648
|
EQ_VALUES = '=VALUES('.freeze
|
|
649
|
+
Sequel::Deprecation.deprecate_constant(self, :EQ_VALUES)
|
|
612
650
|
EQ = '='.freeze
|
|
651
|
+
Sequel::Deprecation.deprecate_constant(self, :EQ)
|
|
613
652
|
WITH_ROLLUP = ' WITH ROLLUP'.freeze
|
|
614
|
-
|
|
615
|
-
MATCH_AGAINST_BOOLEAN = ["(MATCH ".freeze, " AGAINST (".freeze, " IN BOOLEAN MODE))".freeze].freeze
|
|
653
|
+
Sequel::Deprecation.deprecate_constant(self, :WITH_ROLLUP)
|
|
616
654
|
EXPLAIN = 'EXPLAIN '.freeze
|
|
655
|
+
Sequel::Deprecation.deprecate_constant(self, :EXPLAIN)
|
|
617
656
|
EXPLAIN_EXTENDED = 'EXPLAIN EXTENDED '.freeze
|
|
657
|
+
Sequel::Deprecation.deprecate_constant(self, :EXPLAIN_EXTENDED)
|
|
618
658
|
BACKSLASH_RE = /\\/.freeze
|
|
659
|
+
Sequel::Deprecation.deprecate_constant(self, :BACKSLASH_RE)
|
|
619
660
|
QUAD_BACKSLASH = "\\\\\\\\".freeze
|
|
661
|
+
Sequel::Deprecation.deprecate_constant(self, :QUAD_BACKSLASH)
|
|
620
662
|
BLOB_START = "0x".freeze
|
|
663
|
+
Sequel::Deprecation.deprecate_constant(self, :BLOB_START)
|
|
621
664
|
EMPTY_BLOB = "''".freeze
|
|
665
|
+
Sequel::Deprecation.deprecate_constant(self, :EMPTY_BLOB)
|
|
622
666
|
HSTAR = "H*".freeze
|
|
667
|
+
Sequel::Deprecation.deprecate_constant(self, :HSTAR)
|
|
623
668
|
CURRENT_TIMESTAMP_56 = 'CURRENT_TIMESTAMP(6)'.freeze
|
|
624
|
-
|
|
625
|
-
# Comes directly from MySQL's documentation, used for queries with limits without offsets
|
|
669
|
+
Sequel::Deprecation.deprecate_constant(self, :CURRENT_TIMESTAMP_56)
|
|
626
670
|
ONLY_OFFSET = ",18446744073709551615".freeze
|
|
671
|
+
Sequel::Deprecation.deprecate_constant(self, :ONLY_OFFSET)
|
|
627
672
|
|
|
673
|
+
MATCH_AGAINST = ["MATCH ".freeze, " AGAINST (".freeze, ")".freeze].freeze
|
|
674
|
+
MATCH_AGAINST_BOOLEAN = ["MATCH ".freeze, " AGAINST (".freeze, " IN BOOLEAN MODE)".freeze].freeze
|
|
628
675
|
NON_SQL_OPTIONS = (Dataset::NON_SQL_OPTIONS + [:insert_ignore, :update_ignore, :on_duplicate_key_update]).freeze
|
|
629
676
|
|
|
630
677
|
Dataset.def_sql_method(self, :delete, %w'delete from where order limit')
|
|
@@ -640,37 +687,37 @@ module Sequel
|
|
|
640
687
|
def complex_expression_sql_append(sql, op, args)
|
|
641
688
|
case op
|
|
642
689
|
when :IN, :"NOT IN"
|
|
643
|
-
ds = args
|
|
690
|
+
ds = args[1]
|
|
644
691
|
if ds.is_a?(Sequel::Dataset) && ds.opts[:limit]
|
|
645
|
-
super(sql, op, [args
|
|
692
|
+
super(sql, op, [args[0], ds.from_self])
|
|
646
693
|
else
|
|
647
694
|
super
|
|
648
695
|
end
|
|
649
696
|
when :~, :'!~', :'~*', :'!~*', :LIKE, :'NOT LIKE', :ILIKE, :'NOT ILIKE'
|
|
650
|
-
sql <<
|
|
651
|
-
literal_append(sql, args
|
|
652
|
-
sql <<
|
|
697
|
+
sql << '('
|
|
698
|
+
literal_append(sql, args[0])
|
|
699
|
+
sql << ' '
|
|
653
700
|
sql << 'NOT ' if [:'NOT LIKE', :'NOT ILIKE', :'!~', :'!~*'].include?(op)
|
|
654
|
-
sql << ([:~, :'!~', :'~*', :'!~*'].include?(op) ? REGEXP : LIKE)
|
|
655
|
-
sql <<
|
|
656
|
-
sql << BINARY if [:~, :'!~', :LIKE, :'NOT LIKE'].include?(op)
|
|
657
|
-
literal_append(sql, args
|
|
701
|
+
sql << ([:~, :'!~', :'~*', :'!~*'].include?(op) ? 'REGEXP' : 'LIKE')
|
|
702
|
+
sql << ' '
|
|
703
|
+
sql << 'BINARY ' if [:~, :'!~', :LIKE, :'NOT LIKE'].include?(op)
|
|
704
|
+
literal_append(sql, args[1])
|
|
658
705
|
if [:LIKE, :'NOT LIKE', :ILIKE, :'NOT ILIKE'].include?(op)
|
|
659
|
-
sql << ESCAPE
|
|
660
|
-
literal_append(sql,
|
|
706
|
+
sql << " ESCAPE "
|
|
707
|
+
literal_append(sql, "\\")
|
|
661
708
|
end
|
|
662
|
-
sql <<
|
|
709
|
+
sql << ')'
|
|
663
710
|
when :'||'
|
|
664
711
|
if args.length > 1
|
|
665
|
-
sql << CONCAT
|
|
712
|
+
sql << "CONCAT"
|
|
666
713
|
array_sql_append(sql, args)
|
|
667
714
|
else
|
|
668
|
-
literal_append(sql, args
|
|
715
|
+
literal_append(sql, args[0])
|
|
669
716
|
end
|
|
670
717
|
when :'B~'
|
|
671
|
-
sql <<
|
|
672
|
-
literal_append(sql, args
|
|
673
|
-
sql <<
|
|
718
|
+
sql << "CAST(~"
|
|
719
|
+
literal_append(sql, args[0])
|
|
720
|
+
sql << " AS SIGNED INTEGER)"
|
|
674
721
|
else
|
|
675
722
|
super
|
|
676
723
|
end
|
|
@@ -682,7 +729,7 @@ module Sequel
|
|
|
682
729
|
# fractional seconds.
|
|
683
730
|
def constant_sql_append(sql, constant)
|
|
684
731
|
if constant == :CURRENT_TIMESTAMP && supports_timestamp_usecs?
|
|
685
|
-
sql <<
|
|
732
|
+
sql << 'CURRENT_TIMESTAMP(6)'
|
|
686
733
|
else
|
|
687
734
|
super
|
|
688
735
|
end
|
|
@@ -719,7 +766,7 @@ module Sequel
|
|
|
719
766
|
# Load the PrettyTable class, needed for explain output
|
|
720
767
|
Sequel.extension(:_pretty_table) unless defined?(Sequel::PrettyTable)
|
|
721
768
|
|
|
722
|
-
ds = db.send(:metadata_dataset).with_sql((opts[:extended] ?
|
|
769
|
+
ds = db.send(:metadata_dataset).with_sql((opts[:extended] ? 'EXPLAIN EXTENDED ' : 'EXPLAIN ') + select_sql).naked
|
|
723
770
|
rows = ds.all
|
|
724
771
|
Sequel::PrettyTable.string(rows, ds.columns)
|
|
725
772
|
end
|
|
@@ -753,9 +800,9 @@ module Sequel
|
|
|
753
800
|
def join_type_sql(join_type)
|
|
754
801
|
case join_type
|
|
755
802
|
when :straight
|
|
756
|
-
STRAIGHT_JOIN
|
|
803
|
+
'STRAIGHT_JOIN'
|
|
757
804
|
when :natural_inner
|
|
758
|
-
|
|
805
|
+
'NATURAL LEFT JOIN'
|
|
759
806
|
else
|
|
760
807
|
super
|
|
761
808
|
end
|
|
@@ -808,7 +855,7 @@ module Sequel
|
|
|
808
855
|
|
|
809
856
|
# MySQL uses the nonstandard ` (backtick) for quoting identifiers.
|
|
810
857
|
def quoted_identifier_append(sql, c)
|
|
811
|
-
sql <<
|
|
858
|
+
sql << '`' << c.to_s.gsub('`', '``') << '`'
|
|
812
859
|
end
|
|
813
860
|
|
|
814
861
|
# MySQL does not support derived column lists
|
|
@@ -881,10 +928,10 @@ module Sequel
|
|
|
881
928
|
# from, but include the others for the purposes of selecting rows.
|
|
882
929
|
def delete_from_sql(sql)
|
|
883
930
|
if joined_dataset?
|
|
884
|
-
sql <<
|
|
931
|
+
sql << ' '
|
|
885
932
|
tables = @opts[:delete_from] || @opts[:from][0..0]
|
|
886
933
|
source_list_append(sql, tables)
|
|
887
|
-
sql << FROM
|
|
934
|
+
sql << ' FROM '
|
|
888
935
|
source_list_append(sql, @opts[:from])
|
|
889
936
|
select_join_sql(sql)
|
|
890
937
|
else
|
|
@@ -896,7 +943,7 @@ module Sequel
|
|
|
896
943
|
def insert_columns_sql(sql)
|
|
897
944
|
values = opts[:values]
|
|
898
945
|
if values.is_a?(Array) && values.empty?
|
|
899
|
-
sql <<
|
|
946
|
+
sql << " ()"
|
|
900
947
|
else
|
|
901
948
|
super
|
|
902
949
|
end
|
|
@@ -904,12 +951,12 @@ module Sequel
|
|
|
904
951
|
|
|
905
952
|
# MySQL supports INSERT IGNORE INTO
|
|
906
953
|
def insert_ignore_sql(sql)
|
|
907
|
-
sql << IGNORE if opts[:insert_ignore]
|
|
954
|
+
sql << " IGNORE" if opts[:insert_ignore]
|
|
908
955
|
end
|
|
909
956
|
|
|
910
957
|
# MySQL supports UPDATE IGNORE
|
|
911
958
|
def update_ignore_sql(sql)
|
|
912
|
-
sql << IGNORE if opts[:update_ignore]
|
|
959
|
+
sql << " IGNORE" if opts[:update_ignore]
|
|
913
960
|
end
|
|
914
961
|
|
|
915
962
|
# MySQL supports INSERT ... ON DUPLICATE KEY UPDATE
|
|
@@ -924,11 +971,11 @@ module Sequel
|
|
|
924
971
|
update_cols = update_cols[0..-2]
|
|
925
972
|
end
|
|
926
973
|
|
|
927
|
-
sql <<
|
|
974
|
+
sql << " ON DUPLICATE KEY UPDATE "
|
|
928
975
|
c = false
|
|
929
|
-
co =
|
|
930
|
-
values =
|
|
931
|
-
endp =
|
|
976
|
+
co = ', '
|
|
977
|
+
values = '=VALUES('
|
|
978
|
+
endp = ')'
|
|
932
979
|
update_cols.each do |col|
|
|
933
980
|
sql << co if c
|
|
934
981
|
quote_identifier_append(sql, col)
|
|
@@ -938,7 +985,7 @@ module Sequel
|
|
|
938
985
|
c ||= true
|
|
939
986
|
end
|
|
940
987
|
if update_vals
|
|
941
|
-
eq =
|
|
988
|
+
eq = '='
|
|
942
989
|
update_vals.map do |col,v|
|
|
943
990
|
sql << co if c
|
|
944
991
|
quote_identifier_append(sql, col)
|
|
@@ -954,7 +1001,7 @@ module Sequel
|
|
|
954
1001
|
def insert_values_sql(sql)
|
|
955
1002
|
values = opts[:values]
|
|
956
1003
|
if values.is_a?(Array) && values.empty?
|
|
957
|
-
sql <<
|
|
1004
|
+
sql << " VALUES ()"
|
|
958
1005
|
else
|
|
959
1006
|
super
|
|
960
1007
|
end
|
|
@@ -963,7 +1010,7 @@ module Sequel
|
|
|
963
1010
|
# MySQL allows a LIMIT in DELETE and UPDATE statements.
|
|
964
1011
|
def limit_sql(sql)
|
|
965
1012
|
if l = @opts[:limit]
|
|
966
|
-
sql << LIMIT
|
|
1013
|
+
sql << " LIMIT "
|
|
967
1014
|
literal_append(sql, l)
|
|
968
1015
|
end
|
|
969
1016
|
end
|
|
@@ -973,15 +1020,15 @@ module Sequel
|
|
|
973
1020
|
# MySQL uses a preceding X for hex escaping strings
|
|
974
1021
|
def literal_blob_append(sql, v)
|
|
975
1022
|
if v.empty?
|
|
976
|
-
sql <<
|
|
1023
|
+
sql << "''"
|
|
977
1024
|
else
|
|
978
|
-
sql <<
|
|
1025
|
+
sql << "0x" << v.unpack("H*").first
|
|
979
1026
|
end
|
|
980
1027
|
end
|
|
981
1028
|
|
|
982
1029
|
# Use 0 for false on MySQL
|
|
983
1030
|
def literal_false
|
|
984
|
-
|
|
1031
|
+
'0'
|
|
985
1032
|
end
|
|
986
1033
|
|
|
987
1034
|
# Raise error for infinitate and NaN values
|
|
@@ -995,12 +1042,12 @@ module Sequel
|
|
|
995
1042
|
|
|
996
1043
|
# SQL fragment for String. Doubles \ and ' by default.
|
|
997
1044
|
def literal_string_append(sql, v)
|
|
998
|
-
sql <<
|
|
1045
|
+
sql << "'" << v.gsub("\\", "\\\\\\\\").gsub("'", "''") << "'"
|
|
999
1046
|
end
|
|
1000
1047
|
|
|
1001
1048
|
# Use 1 for true on MySQL
|
|
1002
1049
|
def literal_true
|
|
1003
|
-
|
|
1050
|
+
'1'
|
|
1004
1051
|
end
|
|
1005
1052
|
|
|
1006
1053
|
# MySQL supports multiple rows in INSERT.
|
|
@@ -1014,19 +1061,19 @@ module Sequel
|
|
|
1014
1061
|
end
|
|
1015
1062
|
|
|
1016
1063
|
def select_only_offset_sql(sql)
|
|
1017
|
-
sql << LIMIT
|
|
1064
|
+
sql << " LIMIT "
|
|
1018
1065
|
literal_append(sql, @opts[:offset])
|
|
1019
|
-
sql <<
|
|
1066
|
+
sql << ",18446744073709551615"
|
|
1020
1067
|
end
|
|
1021
1068
|
|
|
1022
1069
|
# Support FOR SHARE locking when using the :share lock style.
|
|
1023
1070
|
def select_lock_sql(sql)
|
|
1024
|
-
@opts[:lock] == :share ? (sql <<
|
|
1071
|
+
@opts[:lock] == :share ? (sql << ' LOCK IN SHARE MODE') : super
|
|
1025
1072
|
end
|
|
1026
1073
|
|
|
1027
1074
|
# MySQL specific SQL_CALC_FOUND_ROWS option
|
|
1028
1075
|
def select_calc_found_rows_sql(sql)
|
|
1029
|
-
sql << SQL_CALC_FOUND_ROWS if opts[:calc_found_rows]
|
|
1076
|
+
sql << ' SQL_CALC_FOUND_ROWS' if opts[:calc_found_rows]
|
|
1030
1077
|
end
|
|
1031
1078
|
|
|
1032
1079
|
# MySQL uses WITH ROLLUP syntax.
|
|
@@ -15,7 +15,9 @@ module Sequel
|
|
|
15
15
|
|
|
16
16
|
module DatabaseMethods
|
|
17
17
|
TEMPORARY = 'GLOBAL TEMPORARY '.freeze
|
|
18
|
+
Sequel::Deprecation.deprecate_constant(self, :TEMPORARY)
|
|
18
19
|
AUTOINCREMENT = ''.freeze
|
|
20
|
+
Sequel::Deprecation.deprecate_constant(self, :AUTOINCREMENT)
|
|
19
21
|
|
|
20
22
|
attr_accessor :autosequence
|
|
21
23
|
|
|
@@ -86,7 +88,7 @@ module Sequel
|
|
|
86
88
|
false
|
|
87
89
|
end
|
|
88
90
|
|
|
89
|
-
IGNORE_OWNERS = %w'APEX_040000 CTXSYS EXFSYS MDSYS OLAPSYS ORDDATA ORDSYS SYS SYSTEM XDB XDBMETADATA XDBPM XFILES WMSYS'
|
|
91
|
+
IGNORE_OWNERS = %w'APEX_040000 CTXSYS EXFSYS MDSYS OLAPSYS ORDDATA ORDSYS SYS SYSTEM XDB XDBMETADATA XDBPM XFILES WMSYS'#.freeze # SEQUEL5
|
|
90
92
|
|
|
91
93
|
def tables(opts=OPTS)
|
|
92
94
|
m = output_identifier_meth
|
|
@@ -174,7 +176,7 @@ module Sequel
|
|
|
174
176
|
end
|
|
175
177
|
|
|
176
178
|
def auto_increment_sql
|
|
177
|
-
|
|
179
|
+
''
|
|
178
180
|
end
|
|
179
181
|
|
|
180
182
|
def create_sequence_sql(name, opts=OPTS)
|
|
@@ -251,7 +253,7 @@ module Sequel
|
|
|
251
253
|
TRANSACTION_ISOLATION_LEVELS = {:uncommitted=>'READ COMMITTED'.freeze,
|
|
252
254
|
:committed=>'READ COMMITTED'.freeze,
|
|
253
255
|
:repeatable=>'SERIALIZABLE'.freeze,
|
|
254
|
-
:serializable=>'SERIALIZABLE'.freeze}
|
|
256
|
+
:serializable=>'SERIALIZABLE'.freeze}#.freeze # SEQUEL5
|
|
255
257
|
# Oracle doesn't support READ UNCOMMITTED OR REPEATABLE READ transaction
|
|
256
258
|
# isolation levels, so upgrade to the next highest level in those cases.
|
|
257
259
|
def set_transaction_isolation_sql(level)
|
|
@@ -302,7 +304,7 @@ module Sequel
|
|
|
302
304
|
|
|
303
305
|
# SQL fragment for showing a table is temporary
|
|
304
306
|
def temporary_table_sql
|
|
305
|
-
TEMPORARY
|
|
307
|
+
'GLOBAL TEMPORARY '
|
|
306
308
|
end
|
|
307
309
|
|
|
308
310
|
# Oracle uses clob for text types.
|
|
@@ -318,19 +320,32 @@ module Sequel
|
|
|
318
320
|
|
|
319
321
|
module DatasetMethods
|
|
320
322
|
ROW_NUMBER_EXPRESSION = LiteralString.new('ROWNUM').freeze
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
323
|
+
BITAND_PROC = lambda{|a, b| Sequel.lit(["CAST(BITAND(", ", ", ") AS INTEGER)"], a, b)}
|
|
324
|
+
|
|
325
|
+
SPACE = ' '.freeze
|
|
326
|
+
Sequel::Deprecation.deprecate_constant(self, :SPACE)
|
|
327
|
+
APOS = "'".freeze
|
|
328
|
+
Sequel::Deprecation.deprecate_constant(self, :APOS)
|
|
329
|
+
APOS_RE = /'/.freeze
|
|
330
|
+
Sequel::Deprecation.deprecate_constant(self, :APOS_RE)
|
|
331
|
+
DOUBLE_APOS = "''".freeze
|
|
332
|
+
Sequel::Deprecation.deprecate_constant(self, :DOUBLE_APOS)
|
|
333
|
+
FROM = ' FROM '.freeze
|
|
334
|
+
Sequel::Deprecation.deprecate_constant(self, :FROM)
|
|
326
335
|
TIMESTAMP_FORMAT = "TIMESTAMP '%Y-%m-%d %H:%M:%S%N %z'".freeze
|
|
336
|
+
Sequel::Deprecation.deprecate_constant(self, :TIMESTAMP_FORMAT)
|
|
327
337
|
TIMESTAMP_OFFSET_FORMAT = "%+03i:%02i".freeze
|
|
338
|
+
Sequel::Deprecation.deprecate_constant(self, :TIMESTAMP_OFFSET_FORMAT)
|
|
328
339
|
BOOL_FALSE = "'N'".freeze
|
|
340
|
+
Sequel::Deprecation.deprecate_constant(self, :BOOL_FALSE)
|
|
329
341
|
BOOL_TRUE = "'Y'".freeze
|
|
342
|
+
Sequel::Deprecation.deprecate_constant(self, :BOOL_TRUE)
|
|
330
343
|
HSTAR = "H*".freeze
|
|
344
|
+
Sequel::Deprecation.deprecate_constant(self, :HSTAR)
|
|
331
345
|
DUAL = ' FROM DUAL'.freeze
|
|
332
|
-
|
|
346
|
+
Sequel::Deprecation.deprecate_constant(self, :DUAL)
|
|
333
347
|
SKIP_LOCKED = " SKIP LOCKED".freeze
|
|
348
|
+
Sequel::Deprecation.deprecate_constant(self, :SKIP_LOCKED)
|
|
334
349
|
|
|
335
350
|
include(Module.new do
|
|
336
351
|
Dataset.def_sql_method(self, :select, %w'with select distinct columns from join where group having compounds order lock')
|
|
@@ -354,9 +369,9 @@ module Sequel
|
|
|
354
369
|
sql << 'NOT '
|
|
355
370
|
end
|
|
356
371
|
sql << 'REGEXP_LIKE('
|
|
357
|
-
literal_append(sql, args
|
|
372
|
+
literal_append(sql, args[0])
|
|
358
373
|
sql << ','
|
|
359
|
-
literal_append(sql, args
|
|
374
|
+
literal_append(sql, args[1])
|
|
360
375
|
if op == :'~*' || op == :'!~*'
|
|
361
376
|
sql << ", 'i'"
|
|
362
377
|
end
|
|
@@ -530,17 +545,17 @@ module Sequel
|
|
|
530
545
|
# the use of AS anywhere, so this disables it in all cases.
|
|
531
546
|
def as_sql_append(sql, aliaz, column_aliases=nil)
|
|
532
547
|
raise Error, "oracle does not support derived column lists" if column_aliases
|
|
533
|
-
sql <<
|
|
548
|
+
sql << ' '
|
|
534
549
|
quote_identifier_append(sql, aliaz)
|
|
535
550
|
end
|
|
536
551
|
|
|
537
552
|
# The strftime format to use when literalizing the time.
|
|
538
553
|
def default_timestamp_format
|
|
539
|
-
|
|
554
|
+
"TIMESTAMP '%Y-%m-%d %H:%M:%S%N %z'"
|
|
540
555
|
end
|
|
541
556
|
|
|
542
557
|
def empty_from_sql
|
|
543
|
-
DUAL
|
|
558
|
+
' FROM DUAL'
|
|
544
559
|
end
|
|
545
560
|
|
|
546
561
|
# There is no function on Microsoft SQL Server that does character length
|
|
@@ -575,7 +590,7 @@ module Sequel
|
|
|
575
590
|
|
|
576
591
|
# Use a colon for the timestamp offset, since Oracle appears to require it.
|
|
577
592
|
def format_timestamp_offset(hour, minute)
|
|
578
|
-
sprintf(
|
|
593
|
+
sprintf("%+03i:%02i", hour, minute)
|
|
579
594
|
end
|
|
580
595
|
|
|
581
596
|
# Oracle doesn't support empty values when inserting.
|
|
@@ -585,22 +600,22 @@ module Sequel
|
|
|
585
600
|
|
|
586
601
|
# Use string in hex format for blob data.
|
|
587
602
|
def literal_blob_append(sql, v)
|
|
588
|
-
sql <<
|
|
603
|
+
sql << "'" << v.unpack("H*").first << "'"
|
|
589
604
|
end
|
|
590
605
|
|
|
591
606
|
# Oracle uses 'N' for false values.
|
|
592
607
|
def literal_false
|
|
593
|
-
|
|
608
|
+
"'N'"
|
|
594
609
|
end
|
|
595
610
|
|
|
596
611
|
# Oracle uses the SQL standard of only doubling ' inside strings.
|
|
597
612
|
def literal_string_append(sql, v)
|
|
598
|
-
sql <<
|
|
613
|
+
sql << "'" << v.gsub("'", "''") << "'"
|
|
599
614
|
end
|
|
600
615
|
|
|
601
616
|
# Oracle uses 'Y' for true values.
|
|
602
617
|
def literal_true
|
|
603
|
-
|
|
618
|
+
"'Y'"
|
|
604
619
|
end
|
|
605
620
|
|
|
606
621
|
# Oracle can insert multiple rows using a UNION
|
|
@@ -613,7 +628,7 @@ module Sequel
|
|
|
613
628
|
super
|
|
614
629
|
|
|
615
630
|
if @opts[:skip_locked]
|
|
616
|
-
sql <<
|
|
631
|
+
sql << " SKIP LOCKED"
|
|
617
632
|
end
|
|
618
633
|
end
|
|
619
634
|
|