sequel 3.47.0 → 3.48.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (243) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +230 -0
  3. data/README.rdoc +31 -40
  4. data/Rakefile +1 -14
  5. data/doc/active_record.rdoc +29 -29
  6. data/doc/association_basics.rdoc +4 -13
  7. data/doc/cheat_sheet.rdoc +8 -6
  8. data/doc/code_order.rdoc +89 -0
  9. data/doc/core_extensions.rdoc +3 -3
  10. data/doc/dataset_basics.rdoc +7 -8
  11. data/doc/dataset_filtering.rdoc +7 -2
  12. data/doc/mass_assignment.rdoc +2 -3
  13. data/doc/migration.rdoc +8 -8
  14. data/doc/model_hooks.rdoc +11 -7
  15. data/doc/object_model.rdoc +2 -2
  16. data/doc/opening_databases.rdoc +5 -14
  17. data/doc/prepared_statements.rdoc +5 -9
  18. data/doc/querying.rdoc +23 -28
  19. data/doc/reflection.rdoc +11 -0
  20. data/doc/release_notes/3.48.0.txt +477 -0
  21. data/doc/schema_modification.rdoc +12 -5
  22. data/doc/security.rdoc +2 -2
  23. data/doc/sharding.rdoc +1 -2
  24. data/doc/sql.rdoc +10 -13
  25. data/doc/testing.rdoc +8 -4
  26. data/doc/transactions.rdoc +2 -2
  27. data/doc/validations.rdoc +40 -17
  28. data/doc/virtual_rows.rdoc +2 -2
  29. data/lib/sequel/adapters/ado.rb +25 -20
  30. data/lib/sequel/adapters/ado/access.rb +1 -0
  31. data/lib/sequel/adapters/ado/mssql.rb +1 -0
  32. data/lib/sequel/adapters/db2.rb +9 -7
  33. data/lib/sequel/adapters/dbi.rb +16 -16
  34. data/lib/sequel/adapters/do.rb +17 -18
  35. data/lib/sequel/adapters/do/mysql.rb +1 -0
  36. data/lib/sequel/adapters/do/postgres.rb +2 -0
  37. data/lib/sequel/adapters/do/sqlite.rb +1 -0
  38. data/lib/sequel/adapters/firebird.rb +5 -7
  39. data/lib/sequel/adapters/ibmdb.rb +23 -20
  40. data/lib/sequel/adapters/informix.rb +8 -2
  41. data/lib/sequel/adapters/jdbc.rb +39 -35
  42. data/lib/sequel/adapters/jdbc/as400.rb +1 -0
  43. data/lib/sequel/adapters/jdbc/cubrid.rb +1 -0
  44. data/lib/sequel/adapters/jdbc/db2.rb +1 -0
  45. data/lib/sequel/adapters/jdbc/derby.rb +1 -0
  46. data/lib/sequel/adapters/jdbc/firebird.rb +1 -0
  47. data/lib/sequel/adapters/jdbc/h2.rb +1 -0
  48. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -0
  49. data/lib/sequel/adapters/jdbc/informix.rb +1 -0
  50. data/lib/sequel/adapters/jdbc/jtds.rb +1 -0
  51. data/lib/sequel/adapters/jdbc/mssql.rb +1 -0
  52. data/lib/sequel/adapters/jdbc/mysql.rb +1 -0
  53. data/lib/sequel/adapters/jdbc/oracle.rb +1 -0
  54. data/lib/sequel/adapters/jdbc/postgresql.rb +2 -0
  55. data/lib/sequel/adapters/jdbc/progress.rb +1 -0
  56. data/lib/sequel/adapters/jdbc/sqlite.rb +1 -0
  57. data/lib/sequel/adapters/jdbc/sqlserver.rb +1 -0
  58. data/lib/sequel/adapters/mock.rb +30 -31
  59. data/lib/sequel/adapters/mysql.rb +6 -7
  60. data/lib/sequel/adapters/mysql2.rb +5 -6
  61. data/lib/sequel/adapters/odbc.rb +22 -20
  62. data/lib/sequel/adapters/odbc/mssql.rb +1 -0
  63. data/lib/sequel/adapters/openbase.rb +4 -1
  64. data/lib/sequel/adapters/oracle.rb +10 -8
  65. data/lib/sequel/adapters/postgres.rb +12 -10
  66. data/lib/sequel/adapters/shared/access.rb +6 -0
  67. data/lib/sequel/adapters/shared/cubrid.rb +2 -0
  68. data/lib/sequel/adapters/shared/db2.rb +2 -0
  69. data/lib/sequel/adapters/shared/firebird.rb +2 -0
  70. data/lib/sequel/adapters/shared/informix.rb +2 -0
  71. data/lib/sequel/adapters/shared/mssql.rb +14 -8
  72. data/lib/sequel/adapters/shared/mysql.rb +6 -0
  73. data/lib/sequel/adapters/shared/oracle.rb +2 -0
  74. data/lib/sequel/adapters/shared/postgres.rb +14 -4
  75. data/lib/sequel/adapters/shared/progress.rb +1 -0
  76. data/lib/sequel/adapters/shared/sqlite.rb +4 -3
  77. data/lib/sequel/adapters/sqlite.rb +6 -7
  78. data/lib/sequel/adapters/swift.rb +20 -21
  79. data/lib/sequel/adapters/swift/mysql.rb +1 -0
  80. data/lib/sequel/adapters/swift/postgres.rb +2 -0
  81. data/lib/sequel/adapters/swift/sqlite.rb +1 -0
  82. data/lib/sequel/adapters/tinytds.rb +5 -6
  83. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +68 -0
  84. data/lib/sequel/connection_pool.rb +1 -1
  85. data/lib/sequel/core.rb +57 -50
  86. data/lib/sequel/database/connecting.rb +9 -10
  87. data/lib/sequel/database/dataset.rb +11 -6
  88. data/lib/sequel/database/dataset_defaults.rb +61 -69
  89. data/lib/sequel/database/features.rb +21 -0
  90. data/lib/sequel/database/misc.rb +23 -3
  91. data/lib/sequel/database/query.rb +13 -7
  92. data/lib/sequel/database/schema_methods.rb +6 -6
  93. data/lib/sequel/database/transactions.rb +1 -0
  94. data/lib/sequel/dataset/actions.rb +51 -38
  95. data/lib/sequel/dataset/features.rb +1 -0
  96. data/lib/sequel/dataset/graph.rb +9 -33
  97. data/lib/sequel/dataset/misc.rb +30 -5
  98. data/lib/sequel/dataset/mutation.rb +2 -3
  99. data/lib/sequel/dataset/prepared_statements.rb +1 -1
  100. data/lib/sequel/dataset/query.rb +91 -27
  101. data/lib/sequel/dataset/sql.rb +40 -6
  102. data/lib/sequel/deprecated.rb +74 -0
  103. data/lib/sequel/deprecated_core_extensions.rb +135 -0
  104. data/lib/sequel/extensions/columns_introspection.rb +1 -5
  105. data/lib/sequel/extensions/core_extensions.rb +10 -3
  106. data/lib/sequel/extensions/date_arithmetic.rb +1 -0
  107. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +33 -0
  108. data/lib/sequel/extensions/filter_having.rb +58 -0
  109. data/lib/sequel/extensions/graph_each.rb +63 -0
  110. data/lib/sequel/extensions/hash_aliases.rb +44 -0
  111. data/lib/sequel/extensions/looser_typecasting.rb +14 -3
  112. data/lib/sequel/extensions/migration.rb +2 -3
  113. data/lib/sequel/extensions/named_timezones.rb +14 -1
  114. data/lib/sequel/extensions/null_dataset.rb +7 -1
  115. data/lib/sequel/extensions/pagination.rb +15 -5
  116. data/lib/sequel/extensions/pg_auto_parameterize.rb +1 -0
  117. data/lib/sequel/extensions/pg_hstore_ops.rb +48 -14
  118. data/lib/sequel/extensions/pg_json.rb +7 -7
  119. data/lib/sequel/extensions/pg_range_ops.rb +8 -2
  120. data/lib/sequel/extensions/pg_statement_cache.rb +1 -0
  121. data/lib/sequel/extensions/pretty_table.rb +13 -4
  122. data/lib/sequel/extensions/query.rb +21 -4
  123. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +22 -0
  124. data/lib/sequel/extensions/schema_caching.rb +10 -7
  125. data/lib/sequel/extensions/schema_dumper.rb +35 -48
  126. data/lib/sequel/extensions/select_remove.rb +13 -4
  127. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +117 -0
  128. data/lib/sequel/extensions/set_overrides.rb +43 -0
  129. data/lib/sequel/extensions/to_dot.rb +6 -0
  130. data/lib/sequel/model.rb +12 -6
  131. data/lib/sequel/model/associations.rb +80 -38
  132. data/lib/sequel/model/base.rb +137 -52
  133. data/lib/sequel/model/errors.rb +7 -2
  134. data/lib/sequel/plugins/active_model.rb +13 -0
  135. data/lib/sequel/plugins/after_initialize.rb +43 -0
  136. data/lib/sequel/plugins/association_proxies.rb +63 -7
  137. data/lib/sequel/plugins/auto_validations.rb +56 -16
  138. data/lib/sequel/plugins/blacklist_security.rb +63 -0
  139. data/lib/sequel/plugins/class_table_inheritance.rb +9 -0
  140. data/lib/sequel/plugins/constraint_validations.rb +50 -8
  141. data/lib/sequel/plugins/dataset_associations.rb +2 -0
  142. data/lib/sequel/plugins/hook_class_methods.rb +7 -1
  143. data/lib/sequel/plugins/identity_map.rb +4 -0
  144. data/lib/sequel/plugins/json_serializer.rb +32 -13
  145. data/lib/sequel/plugins/optimistic_locking.rb +1 -1
  146. data/lib/sequel/plugins/rcte_tree.rb +4 -4
  147. data/lib/sequel/plugins/scissors.rb +33 -0
  148. data/lib/sequel/plugins/serialization.rb +1 -1
  149. data/lib/sequel/plugins/single_table_inheritance.rb +6 -0
  150. data/lib/sequel/plugins/tree.rb +5 -1
  151. data/lib/sequel/plugins/validation_class_methods.rb +2 -1
  152. data/lib/sequel/plugins/validation_helpers.rb +15 -11
  153. data/lib/sequel/plugins/xml_serializer.rb +12 -3
  154. data/lib/sequel/sql.rb +12 -2
  155. data/lib/sequel/timezones.rb +1 -1
  156. data/lib/sequel/version.rb +1 -1
  157. data/lib/sequel_core.rb +1 -0
  158. data/lib/sequel_model.rb +1 -0
  159. data/spec/adapters/mssql_spec.rb +24 -57
  160. data/spec/adapters/postgres_spec.rb +27 -55
  161. data/spec/adapters/spec_helper.rb +1 -1
  162. data/spec/adapters/sqlite_spec.rb +1 -1
  163. data/spec/bin_spec.rb +251 -0
  164. data/spec/core/database_spec.rb +46 -32
  165. data/spec/core/dataset_spec.rb +233 -181
  166. data/spec/core/deprecated_spec.rb +78 -0
  167. data/spec/core/expression_filters_spec.rb +3 -4
  168. data/spec/core/mock_adapter_spec.rb +9 -9
  169. data/spec/core/object_graph_spec.rb +9 -19
  170. data/spec/core/schema_spec.rb +3 -1
  171. data/spec/core/spec_helper.rb +19 -0
  172. data/spec/core_extensions_spec.rb +80 -30
  173. data/spec/extensions/after_initialize_spec.rb +24 -0
  174. data/spec/extensions/association_proxies_spec.rb +37 -1
  175. data/spec/extensions/auto_validations_spec.rb +20 -4
  176. data/spec/extensions/blacklist_security_spec.rb +87 -0
  177. data/spec/extensions/boolean_readers_spec.rb +2 -1
  178. data/spec/extensions/class_table_inheritance_spec.rb +7 -0
  179. data/spec/extensions/columns_introspection_spec.rb +3 -3
  180. data/spec/extensions/constraint_validations_plugin_spec.rb +83 -5
  181. data/spec/extensions/core_refinements_spec.rb +7 -7
  182. data/spec/extensions/dataset_associations_spec.rb +2 -2
  183. data/spec/extensions/date_arithmetic_spec.rb +1 -1
  184. data/spec/extensions/defaults_setter_spec.rb +2 -1
  185. data/spec/extensions/empty_array_ignore_nulls_spec.rb +24 -0
  186. data/spec/extensions/filter_having_spec.rb +40 -0
  187. data/spec/extensions/graph_each_spec.rb +109 -0
  188. data/spec/extensions/hash_aliases_spec.rb +16 -0
  189. data/spec/extensions/hook_class_methods_spec.rb +2 -2
  190. data/spec/extensions/identity_map_spec.rb +3 -3
  191. data/spec/extensions/json_serializer_spec.rb +19 -19
  192. data/spec/extensions/lazy_attributes_spec.rb +1 -0
  193. data/spec/extensions/list_spec.rb +13 -13
  194. data/spec/extensions/looser_typecasting_spec.rb +10 -3
  195. data/spec/extensions/many_through_many_spec.rb +1 -1
  196. data/spec/extensions/migration_spec.rb +7 -7
  197. data/spec/extensions/named_timezones_spec.rb +6 -0
  198. data/spec/extensions/nested_attributes_spec.rb +2 -2
  199. data/spec/extensions/null_dataset_spec.rb +1 -1
  200. data/spec/extensions/pagination_spec.rb +2 -2
  201. data/spec/extensions/pg_hstore_ops_spec.rb +75 -0
  202. data/spec/extensions/pg_range_ops_spec.rb +4 -2
  203. data/spec/extensions/pg_row_plugin_spec.rb +1 -1
  204. data/spec/extensions/pretty_table_spec.rb +1 -1
  205. data/spec/extensions/query_literals_spec.rb +1 -1
  206. data/spec/extensions/query_spec.rb +3 -3
  207. data/spec/extensions/schema_caching_spec.rb +3 -3
  208. data/spec/extensions/schema_dumper_spec.rb +27 -2
  209. data/spec/extensions/schema_spec.rb +2 -2
  210. data/spec/extensions/scissors_spec.rb +26 -0
  211. data/spec/extensions/select_remove_spec.rb +1 -1
  212. data/spec/extensions/sequel_3_dataset_methods_spec.rb +102 -0
  213. data/spec/extensions/set_overrides_spec.rb +45 -0
  214. data/spec/extensions/single_table_inheritance_spec.rb +10 -0
  215. data/spec/extensions/spec_helper.rb +24 -1
  216. data/spec/extensions/static_cache_spec.rb +1 -1
  217. data/spec/extensions/string_stripper_spec.rb +2 -1
  218. data/spec/extensions/to_dot_spec.rb +1 -1
  219. data/spec/extensions/typecast_on_load_spec.rb +3 -2
  220. data/spec/extensions/update_primary_key_spec.rb +2 -2
  221. data/spec/extensions/validation_class_methods_spec.rb +19 -19
  222. data/spec/extensions/validation_helpers_spec.rb +30 -21
  223. data/spec/extensions/xml_serializer_spec.rb +5 -5
  224. data/spec/integration/associations_test.rb +10 -30
  225. data/spec/integration/dataset_test.rb +20 -24
  226. data/spec/integration/eager_loader_test.rb +5 -5
  227. data/spec/integration/model_test.rb +3 -3
  228. data/spec/integration/plugin_test.rb +7 -39
  229. data/spec/integration/schema_test.rb +4 -38
  230. data/spec/integration/spec_helper.rb +2 -1
  231. data/spec/model/association_reflection_spec.rb +70 -5
  232. data/spec/model/associations_spec.rb +11 -11
  233. data/spec/model/base_spec.rb +25 -8
  234. data/spec/model/class_dataset_methods_spec.rb +143 -0
  235. data/spec/model/dataset_methods_spec.rb +1 -1
  236. data/spec/model/eager_loading_spec.rb +25 -25
  237. data/spec/model/hooks_spec.rb +1 -1
  238. data/spec/model/model_spec.rb +22 -7
  239. data/spec/model/plugins_spec.rb +1 -6
  240. data/spec/model/record_spec.rb +37 -29
  241. data/spec/model/spec_helper.rb +23 -1
  242. data/spec/model/validations_spec.rb +15 -17
  243. metadata +32 -3
@@ -3,6 +3,8 @@ Sequel.require 'adapters/utils/split_alter_table'
3
3
  module Sequel
4
4
  module Cubrid
5
5
  module DatabaseMethods
6
+ extend Sequel::Database::ResetIdentifierMangling
7
+
6
8
  include Sequel::Database::SplitAlterTable
7
9
 
8
10
  AUTOINCREMENT = 'AUTO_INCREMENT'.freeze
@@ -10,6 +10,8 @@ module Sequel
10
10
  end
11
11
 
12
12
  module DatabaseMethods
13
+ extend Sequel::Database::ResetIdentifierMangling
14
+
13
15
  AUTOINCREMENT = 'GENERATED ALWAYS AS IDENTITY'.freeze
14
16
  NOT_NULL = ' NOT NULL'.freeze
15
17
  NULL = ''.freeze
@@ -1,6 +1,8 @@
1
1
  module Sequel
2
2
  module Firebird
3
3
  module DatabaseMethods
4
+ extend Sequel::Database::ResetIdentifierMangling
5
+
4
6
  AUTO_INCREMENT = ''.freeze
5
7
  TEMPORARY = 'GLOBAL TEMPORARY '.freeze
6
8
 
@@ -1,6 +1,8 @@
1
1
  module Sequel
2
2
  module Informix
3
3
  module DatabaseMethods
4
+ extend Sequel::Database::ResetIdentifierMangling
5
+
4
6
  TEMPORARY = 'TEMP '.freeze
5
7
 
6
8
  # Informix uses the :informix database type
@@ -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
- attr_accessor :mssql_unicode_strings
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]||default_schema||'dbo').to_s).
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] || default_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
- attr_accessor :mssql_unicode_strings
451
+ attr_writer :mssql_unicode_strings
445
452
 
446
- # Copy the mssql_unicode_strings option from the +db+ object.
447
- def initialize(db, opts={})
448
- super
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
@@ -3,6 +3,8 @@ Sequel.require 'adapters/utils/emulate_offset_with_row_number'
3
3
  module Sequel
4
4
  module Oracle
5
5
  module DatabaseMethods
6
+ extend Sequel::Database::ResetIdentifierMangling
7
+
6
8
  TEMPORARY = 'GLOBAL TEMPORARY '.freeze
7
9
  AUTOINCREMENT = ''.freeze
8
10
 
@@ -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 (default_schema by default)
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 (default_schema by default)
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] || default_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) # lock without a transaction
1192
+ @db.execute(sql, opts)
1183
1193
  end
1184
1194
  nil
1185
1195
  end
@@ -1,6 +1,7 @@
1
1
  module Sequel
2
2
  module Progress
3
3
  module DatabaseMethods
4
+ extend Sequel::Database::ResetIdentifierMangling
4
5
 
5
6
  # Progress uses the :progress database type.
6
7
  def database_type
@@ -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
- def transaction_mode
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.ts_require 'adapters/swift/postgres'
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.ts_require 'adapters/swift/mysql'
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.ts_require 'adapters/swift/sqlite'
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
@@ -8,6 +8,7 @@ module Sequel
8
8
  module MySQL
9
9
  # Database instance methods for MySQL databases accessed via Swift.
10
10
  module DatabaseMethods
11
+ extend Sequel::Database::ResetIdentifierMangling
11
12
  include Sequel::MySQL::DatabaseMethods
12
13
 
13
14
  private
@@ -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
- Sequel.tsk_require("sequel/connection_pool/#{v}")
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