sequel 3.48.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +114 -0
- data/Rakefile +10 -7
- data/doc/association_basics.rdoc +25 -23
- data/doc/code_order.rdoc +7 -0
- data/doc/core_extensions.rdoc +0 -10
- data/doc/object_model.rdoc +4 -1
- data/doc/querying.rdoc +3 -3
- data/doc/release_notes/4.0.0.txt +262 -0
- data/doc/security.rdoc +0 -28
- data/doc/testing.rdoc +8 -14
- data/lib/sequel/adapters/ado.rb +7 -11
- data/lib/sequel/adapters/ado/access.rb +8 -8
- data/lib/sequel/adapters/ado/mssql.rb +4 -4
- data/lib/sequel/adapters/amalgalite.rb +6 -6
- data/lib/sequel/adapters/cubrid.rb +7 -7
- data/lib/sequel/adapters/db2.rb +5 -9
- data/lib/sequel/adapters/dbi.rb +2 -6
- data/lib/sequel/adapters/do.rb +4 -4
- data/lib/sequel/adapters/firebird.rb +4 -4
- data/lib/sequel/adapters/ibmdb.rb +8 -8
- data/lib/sequel/adapters/informix.rb +2 -10
- data/lib/sequel/adapters/jdbc.rb +17 -17
- data/lib/sequel/adapters/jdbc/as400.rb +2 -2
- data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
- data/lib/sequel/adapters/jdbc/db2.rb +1 -1
- data/lib/sequel/adapters/jdbc/derby.rb +1 -1
- data/lib/sequel/adapters/jdbc/h2.rb +2 -2
- data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
- data/lib/sequel/adapters/jdbc/informix.rb +1 -1
- data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
- data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
- data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
- data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
- data/lib/sequel/adapters/mock.rb +7 -7
- data/lib/sequel/adapters/mysql.rb +3 -3
- data/lib/sequel/adapters/mysql2.rb +4 -4
- data/lib/sequel/adapters/odbc.rb +2 -6
- data/lib/sequel/adapters/odbc/mssql.rb +1 -1
- data/lib/sequel/adapters/openbase.rb +1 -5
- data/lib/sequel/adapters/oracle.rb +13 -17
- data/lib/sequel/adapters/postgres.rb +20 -25
- data/lib/sequel/adapters/shared/cubrid.rb +3 -3
- data/lib/sequel/adapters/shared/db2.rb +2 -2
- data/lib/sequel/adapters/shared/firebird.rb +7 -7
- data/lib/sequel/adapters/shared/mssql.rb +9 -9
- data/lib/sequel/adapters/shared/mysql.rb +29 -13
- data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
- data/lib/sequel/adapters/shared/oracle.rb +22 -13
- data/lib/sequel/adapters/shared/postgres.rb +61 -46
- data/lib/sequel/adapters/shared/sqlite.rb +9 -9
- data/lib/sequel/adapters/sqlite.rb +17 -11
- data/lib/sequel/adapters/swift.rb +3 -3
- data/lib/sequel/adapters/swift/mysql.rb +1 -1
- data/lib/sequel/adapters/swift/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +8 -8
- data/lib/sequel/ast_transformer.rb +3 -1
- data/lib/sequel/connection_pool.rb +4 -2
- data/lib/sequel/connection_pool/sharded_single.rb +2 -2
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
- data/lib/sequel/connection_pool/threaded.rb +7 -7
- data/lib/sequel/core.rb +4 -67
- data/lib/sequel/database.rb +1 -0
- data/lib/sequel/database/connecting.rb +2 -8
- data/lib/sequel/database/dataset.rb +2 -7
- data/lib/sequel/database/dataset_defaults.rb +0 -18
- data/lib/sequel/database/features.rb +4 -4
- data/lib/sequel/database/misc.rb +6 -8
- data/lib/sequel/database/query.rb +5 -61
- data/lib/sequel/database/schema_generator.rb +22 -20
- data/lib/sequel/database/schema_methods.rb +48 -20
- data/lib/sequel/database/transactions.rb +7 -17
- data/lib/sequel/dataset.rb +2 -0
- data/lib/sequel/dataset/actions.rb +23 -91
- data/lib/sequel/dataset/features.rb +1 -4
- data/lib/sequel/dataset/graph.rb +3 -47
- data/lib/sequel/dataset/misc.rb +4 -33
- data/lib/sequel/dataset/prepared_statements.rb +3 -1
- data/lib/sequel/dataset/query.rb +116 -240
- data/lib/sequel/dataset/sql.rb +19 -97
- data/lib/sequel/deprecated.rb +0 -16
- data/lib/sequel/exceptions.rb +0 -3
- data/lib/sequel/extensions/_pretty_table.rb +1 -1
- data/lib/sequel/extensions/columns_introspection.rb +1 -12
- data/lib/sequel/extensions/constraint_validations.rb +3 -3
- data/lib/sequel/extensions/core_extensions.rb +0 -9
- data/lib/sequel/extensions/date_arithmetic.rb +1 -2
- data/lib/sequel/extensions/graph_each.rb +11 -0
- data/lib/sequel/extensions/migration.rb +5 -5
- data/lib/sequel/extensions/null_dataset.rb +11 -13
- data/lib/sequel/extensions/pagination.rb +3 -6
- data/lib/sequel/extensions/pg_array.rb +6 -4
- data/lib/sequel/extensions/pg_array_ops.rb +35 -1
- data/lib/sequel/extensions/pg_json.rb +12 -2
- data/lib/sequel/extensions/pg_json_ops.rb +266 -0
- data/lib/sequel/extensions/pg_range.rb +2 -2
- data/lib/sequel/extensions/pg_range_ops.rb +0 -8
- data/lib/sequel/extensions/pg_row.rb +2 -2
- data/lib/sequel/extensions/pretty_table.rb +0 -4
- data/lib/sequel/extensions/query.rb +3 -8
- data/lib/sequel/extensions/schema_caching.rb +0 -7
- data/lib/sequel/extensions/schema_dumper.rb +10 -17
- data/lib/sequel/extensions/select_remove.rb +0 -4
- data/lib/sequel/extensions/set_overrides.rb +28 -0
- data/lib/sequel/extensions/to_dot.rb +6 -10
- data/lib/sequel/model.rb +6 -7
- data/lib/sequel/model/associations.rb +127 -182
- data/lib/sequel/model/base.rb +88 -211
- data/lib/sequel/model/errors.rb +0 -13
- data/lib/sequel/model/plugins.rb +2 -2
- data/lib/sequel/no_core_ext.rb +0 -1
- data/lib/sequel/plugins/after_initialize.rb +11 -17
- data/lib/sequel/plugins/association_autoreloading.rb +1 -47
- data/lib/sequel/plugins/association_dependencies.rb +2 -2
- data/lib/sequel/plugins/auto_validations.rb +2 -8
- data/lib/sequel/plugins/blacklist_security.rb +32 -2
- data/lib/sequel/plugins/caching.rb +1 -1
- data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/composition.rb +10 -8
- data/lib/sequel/plugins/constraint_validations.rb +2 -2
- data/lib/sequel/plugins/dataset_associations.rb +4 -0
- data/lib/sequel/plugins/defaults_setter.rb +8 -6
- data/lib/sequel/plugins/dirty.rb +6 -6
- data/lib/sequel/plugins/force_encoding.rb +13 -8
- data/lib/sequel/plugins/hook_class_methods.rb +1 -7
- data/lib/sequel/plugins/json_serializer.rb +13 -74
- data/lib/sequel/plugins/lazy_attributes.rb +2 -4
- data/lib/sequel/plugins/list.rb +1 -1
- data/lib/sequel/plugins/many_through_many.rb +4 -11
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
- data/lib/sequel/plugins/nested_attributes.rb +1 -1
- data/lib/sequel/plugins/optimistic_locking.rb +3 -5
- data/lib/sequel/plugins/pg_array_associations.rb +453 -0
- data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
- data/lib/sequel/plugins/prepared_statements.rb +1 -1
- data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
- data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
- data/lib/sequel/plugins/rcte_tree.rb +1 -1
- data/lib/sequel/plugins/serialization.rb +5 -4
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +7 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/touch.rb +2 -2
- data/lib/sequel/plugins/tree.rb +1 -1
- data/lib/sequel/plugins/typecast_on_load.rb +19 -4
- data/lib/sequel/plugins/validation_class_methods.rb +0 -30
- data/lib/sequel/plugins/validation_helpers.rb +13 -31
- data/lib/sequel/plugins/xml_serializer.rb +18 -57
- data/lib/sequel/sql.rb +20 -22
- data/lib/sequel/version.rb +2 -2
- data/spec/adapters/db2_spec.rb +14 -23
- data/spec/adapters/firebird_spec.rb +25 -29
- data/spec/adapters/informix_spec.rb +11 -14
- data/spec/adapters/mssql_spec.rb +71 -77
- data/spec/adapters/mysql_spec.rb +165 -172
- data/spec/adapters/oracle_spec.rb +36 -39
- data/spec/adapters/postgres_spec.rb +175 -100
- data/spec/adapters/spec_helper.rb +13 -11
- data/spec/adapters/sqlite_spec.rb +36 -44
- data/spec/core/connection_pool_spec.rb +2 -1
- data/spec/core/database_spec.rb +55 -55
- data/spec/core/dataset_spec.rb +45 -249
- data/spec/core/deprecated_spec.rb +0 -8
- data/spec/core/expression_filters_spec.rb +23 -5
- data/spec/core/object_graph_spec.rb +4 -66
- data/spec/core/schema_spec.rb +35 -12
- data/spec/core/spec_helper.rb +3 -2
- data/spec/core_extensions_spec.rb +17 -19
- data/spec/extensions/arbitrary_servers_spec.rb +2 -3
- data/spec/extensions/association_dependencies_spec.rb +14 -14
- data/spec/extensions/auto_validations_spec.rb +7 -0
- data/spec/extensions/blacklist_security_spec.rb +5 -5
- data/spec/extensions/blank_spec.rb +2 -0
- data/spec/extensions/class_table_inheritance_spec.rb +2 -2
- data/spec/extensions/columns_introspection_spec.rb +2 -29
- data/spec/extensions/composition_spec.rb +10 -17
- data/spec/extensions/core_refinements_spec.rb +5 -1
- data/spec/extensions/dataset_associations_spec.rb +18 -0
- data/spec/extensions/date_arithmetic_spec.rb +2 -2
- data/spec/extensions/defaults_setter_spec.rb +9 -9
- data/spec/extensions/dirty_spec.rb +0 -5
- data/spec/extensions/eval_inspect_spec.rb +2 -0
- data/spec/extensions/force_encoding_spec.rb +2 -18
- data/spec/extensions/hash_aliases_spec.rb +8 -0
- data/spec/extensions/hook_class_methods_spec.rb +39 -58
- data/spec/extensions/inflector_spec.rb +2 -0
- data/spec/extensions/instance_filters_spec.rb +8 -8
- data/spec/extensions/json_serializer_spec.rb +1 -41
- data/spec/extensions/list_spec.rb +1 -1
- data/spec/extensions/many_through_many_spec.rb +106 -109
- data/spec/extensions/migration_spec.rb +2 -0
- data/spec/extensions/named_timezones_spec.rb +1 -0
- data/spec/extensions/pg_array_associations_spec.rb +603 -0
- data/spec/extensions/pg_array_ops_spec.rb +25 -0
- data/spec/extensions/pg_array_spec.rb +9 -1
- data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
- data/spec/extensions/pg_hstore_spec.rb +1 -0
- data/spec/extensions/pg_json_ops_spec.rb +131 -0
- data/spec/extensions/pg_json_spec.rb +10 -4
- data/spec/extensions/pg_range_ops_spec.rb +2 -5
- data/spec/extensions/pg_range_spec.rb +6 -2
- data/spec/extensions/pg_row_ops_spec.rb +2 -0
- data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
- data/spec/extensions/rcte_tree_spec.rb +15 -15
- data/spec/extensions/schema_dumper_spec.rb +0 -1
- data/spec/extensions/schema_spec.rb +9 -9
- data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
- data/spec/extensions/serialization_spec.rb +18 -29
- data/spec/extensions/set_overrides_spec.rb +4 -0
- data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
- data/spec/extensions/single_table_inheritance_spec.rb +4 -4
- data/spec/extensions/spec_helper.rb +8 -9
- data/spec/extensions/sql_expr_spec.rb +2 -0
- data/spec/extensions/string_date_time_spec.rb +2 -0
- data/spec/extensions/string_stripper_spec.rb +2 -0
- data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
- data/spec/extensions/thread_local_timezones_spec.rb +2 -0
- data/spec/extensions/timestamps_spec.rb +1 -1
- data/spec/extensions/to_dot_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +24 -24
- data/spec/extensions/tree_spec.rb +7 -7
- data/spec/extensions/typecast_on_load_spec.rb +8 -1
- data/spec/extensions/update_primary_key_spec.rb +10 -10
- data/spec/extensions/validation_class_methods_spec.rb +10 -39
- data/spec/extensions/validation_helpers_spec.rb +29 -47
- data/spec/extensions/xml_serializer_spec.rb +1 -23
- data/spec/integration/associations_test.rb +231 -40
- data/spec/integration/database_test.rb +1 -1
- data/spec/integration/dataset_test.rb +64 -64
- data/spec/integration/eager_loader_test.rb +28 -28
- data/spec/integration/migrator_test.rb +1 -1
- data/spec/integration/model_test.rb +2 -2
- data/spec/integration/plugin_test.rb +21 -21
- data/spec/integration/prepared_statement_test.rb +7 -7
- data/spec/integration/schema_test.rb +115 -110
- data/spec/integration/spec_helper.rb +17 -27
- data/spec/integration/timezone_test.rb +1 -1
- data/spec/integration/transaction_test.rb +10 -10
- data/spec/integration/type_test.rb +2 -2
- data/spec/model/association_reflection_spec.rb +2 -28
- data/spec/model/associations_spec.rb +239 -188
- data/spec/model/base_spec.rb +27 -68
- data/spec/model/dataset_methods_spec.rb +4 -4
- data/spec/model/eager_loading_spec.rb +160 -172
- data/spec/model/hooks_spec.rb +62 -79
- data/spec/model/model_spec.rb +36 -51
- data/spec/model/plugins_spec.rb +5 -19
- data/spec/model/record_spec.rb +125 -151
- data/spec/model/spec_helper.rb +8 -6
- data/spec/model/validations_spec.rb +4 -17
- data/spec/spec_config.rb +2 -10
- metadata +50 -56
- data/lib/sequel/deprecated_core_extensions.rb +0 -135
- data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
- data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
- data/lib/sequel/plugins/identity_map.rb +0 -260
- data/lib/sequel_core.rb +0 -2
- data/lib/sequel_model.rb +0 -2
- data/spec/extensions/association_autoreloading_spec.rb +0 -102
- data/spec/extensions/identity_map_spec.rb +0 -337
- data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
- data/spec/extensions/pg_statement_cache_spec.rb +0 -208
- data/spec/rcov.opts +0 -8
- data/spec/spec_config.rb.example +0 -10
data/doc/security.rdoc
CHANGED
@@ -18,11 +18,8 @@ could conceivably be abused to do so:
|
|
18
18
|
|
19
19
|
* Sequel::Schema::CreateTableGenerator.add_type_method
|
20
20
|
* Sequel::Dataset.def_mutation_method
|
21
|
-
* Sequel::Dataset.def_append_methods
|
22
21
|
* Sequel::Model::Plugins.def_dataset_methods
|
23
22
|
* Sequel.def_adapter_method (private)
|
24
|
-
* Sequel::Model::InstanceMethods.class_attr_overridable (private)
|
25
|
-
* Sequel::Model::InstanceMethods.class_attr_reader (private)
|
26
23
|
* Sequel::SQL::Expression.to_s_method (private)
|
27
24
|
* Sequel::Plugins::HookClassMethods::ClassMethods#add_hook_type
|
28
25
|
|
@@ -250,31 +247,6 @@ Then you have a denial of service vulnerability. In general, such a vulnerabili
|
|
250
247
|
is unlikely, because you are probably indexing into the returned hash(es) by name,
|
251
248
|
and if an alias was used and you didn't expect it, your application wouldn't work.
|
252
249
|
|
253
|
-
The more insidious cases are those where an explicit alias is not used at all, but
|
254
|
-
an unaliased expression is used and the database chooses which alias to use. For
|
255
|
-
example, on SQLite, the following types of queries are vulnerable to denial of service:
|
256
|
-
|
257
|
-
DB[:table].get(params[:a].to_s)
|
258
|
-
DB[:table].select_map(params[:b].to_s)
|
259
|
-
DB[:table].select_order_map(params[:c].to_s)
|
260
|
-
|
261
|
-
In these cases, the queries will work correctly, but an unused symbol will be created.
|
262
|
-
To protect against the denial of service, use an explicit alias:
|
263
|
-
|
264
|
-
DB[:table].get(Sequel.as(params[:a].to_s, :a))
|
265
|
-
DB[:table].select_map(Sequel.as(params[:b].to_s, :a))
|
266
|
-
DB[:table].select_order_map(Sequel.as(params[:c].to_s, :a))
|
267
|
-
|
268
|
-
While the above code is unlikely to be used in practice, variants that use expressions
|
269
|
-
could be. For example, if you want to select all values in a specific column, with
|
270
|
-
a suffix provided by the user:
|
271
|
-
|
272
|
-
DB[:table].select_map(Sequel.join(:column, params[:suffix].to_s))
|
273
|
-
|
274
|
-
As above, you should use an explicit alias to protect against denial of service:
|
275
|
-
|
276
|
-
DB[:table].select_map(Sequel.join(:column, params[:suffix].to_s).as(:a))
|
277
|
-
|
278
250
|
=== Database Connection Options
|
279
251
|
|
280
252
|
All database connection options are converted to symbols. For a
|
data/doc/testing.rdoc
CHANGED
@@ -136,6 +136,10 @@ The +spec+ rake task (which is also the default rake task) runs Sequel's core an
|
|
136
136
|
|
137
137
|
The +spec_plugin+ rake task runs the specs for the plugins and extensions that ship with Sequel. These also use a mocked database connection, and operate very similarly to the general Sequel core and model specs.
|
138
138
|
|
139
|
+
== rake spec_core_ext
|
140
|
+
|
141
|
+
The +spec_core_ext+ rake task runs the specs for the core_extensions extension. These are run separately from the other extension tests to make sure none of the other extensions require the core_extensions.
|
142
|
+
|
139
143
|
== rake spec_bin
|
140
144
|
|
141
145
|
The +spec_bin+ rake task runs the specs for bin/sequel. These use an SQLite3 database, and require either the sqlite3 (non-JRuby) or jdbc-sqlite3 (JRuby) gem.
|
@@ -154,20 +158,10 @@ Sequel does not create test databases automatically, except for file-based datab
|
|
154
158
|
|
155
159
|
=== Connection Strings
|
156
160
|
|
157
|
-
The
|
158
|
-
|
159
|
-
* SEQUEL_INTEGRATION_URL: integration specs
|
160
|
-
* SEQUEL_FB_SPEC_DB: firebird adapter specs
|
161
|
-
* SEQUEL_MSSQL_SPEC_DB: mssql adapter specs
|
162
|
-
* SEQUEL_PG_SPEC_DB: postgres adapter specs
|
163
|
-
* SEQUEL_SQLITE_SPEC_DB: sqlite adapter specs
|
164
|
-
* SEQUEL_MY_SPEC_DB: mysql adapter specs
|
165
|
-
* SEQUEL_DB2_SPEC_DB: db2 adapter specs
|
161
|
+
The SEQUEL_INTEGRATION_URL environment variable specifies the Database connection URL to use for the adapter and integration specs. Additionally, when running the adapter specs, you can also use the SEQUEL_<i>ADAPTER</i>_URL environment variable (e.g. SEQUEL_POSTGRES_URL for spec_postgres).
|
166
162
|
|
167
163
|
=== Other
|
168
164
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
* SEQUEL_NO_PENDING: Don't mark any specs as pending, try running all specs
|
173
|
-
* SKIPPED_TEST_WARN: Warn when skipping any tests because libraries aren't available
|
165
|
+
SEQUEL_COLUMNS_INTROSPECTION :: Whether to run the specs with the columns_introspection extension loaded by default
|
166
|
+
SEQUEL_NO_PENDING :: Don't mark any specs as pending, try running all specs
|
167
|
+
SKIPPED_TEST_WARN :: Warn when skipping any tests because libraries aren't available
|
data/lib/sequel/adapters/ado.rb
CHANGED
@@ -45,12 +45,12 @@ module Sequel
|
|
45
45
|
end
|
46
46
|
|
47
47
|
# Just execute so it doesn't attempt to return the number of rows modified.
|
48
|
-
def execute_ddl(sql, opts=
|
48
|
+
def execute_ddl(sql, opts=OPTS)
|
49
49
|
execute(sql, opts)
|
50
50
|
end
|
51
51
|
|
52
52
|
# Just execute so it doesn't attempt to return the number of rows modified.
|
53
|
-
def execute_insert(sql, opts=
|
53
|
+
def execute_insert(sql, opts=OPTS)
|
54
54
|
execute(sql, opts)
|
55
55
|
end
|
56
56
|
|
@@ -58,7 +58,7 @@ module Sequel
|
|
58
58
|
# unless is a provider is in use (since some providers don't seem to
|
59
59
|
# return the number of affected rows, but the default provider appears
|
60
60
|
# to).
|
61
|
-
def execute_dui(sql, opts=
|
61
|
+
def execute_dui(sql, opts=OPTS)
|
62
62
|
return super if opts[:provider]
|
63
63
|
synchronize(opts[:server]) do |conn|
|
64
64
|
begin
|
@@ -70,7 +70,7 @@ module Sequel
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
def execute(sql, opts=
|
73
|
+
def execute(sql, opts=OPTS)
|
74
74
|
synchronize(opts[:server]) do |conn|
|
75
75
|
begin
|
76
76
|
r = log_yield(sql){conn.Execute(sql)}
|
@@ -81,10 +81,6 @@ module Sequel
|
|
81
81
|
end
|
82
82
|
nil
|
83
83
|
end
|
84
|
-
def do(*a, &block)
|
85
|
-
Sequel::Deprecation.deprecate('Database#do', 'Please use Database#execute')
|
86
|
-
execute(*a, &block)
|
87
|
-
end
|
88
84
|
|
89
85
|
private
|
90
86
|
|
@@ -110,11 +106,11 @@ module Sequel
|
|
110
106
|
# The ADO adapter's default provider doesn't support transactions, since it
|
111
107
|
# creates a new native connection for each query. So Sequel only attempts
|
112
108
|
# to use transactions if an explicit :provider is given.
|
113
|
-
def begin_transaction(conn, opts=
|
109
|
+
def begin_transaction(conn, opts=OPTS)
|
114
110
|
super if @opts[:provider]
|
115
111
|
end
|
116
112
|
|
117
|
-
def commit_transaction(conn, opts=
|
113
|
+
def commit_transaction(conn, opts=OPTS)
|
118
114
|
super if @opts[:provider]
|
119
115
|
end
|
120
116
|
|
@@ -126,7 +122,7 @@ module Sequel
|
|
126
122
|
super || (e.is_a?(::WIN32OLERuntimeError) && e.message =~ DISCONNECT_ERROR_RE)
|
127
123
|
end
|
128
124
|
|
129
|
-
def rollback_transaction(conn, opts=
|
125
|
+
def rollback_transaction(conn, opts=OPTS)
|
130
126
|
super if @opts[:provider]
|
131
127
|
end
|
132
128
|
end
|
@@ -106,7 +106,7 @@ module Sequel
|
|
106
106
|
super
|
107
107
|
end
|
108
108
|
|
109
|
-
def execute_insert(sql, opts=
|
109
|
+
def execute_insert(sql, opts=OPTS)
|
110
110
|
synchronize(opts[:server]) do |conn|
|
111
111
|
begin
|
112
112
|
r = log_yield(sql){conn.Execute(sql)}
|
@@ -119,18 +119,18 @@ module Sequel
|
|
119
119
|
nil
|
120
120
|
end
|
121
121
|
|
122
|
-
def tables(opts=
|
122
|
+
def tables(opts=OPTS)
|
123
123
|
m = output_identifier_meth
|
124
124
|
ado_schema_tables.map {|tbl| m.call(tbl['TABLE_NAME'])}
|
125
125
|
end
|
126
126
|
|
127
|
-
def views(opts=
|
127
|
+
def views(opts=OPTS)
|
128
128
|
m = output_identifier_meth
|
129
129
|
ado_schema_views.map {|tbl| m.call(tbl['TABLE_NAME'])}
|
130
130
|
end
|
131
131
|
|
132
132
|
# Note OpenSchema returns compound indexes as multiple rows
|
133
|
-
def indexes(table_name,opts=
|
133
|
+
def indexes(table_name,opts=OPTS)
|
134
134
|
m = output_identifier_meth
|
135
135
|
idxs = ado_schema_indexes(table_name).inject({}) do |memo, idx|
|
136
136
|
unless idx["PRIMARY_KEY"]
|
@@ -145,7 +145,7 @@ module Sequel
|
|
145
145
|
end
|
146
146
|
|
147
147
|
# Note OpenSchema returns compound foreign key relationships as multiple rows
|
148
|
-
def foreign_key_list(table, opts=
|
148
|
+
def foreign_key_list(table, opts=OPTS)
|
149
149
|
m = output_identifier_meth
|
150
150
|
fks = ado_schema_foreign_keys(table).inject({}) do |memo, fk|
|
151
151
|
name = m.call(fk['FK_NAME'])
|
@@ -200,15 +200,15 @@ module Sequel
|
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
203
|
-
def begin_transaction(conn, opts=
|
203
|
+
def begin_transaction(conn, opts=OPTS)
|
204
204
|
log_yield('Transaction.begin'){conn.BeginTrans}
|
205
205
|
end
|
206
206
|
|
207
|
-
def commit_transaction(conn, opts=
|
207
|
+
def commit_transaction(conn, opts=OPTS)
|
208
208
|
log_yield('Transaction.commit'){conn.CommitTrans}
|
209
209
|
end
|
210
210
|
|
211
|
-
def rollback_transaction(conn, opts=
|
211
|
+
def rollback_transaction(conn, opts=OPTS)
|
212
212
|
log_yield('Transaction.rollback'){conn.RollbackTrans}
|
213
213
|
end
|
214
214
|
|
@@ -15,7 +15,7 @@ module Sequel
|
|
15
15
|
# Issue a separate query to get the rows modified. ADO appears to
|
16
16
|
# use pass by reference with an integer variable, which is obviously
|
17
17
|
# not supported directly in ruby, and I'm not aware of a workaround.
|
18
|
-
def execute_dui(sql, opts=
|
18
|
+
def execute_dui(sql, opts=OPTS)
|
19
19
|
return super unless @opts[:provider]
|
20
20
|
synchronize(opts[:server]) do |conn|
|
21
21
|
begin
|
@@ -33,15 +33,15 @@ module Sequel
|
|
33
33
|
# The ADO adapter's default provider doesn't support transactions, since it
|
34
34
|
# creates a new native connection for each query. So Sequel only attempts
|
35
35
|
# to use transactions if an explicit :provider is given.
|
36
|
-
def begin_transaction(conn, opts=
|
36
|
+
def begin_transaction(conn, opts=OPTS)
|
37
37
|
super if @opts[:provider]
|
38
38
|
end
|
39
39
|
|
40
|
-
def commit_transaction(conn, opts=
|
40
|
+
def commit_transaction(conn, opts=OPTS)
|
41
41
|
super if @opts[:provider]
|
42
42
|
end
|
43
43
|
|
44
|
-
def rollback_transaction(conn, opts=
|
44
|
+
def rollback_transaction(conn, opts=OPTS)
|
45
45
|
super if @opts[:provider]
|
46
46
|
end
|
47
47
|
end
|
@@ -89,23 +89,23 @@ module Sequel
|
|
89
89
|
end
|
90
90
|
|
91
91
|
# Run the given SQL with the given arguments. Returns nil.
|
92
|
-
def execute_ddl(sql, opts=
|
92
|
+
def execute_ddl(sql, opts=OPTS)
|
93
93
|
_execute(sql, opts){|conn| log_yield(sql){conn.execute_batch(sql)}}
|
94
94
|
nil
|
95
95
|
end
|
96
96
|
|
97
97
|
# Run the given SQL with the given arguments and return the number of changed rows.
|
98
|
-
def execute_dui(sql, opts=
|
98
|
+
def execute_dui(sql, opts=OPTS)
|
99
99
|
_execute(sql, opts){|conn| log_yield(sql){conn.execute_batch(sql)}; conn.row_changes}
|
100
100
|
end
|
101
101
|
|
102
102
|
# Run the given SQL with the given arguments and return the last inserted row id.
|
103
|
-
def execute_insert(sql, opts=
|
103
|
+
def execute_insert(sql, opts=OPTS)
|
104
104
|
_execute(sql, opts){|conn| log_yield(sql){conn.execute_batch(sql)}; conn.last_insert_rowid}
|
105
105
|
end
|
106
106
|
|
107
107
|
# Run the given SQL with the given arguments and yield each row.
|
108
|
-
def execute(sql, opts=
|
108
|
+
def execute(sql, opts=OPTS)
|
109
109
|
_execute(sql, opts) do |conn|
|
110
110
|
begin
|
111
111
|
yield(stmt = log_yield(sql){conn.prepare(sql)})
|
@@ -116,7 +116,7 @@ module Sequel
|
|
116
116
|
end
|
117
117
|
|
118
118
|
# Run the given SQL with the given arguments and return the first value of the first row.
|
119
|
-
def single_value(sql, opts=
|
119
|
+
def single_value(sql, opts=OPTS)
|
120
120
|
_execute(sql, opts){|conn| log_yield(sql){conn.first_value_from(sql)}}
|
121
121
|
end
|
122
122
|
|
@@ -172,7 +172,7 @@ module Sequel
|
|
172
172
|
|
173
173
|
# Quote the string using the adapter instance method.
|
174
174
|
def literal_string_append(sql, v)
|
175
|
-
db.synchronize{|c| sql << c.quote(v)}
|
175
|
+
db.synchronize(@opts[:server]){|c| sql << c.quote(v)}
|
176
176
|
end
|
177
177
|
end
|
178
178
|
end
|
@@ -34,7 +34,7 @@ module Sequel
|
|
34
34
|
@server_version ||= synchronize{|c| c.server_version}
|
35
35
|
end
|
36
36
|
|
37
|
-
def execute(sql, opts=
|
37
|
+
def execute(sql, opts=OPTS)
|
38
38
|
synchronize(opts[:server]) do |conn|
|
39
39
|
r = log_yield(sql) do
|
40
40
|
begin
|
@@ -75,25 +75,25 @@ module Sequel
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
def execute_ddl(sql, opts=
|
78
|
+
def execute_ddl(sql, opts=OPTS)
|
79
79
|
execute(sql, opts.merge(:type=>:ddl))
|
80
80
|
end
|
81
81
|
|
82
|
-
def execute_dui(sql, opts=
|
82
|
+
def execute_dui(sql, opts=OPTS)
|
83
83
|
execute(sql, opts.merge(:type=>:dui))
|
84
84
|
end
|
85
85
|
|
86
|
-
def execute_insert(sql, opts=
|
86
|
+
def execute_insert(sql, opts=OPTS)
|
87
87
|
execute(sql, opts.merge(:type=>:insert))
|
88
88
|
end
|
89
89
|
|
90
90
|
private
|
91
91
|
|
92
|
-
def begin_transaction(conn, opts=
|
92
|
+
def begin_transaction(conn, opts=OPTS)
|
93
93
|
log_yield(TRANSACTION_BEGIN){conn.auto_commit = false}
|
94
94
|
end
|
95
95
|
|
96
|
-
def commit_transaction(conn, opts=
|
96
|
+
def commit_transaction(conn, opts=OPTS)
|
97
97
|
log_yield(TRANSACTION_COMMIT){conn.commit}
|
98
98
|
end
|
99
99
|
|
@@ -109,7 +109,7 @@ module Sequel
|
|
109
109
|
|
110
110
|
# This doesn't actually work, as the cubrid ruby driver
|
111
111
|
# does not implement transactions correctly.
|
112
|
-
def rollback_transaction(conn, opts=
|
112
|
+
def rollback_transaction(conn, opts=OPTS)
|
113
113
|
log_yield(TRANSACTION_ROLLBACK){conn.rollback}
|
114
114
|
end
|
115
115
|
end
|
data/lib/sequel/adapters/db2.rb
CHANGED
@@ -56,15 +56,11 @@ module Sequel
|
|
56
56
|
DB2CLI.SQLFreeHandle(DB2CLI::SQL_HANDLE_DBC, conn)
|
57
57
|
end
|
58
58
|
|
59
|
-
def execute(sql, opts=
|
59
|
+
def execute(sql, opts=OPTS, &block)
|
60
60
|
synchronize(opts[:server]){|conn| log_connection_execute(conn, sql, &block)}
|
61
61
|
end
|
62
|
-
def do(*a, &block)
|
63
|
-
Sequel::Deprecation.deprecate('Database#do', 'Please use Database#execute')
|
64
|
-
execute(*a, &block)
|
65
|
-
end
|
66
62
|
|
67
|
-
def execute_insert(sql, opts=
|
63
|
+
def execute_insert(sql, opts=OPTS)
|
68
64
|
synchronize(opts[:server]) do |conn|
|
69
65
|
log_connection_execute(conn, sql)
|
70
66
|
sql = "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1"
|
@@ -122,7 +118,7 @@ module Sequel
|
|
122
118
|
[DB2Error]
|
123
119
|
end
|
124
120
|
|
125
|
-
def begin_transaction(conn, opts=
|
121
|
+
def begin_transaction(conn, opts=OPTS)
|
126
122
|
log_yield(TRANSACTION_BEGIN){DB2CLI.SQLSetConnectAttr(conn, DB2CLI::SQL_ATTR_AUTOCOMMIT, DB2CLI::SQL_AUTOCOMMIT_OFF)}
|
127
123
|
set_transaction_isolation(conn, opts)
|
128
124
|
end
|
@@ -133,11 +129,11 @@ module Sequel
|
|
133
129
|
super
|
134
130
|
end
|
135
131
|
|
136
|
-
def rollback_transaction(conn, opts=
|
132
|
+
def rollback_transaction(conn, opts=OPTS)
|
137
133
|
log_yield(TRANSACTION_ROLLBACK){DB2CLI.SQLEndTran(DB2CLI::SQL_HANDLE_DBC, conn, DB2CLI::SQL_ROLLBACK)}
|
138
134
|
end
|
139
135
|
|
140
|
-
def commit_transaction(conn, opts=
|
136
|
+
def commit_transaction(conn, opts=OPTS)
|
141
137
|
log_yield(TRANSACTION_COMMIT){DB2CLI.SQLEndTran(DB2CLI::SQL_HANDLE_DBC, conn, DB2CLI::SQL_COMMIT)}
|
142
138
|
end
|
143
139
|
|
data/lib/sequel/adapters/dbi.rb
CHANGED
@@ -53,7 +53,7 @@ module Sequel
|
|
53
53
|
c.disconnect
|
54
54
|
end
|
55
55
|
|
56
|
-
def execute(sql, opts=
|
56
|
+
def execute(sql, opts=OPTS)
|
57
57
|
synchronize(opts[:server]) do |conn|
|
58
58
|
r = log_yield(sql){conn.execute(sql)}
|
59
59
|
yield(r) if block_given?
|
@@ -61,13 +61,9 @@ module Sequel
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def execute_dui(sql, opts=
|
64
|
+
def execute_dui(sql, opts=OPTS)
|
65
65
|
synchronize(opts[:server]){|conn| log_yield(sql){conn.do(sql)}}
|
66
66
|
end
|
67
|
-
def do(*a, &block)
|
68
|
-
Sequel::Deprecation.deprecate('Database#do', 'Please use Database#execute_dui')
|
69
|
-
execute_dui(*a, &block)
|
70
|
-
end
|
71
67
|
|
72
68
|
private
|
73
69
|
|
data/lib/sequel/adapters/do.rb
CHANGED
@@ -58,7 +58,7 @@ module Sequel
|
|
58
58
|
# a SELECT statement is being used (or something else that returns rows).
|
59
59
|
# Otherwise, the return value is the insert id if opts[:type] is :insert,
|
60
60
|
# or the number of affected rows, otherwise.
|
61
|
-
def execute(sql, opts=
|
61
|
+
def execute(sql, opts=OPTS)
|
62
62
|
synchronize(opts[:server]) do |conn|
|
63
63
|
begin
|
64
64
|
command = conn.create_command(sql)
|
@@ -82,13 +82,13 @@ module Sequel
|
|
82
82
|
|
83
83
|
# Execute the SQL on the this database, returning the number of affected
|
84
84
|
# rows.
|
85
|
-
def execute_dui(sql, opts=
|
85
|
+
def execute_dui(sql, opts=OPTS)
|
86
86
|
execute(sql, opts)
|
87
87
|
end
|
88
88
|
|
89
89
|
# Execute the SQL on this database, returning the primary key of the
|
90
90
|
# table being inserted to.
|
91
|
-
def execute_insert(sql, opts=
|
91
|
+
def execute_insert(sql, opts=OPTS)
|
92
92
|
execute(sql, opts.merge(:type=>:insert))
|
93
93
|
end
|
94
94
|
|
@@ -100,7 +100,7 @@ module Sequel
|
|
100
100
|
|
101
101
|
# Return the DataObjects URI for the Sequel URI, removing the do:
|
102
102
|
# prefix.
|
103
|
-
def uri(opts=
|
103
|
+
def uri(opts=OPTS)
|
104
104
|
opts = @opts.merge(opts)
|
105
105
|
(opts[:uri] || opts[:url]).sub(/\Ado:/, '')
|
106
106
|
end
|
@@ -29,7 +29,7 @@ module Sequel
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def execute(sql, opts=
|
32
|
+
def execute(sql, opts=OPTS)
|
33
33
|
begin
|
34
34
|
synchronize(opts[:server]) do |conn|
|
35
35
|
if conn.transaction_started && !_trans(conn)
|
@@ -52,7 +52,7 @@ module Sequel
|
|
52
52
|
@primary_keys = {}
|
53
53
|
end
|
54
54
|
|
55
|
-
def begin_transaction(conn, opts=
|
55
|
+
def begin_transaction(conn, opts=OPTS)
|
56
56
|
log_yield(TRANSACTION_BEGIN) do
|
57
57
|
begin
|
58
58
|
conn.transaction
|
@@ -63,7 +63,7 @@ module Sequel
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
def commit_transaction(conn, opts=
|
66
|
+
def commit_transaction(conn, opts=OPTS)
|
67
67
|
log_yield(TRANSACTION_COMMIT){conn.commit}
|
68
68
|
end
|
69
69
|
|
@@ -71,7 +71,7 @@ module Sequel
|
|
71
71
|
[Fb::Error]
|
72
72
|
end
|
73
73
|
|
74
|
-
def rollback_transaction(conn, opts=
|
74
|
+
def rollback_transaction(conn, opts=OPTS)
|
75
75
|
log_yield(TRANSACTION_ROLLBACK){conn.rollback}
|
76
76
|
end
|
77
77
|
end
|