sequel 4.46.0 → 4.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +210 -0
  3. data/Rakefile +1 -1
  4. data/doc/advanced_associations.rdoc +1 -1
  5. data/doc/opening_databases.rdoc +3 -2
  6. data/doc/release_notes/4.47.0.txt +56 -0
  7. data/doc/release_notes/4.48.0.txt +293 -0
  8. data/doc/release_notes/4.49.0.txt +222 -0
  9. data/lib/sequel/adapters/ado/access.rb +2 -1
  10. data/lib/sequel/adapters/do/postgres.rb +5 -2
  11. data/lib/sequel/adapters/ibmdb.rb +30 -8
  12. data/lib/sequel/adapters/jdbc/as400.rb +1 -1
  13. data/lib/sequel/adapters/jdbc/db2.rb +12 -3
  14. data/lib/sequel/adapters/jdbc/derby.rb +4 -5
  15. data/lib/sequel/adapters/jdbc/h2.rb +10 -1
  16. data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
  17. data/lib/sequel/adapters/jdbc/postgresql.rb +46 -20
  18. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
  19. data/lib/sequel/adapters/jdbc/sqlserver.rb +20 -6
  20. data/lib/sequel/adapters/jdbc.rb +39 -23
  21. data/lib/sequel/adapters/mock.rb +27 -19
  22. data/lib/sequel/adapters/mysql.rb +17 -16
  23. data/lib/sequel/adapters/mysql2.rb +5 -6
  24. data/lib/sequel/adapters/oracle.rb +5 -9
  25. data/lib/sequel/adapters/postgres.rb +91 -103
  26. data/lib/sequel/adapters/shared/db2.rb +22 -6
  27. data/lib/sequel/adapters/shared/mssql.rb +5 -4
  28. data/lib/sequel/adapters/shared/mysql.rb +79 -25
  29. data/lib/sequel/adapters/shared/oracle.rb +26 -3
  30. data/lib/sequel/adapters/shared/postgres.rb +199 -95
  31. data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
  32. data/lib/sequel/adapters/shared/sqlite.rb +72 -82
  33. data/lib/sequel/adapters/sqlanywhere.rb +4 -1
  34. data/lib/sequel/adapters/sqlite.rb +5 -3
  35. data/lib/sequel/adapters/swift/postgres.rb +5 -2
  36. data/lib/sequel/adapters/tinytds.rb +0 -5
  37. data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
  38. data/lib/sequel/adapters/utils/pg_types.rb +2 -76
  39. data/lib/sequel/ast_transformer.rb +1 -1
  40. data/lib/sequel/connection_pool/sharded_single.rb +1 -1
  41. data/lib/sequel/connection_pool/sharded_threaded.rb +1 -1
  42. data/lib/sequel/connection_pool/single.rb +2 -2
  43. data/lib/sequel/connection_pool/threaded.rb +2 -2
  44. data/lib/sequel/connection_pool.rb +9 -2
  45. data/lib/sequel/core.rb +2 -2
  46. data/lib/sequel/database/connecting.rb +8 -8
  47. data/lib/sequel/database/dataset.rb +6 -3
  48. data/lib/sequel/database/dataset_defaults.rb +14 -1
  49. data/lib/sequel/database/misc.rb +1 -1
  50. data/lib/sequel/database/query.rb +3 -0
  51. data/lib/sequel/database/schema_methods.rb +1 -1
  52. data/lib/sequel/dataset/actions.rb +72 -10
  53. data/lib/sequel/dataset/dataset_module.rb +58 -0
  54. data/lib/sequel/dataset/graph.rb +1 -1
  55. data/lib/sequel/dataset/misc.rb +1 -0
  56. data/lib/sequel/dataset/prepared_statements.rb +3 -3
  57. data/lib/sequel/dataset/query.rb +22 -11
  58. data/lib/sequel/dataset.rb +1 -1
  59. data/lib/sequel/exceptions.rb +8 -0
  60. data/lib/sequel/extensions/_model_pg_row.rb +5 -2
  61. data/lib/sequel/extensions/core_extensions.rb +4 -1
  62. data/lib/sequel/extensions/current_datetime_timestamp.rb +2 -1
  63. data/lib/sequel/extensions/date_arithmetic.rb +1 -0
  64. data/lib/sequel/extensions/duplicate_columns_handler.rb +3 -3
  65. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +3 -0
  66. data/lib/sequel/extensions/filter_having.rb +2 -0
  67. data/lib/sequel/extensions/freeze_datasets.rb +2 -0
  68. data/lib/sequel/extensions/from_block.rb +1 -1
  69. data/lib/sequel/extensions/graph_each.rb +2 -2
  70. data/lib/sequel/extensions/hash_aliases.rb +2 -0
  71. data/lib/sequel/extensions/identifier_mangling.rb +0 -7
  72. data/lib/sequel/extensions/meta_def.rb +2 -0
  73. data/lib/sequel/extensions/migration.rb +11 -8
  74. data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
  75. data/lib/sequel/extensions/null_dataset.rb +1 -0
  76. data/lib/sequel/extensions/pagination.rb +1 -1
  77. data/lib/sequel/extensions/pg_array.rb +207 -130
  78. data/lib/sequel/extensions/pg_hstore.rb +38 -20
  79. data/lib/sequel/extensions/pg_inet.rb +18 -6
  80. data/lib/sequel/extensions/pg_interval.rb +19 -12
  81. data/lib/sequel/extensions/pg_json.rb +25 -14
  82. data/lib/sequel/extensions/pg_json_ops.rb +2 -2
  83. data/lib/sequel/extensions/pg_range.rb +133 -100
  84. data/lib/sequel/extensions/pg_range_ops.rb +4 -3
  85. data/lib/sequel/extensions/pg_row.rb +68 -39
  86. data/lib/sequel/extensions/pg_row_ops.rb +11 -5
  87. data/lib/sequel/extensions/query_literals.rb +2 -0
  88. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +2 -0
  89. data/lib/sequel/extensions/s.rb +1 -1
  90. data/lib/sequel/extensions/schema_dumper.rb +29 -25
  91. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +3 -1
  92. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +83 -0
  93. data/lib/sequel/extensions/server_block.rb +32 -15
  94. data/lib/sequel/extensions/set_overrides.rb +2 -2
  95. data/lib/sequel/extensions/string_agg.rb +0 -1
  96. data/lib/sequel/extensions/symbol_aref.rb +0 -4
  97. data/lib/sequel/model/associations.rb +35 -7
  98. data/lib/sequel/model/base.rb +113 -87
  99. data/lib/sequel/model/dataset_module.rb +5 -43
  100. data/lib/sequel/model/errors.rb +2 -1
  101. data/lib/sequel/model/inflections.rb +17 -5
  102. data/lib/sequel/model.rb +26 -58
  103. data/lib/sequel/plugins/active_model.rb +2 -2
  104. data/lib/sequel/plugins/association_autoreloading.rb +2 -0
  105. data/lib/sequel/plugins/association_dependencies.rb +3 -3
  106. data/lib/sequel/plugins/association_pks.rb +73 -46
  107. data/lib/sequel/plugins/association_proxies.rb +1 -1
  108. data/lib/sequel/plugins/auto_validations.rb +6 -2
  109. data/lib/sequel/plugins/boolean_readers.rb +2 -2
  110. data/lib/sequel/plugins/boolean_subsets.rb +1 -1
  111. data/lib/sequel/plugins/caching.rb +19 -13
  112. data/lib/sequel/plugins/class_table_inheritance.rb +24 -13
  113. data/lib/sequel/plugins/column_conflicts.rb +7 -2
  114. data/lib/sequel/plugins/column_select.rb +3 -3
  115. data/lib/sequel/plugins/composition.rb +2 -2
  116. data/lib/sequel/plugins/csv_serializer.rb +8 -8
  117. data/lib/sequel/plugins/dataset_associations.rb +25 -13
  118. data/lib/sequel/plugins/defaults_setter.rb +13 -1
  119. data/lib/sequel/plugins/eager_each.rb +1 -1
  120. data/lib/sequel/plugins/force_encoding.rb +2 -2
  121. data/lib/sequel/plugins/hook_class_methods.rb +9 -12
  122. data/lib/sequel/plugins/identifier_columns.rb +2 -0
  123. data/lib/sequel/plugins/instance_filters.rb +3 -1
  124. data/lib/sequel/plugins/instance_hooks.rb +17 -9
  125. data/lib/sequel/plugins/json_serializer.rb +19 -12
  126. data/lib/sequel/plugins/lazy_attributes.rb +8 -7
  127. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +2 -0
  128. data/lib/sequel/plugins/modification_detection.rb +3 -0
  129. data/lib/sequel/plugins/nested_attributes.rb +6 -2
  130. data/lib/sequel/plugins/pg_array_associations.rb +5 -0
  131. data/lib/sequel/plugins/pg_row.rb +4 -2
  132. data/lib/sequel/plugins/pg_typecast_on_load.rb +2 -0
  133. data/lib/sequel/plugins/prepared_statements.rb +1 -0
  134. data/lib/sequel/plugins/rcte_tree.rb +4 -24
  135. data/lib/sequel/plugins/serialization.rb +9 -15
  136. data/lib/sequel/plugins/single_table_inheritance.rb +8 -3
  137. data/lib/sequel/plugins/split_values.rb +6 -5
  138. data/lib/sequel/plugins/static_cache.rb +31 -25
  139. data/lib/sequel/plugins/subset_conditions.rb +3 -1
  140. data/lib/sequel/plugins/table_select.rb +1 -1
  141. data/lib/sequel/plugins/touch.rb +4 -2
  142. data/lib/sequel/plugins/validation_class_methods.rb +5 -6
  143. data/lib/sequel/plugins/validation_helpers.rb +14 -8
  144. data/lib/sequel/plugins/xml_serializer.rb +4 -4
  145. data/lib/sequel/sql.rb +18 -9
  146. data/lib/sequel/version.rb +1 -1
  147. data/spec/adapters/db2_spec.rb +115 -14
  148. data/spec/adapters/mssql_spec.rb +4 -4
  149. data/spec/adapters/mysql_spec.rb +83 -29
  150. data/spec/adapters/oracle_spec.rb +28 -24
  151. data/spec/adapters/postgres_spec.rb +40 -24
  152. data/spec/adapters/sqlanywhere_spec.rb +88 -86
  153. data/spec/adapters/sqlite_spec.rb +29 -24
  154. data/spec/bin_spec.rb +7 -1
  155. data/spec/core/connection_pool_spec.rb +45 -14
  156. data/spec/core/database_spec.rb +155 -0
  157. data/spec/core/dataset_spec.rb +219 -36
  158. data/spec/core/schema_spec.rb +16 -0
  159. data/spec/core/spec_helper.rb +1 -0
  160. data/spec/core_extensions_spec.rb +6 -2
  161. data/spec/extensions/active_model_spec.rb +1 -1
  162. data/spec/extensions/arbitrary_servers_spec.rb +1 -1
  163. data/spec/extensions/association_pks_spec.rb +34 -2
  164. data/spec/extensions/auto_literal_strings_spec.rb +5 -1
  165. data/spec/extensions/auto_validations_spec.rb +2 -0
  166. data/spec/extensions/boolean_readers_spec.rb +1 -1
  167. data/spec/extensions/boolean_subsets_spec.rb +1 -1
  168. data/spec/extensions/class_table_inheritance_spec.rb +106 -19
  169. data/spec/extensions/column_conflicts_spec.rb +11 -0
  170. data/spec/extensions/column_select_spec.rb +1 -0
  171. data/spec/extensions/composition_spec.rb +13 -0
  172. data/spec/extensions/connection_validator_spec.rb +1 -1
  173. data/spec/extensions/dataset_associations_spec.rb +20 -8
  174. data/spec/extensions/defaults_setter_spec.rb +15 -1
  175. data/spec/extensions/filter_having_spec.rb +5 -3
  176. data/spec/extensions/hash_aliases_spec.rb +3 -1
  177. data/spec/extensions/identifier_columns_spec.rb +3 -1
  178. data/spec/extensions/implicit_subquery_spec.rb +4 -2
  179. data/spec/extensions/json_serializer_spec.rb +18 -0
  180. data/spec/extensions/lazy_attributes_spec.rb +3 -3
  181. data/spec/extensions/many_through_many_spec.rb +4 -4
  182. data/spec/extensions/meta_def_spec.rb +9 -0
  183. data/spec/extensions/migration_spec.rb +3 -3
  184. data/spec/extensions/nested_attributes_spec.rb +14 -3
  185. data/spec/extensions/no_auto_literal_strings_spec.rb +8 -4
  186. data/spec/extensions/null_dataset_spec.rb +1 -1
  187. data/spec/extensions/pg_array_associations_spec.rb +29 -18
  188. data/spec/extensions/pg_array_spec.rb +44 -25
  189. data/spec/extensions/pg_hstore_spec.rb +10 -0
  190. data/spec/extensions/pg_inet_spec.rb +26 -0
  191. data/spec/extensions/pg_interval_spec.rb +20 -0
  192. data/spec/extensions/pg_json_spec.rb +24 -0
  193. data/spec/extensions/pg_range_spec.rb +98 -14
  194. data/spec/extensions/pg_row_spec.rb +14 -4
  195. data/spec/extensions/pg_typecast_on_load_spec.rb +11 -9
  196. data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
  197. data/spec/extensions/query_literals_spec.rb +3 -1
  198. data/spec/extensions/schema_dumper_spec.rb +108 -94
  199. data/spec/extensions/sequel_3_dataset_methods_spec.rb +10 -6
  200. data/spec/extensions/sequel_4_dataset_methods_spec.rb +121 -0
  201. data/spec/extensions/serialization_spec.rb +1 -1
  202. data/spec/extensions/server_block_spec.rb +7 -0
  203. data/spec/extensions/single_table_inheritance_spec.rb +17 -1
  204. data/spec/extensions/spec_helper.rb +7 -1
  205. data/spec/extensions/static_cache_spec.rb +75 -24
  206. data/spec/extensions/string_agg_spec.rb +1 -1
  207. data/spec/extensions/touch_spec.rb +9 -0
  208. data/spec/extensions/validation_helpers_spec.rb +10 -5
  209. data/spec/extensions/whitelist_security_spec.rb +26 -0
  210. data/spec/integration/associations_test.rb +8 -0
  211. data/spec/integration/dataset_test.rb +45 -44
  212. data/spec/integration/model_test.rb +53 -4
  213. data/spec/integration/plugin_test.rb +28 -4
  214. data/spec/integration/prepared_statement_test.rb +3 -0
  215. data/spec/integration/schema_test.rb +21 -1
  216. data/spec/integration/transaction_test.rb +40 -40
  217. data/spec/model/association_reflection_spec.rb +43 -1
  218. data/spec/model/associations_spec.rb +29 -9
  219. data/spec/model/class_dataset_methods_spec.rb +20 -4
  220. data/spec/model/dataset_methods_spec.rb +12 -3
  221. data/spec/model/eager_loading_spec.rb +8 -8
  222. data/spec/model/model_spec.rb +45 -1
  223. data/spec/model/plugins_spec.rb +34 -0
  224. data/spec/model/record_spec.rb +1 -1
  225. data/spec/spec_config.rb +2 -0
  226. metadata +11 -4
  227. data/spec/adapters/firebird_spec.rb +0 -405
  228. data/spec/adapters/informix_spec.rb +0 -100
@@ -0,0 +1,222 @@
1
+ = Forward Compatibility
2
+
3
+ Sequel 4.49.0 will be the last minor release of Sequel 4. While the
4
+ vast majority of backwards incompatible changes in Sequel 5 have
5
+ deprecation warnings in 4.49.0, there are a few changes that do
6
+ not. Here is a brief list of changes coming in Sequel 5 that
7
+ do not have deprecation warnings (note that this list may not be
8
+ exhaustive):
9
+
10
+ * The {before,after,around}_validation hooks will always be called
11
+ when saving, even if the validate: false option is used. This
12
+ will allow you to use the before_validation hook to make changes
13
+ to the model instance that are required before validation and
14
+ before saving even if not validating. Currently, you would have
15
+ to use both a before_save and before_validation hook, which would
16
+ both be run on normal instance saving.
17
+
18
+ * Getting values for newly created model instances after insertion
19
+ now happens before after_create is called, instead of after.
20
+ This behavior is currently available via the before_after_save
21
+ plugin, and and will become the default behavior.
22
+
23
+ * Sequel will now immediately attempt to the connect to the database
24
+ when a Database instance is created, in order to fail fast. This
25
+ behavior is currently available via the test: true option, and
26
+ will become the default behavior. You can force not testing the
27
+ connection by using the test: false option.
28
+
29
+ * The validates_unique method in the validation_helpers plugin will
30
+ now only check for uniqueness by default if the record is new or
31
+ one of the related columns has been modified by default. You can
32
+ use only_if_modified: false to force the uniqueness check.
33
+
34
+ * Database schema methods and schema generator methods will return
35
+ nil instead of some internal value.
36
+
37
+ * Many cases where Sequel uses send internally will be switched to
38
+ public_send so they only call public methods, unless it is
39
+ specifically expected that they will call private methods.
40
+
41
+ * Model association hooks will be nil instead of empty arrays by
42
+ default. They will only be arrays if that hook has been set for
43
+ the association.
44
+
45
+ * Internal uses of instance_eval with a block will be changed to
46
+ instance_exec. This will allow them to be used with lambdas that
47
+ take no arguments. Unfortunately, it will break the case where a
48
+ lambda is currently used that takes one argument.
49
+
50
+ * Most internal constants will be frozen, unless there is a
51
+ requirement that they be modified at runtime.
52
+
53
+ * The @was_new instance variable set during model instance creation
54
+ will be removed.
55
+
56
+ = Deprecated Features
57
+
58
+ * Model association before callbacks returning false canceling the
59
+ action is now deprecated. The callbacks should now call
60
+ Model#cancel_action to cancel the action.
61
+
62
+ * Loading plugins by requiring them via sequel_#{plugin} is now
63
+ deprecated. Affected plugins should move the plugin file so it can
64
+ be required via sequel/plugins/#{plugin}.
65
+
66
+ * In the mock adapter, Dataset#autoid=, #_fetch=, and #numrows= are
67
+ now deprecated. They modified the dataset itself, which would not
68
+ work for frozen datasets. Dataset#with_autoid, #with_fetch,
69
+ and #with_numrows should be used instead, which return a modified
70
+ copy.
71
+
72
+ * In the null_dataset extension, Dataset#nullify! is now deprecated.
73
+ It modified the dataset itself, which would not work for frozen
74
+ datasets. Dataset#nullify should be used instead, which returns a
75
+ modified copy.
76
+
77
+ * Modifying the validation_helpers plugin DEFAULT_OPTIONS hash is now
78
+ deprecated. Any change to the default options should be done by
79
+ overriding the Model#default_validation_helpers_options private
80
+ method.
81
+
82
+ * Modifying ConnectionPool::CONNECTION_POOL_MAP to support an
83
+ external connection pool is now deprecated. To use an external
84
+ connection pool, pass the pool class via the :pool_class
85
+ Database option. Additionally, using a :pool_class option that
86
+ is not a class or a symbol for one of the default connection
87
+ pools is also deprecated.
88
+
89
+ * ConnectionPool#created_count is now deprecated. This method was
90
+ misnamed, as it was in alias to size, but the name implies it
91
+ returns how many connections have been created, as opposed to how
92
+ many connections are still in the pool.
93
+
94
+ * Sequel::SQL::Function#f is now deprecated, switch to using #name
95
+ instead.
96
+
97
+ * Sequel::SQL::AliasedExpression#aliaz is now deprecated, switch
98
+ to using #alias instead.
99
+
100
+ * The :eager_loading_predicate_key association option and
101
+ eager_loading_predicate_key association method are now deprecated.
102
+ The predicate_key option and method should be used instead.
103
+
104
+ * The cti_columns class method in the class_table_inheritance plugin
105
+ is now deprecated.
106
+
107
+ * The serialized_columns class method in the serialization plugin
108
+ is now deprecated.
109
+
110
+ * Having ds.join_table(:table, :cross, :a=>:b) be treated as an
111
+ inner join on MySQL is now deprecated.
112
+
113
+ * Sequel::IBMDB::Connection#prepared_statements= in the ibmdb
114
+ adapter is now deprecated.
115
+
116
+ * Additional internal constants are now deprecated.
117
+
118
+ = New Features
119
+
120
+ * Database#extend_datasets and Database#with_extend if given a block
121
+ now use a Dataset::DatasetModule instance instead of a plain Module
122
+ instance. Dataset::DatasetModule is a subset of
123
+ Model::DatasetModule, and allows for the easy creation of dataset
124
+ methods that can perform caching for frozen datasets.
125
+
126
+ Defining dataset methods is done by calling methods with the same
127
+ name as dataset methods inside the extend_datasets or with_extend
128
+ block:
129
+
130
+ DB.extend_datasets do
131
+ order :by_id, :id
132
+ select :with_id_and_name, :id, :name
133
+ where :active, :active
134
+ end
135
+
136
+ This is equivalent to:
137
+
138
+ DB.extend_datasets do
139
+ def by_id
140
+ order(:id)
141
+ end
142
+
143
+ def with_id_and_name
144
+ select(:id, :name)
145
+ end
146
+
147
+ def active
148
+ where(:active)
149
+ end
150
+ end
151
+
152
+ Except that for frozen datasets (the default in Sequel 5),
153
+ code like:
154
+
155
+ 100.times do
156
+ DB[:table].active.with_id_and_name.by_id
157
+ end
158
+
159
+ will only allocate 4 datasets instead of 400, and can be
160
+ 3-4 times faster.
161
+
162
+ * Dataset#where_{all,each,single_value} are now core dataset methods
163
+ instead of just model dataset methods. These methods allow you to
164
+ replace:
165
+
166
+ dataset.where(cond).all
167
+ dataset.where(cond).each{}
168
+ dataset.where(cond).single_value
169
+
170
+ with:
171
+
172
+ dataset.where_all(cond)
173
+ dataset.where_each(cond){}
174
+ dataset.where_single_value(cond)
175
+
176
+ The advantage of #where_{all,each,single_value} is that frozen
177
+ datasets can take potentially advantage of caching and perform
178
+ 70%-300% faster.
179
+
180
+ * Oracle 12 native limit/offset support is now supported, which
181
+ in particular makes offset queries much faster as they don't
182
+ have to be emulated using the row_number window function.
183
+
184
+ * Dataset#paged_each in the mysql2 adapter now supports a
185
+ :stream=>false option to disable streaming and fallback to
186
+ the default implementation.
187
+
188
+ * The postgres adapter now supports the :sslrootcert option
189
+ directly, you no longer need to specify it using the
190
+ :driver_options hash.
191
+
192
+ * The single_table_inheritance plugin now supports an
193
+ sti_class_from_sti_key method for getting the appropriate
194
+ subclass for the given key.
195
+
196
+ = Other Improvements
197
+
198
+ * Using the dataset_associations plugin with a many_through_many
199
+ association that joins to the same table multiple times is now
200
+ handled correctly by automatically aliasing the table
201
+ appropriately.
202
+
203
+ * On Ruby 2.1+, Sequel::Error#cause will use wrapped_exception
204
+ if one is set. This doesn't result in different behavior in
205
+ most cases, but it can in cases where nested exception handling
206
+ is done and Sequel tries to raise the most relevant exception.
207
+
208
+ * Using the composition plugin with the :mapping option now works
209
+ correctly when using the column_conflicts plugin.
210
+
211
+ * The validation_helpers plugin's validates_max_length method
212
+ now correctly gets the default :nil_message option from
213
+ the default_validation_helpers_options method instead of
214
+ looking at the plugin defaults.
215
+
216
+ * The duplicate_columns_handler extension no longer makes the
217
+ Dataset#columns= method public.
218
+
219
+ * On H2 1.4+, alter_table add_primary_key now works correctly.
220
+
221
+ * The jdbc/sqlserver adapter's datetimeoffset type handling now
222
+ works with more JDBC driver versions.
@@ -299,7 +299,8 @@ module Sequel
299
299
 
300
300
  def fetch_ado_schema(type, criteria=[])
301
301
  execute_open_ado_schema(type, criteria) do |s|
302
- cols = s.Fields.extend(Enumerable).map(&:Name)
302
+ cols = []
303
+ s.Fields.each{|f| cols << f.Name}
303
304
  s.getRows.transpose.each do |r|
304
305
  row = {}
305
306
  cols.each{|c| row[c] = r.shift}
@@ -4,8 +4,6 @@ Sequel::DataObjects.load_driver 'do_postgres'
4
4
  Sequel.require 'adapters/shared/postgres'
5
5
 
6
6
  module Sequel
7
- Postgres::CONVERTED_EXCEPTIONS << ::DataObjects::Error
8
-
9
7
  module DataObjects
10
8
  Sequel.synchronize do
11
9
  DATABASE_SETUP[:postgres] = proc do |db|
@@ -31,6 +29,11 @@ module Sequel
31
29
 
32
30
  private
33
31
 
32
+ DATABASE_ERROR_CLASSES = [::DataObjects::Error].freeze
33
+ def database_error_classes
34
+ DATABASE_ERROR_CLASSES
35
+ end
36
+
34
37
  # Extend the adapter with the DataObjects PostgreSQL AdapterMethods
35
38
  def setup_connection(conn)
36
39
  conn = super(conn)
@@ -6,12 +6,17 @@ Sequel.require 'adapters/shared/db2'
6
6
  module Sequel
7
7
 
8
8
  module IBMDB
9
+ # SEQUEL5: Remove
9
10
  @convert_smallint_to_bool = true
10
-
11
11
  class << self
12
- # Whether to convert smallint values to bool, true by default.
13
- # Can also be overridden per dataset.
14
- attr_accessor :convert_smallint_to_bool
12
+ def convert_smallint_to_bool
13
+ Sequel::Deprecation.deprecate("Sequel::IBMDB.convert_smallint_to_bool", "Call this method on the Database instance")
14
+ @convert_smallint_to_bool
15
+ end
16
+ def convert_smallint_to_bool=(v)
17
+ Sequel::Deprecation.deprecate("Sequel::IBMDB.convert_smallint_to_bool=", "Call this method on the Database instance")
18
+ @convert_smallint_to_bool = v
19
+ end
15
20
  end
16
21
 
17
22
  tt = Class.new do
@@ -32,7 +37,12 @@ module Sequel
32
37
  class Connection
33
38
  # A hash with prepared statement name symbol keys, where each value is
34
39
  # a two element array with an sql string and cached Statement value.
35
- attr_accessor :prepared_statements
40
+ attr_reader :prepared_statements
41
+
42
+ def prepared_statements=(v)
43
+ Sequel::Deprecation.deprecate("Sequel::IBMDB::Connection#prepared_statements=", "Use replace on the hash instead of reassigning it")
44
+ @prepared_statements = v
45
+ end
36
46
 
37
47
  # Error class for exceptions raised by the connection.
38
48
  class Error < StandardError
@@ -187,6 +197,16 @@ module Sequel
187
197
 
188
198
  # Hash of connection procs for converting
189
199
  attr_reader :conversion_procs
200
+
201
+ # Whether to convert smallint values to bool for this Database instance
202
+ #attr_accessor :convert_smallint_to_bool # SEQUEL5
203
+
204
+ # SEQUEL5: Remove
205
+ attr_writer :convert_smallint_to_bool
206
+ def convert_smallint_to_bool
207
+ v = @convert_smallint_to_bool
208
+ v.nil? ? Sequel::IBMDB.instance_variable_get(:@convert_smallint_to_bool) : v
209
+ end
190
210
 
191
211
  # Create a new connection object for the given server.
192
212
  def connect(server)
@@ -284,6 +304,7 @@ module Sequel
284
304
  end
285
305
 
286
306
  def adapter_initialize
307
+ #@convert_smallint_to_bool = typecast_value_boolean(opts.fetch(:convert_smallint_to_bool, true)) # SEQUEL5
287
308
  @conversion_procs = DB2_TYPES.dup
288
309
  @conversion_procs[:timestamp] = method(:to_application_timestamp)
289
310
  end
@@ -349,7 +370,7 @@ module Sequel
349
370
 
350
371
  # Convert smallint type to boolean if convert_smallint_to_bool is true
351
372
  def schema_column_type(db_type)
352
- if Sequel::IBMDB.convert_smallint_to_bool && db_type =~ /smallint/i
373
+ if convert_smallint_to_bool && db_type =~ /smallint/i
353
374
  :boolean
354
375
  else
355
376
  super
@@ -379,13 +400,14 @@ module Sequel
379
400
 
380
401
  # Override the default IBMDB.convert_smallint_to_bool setting for this dataset.
381
402
  def convert_smallint_to_bool=(v)
403
+ Sequel::Deprecation.deprecate("Sequel::IBMDB::Dataset#convert_smallint_to_bool=", "Call with_convert_smallint_to_bool instead, which returns a modified copy instead of modifying the object")
382
404
  @opts[:convert_smallint_to_bool] = v
383
405
  end
384
406
 
385
407
  # Whether to convert smallint to boolean arguments for this dataset.
386
408
  # Defaults to the IBMDB module setting.
387
409
  def convert_smallint_to_bool
388
- opts.has_key?(:convert_smallint_to_bool) ? opts[:convert_smallint_to_bool] : IBMDB.convert_smallint_to_bool
410
+ opts.has_key?(:convert_smallint_to_bool) ? opts[:convert_smallint_to_bool] : db.convert_smallint_to_bool
389
411
  end
390
412
 
391
413
  # Return a cloned dataset with the convert_smallint_to_bool option set.
@@ -405,7 +427,7 @@ module Sequel
405
427
  type = stmt.field_type(i).downcase.to_sym
406
428
  # decide if it is a smallint from precision
407
429
  type = :boolean if type == :int && convert && stmt.field_precision(i) < 8
408
- type = :blob if type == :clob && Sequel::DB2.use_clob_as_blob
430
+ type = :blob if type == :clob && db.use_clob_as_blob
409
431
  columns << [key, cps[type]]
410
432
  end
411
433
  cols = columns.map{|c| c[0]}
@@ -1,6 +1,6 @@
1
1
  # frozen-string-literal: true
2
2
 
3
- Sequel::Deprecation.deprecate("The jdbc/as400 adapter", "Please consider maintaining it yourself as an external gem if you want to continue using it")
3
+ Sequel::Deprecation.deprecate("The jdbc/as400 adapter", "This gem will replace it: https://github.com/ecraft/sequel-jdbc-as400")
4
4
 
5
5
  Sequel::JDBC.load_driver('com.ibm.as400.access.AS400JDBCDriver')
6
6
  Sequel.require 'adapters/jdbc/transactions'
@@ -35,7 +35,8 @@ module Sequel
35
35
  end
36
36
  end
37
37
 
38
- class TypeConvertor
38
+ # SEQUEL5: Remove
39
+ class Type_Convertor
39
40
  def DB2Clob(r, i)
40
41
  if v = r.getClob(i)
41
42
  v = v.getSubString(1, v.length)
@@ -63,7 +64,7 @@ module Sequel
63
64
  def set_ps_arg(cps, arg, i)
64
65
  case arg
65
66
  when Sequel::SQL::Blob
66
- if ::Sequel::DB2.use_clob_as_blob
67
+ if use_clob_as_blob
67
68
  cps.setString(i, arg)
68
69
  else
69
70
  super
@@ -91,7 +92,15 @@ module Sequel
91
92
  super
92
93
  map = @type_convertor_map
93
94
  types = Java::JavaSQL::Types
94
- map[types::NCLOB] = map[types::CLOB] = TypeConvertor::INSTANCE.method(:DB2Clob)
95
+ map[types::NCLOB] = map[types::CLOB] = method(:convert_clob)
96
+ end
97
+
98
+ def convert_clob(r, i)
99
+ if v = r.getClob(i)
100
+ v = v.getSubString(1, v.length)
101
+ v = Sequel::SQL::Blob.new(v) if use_clob_as_blob
102
+ v
103
+ end
95
104
  end
96
105
  end
97
106
 
@@ -54,7 +54,7 @@ module Sequel
54
54
  end
55
55
  end
56
56
 
57
- # Derby supports transaction DDL statements.
57
+ # Derby supports transactional DDL statements.
58
58
  def supports_transactional_ddl?
59
59
  true
60
60
  end
@@ -227,8 +227,7 @@ module Sequel
227
227
  Sequel::Deprecation.deprecate_constant(self, :EMULATED_FUNCTION_MAP)
228
228
 
229
229
  # Derby doesn't support an expression between CASE and WHEN,
230
- # so remove
231
- # conditions.
230
+ # so remove conditions.
232
231
  def case_expression_sql_append(sql, ce)
233
232
  super(sql, ce.with_merged_expression)
234
233
  end
@@ -300,7 +299,7 @@ module Sequel
300
299
  end
301
300
 
302
301
  # Derby uses an expression yielding false for false values.
303
- # Newer versions can use the FALSE literal, but the latest gem version cannot.
302
+ # Newer versions can use the FALSE literal, but older versions cannot.
304
303
  def literal_false
305
304
  if db.svn_version >= 1040133
306
305
  'FALSE'
@@ -315,7 +314,7 @@ module Sequel
315
314
  end
316
315
 
317
316
  # Derby uses an expression yielding true for true values.
318
- # Newer versions can use the TRUE literal, but the latest gem version cannot.
317
+ # Newer versions can use the TRUE literal, but older versions cannot.
319
318
  def literal_true
320
319
  if db.svn_version >= 1040133
321
320
  'TRUE'
@@ -30,6 +30,15 @@ module Sequel
30
30
  :h2
31
31
  end
32
32
 
33
+ def freeze
34
+ h2_version
35
+ super
36
+ end
37
+
38
+ def h2_version
39
+ @h2_version ||= get(Sequel.function(:H2VERSION))
40
+ end
41
+
33
42
  # Rollback an existing prepared transaction with the given transaction
34
43
  # identifier string.
35
44
  def rollback_prepared_transaction(transaction_id, opts=OPTS)
@@ -84,7 +93,7 @@ module Sequel
84
93
 
85
94
  sqls = [super(table, op)]
86
95
 
87
- if pk && op[:type] != :identity
96
+ if pk && (h2_version >= '1.4' || op[:type] != :identity)
88
97
  sqls << "ALTER TABLE #{quote_schema_table(table)} ADD PRIMARY KEY (#{quote_identifier(op[:name])})"
89
98
  end
90
99
 
@@ -14,7 +14,8 @@ module Sequel
14
14
  end
15
15
  end
16
16
 
17
- class TypeConvertor
17
+ # SEQUEL5: Remove
18
+ class Type_Convertor
18
19
  JAVA_BIG_DECIMAL_CONSTRUCTOR = java.math.BigDecimal.java_class.constructor(Java::long).method(:new_instance)
19
20
 
20
21
  def OracleDecimal(r, i)
@@ -31,6 +32,19 @@ module Sequel
31
32
 
32
33
  # Database and Dataset support for Oracle databases accessed via JDBC.
33
34
  module Oracle
35
+ JAVA_BIG_DECIMAL_CONSTRUCTOR = java.math.BigDecimal.java_class.constructor(Java::long).method(:new_instance)
36
+
37
+ def self.OracleDecimal(r, i)
38
+ if v = r.getBigDecimal(i)
39
+ i = v.long_value
40
+ if v == JAVA_BIG_DECIMAL_CONSTRUCTOR.call(i)
41
+ i
42
+ else
43
+ BigDecimal.new(v.to_string)
44
+ end
45
+ end
46
+ end
47
+
34
48
  # Instance methods for Oracle Database objects accessed via JDBC.
35
49
  module DatabaseMethods
36
50
  PRIMARY_KEY_INDEX_RE = /\Asys_/i.freeze
@@ -110,7 +124,7 @@ module Sequel
110
124
 
111
125
  def setup_type_convertor_map
112
126
  super
113
- @type_convertor_map[:OracleDecimal] = TypeConvertor::INSTANCE.method(:OracleDecimal)
127
+ @type_convertor_map[:OracleDecimal] = Oracle.method(:OracleDecimal)
114
128
  end
115
129
  end
116
130
 
@@ -4,8 +4,6 @@ Sequel::JDBC.load_driver('org.postgresql.Driver', :Postgres)
4
4
  Sequel.require 'adapters/shared/postgres'
5
5
 
6
6
  module Sequel
7
- Postgres::CONVERTED_EXCEPTIONS << NativeException
8
-
9
7
  module JDBC
10
8
  Sequel.synchronize do
11
9
  DATABASE_SETUP[:postgresql] = proc do |db|
@@ -15,11 +13,27 @@ module Sequel
15
13
  end
16
14
  end
17
15
 
18
- class TypeConvertor
16
+ # SEQUEL5: Remove
17
+ class Type_Convertor
18
+ def RubyPGArray(r, i)
19
+ if v = r.getArray(i)
20
+ v.array.to_ary
21
+ end
22
+ end
23
+ def RubyPGHstore(r, i)
24
+ if v = r.getObject(i)
25
+ v.to_hash
26
+ end
27
+ end
28
+ end
29
+
30
+ # Adapter, Database, and Dataset support for accessing a PostgreSQL
31
+ # database via JDBC.
32
+ module Postgres
19
33
  # Return PostgreSQL array types as ruby Arrays instead of
20
34
  # JDBC PostgreSQL driver-specific array type. Only used if the
21
35
  # database does not have a conversion proc for the type.
22
- def RubyPGArray(r, i)
36
+ def self.RubyPGArray(r, i)
23
37
  if v = r.getArray(i)
24
38
  v.array.to_ary
25
39
  end
@@ -28,16 +42,12 @@ module Sequel
28
42
  # Return PostgreSQL hstore types as ruby Hashes instead of
29
43
  # Java HashMaps. Only used if the database does not have a
30
44
  # conversion proc for the type.
31
- def RubyPGHstore(r, i)
45
+ def self.RubyPGHstore(r, i)
32
46
  if v = r.getObject(i)
33
47
  v.to_hash
34
48
  end
35
49
  end
36
- end
37
50
 
38
- # Adapter, Database, and Dataset support for accessing a PostgreSQL
39
- # database via JDBC.
40
- module Postgres
41
51
  # Methods to add to Database instances that access PostgreSQL via
42
52
  # JDBC.
43
53
  module DatabaseMethods
@@ -50,6 +60,12 @@ module Sequel
50
60
  db.send(:initialize_postgres_adapter)
51
61
  end
52
62
 
63
+ # Remove any current entry for the oid in the oid_convertor_map.
64
+ def add_conversion_proc(oid, *)
65
+ super
66
+ Sequel.synchronize{@oid_convertor_map.delete(oid)}
67
+ end
68
+
53
69
  # See Sequel::Postgres::Adapter#copy_into
54
70
  def copy_into(table, opts=OPTS)
55
71
  data = opts[:data]
@@ -61,7 +77,7 @@ module Sequel
61
77
  raise Error, "Must provide either a :data option or a block to copy_into"
62
78
  end
63
79
 
64
- synchronize(opts) do |conn|
80
+ synchronize(opts[:server]) do |conn|
65
81
  begin
66
82
  copy_manager = org.postgresql.copy.CopyManager.new(conn)
67
83
  copier = copy_manager.copy_in(copy_into_sql(table, opts))
@@ -73,7 +89,7 @@ module Sequel
73
89
  data.each { |d| copier.writeToCopy(d.to_java_bytes, 0, d.length) }
74
90
  end
75
91
  rescue Exception => e
76
- copier.cancelCopy
92
+ copier.cancelCopy if copier
77
93
  raise
78
94
  ensure
79
95
  unless e
@@ -105,8 +121,12 @@ module Sequel
105
121
  end
106
122
  b
107
123
  end
124
+ rescue => e
125
+ raise_error(e, :disconnect=>true)
108
126
  ensure
109
- raise DatabaseDisconnectError, "disconnecting as a partial COPY may leave the connection in an unusable state" if buf
127
+ if buf && !e
128
+ raise DatabaseDisconnectError, "disconnecting as a partial COPY may leave the connection in an unusable state"
129
+ end
110
130
  end
111
131
  end
112
132
  end
@@ -122,19 +142,24 @@ module Sequel
122
142
  else
123
143
  false
124
144
  end
125
- Sequel.synchronize{@oid_convertor_map[oid] = conv}
145
+ Sequel.synchronize{@oid_convertor_map[oid] = conv}
126
146
  end
127
147
  conv
128
148
  end
129
149
 
130
150
  private
131
151
 
132
- # Clear oid convertor map cache when conversion procs are updated.
152
+ # SEQUEL5: Remove
133
153
  def conversion_procs_updated
134
154
  super
135
155
  Sequel.synchronize{@oid_convertor_map = {}}
136
156
  end
137
157
 
158
+ DATABASE_ERROR_CLASSES = [NativeException].freeze
159
+ def database_error_classes
160
+ DATABASE_ERROR_CLASSES
161
+ end
162
+
138
163
  def disconnect_error?(exception, opts)
139
164
  super || exception.message =~ /\A(This connection has been closed\.|FATAL: terminating connection due to administrator command|An I\/O error occurred while sending to the backend\.)\z/
140
165
  end
@@ -178,8 +203,6 @@ module Sequel
178
203
  def setup_type_convertor_map
179
204
  super
180
205
  @oid_convertor_map = {}
181
- @type_convertor_map[:RubyPGArray] = TypeConvertor::INSTANCE.method(:RubyPGArray)
182
- @type_convertor_map[:RubyPGHstore] = TypeConvertor::INSTANCE.method(:RubyPGHstore)
183
206
  end
184
207
  end
185
208
 
@@ -188,6 +211,8 @@ module Sequel
188
211
  include Sequel::Postgres::DatasetMethods
189
212
  APOS = "'".freeze
190
213
  Sequel::Deprecation.deprecate_constant(self, :APOS)
214
+ HSTORE_TYPE = 'hstore'.freeze
215
+ Sequel::Deprecation.deprecate_constant(self, :HSTORE_TYPE)
191
216
 
192
217
  private
193
218
 
@@ -203,8 +228,9 @@ module Sequel
203
228
 
204
229
  STRING_TYPE = Java::JavaSQL::Types::VARCHAR
205
230
  ARRAY_TYPE = Java::JavaSQL::Types::ARRAY
231
+ ARRAY_METHOD = Postgres.method(:RubyPGArray)
206
232
  PG_SPECIFIC_TYPES = [ARRAY_TYPE, Java::JavaSQL::Types::OTHER, Java::JavaSQL::Types::STRUCT]#.freeze # SEQUEL5
207
- HSTORE_TYPE = 'hstore'.freeze
233
+ HSTORE_METHOD = Postgres.method(:RubyPGHstore)
208
234
 
209
235
  def type_convertor(map, meta, type, i)
210
236
  case type
@@ -213,11 +239,11 @@ module Sequel
213
239
  if pr = db.oid_convertor_proc(oid)
214
240
  pr
215
241
  elsif type == ARRAY_TYPE
216
- map[:RubyPGArray]
242
+ ARRAY_METHOD
217
243
  elsif oid == 2950 # UUID
218
244
  map[STRING_TYPE]
219
- elsif meta.getPGType(i) == HSTORE_TYPE
220
- map[:RubyPGHstore]
245
+ elsif meta.getPGType(i) == 'hstore'
246
+ HSTORE_METHOD
221
247
  else
222
248
  super
223
249
  end