sequel 5.65.0 → 5.66.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24bfe7c123337539140b0385dd9a828fe0fec4d6ad4e39e5fd8f150258ae7a03
4
- data.tar.gz: d820be46e60ba7b08b1129f0a6b67a24a550a27d5b682a84730172bc256f4118
3
+ metadata.gz: 7284ac53d44e98a2ddaf7c0e8068fe0716a9071bef14c484bbe77cc553d775f0
4
+ data.tar.gz: '0828c8d85355205f8b6ee8a58ba5f9b85ebec07381a687f08fa909e883ac8eed'
5
5
  SHA512:
6
- metadata.gz: bd5c7dacdf48f8ada7c34c88210ac804faa1b47741f946ca16cd6f645c1f86055eb85ac6b601e9cef2ab4aa8a5cba3dc444e3005d6ed61d324c1158f2e03a70e
7
- data.tar.gz: d17eb580a3f50f4b0c33561aed320c2ea3089044b905f4dc845ea8682afe1cdbf2798c6cd202f1233b1d168d06c9686a94728d41e0f47264245a33da5a99b251
6
+ metadata.gz: d5e42c07446ea4cd3b42eb566a20cf81b4fb7e641d7b521ead6bcfc32a8ff0a0bf7b76d7a2a8ba654a0bdd80a67db6def93ba1efba61dd5eeebf68a14cdb722a
7
+ data.tar.gz: ad7397637ab9bfb0903eff1c46c8ed5901bc2eff3a4ba5a2411ba61fb32f9e6d00871063cc55f6d21798f5790f0a5158c19f0343839a6d6750b53a3301395c90
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ === 5.66.0 (2023-03-01)
2
+
3
+ * Recognize SQLite error related to strict tables as a constraint violation when using the amalgalite adapter (jeremyevans)
4
+
5
+ * Make Dataset#count work correctly for datasets using Dataset#values (jeremyevans) (#1992)
6
+
7
+ * Make Dataset#count with no argument/block handle dataset with custom SQL using ORDER BY on MSSQL (jeremyevans)
8
+
9
+ * Make Dataset#empty? correctly handle datasets with custom SQL or using Dataset#values where the first value is NULL (andy-k, jeremyevans) (#1990)
10
+
1
11
  === 5.65.0 (2023-02-01)
2
12
 
3
13
  * Allow pg_auto_parameterize extension to use placeholder loaders (jeremyevans)
@@ -0,0 +1,24 @@
1
+ = Improvements
2
+
3
+ * Dataset#empty? now correctly handles datasets using custom SQL or
4
+ Dataset#values where the first value in the first row is NULL.
5
+
6
+ * Dataset#count without an argument or block now works correctly on
7
+ Microsoft SQL Server when using custom SQL that uses ORDER BY.
8
+
9
+ * Dataset#count now works correctly for datasets using Dataset#values.
10
+
11
+ * Sequel now recognizes an additional SQLite constraint violation
12
+ error that occurs with recent versions of amalgalite.
13
+
14
+ * Dataset#values will now raise an exception when called with an empty
15
+ array. Previously, an exception would not be raised until the query
16
+ was sent to the database.
17
+
18
+ = Backwards Compatibility
19
+
20
+ * The changes to make Dataset#empty? and #count work with custom SQL
21
+ on Microsoft SQL Server now result in running the custom SQL, which
22
+ could result in worse performance than in previous versions. You can
23
+ wrap such datasets with Dataset#from_self manually to restore the
24
+ previous behavior.
@@ -591,6 +591,18 @@ module Sequel
591
591
  end
592
592
  end
593
593
 
594
+ # For a dataset with custom SQL, since it may include ORDER BY, you
595
+ # cannot wrap it in a subquery. Load entire query in this case to get
596
+ # the number of rows. In general, you should avoid calling this method
597
+ # on datasets with custom SQL.
598
+ def count(*a, &block)
599
+ if (@opts[:sql] && a.empty? && !block)
600
+ naked.to_a.length
601
+ else
602
+ super
603
+ end
604
+ end
605
+
594
606
  # Uses CROSS APPLY to join the given table into the current dataset.
595
607
  def cross_apply(table)
596
608
  join_table(:cross_apply, table)
@@ -601,6 +613,19 @@ module Sequel
601
613
  clone(:disable_insert_output=>true)
602
614
  end
603
615
 
616
+ # For a dataset with custom SQL, since it may include ORDER BY, you
617
+ # cannot wrap it in a subquery. Run query, and if it returns any
618
+ # records, return true. In general, you should avoid calling this method
619
+ # on datasets with custom SQL.
620
+ def empty?
621
+ if @opts[:sql]
622
+ naked.each{return false}
623
+ true
624
+ else
625
+ super
626
+ end
627
+ end
628
+
604
629
  # MSSQL treats [] as a metacharacter in LIKE expresions.
605
630
  def escape_like(string)
606
631
  string.gsub(/[\\%_\[\]]/){|m| "\\#{m}"}
@@ -385,7 +385,12 @@ module Sequel
385
385
  # Use a custom expression with EXISTS to determine whether a dataset
386
386
  # is empty.
387
387
  def empty?
388
- db[:dual].where(@opts[:offset] ? exists : unordered.exists).get(1) == nil
388
+ if @opts[:sql]
389
+ naked.each{return false}
390
+ true
391
+ else
392
+ db[:dual].where(@opts[:offset] ? exists : unordered.exists).get(1) == nil
393
+ end
389
394
  end
390
395
 
391
396
  # Oracle requires SQL standard datetimes
@@ -805,6 +805,7 @@ module Sequel
805
805
  # DB.values([[1, 2], [3, 4]]).order(:column2).limit(1, 1)
806
806
  # # VALUES ((1, 2), (3, 4)) ORDER BY column2 LIMIT 1 OFFSET 1
807
807
  def values(v)
808
+ raise Error, "Cannot provide an empty array for values" if v.empty?
808
809
  @default_dataset.clone(:values=>v)
809
810
  end
810
811
 
@@ -1706,6 +1707,12 @@ module Sequel
1706
1707
  clone(:disable_insert_returning=>true)
1707
1708
  end
1708
1709
 
1710
+ # Always return false when using VALUES
1711
+ def empty?
1712
+ return false if @opts[:values]
1713
+ super
1714
+ end
1715
+
1709
1716
  # Return the results of an EXPLAIN query as a string
1710
1717
  def explain(opts=OPTS)
1711
1718
  with_sql((opts[:analyze] ? 'EXPLAIN ANALYZE ' : 'EXPLAIN ') + select_sql).map(:'QUERY PLAN').join("\r\n")
@@ -2125,6 +2132,11 @@ module Sequel
2125
2132
  "TRUNCATE TABLE#{' ONLY' if to[:only]} #{table}#{' RESTART IDENTITY' if to[:restart]}#{' CASCADE' if to[:cascade]}"
2126
2133
  end
2127
2134
 
2135
+ # Use from_self for aggregate dataset using VALUES.
2136
+ def aggreate_dataset_use_from_self?
2137
+ super || @opts[:values]
2138
+ end
2139
+
2128
2140
  # Allow truncation of multiple source tables.
2129
2141
  def check_truncation_allowed!
2130
2142
  raise(InvalidOperation, "Grouped datasets cannot be truncated") if opts[:group]
@@ -169,6 +169,7 @@ module Sequel
169
169
  # DB.values([[1, 2], [3, 4]])
170
170
  # # VALUES ((1, 2), (3, 4))
171
171
  def values(v)
172
+ raise Error, "Cannot provide an empty array for values" if v.empty?
172
173
  @default_dataset.clone(:values=>v)
173
174
  end
174
175
 
@@ -356,6 +357,7 @@ module Sequel
356
357
  DATABASE_ERROR_REGEXPS = {
357
358
  /(is|are) not unique\z|PRIMARY KEY must be unique\z|UNIQUE constraint failed: .+\z/ => UniqueConstraintViolation,
358
359
  /foreign key constraint failed\z/i => ForeignKeyConstraintViolation,
360
+ /\ASQLITE ERROR 3091/ => CheckConstraintViolation,
359
361
  /\A(SQLITE ERROR 275 \(CONSTRAINT_CHECK\) : )?CHECK constraint failed/ => CheckConstraintViolation,
360
362
  /\A(SQLITE ERROR 19 \(CONSTRAINT\) : )?constraint failed\z/ => ConstraintViolation,
361
363
  /\Acannot store [A-Z]+ value in [A-Z]+ column / => ConstraintViolation,
@@ -655,6 +657,12 @@ module Sequel
655
657
  @opts[:where] ? super : where(1=>1).delete(&block)
656
658
  end
657
659
 
660
+ # Always return false when using VALUES
661
+ def empty?
662
+ return false if @opts[:values]
663
+ super
664
+ end
665
+
658
666
  # Return an array of strings specifying a query explanation for a SELECT of the
659
667
  # current dataset. Currently, the options are ignored, but it accepts options
660
668
  # to be compatible with other adapters.
@@ -868,6 +876,11 @@ module Sequel
868
876
  end
869
877
  end
870
878
 
879
+ # Use from_self for aggregate dataset using VALUES.
880
+ def aggreate_dataset_use_from_self?
881
+ super || @opts[:values]
882
+ end
883
+
871
884
  # SQLite uses string literals instead of identifiers in AS clauses.
872
885
  def as_sql_append(sql, aliaz, column_aliases=nil)
873
886
  raise Error, "sqlite does not support derived column lists" if column_aliases
@@ -174,7 +174,7 @@ module Sequel
174
174
  # # => false
175
175
  def empty?
176
176
  cached_dataset(:_empty_ds) do
177
- single_value_ds.unordered.select(EMPTY_SELECT)
177
+ (@opts[:sql] ? from_self : self).single_value_ds.unordered.select(EMPTY_SELECT)
178
178
  end.single_value!.nil?
179
179
  end
180
180
 
@@ -977,7 +977,12 @@ module Sequel
977
977
  # order if not. Also removes the row_proc, which isn't needed
978
978
  # for aggregate calculations.
979
979
  def aggregate_dataset
980
- (options_overlap(COUNT_FROM_SELF_OPTS) ? from_self : unordered).naked
980
+ (aggreate_dataset_use_from_self? ? from_self : unordered).naked
981
+ end
982
+
983
+ # Whether to use from_self for an aggregate dataset.
984
+ def aggreate_dataset_use_from_self?
985
+ options_overlap(COUNT_FROM_SELF_OPTS)
981
986
  end
982
987
 
983
988
  # Append aliasing expression to SQL string.
@@ -6,7 +6,7 @@ module Sequel
6
6
 
7
7
  # The minor version of Sequel. Bumped for every non-patch level
8
8
  # release, generally around once a month.
9
- MINOR = 65
9
+ MINOR = 66
10
10
 
11
11
  # The tiny version of Sequel. Usually 0, only bumped for bugfix
12
12
  # releases that fix regressions from previous versions.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.65.0
4
+ version: 5.66.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-01 00:00:00.000000000 Z
11
+ date: 2023-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -197,6 +197,7 @@ extra_rdoc_files:
197
197
  - doc/release_notes/5.63.0.txt
198
198
  - doc/release_notes/5.64.0.txt
199
199
  - doc/release_notes/5.65.0.txt
200
+ - doc/release_notes/5.66.0.txt
200
201
  - doc/release_notes/5.7.0.txt
201
202
  - doc/release_notes/5.8.0.txt
202
203
  - doc/release_notes/5.9.0.txt
@@ -290,6 +291,7 @@ files:
290
291
  - doc/release_notes/5.63.0.txt
291
292
  - doc/release_notes/5.64.0.txt
292
293
  - doc/release_notes/5.65.0.txt
294
+ - doc/release_notes/5.66.0.txt
293
295
  - doc/release_notes/5.7.0.txt
294
296
  - doc/release_notes/5.8.0.txt
295
297
  - doc/release_notes/5.9.0.txt
@@ -613,7 +615,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
613
615
  - !ruby/object:Gem::Version
614
616
  version: '0'
615
617
  requirements: []
616
- rubygems_version: 3.4.1
618
+ rubygems_version: 3.4.6
617
619
  signing_key:
618
620
  specification_version: 4
619
621
  summary: The Database Toolkit for Ruby