sequel 5.39.0 → 5.72.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +408 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +59 -27
- data/bin/sequel +11 -3
- data/doc/advanced_associations.rdoc +16 -14
- data/doc/association_basics.rdoc +119 -24
- data/doc/cheat_sheet.rdoc +11 -3
- data/doc/mass_assignment.rdoc +1 -1
- data/doc/migration.rdoc +13 -6
- data/doc/model_hooks.rdoc +1 -1
- data/doc/object_model.rdoc +8 -8
- data/doc/opening_databases.rdoc +26 -12
- data/doc/postgresql.rdoc +16 -8
- data/doc/querying.rdoc +5 -3
- data/doc/release_notes/5.40.0.txt +40 -0
- data/doc/release_notes/5.41.0.txt +25 -0
- data/doc/release_notes/5.42.0.txt +136 -0
- data/doc/release_notes/5.43.0.txt +98 -0
- data/doc/release_notes/5.44.0.txt +32 -0
- data/doc/release_notes/5.45.0.txt +34 -0
- data/doc/release_notes/5.46.0.txt +87 -0
- data/doc/release_notes/5.47.0.txt +59 -0
- data/doc/release_notes/5.48.0.txt +14 -0
- data/doc/release_notes/5.49.0.txt +59 -0
- data/doc/release_notes/5.50.0.txt +78 -0
- data/doc/release_notes/5.51.0.txt +47 -0
- data/doc/release_notes/5.52.0.txt +87 -0
- data/doc/release_notes/5.53.0.txt +23 -0
- data/doc/release_notes/5.54.0.txt +27 -0
- data/doc/release_notes/5.55.0.txt +21 -0
- data/doc/release_notes/5.56.0.txt +51 -0
- data/doc/release_notes/5.57.0.txt +23 -0
- data/doc/release_notes/5.58.0.txt +31 -0
- data/doc/release_notes/5.59.0.txt +73 -0
- data/doc/release_notes/5.60.0.txt +22 -0
- data/doc/release_notes/5.61.0.txt +43 -0
- data/doc/release_notes/5.62.0.txt +132 -0
- data/doc/release_notes/5.63.0.txt +33 -0
- data/doc/release_notes/5.64.0.txt +50 -0
- data/doc/release_notes/5.65.0.txt +21 -0
- data/doc/release_notes/5.66.0.txt +24 -0
- data/doc/release_notes/5.67.0.txt +32 -0
- data/doc/release_notes/5.68.0.txt +61 -0
- data/doc/release_notes/5.69.0.txt +26 -0
- data/doc/release_notes/5.70.0.txt +35 -0
- data/doc/release_notes/5.71.0.txt +21 -0
- data/doc/release_notes/5.72.0.txt +33 -0
- data/doc/schema_modification.rdoc +1 -1
- data/doc/security.rdoc +9 -9
- data/doc/sharding.rdoc +3 -1
- data/doc/sql.rdoc +28 -16
- data/doc/testing.rdoc +22 -11
- data/doc/transactions.rdoc +6 -6
- data/doc/virtual_rows.rdoc +2 -2
- data/lib/sequel/adapters/ado/access.rb +1 -1
- data/lib/sequel/adapters/ado.rb +17 -17
- data/lib/sequel/adapters/amalgalite.rb +3 -5
- data/lib/sequel/adapters/ibmdb.rb +2 -2
- data/lib/sequel/adapters/jdbc/derby.rb +8 -0
- data/lib/sequel/adapters/jdbc/h2.rb +60 -10
- data/lib/sequel/adapters/jdbc/hsqldb.rb +6 -0
- data/lib/sequel/adapters/jdbc/postgresql.rb +7 -4
- data/lib/sequel/adapters/jdbc.rb +16 -18
- data/lib/sequel/adapters/mysql.rb +92 -67
- data/lib/sequel/adapters/mysql2.rb +54 -49
- data/lib/sequel/adapters/odbc.rb +6 -2
- data/lib/sequel/adapters/oracle.rb +4 -3
- data/lib/sequel/adapters/postgres.rb +83 -40
- data/lib/sequel/adapters/shared/access.rb +11 -1
- data/lib/sequel/adapters/shared/db2.rb +30 -0
- data/lib/sequel/adapters/shared/mssql.rb +90 -9
- data/lib/sequel/adapters/shared/mysql.rb +47 -2
- data/lib/sequel/adapters/shared/oracle.rb +82 -1
- data/lib/sequel/adapters/shared/postgres.rb +496 -178
- data/lib/sequel/adapters/shared/sqlanywhere.rb +11 -1
- data/lib/sequel/adapters/shared/sqlite.rb +116 -11
- data/lib/sequel/adapters/sqlanywhere.rb +1 -1
- data/lib/sequel/adapters/sqlite.rb +60 -18
- data/lib/sequel/adapters/tinytds.rb +1 -1
- data/lib/sequel/adapters/trilogy.rb +117 -0
- data/lib/sequel/adapters/utils/columns_limit_1.rb +22 -0
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
- data/lib/sequel/ast_transformer.rb +6 -0
- data/lib/sequel/connection_pool/sharded_single.rb +5 -7
- data/lib/sequel/connection_pool/sharded_threaded.rb +16 -11
- data/lib/sequel/connection_pool/sharded_timed_queue.rb +374 -0
- data/lib/sequel/connection_pool/single.rb +6 -8
- data/lib/sequel/connection_pool/threaded.rb +14 -8
- data/lib/sequel/connection_pool/timed_queue.rb +270 -0
- data/lib/sequel/connection_pool.rb +55 -31
- data/lib/sequel/core.rb +28 -18
- data/lib/sequel/database/connecting.rb +27 -3
- data/lib/sequel/database/dataset.rb +16 -6
- data/lib/sequel/database/misc.rb +69 -14
- data/lib/sequel/database/query.rb +73 -2
- data/lib/sequel/database/schema_generator.rb +46 -53
- data/lib/sequel/database/schema_methods.rb +18 -2
- data/lib/sequel/dataset/actions.rb +108 -14
- data/lib/sequel/dataset/deprecated_singleton_class_methods.rb +42 -0
- data/lib/sequel/dataset/features.rb +20 -0
- data/lib/sequel/dataset/misc.rb +12 -2
- data/lib/sequel/dataset/placeholder_literalizer.rb +20 -9
- data/lib/sequel/dataset/prepared_statements.rb +2 -0
- data/lib/sequel/dataset/query.rb +171 -44
- data/lib/sequel/dataset/sql.rb +182 -47
- data/lib/sequel/dataset.rb +4 -0
- data/lib/sequel/extensions/_model_pg_row.rb +0 -12
- data/lib/sequel/extensions/_pretty_table.rb +1 -1
- data/lib/sequel/extensions/any_not_empty.rb +1 -1
- data/lib/sequel/extensions/async_thread_pool.rb +439 -0
- data/lib/sequel/extensions/auto_literal_strings.rb +1 -1
- data/lib/sequel/extensions/blank.rb +8 -0
- data/lib/sequel/extensions/connection_expiration.rb +15 -9
- data/lib/sequel/extensions/connection_validator.rb +16 -11
- data/lib/sequel/extensions/constraint_validations.rb +1 -1
- data/lib/sequel/extensions/core_refinements.rb +36 -11
- data/lib/sequel/extensions/date_arithmetic.rb +71 -31
- data/lib/sequel/extensions/date_parse_input_handler.rb +67 -0
- data/lib/sequel/extensions/datetime_parse_to_time.rb +5 -1
- data/lib/sequel/extensions/duplicate_columns_handler.rb +1 -1
- data/lib/sequel/extensions/eval_inspect.rb +2 -0
- data/lib/sequel/extensions/index_caching.rb +5 -1
- data/lib/sequel/extensions/inflector.rb +9 -1
- data/lib/sequel/extensions/is_distinct_from.rb +141 -0
- data/lib/sequel/extensions/looser_typecasting.rb +3 -0
- data/lib/sequel/extensions/migration.rb +11 -2
- data/lib/sequel/extensions/named_timezones.rb +26 -6
- data/lib/sequel/extensions/pagination.rb +1 -1
- data/lib/sequel/extensions/pg_array.rb +32 -4
- data/lib/sequel/extensions/pg_array_ops.rb +2 -2
- data/lib/sequel/extensions/pg_auto_parameterize.rb +509 -0
- data/lib/sequel/extensions/pg_auto_parameterize_in_array.rb +110 -0
- data/lib/sequel/extensions/pg_enum.rb +2 -3
- data/lib/sequel/extensions/pg_extended_date_support.rb +38 -27
- data/lib/sequel/extensions/pg_extended_integer_support.rb +116 -0
- data/lib/sequel/extensions/pg_hstore.rb +6 -1
- data/lib/sequel/extensions/pg_hstore_ops.rb +53 -3
- data/lib/sequel/extensions/pg_inet.rb +10 -11
- data/lib/sequel/extensions/pg_inet_ops.rb +1 -1
- data/lib/sequel/extensions/pg_interval.rb +45 -19
- data/lib/sequel/extensions/pg_json.rb +13 -15
- data/lib/sequel/extensions/pg_json_ops.rb +73 -2
- data/lib/sequel/extensions/pg_loose_count.rb +3 -1
- data/lib/sequel/extensions/pg_multirange.rb +367 -0
- data/lib/sequel/extensions/pg_range.rb +11 -24
- data/lib/sequel/extensions/pg_range_ops.rb +37 -9
- data/lib/sequel/extensions/pg_row.rb +21 -19
- data/lib/sequel/extensions/pg_row_ops.rb +1 -1
- data/lib/sequel/extensions/query.rb +2 -0
- data/lib/sequel/extensions/s.rb +2 -1
- data/lib/sequel/extensions/schema_caching.rb +1 -1
- data/lib/sequel/extensions/schema_dumper.rb +45 -11
- data/lib/sequel/extensions/server_block.rb +10 -13
- data/lib/sequel/extensions/set_literalizer.rb +58 -0
- data/lib/sequel/extensions/sql_comments.rb +110 -3
- data/lib/sequel/extensions/sql_log_normalizer.rb +108 -0
- data/lib/sequel/extensions/sqlite_json_ops.rb +255 -0
- data/lib/sequel/extensions/string_agg.rb +1 -1
- data/lib/sequel/extensions/string_date_time.rb +19 -23
- data/lib/sequel/extensions/symbol_aref.rb +2 -0
- data/lib/sequel/model/associations.rb +345 -101
- data/lib/sequel/model/base.rb +51 -27
- data/lib/sequel/model/dataset_module.rb +3 -0
- data/lib/sequel/model/errors.rb +10 -1
- data/lib/sequel/model/inflections.rb +1 -1
- data/lib/sequel/model/plugins.rb +5 -0
- data/lib/sequel/plugins/association_proxies.rb +2 -0
- data/lib/sequel/plugins/async_thread_pool.rb +39 -0
- data/lib/sequel/plugins/auto_restrict_eager_graph.rb +62 -0
- data/lib/sequel/plugins/auto_validations.rb +87 -15
- data/lib/sequel/plugins/auto_validations_constraint_validations_presence_message.rb +68 -0
- data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/column_encryption.rb +728 -0
- data/lib/sequel/plugins/composition.rb +10 -4
- data/lib/sequel/plugins/concurrent_eager_loading.rb +174 -0
- data/lib/sequel/plugins/constraint_validations.rb +10 -6
- data/lib/sequel/plugins/dataset_associations.rb +4 -1
- data/lib/sequel/plugins/defaults_setter.rb +16 -0
- data/lib/sequel/plugins/dirty.rb +1 -1
- data/lib/sequel/plugins/enum.rb +124 -0
- data/lib/sequel/plugins/finder.rb +4 -2
- data/lib/sequel/plugins/insert_conflict.rb +4 -0
- data/lib/sequel/plugins/instance_specific_default.rb +1 -1
- data/lib/sequel/plugins/json_serializer.rb +39 -24
- data/lib/sequel/plugins/lazy_attributes.rb +3 -0
- data/lib/sequel/plugins/list.rb +3 -1
- data/lib/sequel/plugins/many_through_many.rb +109 -10
- data/lib/sequel/plugins/mssql_optimistic_locking.rb +8 -38
- data/lib/sequel/plugins/nested_attributes.rb +12 -7
- data/lib/sequel/plugins/optimistic_locking.rb +9 -42
- data/lib/sequel/plugins/optimistic_locking_base.rb +55 -0
- data/lib/sequel/plugins/pg_array_associations.rb +56 -38
- data/lib/sequel/plugins/pg_auto_constraint_validations.rb +11 -3
- data/lib/sequel/plugins/pg_xmin_optimistic_locking.rb +109 -0
- data/lib/sequel/plugins/prepared_statements.rb +12 -2
- data/lib/sequel/plugins/prepared_statements_safe.rb +2 -1
- data/lib/sequel/plugins/primary_key_lookup_check_values.rb +154 -0
- data/lib/sequel/plugins/rcte_tree.rb +27 -19
- data/lib/sequel/plugins/require_valid_schema.rb +67 -0
- data/lib/sequel/plugins/serialization.rb +9 -3
- data/lib/sequel/plugins/serialization_modification_detection.rb +2 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +8 -0
- data/lib/sequel/plugins/sql_comments.rb +189 -0
- data/lib/sequel/plugins/static_cache.rb +39 -1
- data/lib/sequel/plugins/static_cache_cache.rb +5 -1
- data/lib/sequel/plugins/subclasses.rb +28 -11
- data/lib/sequel/plugins/tactical_eager_loading.rb +23 -10
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/unused_associations.rb +521 -0
- data/lib/sequel/plugins/update_or_create.rb +1 -1
- data/lib/sequel/plugins/validate_associated.rb +22 -12
- data/lib/sequel/plugins/validation_helpers.rb +46 -12
- data/lib/sequel/plugins/validation_helpers_generic_type_messages.rb +73 -0
- data/lib/sequel/plugins/xml_serializer.rb +1 -1
- data/lib/sequel/sql.rb +1 -1
- data/lib/sequel/timezones.rb +12 -14
- data/lib/sequel/version.rb +1 -1
- metadata +132 -38
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
2
|
|
3
3
|
require 'mysql'
|
4
|
-
raise(LoadError, "require 'mysql' did not define Mysql::CLIENT_MULTI_RESULTS
|
4
|
+
raise(LoadError, "require 'mysql' did not define Mysql::CLIENT_MULTI_RESULTS!, so it not supported. Please install the mysql or ruby-mysql gem.\n") unless defined?(Mysql::CLIENT_MULTI_RESULTS)
|
5
5
|
|
6
6
|
require_relative 'utils/mysql_mysql2'
|
7
7
|
require_relative 'utils/mysql_prepared_statements'
|
@@ -29,6 +29,21 @@ module Sequel
|
|
29
29
|
end
|
30
30
|
MYSQL_TYPES.freeze
|
31
31
|
|
32
|
+
RUBY_MYSQL_3 = !Mysql.respond_to?(:init)
|
33
|
+
RUBY_MYSQL_4 = RUBY_MYSQL_3 && ::Mysql::VERSION.to_i >= 4
|
34
|
+
|
35
|
+
if RUBY_MYSQL_3
|
36
|
+
class Adapter < ::Mysql
|
37
|
+
alias real_connect connect
|
38
|
+
alias use_result store_result
|
39
|
+
if RUBY_MYSQL_4
|
40
|
+
def initialize(**opts)
|
41
|
+
super(**opts.merge(:cast=>false))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
32
47
|
class Database < Sequel::Database
|
33
48
|
include Sequel::MySQL::DatabaseMethods
|
34
49
|
include Sequel::MySQL::MysqlMysql2::DatabaseMethods
|
@@ -71,21 +86,40 @@ module Sequel
|
|
71
86
|
# disconnect this connection (a.k.a @@wait_timeout).
|
72
87
|
def connect(server)
|
73
88
|
opts = server_opts(server)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
89
|
+
|
90
|
+
if !RUBY_MYSQL_3
|
91
|
+
conn = Mysql.init
|
92
|
+
conn.options(Mysql::READ_DEFAULT_GROUP, opts[:config_default_group] || "client")
|
93
|
+
conn.options(Mysql::OPT_LOCAL_INFILE, opts[:config_local_infile]) if opts.has_key?(:config_local_infile)
|
94
|
+
if encoding = opts[:encoding] || opts[:charset]
|
95
|
+
# Set encoding before connecting so that the mysql driver knows what
|
96
|
+
# encoding we want to use, but this can be overridden by READ_DEFAULT_GROUP.
|
97
|
+
conn.options(Mysql::SET_CHARSET_NAME, encoding)
|
98
|
+
end
|
99
|
+
if read_timeout = opts[:read_timeout] and defined? Mysql::OPT_READ_TIMEOUT
|
100
|
+
conn.options(Mysql::OPT_READ_TIMEOUT, read_timeout)
|
101
|
+
end
|
102
|
+
if connect_timeout = opts[:connect_timeout] and defined? Mysql::OPT_CONNECT_TIMEOUT
|
103
|
+
conn.options(Mysql::OPT_CONNECT_TIMEOUT, connect_timeout)
|
104
|
+
end
|
105
|
+
else
|
106
|
+
# ruby-mysql 3+ API
|
107
|
+
conn = Adapter.new
|
108
|
+
# no support for default group
|
109
|
+
conn.local_infile = opts[:config_local_infile] if opts.has_key?(:config_local_infile)
|
110
|
+
if encoding = opts[:encoding] || opts[:charset]
|
111
|
+
conn.charset = encoding
|
112
|
+
end
|
113
|
+
if read_timeout = opts[:read_timeout]
|
114
|
+
conn.read_timeout = read_timeout
|
115
|
+
end
|
116
|
+
if connect_timeout = opts[:connect_timeout]
|
117
|
+
conn.connect_timeout = connect_timeout
|
118
|
+
end
|
119
|
+
opts[:compress] = false
|
88
120
|
end
|
121
|
+
|
122
|
+
conn.ssl_set(opts[:sslkey], opts[:sslcert], opts[:sslca], opts[:sslcapath], opts[:sslcipher]) if opts[:sslca] || opts[:sslkey]
|
89
123
|
conn.real_connect(
|
90
124
|
opts[:host] || 'localhost',
|
91
125
|
opts[:user],
|
@@ -152,56 +186,49 @@ module Sequel
|
|
152
186
|
super
|
153
187
|
end
|
154
188
|
|
155
|
-
# Return the version of the MySQL server to which we are connecting.
|
156
|
-
def server_version(server=nil)
|
157
|
-
@server_version ||= (synchronize(server){|conn| conn.server_version if conn.respond_to?(:server_version)} || super)
|
158
|
-
end
|
159
|
-
|
160
189
|
private
|
161
190
|
|
162
191
|
# Execute the given SQL on the given connection. If the :type
|
163
192
|
# option is :select, yield the result of the query, otherwise
|
164
193
|
# yield the connection if a block is given.
|
165
194
|
def _execute(conn, sql, opts)
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
r = nil
|
178
|
-
end
|
179
|
-
begin
|
180
|
-
conn.next_result
|
181
|
-
r = conn.use_result
|
182
|
-
rescue Mysql::Error => e
|
183
|
-
raise_error(e, :disconnect=>true) if MYSQL_DATABASE_DISCONNECT_ERRORS.match(e.message)
|
184
|
-
break
|
185
|
-
end
|
186
|
-
yield r if opts[:type] == :select
|
195
|
+
r = log_connection_yield((log_sql = opts[:log_sql]) ? sql + log_sql : sql, conn){conn.query(sql)}
|
196
|
+
if opts[:type] == :select
|
197
|
+
yield r if r
|
198
|
+
elsif defined?(yield)
|
199
|
+
yield conn
|
200
|
+
end
|
201
|
+
if conn.respond_to?(:more_results?)
|
202
|
+
while conn.more_results? do
|
203
|
+
if r
|
204
|
+
r.free
|
205
|
+
r = nil
|
187
206
|
end
|
207
|
+
begin
|
208
|
+
conn.next_result
|
209
|
+
r = conn.use_result
|
210
|
+
rescue Mysql::Error => e
|
211
|
+
raise_error(e, :disconnect=>true) if MYSQL_DATABASE_DISCONNECT_ERRORS.match(e.message)
|
212
|
+
break
|
213
|
+
end
|
214
|
+
yield r if opts[:type] == :select
|
188
215
|
end
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
r.free if r
|
216
|
+
end
|
217
|
+
rescue Mysql::Error => e
|
218
|
+
raise_error(e)
|
219
|
+
ensure
|
220
|
+
r.free if r
|
221
|
+
# Use up all results to avoid a commands out of sync message.
|
222
|
+
if conn.respond_to?(:more_results?)
|
223
|
+
while conn.more_results? do
|
224
|
+
begin
|
225
|
+
conn.next_result
|
226
|
+
r = conn.use_result
|
227
|
+
rescue Mysql::Error => e
|
228
|
+
raise_error(e, :disconnect=>true) if MYSQL_DATABASE_DISCONNECT_ERRORS.match(e.message)
|
229
|
+
break
|
204
230
|
end
|
231
|
+
r.free if r
|
205
232
|
end
|
206
233
|
end
|
207
234
|
end
|
@@ -233,17 +260,15 @@ module Sequel
|
|
233
260
|
# the conversion raises an InvalidValue exception, return v
|
234
261
|
# if :string and nil otherwise.
|
235
262
|
def convert_date_time(v)
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
raise
|
246
|
-
end
|
263
|
+
yield v
|
264
|
+
rescue InvalidValue
|
265
|
+
case @convert_invalid_date_time
|
266
|
+
when nil, :nil
|
267
|
+
nil
|
268
|
+
when :string
|
269
|
+
v
|
270
|
+
else
|
271
|
+
raise
|
247
272
|
end
|
248
273
|
end
|
249
274
|
|
@@ -86,20 +86,26 @@ module Sequel
|
|
86
86
|
if NativePreparedStatements
|
87
87
|
# Use a native mysql2 prepared statement to implement prepared statements.
|
88
88
|
def execute_prepared_statement(ps_name, opts, &block)
|
89
|
-
|
89
|
+
if ps_name.is_a?(Sequel::Dataset::ArgumentMapper)
|
90
|
+
ps = ps_name
|
91
|
+
ps_name = ps.prepared_statement_name
|
92
|
+
else
|
93
|
+
ps = prepared_statement(ps_name)
|
94
|
+
end
|
90
95
|
sql = ps.prepared_sql
|
91
96
|
|
92
97
|
synchronize(opts[:server]) do |conn|
|
93
98
|
stmt, ps_sql = conn.prepared_statements[ps_name]
|
94
99
|
unless ps_sql == sql
|
95
100
|
stmt.close if stmt
|
96
|
-
stmt = log_connection_yield(
|
101
|
+
stmt = log_connection_yield("Preparing #{ps_name}: #{sql}", conn){conn.prepare(sql)}
|
97
102
|
conn.prepared_statements[ps_name] = [stmt, sql]
|
98
103
|
end
|
99
104
|
|
100
|
-
|
101
|
-
|
102
|
-
|
105
|
+
opts = Hash[opts]
|
106
|
+
opts[:sql] = "Executing #{ps_name || sql}"
|
107
|
+
if ps_name && ps.log_sql
|
108
|
+
opts[:log_sql] = " (#{sql})"
|
103
109
|
end
|
104
110
|
|
105
111
|
_execute(conn, stmt, opts, &block)
|
@@ -111,56 +117,55 @@ module Sequel
|
|
111
117
|
# option is :select, yield the result of the query, otherwise
|
112
118
|
# yield the connection if a block is given.
|
113
119
|
def _execute(conn, sql, opts)
|
114
|
-
|
115
|
-
|
116
|
-
if
|
117
|
-
|
118
|
-
|
119
|
-
end
|
120
|
+
stream = opts[:stream]
|
121
|
+
if NativePreparedStatements
|
122
|
+
if args = opts[:arguments]
|
123
|
+
args = args.map{|arg| bound_variable_value(arg)}
|
124
|
+
end
|
120
125
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
126
|
+
case sql
|
127
|
+
when ::Mysql2::Statement
|
128
|
+
stmt = sql
|
129
|
+
sql = opts[:sql] || ''
|
130
|
+
when Dataset
|
131
|
+
sql = sql.sql
|
132
|
+
close_stmt = true
|
133
|
+
stmt = conn.prepare(sql)
|
129
134
|
end
|
135
|
+
end
|
130
136
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
137
|
+
r = log_connection_yield((log_sql = opts[:log_sql]) ? sql + log_sql : sql, conn, args) do
|
138
|
+
if stmt
|
139
|
+
conn.query_options.merge!(:cache_rows=>true, :database_timezone => timezone, :application_timezone => Sequel.application_timezone, :stream=>stream, :cast_booleans=>convert_tinyint_to_bool)
|
140
|
+
stmt.execute(*args)
|
141
|
+
else
|
142
|
+
conn.query(sql, :database_timezone => timezone, :application_timezone => Sequel.application_timezone, :stream=>stream)
|
138
143
|
end
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
else
|
151
|
-
yield r
|
144
|
+
end
|
145
|
+
if opts[:type] == :select
|
146
|
+
if r
|
147
|
+
if stream
|
148
|
+
begin
|
149
|
+
r2 = yield r
|
150
|
+
ensure
|
151
|
+
# If r2 is nil, it means the block did not exit normally,
|
152
|
+
# so the rest of the results must be drained to prevent
|
153
|
+
# "commands out of sync" errors.
|
154
|
+
r.each{} unless r2
|
152
155
|
end
|
156
|
+
else
|
157
|
+
yield r
|
153
158
|
end
|
154
|
-
elsif block_given?
|
155
|
-
yield conn
|
156
|
-
end
|
157
|
-
rescue ::Mysql2::Error => e
|
158
|
-
raise_error(e)
|
159
|
-
ensure
|
160
|
-
if stmt
|
161
|
-
conn.query_options.replace(conn.instance_variable_get(:@sequel_default_query_options))
|
162
|
-
stmt.close if close_stmt
|
163
159
|
end
|
160
|
+
elsif defined?(yield)
|
161
|
+
yield conn
|
162
|
+
end
|
163
|
+
rescue ::Mysql2::Error => e
|
164
|
+
raise_error(e)
|
165
|
+
ensure
|
166
|
+
if stmt
|
167
|
+
conn.query_options.replace(conn.instance_variable_get(:@sequel_default_query_options))
|
168
|
+
stmt.close if close_stmt
|
164
169
|
end
|
165
170
|
end
|
166
171
|
|
@@ -244,7 +249,7 @@ module Sequel
|
|
244
249
|
# it hasn't been disabled.
|
245
250
|
def paged_each(opts=OPTS, &block)
|
246
251
|
if STREAMING_SUPPORTED && opts[:stream] != false
|
247
|
-
unless
|
252
|
+
unless defined?(yield)
|
248
253
|
return enum_for(:paged_each, opts)
|
249
254
|
end
|
250
255
|
stream.each(&block)
|
data/lib/sequel/adapters/odbc.rb
CHANGED
@@ -40,7 +40,7 @@ module Sequel
|
|
40
40
|
synchronize(opts[:server]) do |conn|
|
41
41
|
begin
|
42
42
|
r = log_connection_yield(sql, conn){conn.run(sql)}
|
43
|
-
yield(r) if
|
43
|
+
yield(r) if defined?(yield)
|
44
44
|
rescue ::ODBC::Error, ArgumentError => e
|
45
45
|
raise_error(e)
|
46
46
|
ensure
|
@@ -94,7 +94,11 @@ module Sequel
|
|
94
94
|
self.columns = columns
|
95
95
|
s.each do |row|
|
96
96
|
hash = {}
|
97
|
-
cols.each
|
97
|
+
cols.each do |n,t,j|
|
98
|
+
v = row[j]
|
99
|
+
# We can assume v is not false, so this shouldn't convert false to nil.
|
100
|
+
hash[n] = (convert_odbc_value(v, t) if v)
|
101
|
+
end
|
98
102
|
yield hash
|
99
103
|
end
|
100
104
|
end
|
@@ -88,11 +88,11 @@ module Sequel
|
|
88
88
|
r = conn.parse(sql)
|
89
89
|
args = cursor_bind_params(conn, r, args)
|
90
90
|
nr = log_connection_yield(sql, conn, args){r.exec}
|
91
|
-
r = nr unless
|
91
|
+
r = nr unless defined?(yield)
|
92
92
|
else
|
93
93
|
r = log_connection_yield(sql, conn){conn.exec(sql)}
|
94
94
|
end
|
95
|
-
if
|
95
|
+
if defined?(yield)
|
96
96
|
yield(r)
|
97
97
|
elsif type == :insert
|
98
98
|
last_insert_id(conn, opts)
|
@@ -192,7 +192,7 @@ module Sequel
|
|
192
192
|
log_sql << ")"
|
193
193
|
end
|
194
194
|
r = log_connection_yield(log_sql, conn, args){cursor.exec}
|
195
|
-
if
|
195
|
+
if defined?(yield)
|
196
196
|
yield(cursor)
|
197
197
|
elsif type == :insert
|
198
198
|
last_insert_id(conn, opts)
|
@@ -312,6 +312,7 @@ module Sequel
|
|
312
312
|
:char_used => column.char_used?,
|
313
313
|
:char_size => column.char_size,
|
314
314
|
:data_size => column.data_size,
|
315
|
+
:column_size => column.precision,
|
315
316
|
:precision => column.precision,
|
316
317
|
:scale => column.scale,
|
317
318
|
:fsprecision => column.fsprecision,
|