sequel 4.45.0 → 4.46.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +108 -0
  3. data/doc/release_notes/4.46.0.txt +404 -0
  4. data/doc/security.rdoc +9 -0
  5. data/doc/sql.rdoc +2 -2
  6. data/doc/testing.rdoc +1 -1
  7. data/doc/validations.rdoc +1 -2
  8. data/lib/sequel/adapters/ado.rb +8 -3
  9. data/lib/sequel/adapters/ado/access.rb +8 -4
  10. data/lib/sequel/adapters/ado/mssql.rb +3 -1
  11. data/lib/sequel/adapters/amalgalite.rb +5 -0
  12. data/lib/sequel/adapters/cubrid.rb +16 -7
  13. data/lib/sequel/adapters/do.rb +7 -1
  14. data/lib/sequel/adapters/do/mysql.rb +8 -4
  15. data/lib/sequel/adapters/ibmdb.rb +10 -5
  16. data/lib/sequel/adapters/jdbc.rb +8 -2
  17. data/lib/sequel/adapters/jdbc/as400.rb +10 -3
  18. data/lib/sequel/adapters/jdbc/db2.rb +27 -16
  19. data/lib/sequel/adapters/jdbc/derby.rb +47 -20
  20. data/lib/sequel/adapters/jdbc/h2.rb +13 -7
  21. data/lib/sequel/adapters/jdbc/hsqldb.rb +18 -9
  22. data/lib/sequel/adapters/jdbc/mssql.rb +5 -2
  23. data/lib/sequel/adapters/jdbc/mysql.rb +3 -2
  24. data/lib/sequel/adapters/jdbc/oracle.rb +3 -2
  25. data/lib/sequel/adapters/jdbc/postgresql.rb +4 -3
  26. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +2 -1
  27. data/lib/sequel/adapters/jdbc/sqlite.rb +10 -3
  28. data/lib/sequel/adapters/jdbc/sqlserver.rb +23 -0
  29. data/lib/sequel/adapters/jdbc/transactions.rb +16 -10
  30. data/lib/sequel/adapters/mock.rb +5 -0
  31. data/lib/sequel/adapters/mysql.rb +8 -1
  32. data/lib/sequel/adapters/mysql2.rb +6 -1
  33. data/lib/sequel/adapters/odbc.rb +20 -8
  34. data/lib/sequel/adapters/odbc/mssql.rb +6 -3
  35. data/lib/sequel/adapters/oracle.rb +12 -6
  36. data/lib/sequel/adapters/postgres.rb +20 -8
  37. data/lib/sequel/adapters/shared/access.rb +76 -47
  38. data/lib/sequel/adapters/shared/cubrid.rb +16 -11
  39. data/lib/sequel/adapters/shared/db2.rb +46 -19
  40. data/lib/sequel/adapters/shared/firebird.rb +20 -8
  41. data/lib/sequel/adapters/shared/informix.rb +6 -3
  42. data/lib/sequel/adapters/shared/mssql.rb +132 -72
  43. data/lib/sequel/adapters/shared/mysql.rb +112 -65
  44. data/lib/sequel/adapters/shared/oracle.rb +36 -21
  45. data/lib/sequel/adapters/shared/postgres.rb +91 -56
  46. data/lib/sequel/adapters/shared/sqlanywhere.rb +65 -37
  47. data/lib/sequel/adapters/shared/sqlite.rb +67 -32
  48. data/lib/sequel/adapters/sqlanywhere.rb +9 -1
  49. data/lib/sequel/adapters/sqlite.rb +8 -1
  50. data/lib/sequel/adapters/swift.rb +5 -0
  51. data/lib/sequel/adapters/swift/mysql.rb +4 -2
  52. data/lib/sequel/adapters/swift/sqlite.rb +1 -1
  53. data/lib/sequel/adapters/tinytds.rb +10 -3
  54. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +1 -1
  55. data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +1 -1
  56. data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -0
  57. data/lib/sequel/adapters/utils/pg_types.rb +14 -6
  58. data/lib/sequel/adapters/utils/replace.rb +4 -2
  59. data/lib/sequel/connection_pool/single.rb +2 -2
  60. data/lib/sequel/core.rb +24 -11
  61. data/lib/sequel/database/connecting.rb +9 -3
  62. data/lib/sequel/database/dataset_defaults.rb +7 -1
  63. data/lib/sequel/database/logging.rb +1 -0
  64. data/lib/sequel/database/misc.rb +5 -2
  65. data/lib/sequel/database/query.rb +7 -5
  66. data/lib/sequel/database/schema_generator.rb +1 -0
  67. data/lib/sequel/database/schema_methods.rb +50 -27
  68. data/lib/sequel/database/transactions.rb +19 -9
  69. data/lib/sequel/dataset/actions.rb +15 -6
  70. data/lib/sequel/dataset/graph.rb +15 -5
  71. data/lib/sequel/dataset/misc.rb +12 -4
  72. data/lib/sequel/dataset/mutation.rb +17 -8
  73. data/lib/sequel/dataset/prepared_statements.rb +3 -2
  74. data/lib/sequel/dataset/query.rb +84 -38
  75. data/lib/sequel/dataset/sql.rb +302 -191
  76. data/lib/sequel/deprecated.rb +26 -17
  77. data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +2 -2
  78. data/lib/sequel/extensions/auto_literal_strings.rb +74 -0
  79. data/lib/sequel/extensions/from_block.rb +1 -0
  80. data/lib/sequel/extensions/graph_each.rb +1 -1
  81. data/lib/sequel/extensions/identifier_mangling.rb +2 -2
  82. data/lib/sequel/extensions/migration.rb +28 -4
  83. data/lib/sequel/extensions/no_auto_literal_strings.rb +2 -0
  84. data/lib/sequel/extensions/schema_dumper.rb +4 -4
  85. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +5 -3
  86. data/lib/sequel/extensions/set_overrides.rb +2 -0
  87. data/lib/sequel/extensions/split_array_nil.rb +2 -2
  88. data/lib/sequel/extensions/virtual_row_method_block.rb +44 -0
  89. data/lib/sequel/model.rb +11 -7
  90. data/lib/sequel/model/associations.rb +5 -7
  91. data/lib/sequel/model/base.rb +47 -45
  92. data/lib/sequel/model/dataset_module.rb +9 -14
  93. data/lib/sequel/model/plugins.rb +3 -0
  94. data/lib/sequel/no_core_ext.rb +1 -0
  95. data/lib/sequel/plugins/blacklist_security.rb +1 -1
  96. data/lib/sequel/plugins/boolean_subsets.rb +7 -5
  97. data/lib/sequel/plugins/class_table_inheritance.rb +47 -10
  98. data/lib/sequel/plugins/dataset_associations.rb +1 -1
  99. data/lib/sequel/plugins/def_dataset_method.rb +90 -0
  100. data/lib/sequel/plugins/finder.rb +240 -0
  101. data/lib/sequel/plugins/inverted_subsets.rb +19 -12
  102. data/lib/sequel/plugins/many_through_many.rb +1 -1
  103. data/lib/sequel/plugins/nested_attributes.rb +1 -1
  104. data/lib/sequel/plugins/schema.rb +1 -1
  105. data/lib/sequel/plugins/single_table_inheritance.rb +7 -1
  106. data/lib/sequel/plugins/subset_conditions.rb +11 -3
  107. data/lib/sequel/plugins/whitelist_security.rb +118 -0
  108. data/lib/sequel/sql.rb +80 -36
  109. data/lib/sequel/timezones.rb +2 -0
  110. data/lib/sequel/version.rb +1 -1
  111. data/spec/adapters/mssql_spec.rb +20 -0
  112. data/spec/adapters/mysql_spec.rb +1 -1
  113. data/spec/adapters/oracle_spec.rb +12 -8
  114. data/spec/adapters/postgres_spec.rb +1 -1
  115. data/spec/adapters/spec_helper.rb +1 -1
  116. data/spec/adapters/sqlite_spec.rb +36 -34
  117. data/spec/core/connection_pool_spec.rb +2 -1
  118. data/spec/core/database_spec.rb +87 -9
  119. data/spec/core/dataset_spec.rb +501 -129
  120. data/spec/core/deprecated_spec.rb +1 -1
  121. data/spec/core/expression_filters_spec.rb +146 -60
  122. data/spec/core/mock_adapter_spec.rb +1 -1
  123. data/spec/core/object_graph_spec.rb +61 -9
  124. data/spec/core/placeholder_literalizer_spec.rb +20 -2
  125. data/spec/core/schema_generator_spec.rb +6 -6
  126. data/spec/core/schema_spec.rb +54 -5
  127. data/spec/core_extensions_spec.rb +122 -18
  128. data/spec/deprecation_helper.rb +27 -2
  129. data/spec/extensions/_deprecated_identifier_mangling_spec.rb +6 -6
  130. data/spec/extensions/association_proxies_spec.rb +2 -2
  131. data/spec/extensions/auto_literal_strings_spec.rb +212 -0
  132. data/spec/extensions/blacklist_security_spec.rb +1 -0
  133. data/spec/extensions/class_table_inheritance_spec.rb +1037 -39
  134. data/spec/extensions/column_select_spec.rb +20 -8
  135. data/spec/extensions/columns_introspection_spec.rb +3 -3
  136. data/spec/extensions/core_refinements_spec.rb +29 -12
  137. data/spec/extensions/dataset_associations_spec.rb +12 -12
  138. data/spec/extensions/def_dataset_method_spec.rb +100 -0
  139. data/spec/extensions/error_sql_spec.rb +1 -1
  140. data/spec/extensions/finder_spec.rb +260 -0
  141. data/spec/extensions/graph_each_spec.rb +2 -2
  142. data/spec/extensions/identifier_mangling_spec.rb +14 -8
  143. data/spec/extensions/inverted_subsets_spec.rb +4 -4
  144. data/spec/extensions/lazy_attributes_spec.rb +7 -0
  145. data/spec/extensions/many_through_many_spec.rb +38 -14
  146. data/spec/extensions/nested_attributes_spec.rb +18 -6
  147. data/spec/extensions/no_auto_literal_strings_spec.rb +1 -1
  148. data/spec/extensions/pg_enum_spec.rb +16 -1
  149. data/spec/extensions/pg_interval_spec.rb +11 -2
  150. data/spec/extensions/pg_loose_count_spec.rb +5 -0
  151. data/spec/extensions/pg_row_spec.rb +25 -0
  152. data/spec/extensions/prepared_statements_spec.rb +10 -1
  153. data/spec/extensions/query_spec.rb +2 -2
  154. data/spec/extensions/schema_dumper_spec.rb +2 -2
  155. data/spec/extensions/schema_spec.rb +2 -2
  156. data/spec/extensions/set_overrides_spec.rb +7 -3
  157. data/spec/extensions/sql_expr_spec.rb +0 -1
  158. data/spec/extensions/subset_conditions_spec.rb +6 -6
  159. data/spec/extensions/table_select_spec.rb +24 -12
  160. data/spec/extensions/to_dot_spec.rb +4 -4
  161. data/spec/extensions/whitelist_security_spec.rb +131 -0
  162. data/spec/integration/dataset_test.rb +9 -5
  163. data/spec/integration/model_test.rb +2 -0
  164. data/spec/integration/plugin_test.rb +2 -2
  165. data/spec/integration/spec_helper.rb +1 -1
  166. data/spec/model/associations_spec.rb +39 -11
  167. data/spec/model/base_spec.rb +44 -24
  168. data/spec/model/class_dataset_methods_spec.rb +18 -16
  169. data/spec/model/dataset_methods_spec.rb +4 -4
  170. data/spec/model/eager_loading_spec.rb +84 -24
  171. data/spec/model/model_spec.rb +97 -63
  172. data/spec/model/record_spec.rb +21 -13
  173. metadata +13 -2
@@ -23,6 +23,7 @@ could conceivably be abused to do so:
23
23
  * Sequel.def_adapter_method (private)
24
24
  * Sequel::SQL::Expression.to_s_method (private)
25
25
  * Sequel::Plugins::HookClassMethods::ClassMethods#add_hook_type
26
+ * Sequel::Plugins.def_dataset_methods
26
27
 
27
28
  As long as you don't call those with user input, you should not be
28
29
  vulnerable to code execution.
@@ -196,6 +197,14 @@ for plain strings as literal strings in update methods.
196
197
  The Sequel::Dataset#lock_style and Sequel::Model#lock! methods also treat
197
198
  an input string as SQL code. This method should not be called with user input.
198
199
 
200
+ ==== SQL Fragment passed to Virtual Row #` method
201
+
202
+ Virtual row blocks currently support a #` method for using literal SQL:
203
+
204
+ DB[:table].where{a > `some SQL`}
205
+
206
+ This method should not be called with user input.
207
+
199
208
  ==== SQL Type Names
200
209
 
201
210
  In general, most places where Sequel needs to use an SQL type that should
@@ -239,8 +239,8 @@ If the database supports window functions, Sequel can handle them by calling the
239
239
  DB[:albums].select{function(:col1).over(:partition=>col2, :order=>col3)}
240
240
  # SELECT function(col1) OVER (PARTITION BY col2 ORDER BY col3) FROM albums
241
241
 
242
- DB[:albums].select{function(c1, c2).over(:partition=>[c3, c4], :order=>[c5, c6])}
243
- # SELECT function(c1, c2) OVER (PARTITION BY c3, c4 ORDER BY c5, c6) FROM albums
242
+ DB[:albums].select{function(c1, c2).over(:partition=>[c3, c4], :order=>[c5, c6.desc])}
243
+ # SELECT function(c1, c2) OVER (PARTITION BY c3, c4 ORDER BY c5, c6 DESC) FROM albums
244
244
 
245
245
  === Schema Qualified Functions
246
246
 
@@ -158,11 +158,11 @@ SEQUEL_DUPLICATE_COLUMNS_HANDLER :: Use the duplicate columns handler extension
158
158
  SEQUEL_ERROR_SQL :: Use the error_sql extension when running the specs
159
159
  SEQUEL_FREEZE_DATASETS :: Use the freeze_datasets extension when running the specs
160
160
  SEQUEL_FREEZE_DATABASE :: Freeze the database before running the integration specs
161
+ SEQUEL_IDENTIFIER_MANGLING :: Use the identifier_mangling extension when running the specs
161
162
  SEQUEL_MODEL_PREPARED_STATEMENTS :: Use the prepared_statements and prepared_statements_associations plugins when running the specs
162
163
  SEQUEL_NO_AUTO_LITERAL_STRINGS :: Use the no_auto_string_literals extension when running the specs
163
164
  SEQUEL_NO_CACHE_ASSOCIATIONS :: Don't cache association metadata when running the specs
164
165
  SEQUEL_NO_CHECK_SQLS :: Don't check for specific SQL syntax when running the specs
165
- SEQUEL_NO_MANGLE :: Don't use the identifier_mangling extension when runnsing the specs
166
166
  SEQUEL_NO_PENDING :: Don't skip any specs, try running all specs (note, can cause lockups for some adapters)
167
167
  SEQUEL_NO_SPLIT_SYMBOLS :: Turn off symbol splitting when running the specs
168
168
  SKIPPED_TEST_WARN :: Warn when skipping any tests because libraries aren't available
@@ -496,7 +496,6 @@ This will make sure that all string columns in the model are validated to make s
496
496
  If you forget to call +super+, the validations that you defined in <tt>Sequel::Model</tt> will not be enforced. It's a good idea to call super whenever you override one of <tt>Sequel::Model</tt>'s methods, unless you specifically do not want the default behavior.
497
497
 
498
498
  == <tt>Sequel::Model::Errors</tt>
499
- '
500
499
  As mentioned earlier, <tt>Sequel::Model::Errors</tt> is a subclass of Hash with a few special methods, the most common of which are described here:
501
500
 
502
501
  === +add+
@@ -513,7 +512,7 @@ As mentioned earlier, <tt>Sequel::Model::Errors</tt> is a subclass of Hash with
513
512
 
514
513
  If you want to make some validations dependent upon the results of other validations, you may want to use +on+ inside your validates method:
515
514
 
516
- validates_integer(:release_date) if errors.on(:record_date)
515
+ validates_integer(:release_date) unless errors.on(:record_date)
517
516
 
518
517
  Here, you don't care about validating the release date if there were validation errors for the record date.
519
518
 
@@ -83,9 +83,11 @@ module Sequel
83
83
  CONVERSION_PROCS[i] = method
84
84
  end
85
85
  end
86
+ # CONVERSION_PROCS.freeze # SEQUEL5
86
87
 
87
88
  class Database < Sequel::Database
88
89
  DISCONNECT_ERROR_RE = /Communication link failure/
90
+ Sequel::Deprecation.deprecate_constant(self, :DISCONNECT_ERROR_RE)
89
91
 
90
92
  set_adapter_scheme :ado
91
93
 
@@ -201,6 +203,10 @@ module Sequel
201
203
  super
202
204
  end
203
205
 
206
+ def dataset_class_default
207
+ Dataset
208
+ end
209
+
204
210
  # The ADO adapter's default provider doesn't support transactions, since it
205
211
  # creates a new native connection for each query. So Sequel only attempts
206
212
  # to use transactions if an explicit :provider is given.
@@ -217,7 +223,7 @@ module Sequel
217
223
  end
218
224
 
219
225
  def disconnect_error?(e, opts)
220
- super || (e.is_a?(::WIN32OLERuntimeError) && e.message =~ DISCONNECT_ERROR_RE)
226
+ super || (e.is_a?(::WIN32OLERuntimeError) && e.message =~ /Communication link failure/)
221
227
  end
222
228
 
223
229
  def rollback_transaction(conn, opts=OPTS)
@@ -227,8 +233,7 @@ module Sequel
227
233
 
228
234
  class Dataset < Sequel::Dataset
229
235
  Database::DatasetClass = self
230
-
231
-
236
+ Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
232
237
 
233
238
  def fetch_rows(sql)
234
239
  execute(sql) do |recordset|
@@ -15,7 +15,7 @@ module Sequel
15
15
  :tables => 20,
16
16
  :views => 23,
17
17
  :foreign_keys => 27
18
- }
18
+ }#.freeze # SEQUEL5
19
19
 
20
20
  attr_reader :type, :criteria
21
21
 
@@ -42,7 +42,8 @@ module Sequel
42
42
  131 => "DECIMAL",
43
43
  201 => "TEXT",
44
44
  205 => "IMAGE"
45
- }
45
+ }#.freeze # SEQUEL5
46
+ #DATA_TYPE.each_value(&:freeze) # SEQUEL5
46
47
 
47
48
  def initialize(row)
48
49
  @row = row
@@ -90,7 +91,9 @@ module Sequel
90
91
  include Sequel::Database::SplitAlterTable
91
92
 
92
93
  DECIMAL_TYPE_RE = /decimal/io
94
+ Sequel::Deprecation.deprecate_constant(self, :DECIMAL_TYPE_RE)
93
95
  LAST_INSERT_ID = "SELECT @@IDENTITY".freeze
96
+ Sequel::Deprecation.deprecate_constant(self, :LAST_INSERT_ID)
94
97
 
95
98
  # Remove cached schema after altering a table, since otherwise it can be cached
96
99
  # incorrectly in the rename column case.
@@ -111,7 +114,8 @@ module Sequel
111
114
  synchronize(opts[:server]) do |conn|
112
115
  begin
113
116
  log_connection_yield(sql, conn){conn.Execute(sql)}
114
- res = log_connection_yield(LAST_INSERT_ID, conn){conn.Execute(LAST_INSERT_ID)}
117
+ last_insert_sql = "SELECT @@IDENTITY"
118
+ res = log_connection_yield(last_insert_sql, conn){conn.Execute(last_insert_sql)}
115
119
  res.getRows.transpose.each{|r| return r.shift}
116
120
  rescue ::WIN32OLERuntimeError => e
117
121
  raise_error(e)
@@ -240,7 +244,7 @@ module Sequel
240
244
  idx["COLUMN_NAME"] == row["COLUMN_NAME"] &&
241
245
  idx["PRIMARY_KEY"]
242
246
  },
243
- :type => if row.db_type =~ DECIMAL_TYPE_RE && row.scale == 0
247
+ :type => if row.db_type =~ /decimal/i && row.scale == 0
244
248
  :integer
245
249
  else
246
250
  schema_column_type(row.db_type)
@@ -12,6 +12,7 @@ module Sequel
12
12
  # Query to use to get the number of rows affected by an update or
13
13
  # delete query.
14
14
  ROWS_AFFECTED = "SELECT @@ROWCOUNT AS AffectedRows"
15
+ Sequel::Deprecation.deprecate_constant(self, :ROWS_AFFECTED)
15
16
 
16
17
  # Issue a separate query to get the rows modified. ADO appears to
17
18
  # use pass by reference with an integer variable, which is obviously
@@ -21,7 +22,8 @@ module Sequel
21
22
  synchronize(opts[:server]) do |conn|
22
23
  begin
23
24
  log_connection_yield(sql, conn){conn.Execute(sql)}
24
- res = log_connection_yield(ROWS_AFFECTED, conn){conn.Execute(ROWS_AFFECTED)}
25
+ rows_affected_sql = "SELECT @@ROWCOUNT AS AffectedRows"
26
+ res = log_connection_yield(rows_affected_sql, conn){conn.Execute(rows_affected_sql)}
25
27
  res.getRows.transpose.each{|r| return r.shift}
26
28
  rescue ::WIN32OLERuntimeError => e
27
29
  raise_error(e)
@@ -145,6 +145,10 @@ module Sequel
145
145
  o
146
146
  end
147
147
 
148
+ def dataset_class_default
149
+ Dataset
150
+ end
151
+
148
152
  # Both main error classes that Amalgalite raises
149
153
  def database_error_classes
150
154
  [::Amalgalite::Error, ::Amalgalite::SQLite3::Error]
@@ -156,6 +160,7 @@ module Sequel
156
160
  include ::Sequel::SQLite::DatasetMethods
157
161
 
158
162
  Database::DatasetClass = self
163
+ Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
159
164
 
160
165
  # Yield a hash for each row in the dataset.
161
166
  def fetch_rows(sql)
@@ -11,13 +11,15 @@ module Sequel
11
11
  ::Cubrid::DATE => lambda{|t| Date.new(t.year, t.month, t.day)},
12
12
  ::Cubrid::TIME => lambda{|t| SQLTime.create(t.hour, t.min, t.sec)},
13
13
  21 => lambda(&:to_i)
14
- }
14
+ }#.freeze # SEQUEL5
15
15
 
16
16
  class Database < Sequel::Database
17
17
  include Sequel::Cubrid::DatabaseMethods
18
18
 
19
19
  ROW_COUNT = "SELECT ROW_COUNT()".freeze
20
+ Sequel::Deprecation.deprecate_constant(self, :ROW_COUNT)
20
21
  LAST_INSERT_ID = "SELECT LAST_INSERT_ID()".freeze
22
+ Sequel::Deprecation.deprecate_constant(self, :LAST_INSERT_ID)
21
23
 
22
24
  set_adapter_scheme :cubrid
23
25
 
@@ -59,14 +61,14 @@ module Sequel
59
61
 
60
62
  # Work around bugs by using the ROW_COUNT function.
61
63
  begin
62
- r2 = conn.query(ROW_COUNT)
64
+ r2 = conn.query("SELECT ROW_COUNT()")
63
65
  r2.each{|a| return a.first.to_i}
64
66
  ensure
65
67
  r2.close if r2
66
68
  end
67
69
  when :insert
68
70
  begin
69
- r2 = conn.query(LAST_INSERT_ID)
71
+ r2 = conn.query("SELECT LAST_INSERT_ID()")
70
72
  r2.each{|a| return a.first.to_i}
71
73
  ensure
72
74
  r2.close if r2
@@ -99,11 +101,15 @@ module Sequel
99
101
  private
100
102
 
101
103
  def begin_transaction(conn, opts=OPTS)
102
- log_connection_yield(TRANSACTION_BEGIN, conn){conn.auto_commit = false}
104
+ log_connection_yield("Transaction.begin", conn){conn.auto_commit = false}
103
105
  end
104
106
 
105
107
  def commit_transaction(conn, opts=OPTS)
106
- log_connection_yield(TRANSACTION_COMMIT, conn){conn.commit}
108
+ log_connection_yield('Transaction.commit', conn){conn.commit}
109
+ end
110
+
111
+ def dataset_class_default
112
+ Dataset
107
113
  end
108
114
 
109
115
  def database_error_classes
@@ -119,21 +125,24 @@ module Sequel
119
125
  # This doesn't actually work, as the cubrid ruby driver
120
126
  # does not implement transactions correctly.
121
127
  def rollback_transaction(conn, opts=OPTS)
122
- log_connection_yield(TRANSACTION_ROLLBACK, conn){conn.rollback}
128
+ log_connection_yield('Transaction.rollback', conn){conn.rollback}
123
129
  end
124
130
  end
125
131
 
126
132
  class Dataset < Sequel::Dataset
127
133
  include Sequel::Cubrid::DatasetMethods
128
134
  COLUMN_INFO_NAME = "name".freeze
135
+ Sequel::Deprecation.deprecate_constant(self, :COLUMN_INFO_NAME)
129
136
  COLUMN_INFO_TYPE = "type_name".freeze
137
+ Sequel::Deprecation.deprecate_constant(self, :COLUMN_INFO_TYPE)
130
138
 
131
139
  Database::DatasetClass = self
140
+ Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
132
141
 
133
142
  def fetch_rows(sql)
134
143
  execute(sql) do |stmt|
135
144
  begin
136
- cols = stmt.column_info.map{|c| [output_identifier(c[COLUMN_INFO_NAME]), CUBRID_TYPE_PROCS[c[COLUMN_INFO_TYPE]]]}
145
+ cols = stmt.column_info.map{|c| [output_identifier(c["name"]), CUBRID_TYPE_PROCS[c["type_name"]]]}
137
146
  self.columns = cols.map(&:first)
138
147
  stmt.each do |r|
139
148
  row = {}
@@ -33,6 +33,7 @@ module Sequel
33
33
  # use a pool size at least as large as the pool size being used by Sequel.
34
34
  class Database < Sequel::Database
35
35
  DISCONNECT_ERROR_RE = /terminating connection due to administrator command/
36
+ Sequel::Deprecation.deprecate_constant(self, :DISCONNECT_ERROR_RE)
36
37
 
37
38
  set_adapter_scheme :do
38
39
 
@@ -121,9 +122,13 @@ module Sequel
121
122
  [::DataObjects::Error]
122
123
  end
123
124
 
125
+ def dataset_class_default
126
+ Dataset
127
+ end
128
+
124
129
  # Recognize DataObjects::ConnectionError instances as disconnect errors.
125
130
  def disconnect_error?(e, opts)
126
- super || (e.is_a?(::DataObjects::Error) && (e.is_a?(::DataObjects::ConnectionError) || e.message =~ DISCONNECT_ERROR_RE))
131
+ super || (e.is_a?(::DataObjects::Error) && (e.is_a?(::DataObjects::ConnectionError) || e.message =~ /terminating connection due to administrator command/))
127
132
  end
128
133
 
129
134
  # Execute SQL on the connection by creating a command first
@@ -141,6 +146,7 @@ module Sequel
141
146
  # Dataset class for Sequel::DataObjects::Database objects.
142
147
  class Dataset < Sequel::Dataset
143
148
  Database::DatasetClass = self
149
+ Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
144
150
 
145
151
  # Execute the SQL on the database and yield the rows as hashes
146
152
  # with symbol keys.
@@ -43,9 +43,13 @@ module Sequel
43
43
  # Dataset class for MySQL datasets accessed via DataObjects.
44
44
  class Dataset < DataObjects::Dataset
45
45
  include Sequel::MySQL::DatasetMethods
46
- APOS = Dataset::APOS
47
- APOS_RE = Dataset::APOS_RE
48
- DOUBLE_APOS = Dataset::DOUBLE_APOS
46
+
47
+ APOS = "'".freeze
48
+ Sequel::Deprecation.deprecate_constant(self, :APOS)
49
+ APOS_RE = /'/.freeze
50
+ Sequel::Deprecation.deprecate_constant(self, :APOS_RE)
51
+ DOUBLE_APOS = "''".freeze
52
+ Sequel::Deprecation.deprecate_constant(self, :DOUBLE_APOS)
49
53
 
50
54
  # The DataObjects MySQL driver uses the number of rows actually modified in the update,
51
55
  # instead of the number of matched by the filter.
@@ -57,7 +61,7 @@ module Sequel
57
61
 
58
62
  # do_mysql sets NO_BACKSLASH_ESCAPES, so use standard SQL string escaping
59
63
  def literal_string_append(sql, s)
60
- sql << APOS << s.gsub(APOS_RE, DOUBLE_APOS) << APOS
64
+ sql << "'" << s.gsub("'", "''") << "'"
61
65
  end
62
66
  end
63
67
  end
@@ -26,7 +26,7 @@ module Sequel
26
26
  :blob => ::Sequel::SQL::Blob.method(:new),
27
27
  :time => ::Sequel.method(:string_to_time),
28
28
  :date => ::Sequel.method(:string_to_date)
29
- }
29
+ }#.freeze # SEQUEL5
30
30
 
31
31
  # Wraps an underlying connection to DB2 using IBM_DB.
32
32
  class Connection
@@ -291,14 +291,14 @@ module Sequel
291
291
  # IBM_DB uses an autocommit setting instead of sending SQL queries.
292
292
  # So starting a transaction just turns autocommit off.
293
293
  def begin_transaction(conn, opts=OPTS)
294
- log_connection_yield(TRANSACTION_BEGIN, conn){conn.autocommit = false}
294
+ log_connection_yield('Transaction.begin', conn){conn.autocommit = false}
295
295
  set_transaction_isolation(conn, opts)
296
296
  end
297
297
 
298
298
  # This commits transaction in progress on the
299
299
  # connection and sets autocommit back on.
300
300
  def commit_transaction(conn, opts=OPTS)
301
- log_connection_yield(TRANSACTION_COMMIT, conn){conn.commit}
301
+ log_connection_yield('Transaction.commit', conn){conn.commit}
302
302
  end
303
303
 
304
304
  def database_error_classes
@@ -309,6 +309,10 @@ module Sequel
309
309
  exception.sqlstate
310
310
  end
311
311
 
312
+ def dataset_class_default
313
+ Dataset
314
+ end
315
+
312
316
  # Don't convert smallint to boolean for the metadata
313
317
  # dataset, since the DB2 metadata does not use
314
318
  # boolean columns, and some smallint columns are
@@ -340,7 +344,7 @@ module Sequel
340
344
  # This rolls back the transaction in progress on the
341
345
  # connection and sets autocommit back on.
342
346
  def rollback_transaction(conn, opts=OPTS)
343
- log_connection_yield(TRANSACTION_ROLLBACK, conn){conn.rollback}
347
+ log_connection_yield('Transaction.rollback', conn){conn.rollback}
344
348
  end
345
349
 
346
350
  # Convert smallint type to boolean if convert_smallint_to_bool is true
@@ -357,6 +361,7 @@ module Sequel
357
361
  include Sequel::DB2::DatasetMethods
358
362
 
359
363
  Database::DatasetClass = self
364
+ Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
360
365
 
361
366
  module CallableStatementMethods
362
367
  # Extend given dataset with this module so subselects inside subselects in
@@ -403,7 +408,7 @@ module Sequel
403
408
  type = :blob if type == :clob && Sequel::DB2.use_clob_as_blob
404
409
  columns << [key, cps[type]]
405
410
  end
406
- cols = columns.map{|c| c.at(0)}
411
+ cols = columns.map{|c| c[0]}
407
412
  self.columns = cols
408
413
 
409
414
  while res = stmt.fetch_array
@@ -28,6 +28,7 @@ module Sequel
28
28
  # The types to check for 0 scale to transform :decimal types
29
29
  # to :integer.
30
30
  DECIMAL_TYPE_RE = /number|numeric|decimal/io
31
+ Sequel::Deprecation.deprecate_constant(self, :DECIMAL_TYPE_RE)
31
32
 
32
33
  # Contains procs keyed on subadapter type that extend the
33
34
  # given database object so it supports the correct database type.
@@ -402,6 +403,10 @@ module Sequel
402
403
  true
403
404
  end
404
405
 
406
+ def dataset_class_default
407
+ Dataset
408
+ end
409
+
405
410
  # Raise a disconnect error if the SQL state of the cause of the exception indicates so.
406
411
  def disconnect_error?(exception, opts)
407
412
  cause = exception.respond_to?(:cause) ? exception.cause : exception
@@ -649,7 +654,7 @@ module Sequel
649
654
  s[:auto_increment] = h[:is_autoincrement] == "YES"
650
655
  end
651
656
  s[:max_length] = s[:column_size] if s[:type] == :string
652
- if s[:db_type] =~ DECIMAL_TYPE_RE && s[:scale] == 0
657
+ if s[:db_type] =~ /number|numeric|decimal/i && s[:scale] == 0
653
658
  s[:type] = :integer
654
659
  end
655
660
  schema_column_set_db_type(s)
@@ -704,6 +709,7 @@ module Sequel
704
709
  include StoredProcedures
705
710
 
706
711
  Database::DatasetClass = self
712
+ Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
707
713
 
708
714
  PreparedStatementMethods = prepared_statements_module(
709
715
  "sql = self; opts = Hash[opts]; opts[:arguments] = bind_arguments",
@@ -802,7 +808,7 @@ module Sequel
802
808
  i += 1
803
809
  cols << [output_identifier(meta.getColumnLabel(i)), i, convert ? type_convertor(map, meta, meta.getColumnType(i), i) : basic_type_convertor(map, meta, meta.getColumnType(i), i)]
804
810
  end
805
- self.columns = cols.map{|c| c.at(0)}
811
+ self.columns = cols.map{|c| c[0]}
806
812
 
807
813
  while result.next
808
814
  row = {}
@@ -23,8 +23,11 @@ module Sequel
23
23
  include Sequel::JDBC::Transactions
24
24
 
25
25
  TRANSACTION_BEGIN = 'Transaction.begin'.freeze
26
+ Sequel::Deprecation.deprecate_constant(self, :TRANSACTION_BEGIN)
26
27
  TRANSACTION_COMMIT = 'Transaction.commit'.freeze
28
+ Sequel::Deprecation.deprecate_constant(self, :TRANSACTION_COMMIT)
27
29
  TRANSACTION_ROLLBACK = 'Transaction.rollback'.freeze
30
+ Sequel::Deprecation.deprecate_constant(self, :TRANSACTION_ROLLBACK)
28
31
 
29
32
  # AS400 uses the :as400 database type.
30
33
  def database_type
@@ -59,19 +62,23 @@ module Sequel
59
62
  include EmulateOffsetWithRowNumber
60
63
 
61
64
  WILDCARD = Sequel::LiteralString.new('*').freeze
65
+ Sequel::Deprecation.deprecate_constant(self, :WILDCARD)
62
66
  FETCH_FIRST_ROW_ONLY = " FETCH FIRST ROW ONLY".freeze
67
+ Sequel::Deprecation.deprecate_constant(self, :FETCH_FIRST_ROW_ONLY)
63
68
  FETCH_FIRST = " FETCH FIRST ".freeze
69
+ Sequel::Deprecation.deprecate_constant(self, :FETCH_FIRST)
64
70
  ROWS_ONLY = " ROWS ONLY".freeze
71
+ Sequel::Deprecation.deprecate_constant(self, :ROWS_ONLY)
65
72
 
66
73
  # Modify the sql to limit the number of rows returned
67
74
  def select_limit_sql(sql)
68
75
  if l = @opts[:limit]
69
76
  if l == 1
70
- sql << FETCH_FIRST_ROW_ONLY
77
+ sql << " FETCH FIRST ROW ONLY"
71
78
  elsif l > 1
72
- sql << FETCH_FIRST
79
+ sql << " FETCH FIRST "
73
80
  literal_append(sql, l)
74
- sql << ROWS_ONLY
81
+ sql << " ROWS ONLY"
75
82
  end
76
83
  end
77
84
  end