sequel 4.47.0 → 4.48.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +134 -0
  3. data/Rakefile +1 -1
  4. data/doc/release_notes/4.48.0.txt +293 -0
  5. data/lib/sequel/adapters/ado/access.rb +2 -1
  6. data/lib/sequel/adapters/do/postgres.rb +5 -2
  7. data/lib/sequel/adapters/ibmdb.rb +24 -7
  8. data/lib/sequel/adapters/jdbc.rb +36 -22
  9. data/lib/sequel/adapters/jdbc/db2.rb +12 -3
  10. data/lib/sequel/adapters/jdbc/derby.rb +4 -5
  11. data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
  12. data/lib/sequel/adapters/jdbc/postgresql.rb +43 -18
  13. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
  14. data/lib/sequel/adapters/jdbc/sqlserver.rb +11 -4
  15. data/lib/sequel/adapters/mock.rb +24 -19
  16. data/lib/sequel/adapters/mysql.rb +17 -16
  17. data/lib/sequel/adapters/mysql2.rb +4 -5
  18. data/lib/sequel/adapters/oracle.rb +5 -9
  19. data/lib/sequel/adapters/postgres.rb +89 -102
  20. data/lib/sequel/adapters/shared/db2.rb +22 -6
  21. data/lib/sequel/adapters/shared/mssql.rb +5 -4
  22. data/lib/sequel/adapters/shared/mysql.rb +75 -24
  23. data/lib/sequel/adapters/shared/postgres.rb +196 -94
  24. data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
  25. data/lib/sequel/adapters/shared/sqlite.rb +72 -82
  26. data/lib/sequel/adapters/sqlanywhere.rb +4 -1
  27. data/lib/sequel/adapters/sqlite.rb +5 -3
  28. data/lib/sequel/adapters/swift/postgres.rb +5 -2
  29. data/lib/sequel/adapters/tinytds.rb +0 -5
  30. data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
  31. data/lib/sequel/adapters/utils/pg_types.rb +2 -76
  32. data/lib/sequel/core.rb +2 -2
  33. data/lib/sequel/database/connecting.rb +5 -5
  34. data/lib/sequel/database/dataset.rb +6 -3
  35. data/lib/sequel/database/misc.rb +1 -1
  36. data/lib/sequel/database/query.rb +3 -0
  37. data/lib/sequel/database/schema_methods.rb +1 -1
  38. data/lib/sequel/dataset/actions.rb +18 -10
  39. data/lib/sequel/dataset/graph.rb +1 -1
  40. data/lib/sequel/dataset/misc.rb +1 -0
  41. data/lib/sequel/dataset/prepared_statements.rb +3 -3
  42. data/lib/sequel/dataset/query.rb +19 -8
  43. data/lib/sequel/extensions/core_extensions.rb +4 -1
  44. data/lib/sequel/extensions/duplicate_columns_handler.rb +1 -1
  45. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +3 -0
  46. data/lib/sequel/extensions/filter_having.rb +2 -0
  47. data/lib/sequel/extensions/freeze_datasets.rb +2 -0
  48. data/lib/sequel/extensions/from_block.rb +1 -1
  49. data/lib/sequel/extensions/graph_each.rb +2 -2
  50. data/lib/sequel/extensions/hash_aliases.rb +2 -0
  51. data/lib/sequel/extensions/identifier_mangling.rb +0 -7
  52. data/lib/sequel/extensions/meta_def.rb +2 -0
  53. data/lib/sequel/extensions/migration.rb +6 -6
  54. data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
  55. data/lib/sequel/extensions/pagination.rb +1 -1
  56. data/lib/sequel/extensions/pg_array.rb +207 -130
  57. data/lib/sequel/extensions/pg_hstore.rb +38 -20
  58. data/lib/sequel/extensions/pg_inet.rb +18 -6
  59. data/lib/sequel/extensions/pg_interval.rb +19 -12
  60. data/lib/sequel/extensions/pg_json.rb +25 -14
  61. data/lib/sequel/extensions/pg_json_ops.rb +2 -2
  62. data/lib/sequel/extensions/pg_range.rb +133 -100
  63. data/lib/sequel/extensions/pg_range_ops.rb +4 -3
  64. data/lib/sequel/extensions/pg_row.rb +68 -39
  65. data/lib/sequel/extensions/pg_row_ops.rb +11 -5
  66. data/lib/sequel/extensions/query_literals.rb +2 -0
  67. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +2 -0
  68. data/lib/sequel/extensions/s.rb +1 -1
  69. data/lib/sequel/extensions/schema_dumper.rb +24 -24
  70. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +3 -1
  71. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +83 -0
  72. data/lib/sequel/extensions/set_overrides.rb +2 -2
  73. data/lib/sequel/extensions/string_agg.rb +0 -1
  74. data/lib/sequel/extensions/symbol_aref.rb +0 -4
  75. data/lib/sequel/model.rb +25 -57
  76. data/lib/sequel/model/associations.rb +14 -5
  77. data/lib/sequel/model/base.rb +96 -32
  78. data/lib/sequel/plugins/association_pks.rb +73 -46
  79. data/lib/sequel/plugins/association_proxies.rb +1 -1
  80. data/lib/sequel/plugins/auto_validations.rb +6 -2
  81. data/lib/sequel/plugins/boolean_readers.rb +1 -1
  82. data/lib/sequel/plugins/caching.rb +19 -13
  83. data/lib/sequel/plugins/class_table_inheritance.rb +19 -10
  84. data/lib/sequel/plugins/column_conflicts.rb +7 -2
  85. data/lib/sequel/plugins/column_select.rb +1 -1
  86. data/lib/sequel/plugins/csv_serializer.rb +8 -8
  87. data/lib/sequel/plugins/defaults_setter.rb +10 -0
  88. data/lib/sequel/plugins/eager_each.rb +1 -1
  89. data/lib/sequel/plugins/force_encoding.rb +2 -2
  90. data/lib/sequel/plugins/hook_class_methods.rb +9 -12
  91. data/lib/sequel/plugins/identifier_columns.rb +2 -0
  92. data/lib/sequel/plugins/instance_filters.rb +3 -1
  93. data/lib/sequel/plugins/instance_hooks.rb +17 -9
  94. data/lib/sequel/plugins/json_serializer.rb +17 -10
  95. data/lib/sequel/plugins/lazy_attributes.rb +8 -7
  96. data/lib/sequel/plugins/modification_detection.rb +3 -0
  97. data/lib/sequel/plugins/nested_attributes.rb +5 -1
  98. data/lib/sequel/plugins/pg_array_associations.rb +5 -0
  99. data/lib/sequel/plugins/prepared_statements.rb +1 -0
  100. data/lib/sequel/plugins/rcte_tree.rb +4 -4
  101. data/lib/sequel/plugins/serialization.rb +3 -10
  102. data/lib/sequel/plugins/single_table_inheritance.rb +2 -2
  103. data/lib/sequel/plugins/split_values.rb +6 -5
  104. data/lib/sequel/plugins/static_cache.rb +31 -25
  105. data/lib/sequel/plugins/subset_conditions.rb +3 -1
  106. data/lib/sequel/plugins/table_select.rb +1 -1
  107. data/lib/sequel/plugins/touch.rb +2 -1
  108. data/lib/sequel/plugins/validation_class_methods.rb +5 -6
  109. data/lib/sequel/plugins/validation_helpers.rb +2 -4
  110. data/lib/sequel/plugins/xml_serializer.rb +4 -4
  111. data/lib/sequel/sql.rb +2 -2
  112. data/lib/sequel/version.rb +1 -1
  113. data/spec/adapters/db2_spec.rb +115 -14
  114. data/spec/adapters/mysql_spec.rb +78 -28
  115. data/spec/adapters/oracle_spec.rb +24 -24
  116. data/spec/adapters/postgres_spec.rb +38 -24
  117. data/spec/adapters/sqlanywhere_spec.rb +88 -86
  118. data/spec/adapters/sqlite_spec.rb +29 -24
  119. data/spec/core/connection_pool_spec.rb +17 -0
  120. data/spec/core/database_spec.rb +6 -0
  121. data/spec/core/dataset_spec.rb +46 -36
  122. data/spec/core/schema_spec.rb +16 -0
  123. data/spec/core/spec_helper.rb +1 -0
  124. data/spec/core_extensions_spec.rb +6 -2
  125. data/spec/extensions/active_model_spec.rb +1 -1
  126. data/spec/extensions/arbitrary_servers_spec.rb +1 -1
  127. data/spec/extensions/association_pks_spec.rb +34 -2
  128. data/spec/extensions/auto_literal_strings_spec.rb +5 -1
  129. data/spec/extensions/auto_validations_spec.rb +2 -0
  130. data/spec/extensions/boolean_readers_spec.rb +1 -1
  131. data/spec/extensions/boolean_subsets_spec.rb +1 -1
  132. data/spec/extensions/class_table_inheritance_spec.rb +48 -2
  133. data/spec/extensions/column_conflicts_spec.rb +11 -0
  134. data/spec/extensions/connection_validator_spec.rb +1 -1
  135. data/spec/extensions/dataset_associations_spec.rb +8 -8
  136. data/spec/extensions/defaults_setter_spec.rb +1 -1
  137. data/spec/extensions/filter_having_spec.rb +5 -3
  138. data/spec/extensions/hash_aliases_spec.rb +3 -1
  139. data/spec/extensions/identifier_columns_spec.rb +3 -1
  140. data/spec/extensions/implicit_subquery_spec.rb +4 -2
  141. data/spec/extensions/json_serializer_spec.rb +18 -0
  142. data/spec/extensions/lazy_attributes_spec.rb +3 -3
  143. data/spec/extensions/meta_def_spec.rb +9 -0
  144. data/spec/extensions/migration_spec.rb +3 -3
  145. data/spec/extensions/nested_attributes_spec.rb +14 -3
  146. data/spec/extensions/no_auto_literal_strings_spec.rb +8 -4
  147. data/spec/extensions/pg_array_associations_spec.rb +29 -18
  148. data/spec/extensions/pg_array_spec.rb +44 -25
  149. data/spec/extensions/pg_hstore_spec.rb +10 -0
  150. data/spec/extensions/pg_inet_spec.rb +26 -0
  151. data/spec/extensions/pg_interval_spec.rb +20 -0
  152. data/spec/extensions/pg_json_spec.rb +24 -0
  153. data/spec/extensions/pg_range_spec.rb +98 -14
  154. data/spec/extensions/pg_row_spec.rb +14 -4
  155. data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
  156. data/spec/extensions/query_literals_spec.rb +3 -1
  157. data/spec/extensions/schema_dumper_spec.rb +96 -98
  158. data/spec/extensions/sequel_3_dataset_methods_spec.rb +10 -6
  159. data/spec/extensions/sequel_4_dataset_methods_spec.rb +121 -0
  160. data/spec/extensions/single_table_inheritance_spec.rb +1 -1
  161. data/spec/extensions/spec_helper.rb +7 -1
  162. data/spec/extensions/static_cache_spec.rb +75 -24
  163. data/spec/extensions/string_agg_spec.rb +1 -1
  164. data/spec/extensions/touch_spec.rb +9 -0
  165. data/spec/extensions/validation_helpers_spec.rb +9 -3
  166. data/spec/extensions/whitelist_security_spec.rb +26 -0
  167. data/spec/integration/dataset_test.rb +45 -44
  168. data/spec/integration/plugin_test.rb +20 -0
  169. data/spec/integration/prepared_statement_test.rb +3 -0
  170. data/spec/integration/schema_test.rb +21 -1
  171. data/spec/integration/transaction_test.rb +40 -40
  172. data/spec/model/class_dataset_methods_spec.rb +14 -4
  173. data/spec/model/dataset_methods_spec.rb +12 -3
  174. data/spec/model/model_spec.rb +8 -0
  175. metadata +6 -4
  176. data/spec/adapters/firebird_spec.rb +0 -405
  177. data/spec/adapters/informix_spec.rb +0 -100
@@ -4,12 +4,17 @@ module Sequel
4
4
  module SqlAnywhere
5
5
  Sequel::Database.set_shared_adapter_scheme(:sqlanywhere, self)
6
6
 
7
+ # SEQUEL5: Remove
7
8
  @convert_smallint_to_bool = true
8
-
9
9
  class << self
10
- # Whether to convert smallint values to bool, false by default.
11
- # Can also be overridden per dataset.
12
- attr_accessor :convert_smallint_to_bool
10
+ def convert_smallint_to_bool
11
+ Sequel::Deprecation.deprecate("Sequel::SqlAnywhere.convert_smallint_to_bool", "Call this method on the Database instance")
12
+ @convert_smallint_to_bool
13
+ end
14
+ def convert_smallint_to_bool=(v)
15
+ Sequel::Deprecation.deprecate("Sequel::SqlAnywhere.convert_smallint_to_bool=", "Call this method on the Database instance")
16
+ @convert_smallint_to_bool = v
17
+ end
13
18
  end
14
19
 
15
20
  module DatabaseMethods
@@ -36,7 +41,7 @@ module Sequel
36
41
  # Whether to convert smallint to boolean arguments for this dataset.
37
42
  # Defaults to the SqlAnywhere module setting.
38
43
  def convert_smallint_to_bool
39
- defined?(@convert_smallint_to_bool) ? @convert_smallint_to_bool : (@convert_smallint_to_bool = ::Sequel::SqlAnywhere.convert_smallint_to_bool)
44
+ defined?(@convert_smallint_to_bool) ? @convert_smallint_to_bool : (@convert_smallint_to_bool = ::Sequel::SqlAnywhere.instance_variable_get(:@convert_smallint_to_bool)) # true) # SEQUEL5
40
45
  end
41
46
 
42
47
  # Sysbase Server uses the :sqlanywhere type.
@@ -319,14 +324,22 @@ module Sequel
319
324
  Dataset.def_sql_method(self, :insert, %w'with insert into columns values')
320
325
  Dataset.def_sql_method(self, :select, %w'with select distinct limit columns into from join where group having compounds order lock')
321
326
 
327
+ # Override the default IBMDB.convert_smallint_to_bool setting for this dataset.
328
+ def convert_smallint_to_bool=(v)
329
+ Sequel::Deprecation.deprecate("Sequel::SqlAnywhere::Dataset#convert_smallint_to_bool=", "Call with_convert_smallint_to_bool instead, which returns a modified copy instead of modifying the object")
330
+ @opts[:convert_smallint_to_bool] = v
331
+ end
332
+
322
333
  # Whether to convert smallint to boolean arguments for this dataset.
323
- # Defaults to the SqlAnywhere module setting.
334
+ # Defaults to the IBMDB module setting.
324
335
  def convert_smallint_to_bool
325
- defined?(@convert_smallint_to_bool) ? @convert_smallint_to_bool : (@convert_smallint_to_bool = @db.convert_smallint_to_bool)
336
+ opts.has_key?(:convert_smallint_to_bool) ? opts[:convert_smallint_to_bool] : db.convert_smallint_to_bool
326
337
  end
327
338
 
328
- # Override the default SqlAnywhere.convert_smallint_to_bool setting for this dataset.
329
- attr_writer :convert_smallint_to_bool
339
+ # Return a cloned dataset with the convert_smallint_to_bool option set.
340
+ def with_convert_smallint_to_bool(v)
341
+ clone(:convert_smallint_to_bool=>v)
342
+ end
330
343
 
331
344
  def supports_cte?(type=:select)
332
345
  type == :select || type == :insert
@@ -424,7 +437,7 @@ module Sequel
424
437
  string.gsub(/[\\%_\[]/){|m| "\\#{m}"}
425
438
  end
426
439
 
427
- # Use Date() and Now() for CURRENT_DATE and CURRENT_TIMESTAMP
440
+ # Use today() and Now() for CURRENT_DATE and CURRENT_TIMESTAMP
428
441
  def constant_sql_append(sql, constant)
429
442
  case constant
430
443
  when :CURRENT_DATE
@@ -20,12 +20,14 @@ module Sequel
20
20
 
21
21
  PRIMARY_KEY_INDEX_RE = /\Asqlite_autoindex_/.freeze
22
22
  Sequel::Deprecation.deprecate_constant(self, :PRIMARY_KEY_INDEX_RE)
23
+ TABLES_FILTER = Sequel.~(:name=>'sqlite_sequence'.freeze) & {:type => 'table'.freeze}
24
+ Sequel::Deprecation.deprecate_constant(self, :TABLES_FILTER)
25
+ VIEWS_FILTER = {:type => 'view'.freeze}.freeze
26
+ Sequel::Deprecation.deprecate_constant(self, :VIEWS_FILTER)
23
27
 
24
28
  AUTO_VACUUM = [:none, :full, :incremental].freeze
25
29
  SYNCHRONOUS = [:off, :normal, :full].freeze
26
- TABLES_FILTER = Sequel.~(:name=>'sqlite_sequence'.freeze) & {:type => 'table'.freeze}
27
30
  TEMP_STORE = [:default, :file, :memory].freeze
28
- VIEWS_FILTER = {:type => 'view'.freeze}.freeze
29
31
  TRANSACTION_MODE = {
30
32
  :deferred => "BEGIN DEFERRED TRANSACTION".freeze,
31
33
  :immediate => "BEGIN IMMEDIATE TRANSACTION".freeze,
@@ -37,26 +39,6 @@ module Sequel
37
39
  # booleans be stored as integers, but historically Sequel has used 't'/'f'.
38
40
  attr_accessor :integer_booleans
39
41
 
40
- # A symbol signifying the value of the auto_vacuum PRAGMA.
41
- def auto_vacuum
42
- AUTO_VACUUM[pragma_get(:auto_vacuum).to_i]
43
- end
44
-
45
- # Set the auto_vacuum PRAGMA using the given symbol (:none, :full, or
46
- # :incremental). See pragma_set. Consider using the :auto_vacuum
47
- # Database option instead.
48
- def auto_vacuum=(value)
49
- value = AUTO_VACUUM.index(value) || (raise Error, "Invalid value for auto_vacuum option. Please specify one of :none, :full, :incremental.")
50
- pragma_set(:auto_vacuum, value)
51
- end
52
-
53
- # Set the case_sensitive_like PRAGMA using the given boolean value, if using
54
- # SQLite 3.2.3+. If not using 3.2.3+, no error is raised. See pragma_set.
55
- # Consider using the :case_sensitive_like Database option instead.
56
- def case_sensitive_like=(value)
57
- pragma_set(:case_sensitive_like, !!value ? 'on' : 'off') if sqlite_version >= 30203
58
- end
59
-
60
42
  # A symbol signifying the value of the default transaction mode
61
43
  attr_reader :transaction_mode
62
44
 
@@ -74,18 +56,50 @@ module Sequel
74
56
  :sqlite
75
57
  end
76
58
 
77
- # Boolean signifying the value of the foreign_keys PRAGMA, or nil
78
- # if not using SQLite 3.6.19+.
59
+ # SEQUEL5: Remove
60
+ def auto_vacuum
61
+ AUTO_VACUUM[pragma_get(:auto_vacuum).to_i]
62
+ end
63
+ def auto_vacuum=(value)
64
+ value = AUTO_VACUUM.index(value) || (raise Error, "Invalid value for auto_vacuum option. Please specify one of :none, :full, :incremental.")
65
+ pragma_set(:auto_vacuum, value)
66
+ end
67
+ def case_sensitive_like=(value)
68
+ pragma_set(:case_sensitive_like, !!value ? 'on' : 'off') if sqlite_version >= 30203
69
+ end
79
70
  def foreign_keys
80
71
  pragma_get(:foreign_keys).to_i == 1 if sqlite_version >= 30619
81
72
  end
82
-
83
- # Set the foreign_keys PRAGMA using the given boolean value, if using
84
- # SQLite 3.6.19+. If not using 3.6.19+, no error is raised. See pragma_set.
85
- # Consider using the :foreign_keys Database option instead.
86
73
  def foreign_keys=(value)
87
74
  pragma_set(:foreign_keys, !!value ? 'on' : 'off') if sqlite_version >= 30619
88
75
  end
76
+ def pragma_get(name)
77
+ Sequel::Deprecation.deprecate('Database#{pragma_get,auto_vacuum,case_sensitive_like,foreign_keys,synchronous,temp_store} on SQLite', "These methods may not be safe when using multiple connections, call fetch(#{"PRAGMA #{name}".inspect}).single_value if you really want to get the pragma value")
78
+ self["PRAGMA #{name}"].single_value
79
+ end
80
+ def pragma_set(name, value)
81
+ Sequel::Deprecation.deprecate('Database#{pragma_set,auto_vacuum=,case_sensitive_like=,foreign_keys=,synchronous=,temp_store=} on SQLite', "These methods are not thread safe or safe when using multiple connections, pass the appropriate option when connecting to set the pragma correctly for all connections")
82
+ execute_ddl("PRAGMA #{name} = #{value}")
83
+ end
84
+ def synchronous
85
+ SYNCHRONOUS[pragma_get(:synchronous).to_i]
86
+ end
87
+ def synchronous=(value)
88
+ value = SYNCHRONOUS.index(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.")
89
+ pragma_set(:synchronous, value)
90
+ end
91
+ def temp_store
92
+ TEMP_STORE[pragma_get(:temp_store).to_i]
93
+ end
94
+ def temp_store=(value)
95
+ value = TEMP_STORE.index(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.")
96
+ pragma_set(:temp_store, value)
97
+ end
98
+
99
+ # Set the integer_booleans option using the passed in :integer_boolean option.
100
+ def set_integer_booleans
101
+ @integer_booleans = @opts.has_key?(:integer_booleans) ? typecast_value_boolean(@opts[:integer_booleans]) : true
102
+ end
89
103
 
90
104
  # Return the array of foreign key info hashes using the foreign_key_list PRAGMA,
91
105
  # including information for the :on_update and :on_delete entries.
@@ -115,8 +129,18 @@ module Sequel
115
129
  im = input_identifier_meth
116
130
  indexes = {}
117
131
  metadata_dataset.with_sql("PRAGMA index_list(?)", im.call(table)).each do |r|
118
- # :only_autocreated internal option can be used to get only autocreated indexes
119
- next if (!!(r[:name] =~ /\Asqlite_autoindex_/) ^ !!opts[:only_autocreated])
132
+ if opts[:only_autocreated]
133
+ # If specifically asked for only autocreated indexes, then return those an only those
134
+ next unless r[:name] =~ /\Asqlite_autoindex_/
135
+ elsif r.has_key?(:origin)
136
+ # If origin is set, then only exclude primary key indexes and partial indexes
137
+ next if r[:origin] == 'pk'
138
+ next if r[:partial].to_i == 1
139
+ else
140
+ # When :origin key not present, assume any autoindex could be a primary key one and exclude it
141
+ next if r[:name] =~ /\Asqlite_autoindex_/
142
+ end
143
+
120
144
  indexes[m.call(r[:name])] = {:unique=>r[:unique].to_i==1}
121
145
  end
122
146
  indexes.each do |k, v|
@@ -125,28 +149,6 @@ module Sequel
125
149
  indexes
126
150
  end
127
151
 
128
- # Get the value of the given PRAGMA.
129
- def pragma_get(name)
130
- Sequel::Deprecation.deprecate('Database#{pragma_get,auto_vacuum,case_sensitive_like,foreign_keys,synchronous,temp_store} on SQLite', "These methods may not be safe when using multiple connections, call fetch(#{"PRAGMA #{name}".inspect}).single_value if you really want to get the pragma value")
131
- self["PRAGMA #{name}"].single_value
132
- end
133
-
134
- # Set the value of the given PRAGMA to value.
135
- #
136
- # This method is not thread safe, and will not work correctly if there
137
- # are multiple connections in the Database's connection pool. PRAGMA
138
- # modifications should be done when the connection is created, using
139
- # an option provided when creating the Database object.
140
- def pragma_set(name, value)
141
- Sequel::Deprecation.deprecate('Database#{pragma_set,auto_vacuum=,case_sensitive_like=,foreign_keys=,synchronous=,temp_store=} on SQLite', "These methods are not thread safe or safe when using multiple connections, pass the appropriate option when connecting to set the pragma correctly for all connections")
142
- execute_ddl("PRAGMA #{name} = #{value}")
143
- end
144
-
145
- # Set the integer_booleans option using the passed in :integer_boolean option.
146
- def set_integer_booleans
147
- @integer_booleans = @opts.has_key?(:integer_booleans) ? typecast_value_boolean(@opts[:integer_booleans]) : true
148
- end
149
-
150
152
  # The version of the server as an integer, where 3.6.19 = 30619.
151
153
  # If the server version can't be determined, 0 is used.
152
154
  def sqlite_version
@@ -190,36 +192,12 @@ module Sequel
190
192
  defined?(@use_timestamp_timezones) ? @use_timestamp_timezones : (@use_timestamp_timezones = false)
191
193
  end
192
194
 
193
- # A symbol signifying the value of the synchronous PRAGMA.
194
- def synchronous
195
- SYNCHRONOUS[pragma_get(:synchronous).to_i]
196
- end
197
-
198
- # Set the synchronous PRAGMA using the given symbol (:off, :normal, or :full). See pragma_set.
199
- # Consider using the :synchronous Database option instead.
200
- def synchronous=(value)
201
- value = SYNCHRONOUS.index(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.")
202
- pragma_set(:synchronous, value)
203
- end
204
-
205
195
  # Array of symbols specifying the table names in the current database.
206
196
  #
207
197
  # Options:
208
198
  # :server :: Set the server to use.
209
199
  def tables(opts=OPTS)
210
- tables_and_views(TABLES_FILTER, opts)
211
- end
212
-
213
- # A symbol signifying the value of the temp_store PRAGMA.
214
- def temp_store
215
- TEMP_STORE[pragma_get(:temp_store).to_i]
216
- end
217
-
218
- # Set the temp_store PRAGMA using the given symbol (:default, :file, or :memory). See pragma_set.
219
- # Consider using the :temp_store Database option instead.
220
- def temp_store=(value)
221
- value = TEMP_STORE.index(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.")
222
- pragma_set(:temp_store, value)
200
+ tables_and_views(Sequel.~(:name=>'sqlite_sequence') & {:type => 'table'}, opts)
223
201
  end
224
202
 
225
203
  # Creates a dataset that uses the VALUES clause:
@@ -235,7 +213,7 @@ module Sequel
235
213
  # Options:
236
214
  # :server :: Set the server to use.
237
215
  def views(opts=OPTS)
238
- tables_and_views(VIEWS_FILTER, opts)
216
+ tables_and_views({:type => 'view'}, opts)
239
217
  end
240
218
 
241
219
  private
@@ -438,8 +416,12 @@ module Sequel
438
416
 
439
417
  # Determine unique constraints and make sure the new columns have them
440
418
  unique_columns = []
441
- indexes(table, :only_autocreated=>true).each_value do |h|
442
- unique_columns.concat(h[:columns]) if h[:columns].length == 1 && h[:unique]
419
+ skip_indexes = []
420
+ indexes(table, :only_autocreated=>true).each do |name, h|
421
+ skip_indexes << name
422
+ if h[:columns].length == 1 && h[:unique]
423
+ unique_columns.concat(h[:columns])
424
+ end
443
425
  end
444
426
  unique_columns -= pks
445
427
  unless unique_columns.empty?
@@ -462,6 +444,7 @@ module Sequel
462
444
  "DROP TABLE #{bt}"
463
445
  ]
464
446
  indexes(table).each do |name, h|
447
+ next if skip_indexes.include?(name)
465
448
  if (h[:columns].map(&:to_s) - new_columns).empty?
466
449
  a << alter_table_sql(table, h.merge(:op=>:add_index, :name=>name))
467
450
  end
@@ -471,7 +454,7 @@ module Sequel
471
454
 
472
455
  # Does the reverse of on_delete_clause, eg. converts strings like +'SET NULL'+
473
456
  # to symbols +:set_null+.
474
- def on_delete_sql_to_sym str
457
+ def on_delete_sql_to_sym(str)
475
458
  case str
476
459
  when 'RESTRICT'
477
460
  :restrict
@@ -549,6 +532,9 @@ module Sequel
549
532
  include Dataset::Replace
550
533
  include UnmodifiedIdentifiers::DatasetMethods
551
534
 
535
+ # The allowed values for insert_conflict
536
+ INSERT_CONFLICT_RESOLUTIONS = %w'ROLLBACK ABORT FAIL IGNORE REPLACE'.each(&:freeze).freeze
537
+
552
538
  CONSTANT_MAP = {:CURRENT_DATE=>"date(CURRENT_TIMESTAMP, 'localtime')".freeze, :CURRENT_TIMESTAMP=>"datetime(CURRENT_TIMESTAMP, 'localtime')".freeze, :CURRENT_TIME=>"time(CURRENT_TIMESTAMP, 'localtime')".freeze}#.freeze # SEQUEL5
553
539
  EXTRACT_MAP = {:year=>"'%Y'", :month=>"'%m'", :day=>"'%d'", :hour=>"'%H'", :minute=>"'%M'", :second=>"'%f'"}#.freeze # SEQUEL5
554
540
  #EXTRACT_MAP.each_value(&:freeze) # SEQUEL5
@@ -676,7 +662,7 @@ module Sequel
676
662
  end
677
663
 
678
664
  # Return an array of strings specifying a query explanation for a SELECT of the
679
- # current dataset. Currently, the options are ignore, but it accepts options
665
+ # current dataset. Currently, the options are ignored, but it accepts options
680
666
  # to be compatible with other adapters.
681
667
  def explain(opts=nil)
682
668
  # Load the PrettyTable class, needed for explain output
@@ -723,6 +709,10 @@ module Sequel
723
709
  # DB[:table].insert_conflict(:replace).insert(:a=>1, :b=>2)
724
710
  # # INSERT OR REPLACE INTO TABLE (a, b) VALUES (1, 2)
725
711
  def insert_conflict(resolution = :ignore)
712
+ unless INSERT_CONFLICT_RESOLUTIONS.include?(resolution.to_s.upcase)
713
+ Sequel::Deprecation.deprecate("Passing #{resolution.inspect} argument to Dataset#insert_conflict", "The allowed values are: :rollback, :abort, :fail, :ignore, or :replace")
714
+ # raise Error, "Invalid value passed to Dataset#insert_conflict: #{resolution.inspect}. The allowed values are: :rollback, :abort, :fail, :ignore, or :replace"
715
+ end
726
716
  clone(:insert_conflict => resolution)
727
717
  end
728
718
 
@@ -19,7 +19,7 @@ module Sequel
19
19
  end
20
20
  end
21
21
 
22
- TYPE_TRANSLATOR = tt = Class.new do
22
+ tt = Class.new do
23
23
  def blob(s) ::Sequel::SQL::Blob.new(s) end
24
24
  def boolean(s) s.to_i != 0 end
25
25
  def date(s) ::Date.strptime(s) end
@@ -27,6 +27,9 @@ module Sequel
27
27
  def time(s) ::Sequel.string_to_time(s) end
28
28
  end.new
29
29
 
30
+ TYPE_TRANSLATOR = tt
31
+ Sequel::Deprecation.deprecate_constant(self, :TYPE_TRANSLATOR)
32
+
30
33
  SQLANYWHERE_TYPES = {}
31
34
  {
32
35
  [0, 484] => tt.method(:decimal),
@@ -7,9 +7,9 @@ module Sequel
7
7
  # Top level module for holding all SQLite-related modules and classes
8
8
  # for Sequel.
9
9
  module SQLite
10
- TYPE_TRANSLATOR = tt = Class.new do
11
- FALSE_VALUES = (%w'0 false f no n' + [0]).freeze
10
+ FALSE_VALUES = (%w'0 false f no n' + [0]).freeze
12
11
 
12
+ tt = Class.new do
13
13
  def blob(s)
14
14
  Sequel::SQL::Blob.new(s.to_s)
15
15
  end
@@ -58,9 +58,11 @@ module Sequel
58
58
  raise Sequel::Error, "unhandled type when converting to date: #{s.inspect} (#{s.class.inspect})"
59
59
  end
60
60
  end
61
-
62
61
  end.new
63
62
 
63
+ TYPE_TRANSLATOR = tt
64
+ Sequel::Deprecation.deprecate_constant(self, :TYPE_TRANSLATOR)
65
+
64
66
  # Hash with string keys and callable values for converting SQLite types.
65
67
  SQLITE_TYPES = {}
66
68
  {
@@ -4,8 +4,6 @@ require 'swift/db/postgres'
4
4
  Sequel.require 'adapters/shared/postgres'
5
5
 
6
6
  module Sequel
7
- Postgres::CONVERTED_EXCEPTIONS << ::Swift::Error
8
-
9
7
  module Swift
10
8
  # Adapter, Database, and Dataset support for accessing a PostgreSQL
11
9
  # database via Swift.
@@ -23,6 +21,11 @@ module Sequel
23
21
 
24
22
  private
25
23
 
24
+ DATABASE_ERROR_CLASSES = [::Swift::Error].freeze
25
+ def database_error_classes
26
+ DATABASE_ERROR_CLASSES
27
+ end
28
+
26
29
  # Remove all other options except for ones specifically handled, as
27
30
  # otherwise swift passes them to dbic++ which passes them to PostgreSQL
28
31
  # which can raise an error.
@@ -188,14 +188,11 @@ module Sequel
188
188
  Database::DatasetClass = self
189
189
  Sequel::Deprecation.deprecate_constant(Database, :DatasetClass)
190
190
 
191
- # SQLite already supports named bind arguments, so use directly.
192
191
  module ArgumentMapper
193
192
  include Sequel::Dataset::ArgumentMapper
194
193
 
195
194
  protected
196
195
 
197
- # Return a hash with the same values as the given hash,
198
- # but with the keys converted to strings.
199
196
  def map_to_prepared_args(hash)
200
197
  args = {}
201
198
  hash.each{|k,v| args[k.to_s.gsub('.', '__')] = v}
@@ -204,8 +201,6 @@ module Sequel
204
201
 
205
202
  private
206
203
 
207
- # SQLite uses a : before the name of the argument for named
208
- # arguments.
209
204
  def prepared_arg(k)
210
205
  LiteralString.new("@#{k.to_s.gsub('.', '__')}")
211
206
  end
@@ -18,7 +18,7 @@ module Sequel
18
18
  closed MySQL connection
19
19
  END
20
20
  # Error messages for mysql and mysql2 that indicate the current connection should be disconnected
21
- MYSQL_DATABASE_DISCONNECT_ERRORS = /\A#{Regexp.union(disconnect_errors)}/o
21
+ MYSQL_DATABASE_DISCONNECT_ERRORS = /\A#{Regexp.union(disconnect_errors)}/
22
22
 
23
23
  # Support stored procedures on MySQL
24
24
  def call_sproc(name, opts=OPTS, &block)
@@ -1,78 +1,4 @@
1
1
  # frozen-string-literal: true
2
2
 
3
- module Sequel
4
- module Postgres
5
- NAN = 0.0/0.0
6
- PLUS_INFINITY = 1.0/0.0
7
- MINUS_INFINITY = -1.0/0.0
8
-
9
- NAN_STR = 'NaN'.freeze
10
- Sequel::Deprecation.deprecate_constant(self, :NAN_STR)
11
- PLUS_INFINITY_STR = 'Infinity'.freeze
12
- Sequel::Deprecation.deprecate_constant(self, :PLUS_INFINITY_STR)
13
- MINUS_INFINITY_STR = '-Infinity'.freeze
14
- Sequel::Deprecation.deprecate_constant(self, :MINUS_INFINITY_STR)
15
- TRUE_STR = 't'.freeze
16
- Sequel::Deprecation.deprecate_constant(self, :TRUE_STR)
17
- DASH_STR = '-'.freeze
18
- Sequel::Deprecation.deprecate_constant(self, :DASH_STR)
19
-
20
- TYPE_TRANSLATOR = tt = Class.new do
21
- def boolean(s) s == 't' end
22
- def integer(s) s.to_i end
23
- def float(s)
24
- case s
25
- when 'NaN'
26
- NAN
27
- when 'Infinity'
28
- PLUS_INFINITY
29
- when '-Infinity'
30
- MINUS_INFINITY
31
- else
32
- s.to_f
33
- end
34
- end
35
- def date(s) ::Date.new(*s.split('-').map(&:to_i)) end
36
- def bytea(str)
37
- str = if str =~ /\A\\x/
38
- # PostgreSQL 9.0+ bytea hex format
39
- str[2..-1].gsub(/(..)/){|s| s.to_i(16).chr}
40
- else
41
- # Historical PostgreSQL bytea escape format
42
- str.gsub(/\\(\\|'|[0-3][0-7][0-7])/) {|s|
43
- if s.size == 2 then s[1,1] else s[1,3].oct.chr end
44
- }
45
- end
46
- ::Sequel::SQL::Blob.new(str)
47
- end
48
- end.new
49
-
50
- # Type OIDs for string types used by PostgreSQL. These types don't
51
- # have conversion procs associated with them (since the data is
52
- # already in the form of a string).
53
- STRING_TYPES = [18, 19, 25, 1042, 1043]#.freeze # SEQUEL5
54
-
55
- # Hash with type name strings/symbols and callable values for converting PostgreSQL types.
56
- # Non-builtin types that don't have fixed numbers should use this to register
57
- # conversion procs.
58
- PG_NAMED_TYPES = {} unless defined?(PG_NAMED_TYPES)
59
- PG_NAMED__TYPES = PG_NAMED_TYPES
60
- Sequel::Deprecation.deprecate_constant(self, :PG_NAMED_TYPES)
61
-
62
- # Hash with integer keys and callable values for converting PostgreSQL types.
63
- PG_TYPES = {} unless defined?(PG_TYPES)
64
-
65
- {
66
- [16] => tt.method(:boolean),
67
- [17] => tt.method(:bytea),
68
- [20, 21, 23, 26] => tt.method(:integer),
69
- [700, 701] => tt.method(:float),
70
- [1700] => ::BigDecimal.method(:new),
71
- [1083, 1266] => ::Sequel.method(:string_to_time),
72
- [1082] => ::Sequel.method(:string_to_date),
73
- [1184, 1114] => ::Sequel.method(:database_to_application_timestamp),
74
- }.each do |k,v|
75
- k.each{|n| PG_TYPES[n] = v}
76
- end
77
- end
78
- end
3
+ Sequel::Deprecation.deprecate("requiring sequel/adapters/utils/pg_types", "This file should no longer be required, use Database#conversion_procs to modify conversion procs for a Database instance")
4
+ Sequel.require 'adapters/shared/postgres'