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
@@ -7,6 +7,7 @@ module Sequel
7
7
  module AS400
8
8
  # Instance methods for AS400 Database objects accessed via JDBC.
9
9
  module DatabaseMethods
10
+ extend Sequel::Database::ResetIdentifierMangling
10
11
  include Sequel::JDBC::Transactions
11
12
 
12
13
  TRANSACTION_BEGIN = 'Transaction.begin'.freeze
@@ -5,6 +5,7 @@ module Sequel
5
5
  module JDBC
6
6
  module Cubrid
7
7
  module DatabaseMethods
8
+ extend Sequel::Database::ResetIdentifierMangling
8
9
  include Sequel::Cubrid::DatabaseMethods
9
10
  include Sequel::JDBC::Transactions
10
11
 
@@ -16,6 +16,7 @@ module Sequel
16
16
  module DB2
17
17
  # Database instance methods for DB2 databases accessed via JDBC.
18
18
  module DatabaseMethods
19
+ extend Sequel::Database::ResetIdentifierMangling
19
20
  PRIMARY_KEY_INDEX_RE = /\Asql\d+\z/i.freeze
20
21
 
21
22
  include Sequel::DB2::DatabaseMethods
@@ -6,6 +6,7 @@ module Sequel
6
6
  module Derby
7
7
  # Instance methods for Derby Database objects accessed via JDBC.
8
8
  module DatabaseMethods
9
+ extend Sequel::Database::ResetIdentifierMangling
9
10
  PRIMARY_KEY_INDEX_RE = /\Asql\d+\z/i.freeze
10
11
 
11
12
  include ::Sequel::JDBC::Transactions
@@ -8,6 +8,7 @@ module Sequel
8
8
  module Firebird
9
9
  # Database instance methods for Firebird databases accessed via JDBC.
10
10
  module DatabaseMethods
11
+ extend Sequel::Database::ResetIdentifierMangling
11
12
  include Sequel::Firebird::DatabaseMethods
12
13
  include Sequel::JDBC::Transactions
13
14
 
@@ -4,6 +4,7 @@ module Sequel
4
4
  module H2
5
5
  # Instance methods for H2 Database objects accessed via JDBC.
6
6
  module DatabaseMethods
7
+ extend Sequel::Database::ResetIdentifierMangling
7
8
  PRIMARY_KEY_INDEX_RE = /\Aprimary_key/i.freeze
8
9
 
9
10
  # Commit an existing prepared transaction with the given transaction
@@ -6,6 +6,7 @@ module Sequel
6
6
  module HSQLDB
7
7
  # Instance methods for HSQLDB Database objects accessed via JDBC.
8
8
  module DatabaseMethods
9
+ extend Sequel::Database::ResetIdentifierMangling
9
10
  PRIMARY_KEY_INDEX_RE = /\Asys_idx_sys_pk_/i.freeze
10
11
 
11
12
  include ::Sequel::JDBC::Transactions
@@ -7,6 +7,7 @@ module Sequel
7
7
  module Informix
8
8
  # Database instance methods for Informix databases accessed via JDBC.
9
9
  module DatabaseMethods
10
+ extend Sequel::Database::ResetIdentifierMangling
10
11
  include Sequel::Informix::DatabaseMethods
11
12
 
12
13
  private
@@ -6,6 +6,7 @@ module Sequel
6
6
  # support via JDBC.
7
7
  module JTDS
8
8
  module DatabaseMethods
9
+ extend Sequel::Database::ResetIdentifierMangling
9
10
  include Sequel::JDBC::MSSQL::DatabaseMethods
10
11
 
11
12
  private
@@ -12,6 +12,7 @@ module Sequel
12
12
  module MSSQL
13
13
  # Database instance methods for MSSQL databases accessed via JDBC.
14
14
  module DatabaseMethods
15
+ extend Sequel::Database::ResetIdentifierMangling
15
16
  PRIMARY_KEY_INDEX_RE = /\Apk__/i.freeze
16
17
  ATAT_IDENTITY = 'SELECT @@IDENTITY'.freeze
17
18
  SCOPE_IDENTITY = 'SELECT SCOPE_IDENTITY()'.freeze
@@ -7,6 +7,7 @@ module Sequel
7
7
  module MySQL
8
8
  # Database instance methods for MySQL databases accessed via JDBC.
9
9
  module DatabaseMethods
10
+ extend Sequel::Database::ResetIdentifierMangling
10
11
  include Sequel::MySQL::DatabaseMethods
11
12
  LAST_INSERT_ID = 'SELECT LAST_INSERT_ID()'.freeze
12
13
 
@@ -7,6 +7,7 @@ module Sequel
7
7
  module Oracle
8
8
  # Instance methods for Oracle Database objects accessed via JDBC.
9
9
  module DatabaseMethods
10
+ extend Sequel::Database::ResetIdentifierMangling
10
11
  PRIMARY_KEY_INDEX_RE = /\Asys_/i.freeze
11
12
 
12
13
  include Sequel::Oracle::DatabaseMethods
@@ -10,11 +10,13 @@ module Sequel
10
10
  # Methods to add to Database instances that access PostgreSQL via
11
11
  # JDBC.
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 Progress
9
9
  # Database instance methods for Progress databases accessed via JDBC.
10
10
  module DatabaseMethods
11
+ extend Sequel::Database::ResetIdentifierMangling
11
12
  include Sequel::Progress::DatabaseMethods
12
13
  include Sequel::JDBC::Transactions
13
14
 
@@ -6,6 +6,7 @@ module Sequel
6
6
  module SQLite
7
7
  # Instance methods for SQLite Database objects accessed via JDBC.
8
8
  module DatabaseMethods
9
+ extend Sequel::Database::ResetIdentifierMangling
9
10
  include Sequel::SQLite::DatabaseMethods
10
11
  LAST_INSERT_ROWID = 'SELECT last_insert_rowid()'.freeze
11
12
  FOREIGN_KEY_ERROR_RE = /query does not return ResultSet/.freeze
@@ -7,6 +7,7 @@ module Sequel
7
7
  module SQLServer
8
8
  # Database instance methods for SQLServer databases accessed via JDBC.
9
9
  module DatabaseMethods
10
+ extend Sequel::Database::ResetIdentifierMangling
10
11
  include Sequel::JDBC::MSSQL::DatabaseMethods
11
12
 
12
13
  # Work around a bug in SQL Server JDBC Driver 3.0, where the metadata
@@ -131,37 +131,6 @@ module Sequel
131
131
  # Mock the server version, useful when using the shared adapters
132
132
  attr_accessor :server_version
133
133
 
134
- # Additional options supported:
135
- #
136
- # :autoid :: Call #autoid= with the value
137
- # :columns :: Call #columns= with the value
138
- # :fetch :: Call #fetch= with the value
139
- # :numrows :: Call #numrows= with the value
140
- # :extend :: A module the object is extended with.
141
- # :sqls :: The array to store the SQL queries in.
142
- def initialize(opts={})
143
- super
144
- opts = @opts
145
- @sqls = opts[:sqls] || []
146
- if mod_name = SHARED_ADAPTERS[opts[:host]]
147
- @shared_adapter = true
148
- require "sequel/adapters/shared/#{opts[:host]}"
149
- extend Sequel.const_get(mod_name)::DatabaseMethods
150
- extend_datasets Sequel.const_get(mod_name)::DatasetMethods
151
- if pr = SHARED_ADAPTER_SETUP[opts[:host]]
152
- pr.call(self)
153
- end
154
- else
155
- @shared_adapter = false
156
- end
157
- self.autoid = opts[:autoid]
158
- self.columns = opts[:columns]
159
- self.fetch = opts[:fetch]
160
- self.numrows = opts[:numrows]
161
- extend(opts[:extend]) if opts[:extend]
162
- sqls
163
- end
164
-
165
134
  # Return a related Connection option connecting to the given shard.
166
135
  def connect(server)
167
136
  Connection.new(self, server, server_opts(server))
@@ -297,6 +266,36 @@ module Sequel
297
266
  _nextres(v, sql, 0)
298
267
  end
299
268
 
269
+ # Additional options supported:
270
+ #
271
+ # :autoid :: Call #autoid= with the value
272
+ # :columns :: Call #columns= with the value
273
+ # :fetch :: Call #fetch= with the value
274
+ # :numrows :: Call #numrows= with the value
275
+ # :extend :: A module the object is extended with.
276
+ # :sqls :: The array to store the SQL queries in.
277
+ def adapter_initialize
278
+ opts = @opts
279
+ @sqls = opts[:sqls] || []
280
+ if mod_name = SHARED_ADAPTERS[opts[:host]]
281
+ @shared_adapter = true
282
+ require "sequel/adapters/shared/#{opts[:host]}"
283
+ extend Sequel.const_get(mod_name)::DatabaseMethods
284
+ extend_datasets Sequel.const_get(mod_name)::DatasetMethods
285
+ if pr = SHARED_ADAPTER_SETUP[opts[:host]]
286
+ pr.call(self)
287
+ end
288
+ else
289
+ @shared_adapter = false
290
+ end
291
+ self.autoid = opts[:autoid]
292
+ self.columns = opts[:columns]
293
+ self.fetch = opts[:fetch]
294
+ self.numrows = opts[:numrows]
295
+ extend(opts[:extend]) if opts[:extend]
296
+ sqls
297
+ end
298
+
300
299
  def columns(ds, sql, cs=@columns)
301
300
  case cs
302
301
  when Array
@@ -59,13 +59,6 @@ module Sequel
59
59
  # it returns the strings as is.
60
60
  attr_reader :convert_invalid_date_time
61
61
 
62
- def initialize(opts={})
63
- super
64
- @conversion_procs = MYSQL_TYPES.dup
65
- self.convert_tinyint_to_bool = Sequel::MySQL.convert_tinyint_to_bool
66
- self.convert_invalid_date_time = Sequel::MySQL.convert_invalid_date_time
67
- end
68
-
69
62
  # Connect to the database. In addition to the usual database options,
70
63
  # the following options have effect:
71
64
  #
@@ -221,6 +214,12 @@ module Sequel
221
214
  end
222
215
  end
223
216
 
217
+ def adapter_initialize
218
+ @conversion_procs = MYSQL_TYPES.dup
219
+ self.convert_tinyint_to_bool = Sequel::MySQL.convert_tinyint_to_bool
220
+ self.convert_invalid_date_time = Sequel::MySQL.convert_invalid_date_time
221
+ end
222
+
224
223
  # Try to get an accurate number of rows matched using the query
225
224
  # info. Fall back to affected_rows if there was no match, but
226
225
  # that may be inaccurate.
@@ -14,12 +14,6 @@ module Sequel
14
14
  # Whether to convert tinyint columns to bool for this database
15
15
  attr_accessor :convert_tinyint_to_bool
16
16
 
17
- # Set the convert_tinyint_to_bool setting based on the default value.
18
- def initialize(opts={})
19
- super
20
- self.convert_tinyint_to_bool = Sequel::MySQL.convert_tinyint_to_bool
21
- end
22
-
23
17
  # Connect to the database. In addition to the usual database options,
24
18
  # the following options have effect:
25
19
  #
@@ -89,6 +83,11 @@ module Sequel
89
83
  end
90
84
  end
91
85
 
86
+ # Set the convert_tinyint_to_bool setting based on the default value.
87
+ def adapter_initialize
88
+ self.convert_tinyint_to_bool = Sequel::MySQL.convert_tinyint_to_bool
89
+ end
90
+
92
91
  # MySQL connections use the query method to execute SQL without a result
93
92
  def connection_execute_method
94
93
  :query
@@ -9,25 +9,6 @@ module Sequel
9
9
  DRV_NAME_GUARDS = '{%s}'.freeze
10
10
  DISCONNECT_ERRORS = /\A08S01/.freeze
11
11
 
12
- def initialize(opts)
13
- super
14
- case @opts[:db_type]
15
- when 'mssql'
16
- Sequel.ts_require 'adapters/odbc/mssql'
17
- extend Sequel::ODBC::MSSQL::DatabaseMethods
18
- @dataset_class = Sequel::ODBC::MSSQL::Dataset
19
- set_mssql_unicode_strings
20
- when 'progress'
21
- Sequel.ts_require 'adapters/shared/progress'
22
- extend Sequel::Progress::DatabaseMethods
23
- extend_datasets(Sequel::Progress::DatasetMethods)
24
- when 'db2'
25
- Sequel.ts_require 'adapters/shared/db2'
26
- extend ::Sequel::DB2::DatabaseMethods
27
- extend_datasets ::Sequel::DB2::DatasetMethods
28
- end
29
- end
30
-
31
12
  def connect(server)
32
13
  opts = server_opts(server)
33
14
  if opts.include? :driver
@@ -75,10 +56,31 @@ module Sequel
75
56
  end
76
57
  end
77
58
  end
78
- alias do execute_dui
59
+ def do(*a, &block)
60
+ Sequel::Deprecation.deprecate('Database#do', 'Please use Database#execute_dui')
61
+ execute_dui(*a, &block)
62
+ end
79
63
 
80
64
  private
81
65
 
66
+ def adapter_initialize
67
+ case @opts[:db_type]
68
+ when 'mssql'
69
+ Sequel.require 'adapters/odbc/mssql'
70
+ extend Sequel::ODBC::MSSQL::DatabaseMethods
71
+ self.dataset_class = Sequel::ODBC::MSSQL::Dataset
72
+ set_mssql_unicode_strings
73
+ when 'progress'
74
+ Sequel.require 'adapters/shared/progress'
75
+ extend Sequel::Progress::DatabaseMethods
76
+ extend_datasets(Sequel::Progress::DatasetMethods)
77
+ when 'db2'
78
+ Sequel.require 'adapters/shared/db2'
79
+ extend ::Sequel::DB2::DatabaseMethods
80
+ extend_datasets ::Sequel::DB2::DatasetMethods
81
+ end
82
+ end
83
+
82
84
  def connection_execute_method
83
85
  :do
84
86
  end
@@ -6,6 +6,7 @@ module Sequel
6
6
  # support via ODBC.
7
7
  module MSSQL
8
8
  module DatabaseMethods
9
+ extend Sequel::Database::ResetIdentifierMangling
9
10
  include Sequel::MSSQL::DatabaseMethods
10
11
  LAST_INSERT_ID_SQL='SELECT SCOPE_IDENTITY()'.freeze
11
12
 
@@ -26,7 +26,10 @@ module Sequel
26
26
  r
27
27
  end
28
28
  end
29
- alias_method :do, :execute
29
+ def do(*a, &block)
30
+ Sequel::Deprecation.deprecate('Database#do', 'Please use Database#execute')
31
+ execute(*a, &block)
32
+ end
30
33
  end
31
34
 
32
35
  class Dataset < Sequel::Dataset
@@ -21,13 +21,6 @@ module Sequel
21
21
  # Hash of conversion procs for this database.
22
22
  attr_reader :conversion_procs
23
23
 
24
- def initialize(opts={})
25
- super
26
- @autosequence = opts[:autosequence]
27
- @primary_key_sequences = {}
28
- @conversion_procs = ORACLE_TYPES.dup
29
- end
30
-
31
24
  def connect(server)
32
25
  opts = server_opts(server)
33
26
  if opts[:database]
@@ -71,7 +64,10 @@ module Sequel
71
64
  def execute(sql, opts={}, &block)
72
65
  _execute(nil, sql, opts, &block)
73
66
  end
74
- alias do execute
67
+ def do(*a, &block)
68
+ Sequel::Deprecation.deprecate('Database#do', 'Please use Database#execute')
69
+ execute_dui(*a, &block)
70
+ end
75
71
 
76
72
  def execute_insert(sql, opts={})
77
73
  _execute(:insert, sql, opts)
@@ -109,6 +105,12 @@ module Sequel
109
105
  end
110
106
  end
111
107
 
108
+ def adapter_initialize
109
+ @autosequence = @opts[:autosequence]
110
+ @primary_key_sequences = {}
111
+ @conversion_procs = ORACLE_TYPES.dup
112
+ end
113
+
112
114
  PS_TYPES = {'string'.freeze=>String, 'integer'.freeze=>Integer, 'float'.freeze=>Float,
113
115
  'decimal'.freeze=>Float, 'date'.freeze=>Time, 'datetime'.freeze=>Time,
114
116
  'time'.freeze=>Time, 'boolean'.freeze=>String, 'blob'.freeze=>OCI8::BLOB}
@@ -175,16 +175,6 @@ module Sequel
175
175
  # as a string, or :float to convert to an infinite float.
176
176
  attr_reader :convert_infinite_timestamps
177
177
 
178
- # Add the primary_keys and primary_key_sequences instance variables,
179
- # so we can get the correct return values for inserted rows.
180
- def initialize(*args)
181
- super
182
- @use_iso_date_format = typecast_value_boolean(@opts.fetch(:use_iso_date_format, Postgres.use_iso_date_format))
183
- initialize_postgres_adapter
184
- conversion_procs[1082] = TYPE_TRANSLATOR.method(:date) if @use_iso_date_format
185
- self.convert_infinite_timestamps = @opts[:convert_infinite_timestamps]
186
- end
187
-
188
178
  # Convert given argument so that it can be used directly by pg. Currently, pg doesn't
189
179
  # handle fractional seconds in Time/DateTime or blobs with "\0", and it won't ever
190
180
  # handle Sequel::SQLTime values correctly. Only public for use by the adapter, shouldn't
@@ -471,6 +461,15 @@ module Sequel
471
461
  conn.exec_prepared(ps_name, args)
472
462
  end
473
463
 
464
+ # Add the primary_keys and primary_key_sequences instance variables,
465
+ # so we can get the correct return values for inserted rows.
466
+ def adapter_initialize
467
+ @use_iso_date_format = typecast_value_boolean(@opts.fetch(:use_iso_date_format, Postgres.use_iso_date_format))
468
+ initialize_postgres_adapter
469
+ conversion_procs[1082] = TYPE_TRANSLATOR.method(:date) if @use_iso_date_format
470
+ self.convert_infinite_timestamps = @opts[:convert_infinite_timestamps]
471
+ end
472
+
474
473
  # Convert exceptions raised from the block into DatabaseErrors.
475
474
  def check_database_errors
476
475
  begin
@@ -650,6 +649,9 @@ module Sequel
650
649
  prepared_args << y
651
650
  i = prepared_args.length
652
651
  end
652
+ if type
653
+ Sequel::Deprecation.deprecate('Specifying prepared statement argument types via the __type suffix', "If a manual cast is really need, surround the prepared statement argument in Sequel.cast")
654
+ end
653
655
  LiteralString.new("#{prepared_arg_placeholder}#{i}#{"::#{type}" if type}")
654
656
  end
655
657
 
@@ -1,6 +1,10 @@
1
1
  module Sequel
2
+ require 'adapters/utils/emulate_offset_with_reverse_and_count'
3
+
2
4
  module Access
3
5
  module DatabaseMethods
6
+ extend Sequel::Database::ResetIdentifierMangling
7
+
4
8
  # Access uses type :access as the database_type
5
9
  def database_type
6
10
  :access
@@ -84,6 +88,8 @@ module Sequel
84
88
  end
85
89
 
86
90
  module DatasetMethods
91
+ include EmulateOffsetWithReverseAndCount
92
+
87
93
  SELECT_CLAUSE_METHODS = Dataset.clause_methods(:select, %w'select distinct limit columns into from join where group order having compounds')
88
94
  DATE_FORMAT = '#%Y-%m-%d#'.freeze
89
95
  TIMESTAMP_FORMAT = '#%Y-%m-%d %H:%M:%S#'.freeze