sequel 4.46.0 → 4.49.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 +210 -0
- data/Rakefile +1 -1
- data/doc/advanced_associations.rdoc +1 -1
- data/doc/opening_databases.rdoc +3 -2
- data/doc/release_notes/4.47.0.txt +56 -0
- data/doc/release_notes/4.48.0.txt +293 -0
- data/doc/release_notes/4.49.0.txt +222 -0
- data/lib/sequel/adapters/ado/access.rb +2 -1
- data/lib/sequel/adapters/do/postgres.rb +5 -2
- data/lib/sequel/adapters/ibmdb.rb +30 -8
- data/lib/sequel/adapters/jdbc/as400.rb +1 -1
- data/lib/sequel/adapters/jdbc/db2.rb +12 -3
- data/lib/sequel/adapters/jdbc/derby.rb +4 -5
- data/lib/sequel/adapters/jdbc/h2.rb +10 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
- data/lib/sequel/adapters/jdbc/postgresql.rb +46 -20
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
- data/lib/sequel/adapters/jdbc/sqlserver.rb +20 -6
- data/lib/sequel/adapters/jdbc.rb +39 -23
- data/lib/sequel/adapters/mock.rb +27 -19
- data/lib/sequel/adapters/mysql.rb +17 -16
- data/lib/sequel/adapters/mysql2.rb +5 -6
- data/lib/sequel/adapters/oracle.rb +5 -9
- data/lib/sequel/adapters/postgres.rb +91 -103
- data/lib/sequel/adapters/shared/db2.rb +22 -6
- data/lib/sequel/adapters/shared/mssql.rb +5 -4
- data/lib/sequel/adapters/shared/mysql.rb +79 -25
- data/lib/sequel/adapters/shared/oracle.rb +26 -3
- data/lib/sequel/adapters/shared/postgres.rb +199 -95
- data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
- data/lib/sequel/adapters/shared/sqlite.rb +72 -82
- data/lib/sequel/adapters/sqlanywhere.rb +4 -1
- data/lib/sequel/adapters/sqlite.rb +5 -3
- data/lib/sequel/adapters/swift/postgres.rb +5 -2
- data/lib/sequel/adapters/tinytds.rb +0 -5
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
- data/lib/sequel/adapters/utils/pg_types.rb +2 -76
- data/lib/sequel/ast_transformer.rb +1 -1
- data/lib/sequel/connection_pool/sharded_single.rb +1 -1
- data/lib/sequel/connection_pool/sharded_threaded.rb +1 -1
- data/lib/sequel/connection_pool/single.rb +2 -2
- data/lib/sequel/connection_pool/threaded.rb +2 -2
- data/lib/sequel/connection_pool.rb +9 -2
- data/lib/sequel/core.rb +2 -2
- data/lib/sequel/database/connecting.rb +8 -8
- data/lib/sequel/database/dataset.rb +6 -3
- data/lib/sequel/database/dataset_defaults.rb +14 -1
- data/lib/sequel/database/misc.rb +1 -1
- data/lib/sequel/database/query.rb +3 -0
- data/lib/sequel/database/schema_methods.rb +1 -1
- data/lib/sequel/dataset/actions.rb +72 -10
- data/lib/sequel/dataset/dataset_module.rb +58 -0
- data/lib/sequel/dataset/graph.rb +1 -1
- data/lib/sequel/dataset/misc.rb +1 -0
- data/lib/sequel/dataset/prepared_statements.rb +3 -3
- data/lib/sequel/dataset/query.rb +22 -11
- data/lib/sequel/dataset.rb +1 -1
- data/lib/sequel/exceptions.rb +8 -0
- data/lib/sequel/extensions/_model_pg_row.rb +5 -2
- data/lib/sequel/extensions/core_extensions.rb +4 -1
- data/lib/sequel/extensions/current_datetime_timestamp.rb +2 -1
- data/lib/sequel/extensions/date_arithmetic.rb +1 -0
- data/lib/sequel/extensions/duplicate_columns_handler.rb +3 -3
- data/lib/sequel/extensions/empty_array_ignore_nulls.rb +3 -0
- data/lib/sequel/extensions/filter_having.rb +2 -0
- data/lib/sequel/extensions/freeze_datasets.rb +2 -0
- data/lib/sequel/extensions/from_block.rb +1 -1
- data/lib/sequel/extensions/graph_each.rb +2 -2
- data/lib/sequel/extensions/hash_aliases.rb +2 -0
- data/lib/sequel/extensions/identifier_mangling.rb +0 -7
- data/lib/sequel/extensions/meta_def.rb +2 -0
- data/lib/sequel/extensions/migration.rb +11 -8
- data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
- data/lib/sequel/extensions/null_dataset.rb +1 -0
- data/lib/sequel/extensions/pagination.rb +1 -1
- data/lib/sequel/extensions/pg_array.rb +207 -130
- data/lib/sequel/extensions/pg_hstore.rb +38 -20
- data/lib/sequel/extensions/pg_inet.rb +18 -6
- data/lib/sequel/extensions/pg_interval.rb +19 -12
- data/lib/sequel/extensions/pg_json.rb +25 -14
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/extensions/pg_range.rb +133 -100
- data/lib/sequel/extensions/pg_range_ops.rb +4 -3
- data/lib/sequel/extensions/pg_row.rb +68 -39
- data/lib/sequel/extensions/pg_row_ops.rb +11 -5
- data/lib/sequel/extensions/query_literals.rb +2 -0
- data/lib/sequel/extensions/ruby18_symbol_extensions.rb +2 -0
- data/lib/sequel/extensions/s.rb +1 -1
- data/lib/sequel/extensions/schema_dumper.rb +29 -25
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +3 -1
- data/lib/sequel/extensions/sequel_4_dataset_methods.rb +83 -0
- data/lib/sequel/extensions/server_block.rb +32 -15
- data/lib/sequel/extensions/set_overrides.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +0 -1
- data/lib/sequel/extensions/symbol_aref.rb +0 -4
- data/lib/sequel/model/associations.rb +35 -7
- data/lib/sequel/model/base.rb +113 -87
- data/lib/sequel/model/dataset_module.rb +5 -43
- data/lib/sequel/model/errors.rb +2 -1
- data/lib/sequel/model/inflections.rb +17 -5
- data/lib/sequel/model.rb +26 -58
- data/lib/sequel/plugins/active_model.rb +2 -2
- data/lib/sequel/plugins/association_autoreloading.rb +2 -0
- data/lib/sequel/plugins/association_dependencies.rb +3 -3
- data/lib/sequel/plugins/association_pks.rb +73 -46
- data/lib/sequel/plugins/association_proxies.rb +1 -1
- data/lib/sequel/plugins/auto_validations.rb +6 -2
- data/lib/sequel/plugins/boolean_readers.rb +2 -2
- data/lib/sequel/plugins/boolean_subsets.rb +1 -1
- data/lib/sequel/plugins/caching.rb +19 -13
- data/lib/sequel/plugins/class_table_inheritance.rb +24 -13
- data/lib/sequel/plugins/column_conflicts.rb +7 -2
- data/lib/sequel/plugins/column_select.rb +3 -3
- data/lib/sequel/plugins/composition.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +8 -8
- data/lib/sequel/plugins/dataset_associations.rb +25 -13
- data/lib/sequel/plugins/defaults_setter.rb +13 -1
- data/lib/sequel/plugins/eager_each.rb +1 -1
- data/lib/sequel/plugins/force_encoding.rb +2 -2
- data/lib/sequel/plugins/hook_class_methods.rb +9 -12
- data/lib/sequel/plugins/identifier_columns.rb +2 -0
- data/lib/sequel/plugins/instance_filters.rb +3 -1
- data/lib/sequel/plugins/instance_hooks.rb +17 -9
- data/lib/sequel/plugins/json_serializer.rb +19 -12
- data/lib/sequel/plugins/lazy_attributes.rb +8 -7
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +2 -0
- data/lib/sequel/plugins/modification_detection.rb +3 -0
- data/lib/sequel/plugins/nested_attributes.rb +6 -2
- data/lib/sequel/plugins/pg_array_associations.rb +5 -0
- data/lib/sequel/plugins/pg_row.rb +4 -2
- data/lib/sequel/plugins/pg_typecast_on_load.rb +2 -0
- data/lib/sequel/plugins/prepared_statements.rb +1 -0
- data/lib/sequel/plugins/rcte_tree.rb +4 -24
- data/lib/sequel/plugins/serialization.rb +9 -15
- data/lib/sequel/plugins/single_table_inheritance.rb +8 -3
- data/lib/sequel/plugins/split_values.rb +6 -5
- data/lib/sequel/plugins/static_cache.rb +31 -25
- data/lib/sequel/plugins/subset_conditions.rb +3 -1
- data/lib/sequel/plugins/table_select.rb +1 -1
- data/lib/sequel/plugins/touch.rb +4 -2
- data/lib/sequel/plugins/validation_class_methods.rb +5 -6
- data/lib/sequel/plugins/validation_helpers.rb +14 -8
- data/lib/sequel/plugins/xml_serializer.rb +4 -4
- data/lib/sequel/sql.rb +18 -9
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +115 -14
- data/spec/adapters/mssql_spec.rb +4 -4
- data/spec/adapters/mysql_spec.rb +83 -29
- data/spec/adapters/oracle_spec.rb +28 -24
- data/spec/adapters/postgres_spec.rb +40 -24
- data/spec/adapters/sqlanywhere_spec.rb +88 -86
- data/spec/adapters/sqlite_spec.rb +29 -24
- data/spec/bin_spec.rb +7 -1
- data/spec/core/connection_pool_spec.rb +45 -14
- data/spec/core/database_spec.rb +155 -0
- data/spec/core/dataset_spec.rb +219 -36
- data/spec/core/schema_spec.rb +16 -0
- data/spec/core/spec_helper.rb +1 -0
- data/spec/core_extensions_spec.rb +6 -2
- data/spec/extensions/active_model_spec.rb +1 -1
- data/spec/extensions/arbitrary_servers_spec.rb +1 -1
- data/spec/extensions/association_pks_spec.rb +34 -2
- data/spec/extensions/auto_literal_strings_spec.rb +5 -1
- data/spec/extensions/auto_validations_spec.rb +2 -0
- data/spec/extensions/boolean_readers_spec.rb +1 -1
- data/spec/extensions/boolean_subsets_spec.rb +1 -1
- data/spec/extensions/class_table_inheritance_spec.rb +106 -19
- data/spec/extensions/column_conflicts_spec.rb +11 -0
- data/spec/extensions/column_select_spec.rb +1 -0
- data/spec/extensions/composition_spec.rb +13 -0
- data/spec/extensions/connection_validator_spec.rb +1 -1
- data/spec/extensions/dataset_associations_spec.rb +20 -8
- data/spec/extensions/defaults_setter_spec.rb +15 -1
- data/spec/extensions/filter_having_spec.rb +5 -3
- data/spec/extensions/hash_aliases_spec.rb +3 -1
- data/spec/extensions/identifier_columns_spec.rb +3 -1
- data/spec/extensions/implicit_subquery_spec.rb +4 -2
- data/spec/extensions/json_serializer_spec.rb +18 -0
- data/spec/extensions/lazy_attributes_spec.rb +3 -3
- data/spec/extensions/many_through_many_spec.rb +4 -4
- data/spec/extensions/meta_def_spec.rb +9 -0
- data/spec/extensions/migration_spec.rb +3 -3
- data/spec/extensions/nested_attributes_spec.rb +14 -3
- data/spec/extensions/no_auto_literal_strings_spec.rb +8 -4
- data/spec/extensions/null_dataset_spec.rb +1 -1
- data/spec/extensions/pg_array_associations_spec.rb +29 -18
- data/spec/extensions/pg_array_spec.rb +44 -25
- data/spec/extensions/pg_hstore_spec.rb +10 -0
- data/spec/extensions/pg_inet_spec.rb +26 -0
- data/spec/extensions/pg_interval_spec.rb +20 -0
- data/spec/extensions/pg_json_spec.rb +24 -0
- data/spec/extensions/pg_range_spec.rb +98 -14
- data/spec/extensions/pg_row_spec.rb +14 -4
- data/spec/extensions/pg_typecast_on_load_spec.rb +11 -9
- data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
- data/spec/extensions/query_literals_spec.rb +3 -1
- data/spec/extensions/schema_dumper_spec.rb +108 -94
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +10 -6
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +121 -0
- data/spec/extensions/serialization_spec.rb +1 -1
- data/spec/extensions/server_block_spec.rb +7 -0
- data/spec/extensions/single_table_inheritance_spec.rb +17 -1
- data/spec/extensions/spec_helper.rb +7 -1
- data/spec/extensions/static_cache_spec.rb +75 -24
- data/spec/extensions/string_agg_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +9 -0
- data/spec/extensions/validation_helpers_spec.rb +10 -5
- data/spec/extensions/whitelist_security_spec.rb +26 -0
- data/spec/integration/associations_test.rb +8 -0
- data/spec/integration/dataset_test.rb +45 -44
- data/spec/integration/model_test.rb +53 -4
- data/spec/integration/plugin_test.rb +28 -4
- data/spec/integration/prepared_statement_test.rb +3 -0
- data/spec/integration/schema_test.rb +21 -1
- data/spec/integration/transaction_test.rb +40 -40
- data/spec/model/association_reflection_spec.rb +43 -1
- data/spec/model/associations_spec.rb +29 -9
- data/spec/model/class_dataset_methods_spec.rb +20 -4
- data/spec/model/dataset_methods_spec.rb +12 -3
- data/spec/model/eager_loading_spec.rb +8 -8
- data/spec/model/model_spec.rb +45 -1
- data/spec/model/plugins_spec.rb +34 -0
- data/spec/model/record_spec.rb +1 -1
- data/spec/spec_config.rb +2 -0
- metadata +11 -4
- data/spec/adapters/firebird_spec.rb +0 -405
- data/spec/adapters/informix_spec.rb +0 -100
|
@@ -28,7 +28,8 @@ module Sequel
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
# SEQUEL5: Remove
|
|
32
|
+
class Type_Convertor
|
|
32
33
|
def SqlAnywhereBoolean(r, i)
|
|
33
34
|
if v = Short(r, i)
|
|
34
35
|
v != 0
|
|
@@ -37,6 +38,11 @@ module Sequel
|
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
module SqlAnywhere
|
|
41
|
+
def self.SqlAnywhereBoolean(r, i)
|
|
42
|
+
v = r.getShort(i)
|
|
43
|
+
v != 0 unless r.wasNull
|
|
44
|
+
end
|
|
45
|
+
|
|
40
46
|
# Database instance methods for Sybase databases accessed via JDBC.
|
|
41
47
|
module DatabaseMethods
|
|
42
48
|
include Sequel::SqlAnywhere::DatabaseMethods
|
|
@@ -56,11 +62,6 @@ module Sequel
|
|
|
56
62
|
rs.getLong(1)
|
|
57
63
|
end
|
|
58
64
|
end
|
|
59
|
-
|
|
60
|
-
def setup_type_convertor_map
|
|
61
|
-
super
|
|
62
|
-
@type_convertor_map[:SqlAnywhereBoolean] = TypeConvertor::INSTANCE.method(:SqlAnywhereBoolean)
|
|
63
|
-
end
|
|
64
65
|
end
|
|
65
66
|
|
|
66
67
|
#Dataset class for Sybase datasets accessed via JDBC.
|
|
@@ -70,10 +71,11 @@ module Sequel
|
|
|
70
71
|
private
|
|
71
72
|
|
|
72
73
|
SMALLINT_TYPE = Java::JavaSQL::Types::SMALLINT
|
|
74
|
+
BOOLEAN_METHOD = SqlAnywhere.method(:SqlAnywhereBoolean)
|
|
73
75
|
|
|
74
76
|
def type_convertor(map, meta, type, i)
|
|
75
77
|
if convert_smallint_to_bool && type == SMALLINT_TYPE
|
|
76
|
-
|
|
78
|
+
BOOLEAN_METHOD
|
|
77
79
|
else
|
|
78
80
|
super
|
|
79
81
|
end
|
|
@@ -14,10 +14,9 @@ module Sequel
|
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
# SEQUEL5: Remove
|
|
18
|
+
class Type_Convertor
|
|
18
19
|
def MSSQLRubyTime(r, i)
|
|
19
|
-
# MSSQL-Server TIME should be fetched as string to keep the precision intact, see:
|
|
20
|
-
# https://docs.microsoft.com/en-us/sql/t-sql/data-types/time-transact-sql#a-namebackwardcompatibilityfordownlevelclientsa-backward-compatibility-for-down-level-clients
|
|
21
20
|
if v = r.getString(i)
|
|
22
21
|
Sequel.string_to_time("#{v}")
|
|
23
22
|
end
|
|
@@ -27,6 +26,14 @@ module Sequel
|
|
|
27
26
|
# Database and Dataset instance methods for SQLServer specific
|
|
28
27
|
# support via JDBC.
|
|
29
28
|
module SQLServer
|
|
29
|
+
def self.MSSQLRubyTime(r, i)
|
|
30
|
+
# MSSQL-Server TIME should be fetched as string to keep the precision intact, see:
|
|
31
|
+
# https://docs.microsoft.com/en-us/sql/t-sql/data-types/time-transact-sql#a-namebackwardcompatibilityfordownlevelclientsa-backward-compatibility-for-down-level-clients
|
|
32
|
+
if v = r.getString(i)
|
|
33
|
+
Sequel.string_to_time("#{v}")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
30
37
|
# Database instance methods for SQLServer databases accessed via JDBC.
|
|
31
38
|
module DatabaseMethods
|
|
32
39
|
include Sequel::JDBC::MSSQL::DatabaseMethods
|
|
@@ -34,9 +41,16 @@ module Sequel
|
|
|
34
41
|
def setup_type_convertor_map
|
|
35
42
|
super
|
|
36
43
|
map = @type_convertor_map
|
|
37
|
-
map[Java::JavaSQL::Types::TIME] =
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
map[Java::JavaSQL::Types::TIME] = SQLServer.method(:MSSQLRubyTime)
|
|
45
|
+
|
|
46
|
+
# Work around constant lazy loading in some drivers
|
|
47
|
+
begin
|
|
48
|
+
dto = Java::MicrosoftSql::Types::DATETIMEOFFSET
|
|
49
|
+
rescue NameError
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
if dto
|
|
53
|
+
map[dto] = lambda do |r, i|
|
|
40
54
|
if v = r.getDateTimeOffset(i)
|
|
41
55
|
to_application_timestamp(v.to_s)
|
|
42
56
|
end
|
data/lib/sequel/adapters/jdbc.rb
CHANGED
|
@@ -10,6 +10,7 @@ module Sequel
|
|
|
10
10
|
module JavaLang
|
|
11
11
|
include_package 'java.lang'
|
|
12
12
|
end
|
|
13
|
+
Sequel::Deprecation.deprecate_constant(self, :JavaLang)
|
|
13
14
|
|
|
14
15
|
# Make it accesing the java.sql hierarchy more ruby friendly.
|
|
15
16
|
module JavaSQL
|
|
@@ -20,6 +21,7 @@ module Sequel
|
|
|
20
21
|
module JavaxNaming
|
|
21
22
|
include_package 'javax.naming'
|
|
22
23
|
end
|
|
24
|
+
Sequel::Deprecation.deprecate_constant(self, :JavaxNaming)
|
|
23
25
|
|
|
24
26
|
# Used to identify a jndi connection and to extract the jndi
|
|
25
27
|
# resource name.
|
|
@@ -142,16 +144,18 @@ module Sequel
|
|
|
142
144
|
MAP.freeze
|
|
143
145
|
BASIC_MAP.freeze
|
|
144
146
|
INSTANCE.freeze
|
|
147
|
+
# freeze # SEQUEL5
|
|
145
148
|
end
|
|
146
149
|
|
|
150
|
+
# SEQUEL5: Remove
|
|
151
|
+
Type_Convertor = TypeConvertor
|
|
152
|
+
Sequel::Deprecation.deprecate_constant(self, :TypeConvertor)
|
|
153
|
+
|
|
147
154
|
# JDBC Databases offer a fairly uniform interface that does not change
|
|
148
155
|
# much based on the sub adapter.
|
|
149
156
|
class Database < Sequel::Database
|
|
150
157
|
set_adapter_scheme :jdbc
|
|
151
158
|
|
|
152
|
-
# The type of database we are connecting to
|
|
153
|
-
attr_reader :database_type
|
|
154
|
-
|
|
155
159
|
# The Java database driver we are using (should be a Java class)
|
|
156
160
|
attr_reader :driver
|
|
157
161
|
|
|
@@ -185,12 +189,9 @@ module Sequel
|
|
|
185
189
|
if block_given?
|
|
186
190
|
yield log_connection_yield(sql, conn){cps.executeQuery}
|
|
187
191
|
else
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
log_connection_yield(sql, conn){cps.executeUpdate}
|
|
192
|
+
log_connection_yield(sql, conn){cps.executeUpdate}
|
|
193
|
+
if opts[:type] == :insert
|
|
191
194
|
last_insert_id(conn, opts)
|
|
192
|
-
else
|
|
193
|
-
log_connection_yield(sql, conn){cps.executeUpdate}
|
|
194
195
|
end
|
|
195
196
|
end
|
|
196
197
|
rescue NativeException, JavaSQL::SQLException => e
|
|
@@ -489,7 +490,7 @@ module Sequel
|
|
|
489
490
|
# Gets the connection from JNDI.
|
|
490
491
|
def get_connection_from_jndi
|
|
491
492
|
jndi_name = JNDI_URI_REGEXP.match(uri)[1]
|
|
492
|
-
|
|
493
|
+
javax.naming.InitialContext.new.lookup(jndi_name).connection
|
|
493
494
|
end
|
|
494
495
|
|
|
495
496
|
# Gets the JDBC connection uri from the JNDI resource.
|
|
@@ -526,7 +527,7 @@ module Sequel
|
|
|
526
527
|
# Support fractional seconds for Time objects used in bound variables
|
|
527
528
|
def java_sql_timestamp(time)
|
|
528
529
|
ts = java.sql.Timestamp.new(time.to_i * 1000)
|
|
529
|
-
# Work around jruby 1.6 ruby 1.9 mode bug
|
|
530
|
+
# Work around jruby 1.6 ruby 1.9 mode bug # SEQUEL5: Remove workaround
|
|
530
531
|
ts.setNanos((RUBY_VERSION >= '1.9.0' && time.nsec != 0) ? time.nsec : time.usec * 1000)
|
|
531
532
|
ts
|
|
532
533
|
end
|
|
@@ -680,8 +681,9 @@ module Sequel
|
|
|
680
681
|
# Called before loading subadapter-specific code, necessary so that subadapter initialization code
|
|
681
682
|
# that runs queries works correctly. This cannot be overriding in subadapters,
|
|
682
683
|
def setup_type_convertor_map_early
|
|
683
|
-
|
|
684
|
-
@
|
|
684
|
+
# SEQUEL5: Change back to TypeConvertor
|
|
685
|
+
@type_convertor_map = Type_Convertor::MAP.merge(Java::JavaSQL::Types::TIMESTAMP=>method(:timestamp_convert))
|
|
686
|
+
@basic_type_convertor_map = Type_Convertor::BASIC_MAP.dup
|
|
685
687
|
end
|
|
686
688
|
|
|
687
689
|
# Yield a new statement object, and ensure that it is closed before returning.
|
|
@@ -694,15 +696,19 @@ module Sequel
|
|
|
694
696
|
stmt.close if stmt
|
|
695
697
|
end
|
|
696
698
|
|
|
697
|
-
# A conversion
|
|
699
|
+
# A conversion method for timestamp columns. This is used to make sure timestamps are converted using the
|
|
698
700
|
# correct timezone.
|
|
699
|
-
def
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
to_application_timestamp([v.getYear + 1900, v.getMonth + 1, v.getDate, v.getHours, v.getMinutes, v.getSeconds, v.getNanos])
|
|
703
|
-
end
|
|
701
|
+
def timestamp_convert(r, i)
|
|
702
|
+
if v = r.getTimestamp(i)
|
|
703
|
+
to_application_timestamp([v.getYear + 1900, v.getMonth + 1, v.getDate, v.getHours, v.getMinutes, v.getSeconds, v.getNanos])
|
|
704
704
|
end
|
|
705
705
|
end
|
|
706
|
+
|
|
707
|
+
# SEQUEL5: Remove
|
|
708
|
+
def timestamp_convertor
|
|
709
|
+
Sequel::Deprecation.deprecate("Sequel::JDBC::Database#timestamp_convertor", "Use method(:timestamp_convert) instead")
|
|
710
|
+
method(:timestamp_convert)
|
|
711
|
+
end
|
|
706
712
|
end
|
|
707
713
|
|
|
708
714
|
class Dataset < Sequel::Dataset
|
|
@@ -745,9 +751,14 @@ module Sequel
|
|
|
745
751
|
end
|
|
746
752
|
|
|
747
753
|
# Whether to convert some Java types to ruby types when retrieving rows.
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
754
|
+
def convert_types
|
|
755
|
+
Sequel::Deprecation.deprecate("Sequel::JDBC::Dataset#convert_types", "The private #convert_types? method returns whether to convert types for this dataset")
|
|
756
|
+
@opts[:convert_types]
|
|
757
|
+
end
|
|
758
|
+
def convert_types=(v)
|
|
759
|
+
Sequel::Deprecation.deprecate("Sequel::JDBC::Dataset#convert_types=", "Switch to using #with_convert_types, which returns a modified copy")
|
|
760
|
+
@opts[:convert_types] = v
|
|
761
|
+
end
|
|
751
762
|
|
|
752
763
|
# Correctly return rows from the database and return them as hashes.
|
|
753
764
|
def fetch_rows(sql, &block)
|
|
@@ -755,16 +766,21 @@ module Sequel
|
|
|
755
766
|
self
|
|
756
767
|
end
|
|
757
768
|
|
|
758
|
-
# Set the fetch size on JDBC ResultSets created from
|
|
769
|
+
# Set the fetch size on JDBC ResultSets created from the returned dataset.
|
|
759
770
|
def with_fetch_size(size)
|
|
760
771
|
clone(:fetch_size=>size)
|
|
761
772
|
end
|
|
773
|
+
|
|
774
|
+
# Set whether to convert Java types to ruby types in the returned dataset.
|
|
775
|
+
def with_convert_types(v)
|
|
776
|
+
clone(:convert_types=>v)
|
|
777
|
+
end
|
|
762
778
|
|
|
763
779
|
private
|
|
764
780
|
|
|
765
781
|
# Whether we should convert Java types to ruby types for this dataset.
|
|
766
782
|
def convert_types?
|
|
767
|
-
ct = @convert_types
|
|
783
|
+
ct = @opts[:convert_types]
|
|
768
784
|
ct.nil? ? db.convert_types : ct
|
|
769
785
|
end
|
|
770
786
|
|
data/lib/sequel/adapters/mock.rb
CHANGED
|
@@ -52,7 +52,7 @@ module Sequel
|
|
|
52
52
|
@autoid = case v
|
|
53
53
|
when Integer
|
|
54
54
|
i = v - 1
|
|
55
|
-
proc{
|
|
55
|
+
proc{@mutex.synchronize{i+=1}}
|
|
56
56
|
else
|
|
57
57
|
v
|
|
58
58
|
end
|
|
@@ -128,9 +128,11 @@ module Sequel
|
|
|
128
128
|
# Return all stored SQL queries, and clear the cache
|
|
129
129
|
# of SQL queries.
|
|
130
130
|
def sqls
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
@mutex.synchronize do
|
|
132
|
+
s = @sqls.dup
|
|
133
|
+
@sqls.clear
|
|
134
|
+
s
|
|
135
|
+
end
|
|
134
136
|
end
|
|
135
137
|
|
|
136
138
|
# Enable use of savepoints.
|
|
@@ -140,21 +142,12 @@ module Sequel
|
|
|
140
142
|
|
|
141
143
|
private
|
|
142
144
|
|
|
143
|
-
def _autoid(sql, v, ds=nil)
|
|
144
|
-
if ds
|
|
145
|
-
ds.send(:cache_set, :_autoid, ds.autoid + 1) if ds.autoid.is_a?(Integer)
|
|
146
|
-
v
|
|
147
|
-
else
|
|
148
|
-
_nextres(v, sql, nil)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
145
|
def _execute(c, sql, opts=OPTS, &block)
|
|
153
146
|
sql += " -- args: #{opts[:arguments].inspect}" if opts[:arguments]
|
|
154
147
|
sql += " -- #{@opts[:append]}" if @opts[:append]
|
|
155
148
|
sql += " -- #{c.server.is_a?(Symbol) ? c.server : c.server.inspect}" if c.server != :default
|
|
156
149
|
log_connection_yield(sql, c){} unless opts[:log] == false
|
|
157
|
-
@sqls << sql
|
|
150
|
+
@mutex.synchronize{@sqls << sql}
|
|
158
151
|
|
|
159
152
|
ds = opts[:dataset]
|
|
160
153
|
begin
|
|
@@ -165,8 +158,15 @@ module Sequel
|
|
|
165
158
|
if meth == :numrows
|
|
166
159
|
_numrows(sql, (ds.numrows if ds) || @numrows)
|
|
167
160
|
else
|
|
168
|
-
|
|
169
|
-
|
|
161
|
+
if ds
|
|
162
|
+
@mutex.synchronize do
|
|
163
|
+
v = ds.autoid
|
|
164
|
+
if v.is_a?(Integer)
|
|
165
|
+
ds.send(:cache_set, :_autoid, v + 1)
|
|
166
|
+
end
|
|
167
|
+
v
|
|
168
|
+
end
|
|
169
|
+
end || _nextres(@autoid, sql, nil)
|
|
170
170
|
end
|
|
171
171
|
end
|
|
172
172
|
rescue => e
|
|
@@ -182,7 +182,7 @@ module Sequel
|
|
|
182
182
|
if f.all?{|h| h.is_a?(Hash)}
|
|
183
183
|
f.each{|h| yield h.dup}
|
|
184
184
|
else
|
|
185
|
-
_fetch(sql, f.shift, &block)
|
|
185
|
+
_fetch(sql, @mutex.synchronize{f.shift}, &block)
|
|
186
186
|
end
|
|
187
187
|
when Proc
|
|
188
188
|
h = f.call(sql)
|
|
@@ -209,7 +209,7 @@ module Sequel
|
|
|
209
209
|
when Integer
|
|
210
210
|
v
|
|
211
211
|
when Array
|
|
212
|
-
v.empty? ? default : _nextres(v.shift, sql, default)
|
|
212
|
+
v.empty? ? default : _nextres(@mutex.synchronize{v.shift}, sql, default)
|
|
213
213
|
when Proc
|
|
214
214
|
v.call(sql)
|
|
215
215
|
when Class
|
|
@@ -239,6 +239,7 @@ module Sequel
|
|
|
239
239
|
# :sqls :: The array to store the SQL queries in.
|
|
240
240
|
def adapter_initialize
|
|
241
241
|
opts = @opts
|
|
242
|
+
@mutex = Mutex.new
|
|
242
243
|
@sqls = opts[:sqls] || []
|
|
243
244
|
@shared_adapter = false
|
|
244
245
|
|
|
@@ -284,7 +285,7 @@ module Sequel
|
|
|
284
285
|
if cs.all?{|c| c.is_a?(Symbol)}
|
|
285
286
|
ds.columns(*cs)
|
|
286
287
|
else
|
|
287
|
-
columns(ds, sql, cs.shift)
|
|
288
|
+
columns(ds, sql, @mutex.synchronize{cs.shift})
|
|
288
289
|
end
|
|
289
290
|
end
|
|
290
291
|
when Proc
|
|
@@ -320,6 +321,7 @@ module Sequel
|
|
|
320
321
|
|
|
321
322
|
# Override the databases's autoid setting for this dataset
|
|
322
323
|
def autoid=(v)
|
|
324
|
+
Sequel::Deprecation.deprecate("Sequel::Mock::Dataset#autoid=", "Use with_autoid to return a modified dataset")
|
|
323
325
|
cache_set(:_autoid, nil)
|
|
324
326
|
@opts[:autoid] = v
|
|
325
327
|
end
|
|
@@ -331,6 +333,7 @@ module Sequel
|
|
|
331
333
|
|
|
332
334
|
# Override the databases's fetch setting for this dataset
|
|
333
335
|
def _fetch=(v)
|
|
336
|
+
Sequel::Deprecation.deprecate("Sequel::Mock::Dataset#_fetch=", "Use with_fetch to return a modified dataset")
|
|
334
337
|
cache_set(:_fetch, nil)
|
|
335
338
|
@opts[:fetch] = v
|
|
336
339
|
end
|
|
@@ -342,6 +345,7 @@ module Sequel
|
|
|
342
345
|
|
|
343
346
|
# Override the databases's numrows setting for this dataset
|
|
344
347
|
def numrows=(v)
|
|
348
|
+
Sequel::Deprecation.deprecate("Sequel::Mock::Dataset#_numrows=", "Use with_numrows to return a modified dataset")
|
|
345
349
|
cache_set(:_numrows, nil)
|
|
346
350
|
@opts[:numrows] = v
|
|
347
351
|
end
|
|
@@ -394,6 +398,10 @@ module Sequel
|
|
|
394
398
|
def execute_insert(sql, opts=OPTS, &block)
|
|
395
399
|
super(sql, opts.merge(:dataset=>self), &block)
|
|
396
400
|
end
|
|
401
|
+
|
|
402
|
+
def non_sql_option?(key)
|
|
403
|
+
super || key == :fetch || key == :numrows || key == :autoid
|
|
404
|
+
end
|
|
397
405
|
end
|
|
398
406
|
end
|
|
399
407
|
end
|
|
@@ -16,7 +16,7 @@ module Sequel
|
|
|
16
16
|
def boolean(s) s.to_i != 0 end
|
|
17
17
|
def integer(s) s.to_i end
|
|
18
18
|
def float(s) s.to_f end
|
|
19
|
-
end.new
|
|
19
|
+
end.new#.freeze # SEQUEL5
|
|
20
20
|
|
|
21
21
|
# Hash with integer keys and callable values for converting MySQL types.
|
|
22
22
|
MYSQL_TYPES = {}
|
|
@@ -30,14 +30,18 @@ module Sequel
|
|
|
30
30
|
end
|
|
31
31
|
# MYSQL_TYPES.freeze # SEQUEL5
|
|
32
32
|
|
|
33
|
+
# SEQUEL5: Remove
|
|
34
|
+
@convert_invalid_date_time = false
|
|
33
35
|
class << self
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
def convert_invalid_date_time
|
|
37
|
+
Sequel::Deprecation.deprecate("Sequel::MySQL.convert_invalid_date_time", "Call this method on the Database instance")
|
|
38
|
+
@convert_invalid_date_time
|
|
39
|
+
end
|
|
40
|
+
def convert_invalid_date_time=(v)
|
|
41
|
+
Sequel::Deprecation.deprecate("Sequel::MySQL.convert_invalid_date_time=", "Call this method on the Database instance")
|
|
42
|
+
@convert_invalid_date_time = v
|
|
43
|
+
end
|
|
39
44
|
end
|
|
40
|
-
self.convert_invalid_date_time = false
|
|
41
45
|
|
|
42
46
|
# Database class for MySQL databases used with Sequel.
|
|
43
47
|
class Database < Sequel::Database
|
|
@@ -54,7 +58,7 @@ module Sequel
|
|
|
54
58
|
|
|
55
59
|
# Hash of conversion procs for the current database
|
|
56
60
|
attr_reader :conversion_procs
|
|
57
|
-
|
|
61
|
+
|
|
58
62
|
# Whether to convert tinyint columns to bool for the current database
|
|
59
63
|
attr_reader :convert_tinyint_to_bool
|
|
60
64
|
|
|
@@ -227,8 +231,8 @@ module Sequel
|
|
|
227
231
|
|
|
228
232
|
def adapter_initialize
|
|
229
233
|
@conversion_procs = MYSQL_TYPES.dup
|
|
230
|
-
self.convert_tinyint_to_bool = Sequel::MySQL.convert_tinyint_to_bool
|
|
231
|
-
self.convert_invalid_date_time = Sequel::MySQL.convert_invalid_date_time
|
|
234
|
+
self.convert_tinyint_to_bool = Sequel::MySQL.instance_variable_get(:@convert_tinyint_to_bool) # true # SEQUEL5
|
|
235
|
+
self.convert_invalid_date_time = Sequel::MySQL.instance_variable_get(:@convert_invalid_date_time) # false # SEQUEL5
|
|
232
236
|
end
|
|
233
237
|
|
|
234
238
|
# Try to get an accurate number of rows matched using the query
|
|
@@ -288,7 +292,7 @@ module Sequel
|
|
|
288
292
|
# The database name when using the native adapter is always stored in
|
|
289
293
|
# the :database option.
|
|
290
294
|
def database_name
|
|
291
|
-
Sequel::Deprecation.deprecate("Database#database_name", "Instead, use .get
|
|
295
|
+
Sequel::Deprecation.deprecate("Database#database_name", "Instead, use .get(Sequel.function(:DATABASE))")
|
|
292
296
|
@opts[:database]
|
|
293
297
|
end
|
|
294
298
|
|
|
@@ -316,8 +320,7 @@ module Sequel
|
|
|
316
320
|
cps = db.conversion_procs
|
|
317
321
|
cols = r.fetch_fields.map do |f|
|
|
318
322
|
# Pretend tinyint is another integer type if its length is not 1, to
|
|
319
|
-
# avoid casting to boolean if
|
|
320
|
-
# is set.
|
|
323
|
+
# avoid casting to boolean if convert_tinyint_to_bool is set.
|
|
321
324
|
type_proc = f.type == 1 && cast_tinyint_integer?(f) ? cps[2] : cps[f.type]
|
|
322
325
|
[output_identifier(f.name), type_proc, i+=1]
|
|
323
326
|
end
|
|
@@ -373,9 +376,7 @@ module Sequel
|
|
|
373
376
|
|
|
374
377
|
# Handle correct quoting of strings using ::MySQL.quote.
|
|
375
378
|
def literal_string_append(sql, v)
|
|
376
|
-
sql << "'"
|
|
377
|
-
sql << ::Mysql.quote(v)
|
|
378
|
-
sql << "'"
|
|
379
|
+
sql << "'" << ::Mysql.quote(v) << "'"
|
|
379
380
|
end
|
|
380
381
|
|
|
381
382
|
# Yield each row of the given result set r with columns cols
|
|
@@ -171,7 +171,7 @@ module Sequel
|
|
|
171
171
|
|
|
172
172
|
# Set the convert_tinyint_to_bool setting based on the default value.
|
|
173
173
|
def adapter_initialize
|
|
174
|
-
self.convert_tinyint_to_bool = Sequel::MySQL.convert_tinyint_to_bool
|
|
174
|
+
self.convert_tinyint_to_bool = Sequel::MySQL.instance_variable_get(:@convert_tinyint_to_bool) # true # SEQUEL5
|
|
175
175
|
end
|
|
176
176
|
|
|
177
177
|
if NativePreparedStatements
|
|
@@ -222,7 +222,7 @@ module Sequel
|
|
|
222
222
|
# The database name when using the native adapter is always stored in
|
|
223
223
|
# the :database option.
|
|
224
224
|
def database_name
|
|
225
|
-
Sequel::Deprecation.deprecate("Database#database_name", "Instead, use .get
|
|
225
|
+
Sequel::Deprecation.deprecate("Database#database_name", "Instead, use .get(Sequel.function(:DATABASE))")
|
|
226
226
|
@opts[:database]
|
|
227
227
|
end
|
|
228
228
|
|
|
@@ -260,7 +260,7 @@ module Sequel
|
|
|
260
260
|
|
|
261
261
|
# Use streaming to implement paging if Mysql2 supports it.
|
|
262
262
|
def paged_each(opts=OPTS, &block)
|
|
263
|
-
if STREAMING_SUPPORTED
|
|
263
|
+
if STREAMING_SUPPORTED && opts[:stream] != false
|
|
264
264
|
stream.each(&block)
|
|
265
265
|
else
|
|
266
266
|
super
|
|
@@ -277,7 +277,7 @@ module Sequel
|
|
|
277
277
|
private
|
|
278
278
|
|
|
279
279
|
# Whether to cast tinyint(1) columns to integer instead of boolean.
|
|
280
|
-
# By default, uses the
|
|
280
|
+
# By default, uses the database's convert_tinyint_to_bool
|
|
281
281
|
# setting. Exists for compatibility with the mysql adapter.
|
|
282
282
|
def convert_tinyint_to_bool?
|
|
283
283
|
@db.convert_tinyint_to_bool
|
|
@@ -303,8 +303,7 @@ module Sequel
|
|
|
303
303
|
|
|
304
304
|
# Handle correct quoting of strings using ::Mysql2::Client#escape.
|
|
305
305
|
def literal_string_append(sql, v)
|
|
306
|
-
|
|
307
|
-
sql << "'" << s << "'"
|
|
306
|
+
sql << "'" << db.synchronize(@opts[:server]){|c| c.escape(v)} << "'"
|
|
308
307
|
end
|
|
309
308
|
end
|
|
310
309
|
end
|
|
@@ -112,9 +112,9 @@ module Sequel
|
|
|
112
112
|
@conversion_procs = ORACLE_TYPES.dup
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
-
PS_TYPES = {'string'
|
|
116
|
-
'decimal'
|
|
117
|
-
'time'
|
|
115
|
+
PS_TYPES = {'string'=>String, 'integer'=>Integer, 'float'=>Float,
|
|
116
|
+
'decimal'=>Float, 'date'=>Time, 'datetime'=>Time,
|
|
117
|
+
'time'=>Time, 'boolean'=>String, 'blob'=>OCI8::BLOB}#.freeze # SEQUEL5
|
|
118
118
|
def cursor_bind_params(conn, cursor, args)
|
|
119
119
|
i = 0
|
|
120
120
|
args.map do |arg, type|
|
|
@@ -129,11 +129,7 @@ module Sequel
|
|
|
129
129
|
when ::Sequel::SQL::Blob
|
|
130
130
|
arg = ::OCI8::BLOB.new(conn, arg)
|
|
131
131
|
end
|
|
132
|
-
|
|
133
|
-
cursor.bind_param(i, arg, t)
|
|
134
|
-
else
|
|
135
|
-
cursor.bind_param(i, arg, arg.class)
|
|
136
|
-
end
|
|
132
|
+
cursor.bind_param(i, arg, PS_TYPES[type] || arg.class)
|
|
137
133
|
arg
|
|
138
134
|
end
|
|
139
135
|
end
|
|
@@ -287,7 +283,7 @@ module Sequel
|
|
|
287
283
|
defaults = begin
|
|
288
284
|
metadata_dataset.from(:all_tab_cols).
|
|
289
285
|
where(:table_name=>im.call(table)).
|
|
290
|
-
|
|
286
|
+
as_hash(:column_name, :data_default)
|
|
291
287
|
rescue DatabaseError
|
|
292
288
|
{}
|
|
293
289
|
end
|