sequel 4.45.0 → 4.46.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +108 -0
- data/doc/release_notes/4.46.0.txt +404 -0
- data/doc/security.rdoc +9 -0
- data/doc/sql.rdoc +2 -2
- data/doc/testing.rdoc +1 -1
- data/doc/validations.rdoc +1 -2
- data/lib/sequel/adapters/ado.rb +8 -3
- data/lib/sequel/adapters/ado/access.rb +8 -4
- data/lib/sequel/adapters/ado/mssql.rb +3 -1
- data/lib/sequel/adapters/amalgalite.rb +5 -0
- data/lib/sequel/adapters/cubrid.rb +16 -7
- data/lib/sequel/adapters/do.rb +7 -1
- data/lib/sequel/adapters/do/mysql.rb +8 -4
- data/lib/sequel/adapters/ibmdb.rb +10 -5
- data/lib/sequel/adapters/jdbc.rb +8 -2
- data/lib/sequel/adapters/jdbc/as400.rb +10 -3
- data/lib/sequel/adapters/jdbc/db2.rb +27 -16
- data/lib/sequel/adapters/jdbc/derby.rb +47 -20
- data/lib/sequel/adapters/jdbc/h2.rb +13 -7
- data/lib/sequel/adapters/jdbc/hsqldb.rb +18 -9
- data/lib/sequel/adapters/jdbc/mssql.rb +5 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +3 -2
- data/lib/sequel/adapters/jdbc/oracle.rb +3 -2
- data/lib/sequel/adapters/jdbc/postgresql.rb +4 -3
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +2 -1
- data/lib/sequel/adapters/jdbc/sqlite.rb +10 -3
- data/lib/sequel/adapters/jdbc/sqlserver.rb +23 -0
- data/lib/sequel/adapters/jdbc/transactions.rb +16 -10
- data/lib/sequel/adapters/mock.rb +5 -0
- data/lib/sequel/adapters/mysql.rb +8 -1
- data/lib/sequel/adapters/mysql2.rb +6 -1
- data/lib/sequel/adapters/odbc.rb +20 -8
- data/lib/sequel/adapters/odbc/mssql.rb +6 -3
- data/lib/sequel/adapters/oracle.rb +12 -6
- data/lib/sequel/adapters/postgres.rb +20 -8
- data/lib/sequel/adapters/shared/access.rb +76 -47
- data/lib/sequel/adapters/shared/cubrid.rb +16 -11
- data/lib/sequel/adapters/shared/db2.rb +46 -19
- data/lib/sequel/adapters/shared/firebird.rb +20 -8
- data/lib/sequel/adapters/shared/informix.rb +6 -3
- data/lib/sequel/adapters/shared/mssql.rb +132 -72
- data/lib/sequel/adapters/shared/mysql.rb +112 -65
- data/lib/sequel/adapters/shared/oracle.rb +36 -21
- data/lib/sequel/adapters/shared/postgres.rb +91 -56
- data/lib/sequel/adapters/shared/sqlanywhere.rb +65 -37
- data/lib/sequel/adapters/shared/sqlite.rb +67 -32
- data/lib/sequel/adapters/sqlanywhere.rb +9 -1
- data/lib/sequel/adapters/sqlite.rb +8 -1
- data/lib/sequel/adapters/swift.rb +5 -0
- data/lib/sequel/adapters/swift/mysql.rb +4 -2
- data/lib/sequel/adapters/swift/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +10 -3
- data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +1 -1
- data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +1 -1
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -0
- data/lib/sequel/adapters/utils/pg_types.rb +14 -6
- data/lib/sequel/adapters/utils/replace.rb +4 -2
- data/lib/sequel/connection_pool/single.rb +2 -2
- data/lib/sequel/core.rb +24 -11
- data/lib/sequel/database/connecting.rb +9 -3
- data/lib/sequel/database/dataset_defaults.rb +7 -1
- data/lib/sequel/database/logging.rb +1 -0
- data/lib/sequel/database/misc.rb +5 -2
- data/lib/sequel/database/query.rb +7 -5
- data/lib/sequel/database/schema_generator.rb +1 -0
- data/lib/sequel/database/schema_methods.rb +50 -27
- data/lib/sequel/database/transactions.rb +19 -9
- data/lib/sequel/dataset/actions.rb +15 -6
- data/lib/sequel/dataset/graph.rb +15 -5
- data/lib/sequel/dataset/misc.rb +12 -4
- data/lib/sequel/dataset/mutation.rb +17 -8
- data/lib/sequel/dataset/prepared_statements.rb +3 -2
- data/lib/sequel/dataset/query.rb +84 -38
- data/lib/sequel/dataset/sql.rb +302 -191
- data/lib/sequel/deprecated.rb +26 -17
- data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +2 -2
- data/lib/sequel/extensions/auto_literal_strings.rb +74 -0
- data/lib/sequel/extensions/from_block.rb +1 -0
- data/lib/sequel/extensions/graph_each.rb +1 -1
- data/lib/sequel/extensions/identifier_mangling.rb +2 -2
- data/lib/sequel/extensions/migration.rb +28 -4
- data/lib/sequel/extensions/no_auto_literal_strings.rb +2 -0
- data/lib/sequel/extensions/schema_dumper.rb +4 -4
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +5 -3
- data/lib/sequel/extensions/set_overrides.rb +2 -0
- data/lib/sequel/extensions/split_array_nil.rb +2 -2
- data/lib/sequel/extensions/virtual_row_method_block.rb +44 -0
- data/lib/sequel/model.rb +11 -7
- data/lib/sequel/model/associations.rb +5 -7
- data/lib/sequel/model/base.rb +47 -45
- data/lib/sequel/model/dataset_module.rb +9 -14
- data/lib/sequel/model/plugins.rb +3 -0
- data/lib/sequel/no_core_ext.rb +1 -0
- data/lib/sequel/plugins/blacklist_security.rb +1 -1
- data/lib/sequel/plugins/boolean_subsets.rb +7 -5
- data/lib/sequel/plugins/class_table_inheritance.rb +47 -10
- data/lib/sequel/plugins/dataset_associations.rb +1 -1
- data/lib/sequel/plugins/def_dataset_method.rb +90 -0
- data/lib/sequel/plugins/finder.rb +240 -0
- data/lib/sequel/plugins/inverted_subsets.rb +19 -12
- data/lib/sequel/plugins/many_through_many.rb +1 -1
- data/lib/sequel/plugins/nested_attributes.rb +1 -1
- data/lib/sequel/plugins/schema.rb +1 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +7 -1
- data/lib/sequel/plugins/subset_conditions.rb +11 -3
- data/lib/sequel/plugins/whitelist_security.rb +118 -0
- data/lib/sequel/sql.rb +80 -36
- data/lib/sequel/timezones.rb +2 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/mssql_spec.rb +20 -0
- data/spec/adapters/mysql_spec.rb +1 -1
- data/spec/adapters/oracle_spec.rb +12 -8
- data/spec/adapters/postgres_spec.rb +1 -1
- data/spec/adapters/spec_helper.rb +1 -1
- data/spec/adapters/sqlite_spec.rb +36 -34
- data/spec/core/connection_pool_spec.rb +2 -1
- data/spec/core/database_spec.rb +87 -9
- data/spec/core/dataset_spec.rb +501 -129
- data/spec/core/deprecated_spec.rb +1 -1
- data/spec/core/expression_filters_spec.rb +146 -60
- data/spec/core/mock_adapter_spec.rb +1 -1
- data/spec/core/object_graph_spec.rb +61 -9
- data/spec/core/placeholder_literalizer_spec.rb +20 -2
- data/spec/core/schema_generator_spec.rb +6 -6
- data/spec/core/schema_spec.rb +54 -5
- data/spec/core_extensions_spec.rb +122 -18
- data/spec/deprecation_helper.rb +27 -2
- data/spec/extensions/_deprecated_identifier_mangling_spec.rb +6 -6
- data/spec/extensions/association_proxies_spec.rb +2 -2
- data/spec/extensions/auto_literal_strings_spec.rb +212 -0
- data/spec/extensions/blacklist_security_spec.rb +1 -0
- data/spec/extensions/class_table_inheritance_spec.rb +1037 -39
- data/spec/extensions/column_select_spec.rb +20 -8
- data/spec/extensions/columns_introspection_spec.rb +3 -3
- data/spec/extensions/core_refinements_spec.rb +29 -12
- data/spec/extensions/dataset_associations_spec.rb +12 -12
- data/spec/extensions/def_dataset_method_spec.rb +100 -0
- data/spec/extensions/error_sql_spec.rb +1 -1
- data/spec/extensions/finder_spec.rb +260 -0
- data/spec/extensions/graph_each_spec.rb +2 -2
- data/spec/extensions/identifier_mangling_spec.rb +14 -8
- data/spec/extensions/inverted_subsets_spec.rb +4 -4
- data/spec/extensions/lazy_attributes_spec.rb +7 -0
- data/spec/extensions/many_through_many_spec.rb +38 -14
- data/spec/extensions/nested_attributes_spec.rb +18 -6
- data/spec/extensions/no_auto_literal_strings_spec.rb +1 -1
- data/spec/extensions/pg_enum_spec.rb +16 -1
- data/spec/extensions/pg_interval_spec.rb +11 -2
- data/spec/extensions/pg_loose_count_spec.rb +5 -0
- data/spec/extensions/pg_row_spec.rb +25 -0
- data/spec/extensions/prepared_statements_spec.rb +10 -1
- data/spec/extensions/query_spec.rb +2 -2
- data/spec/extensions/schema_dumper_spec.rb +2 -2
- data/spec/extensions/schema_spec.rb +2 -2
- data/spec/extensions/set_overrides_spec.rb +7 -3
- data/spec/extensions/sql_expr_spec.rb +0 -1
- data/spec/extensions/subset_conditions_spec.rb +6 -6
- data/spec/extensions/table_select_spec.rb +24 -12
- data/spec/extensions/to_dot_spec.rb +4 -4
- data/spec/extensions/whitelist_security_spec.rb +131 -0
- data/spec/integration/dataset_test.rb +9 -5
- data/spec/integration/model_test.rb +2 -0
- data/spec/integration/plugin_test.rb +2 -2
- data/spec/integration/spec_helper.rb +1 -1
- data/spec/model/associations_spec.rb +39 -11
- data/spec/model/base_spec.rb +44 -24
- data/spec/model/class_dataset_methods_spec.rb +18 -16
- data/spec/model/dataset_methods_spec.rb +4 -4
- data/spec/model/eager_loading_spec.rb +84 -24
- data/spec/model/model_spec.rb +97 -63
- data/spec/model/record_spec.rb +21 -13
- metadata +13 -2
@@ -186,13 +186,14 @@ module Sequel
|
|
186
186
|
# Dataset subclass used for datasets that connect to PostgreSQL via JDBC.
|
187
187
|
class Dataset < JDBC::Dataset
|
188
188
|
include Sequel::Postgres::DatasetMethods
|
189
|
-
APOS =
|
189
|
+
APOS = "'".freeze
|
190
|
+
Sequel::Deprecation.deprecate_constant(self, :APOS)
|
190
191
|
|
191
192
|
private
|
192
193
|
|
193
194
|
# Literalize strings similar to the native postgres adapter
|
194
195
|
def literal_string_append(sql, v)
|
195
|
-
sql <<
|
196
|
+
sql << "'" << db.synchronize(@opts[:server]){|c| c.escape_string(v)} << "'"
|
196
197
|
end
|
197
198
|
|
198
199
|
# SQL fragment for Sequel::SQLTime, containing just the time part
|
@@ -202,7 +203,7 @@ module Sequel
|
|
202
203
|
|
203
204
|
STRING_TYPE = Java::JavaSQL::Types::VARCHAR
|
204
205
|
ARRAY_TYPE = Java::JavaSQL::Types::ARRAY
|
205
|
-
PG_SPECIFIC_TYPES = [ARRAY_TYPE, Java::JavaSQL::Types::OTHER, Java::JavaSQL::Types::STRUCT]
|
206
|
+
PG_SPECIFIC_TYPES = [ARRAY_TYPE, Java::JavaSQL::Types::OTHER, Java::JavaSQL::Types::STRUCT]#.freeze # SEQUEL5
|
206
207
|
HSTORE_TYPE = 'hstore'.freeze
|
207
208
|
|
208
209
|
def type_convertor(map, meta, type, i)
|
@@ -43,13 +43,14 @@ module Sequel
|
|
43
43
|
include Sequel::JDBC::Transactions
|
44
44
|
|
45
45
|
LAST_INSERT_ID = 'SELECT @@IDENTITY'.freeze
|
46
|
+
Sequel::Deprecation.deprecate_constant(self, :LAST_INSERT_ID)
|
46
47
|
|
47
48
|
private
|
48
49
|
|
49
50
|
# Get the last inserted id.
|
50
51
|
def last_insert_id(conn, opts=OPTS)
|
51
52
|
statement(conn) do |stmt|
|
52
|
-
sql =
|
53
|
+
sql = 'SELECT @@IDENTITY'
|
53
54
|
rs = log_connection_yield(sql, conn){stmt.executeQuery(sql)}
|
54
55
|
rs.next
|
55
56
|
rs.getLong(1)
|
@@ -20,14 +20,16 @@ module Sequel
|
|
20
20
|
module DatabaseMethods
|
21
21
|
include Sequel::SQLite::DatabaseMethods
|
22
22
|
LAST_INSERT_ROWID = 'SELECT last_insert_rowid()'.freeze
|
23
|
+
Sequel::Deprecation.deprecate_constant(self, :LAST_INSERT_ROWID)
|
23
24
|
FOREIGN_KEY_ERROR_RE = /query does not return ResultSet/.freeze
|
25
|
+
Sequel::Deprecation.deprecate_constant(self, :FOREIGN_KEY_ERROR_RE)
|
24
26
|
|
25
27
|
# Swallow pointless exceptions when the foreign key list pragma
|
26
28
|
# doesn't return any rows.
|
27
29
|
def foreign_key_list(table, opts=OPTS)
|
28
30
|
super
|
29
31
|
rescue Sequel::DatabaseError => e
|
30
|
-
raise unless e
|
32
|
+
raise unless foreign_key_error?(e)
|
31
33
|
[]
|
32
34
|
end
|
33
35
|
|
@@ -36,7 +38,7 @@ module Sequel
|
|
36
38
|
def indexes(table, opts=OPTS)
|
37
39
|
super
|
38
40
|
rescue Sequel::DatabaseError => e
|
39
|
-
raise unless e
|
41
|
+
raise unless foreign_key_error?(e)
|
40
42
|
{}
|
41
43
|
end
|
42
44
|
|
@@ -50,7 +52,7 @@ module Sequel
|
|
50
52
|
# Use last_insert_rowid() to get the last inserted id.
|
51
53
|
def last_insert_id(conn, opts=OPTS)
|
52
54
|
statement(conn) do |stmt|
|
53
|
-
rs = stmt.executeQuery(
|
55
|
+
rs = stmt.executeQuery('SELECT last_insert_rowid()')
|
54
56
|
rs.next
|
55
57
|
rs.getLong(1)
|
56
58
|
end
|
@@ -71,6 +73,11 @@ module Sequel
|
|
71
73
|
conn
|
72
74
|
end
|
73
75
|
|
76
|
+
# Whether the given exception is due to a foreign key error.
|
77
|
+
def foreign_key_error?(exception)
|
78
|
+
exception.message =~ /query does not return ResultSet/
|
79
|
+
end
|
80
|
+
|
74
81
|
# Use getLong instead of getInt for converting integers on SQLite, since SQLite does not enforce a limit of 2**32.
|
75
82
|
# Work around regressions in jdbc-sqlite 3.8.7 for date and blob types.
|
76
83
|
def setup_type_convertor_map
|
@@ -14,6 +14,16 @@ module Sequel
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
class TypeConvertor
|
18
|
+
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
|
+
if v = r.getString(i)
|
22
|
+
Sequel.string_to_time("#{v}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
17
27
|
# Database and Dataset instance methods for SQLServer specific
|
18
28
|
# support via JDBC.
|
19
29
|
module SQLServer
|
@@ -21,6 +31,19 @@ module Sequel
|
|
21
31
|
module DatabaseMethods
|
22
32
|
include Sequel::JDBC::MSSQL::DatabaseMethods
|
23
33
|
|
34
|
+
def setup_type_convertor_map
|
35
|
+
super
|
36
|
+
map = @type_convertor_map
|
37
|
+
map[Java::JavaSQL::Types::TIME] = TypeConvertor::INSTANCE.method(:MSSQLRubyTime)
|
38
|
+
if defined?(Java::MicrosoftSql::Types::DATETIMEOFFSET)
|
39
|
+
map[Java::MicrosoftSql::Types::DATETIMEOFFSET] = lambda do |r, i|
|
40
|
+
if v = r.getDateTimeOffset(i)
|
41
|
+
to_application_timestamp(v.to_s)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
24
47
|
# Work around a bug in SQL Server JDBC Driver 3.0, where the metadata
|
25
48
|
# for the getColumns result set specifies an incorrect type for the
|
26
49
|
# IS_AUTOINCREMENT column. The column is a string, but the type is
|
@@ -4,11 +4,17 @@ module Sequel
|
|
4
4
|
module JDBC
|
5
5
|
module Transactions
|
6
6
|
TRANSACTION_BEGIN = 'Transaction.begin'.freeze
|
7
|
+
Sequel::Deprecation.deprecate_constant(self, :TRANSACTION_BEGIN)
|
7
8
|
TRANSACTION_COMMIT = 'Transaction.commit'.freeze
|
9
|
+
Sequel::Deprecation.deprecate_constant(self, :TRANSACTION_COMMIT)
|
8
10
|
TRANSACTION_RELEASE_SP = 'Transaction.release_savepoint'.freeze
|
11
|
+
Sequel::Deprecation.deprecate_constant(self, :TRANSACTION_RELEASE_SP)
|
9
12
|
TRANSACTION_ROLLBACK = 'Transaction.rollback'.freeze
|
13
|
+
Sequel::Deprecation.deprecate_constant(self, :TRANSACTION_ROLLBACK)
|
10
14
|
TRANSACTION_ROLLBACK_SP = 'Transaction.rollback_savepoint'.freeze
|
15
|
+
Sequel::Deprecation.deprecate_constant(self, :TRANSACTION_ROLLBACK_SP)
|
11
16
|
TRANSACTION_SAVEPOINT= 'Transaction.savepoint'.freeze
|
17
|
+
Sequel::Deprecation.deprecate_constant(self, :TRANSACTION_SAVEPOINT)
|
12
18
|
|
13
19
|
def freeze
|
14
20
|
supports_savepoints?
|
@@ -32,7 +38,7 @@ module Sequel
|
|
32
38
|
JDBC_TRANSACTION_ISOLATION_LEVELS = {:uncommitted=>JavaSQL::Connection::TRANSACTION_READ_UNCOMMITTED,
|
33
39
|
:committed=>JavaSQL::Connection::TRANSACTION_READ_COMMITTED,
|
34
40
|
:repeatable=>JavaSQL::Connection::TRANSACTION_REPEATABLE_READ,
|
35
|
-
:serializable=>JavaSQL::Connection::TRANSACTION_SERIALIZABLE}
|
41
|
+
:serializable=>JavaSQL::Connection::TRANSACTION_SERIALIZABLE}#.freeze # SEQUEL5
|
36
42
|
|
37
43
|
# Set the transaction isolation level on the given connection using
|
38
44
|
# the JDBC API.
|
@@ -55,14 +61,14 @@ module Sequel
|
|
55
61
|
if supports_savepoints?
|
56
62
|
th = _trans(conn)
|
57
63
|
if sps = th[:savepoint_objs]
|
58
|
-
sps << log_connection_yield(
|
64
|
+
sps << log_connection_yield('Transaction.savepoint', conn){conn.set_savepoint}
|
59
65
|
else
|
60
|
-
log_connection_yield(
|
66
|
+
log_connection_yield('Transaction.begin', conn){conn.setAutoCommit(false)}
|
61
67
|
th[:savepoint_objs] = []
|
62
68
|
set_transaction_isolation(conn, opts)
|
63
69
|
end
|
64
70
|
else
|
65
|
-
log_connection_yield(
|
71
|
+
log_connection_yield('Transaction.begin', conn){conn.setAutoCommit(false)}
|
66
72
|
set_transaction_isolation(conn, opts)
|
67
73
|
end
|
68
74
|
end
|
@@ -72,12 +78,12 @@ module Sequel
|
|
72
78
|
if supports_savepoints?
|
73
79
|
sps = _trans(conn)[:savepoint_objs]
|
74
80
|
if sps.empty?
|
75
|
-
log_connection_yield(
|
81
|
+
log_connection_yield('Transaction.commit', conn){conn.commit}
|
76
82
|
elsif supports_releasing_savepoints?
|
77
|
-
log_connection_yield(
|
83
|
+
log_connection_yield('Transaction.release_savepoint', conn){supports_releasing_savepoints? ? conn.release_savepoint(sps.last) : sps.last}
|
78
84
|
end
|
79
85
|
else
|
80
|
-
log_connection_yield(
|
86
|
+
log_connection_yield('Transaction.commit', conn){conn.commit}
|
81
87
|
end
|
82
88
|
end
|
83
89
|
|
@@ -102,12 +108,12 @@ module Sequel
|
|
102
108
|
if supports_savepoints?
|
103
109
|
sps = _trans(conn)[:savepoint_objs]
|
104
110
|
if sps.empty?
|
105
|
-
log_connection_yield(
|
111
|
+
log_connection_yield('Transaction.rollback', conn){conn.rollback}
|
106
112
|
else
|
107
|
-
log_connection_yield(
|
113
|
+
log_connection_yield('Transaction.rollback_savepoint', conn){conn.rollback(sps.last)}
|
108
114
|
end
|
109
115
|
else
|
110
|
-
log_connection_yield(
|
116
|
+
log_connection_yield('Transaction.rollback', conn){conn.rollback}
|
111
117
|
end
|
112
118
|
end
|
113
119
|
end
|
data/lib/sequel/adapters/mock.rb
CHANGED
@@ -296,6 +296,10 @@ module Sequel
|
|
296
296
|
end
|
297
297
|
end
|
298
298
|
|
299
|
+
def dataset_class_default
|
300
|
+
Dataset
|
301
|
+
end
|
302
|
+
|
299
303
|
def quote_identifiers_default
|
300
304
|
shared_adapter? ? super : false
|
301
305
|
end
|
@@ -307,6 +311,7 @@ module Sequel
|
|
307
311
|
|
308
312
|
class Dataset < Sequel::Dataset
|
309
313
|
Database::DatasetClass = self
|
314
|
+
Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
|
310
315
|
|
311
316
|
# The autoid setting for this dataset, if it has been overridden
|
312
317
|
def autoid
|
@@ -28,6 +28,7 @@ module Sequel
|
|
28
28
|
}.each do |k,v|
|
29
29
|
k.each{|n| MYSQL_TYPES[n] = v}
|
30
30
|
end
|
31
|
+
# MYSQL_TYPES.freeze # SEQUEL5
|
31
32
|
|
32
33
|
class << self
|
33
34
|
# Whether to convert invalid date time values by default.
|
@@ -47,6 +48,7 @@ module Sequel
|
|
47
48
|
# Regular expression used for getting accurate number of rows
|
48
49
|
# matched by an update statement.
|
49
50
|
AFFECTED_ROWS_RE = /Rows matched:\s+(\d+)\s+Changed:\s+\d+\s+Warnings:\s+\d+/.freeze
|
51
|
+
Sequel::Deprecation.deprecate_constant(self, :AFFECTED_ROWS_RE)
|
50
52
|
|
51
53
|
set_adapter_scheme :mysql
|
52
54
|
|
@@ -234,7 +236,7 @@ module Sequel
|
|
234
236
|
# that may be inaccurate.
|
235
237
|
def affected_rows(conn)
|
236
238
|
s = conn.info
|
237
|
-
if s && s =~
|
239
|
+
if s && s =~ /Rows matched:\s+(\d+)\s+Changed:\s+\d+\s+Warnings:\s+\d+/
|
238
240
|
$1.to_i
|
239
241
|
else
|
240
242
|
conn.affected_rows
|
@@ -273,6 +275,10 @@ module Sequel
|
|
273
275
|
exception.sqlstate
|
274
276
|
end
|
275
277
|
|
278
|
+
def dataset_class_default
|
279
|
+
Dataset
|
280
|
+
end
|
281
|
+
|
276
282
|
# Raise a disconnect error if the exception message matches the list
|
277
283
|
# of recognized exceptions.
|
278
284
|
def disconnect_error?(e, opts)
|
@@ -299,6 +305,7 @@ module Sequel
|
|
299
305
|
include Sequel::MySQL::PreparedStatements::DatasetMethods
|
300
306
|
|
301
307
|
Database::DatasetClass = self
|
308
|
+
Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
|
302
309
|
|
303
310
|
# Yield all rows matching this dataset. If the dataset is set to
|
304
311
|
# split multiple statements, yield arrays of hashes one per statement
|
@@ -204,6 +204,10 @@ module Sequel
|
|
204
204
|
exception.sql_state
|
205
205
|
end
|
206
206
|
|
207
|
+
def dataset_class_default
|
208
|
+
Dataset
|
209
|
+
end
|
210
|
+
|
207
211
|
# If a connection object is available, try pinging it. Otherwise, if the
|
208
212
|
# error is a Mysql2::Error, check the SQL state and exception message for
|
209
213
|
# disconnects.
|
@@ -236,6 +240,7 @@ module Sequel
|
|
236
240
|
STREAMING_SUPPORTED = ::Mysql2::VERSION >= '0.3.12'
|
237
241
|
|
238
242
|
Database::DatasetClass = self
|
243
|
+
Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
|
239
244
|
|
240
245
|
if NativePreparedStatements
|
241
246
|
PreparedStatementMethods = prepared_statements_module(
|
@@ -299,7 +304,7 @@ module Sequel
|
|
299
304
|
# Handle correct quoting of strings using ::Mysql2::Client#escape.
|
300
305
|
def literal_string_append(sql, v)
|
301
306
|
s = db.synchronize(@opts[:server]){|c| c.escape(v)}
|
302
|
-
sql <<
|
307
|
+
sql << "'" << s << "'"
|
303
308
|
end
|
304
309
|
end
|
305
310
|
end
|
data/lib/sequel/adapters/odbc.rb
CHANGED
@@ -12,8 +12,11 @@ module Sequel
|
|
12
12
|
set_adapter_scheme :odbc
|
13
13
|
|
14
14
|
GUARDED_DRV_NAME = /^\{.+\}$/.freeze
|
15
|
+
Sequel::Deprecation.deprecate_constant(self, :GUARDED_DRV_NAME)
|
15
16
|
DRV_NAME_GUARDS = '{%s}'.freeze
|
17
|
+
Sequel::Deprecation.deprecate_constant(self, :DRV_NAME_GUARDS)
|
16
18
|
DISCONNECT_ERRORS = /\A08S01/.freeze
|
19
|
+
Sequel::Deprecation.deprecate_constant(self, :DISCONNECT_ERRORS)
|
17
20
|
|
18
21
|
def connect(server)
|
19
22
|
opts = server_opts(server)
|
@@ -23,8 +26,8 @@ module Sequel
|
|
23
26
|
drv = ::ODBC::Driver.new
|
24
27
|
drv.name = 'Sequel ODBC Driver130'
|
25
28
|
opts.each do |param, value|
|
26
|
-
if :driver == param
|
27
|
-
value =
|
29
|
+
if :driver == param && value !~ /\A\{.+\}\z/
|
30
|
+
value = "{#{value}}"
|
28
31
|
end
|
29
32
|
drv.attrs[param.to_s.upcase] = value.to_s
|
30
33
|
end
|
@@ -80,24 +83,33 @@ module Sequel
|
|
80
83
|
[::ODBC::Error]
|
81
84
|
end
|
82
85
|
|
86
|
+
def dataset_class_default
|
87
|
+
Dataset
|
88
|
+
end
|
89
|
+
|
83
90
|
def disconnect_error?(e, opts)
|
84
|
-
super || (e.is_a?(::ODBC::Error) &&
|
91
|
+
super || (e.is_a?(::ODBC::Error) && /\A08S01/.match(e.message))
|
85
92
|
end
|
86
93
|
end
|
87
94
|
|
88
95
|
class Dataset < Sequel::Dataset
|
89
96
|
BOOL_TRUE = '1'.freeze
|
97
|
+
Sequel::Deprecation.deprecate_constant(self, :BOOL_TRUE)
|
90
98
|
BOOL_FALSE = '0'.freeze
|
99
|
+
Sequel::Deprecation.deprecate_constant(self, :BOOL_FALSE)
|
91
100
|
ODBC_DATE_FORMAT = "{d '%Y-%m-%d'}".freeze
|
101
|
+
Sequel::Deprecation.deprecate_constant(self, :ODBC_DATE_FORMAT)
|
92
102
|
TIMESTAMP_FORMAT="{ts '%Y-%m-%d %H:%M:%S'}".freeze
|
103
|
+
Sequel::Deprecation.deprecate_constant(self, :TIMESTAMP_FORMAT)
|
93
104
|
|
94
105
|
Database::DatasetClass = self
|
106
|
+
Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
|
95
107
|
|
96
108
|
def fetch_rows(sql)
|
97
109
|
execute(sql) do |s|
|
98
110
|
i = -1
|
99
111
|
cols = s.columns(true).map{|c| [output_identifier(c.name), c.type, i+=1]}
|
100
|
-
columns = cols.map{|c| c
|
112
|
+
columns = cols.map{|c| c[0]}
|
101
113
|
self.columns = columns
|
102
114
|
if rows = s.fetch_all
|
103
115
|
rows.each do |row|
|
@@ -136,19 +148,19 @@ module Sequel
|
|
136
148
|
end
|
137
149
|
|
138
150
|
def default_timestamp_format
|
139
|
-
|
151
|
+
"{ts '%Y-%m-%d %H:%M:%S'}"
|
140
152
|
end
|
141
153
|
|
142
154
|
def literal_date(v)
|
143
|
-
v.strftime(
|
155
|
+
v.strftime("{d '%Y-%m-%d'}")
|
144
156
|
end
|
145
157
|
|
146
158
|
def literal_false
|
147
|
-
|
159
|
+
'0'
|
148
160
|
end
|
149
161
|
|
150
162
|
def literal_true
|
151
|
-
|
163
|
+
'1'
|
152
164
|
end
|
153
165
|
end
|
154
166
|
end
|
@@ -18,6 +18,7 @@ module Sequel
|
|
18
18
|
module DatabaseMethods
|
19
19
|
include Sequel::MSSQL::DatabaseMethods
|
20
20
|
LAST_INSERT_ID_SQL='SELECT SCOPE_IDENTITY()'.freeze
|
21
|
+
Sequel::Deprecation.deprecate_constant(self, :LAST_INSERT_ID_SQL)
|
21
22
|
|
22
23
|
# Return the last inserted identity value.
|
23
24
|
def execute_insert(sql, opts=OPTS)
|
@@ -25,7 +26,8 @@ module Sequel
|
|
25
26
|
begin
|
26
27
|
log_connection_yield(sql, conn){conn.do(sql)}
|
27
28
|
begin
|
28
|
-
|
29
|
+
last_insert_id_sql = 'SELECT SCOPE_IDENTITY()'
|
30
|
+
s = log_connection_yield(last_insert_id_sql, conn){conn.run(last_insert_id_sql)}
|
29
31
|
if (rows = s.fetch_all) and (row = rows.first) and (v = row.first)
|
30
32
|
Integer(v)
|
31
33
|
end
|
@@ -44,17 +46,18 @@ module Sequel
|
|
44
46
|
# Use ODBC format, not Microsoft format, as the ODBC layer does
|
45
47
|
# some translation. MSSQL version is over-ridden to allow 3 millisecond decimal places
|
46
48
|
TIMESTAMP_FORMAT="{ts '%Y-%m-%d %H:%M:%S%N'}".freeze
|
49
|
+
Sequel::Deprecation.deprecate_constant(self, :TIMESTAMP_FORMAT)
|
47
50
|
|
48
51
|
private
|
49
52
|
|
50
53
|
def default_timestamp_format
|
51
|
-
|
54
|
+
"{ts '%Y-%m-%d %H:%M:%S%N'}"
|
52
55
|
end
|
53
56
|
|
54
57
|
# Use ODBC format, not Microsoft format, as the ODBC layer does
|
55
58
|
# some translation.
|
56
59
|
def literal_date(v)
|
57
|
-
v.strftime(
|
60
|
+
v.strftime("{d '%Y-%m-%d'}")
|
58
61
|
end
|
59
62
|
end
|
60
63
|
end
|
@@ -13,12 +13,12 @@ module Sequel
|
|
13
13
|
# ORA-01012: not logged on
|
14
14
|
# ORA-03113: end-of-file on communication channel
|
15
15
|
# ORA-03114: not connected to ORACLE
|
16
|
-
CONNECTION_ERROR_CODES = [ 28, 1012, 3113, 3114 ]
|
16
|
+
CONNECTION_ERROR_CODES = [ 28, 1012, 3113, 3114 ]#.freeze # SEQUEL5
|
17
17
|
|
18
18
|
ORACLE_TYPES = {
|
19
19
|
:blob=>lambda{|b| Sequel::SQL::Blob.new(b.read)},
|
20
20
|
:clob=>lambda(&:read)
|
21
|
-
}
|
21
|
+
}#.freeze # SEQUEL5
|
22
22
|
|
23
23
|
# Hash of conversion procs for this database.
|
24
24
|
attr_reader :conversion_procs
|
@@ -164,6 +164,10 @@ module Sequel
|
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
+
def dataset_class_default
|
168
|
+
Dataset
|
169
|
+
end
|
170
|
+
|
167
171
|
def execute_prepared_statement(conn, type, name, opts)
|
168
172
|
ps = prepared_statement(name)
|
169
173
|
sql = ps.prepared_sql
|
@@ -216,12 +220,12 @@ module Sequel
|
|
216
220
|
end
|
217
221
|
|
218
222
|
def begin_transaction(conn, opts=OPTS)
|
219
|
-
log_connection_yield(
|
223
|
+
log_connection_yield('Transaction.begin', conn){conn.autocommit = false}
|
220
224
|
set_transaction_isolation(conn, opts)
|
221
225
|
end
|
222
226
|
|
223
227
|
def commit_transaction(conn, opts=OPTS)
|
224
|
-
log_connection_yield(
|
228
|
+
log_connection_yield('Transaction.commit', conn){conn.commit}
|
225
229
|
end
|
226
230
|
|
227
231
|
def disconnect_error?(e, opts)
|
@@ -253,7 +257,7 @@ module Sequel
|
|
253
257
|
end
|
254
258
|
|
255
259
|
def rollback_transaction(conn, opts=OPTS)
|
256
|
-
log_connection_yield(
|
260
|
+
log_connection_yield('Transaction.rollback', conn){conn.rollback}
|
257
261
|
end
|
258
262
|
|
259
263
|
def schema_parse_table(table, opts=OPTS)
|
@@ -325,8 +329,10 @@ module Sequel
|
|
325
329
|
include DatasetMethods
|
326
330
|
|
327
331
|
Database::DatasetClass = self
|
332
|
+
Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
|
328
333
|
|
329
334
|
PREPARED_ARG_PLACEHOLDER = ':'.freeze
|
335
|
+
Sequel::Deprecation.deprecate_constant(self, :PREPARED_ARG_PLACEHOLDER)
|
330
336
|
|
331
337
|
# Oracle already supports named bind arguments, so use directly.
|
332
338
|
module ArgumentMapper
|
@@ -398,7 +404,7 @@ module Sequel
|
|
398
404
|
end
|
399
405
|
|
400
406
|
def prepared_arg_placeholder
|
401
|
-
|
407
|
+
':'
|
402
408
|
end
|
403
409
|
|
404
410
|
def bound_variable_modules
|