sequel 5.106.0 → 5.109.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 (147) hide show
  1. checksums.yaml +4 -4
  2. data/bin/sequel +5 -5
  3. data/lib/sequel/adapters/ado.rb +1 -1
  4. data/lib/sequel/adapters/amalgalite.rb +34 -8
  5. data/lib/sequel/adapters/ibmdb.rb +2 -2
  6. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
  7. data/lib/sequel/adapters/jdbc/mssql.rb +28 -5
  8. data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
  9. data/lib/sequel/adapters/jdbc/postgresql.rb +14 -3
  10. data/lib/sequel/adapters/jdbc.rb +4 -3
  11. data/lib/sequel/adapters/mock.rb +1 -1
  12. data/lib/sequel/adapters/mysql.rb +7 -2
  13. data/lib/sequel/adapters/mysql2.rb +5 -4
  14. data/lib/sequel/adapters/postgres.rb +42 -39
  15. data/lib/sequel/adapters/shared/db2.rb +5 -2
  16. data/lib/sequel/adapters/shared/mssql.rb +11 -5
  17. data/lib/sequel/adapters/shared/mysql.rb +2 -2
  18. data/lib/sequel/adapters/shared/postgres.rb +80 -92
  19. data/lib/sequel/adapters/shared/sqlanywhere.rb +0 -32
  20. data/lib/sequel/adapters/shared/sqlite.rb +8 -7
  21. data/lib/sequel/adapters/sqlite.rb +13 -9
  22. data/lib/sequel/adapters/trilogy.rb +2 -1
  23. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +1 -1
  24. data/lib/sequel/adapters/utils/mysql_mysql2.rb +11 -1
  25. data/lib/sequel/connection_pool/sharded_single.rb +1 -1
  26. data/lib/sequel/connection_pool/sharded_threaded.rb +7 -5
  27. data/lib/sequel/connection_pool/sharded_timed_queue.rb +3 -3
  28. data/lib/sequel/connection_pool/threaded.rb +9 -7
  29. data/lib/sequel/connection_pool/timed_queue.rb +2 -2
  30. data/lib/sequel/connection_pool.rb +3 -3
  31. data/lib/sequel/core.rb +44 -24
  32. data/lib/sequel/database/connecting.rb +1 -1
  33. data/lib/sequel/database/features.rb +1 -1
  34. data/lib/sequel/database/misc.rb +6 -11
  35. data/lib/sequel/database/query.rb +2 -2
  36. data/lib/sequel/database/schema_generator.rb +7 -5
  37. data/lib/sequel/database/schema_methods.rb +2 -2
  38. data/lib/sequel/database/transactions.rb +5 -7
  39. data/lib/sequel/dataset/actions.rb +2 -2
  40. data/lib/sequel/dataset/features.rb +4 -4
  41. data/lib/sequel/dataset/graph.rb +1 -1
  42. data/lib/sequel/dataset/misc.rb +3 -3
  43. data/lib/sequel/dataset/prepared_statements.rb +2 -2
  44. data/lib/sequel/dataset/query.rb +8 -8
  45. data/lib/sequel/dataset/sql.rb +32 -13
  46. data/lib/sequel/dataset.rb +2 -2
  47. data/lib/sequel/deprecated.rb +2 -2
  48. data/lib/sequel/exceptions.rb +2 -2
  49. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  50. data/lib/sequel/extensions/async_thread_pool.rb +3 -3
  51. data/lib/sequel/extensions/auto_cast_date_and_time.rb +2 -2
  52. data/lib/sequel/extensions/blank.rb +2 -2
  53. data/lib/sequel/extensions/constraint_validations.rb +1 -1
  54. data/lib/sequel/extensions/core_refinements.rb +7 -10
  55. data/lib/sequel/extensions/date_arithmetic.rb +1 -1
  56. data/lib/sequel/extensions/datetime_parse_to_time.rb +2 -2
  57. data/lib/sequel/extensions/duplicate_columns_handler.rb +1 -3
  58. data/lib/sequel/extensions/graph_each.rb +1 -1
  59. data/lib/sequel/extensions/index_caching.rb +1 -1
  60. data/lib/sequel/extensions/inflector.rb +5 -5
  61. data/lib/sequel/extensions/is_distinct_from.rb +2 -2
  62. data/lib/sequel/extensions/lit_require_frozen.rb +20 -4
  63. data/lib/sequel/extensions/migration.rb +21 -7
  64. data/lib/sequel/extensions/named_timezones.rb +9 -9
  65. data/lib/sequel/extensions/pg_array.rb +10 -8
  66. data/lib/sequel/extensions/pg_array_ops.rb +69 -14
  67. data/lib/sequel/extensions/pg_auto_parameterize.rb +2 -2
  68. data/lib/sequel/extensions/pg_auto_parameterize_in_array.rb +3 -3
  69. data/lib/sequel/extensions/pg_enum.rb +2 -2
  70. data/lib/sequel/extensions/pg_extended_date_support.rb +5 -5
  71. data/lib/sequel/extensions/pg_extended_integer_support.rb +1 -1
  72. data/lib/sequel/extensions/pg_hstore.rb +2 -2
  73. data/lib/sequel/extensions/pg_hstore_ops.rb +5 -5
  74. data/lib/sequel/extensions/pg_inet.rb +2 -2
  75. data/lib/sequel/extensions/pg_inet_ops.rb +2 -2
  76. data/lib/sequel/extensions/pg_interval.rb +6 -6
  77. data/lib/sequel/extensions/pg_json.rb +4 -4
  78. data/lib/sequel/extensions/pg_json_ops.rb +15 -13
  79. data/lib/sequel/extensions/pg_range.rb +6 -6
  80. data/lib/sequel/extensions/pg_range_ops.rb +7 -7
  81. data/lib/sequel/extensions/pg_row.rb +4 -4
  82. data/lib/sequel/extensions/pg_row_ops.rb +6 -6
  83. data/lib/sequel/extensions/provenance.rb +2 -2
  84. data/lib/sequel/extensions/query.rb +2 -2
  85. data/lib/sequel/extensions/s.rb +6 -10
  86. data/lib/sequel/extensions/schema_dumper.rb +10 -6
  87. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +2 -0
  88. data/lib/sequel/extensions/sql_comments.rb +1 -1
  89. data/lib/sequel/extensions/sql_log_normalizer.rb +1 -1
  90. data/lib/sequel/extensions/sqlite_json_ops.rb +2 -2
  91. data/lib/sequel/extensions/string_agg.rb +5 -5
  92. data/lib/sequel/extensions/symbol_aref.rb +12 -32
  93. data/lib/sequel/extensions/symbol_aref_refinement.rb +2 -5
  94. data/lib/sequel/extensions/symbol_as.rb +1 -2
  95. data/lib/sequel/extensions/symbol_as_refinement.rb +1 -5
  96. data/lib/sequel/extensions/transaction_connection_validator.rb +1 -1
  97. data/lib/sequel/model/associations.rb +17 -17
  98. data/lib/sequel/model/base.rb +18 -15
  99. data/lib/sequel/model/inflections.rb +1 -1
  100. data/lib/sequel/model/plugins.rb +2 -2
  101. data/lib/sequel/model.rb +2 -2
  102. data/lib/sequel/plugins/association_pks.rb +1 -1
  103. data/lib/sequel/plugins/association_proxies.rb +4 -4
  104. data/lib/sequel/plugins/auto_restrict_eager_graph.rb +2 -0
  105. data/lib/sequel/plugins/caching.rb +28 -3
  106. data/lib/sequel/plugins/class_table_inheritance.rb +1 -1
  107. data/lib/sequel/plugins/column_encryption.rb +10 -10
  108. data/lib/sequel/plugins/concurrent_eager_loading.rb +2 -2
  109. data/lib/sequel/plugins/csv_serializer.rb +9 -20
  110. data/lib/sequel/plugins/deprecated_associations.rb +2 -2
  111. data/lib/sequel/plugins/eager_each.rb +1 -1
  112. data/lib/sequel/plugins/finder.rb +1 -1
  113. data/lib/sequel/plugins/forbid_lazy_load.rb +3 -3
  114. data/lib/sequel/plugins/insert_conflict.rb +1 -1
  115. data/lib/sequel/plugins/insert_returning_select.rb +1 -1
  116. data/lib/sequel/plugins/instance_filters.rb +8 -0
  117. data/lib/sequel/plugins/instance_hooks.rb +19 -0
  118. data/lib/sequel/plugins/json_serializer.rb +4 -4
  119. data/lib/sequel/plugins/lazy_attributes.rb +1 -1
  120. data/lib/sequel/plugins/many_through_many.rb +1 -1
  121. data/lib/sequel/plugins/mssql_optimistic_locking.rb +9 -0
  122. data/lib/sequel/plugins/optimistic_locking.rb +12 -2
  123. data/lib/sequel/plugins/optimistic_locking_base.rb +14 -0
  124. data/lib/sequel/plugins/pg_array_associations.rb +4 -4
  125. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +3 -3
  126. data/lib/sequel/plugins/pg_eager_any_typed_array.rb +2 -2
  127. data/lib/sequel/plugins/pg_xmin_optimistic_locking.rb +11 -2
  128. data/lib/sequel/plugins/prepared_statements.rb +2 -2
  129. data/lib/sequel/plugins/select_on_skipped_update.rb +63 -0
  130. data/lib/sequel/plugins/serialization.rb +1 -1
  131. data/lib/sequel/plugins/sharding.rb +1 -1
  132. data/lib/sequel/plugins/single_table_inheritance.rb +21 -3
  133. data/lib/sequel/plugins/skip_saving_columns.rb +2 -2
  134. data/lib/sequel/plugins/split_values.rb +1 -1
  135. data/lib/sequel/plugins/sql_comments.rb +8 -8
  136. data/lib/sequel/plugins/subclasses.rb +6 -6
  137. data/lib/sequel/plugins/subset_conditions.rb +5 -16
  138. data/lib/sequel/plugins/tactical_eager_loading.rb +1 -1
  139. data/lib/sequel/plugins/throw_failures.rb +3 -3
  140. data/lib/sequel/plugins/unused_associations.rb +5 -5
  141. data/lib/sequel/plugins/validate_associated.rb +7 -1
  142. data/lib/sequel/plugins/validate_associated_context.rb +52 -0
  143. data/lib/sequel/plugins/validation_helpers.rb +1 -1
  144. data/lib/sequel/plugins/xml_serializer.rb +2 -0
  145. data/lib/sequel/sql.rb +120 -116
  146. data/lib/sequel/version.rb +1 -1
  147. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93dd74cb4407d389f289342898c26327d91db1ddd733478461bd8620a3a1771b
4
- data.tar.gz: b00796ca61d19f2d9aeaaa764565893e73f5dd4c0752e11bd38635fdb94b1cea
3
+ metadata.gz: d532e5b8b7464ce5420441aada5a737826aadf657b7ae2d74e00947fb9073b8c
4
+ data.tar.gz: 8768f69d56e2683b1a3613fb087372fb419fe5086f6e6c399278d648e106527b
5
5
  SHA512:
6
- metadata.gz: 2502a507d57a7f64dae3ddc9e736254461a3a05f15f95a4835e2ddd83cb3cf3a9f6719f97e6b05239508d4e8445cff8b502198d40eea9f2c0af9d7ea385f829f
7
- data.tar.gz: 8f3e230dc402a4e9d4b2c1d60fb5bdcac580f8368a2ad79a132a29348df8bce6b78f983658c6cf1e406b53164f79f1103cdbfb8ccfd29d0ec90db48a57f348a2
6
+ metadata.gz: 9e1c3559c9fe77f574f54e6b0c67a1ab421d9cc2661aba5121693bc0a101e7d922474e443ae2c93ff55a7a4e7880c7a1eb9b6476a9b2b4b22fbb361d616996db
7
+ data.tar.gz: '07583c0e8b4375f7016a8806973ff555ec8dc2225f0306b8a73535e34c1a517a3d5071299613d80b328cd1835519a5df577b372495ef793c1e58aad271ae9661'
data/bin/sequel CHANGED
@@ -74,7 +74,7 @@ options = OptionParser.new do |opts|
74
74
  loggers << file
75
75
  end
76
76
 
77
- opts.on("-L", "--load-dir DIR", "loads all *.rb under specifed directory") do |v|
77
+ opts.on("-L", "--load-dir DIR", "loads all *.rb under specified directory") do |v|
78
78
  load_dirs << v
79
79
  end
80
80
 
@@ -200,9 +200,9 @@ begin
200
200
  same_db = DB.database_type==TO_DB.database_type
201
201
  index_opts = {:same_db=>same_db}
202
202
 
203
- # :nocov:
203
+ # simplecov:disable
204
204
  index_opts[:index_names] = :namespace if !DB.global_index_namespace? && TO_DB.global_index_namespace?
205
- # :nocov:
205
+ # simplecov:enable
206
206
 
207
207
  if DB.database_type == :sqlite && !same_db
208
208
  # SQLite integer types allows 64-bit integers
@@ -271,10 +271,10 @@ if !ARGV.empty?
271
271
  ARGV.each{|v| load(v)}
272
272
  elsif !$stdin.isatty
273
273
  eval($stdin.read)
274
- # :nocov:
274
+ # simplecov:disable
275
275
  else
276
276
  require 'irb'
277
277
  puts "Your database is stored in DB..."
278
278
  IRB.start
279
279
  end
280
- # :nocov:
280
+ # simplecov:enable
@@ -108,7 +108,7 @@ module Sequel
108
108
  # Pay special attention to the :provider option, as without specifying a provider,
109
109
  # many things will be broken. The SQLNCLI10 provider appears to work well if you
110
110
  # are connecting to Microsoft SQL Server, but it is not the default as that is not
111
- # always available and would break backwards compatability.
111
+ # always available and would break backwards compatibility.
112
112
  def connect(server)
113
113
  opts = server_opts(server)
114
114
  s = opts[:conn_string] || "driver=#{opts[:driver]};server=#{opts[:host]};database=#{opts[:database]}#{";uid=#{opts[:user]};pwd=#{opts[:password]}" if opts[:user]}"
@@ -7,13 +7,39 @@ module Sequel
7
7
  module Amalgalite
8
8
  # Type conversion map class for Sequel's use of Amalgamite
9
9
  class SequelTypeMap < ::Amalgalite::TypeMaps::DefaultMap
10
- methods_handling_sql_types.delete('string')
11
- methods_handling_sql_types.merge!(
12
- 'datetime' => %w'datetime timestamp',
13
- 'time' => %w'time',
14
- 'float' => ['float', 'double', 'real', 'double precision'],
15
- 'decimal' => %w'numeric decimal money'
16
- )
10
+ if respond_to?(:methods_handling_sql_types, true)
11
+ # Amalgalite < 2 support
12
+ methods_handling_sql_types.delete('string')
13
+ methods_handling_sql_types.merge!(
14
+ 'datetime' => %w'datetime timestamp',
15
+ 'time' => %w'time',
16
+ 'float' => ['float', 'double', 'real', 'double precision'],
17
+ 'decimal' => %w'numeric decimal money'
18
+
19
+ )
20
+
21
+ def result_value_method(type)
22
+ self.class.sql_to_method(type)
23
+ end
24
+ else
25
+ # Amalgalite 2 support
26
+ SQL_TO_METHOD = superclass::SQL_TO_METHOD.merge(
27
+ 'datetime' => :datetime,
28
+ 'timestamp' => :datetime,
29
+ 'time' => :time,
30
+ 'float' => :float,
31
+ 'double' => :float,
32
+ 'real' => :float,
33
+ 'double precision' => :float,
34
+ 'decimal' => :decimal,
35
+ 'numeric' => :decimal,
36
+ 'money' => :decimal
37
+ )
38
+
39
+ def result_value_method(type)
40
+ SQL_TO_METHOD[type]
41
+ end
42
+ end
17
43
 
18
44
  # Store the related database object, in order to be able to correctly
19
45
  # handle the database timezone.
@@ -48,7 +74,7 @@ module Sequel
48
74
  if value.is_a?(::Amalgalite::Blob)
49
75
  SQL::Blob.new(value.to_s)
50
76
  elsif value.is_a?(String) && declared_type
51
- (meth = self.class.sql_to_method(declared_type.downcase)) ? public_send(meth, value) : value
77
+ (meth = result_value_method(declared_type.downcase)) ? public_send(meth, value) : value
52
78
  else
53
79
  super
54
80
  end
@@ -312,13 +312,13 @@ module Sequel
312
312
  # Don't convert smallint to boolean for the metadata
313
313
  # dataset, since the DB2 metadata does not use
314
314
  # boolean columns, and some smallint columns are
315
- # accidently treated as booleans.
315
+ # accidentally treated as booleans.
316
316
  def _metadata_dataset
317
317
  super.with_convert_smallint_to_bool(false)
318
318
  end
319
319
 
320
320
  # Format Numeric, Date, and Time types specially for use
321
- # as IBM_DB prepared statements argument vlaues.
321
+ # as IBM_DB prepared statements argument values.
322
322
  def prepared_statement_arg(v)
323
323
  case v
324
324
  when Numeric
@@ -163,7 +163,7 @@ module Sequel
163
163
  end
164
164
 
165
165
  # HSQLDB does support common table expressions, but the support is broken.
166
- # CTEs operate more like temprorary tables or views, lasting longer than the duration of the expression.
166
+ # CTEs operate more like temporary tables or views, lasting longer than the duration of the expression.
167
167
  # CTEs in earlier queries might take precedence over CTEs with the same name in later queries.
168
168
  # Also, if any CTE is recursive, all CTEs must be recursive.
169
169
  # If you want to use CTEs with HSQLDB, you'll have to manually modify the dataset to allow it.
@@ -12,11 +12,34 @@ module Sequel
12
12
 
13
13
  # Get the last inserted id using SCOPE_IDENTITY().
14
14
  def last_insert_id(conn, opts=OPTS)
15
- statement(conn) do |stmt|
16
- sql = opts[:prepared] ? 'SELECT @@IDENTITY' : 'SELECT SCOPE_IDENTITY()'
17
- rs = log_connection_yield(sql, conn){stmt.executeQuery(sql)}
18
- rs.next
19
- rs.getLong(1)
15
+ if (stmt = opts[:stmt]) && opts[:prepared]
16
+ rs = stmt.getGeneratedKeys
17
+ begin
18
+ if rs.next
19
+ begin
20
+ rs.getLong(1)
21
+ rescue
22
+ rs.getObject(1) rescue nil
23
+ end
24
+ end
25
+ ensure
26
+ rs.close
27
+ end
28
+ else
29
+ statement(conn) do |stmt|
30
+ sql = 'SELECT SCOPE_IDENTITY()'
31
+ rs = log_connection_yield(sql, conn){stmt.executeQuery(sql)}
32
+ rs.next
33
+ rs.getLong(1)
34
+ end
35
+ end
36
+ end
37
+
38
+ def prepare_jdbc_statement(conn, sql, opts)
39
+ if opts[:type] == :insert
40
+ conn.prepareStatement(sql, JavaSQL::Statement::RETURN_GENERATED_KEYS)
41
+ else
42
+ super
20
43
  end
21
44
  end
22
45
 
@@ -68,7 +68,7 @@ module Sequel
68
68
  end
69
69
 
70
70
  # Run the default connection setting SQL statements.
71
- # Apply the connectiong setting SQLs for every new connection.
71
+ # Apply the connection setting SQLs for every new connection.
72
72
  def setup_connection(conn)
73
73
  mysql_connection_setting_sqls.each{|sql| statement(conn){|s| log_connection_yield(sql, conn){s.execute(sql)}}}
74
74
  super
@@ -75,7 +75,14 @@ module Sequel
75
75
  def copy_table(table, opts=OPTS)
76
76
  synchronize(opts[:server]) do |conn|
77
77
  copy_manager = Java::OrgPostgresqlCopy::CopyManager.new(conn)
78
- copier = copy_manager.copy_out(copy_table_sql(table, opts))
78
+ sql = copy_table_sql(table, opts)
79
+
80
+ begin
81
+ copier = copy_manager.copy_out(sql)
82
+ rescue *DATABASE_ERROR_CLASSES => e
83
+ raise_error(e)
84
+ end
85
+
79
86
  begin
80
87
  if defined?(yield)
81
88
  while buf = copier.readFromCopy
@@ -147,7 +154,11 @@ module Sequel
147
154
  # a PGObject instance with unknown type and the bound argument string value,
148
155
  # and set that as the prepared statement argument.
149
156
  def set_ps_arg(cps, arg, i)
150
- if v = bound_variable_arg(arg, nil)
157
+ unless v = bound_variable_arg(arg, nil)
158
+ v = arg.strftime("%F %T.%6N%z") if arg.is_a?(DateTime)
159
+ end
160
+
161
+ if v
151
162
  obj = Java::OrgPostgresqlUtil::PGobject.new
152
163
  obj.setType("unknown")
153
164
  obj.setValue(v)
@@ -202,7 +213,7 @@ module Sequel
202
213
  INTEGER_TYPE = Java::JavaSQL::Types::INTEGER
203
214
  STRING_TYPE = Java::JavaSQL::Types::VARCHAR
204
215
  ARRAY_TYPE = Java::JavaSQL::Types::ARRAY
205
- PG_SPECIFIC_TYPES = [Java::JavaSQL::Types::ARRAY, Java::JavaSQL::Types::OTHER, Java::JavaSQL::Types::STRUCT, Java::JavaSQL::Types::TIME_WITH_TIMEZONE, Java::JavaSQL::Types::TIME].freeze
216
+ PG_SPECIFIC_TYPES = [Java::JavaSQL::Types::ARRAY, Java::JavaSQL::Types::OTHER, Java::JavaSQL::Types::STRUCT, Java::JavaSQL::Types::TIME_WITH_TIMEZONE, Java::JavaSQL::Types::TIME, Java::JavaSQL::Types::TIMESTAMP_WITH_TIMEZONE, Java::JavaSQL::Types::TIMESTAMP].freeze
206
217
 
207
218
  # Return PostgreSQL hstore types as ruby Hashes instead of
208
219
  # Java HashMaps. Only used if the database does not have a
@@ -5,7 +5,7 @@ require_relative 'utils/stored_procedures'
5
5
 
6
6
  module Sequel
7
7
  module JDBC
8
- # Make it accesing the java.sql hierarchy more ruby friendly.
8
+ # Make it accessing the java.sql hierarchy more ruby friendly.
9
9
  module JavaSQL
10
10
  include_package 'java.sql'
11
11
  end
@@ -24,7 +24,7 @@ module Sequel
24
24
 
25
25
  # Default database error classes
26
26
  DATABASE_ERROR_CLASSES = [NativeException]
27
- if JRUBY_VERSION < '9.2'
27
+ if JRUBY_VERSION.to_r < Rational('9.2')
28
28
  # On JRuby <9.2, still include ::NativeException, as it is still needed in some cases
29
29
  DATABASE_ERROR_CLASSES << ::NativeException
30
30
  end
@@ -361,7 +361,7 @@ module Sequel
361
361
  # The uri for this connection. You can specify the uri
362
362
  # using the :uri, :url, or :database options. You don't
363
363
  # need to worry about this if you use Sequel.connect
364
- # with the JDBC connectrion strings.
364
+ # with the JDBC connection strings.
365
365
  def uri(opts=OPTS)
366
366
  opts = @opts.merge(opts)
367
367
  ur = opts[:uri] || opts[:url] || opts[:database]
@@ -496,6 +496,7 @@ module Sequel
496
496
  rescue *DATABASE_ERROR_CLASSES => e
497
497
  raise_error(e)
498
498
  ensure
499
+ cps.clear_parameters
499
500
  cps.close unless name
500
501
  end
501
502
  end
@@ -38,7 +38,7 @@ module Sequel
38
38
  #
39
39
  # nil :: Return nil for all inserts
40
40
  # Integer :: Starting integer for next insert, with
41
- # futher inserts getting an incremented
41
+ # further inserts getting an incremented
42
42
  # value
43
43
  # Array :: First insert gets the first value in the
44
44
  # array, second gets the second value, etc.
@@ -69,7 +69,7 @@ module Sequel
69
69
  # :auto_is_null :: Set to true to use MySQL default behavior of having
70
70
  # a filter for an autoincrement column equals NULL to return the last
71
71
  # inserted row.
72
- # :charset :: Same as :encoding (:encoding takes precendence)
72
+ # :charset :: Same as :encoding (:encoding takes precedence)
73
73
  # :compress :: Set to false to not compress results from the server
74
74
  # :config_default_group :: The default group to read from the in
75
75
  # the MySQL config file.
@@ -284,8 +284,13 @@ module Sequel
284
284
  Dataset
285
285
  end
286
286
 
287
+ # If the error is a Mysql::Error, check the client error code and exception
288
+ # message for disconnects.
287
289
  def disconnect_error?(e, opts)
288
- super || (e.is_a?(::Mysql::Error) && MYSQL_DATABASE_DISCONNECT_ERRORS.match(e.message))
290
+ super ||
291
+ (e.is_a?(::Mysql::Error) &&
292
+ (MYSQL_DISCONNECT_ERROR_CODES.include?(e.errno) ||
293
+ MYSQL_DATABASE_DISCONNECT_ERRORS.match(e.message)))
289
294
  end
290
295
 
291
296
  # Convert tinyint(1) type to boolean if convert_tinyint_to_bool is true
@@ -28,7 +28,7 @@ module Sequel
28
28
  # :auto_is_null :: Set to true to use MySQL default behavior of having
29
29
  # a filter for an autoincrement column equals NULL to return the last
30
30
  # inserted row.
31
- # :charset :: Same as :encoding (:encoding takes precendence)
31
+ # :charset :: Same as :encoding (:encoding takes precedence)
32
32
  # :encoding :: Set all the related character sets for this
33
33
  # connection (connection, client, database, server, and results).
34
34
  #
@@ -215,13 +215,14 @@ module Sequel
215
215
  end
216
216
 
217
217
  # If a connection object is available, try pinging it. Otherwise, if the
218
- # error is a Mysql2::Error, check the SQL state and exception message for
219
- # disconnects.
218
+ # error is a Mysql2::Error, check the client error code, SQL state, and
219
+ # exception message for disconnects.
220
220
  def disconnect_error?(e, opts)
221
221
  super ||
222
222
  ((conn = opts[:conn]) && !conn.ping) ||
223
223
  (e.is_a?(::Mysql2::Error) &&
224
- ((e.sql_state && e.sql_state.start_with?("08")) ||
224
+ (MYSQL_DISCONNECT_ERROR_CODES.include?(e.errno) ||
225
+ (e.sql_state && e.sql_state.start_with?("08")) ||
225
226
  MYSQL_DATABASE_DISCONNECT_ERRORS.match(e.message)))
226
227
  end
227
228
 
@@ -5,7 +5,7 @@ require_relative 'shared/postgres'
5
5
  begin
6
6
  require 'pg'
7
7
 
8
- # :nocov:
8
+ # simplecov:disable
9
9
  Sequel::Postgres::PGError = PG::Error if defined?(PG::Error)
10
10
  Sequel::Postgres::PGconn = PG::Connection if defined?(PG::Connection)
11
11
  Sequel::Postgres::PGresult = PG::Result if defined?(PG::Result)
@@ -16,7 +16,7 @@ begin
16
16
  end
17
17
 
18
18
  if defined?(PG::TypeMapByClass)
19
- # :nocov:
19
+ # simplecov:enable
20
20
  type_map = Sequel::Postgres::PG_QUERY_TYPE_MAP = PG::TypeMapByClass.new
21
21
  type_map[Integer] = PG::TextEncoder::Integer.new
22
22
  type_map[FalseClass] = type_map[TrueClass] = PG::TextEncoder::Boolean.new
@@ -25,7 +25,7 @@ begin
25
25
 
26
26
  Sequel::Postgres::USES_PG = true
27
27
  rescue LoadError => e
28
- # :nocov:
28
+ # simplecov:disable
29
29
  begin
30
30
  require 'sequel/postgres-pr'
31
31
  rescue LoadError
@@ -36,19 +36,19 @@ rescue LoadError => e
36
36
  end
37
37
  end
38
38
  Sequel::Postgres::USES_PG = false
39
- # :nocov:
39
+ # simplecov:enable
40
40
  end
41
41
 
42
42
  module Sequel
43
43
  module Postgres
44
- # :nocov:
44
+ # simplecov:disable
45
45
  if USES_PG
46
46
  # Whether the given sequel_pg version integer is supported.
47
47
  def self.sequel_pg_version_supported?(version)
48
48
  version >= 10617
49
49
  end
50
50
  end
51
- # :nocov:
51
+ # simplecov:enable
52
52
 
53
53
  # PGconn subclass for connection specific methods used with the
54
54
  # pg or postgres-pr driver.
@@ -56,9 +56,9 @@ module Sequel
56
56
  # The underlying exception classes to reraise as disconnect errors
57
57
  # instead of regular database errors.
58
58
  DISCONNECT_ERROR_CLASSES = [IOError, Errno::EPIPE, Errno::ECONNRESET]
59
- # :nocov:
59
+ # simplecov:disable
60
60
  if defined?(::PG::ConnectionBad)
61
- # :nocov:
61
+ # simplecov:enable
62
62
  DISCONNECT_ERROR_CLASSES << ::PG::ConnectionBad
63
63
  end
64
64
  DISCONNECT_ERROR_CLASSES.freeze
@@ -84,7 +84,7 @@ module Sequel
84
84
  # are SQL strings.
85
85
  attr_reader :prepared_statements
86
86
 
87
- # :nocov:
87
+ # simplecov:disable
88
88
  unless public_method_defined?(:async_exec_params)
89
89
  alias async_exec_params async_exec
90
90
  end
@@ -127,7 +127,7 @@ module Sequel
127
127
  alias cmd_tuples cmdtuples
128
128
  end
129
129
  end
130
- # :nocov:
130
+ # simplecov:enable
131
131
 
132
132
  # Raise a Sequel::DatabaseDisconnectError if a one of the disconnect
133
133
  # error classes is raised, or a PGError is raised and the connection
@@ -185,12 +185,12 @@ module Sequel
185
185
  case arg
186
186
  when Sequel::SQL::Blob
187
187
  {:value=>arg, :type=>17, :format=>1}
188
- # :nocov:
188
+ # simplecov:disable
189
189
  # Not covered by tests as tests use pg_extended_date_support
190
190
  # extension, which has basically the same code.
191
191
  when Time, DateTime
192
192
  @default_dataset.literal_date_or_time(arg)
193
- # :nocov:
193
+ # simplecov:enable
194
194
  else
195
195
  arg
196
196
  end
@@ -225,9 +225,9 @@ module Sequel
225
225
  :sslmode => opts[:sslmode],
226
226
  :sslrootcert => opts[:sslrootcert]
227
227
  }.delete_if { |key, value| blank_object?(value) }
228
- # :nocov:
228
+ # simplecov:disable
229
229
  connection_params.merge!(opts[:driver_options]) if opts[:driver_options]
230
- # :nocov:
230
+ # simplecov:enable
231
231
  conn = Adapter.connect(opts[:conn_str] || connection_params)
232
232
 
233
233
  conn.instance_variable_set(:@prepared_statements, {})
@@ -236,12 +236,12 @@ module Sequel
236
236
  conn.set_notice_receiver(&receiver)
237
237
  end
238
238
 
239
- # :nocov:
239
+ # simplecov:disable
240
240
  if conn.respond_to?(:type_map_for_queries=) && defined?(PG_QUERY_TYPE_MAP)
241
- # :nocov:
241
+ # simplecov:enable
242
242
  conn.type_map_for_queries = PG_QUERY_TYPE_MAP
243
243
  end
244
- # :nocov:
244
+ # simplecov:disable
245
245
  else
246
246
  unless typecast_value_boolean(@opts.fetch(:force_standard_strings, true))
247
247
  raise Error, "Cannot create connection using postgres-pr unless force_standard_strings is set"
@@ -256,11 +256,11 @@ module Sequel
256
256
  opts[:password]
257
257
  )
258
258
  end
259
- # :nocov:
259
+ # simplecov:enable
260
260
 
261
261
  conn.instance_variable_set(:@db, self)
262
262
 
263
- # :nocov:
263
+ # simplecov:disable
264
264
  if encoding = opts[:encoding] || opts[:charset]
265
265
  if conn.respond_to?(:set_client_encoding)
266
266
  conn.set_client_encoding(encoding)
@@ -268,7 +268,7 @@ module Sequel
268
268
  conn.async_exec("set client_encoding to '#{encoding}'")
269
269
  end
270
270
  end
271
- # :nocov:
271
+ # simplecov:enable
272
272
 
273
273
  connection_configuration_sqls(opts).each{|sql| conn.execute(sql)}
274
274
  conn
@@ -295,9 +295,9 @@ module Sequel
295
295
  nil
296
296
  end
297
297
 
298
- # :nocov:
298
+ # simplecov:disable
299
299
  if USES_PG && Object.const_defined?(:PG) && ::PG.const_defined?(:Constants) && ::PG::Constants.const_defined?(:PG_DIAG_SCHEMA_NAME)
300
- # :nocov:
300
+ # simplecov:enable
301
301
  # Return a hash of information about the related PGError (or Sequel::DatabaseError that
302
302
  # wraps a PGError), with the following entries (any of which may be +nil+):
303
303
  #
@@ -348,9 +348,9 @@ module Sequel
348
348
  synchronize(opts[:server]){|conn| check_database_errors{_execute(conn, sql, opts, &block)}}
349
349
  end
350
350
 
351
- # :nocov:
351
+ # simplecov:disable
352
352
  if USES_PG
353
- # :nocov:
353
+ # simplecov:enable
354
354
  # +copy_table+ uses PostgreSQL's +COPY TO STDOUT+ SQL statement to return formatted
355
355
  # results directly to the caller. This method is only supported if pg is the
356
356
  # underlying ruby driver. This method should only be called if you want
@@ -371,7 +371,8 @@ module Sequel
371
371
  #
372
372
  # The following options are respected:
373
373
  #
374
- # :format :: The format to use. text is the default, so this should be :csv or :binary.
374
+ # :format :: The format to use. The PostgreSQL default is text, possible options are :csv,
375
+ # :json, or :binary.
375
376
  # :options :: An options SQL string to use, which should contain comma separated options.
376
377
  # :server :: The server on which to run the query.
377
378
  #
@@ -380,7 +381,9 @@ module Sequel
380
381
  # of the data.
381
382
  def copy_table(table, opts=OPTS)
382
383
  synchronize(opts[:server]) do |conn|
383
- conn.execute(copy_table_sql(table, opts))
384
+ sql = copy_table_sql(table, opts)
385
+ check_database_errors{conn.execute(sql)}
386
+
384
387
  begin
385
388
  if defined?(yield)
386
389
  while buf = conn.get_copy_data
@@ -544,10 +547,10 @@ module Sequel
544
547
  def adapter_initialize
545
548
  @use_iso_date_format = typecast_value_boolean(@opts.fetch(:use_iso_date_format, true))
546
549
  initialize_postgres_adapter
547
- # :nocov:
550
+ # simplecov:disable
548
551
  add_conversion_proc(17, method(:unescape_bytea)) if USES_PG
549
552
  add_conversion_proc(1082, TYPE_TRANSLATOR_DATE) if @use_iso_date_format
550
- # :nocov:
553
+ # simplecov:enable
551
554
  self.convert_infinite_timestamps = @opts[:convert_infinite_timestamps]
552
555
  end
553
556
 
@@ -560,19 +563,19 @@ module Sequel
560
563
  # Set the DateStyle to ISO if configured, for faster date parsing.
561
564
  def connection_configuration_sqls(opts=@opts)
562
565
  sqls = super
563
- # :nocov:
566
+ # simplecov:disable
564
567
  sqls << "SET DateStyle = 'ISO'" if @use_iso_date_format
565
- # :nocov:
568
+ # simplecov:enable
566
569
  sqls
567
570
  end
568
571
 
569
- # :nocov:
572
+ # simplecov:disable
570
573
  if USES_PG
571
574
  def unescape_bytea(s)
572
575
  ::Sequel::SQL::Blob.new(Adapter.unescape_bytea(s))
573
576
  end
574
577
  end
575
- # :nocov:
578
+ # simplecov:enable
576
579
 
577
580
  DATABASE_ERROR_CLASSES = [PGError].freeze
578
581
  def database_error_classes
@@ -586,9 +589,9 @@ module Sequel
586
589
  end
587
590
 
588
591
  def database_exception_sqlstate(exception, opts)
589
- # :nocov:
592
+ # simplecov:disable
590
593
  if exception.respond_to?(:result) && (result = exception.result)
591
- # :nocov:
594
+ # simplecov:enable
592
595
  result.error_field(PGresult::PG_DIAG_SQLSTATE)
593
596
  end
594
597
  end
@@ -699,9 +702,9 @@ module Sequel
699
702
  clone(:where=>Sequel.lit(['CURRENT OF '], Sequel.identifier(cursor_name)))
700
703
  end
701
704
 
702
- # :nocov:
705
+ # simplecov:disable
703
706
  if USES_PG
704
- # :nocov:
707
+ # simplecov:enable
705
708
  PREPARED_ARG_PLACEHOLDER = LiteralString.new('$').freeze
706
709
 
707
710
  # PostgreSQL specific argument mapper used for mapping the named
@@ -804,7 +807,7 @@ module Sequel
804
807
  end
805
808
 
806
809
  # Set the columns based on the result set, and return the array of
807
- # field numers, type conversion procs, and name symbol arrays.
810
+ # field numbers, type conversion procs, and name symbol arrays.
808
811
  def fetch_rows_set_cols(res)
809
812
  cols = []
810
813
  procs = db.conversion_procs
@@ -848,7 +851,7 @@ module Sequel
848
851
  end
849
852
  end
850
853
 
851
- # :nocov:
854
+ # simplecov:disable
852
855
  if Sequel::Postgres::USES_PG && !ENV['NO_SEQUEL_PG']
853
856
  begin
854
857
  require 'sequel_pg'
@@ -860,4 +863,4 @@ if Sequel::Postgres::USES_PG && !ENV['NO_SEQUEL_PG']
860
863
  rescue LoadError
861
864
  end
862
865
  end
863
- # :nocov:
866
+ # simplecov:enable
@@ -153,7 +153,7 @@ module Sequel
153
153
  end
154
154
 
155
155
  # REORG the related table whenever it is altered. This is not always
156
- # required, but it is necessary for compatibilty with other Sequel
156
+ # required, but it is necessary for compatibility with other Sequel
157
157
  # code in many cases.
158
158
  def apply_alter_table(name, ops)
159
159
  alter_table_sql_list(name, ops).each do |sql|
@@ -190,6 +190,9 @@ module Sequel
190
190
  # creating the table, since it is not possible to do it in one step.
191
191
  def create_table_as(name, sql, options)
192
192
  super
193
+ if options[:temp]
194
+ name = Sequel.qualify(:session, name)
195
+ end
193
196
  from(name).insert(sql.is_a?(Dataset) ? sql : dataset.with_sql(sql))
194
197
  end
195
198
 
@@ -437,7 +440,7 @@ module Sequel
437
440
  '1'
438
441
  end
439
442
 
440
- # DB2 uses a literal hexidecimal number for blob strings
443
+ # DB2 uses a literal hexadecimal number for blob strings
441
444
  def literal_blob_append(sql, v)
442
445
  if db.use_clob_as_blob
443
446
  super