sequel 5.107.0 → 5.108.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 (131) 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/ibmdb.rb +2 -2
  5. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
  6. data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
  7. data/lib/sequel/adapters/jdbc.rb +2 -2
  8. data/lib/sequel/adapters/mock.rb +1 -1
  9. data/lib/sequel/adapters/mysql.rb +7 -2
  10. data/lib/sequel/adapters/mysql2.rb +5 -4
  11. data/lib/sequel/adapters/postgres.rb +37 -37
  12. data/lib/sequel/adapters/shared/db2.rb +2 -2
  13. data/lib/sequel/adapters/shared/mssql.rb +4 -4
  14. data/lib/sequel/adapters/shared/mysql.rb +2 -2
  15. data/lib/sequel/adapters/shared/postgres.rb +67 -44
  16. data/lib/sequel/adapters/shared/sqlite.rb +3 -3
  17. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +1 -1
  18. data/lib/sequel/adapters/utils/mysql_mysql2.rb +11 -1
  19. data/lib/sequel/connection_pool/sharded_single.rb +1 -1
  20. data/lib/sequel/connection_pool/sharded_threaded.rb +7 -5
  21. data/lib/sequel/connection_pool/sharded_timed_queue.rb +3 -3
  22. data/lib/sequel/connection_pool/threaded.rb +9 -7
  23. data/lib/sequel/connection_pool/timed_queue.rb +2 -2
  24. data/lib/sequel/connection_pool.rb +3 -3
  25. data/lib/sequel/core.rb +30 -22
  26. data/lib/sequel/database/connecting.rb +1 -1
  27. data/lib/sequel/database/features.rb +1 -1
  28. data/lib/sequel/database/misc.rb +7 -7
  29. data/lib/sequel/database/query.rb +2 -2
  30. data/lib/sequel/database/schema_generator.rb +4 -4
  31. data/lib/sequel/database/schema_methods.rb +2 -2
  32. data/lib/sequel/database/transactions.rb +4 -4
  33. data/lib/sequel/dataset/actions.rb +1 -1
  34. data/lib/sequel/dataset/features.rb +4 -4
  35. data/lib/sequel/dataset/graph.rb +1 -1
  36. data/lib/sequel/dataset/misc.rb +3 -3
  37. data/lib/sequel/dataset/prepared_statements.rb +2 -2
  38. data/lib/sequel/dataset/query.rb +8 -8
  39. data/lib/sequel/dataset/sql.rb +18 -10
  40. data/lib/sequel/dataset.rb +2 -2
  41. data/lib/sequel/deprecated.rb +2 -2
  42. data/lib/sequel/exceptions.rb +2 -2
  43. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  44. data/lib/sequel/extensions/async_thread_pool.rb +3 -3
  45. data/lib/sequel/extensions/auto_cast_date_and_time.rb +2 -2
  46. data/lib/sequel/extensions/blank.rb +2 -2
  47. data/lib/sequel/extensions/constraint_validations.rb +1 -1
  48. data/lib/sequel/extensions/core_refinements.rb +8 -8
  49. data/lib/sequel/extensions/date_arithmetic.rb +1 -1
  50. data/lib/sequel/extensions/datetime_parse_to_time.rb +2 -2
  51. data/lib/sequel/extensions/duplicate_columns_handler.rb +2 -2
  52. data/lib/sequel/extensions/graph_each.rb +1 -1
  53. data/lib/sequel/extensions/index_caching.rb +1 -1
  54. data/lib/sequel/extensions/inflector.rb +5 -5
  55. data/lib/sequel/extensions/is_distinct_from.rb +2 -2
  56. data/lib/sequel/extensions/lit_require_frozen.rb +3 -3
  57. data/lib/sequel/extensions/migration.rb +21 -7
  58. data/lib/sequel/extensions/named_timezones.rb +8 -8
  59. data/lib/sequel/extensions/pg_array.rb +9 -8
  60. data/lib/sequel/extensions/pg_array_ops.rb +69 -14
  61. data/lib/sequel/extensions/pg_auto_parameterize.rb +2 -2
  62. data/lib/sequel/extensions/pg_auto_parameterize_in_array.rb +3 -3
  63. data/lib/sequel/extensions/pg_enum.rb +2 -2
  64. data/lib/sequel/extensions/pg_extended_date_support.rb +5 -5
  65. data/lib/sequel/extensions/pg_extended_integer_support.rb +1 -1
  66. data/lib/sequel/extensions/pg_hstore.rb +2 -2
  67. data/lib/sequel/extensions/pg_hstore_ops.rb +5 -5
  68. data/lib/sequel/extensions/pg_inet.rb +2 -2
  69. data/lib/sequel/extensions/pg_inet_ops.rb +2 -2
  70. data/lib/sequel/extensions/pg_interval.rb +6 -6
  71. data/lib/sequel/extensions/pg_json.rb +4 -4
  72. data/lib/sequel/extensions/pg_json_ops.rb +11 -11
  73. data/lib/sequel/extensions/pg_range.rb +6 -6
  74. data/lib/sequel/extensions/pg_range_ops.rb +7 -7
  75. data/lib/sequel/extensions/pg_row.rb +4 -4
  76. data/lib/sequel/extensions/pg_row_ops.rb +6 -6
  77. data/lib/sequel/extensions/provenance.rb +2 -2
  78. data/lib/sequel/extensions/query.rb +2 -2
  79. data/lib/sequel/extensions/s.rb +2 -2
  80. data/lib/sequel/extensions/schema_dumper.rb +4 -4
  81. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +2 -0
  82. data/lib/sequel/extensions/sql_comments.rb +1 -1
  83. data/lib/sequel/extensions/sql_log_normalizer.rb +1 -1
  84. data/lib/sequel/extensions/sqlite_json_ops.rb +2 -2
  85. data/lib/sequel/extensions/string_agg.rb +5 -5
  86. data/lib/sequel/extensions/symbol_aref.rb +3 -3
  87. data/lib/sequel/extensions/symbol_aref_refinement.rb +3 -3
  88. data/lib/sequel/extensions/symbol_as_refinement.rb +2 -2
  89. data/lib/sequel/extensions/transaction_connection_validator.rb +1 -1
  90. data/lib/sequel/model/associations.rb +17 -17
  91. data/lib/sequel/model/base.rb +19 -11
  92. data/lib/sequel/model/inflections.rb +1 -1
  93. data/lib/sequel/model/plugins.rb +2 -2
  94. data/lib/sequel/model.rb +2 -2
  95. data/lib/sequel/plugins/association_pks.rb +1 -1
  96. data/lib/sequel/plugins/association_proxies.rb +4 -4
  97. data/lib/sequel/plugins/auto_restrict_eager_graph.rb +2 -0
  98. data/lib/sequel/plugins/caching.rb +1 -1
  99. data/lib/sequel/plugins/class_table_inheritance.rb +1 -1
  100. data/lib/sequel/plugins/column_encryption.rb +10 -10
  101. data/lib/sequel/plugins/concurrent_eager_loading.rb +2 -2
  102. data/lib/sequel/plugins/csv_serializer.rb +2 -2
  103. data/lib/sequel/plugins/deprecated_associations.rb +2 -2
  104. data/lib/sequel/plugins/eager_each.rb +1 -1
  105. data/lib/sequel/plugins/finder.rb +1 -1
  106. data/lib/sequel/plugins/forbid_lazy_load.rb +3 -3
  107. data/lib/sequel/plugins/insert_conflict.rb +1 -1
  108. data/lib/sequel/plugins/insert_returning_select.rb +1 -1
  109. data/lib/sequel/plugins/json_serializer.rb +4 -4
  110. data/lib/sequel/plugins/lazy_attributes.rb +1 -1
  111. data/lib/sequel/plugins/many_through_many.rb +1 -1
  112. data/lib/sequel/plugins/pg_array_associations.rb +4 -4
  113. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +3 -3
  114. data/lib/sequel/plugins/pg_eager_any_typed_array.rb +2 -2
  115. data/lib/sequel/plugins/prepared_statements.rb +2 -2
  116. data/lib/sequel/plugins/serialization.rb +1 -1
  117. data/lib/sequel/plugins/sharding.rb +1 -1
  118. data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
  119. data/lib/sequel/plugins/skip_saving_columns.rb +2 -2
  120. data/lib/sequel/plugins/split_values.rb +1 -1
  121. data/lib/sequel/plugins/sql_comments.rb +8 -8
  122. data/lib/sequel/plugins/subclasses.rb +6 -6
  123. data/lib/sequel/plugins/subset_conditions.rb +2 -2
  124. data/lib/sequel/plugins/tactical_eager_loading.rb +1 -1
  125. data/lib/sequel/plugins/throw_failures.rb +2 -2
  126. data/lib/sequel/plugins/unused_associations.rb +5 -5
  127. data/lib/sequel/plugins/validation_helpers.rb +1 -1
  128. data/lib/sequel/plugins/xml_serializer.rb +2 -0
  129. data/lib/sequel/sql.rb +11 -11
  130. data/lib/sequel/version.rb +1 -1
  131. metadata +1 -1
@@ -204,12 +204,12 @@ module Sequel
204
204
  @in = v
205
205
  end
206
206
 
207
- # Assumes hash partitioning, sets the modulus for this parition.
207
+ # Assumes hash partitioning, sets the modulus for this partition.
208
208
  def modulus(v)
209
209
  @modulus = v
210
210
  end
211
211
 
212
- # Assumes hash partitioning, sets the remainder for this parition.
212
+ # Assumes hash partitioning, sets the remainder for this partition.
213
213
  def remainder(v)
214
214
  @remainder = v
215
215
  end
@@ -406,13 +406,13 @@ module Sequel
406
406
  Data.new(@name, @key, @labels, @source, @destination).freeze
407
407
  end
408
408
 
409
- # Specify the source for the edge, with block evaluted by Target.
409
+ # Specify the source for the edge, with block evaluated by Target.
410
410
  def source(name, &block)
411
411
  raise Error, "cannot specify multiple sources for a property graph edge" if @source
412
412
  @source = Target.new(name, &block)
413
413
  end
414
414
 
415
- # Specify the destination for the edge, with block evaluted by Target.
415
+ # Specify the destination for the edge, with block evaluated by Target.
416
416
  def destination(name, &block)
417
417
  raise Error, "cannot specify multiple destinations for a property graph edge" if @destination
418
418
  @destination = Target.new(name, &block)
@@ -437,12 +437,12 @@ module Sequel
437
437
  Data.new(@vertices, @edges).freeze
438
438
  end
439
439
 
440
- # Adds a vertex to the property graph, with the block evaluted by Vertex.
440
+ # Adds a vertex to the property graph, with the block evaluated by Vertex.
441
441
  def vertex(name, opts=OPTS, &block)
442
442
  @vertices << Vertex.new(name, opts, &block)
443
443
  end
444
444
 
445
- # Adds an edge to the property graph, with the block evaluted by Edge.
445
+ # Adds an edge to the property graph, with the block evaluated by Edge.
446
446
  def edge(name, opts=OPTS, &block)
447
447
  @edges << Edge.new(name, opts, &block)
448
448
  end
@@ -962,7 +962,7 @@ module Sequel
962
962
  # Keys are CHECK constraint name symbols. Values are hashes with the following keys:
963
963
  # :definition :: An SQL fragment for the definition of the constraint
964
964
  # :columns :: An array of column symbols for the columns referenced in the constraint,
965
- # can be an empty array if the database cannot deteremine the column symbols.
965
+ # can be an empty array if the database cannot determine the column symbols.
966
966
  def check_constraints(table)
967
967
  m = output_identifier_meth
968
968
 
@@ -1354,7 +1354,7 @@ module Sequel
1354
1354
  #
1355
1355
  # link :: Add a bidirectional link to a new element (vertex or edge)
1356
1356
  # to :: Add a directional link from the last element to the new element
1357
- # from :: Add a direciton link from the new element to last element
1357
+ # from :: Add a direction link from the new element to last element
1358
1358
  # columns :: Replace the columns the graph table returns
1359
1359
  # add_columns :: Append to the columns the graph table returns.
1360
1360
  #
@@ -1378,7 +1378,7 @@ module Sequel
1378
1378
  # gt = gt.to(:v2)
1379
1379
  # # GRAPH_TABLE ("pgn" MATCH (IS "iv")-[IS "e1"]->(IS "v2") COLUMNS ("c", 1 AS "d"))
1380
1380
  #
1381
- # # Adds bidirection link from vertex to vertex (overriding the default)
1381
+ # # Adds bidirectional link from vertex to vertex (overriding the default)
1382
1382
  # gt = gt.link(:v3, vertex: true)
1383
1383
  # # GRAPH_TABLE ("pgn" MATCH (IS "iv")-[IS "e1"]->(IS "v2")-(IS "v3") COLUMNS ("c", 1 AS "d"))
1384
1384
  #
@@ -1556,12 +1556,12 @@ module Sequel
1556
1556
  seq_ds = metadata_dataset.from(:pg_sequence).where(:seqrelid=>regclass_oid(LiteralString.new(seq.freeze)))
1557
1557
  increment_by = :seqincrement
1558
1558
  min_value = :seqmin
1559
- # :nocov:
1559
+ # simplecov:disable
1560
1560
  else
1561
1561
  seq_ds = metadata_dataset.from(LiteralString.new(seq))
1562
1562
  increment_by = :increment_by
1563
1563
  min_value = :min_value
1564
- # :nocov:
1564
+ # simplecov:enable
1565
1565
  end
1566
1566
 
1567
1567
  get{setval(seq, db[table].select(coalesce(max(pk)+seq_ds.select(increment_by), seq_ds.select(min_value))), false)}
@@ -1574,9 +1574,9 @@ module Sequel
1574
1574
  # PostgreSQL uses SERIAL psuedo-type instead of AUTOINCREMENT for
1575
1575
  # managing incrementing primary keys.
1576
1576
  def serial_primary_key_options
1577
- # :nocov:
1577
+ # simplecov:disable
1578
1578
  auto_increment_key = server_version >= 100002 ? :identity : :serial
1579
- # :nocov:
1579
+ # simplecov:enable
1580
1580
  {:primary_key => true, auto_increment_key => true, :type=>Integer}
1581
1581
  end
1582
1582
 
@@ -1773,12 +1773,12 @@ module Sequel
1773
1773
  if server_version >= 90500
1774
1774
  cpos = Sequel.expr{array_position(co[:conkey], ctable[:attnum])}
1775
1775
  rpos = Sequel.expr{array_position(co[:confkey], rtable[:attnum])}
1776
- # :nocov:
1776
+ # simplecov:disable
1777
1777
  else
1778
1778
  range = 0...32
1779
1779
  cpos = Sequel.expr{SQL::CaseExpression.new(range.map{|x| [SQL::Subscript.new(co[:conkey], [x]), x]}, 32, ctable[:attnum])}
1780
1780
  rpos = Sequel.expr{SQL::CaseExpression.new(range.map{|x| [SQL::Subscript.new(co[:confkey], [x]), x]}, 32, rtable[:attnum])}
1781
- # :nocov:
1781
+ # simplecov:enable
1782
1782
  end
1783
1783
 
1784
1784
  ds = metadata_dataset.
@@ -1815,19 +1815,19 @@ module Sequel
1815
1815
  def _add_validated_enforced_constraint_columns(ds)
1816
1816
  validated_cond = if server_version >= 90100
1817
1817
  Sequel[:convalidated]
1818
- # :nocov:
1818
+ # simplecov:disable
1819
1819
  else
1820
1820
  Sequel.cast(true, TrueClass)
1821
- # :nocov:
1821
+ # simplecov:enable
1822
1822
  end
1823
1823
  ds = ds.select_append(validated_cond.as(:validated))
1824
1824
 
1825
1825
  enforced_cond = if server_version >= 180000
1826
1826
  Sequel[:conenforced]
1827
- # :nocov:
1827
+ # simplecov:disable
1828
1828
  else
1829
1829
  Sequel.cast(true, TrueClass)
1830
- # :nocov:
1830
+ # simplecov:enable
1831
1831
  end
1832
1832
  ds = ds.select_append(enforced_cond.as(:enforced))
1833
1833
 
@@ -1839,11 +1839,11 @@ module Sequel
1839
1839
  @_indexes_ds ||= begin
1840
1840
  if server_version >= 90500
1841
1841
  order = [Sequel[:indc][:relname], Sequel.function(:array_position, Sequel[:ind][:indkey], Sequel[:att][:attnum])]
1842
- # :nocov:
1842
+ # simplecov:disable
1843
1843
  else
1844
1844
  range = 0...32
1845
1845
  order = [Sequel[:indc][:relname], SQL::CaseExpression.new(range.map{|x| [SQL::Subscript.new(Sequel[:ind][:indkey], [x]), x]}, 32, Sequel[:att][:attnum])]
1846
- # :nocov:
1846
+ # simplecov:enable
1847
1847
  end
1848
1848
 
1849
1849
  attnums = SQL::Function.new(:ANY, Sequel[:ind][:indkey])
@@ -1861,10 +1861,10 @@ module Sequel
1861
1861
  order(*order).
1862
1862
  select{[indc[:relname].as(:name), ind[:indisunique].as(:unique), att[:attname].as(:column), con[:condeferrable].as(:deferrable)]}
1863
1863
 
1864
- # :nocov:
1864
+ # simplecov:disable
1865
1865
  ds = ds.where(:indisready=>true) if server_version >= 80300
1866
1866
  ds = ds.where(:indislive=>true) if server_version >= 90300
1867
- # :nocov:
1867
+ # simplecov:enable
1868
1868
 
1869
1869
  ds
1870
1870
  end
@@ -1957,14 +1957,14 @@ module Sequel
1957
1957
  where{pg_attribute[:attnum] > 0}.
1958
1958
  order{pg_attribute[:attnum]}
1959
1959
 
1960
- # :nocov:
1960
+ # simplecov:disable
1961
1961
  if server_version > 100000
1962
- # :nocov:
1962
+ # simplecov:enable
1963
1963
  ds = ds.select_append{pg_attribute[:attidentity]}
1964
1964
 
1965
- # :nocov:
1965
+ # simplecov:disable
1966
1966
  if server_version > 120000
1967
- # :nocov:
1967
+ # simplecov:enable
1968
1968
  ds = ds.select_append{Sequel.~(pg_attribute[:attgenerated]=>'').as(:generated)}
1969
1969
  end
1970
1970
  end
@@ -2554,7 +2554,7 @@ module Sequel
2554
2554
  "#{super}#{create_table_suffix_sql(name, options)}"
2555
2555
  end
2556
2556
 
2557
- # Handle various PostgreSQl specific table extensions such as inheritance,
2557
+ # Handle various PostgreSQL specific table extensions such as inheritance,
2558
2558
  # partitioning, tablespaces, and foreign tables.
2559
2559
  def create_table_suffix_sql(name, options)
2560
2560
  sql = String.new
@@ -2858,9 +2858,9 @@ module Sequel
2858
2858
  row[:auto_increment] = !!(row[:default] =~ /\A(?:nextval)/i) || identity == 'a' || identity == 'd'
2859
2859
  end
2860
2860
 
2861
- # :nocov:
2861
+ # simplecov:disable
2862
2862
  if server_version >= 90600
2863
- # :nocov:
2863
+ # simplecov:enable
2864
2864
  case row[:oid]
2865
2865
  when 1082
2866
2866
  row[:min_value] = MIN_DATE
@@ -2949,9 +2949,9 @@ module Sequel
2949
2949
 
2950
2950
  # PostgreSQL 9.4+ supports views with check option.
2951
2951
  def view_with_check_option_support
2952
- # :nocov:
2952
+ # simplecov:disable
2953
2953
  :local if server_version >= 90400
2954
- # :nocov:
2954
+ # simplecov:enable
2955
2955
  end
2956
2956
  end
2957
2957
 
@@ -3054,12 +3054,12 @@ module Sequel
3054
3054
  rows[0]
3055
3055
  elsif rows.all?{|row| String === row}
3056
3056
  rows.join("\r\n")
3057
- # :nocov:
3057
+ # simplecov:disable
3058
3058
  else
3059
3059
  # This branch is unreachable in tests, but it seems better to just return
3060
3060
  # all rows than throw in error if this case actually happens.
3061
3061
  rows
3062
- # :nocov:
3062
+ # simplecov:enable
3063
3063
  end
3064
3064
  end
3065
3065
 
@@ -3181,8 +3181,11 @@ module Sequel
3181
3181
  # Handle uniqueness violations when inserting, by updating the conflicting row, using
3182
3182
  # ON CONFLICT. With no options, uses ON CONFLICT DO NOTHING. Options:
3183
3183
  # :conflict_where :: The index filter, when using a partial index to determine uniqueness.
3184
- # :constraint :: An explicit constraint name, has precendence over :target.
3184
+ # :constraint :: An explicit constraint name, has precedence over :target.
3185
3185
  # :target :: The column name or expression to handle uniqueness violations on.
3186
+ # :select :: Use ON CONFLICT DO SELECT. This will use the dataset's lock style.
3187
+ # You must use #returning on this dataset when using this option.
3188
+ # :select_where :: A WHERE condition to use for the select.
3186
3189
  # :update :: A hash of columns and values to set. Uses ON CONFLICT DO UPDATE.
3187
3190
  # :update_where :: A WHERE condition to use for the update.
3188
3191
  #
@@ -3213,7 +3216,21 @@ module Sequel
3213
3216
  # # INSERT INTO TABLE (a, b) VALUES (1, 2)
3214
3217
  # # ON CONFLICT ON CONSTRAINT table_a_uidx
3215
3218
  # # DO UPDATE SET b = excluded.b WHERE (table.status_id = 1)
3219
+ #
3220
+ # DB[:table].returning(:a).insert_conflict(target: :a, select: true).insert(a: 1, b: 2)
3221
+ # # INSERT INTO TABLE (a, b) VALUES (1, 2)
3222
+ # # ON CONFLICT (a) DO SELECT RETURNING a
3223
+ #
3224
+ # DB[:table].returning(:a).for_update.
3225
+ # insert_conflict(target: :a, select: true, select_where: {Sequel[:excluded][:b] => 3}).
3226
+ # insert(a: 1, b: 2)
3227
+ # # INSERT INTO TABLE (a, b) VALUES (1, 2)
3228
+ # # ON CONFLICT (a) DO SELECT FOR UPDATE WHERE (excluded.b = 3) RETURNING a
3216
3229
  def insert_conflict(opts=OPTS)
3230
+ if opts[:select] && opts[:update]
3231
+ raise Error, "Cannot provide both :select and :update options to insert_conflict"
3232
+ end
3233
+
3217
3234
  clone(:insert_conflict => opts)
3218
3235
  end
3219
3236
 
@@ -3454,14 +3471,14 @@ module Sequel
3454
3471
  server_version >= 90500
3455
3472
  end
3456
3473
 
3457
- # :nocov:
3474
+ # simplecov:disable
3458
3475
 
3459
3476
  # PostgreSQL supports timezones in literal timestamps
3460
3477
  def supports_timestamp_timezones?
3461
3478
  # SEQUEL6: Remove
3462
3479
  true
3463
3480
  end
3464
- # :nocov:
3481
+ # simplecov:enable
3465
3482
 
3466
3483
  # PostgreSQL 8.4+ supports WINDOW clause.
3467
3484
  def supports_window_clause?
@@ -3576,7 +3593,7 @@ module Sequel
3576
3593
  end
3577
3594
 
3578
3595
  # Use from_self for aggregate dataset using VALUES.
3579
- def aggreate_dataset_use_from_self?
3596
+ def aggregate_dataset_use_from_self?
3580
3597
  super || @opts[:values]
3581
3598
  end
3582
3599
 
@@ -3638,7 +3655,7 @@ module Sequel
3638
3655
  origin = String.new
3639
3656
  origin << 'EXPLAIN '
3640
3657
 
3641
- # :nocov:
3658
+ # simplecov:disable
3642
3659
  if server_version < 90000
3643
3660
  if opts[:analyze]
3644
3661
  origin << 'ANALYZE '
@@ -3646,7 +3663,7 @@ module Sequel
3646
3663
 
3647
3664
  return origin
3648
3665
  end
3649
- # :nocov:
3666
+ # simplecov:enable
3650
3667
 
3651
3668
  comma = nil
3652
3669
  paren = "("
@@ -3726,13 +3743,19 @@ module Sequel
3726
3743
  if values = opts[:update]
3727
3744
  sql << " DO UPDATE SET "
3728
3745
  update_sql_values_hash(sql, values)
3729
- if update_where = opts[:update_where]
3730
- sql << " WHERE "
3731
- literal_append(sql, update_where)
3732
- end
3746
+ where = opts[:update_where]
3747
+ elsif opts[:select]
3748
+ sql << " DO SELECT"
3749
+ select_lock_sql(sql)
3750
+ where = opts[:select_where]
3733
3751
  else
3734
3752
  sql << " DO NOTHING"
3735
3753
  end
3754
+
3755
+ if where
3756
+ sql << " WHERE "
3757
+ literal_append(sql, where)
3758
+ end
3736
3759
  end
3737
3760
  end
3738
3761
 
@@ -210,7 +210,7 @@ module Sequel
210
210
  if ops.length > 1 && ops.all?{|op| op[:op] == :add_constraint || op[:op] == :set_column_null}
211
211
  null_ops, ops = ops.partition{|op| op[:op] == :set_column_null}
212
212
 
213
- # Apply NULL/NOT NULL ops first, since those should be purely idependent of the constraints.
213
+ # Apply NULL/NOT NULL ops first, since those should be purely independent of the constraints.
214
214
  null_ops.each{|op| alter_table_sql_list(table, [op]).flatten.each{|sql| execute_ddl(sql)}}
215
215
 
216
216
  # If you are just doing constraints, apply all of them at the same time,
@@ -730,7 +730,7 @@ module Sequel
730
730
 
731
731
  # Handle uniqueness violations when inserting, by using a specified
732
732
  # resolution algorithm. With no options, uses INSERT OR REPLACE. SQLite
733
- # supports the following conflict resolution algoriths: ROLLBACK, ABORT,
733
+ # supports the following conflict resolution algorithms: ROLLBACK, ABORT,
734
734
  # FAIL, IGNORE and REPLACE.
735
735
  #
736
736
  # On SQLite 3.24.0+, you can pass a hash to use an ON CONFLICT clause.
@@ -892,7 +892,7 @@ module Sequel
892
892
  end
893
893
 
894
894
  # Use from_self for aggregate dataset using VALUES.
895
- def aggreate_dataset_use_from_self?
895
+ def aggregate_dataset_use_from_self?
896
896
  super || @opts[:values]
897
897
  end
898
898
 
@@ -49,7 +49,7 @@ module Sequel
49
49
  else
50
50
  # Sequel doesn't allow a nonpositive limit. If the offset
51
51
  # is greater than the number of rows, the empty result set
52
- # shuld be returned, so use a condition that is always false.
52
+ # should be returned, so use a condition that is always false.
53
53
  ds.where(1=>0)
54
54
  end
55
55
  sql = @opts[:append_sql] || String.new
@@ -22,7 +22,17 @@ module Sequel
22
22
  END
23
23
  # Error messages for mysql and mysql2 that indicate the current connection should be disconnected
24
24
  MYSQL_DATABASE_DISCONNECT_ERRORS = /\A#{Regexp.union(disconnect_errors)}/
25
-
25
+
26
+ # 2027 (CR_MALFORMED_PACKET) deliberately not included (protocol error, not connection error)
27
+ MYSQL_DISCONNECT_ERROR_CODES = [
28
+ 2002, # CR_CONNECTION_ERROR
29
+ 2006, # CR_SERVER_GONE_ERROR
30
+ 2013, # CR_SERVER_LOST
31
+ 2014, # CR_COMMANDS_OUT_OF_SYNC
32
+ 2055, # CR_SERVER_LOST_EXTENDED
33
+ ].freeze
34
+ private_constant :MYSQL_DISCONNECT_ERROR_CODES
35
+
26
36
  # Support stored procedures on MySQL
27
37
  def call_sproc(name, opts=OPTS, &block)
28
38
  args = opts[:args] || []
@@ -38,7 +38,7 @@ class Sequel::ShardedSingleConnectionPool < Sequel::ConnectionPool
38
38
 
39
39
  # Disconnects from the database. Once a connection is requested using
40
40
  # #hold, the connection is reestablished. Options:
41
- # :server :: Should be a symbol specifing the server to disconnect from,
41
+ # :server :: Should be a symbol specifying the server to disconnect from,
42
42
  # or an array of symbols to specify multiple servers.
43
43
  def disconnect(opts=OPTS)
44
44
  (opts[:server] ? Array(opts[:server]) : servers).each do |s|
@@ -1,5 +1,7 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ # SEQUEL6: Remove, deprecation: add warning if used on Ruby 3.2+
4
+
3
5
  require_relative 'threaded'
4
6
 
5
7
  # The slowest and most advanced connection pool, dealing with both multi-threaded
@@ -95,7 +97,7 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
95
97
  #
96
98
  # Once a connection is requested using #hold, the connection pool
97
99
  # creates new connections to the database. Options:
98
- # :server :: Should be a symbol specifing the server to disconnect from,
100
+ # :server :: Should be a symbol specifying the server to disconnect from,
99
101
  # or an array of symbols to specify multiple servers.
100
102
  def disconnect(opts=OPTS)
101
103
  (opts[:server] ? Array(opts[:server]) : sync{@servers.keys}).each do |s|
@@ -203,7 +205,7 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
203
205
 
204
206
  until conn = assign_connection(thread, server)
205
207
  elapsed = Sequel.elapsed_seconds_since(timer)
206
- # :nocov:
208
+ # simplecov:disable
207
209
  raise_pool_timeout(elapsed, server) if elapsed > timeout
208
210
 
209
211
  # It's difficult to get to this point, it can only happen if there is a race condition
@@ -211,7 +213,7 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
211
213
  if conn = acquire_available(thread, server, timeout - elapsed)
212
214
  return conn
213
215
  end
214
- # :nocov:
216
+ # simplecov:enable
215
217
  end
216
218
 
217
219
  conn
@@ -223,11 +225,11 @@ class Sequel::ShardedThreadedConnectionPool < Sequel::ThreadedConnectionPool
223
225
  # Check if connection was checked in between when assign_connection failed and now.
224
226
  # This is very unlikely, but necessary to prevent a situation where the waiter
225
227
  # will wait for a connection even though one has already been checked in.
226
- # :nocov:
228
+ # simplecov:disable
227
229
  if conn = next_available(server)
228
230
  return(allocated(server)[thread] = conn)
229
231
  end
230
- # :nocov:
232
+ # simplecov:enable
231
233
 
232
234
  @waiters[server].wait(@mutex, timeout)
233
235
 
@@ -1,8 +1,8 @@
1
1
  # frozen-string-literal: true
2
2
 
3
- # :nocov:
3
+ # simplecov:disable
4
4
  raise LoadError, "Sequel::ShardedTimedQueueConnectionPool is only available on Ruby 3.2+" unless RUBY_VERSION >= '3.2'
5
- # :nocov:
5
+ # simplecov:enable
6
6
 
7
7
  # A connection pool allowing multi-threaded access to a sharded pool of connections,
8
8
  # using a timed queue (only available in Ruby 3.2+).
@@ -148,7 +148,7 @@ class Sequel::ShardedTimedQueueConnectionPool < Sequel::ConnectionPool
148
148
  @queues[pick_server(server)].num_waiting
149
149
  end
150
150
 
151
- # The total number of connections in the pool. Using a non-existant server will return nil.
151
+ # The total number of connections in the pool. Using a non-existent server will return nil.
152
152
  def size(server=:default)
153
153
  sync{@sizes[server]}
154
154
  end
@@ -1,9 +1,11 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ # SEQUEL6: Remove, deprecation: add warning if used on Ruby 3.2+
4
+
3
5
  # A connection pool allowing multi-threaded access to a pool of connections.
4
6
  # This is the default connection pool used by Sequel.
5
7
  class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
6
- USE_WAITER = true # SEQUEL6: Remove
8
+ USE_WAITER = true
7
9
  Sequel::Deprecation.deprecate_constant(self, :USE_WAITER)
8
10
 
9
11
  # The maximum number of connections this pool will create (per shard/server
@@ -12,11 +14,11 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
12
14
 
13
15
  # An array of connections that are available for use by the pool.
14
16
  # The calling code should already have the mutex before calling this.
15
- attr_reader :available_connections # SEQUEL6: Remove
17
+ attr_reader :available_connections
16
18
 
17
19
  # A hash with thread/fiber keys and connection values for currently allocated connections.
18
20
  # The calling code should already have the mutex before calling this.
19
- attr_reader :allocated # SEQUEL6: Remove
21
+ attr_reader :allocated
20
22
 
21
23
  # The following additional options are respected:
22
24
  # :max_connections :: The maximum number of connections the connection pool
@@ -149,7 +151,7 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
149
151
 
150
152
  until conn = assign_connection(thread)
151
153
  elapsed = Sequel.elapsed_seconds_since(timer)
152
- # :nocov:
154
+ # simplecov:disable
153
155
  raise_pool_timeout(elapsed) if elapsed > timeout
154
156
 
155
157
  # It's difficult to get to this point, it can only happen if there is a race condition
@@ -157,7 +159,7 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
157
159
  if conn = acquire_available(thread, timeout - elapsed)
158
160
  return conn
159
161
  end
160
- # :nocov:
162
+ # simplecov:enable
161
163
  end
162
164
 
163
165
  conn
@@ -169,11 +171,11 @@ class Sequel::ThreadedConnectionPool < Sequel::ConnectionPool
169
171
  # Check if connection was checked in between when assign_connection failed and now.
170
172
  # This is very unlikely, but necessary to prevent a situation where the waiter
171
173
  # will wait for a connection even though one has already been checked in.
172
- # :nocov:
174
+ # simplecov:disable
173
175
  if conn = next_available
174
176
  return(@allocated[thread] = conn)
175
177
  end
176
- # :nocov:
178
+ # simplecov:enable
177
179
 
178
180
  @waiter.wait(@mutex, timeout)
179
181
 
@@ -1,8 +1,8 @@
1
1
  # frozen-string-literal: true
2
2
 
3
- # :nocov:
3
+ # simplecov:disable
4
4
  raise LoadError, "Sequel::TimedQueueConnectionPool is only available on Ruby 3.2+" unless RUBY_VERSION >= '3.2'
5
- # :nocov:
5
+ # simplecov:enable
6
6
 
7
7
  # A connection pool allowing multi-threaded access to a pool of connections,
8
8
  # using a timed queue (only available in Ruby 3.2+).
@@ -38,7 +38,7 @@ class Sequel::ConnectionPool
38
38
  POOL_CLASS_MAP.freeze
39
39
 
40
40
  # Class methods used to return an appropriate pool subclass, separated
41
- # into a module for easier overridding by extensions.
41
+ # into a module for easier overriding by extensions.
42
42
  module ClassMethods
43
43
  # Return a pool subclass instance based on the given options. If a <tt>:pool_class</tt>
44
44
  # option is provided is provided, use that pool class, otherwise
@@ -72,11 +72,11 @@ class Sequel::ConnectionPool
72
72
  opts[:servers] ? :sharded_single : :single
73
73
  elsif RUBY_VERSION >= '3.2'
74
74
  opts[:servers] ? :sharded_timed_queue : :timed_queue
75
- # :nocov:
75
+ # simplecov:disable
76
76
  else
77
77
  opts[:servers] ? :sharded_threaded : :threaded
78
78
  end
79
- # :nocov:
79
+ # simplecov:enable
80
80
 
81
81
  connection_pool_class(:pool_class=>pc)
82
82
  end