sequel 3.47.0 → 3.48.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +230 -0
- data/README.rdoc +31 -40
- data/Rakefile +1 -14
- data/doc/active_record.rdoc +29 -29
- data/doc/association_basics.rdoc +4 -13
- data/doc/cheat_sheet.rdoc +8 -6
- data/doc/code_order.rdoc +89 -0
- data/doc/core_extensions.rdoc +3 -3
- data/doc/dataset_basics.rdoc +7 -8
- data/doc/dataset_filtering.rdoc +7 -2
- data/doc/mass_assignment.rdoc +2 -3
- data/doc/migration.rdoc +8 -8
- data/doc/model_hooks.rdoc +11 -7
- data/doc/object_model.rdoc +2 -2
- data/doc/opening_databases.rdoc +5 -14
- data/doc/prepared_statements.rdoc +5 -9
- data/doc/querying.rdoc +23 -28
- data/doc/reflection.rdoc +11 -0
- data/doc/release_notes/3.48.0.txt +477 -0
- data/doc/schema_modification.rdoc +12 -5
- data/doc/security.rdoc +2 -2
- data/doc/sharding.rdoc +1 -2
- data/doc/sql.rdoc +10 -13
- data/doc/testing.rdoc +8 -4
- data/doc/transactions.rdoc +2 -2
- data/doc/validations.rdoc +40 -17
- data/doc/virtual_rows.rdoc +2 -2
- data/lib/sequel/adapters/ado.rb +25 -20
- data/lib/sequel/adapters/ado/access.rb +1 -0
- data/lib/sequel/adapters/ado/mssql.rb +1 -0
- data/lib/sequel/adapters/db2.rb +9 -7
- data/lib/sequel/adapters/dbi.rb +16 -16
- data/lib/sequel/adapters/do.rb +17 -18
- data/lib/sequel/adapters/do/mysql.rb +1 -0
- data/lib/sequel/adapters/do/postgres.rb +2 -0
- data/lib/sequel/adapters/do/sqlite.rb +1 -0
- data/lib/sequel/adapters/firebird.rb +5 -7
- data/lib/sequel/adapters/ibmdb.rb +23 -20
- data/lib/sequel/adapters/informix.rb +8 -2
- data/lib/sequel/adapters/jdbc.rb +39 -35
- data/lib/sequel/adapters/jdbc/as400.rb +1 -0
- data/lib/sequel/adapters/jdbc/cubrid.rb +1 -0
- data/lib/sequel/adapters/jdbc/db2.rb +1 -0
- data/lib/sequel/adapters/jdbc/derby.rb +1 -0
- data/lib/sequel/adapters/jdbc/firebird.rb +1 -0
- data/lib/sequel/adapters/jdbc/h2.rb +1 -0
- data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -0
- data/lib/sequel/adapters/jdbc/informix.rb +1 -0
- data/lib/sequel/adapters/jdbc/jtds.rb +1 -0
- data/lib/sequel/adapters/jdbc/mssql.rb +1 -0
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -0
- data/lib/sequel/adapters/jdbc/oracle.rb +1 -0
- data/lib/sequel/adapters/jdbc/postgresql.rb +2 -0
- data/lib/sequel/adapters/jdbc/progress.rb +1 -0
- data/lib/sequel/adapters/jdbc/sqlite.rb +1 -0
- data/lib/sequel/adapters/jdbc/sqlserver.rb +1 -0
- data/lib/sequel/adapters/mock.rb +30 -31
- data/lib/sequel/adapters/mysql.rb +6 -7
- data/lib/sequel/adapters/mysql2.rb +5 -6
- data/lib/sequel/adapters/odbc.rb +22 -20
- data/lib/sequel/adapters/odbc/mssql.rb +1 -0
- data/lib/sequel/adapters/openbase.rb +4 -1
- data/lib/sequel/adapters/oracle.rb +10 -8
- data/lib/sequel/adapters/postgres.rb +12 -10
- data/lib/sequel/adapters/shared/access.rb +6 -0
- data/lib/sequel/adapters/shared/cubrid.rb +2 -0
- data/lib/sequel/adapters/shared/db2.rb +2 -0
- data/lib/sequel/adapters/shared/firebird.rb +2 -0
- data/lib/sequel/adapters/shared/informix.rb +2 -0
- data/lib/sequel/adapters/shared/mssql.rb +14 -8
- data/lib/sequel/adapters/shared/mysql.rb +6 -0
- data/lib/sequel/adapters/shared/oracle.rb +2 -0
- data/lib/sequel/adapters/shared/postgres.rb +14 -4
- data/lib/sequel/adapters/shared/progress.rb +1 -0
- data/lib/sequel/adapters/shared/sqlite.rb +4 -3
- data/lib/sequel/adapters/sqlite.rb +6 -7
- data/lib/sequel/adapters/swift.rb +20 -21
- data/lib/sequel/adapters/swift/mysql.rb +1 -0
- data/lib/sequel/adapters/swift/postgres.rb +2 -0
- data/lib/sequel/adapters/swift/sqlite.rb +1 -0
- data/lib/sequel/adapters/tinytds.rb +5 -6
- data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +68 -0
- data/lib/sequel/connection_pool.rb +1 -1
- data/lib/sequel/core.rb +57 -50
- data/lib/sequel/database/connecting.rb +9 -10
- data/lib/sequel/database/dataset.rb +11 -6
- data/lib/sequel/database/dataset_defaults.rb +61 -69
- data/lib/sequel/database/features.rb +21 -0
- data/lib/sequel/database/misc.rb +23 -3
- data/lib/sequel/database/query.rb +13 -7
- data/lib/sequel/database/schema_methods.rb +6 -6
- data/lib/sequel/database/transactions.rb +1 -0
- data/lib/sequel/dataset/actions.rb +51 -38
- data/lib/sequel/dataset/features.rb +1 -0
- data/lib/sequel/dataset/graph.rb +9 -33
- data/lib/sequel/dataset/misc.rb +30 -5
- data/lib/sequel/dataset/mutation.rb +2 -3
- data/lib/sequel/dataset/prepared_statements.rb +1 -1
- data/lib/sequel/dataset/query.rb +91 -27
- data/lib/sequel/dataset/sql.rb +40 -6
- data/lib/sequel/deprecated.rb +74 -0
- data/lib/sequel/deprecated_core_extensions.rb +135 -0
- data/lib/sequel/extensions/columns_introspection.rb +1 -5
- data/lib/sequel/extensions/core_extensions.rb +10 -3
- data/lib/sequel/extensions/date_arithmetic.rb +1 -0
- data/lib/sequel/extensions/empty_array_ignore_nulls.rb +33 -0
- data/lib/sequel/extensions/filter_having.rb +58 -0
- data/lib/sequel/extensions/graph_each.rb +63 -0
- data/lib/sequel/extensions/hash_aliases.rb +44 -0
- data/lib/sequel/extensions/looser_typecasting.rb +14 -3
- data/lib/sequel/extensions/migration.rb +2 -3
- data/lib/sequel/extensions/named_timezones.rb +14 -1
- data/lib/sequel/extensions/null_dataset.rb +7 -1
- data/lib/sequel/extensions/pagination.rb +15 -5
- data/lib/sequel/extensions/pg_auto_parameterize.rb +1 -0
- data/lib/sequel/extensions/pg_hstore_ops.rb +48 -14
- data/lib/sequel/extensions/pg_json.rb +7 -7
- data/lib/sequel/extensions/pg_range_ops.rb +8 -2
- data/lib/sequel/extensions/pg_statement_cache.rb +1 -0
- data/lib/sequel/extensions/pretty_table.rb +13 -4
- data/lib/sequel/extensions/query.rb +21 -4
- data/lib/sequel/extensions/ruby18_symbol_extensions.rb +22 -0
- data/lib/sequel/extensions/schema_caching.rb +10 -7
- data/lib/sequel/extensions/schema_dumper.rb +35 -48
- data/lib/sequel/extensions/select_remove.rb +13 -4
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +117 -0
- data/lib/sequel/extensions/set_overrides.rb +43 -0
- data/lib/sequel/extensions/to_dot.rb +6 -0
- data/lib/sequel/model.rb +12 -6
- data/lib/sequel/model/associations.rb +80 -38
- data/lib/sequel/model/base.rb +137 -52
- data/lib/sequel/model/errors.rb +7 -2
- data/lib/sequel/plugins/active_model.rb +13 -0
- data/lib/sequel/plugins/after_initialize.rb +43 -0
- data/lib/sequel/plugins/association_proxies.rb +63 -7
- data/lib/sequel/plugins/auto_validations.rb +56 -16
- data/lib/sequel/plugins/blacklist_security.rb +63 -0
- data/lib/sequel/plugins/class_table_inheritance.rb +9 -0
- data/lib/sequel/plugins/constraint_validations.rb +50 -8
- data/lib/sequel/plugins/dataset_associations.rb +2 -0
- data/lib/sequel/plugins/hook_class_methods.rb +7 -1
- data/lib/sequel/plugins/identity_map.rb +4 -0
- data/lib/sequel/plugins/json_serializer.rb +32 -13
- data/lib/sequel/plugins/optimistic_locking.rb +1 -1
- data/lib/sequel/plugins/rcte_tree.rb +4 -4
- data/lib/sequel/plugins/scissors.rb +33 -0
- data/lib/sequel/plugins/serialization.rb +1 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +6 -0
- data/lib/sequel/plugins/tree.rb +5 -1
- data/lib/sequel/plugins/validation_class_methods.rb +2 -1
- data/lib/sequel/plugins/validation_helpers.rb +15 -11
- data/lib/sequel/plugins/xml_serializer.rb +12 -3
- data/lib/sequel/sql.rb +12 -2
- data/lib/sequel/timezones.rb +1 -1
- data/lib/sequel/version.rb +1 -1
- data/lib/sequel_core.rb +1 -0
- data/lib/sequel_model.rb +1 -0
- data/spec/adapters/mssql_spec.rb +24 -57
- data/spec/adapters/postgres_spec.rb +27 -55
- data/spec/adapters/spec_helper.rb +1 -1
- data/spec/adapters/sqlite_spec.rb +1 -1
- data/spec/bin_spec.rb +251 -0
- data/spec/core/database_spec.rb +46 -32
- data/spec/core/dataset_spec.rb +233 -181
- data/spec/core/deprecated_spec.rb +78 -0
- data/spec/core/expression_filters_spec.rb +3 -4
- data/spec/core/mock_adapter_spec.rb +9 -9
- data/spec/core/object_graph_spec.rb +9 -19
- data/spec/core/schema_spec.rb +3 -1
- data/spec/core/spec_helper.rb +19 -0
- data/spec/core_extensions_spec.rb +80 -30
- data/spec/extensions/after_initialize_spec.rb +24 -0
- data/spec/extensions/association_proxies_spec.rb +37 -1
- data/spec/extensions/auto_validations_spec.rb +20 -4
- data/spec/extensions/blacklist_security_spec.rb +87 -0
- data/spec/extensions/boolean_readers_spec.rb +2 -1
- data/spec/extensions/class_table_inheritance_spec.rb +7 -0
- data/spec/extensions/columns_introspection_spec.rb +3 -3
- data/spec/extensions/constraint_validations_plugin_spec.rb +83 -5
- data/spec/extensions/core_refinements_spec.rb +7 -7
- data/spec/extensions/dataset_associations_spec.rb +2 -2
- data/spec/extensions/date_arithmetic_spec.rb +1 -1
- data/spec/extensions/defaults_setter_spec.rb +2 -1
- data/spec/extensions/empty_array_ignore_nulls_spec.rb +24 -0
- data/spec/extensions/filter_having_spec.rb +40 -0
- data/spec/extensions/graph_each_spec.rb +109 -0
- data/spec/extensions/hash_aliases_spec.rb +16 -0
- data/spec/extensions/hook_class_methods_spec.rb +2 -2
- data/spec/extensions/identity_map_spec.rb +3 -3
- data/spec/extensions/json_serializer_spec.rb +19 -19
- data/spec/extensions/lazy_attributes_spec.rb +1 -0
- data/spec/extensions/list_spec.rb +13 -13
- data/spec/extensions/looser_typecasting_spec.rb +10 -3
- data/spec/extensions/many_through_many_spec.rb +1 -1
- data/spec/extensions/migration_spec.rb +7 -7
- data/spec/extensions/named_timezones_spec.rb +6 -0
- data/spec/extensions/nested_attributes_spec.rb +2 -2
- data/spec/extensions/null_dataset_spec.rb +1 -1
- data/spec/extensions/pagination_spec.rb +2 -2
- data/spec/extensions/pg_hstore_ops_spec.rb +75 -0
- data/spec/extensions/pg_range_ops_spec.rb +4 -2
- data/spec/extensions/pg_row_plugin_spec.rb +1 -1
- data/spec/extensions/pretty_table_spec.rb +1 -1
- data/spec/extensions/query_literals_spec.rb +1 -1
- data/spec/extensions/query_spec.rb +3 -3
- data/spec/extensions/schema_caching_spec.rb +3 -3
- data/spec/extensions/schema_dumper_spec.rb +27 -2
- data/spec/extensions/schema_spec.rb +2 -2
- data/spec/extensions/scissors_spec.rb +26 -0
- data/spec/extensions/select_remove_spec.rb +1 -1
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +102 -0
- data/spec/extensions/set_overrides_spec.rb +45 -0
- data/spec/extensions/single_table_inheritance_spec.rb +10 -0
- data/spec/extensions/spec_helper.rb +24 -1
- data/spec/extensions/static_cache_spec.rb +1 -1
- data/spec/extensions/string_stripper_spec.rb +2 -1
- data/spec/extensions/to_dot_spec.rb +1 -1
- data/spec/extensions/typecast_on_load_spec.rb +3 -2
- data/spec/extensions/update_primary_key_spec.rb +2 -2
- data/spec/extensions/validation_class_methods_spec.rb +19 -19
- data/spec/extensions/validation_helpers_spec.rb +30 -21
- data/spec/extensions/xml_serializer_spec.rb +5 -5
- data/spec/integration/associations_test.rb +10 -30
- data/spec/integration/dataset_test.rb +20 -24
- data/spec/integration/eager_loader_test.rb +5 -5
- data/spec/integration/model_test.rb +3 -3
- data/spec/integration/plugin_test.rb +7 -39
- data/spec/integration/schema_test.rb +4 -38
- data/spec/integration/spec_helper.rb +2 -1
- data/spec/model/association_reflection_spec.rb +70 -5
- data/spec/model/associations_spec.rb +11 -11
- data/spec/model/base_spec.rb +25 -8
- data/spec/model/class_dataset_methods_spec.rb +143 -0
- data/spec/model/dataset_methods_spec.rb +1 -1
- data/spec/model/eager_loading_spec.rb +25 -25
- data/spec/model/hooks_spec.rb +1 -1
- data/spec/model/model_spec.rb +22 -7
- data/spec/model/plugins_spec.rb +1 -6
- data/spec/model/record_spec.rb +37 -29
- data/spec/model/spec_helper.rb +23 -1
- data/spec/model/validations_spec.rb +15 -17
- metadata +32 -3
@@ -4,6 +4,8 @@ module Sequel
|
|
4
4
|
Dataset::NON_SQL_OPTIONS << :disable_insert_output
|
5
5
|
module MSSQL
|
6
6
|
module DatabaseMethods
|
7
|
+
extend Sequel::Database::ResetIdentifierMangling
|
8
|
+
|
7
9
|
AUTO_INCREMENT = 'IDENTITY(1,1)'.freeze
|
8
10
|
SERVER_VERSION_RE = /^(\d+)\.(\d+)\.(\d+)/.freeze
|
9
11
|
SERVER_VERSION_SQL = "SELECT CAST(SERVERPROPERTY('ProductVersion') AS varchar)".freeze
|
@@ -21,7 +23,12 @@ module Sequel
|
|
21
23
|
# strings. True by default for compatibility, can be set to false for a possible
|
22
24
|
# performance increase. This sets the default for all datasets created from this
|
23
25
|
# Database object.
|
24
|
-
|
26
|
+
attr_reader :mssql_unicode_strings
|
27
|
+
|
28
|
+
def mssql_unicode_strings=(v)
|
29
|
+
@mssql_unicode_strings = v
|
30
|
+
reset_default_dataset
|
31
|
+
end
|
25
32
|
|
26
33
|
# The types to check for 0 scale to transform :decimal types
|
27
34
|
# to :integer.
|
@@ -281,7 +288,7 @@ module Sequel
|
|
281
288
|
m = output_identifier_meth
|
282
289
|
metadata_dataset.from(:information_schema__tables___t).
|
283
290
|
select(:table_name).
|
284
|
-
filter(:table_type=>type, :table_schema=>(opts[:schema]||
|
291
|
+
filter(:table_type=>type, :table_schema=>(opts[:schema]||_default_schema||'dbo').to_s).
|
285
292
|
map{|x| m.call(x[:table_name])}
|
286
293
|
end
|
287
294
|
|
@@ -343,7 +350,7 @@ module Sequel
|
|
343
350
|
:table_schema => :table_schema, :table_name => :table_name).
|
344
351
|
select(:column_name___column, :data_type___db_type, :character_maximum_length___max_chars, :column_default___default, :is_nullable___allow_null, :numeric_precision___column_size, :numeric_scale___scale).
|
345
352
|
filter(:c__table_name=>tn)
|
346
|
-
if schema = opts[:schema] ||
|
353
|
+
if schema = opts[:schema] || _default_schema
|
347
354
|
ds.filter!(:c__table_schema=>schema)
|
348
355
|
end
|
349
356
|
ds.map do |row|
|
@@ -441,12 +448,11 @@ module Sequel
|
|
441
448
|
Sequel::Dataset.def_mutation_method(:disable_insert_output, :output, :module=>self)
|
442
449
|
|
443
450
|
# Allow overriding of the mssql_unicode_strings option at the dataset level.
|
444
|
-
|
451
|
+
attr_writer :mssql_unicode_strings
|
445
452
|
|
446
|
-
#
|
447
|
-
def
|
448
|
-
|
449
|
-
@mssql_unicode_strings = db.mssql_unicode_strings
|
453
|
+
# Use the database's mssql_unicode_strings setting if the dataset hasn't overridden it.
|
454
|
+
def mssql_unicode_strings
|
455
|
+
defined?(@mssql_unicode_strings) ? @mssql_unicode_strings : (@mssql_unicode_strings = db.mssql_unicode_strings)
|
450
456
|
end
|
451
457
|
|
452
458
|
# MSSQL uses + for string concatenation, and LIKE is case insensitive by default.
|
@@ -31,6 +31,8 @@ module Sequel
|
|
31
31
|
# Methods shared by Database instances that connect to MySQL,
|
32
32
|
# currently supported by the native and JDBC adapters.
|
33
33
|
module DatabaseMethods
|
34
|
+
extend Sequel::Database::ResetIdentifierMangling
|
35
|
+
|
34
36
|
AUTO_INCREMENT = 'AUTO_INCREMENT'.freeze
|
35
37
|
CAST_TYPES = {String=>:CHAR, Integer=>:SIGNED, Time=>:DATETIME, DateTime=>:DATETIME, Numeric=>:DECIMAL, BigDecimal=>:DECIMAL, File=>:BINARY}
|
36
38
|
COLUMN_DEFINITION_ORDER = [:collate, :null, :default, :unique, :primary_key, :auto_increment, :references]
|
@@ -431,6 +433,10 @@ module Sequel
|
|
431
433
|
case db_type
|
432
434
|
when /\Aset/io
|
433
435
|
:set
|
436
|
+
when /\Amediumint/io
|
437
|
+
:integer
|
438
|
+
when /\Amediumtext/io
|
439
|
+
:string
|
434
440
|
else
|
435
441
|
super
|
436
442
|
end
|
@@ -87,6 +87,8 @@ module Sequel
|
|
87
87
|
|
88
88
|
# Methods shared by Database instances that connect to PostgreSQL.
|
89
89
|
module DatabaseMethods
|
90
|
+
extend Sequel::Database::ResetIdentifierMangling
|
91
|
+
|
90
92
|
EXCLUDE_SCHEMAS = /pg_*|information_schema/i
|
91
93
|
PREPARED_ARG_PLACEHOLDER = LiteralString.new('$').freeze
|
92
94
|
RE_CURRVAL_ERROR = /currval of sequence "(.*)" is not yet defined in this session|relation "(.*)" does not exist/.freeze
|
@@ -488,7 +490,7 @@ module Sequel
|
|
488
490
|
# Options:
|
489
491
|
# :qualify :: Return the tables as Sequel::SQL::QualifiedIdentifier instances,
|
490
492
|
# using the schema the table is located in as the qualifier.
|
491
|
-
# :schema :: The schema to search
|
493
|
+
# :schema :: The schema to search
|
492
494
|
# :server :: The server to use
|
493
495
|
def tables(opts={}, &block)
|
494
496
|
pg_class_relname('r', opts, &block)
|
@@ -506,7 +508,7 @@ module Sequel
|
|
506
508
|
# Options:
|
507
509
|
# :qualify :: Return the views as Sequel::SQL::QualifiedIdentifier instances,
|
508
510
|
# using the schema the view is located in as the qualifier.
|
509
|
-
# :schema :: The schema to search
|
511
|
+
# :schema :: The schema to search
|
510
512
|
# :server :: The server to use
|
511
513
|
def views(opts={})
|
512
514
|
pg_class_relname('v', opts)
|
@@ -598,6 +600,10 @@ module Sequel
|
|
598
600
|
sqls << "SET standard_conforming_strings = ON" if typecast_value_boolean(@opts.fetch(:force_standard_strings, Postgres.force_standard_strings))
|
599
601
|
|
600
602
|
if (cmm = @opts.fetch(:client_min_messages, Postgres.client_min_messages)) && !cmm.to_s.empty?
|
603
|
+
cmm = cmm.to_s.upcase.strip
|
604
|
+
unless VALID_CLIENT_MIN_MESSAGES.include?(cmm)
|
605
|
+
Sequel::Deprecation.deprecate("Using an unsupported client_min_messages setting will raise an Error in Sequel 4.")
|
606
|
+
end
|
601
607
|
sqls << "SET client_min_messages = '#{cmm.to_s.upcase}'"
|
602
608
|
end
|
603
609
|
|
@@ -803,7 +809,7 @@ module Sequel
|
|
803
809
|
# If opts includes a :schema option, or a default schema is used, restrict the dataset to
|
804
810
|
# that schema. Otherwise, just exclude the default PostgreSQL schemas except for public.
|
805
811
|
def filter_schema(ds, opts)
|
806
|
-
if schema = opts[:schema] ||
|
812
|
+
if schema = opts[:schema] || _default_schema
|
807
813
|
ds.filter(:pg_namespace__nspname=>schema.to_s)
|
808
814
|
else
|
809
815
|
ds.exclude(:pg_namespace__nspname=>EXCLUDE_SCHEMAS)
|
@@ -1178,8 +1184,12 @@ module Sequel
|
|
1178
1184
|
else
|
1179
1185
|
sql = 'LOCK TABLE '
|
1180
1186
|
source_list_append(sql, @opts[:from])
|
1187
|
+
mode = mode.to_s.upcase.strip
|
1188
|
+
unless LOCK_MODES.include?(mode)
|
1189
|
+
Sequel::Deprecation.deprecate("Calling Dataset#lock with an unsupported lock mode will raise an Error in Sequel 4.")
|
1190
|
+
end
|
1181
1191
|
sql << " IN #{mode} MODE"
|
1182
|
-
@db.execute(sql, opts)
|
1192
|
+
@db.execute(sql, opts)
|
1183
1193
|
end
|
1184
1194
|
nil
|
1185
1195
|
end
|
@@ -4,6 +4,8 @@ module Sequel
|
|
4
4
|
# can be used to set PRAGMAs on connections in a thread-safe manner:
|
5
5
|
# :auto_vacuum, :foreign_keys, :synchronous, and :temp_store.
|
6
6
|
module DatabaseMethods
|
7
|
+
extend Sequel::Database::ResetIdentifierMangling
|
8
|
+
|
7
9
|
AUTO_VACUUM = [:none, :full, :incremental].freeze
|
8
10
|
PRIMARY_KEY_INDEX_RE = /\Asqlite_autoindex_/.freeze
|
9
11
|
SYNCHRONOUS = [:off, :normal, :full].freeze
|
@@ -42,10 +44,9 @@ module Sequel
|
|
42
44
|
end
|
43
45
|
|
44
46
|
# A symbol signifying the value of the default transaction mode
|
45
|
-
|
46
|
-
defined?(@transaction_mode) ? @transaction_mode : (@transaction_mode = nil)
|
47
|
-
end
|
47
|
+
attr_reader :transaction_mode
|
48
48
|
|
49
|
+
# Set the default transaction mode.
|
49
50
|
def transaction_mode=(value)
|
50
51
|
if TRANSACTION_MODE.include?(value)
|
51
52
|
@transaction_mode = value
|
@@ -91,13 +91,6 @@ module Sequel
|
|
91
91
|
# The conversion procs to use for this database
|
92
92
|
attr_reader :conversion_procs
|
93
93
|
|
94
|
-
def initialize(opts={})
|
95
|
-
super
|
96
|
-
@conversion_procs = SQLITE_TYPES.dup
|
97
|
-
@conversion_procs['datetime'] = @conversion_procs['timestamp'] = method(:to_application_timestamp)
|
98
|
-
set_integer_booleans
|
99
|
-
end
|
100
|
-
|
101
94
|
# Connect to the database. Since SQLite is a file based database,
|
102
95
|
# the only options available are :database (to specify the database
|
103
96
|
# name), and :timeout, to specify how long to wait for the database to
|
@@ -166,6 +159,12 @@ module Sequel
|
|
166
159
|
|
167
160
|
private
|
168
161
|
|
162
|
+
def adapter_initialize
|
163
|
+
@conversion_procs = SQLITE_TYPES.dup
|
164
|
+
@conversion_procs['datetime'] = @conversion_procs['timestamp'] = method(:to_application_timestamp)
|
165
|
+
set_integer_booleans
|
166
|
+
end
|
167
|
+
|
169
168
|
# Yield an available connection. Rescue
|
170
169
|
# any SQLite3::Exceptions and turn them into DatabaseErrors.
|
171
170
|
def _execute(type, sql, opts, &block)
|
@@ -10,19 +10,19 @@ module Sequel
|
|
10
10
|
# Contains procs keyed on sub adapter type that extend the
|
11
11
|
# given database object so it supports the correct database type.
|
12
12
|
DATABASE_SETUP = {:postgres=>proc do |db|
|
13
|
-
Sequel.
|
13
|
+
Sequel.require 'adapters/swift/postgres'
|
14
14
|
db.extend(Sequel::Swift::Postgres::DatabaseMethods)
|
15
15
|
db.extend_datasets Sequel::Postgres::DatasetMethods
|
16
16
|
db.swift_class = ::Swift::DB::Postgres
|
17
17
|
end,
|
18
18
|
:mysql=>proc do |db|
|
19
|
-
Sequel.
|
19
|
+
Sequel.require 'adapters/swift/mysql'
|
20
20
|
db.extend(Sequel::Swift::MySQL::DatabaseMethods)
|
21
21
|
db.dataset_class = Sequel::Swift::MySQL::Dataset
|
22
22
|
db.swift_class = ::Swift::DB::Mysql
|
23
23
|
end,
|
24
24
|
:sqlite=>proc do |db|
|
25
|
-
Sequel.
|
25
|
+
Sequel.require 'adapters/swift/sqlite'
|
26
26
|
db.extend(Sequel::Swift::SQLite::DatabaseMethods)
|
27
27
|
db.dataset_class = Sequel::Swift::SQLite::Dataset
|
28
28
|
db.swift_class = ::Swift::DB::Sqlite3
|
@@ -37,24 +37,6 @@ module Sequel
|
|
37
37
|
# in this database's connection pool will be instances of this class.
|
38
38
|
attr_accessor :swift_class
|
39
39
|
|
40
|
-
# Call the DATABASE_SETUP proc directly after initialization,
|
41
|
-
# so the object always uses sub adapter specific code. Also,
|
42
|
-
# raise an error immediately if the connection doesn't have a
|
43
|
-
# db_type specified, since one is required to include the correct
|
44
|
-
# subadapter.
|
45
|
-
def initialize(opts)
|
46
|
-
super
|
47
|
-
if db_type = opts[:db_type] and !db_type.to_s.empty?
|
48
|
-
if prok = DATABASE_SETUP[db_type.to_s.to_sym]
|
49
|
-
prok.call(self)
|
50
|
-
else
|
51
|
-
raise(Error, "No :db_type option specified")
|
52
|
-
end
|
53
|
-
else
|
54
|
-
raise(Error, ":db_type option not valid, should be postgres, mysql, or sqlite")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
40
|
# Create an instance of swift_class for the given options.
|
59
41
|
def connect(server)
|
60
42
|
opts = server_opts(server)
|
@@ -101,6 +83,23 @@ module Sequel
|
|
101
83
|
|
102
84
|
private
|
103
85
|
|
86
|
+
# Call the DATABASE_SETUP proc directly after initialization,
|
87
|
+
# so the object always uses sub adapter specific code. Also,
|
88
|
+
# raise an error immediately if the connection doesn't have a
|
89
|
+
# db_type specified, since one is required to include the correct
|
90
|
+
# subadapter.
|
91
|
+
def adapter_initialize
|
92
|
+
if db_type = @opts[:db_type] and !db_type.to_s.empty?
|
93
|
+
if prok = DATABASE_SETUP[db_type.to_s.to_sym]
|
94
|
+
prok.call(self)
|
95
|
+
else
|
96
|
+
raise(Error, "No :db_type option specified")
|
97
|
+
end
|
98
|
+
else
|
99
|
+
raise(Error, ":db_type option not valid, should be postgres, mysql, or sqlite")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
104
103
|
# Method to call on a statement object to execute SQL that does
|
105
104
|
# not return any rows.
|
106
105
|
def connection_execute_method
|
@@ -10,11 +10,13 @@ module Sequel
|
|
10
10
|
module Postgres
|
11
11
|
# Methods to add to Database instances that access PostgreSQL via Swift.
|
12
12
|
module DatabaseMethods
|
13
|
+
extend Sequel::Database::ResetIdentifierMangling
|
13
14
|
include Sequel::Postgres::DatabaseMethods
|
14
15
|
|
15
16
|
# Add the primary_keys and primary_key_sequences instance variables,
|
16
17
|
# so we can get the correct return values for inserted rows.
|
17
18
|
def self.extended(db)
|
19
|
+
super
|
18
20
|
db.send(:initialize_postgres_adapter)
|
19
21
|
end
|
20
22
|
|
@@ -8,6 +8,7 @@ module Sequel
|
|
8
8
|
module SQLite
|
9
9
|
# Database instance methods for SQLite databases accessed via Swift.
|
10
10
|
module DatabaseMethods
|
11
|
+
extend Sequel::Database::ResetIdentifierMangling
|
11
12
|
include Sequel::SQLite::DatabaseMethods
|
12
13
|
|
13
14
|
# Set the correct pragmas on the connection.
|
@@ -7,12 +7,6 @@ module Sequel
|
|
7
7
|
include Sequel::MSSQL::DatabaseMethods
|
8
8
|
set_adapter_scheme :tinytds
|
9
9
|
|
10
|
-
# Choose whether to use unicode strings on initialization
|
11
|
-
def initialize(*)
|
12
|
-
super
|
13
|
-
set_mssql_unicode_strings
|
14
|
-
end
|
15
|
-
|
16
10
|
# Transfer the :user option to the :username option.
|
17
11
|
def connect(server)
|
18
12
|
opts = server_opts(server)
|
@@ -94,6 +88,11 @@ module Sequel
|
|
94
88
|
|
95
89
|
private
|
96
90
|
|
91
|
+
# Choose whether to use unicode strings on initialization
|
92
|
+
def adapter_initialize
|
93
|
+
set_mssql_unicode_strings
|
94
|
+
end
|
95
|
+
|
97
96
|
# For some reason, unless you specify a column can be
|
98
97
|
# NULL, it assumes NOT NULL, so turn NULL on by default unless
|
99
98
|
# the column is a primary key column.
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Sequel
|
2
|
+
module EmulateOffsetWithReverseAndCount
|
3
|
+
# Make empty? work with an offset with an order.
|
4
|
+
# By default it would break since the order would be based on
|
5
|
+
# a column that empty does not select.
|
6
|
+
def empty?
|
7
|
+
if o = @opts[:offset]
|
8
|
+
unlimited.count <= o
|
9
|
+
else
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Emulate OFFSET support using reverse order in a subselect, requiring
|
15
|
+
# a count of the number of rows.
|
16
|
+
#
|
17
|
+
# If offset is used, an order must be provided, since it needs to be
|
18
|
+
# reversed in the subselect. Note that the order needs to be unambiguous
|
19
|
+
# to work correctly, and you must select all columns that you are ordering on.
|
20
|
+
def select_sql
|
21
|
+
return super unless o = @opts[:offset]
|
22
|
+
|
23
|
+
order = @opts[:order] || default_offset_order
|
24
|
+
if order.nil? || order.empty?
|
25
|
+
raise(Error, "#{db.database_type} requires an order be provided if using an offset")
|
26
|
+
end
|
27
|
+
|
28
|
+
ds = unlimited
|
29
|
+
row_count = @opts[:offset_total_count] || ds.clone(:append_sql=>'').count
|
30
|
+
dsa1 = dataset_alias(1)
|
31
|
+
|
32
|
+
if o.is_a?(Symbol) && @opts[:bind_vars] && (match = Sequel::Dataset::PreparedStatementMethods::PLACEHOLDER_RE.match(o.to_s))
|
33
|
+
# Handle use of bound variable offsets. Unfortunately, prepared statement
|
34
|
+
# bound variable offsets cannot be handled, since the bound variable value
|
35
|
+
# isn't available until later.
|
36
|
+
s = match[1].to_sym
|
37
|
+
if prepared_arg?(s)
|
38
|
+
o = prepared_arg(s)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
reverse_offset = row_count - o
|
43
|
+
ds = if reverse_offset > 0
|
44
|
+
ds.limit(reverse_offset).
|
45
|
+
reverse_order(*order).
|
46
|
+
from_self(:alias=>dsa1).
|
47
|
+
limit(@opts[:limit]).
|
48
|
+
order(*order)
|
49
|
+
else
|
50
|
+
# Sequel doesn't allow a nonpositive limit. If the offset
|
51
|
+
# is greater than the number of rows, the empty result set
|
52
|
+
# shuld be returned, so use a condition that is always false.
|
53
|
+
ds.where(1=>0)
|
54
|
+
end
|
55
|
+
sql = @opts[:append_sql] || ''
|
56
|
+
subselect_sql_append(sql, ds)
|
57
|
+
sql
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# The default order to use for datasets with offsets, if no order is defined.
|
63
|
+
# By default, orders by all of the columns in the dataset.
|
64
|
+
def default_offset_order
|
65
|
+
clone(:append_sql=>'', :offset=>nil).columns
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -42,7 +42,7 @@ class Sequel::ConnectionPool
|
|
42
42
|
when Class
|
43
43
|
v.new(db, opts)
|
44
44
|
when Symbol
|
45
|
-
|
45
|
+
require("sequel/connection_pool/#{v}")
|
46
46
|
connection_pool_class(opts).new(db, opts) || raise(Sequel::Error, "No connection pool class found")
|
47
47
|
end
|
48
48
|
end
|