sequel 5.2.0 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +32 -0
- data/bin/sequel +5 -6
- data/doc/release_notes/5.3.0.txt +121 -0
- data/doc/schema_modification.rdoc +15 -4
- data/doc/testing.rdoc +1 -0
- data/lib/sequel/adapters/jdbc.rb +4 -0
- data/lib/sequel/adapters/jdbc/postgresql.rb +15 -0
- data/lib/sequel/adapters/oracle.rb +2 -1
- data/lib/sequel/adapters/postgres.rb +4 -0
- data/lib/sequel/adapters/shared/mysql.rb +38 -3
- data/lib/sequel/adapters/shared/postgres.rb +15 -6
- data/lib/sequel/adapters/shared/sqlite.rb +10 -0
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +2 -0
- data/lib/sequel/connection_pool.rb +12 -0
- data/lib/sequel/database/misc.rb +13 -0
- data/lib/sequel/dataset/dataset_module.rb +1 -1
- data/lib/sequel/dataset/features.rb +5 -0
- data/lib/sequel/dataset/query.rb +20 -6
- data/lib/sequel/dataset/sql.rb +3 -0
- data/lib/sequel/extensions/pg_extended_date_support.rb +15 -0
- data/lib/sequel/extensions/synchronize_sql.rb +45 -0
- data/lib/sequel/model/associations.rb +1 -0
- data/lib/sequel/model/base.rb +4 -11
- data/lib/sequel/plugins/validation_helpers.rb +2 -2
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/postgres_spec.rb +5 -34
- data/spec/core/database_spec.rb +32 -0
- data/spec/core/dataset_spec.rb +19 -0
- data/spec/core/mock_adapter_spec.rb +65 -0
- data/spec/extensions/association_pks_spec.rb +26 -33
- data/spec/extensions/class_table_inheritance_spec.rb +18 -32
- data/spec/extensions/composition_spec.rb +7 -23
- data/spec/extensions/list_spec.rb +4 -5
- data/spec/extensions/many_through_many_spec.rb +24 -32
- data/spec/extensions/optimistic_locking_spec.rb +1 -1
- data/spec/extensions/pg_array_associations_spec.rb +18 -25
- data/spec/extensions/pg_extended_date_support_spec.rb +13 -0
- data/spec/extensions/pg_hstore_spec.rb +2 -2
- data/spec/extensions/prepared_statements_safe_spec.rb +6 -6
- data/spec/extensions/pretty_table_spec.rb +39 -8
- data/spec/extensions/rcte_tree_spec.rb +22 -33
- data/spec/extensions/schema_dumper_spec.rb +42 -31
- data/spec/extensions/serialization_spec.rb +3 -3
- data/spec/extensions/synchronize_sql_spec.rb +124 -0
- data/spec/extensions/timestamps_spec.rb +2 -4
- data/spec/extensions/update_or_create_spec.rb +11 -15
- data/spec/extensions/uuid_spec.rb +2 -3
- data/spec/extensions/xml_serializer_spec.rb +5 -10
- data/spec/integration/database_test.rb +1 -1
- data/spec/integration/dataset_test.rb +7 -0
- data/spec/integration/plugin_test.rb +1 -1
- data/spec/integration/schema_test.rb +3 -3
- data/spec/integration/spec_helper.rb +4 -0
- data/spec/model/base_spec.rb +6 -0
- data/spec/model/eager_loading_spec.rb +31 -6
- data/spec/model/model_spec.rb +9 -19
- data/spec/model/record_spec.rb +4 -8
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac284f3deba98d7ef4b7213b3f6d17c9df344333
|
4
|
+
data.tar.gz: 3396c7263e758fa01b6820cd1eed79e9f1676be0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0c7a62b97b76a7a10a8ebe6df53c17de99efb70a2403a18362a32bb11a66b736885430911e982a834d60013ba84c154ebb7609c0b1d7d8c103fe8d4000cb549
|
7
|
+
data.tar.gz: 9cffa3dd8f2c87aec5598a5ac14676d061c6214f24f1851f721952c3b9c90a263dd2c4d220dfc828f87181faafe9a4d61fe7daf3d82861db0f752871450611f6
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
=== 5.3.0 (2017-12-01)
|
2
|
+
|
3
|
+
* Add logger to Database instance before making first connection in bin/sequel (jeremyevans)
|
4
|
+
|
5
|
+
* Drop support for PostgreSQL <8.1 in Database#indexes (jeremyevans)
|
6
|
+
|
7
|
+
* Add synchronize_sql extension, for checking out a connection around SQL generation (KJTsanaktsidis, jeremyevans) (#1451)
|
8
|
+
|
9
|
+
* Deprecate Dataset#where calls with no existing filter, no argument, and where the virtual row block returns nil (jeremyevans) (#1454)
|
10
|
+
|
11
|
+
* Add DatasetModule#reverse for simpler use of descending orders (jeremyevans)
|
12
|
+
|
13
|
+
* Support WITH clauses in subqueries on SQLite, but not in UNION/INTERSECT/EXCEPT (jeremyevans)
|
14
|
+
|
15
|
+
* Hoist WITH clauses to INSERT statement level if INSERT subquery uses a CTE on MSSQL (jeremyevans)
|
16
|
+
|
17
|
+
* Respect indislive and ignore indcheckxmin index attributes when using Database#indexes on PostgreSQL (jeremyevans)
|
18
|
+
|
19
|
+
* Explicitly disallow use of server-side prepared statements when using Dataset#call in the jdbc/postgresql adapter (jeremyevans) (#1448)
|
20
|
+
|
21
|
+
* Support common table expressions, window functions, dropping CHECK constraints, and recognizing CURRENT_DATE defaults on MariaDB 10.2+ (jeremyevans)
|
22
|
+
|
23
|
+
* Make Database#reset_primary_key_sequence work on PostgreSQL 10+ (jeremyevans)
|
24
|
+
|
25
|
+
* Support :connect_sqls Database option for easily issuing sql commands on all new connections (jeremyevans)
|
26
|
+
|
27
|
+
* Support :extensions Database option for loading extensions when initializing, useful in connection strings (jeremyevans)
|
28
|
+
|
29
|
+
* Avoid warning if trying to rollback after a commit or rollback raises an exception in the postgres adapter (jeremyevans)
|
30
|
+
|
31
|
+
* Support Date::Infinity values in the pg_extended_date_support extension (jeremyevans)
|
32
|
+
|
1
33
|
=== 5.2.0 (2017-10-27)
|
2
34
|
|
3
35
|
* Fix type conversion for smallint unsigned and integer unsigned types on jdbc/mysql (jeremyevans) (#1443)
|
data/bin/sequel
CHANGED
@@ -124,20 +124,19 @@ error_proc["Error: Must specify -m if using -M"] if migrate_ver && !migrate_dir
|
|
124
124
|
error_proc["Error: Cannot specify #{exclusive_options.map{|v| "-#{v}"}.join(' and ')} together"] if exclusive_options.length > 1
|
125
125
|
|
126
126
|
connect_proc = lambda do |database|
|
127
|
-
|
128
|
-
|
127
|
+
db_opts = {:test=>test, :loggers=>loggers}
|
128
|
+
if database.nil? || database.empty?
|
129
|
+
Sequel.connect('mock:///', db_opts)
|
129
130
|
elsif File.exist?(database)
|
130
131
|
require 'yaml'
|
131
132
|
env ||= "development"
|
132
133
|
db_config = YAML.load_file(database)
|
133
134
|
db_config = db_config[env] || db_config[env.to_sym] || db_config
|
134
135
|
db_config.keys.each{|k| db_config[k.to_sym] = db_config.delete(k)}
|
135
|
-
Sequel.connect(db_config,
|
136
|
+
Sequel.connect(db_config, db_opts)
|
136
137
|
else
|
137
|
-
Sequel.connect(database,
|
138
|
+
Sequel.connect(database, db_opts)
|
138
139
|
end
|
139
|
-
db.loggers = loggers
|
140
|
-
db
|
141
140
|
end
|
142
141
|
|
143
142
|
begin
|
@@ -0,0 +1,121 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* An :extensions Database option is now supported, which will load the
|
4
|
+
named extensions into the Database before any connections are
|
5
|
+
initiated:
|
6
|
+
|
7
|
+
DB = Sequel.connect('mock:///', :extensions=>[:error_sql, :synchronize_sql])
|
8
|
+
DB = Sequel.connect('mock:///?extensions=error_sql,synchronize_sql')
|
9
|
+
|
10
|
+
* A :connect_sqls Database option is now supported, which will issue
|
11
|
+
the given queries on all new connections:
|
12
|
+
|
13
|
+
DB = Sequel.connect('postgres:///', :connect_sqls=>[
|
14
|
+
'SET random_page_cost = 1.0',
|
15
|
+
"SET default_tablespace = 'foo'"
|
16
|
+
])
|
17
|
+
|
18
|
+
* DatasetModule#reverse has been added for simpler use of descending
|
19
|
+
orders:
|
20
|
+
|
21
|
+
class Foo < Sequel::Model
|
22
|
+
dataset_module do
|
23
|
+
reverse :newest_first, :created_at
|
24
|
+
end
|
25
|
+
end
|
26
|
+
Foo.newest_first.first(10)
|
27
|
+
|
28
|
+
* A synchronize_sql extension has been added. This extension checks
|
29
|
+
out a connection around SQL string creation, and is useful in the
|
30
|
+
cases where escaping values in the query requires a connection and
|
31
|
+
a large number of values need to be escaped.
|
32
|
+
|
33
|
+
* The following features are now supported on MariaDB 10.2+:
|
34
|
+
|
35
|
+
* Common table expressions.
|
36
|
+
|
37
|
+
* Window functions.
|
38
|
+
|
39
|
+
* Dropping CHECK constraints. Older versions of MariaDB/MySQL
|
40
|
+
ignored CHECK constraints that were added, and Sequel did not
|
41
|
+
attempt to filter them out, so Sequel did not require changes to
|
42
|
+
add CHECK constraints. MariaDB 10.2 CHECK constraints work
|
43
|
+
correctly with Sequel's constraint_validations extension/plugin.
|
44
|
+
|
45
|
+
* Raising CHECK constraint violations as
|
46
|
+
Sequel::CheckConstraintViolation instances.
|
47
|
+
|
48
|
+
* Recognizing curdate() as Sequel::CURRENT_DATE when used as the
|
49
|
+
default value for a date column.
|
50
|
+
|
51
|
+
* Date::Infinity values are now supported in the
|
52
|
+
pg_extended_date_support extension:
|
53
|
+
|
54
|
+
DB.convert_infinite_timestamps = :date
|
55
|
+
|
56
|
+
This returns infinite dates/timestamps as Date::Infinity instances,
|
57
|
+
and literalizes Date::Infinity instances correctly.
|
58
|
+
|
59
|
+
= Improvements
|
60
|
+
|
61
|
+
* Database#reset_primary_key_sequence now works correctly on
|
62
|
+
PostgreSQL 10.
|
63
|
+
|
64
|
+
* If a commit or rollback raises an exception when using the postgres
|
65
|
+
adapter, Sequel will check the connection's current transaction
|
66
|
+
status and only send another rollback if the connection is currently
|
67
|
+
inside a transaction. This fixes a warning that is issued in most
|
68
|
+
cases if a commit or rollback fails.
|
69
|
+
|
70
|
+
* The jdbc/postgresql adapter now forces JDBC PreparedStatement
|
71
|
+
instances created by Dataset#call to never be prepared server side,
|
72
|
+
working around an caching issue in the jdbc-postgres drier in
|
73
|
+
versions greater than 9.4.1200.
|
74
|
+
|
75
|
+
* Database#indexes will no longer return indexes which are in the
|
76
|
+
process of being dropped on PostgreSQL 9.3+. Additionally,
|
77
|
+
Database#indexes will now return indexes that have indcheckxmin
|
78
|
+
set. The previous removal of indexes with indcheckxmin set is
|
79
|
+
more likely to cause false negatives than correctly remove
|
80
|
+
indexes not yet valid.
|
81
|
+
|
82
|
+
* Common table expressions are no longer hoisted from subqueries on
|
83
|
+
SQLite. They are still hoisted from queries used in
|
84
|
+
UNION/INSERT/EXCEPT, since SQLite does not support common table
|
85
|
+
expressions at that level.
|
86
|
+
|
87
|
+
* On Microsoft SQL Server, using an INSERT query with a subquery that
|
88
|
+
uses a common table expression now hoists the common table
|
89
|
+
expression from subquery level to main query level, allowing such
|
90
|
+
queries to work.
|
91
|
+
|
92
|
+
* An additional disconnect error is now recognized in the oracle
|
93
|
+
adapter.
|
94
|
+
|
95
|
+
* bin/sequel now adds a Database logger before the initial
|
96
|
+
connection is made, allowing you to see any connection setup
|
97
|
+
statements issued to the database.
|
98
|
+
|
99
|
+
= Backwards Compatibility
|
100
|
+
|
101
|
+
* Calling a filtering method with no argument and a virtual row
|
102
|
+
block that returns nil on a dataset with no existing filter is
|
103
|
+
deprecated in this version and will emit a warning. The behavior
|
104
|
+
in this version remains the same, where the dataset is not
|
105
|
+
modified. The behavior will change in Sequel 5.4.0 so that a
|
106
|
+
WHERE NULL filter will be added in that case, instead of the
|
107
|
+
filter being ignored, so that the behavior is similar to calling
|
108
|
+
the filtering method with a nil argument.
|
109
|
+
|
110
|
+
# Sequel 5.3.0
|
111
|
+
DB[:a].where{nil}
|
112
|
+
# SELECT * FROM a
|
113
|
+
|
114
|
+
# Sequel 5.4.0
|
115
|
+
DB[:a].where{nil}
|
116
|
+
# SELECT * FROM a WHERE NULL
|
117
|
+
|
118
|
+
* Support for PostgreSQL <8.1 has been dropped from Database#indexes.
|
119
|
+
Sequel's PostgreSQL support requires >=8.2 for Dataset#insert to
|
120
|
+
work, so it doesn't make sense to support earlier versions in other
|
121
|
+
cases.
|
@@ -398,15 +398,26 @@ creates a new column:
|
|
398
398
|
end
|
399
399
|
|
400
400
|
If you want to add a new foreign key constraint to an existing column, you provide an
|
401
|
-
array with a single element
|
402
|
-
|
401
|
+
array with a single element:
|
402
|
+
|
403
|
+
alter_table(:albums) do
|
404
|
+
add_foreign_key [:artist_id], :artists
|
405
|
+
end
|
406
|
+
|
407
|
+
It's encouraged to provide a name when adding the constraint, via the :foreign_key_constraint_name
|
408
|
+
option if adding the column and the constraint:
|
409
|
+
|
410
|
+
alter_table(:albums) do
|
411
|
+
add_foreign_key :artist_id, :artists, foreign_key_constraint_name: :albums_artist_id_fkey
|
412
|
+
end
|
413
|
+
|
414
|
+
or via the :name option if just adding the constraint:
|
403
415
|
|
404
416
|
alter_table(:albums) do
|
405
417
|
add_foreign_key [:artist_id], :artists, name: :albums_artist_id_fkey
|
406
418
|
end
|
407
419
|
|
408
|
-
To set up a multiple column foreign key constraint, use an array with multiple column
|
409
|
-
symbols:
|
420
|
+
To set up a multiple column foreign key constraint, use an array with multiple column symbols:
|
410
421
|
|
411
422
|
alter_table(:albums) do
|
412
423
|
add_foreign_key [:artist_name, :artist_location], :artists, name: :albums_artist_name_location_fkey
|
data/doc/testing.rdoc
CHANGED
@@ -164,3 +164,4 @@ SEQUEL_NO_CHECK_SQLS :: Don't check for specific SQL syntax when running the spe
|
|
164
164
|
SEQUEL_CHECK_PENDING :: Try running all specs (note, can cause lockups for some adapters), and raise errors for skipped specs that don't fail
|
165
165
|
SEQUEL_NO_PENDING :: Don't skip any specs, try running all specs (note, can cause lockups for some adapters)
|
166
166
|
SEQUEL_SPLIT_SYMBOLS :: Turn on symbol splitting when running the adapter and integration specs
|
167
|
+
SEQUEL_SYNCHRONIZE_SQL :: Use the synchronize_sql extension when running the specs
|
data/lib/sequel/adapters/jdbc.rb
CHANGED
@@ -404,6 +404,10 @@ module Sequel
|
|
404
404
|
cps = cps[1]
|
405
405
|
else
|
406
406
|
log_connection_yield("CLOSE #{name}", conn){cps[1].close} if cps
|
407
|
+
if name
|
408
|
+
opts = Hash[opts]
|
409
|
+
opts[:name] = name
|
410
|
+
end
|
407
411
|
cps = log_connection_yield("PREPARE#{" #{name}:" if name} #{sql}", conn){prepare_jdbc_statement(conn, sql, opts)}
|
408
412
|
if size = fetch_size
|
409
413
|
cps.setFetchSize(size)
|
@@ -151,6 +151,21 @@ module Sequel
|
|
151
151
|
nil
|
152
152
|
end
|
153
153
|
|
154
|
+
# Work around issue when using Sequel's bound variable support where the
|
155
|
+
# same SQL is used in different bound variable calls, but the schema has
|
156
|
+
# changed between the calls. This is necessary as jdbc-postgres versions
|
157
|
+
# after 9.4.1200 violate the JDBC API. These versions cache separate
|
158
|
+
# PreparedStatement instances, which are eventually prepared server side after the
|
159
|
+
# prepareThreshold is met. The JDBC API violation is that PreparedStatement#close
|
160
|
+
# does not release the server side prepared statement.
|
161
|
+
def prepare_jdbc_statement(conn, sql, opts)
|
162
|
+
ps = super
|
163
|
+
unless opts[:name]
|
164
|
+
ps.prepare_threshold = 0
|
165
|
+
end
|
166
|
+
ps
|
167
|
+
end
|
168
|
+
|
154
169
|
# If the given argument is a recognized PostgreSQL-specific type, create
|
155
170
|
# a PGObject instance with unknown type and the bound argument string value,
|
156
171
|
# and set that as the prepared statement argument.
|
@@ -11,9 +11,10 @@ module Sequel
|
|
11
11
|
|
12
12
|
# ORA-00028: your session has been killed
|
13
13
|
# ORA-01012: not logged on
|
14
|
+
# ORA-02396: exceeded maximum idle time, please connect again
|
14
15
|
# ORA-03113: end-of-file on communication channel
|
15
16
|
# ORA-03114: not connected to ORACLE
|
16
|
-
CONNECTION_ERROR_CODES = [ 28, 1012, 3113, 3114 ].freeze
|
17
|
+
CONNECTION_ERROR_CODES = [ 28, 1012, 2396, 3113, 3114 ].freeze
|
17
18
|
|
18
19
|
ORACLE_TYPES = {
|
19
20
|
:blob=>lambda{|b| Sequel::SQL::Blob.new(b.read)},
|
@@ -74,6 +74,7 @@ module Sequel
|
|
74
74
|
|
75
75
|
def freeze
|
76
76
|
server_version
|
77
|
+
mariadb?
|
77
78
|
supports_timestamp_usecs?
|
78
79
|
super
|
79
80
|
end
|
@@ -116,10 +117,16 @@ module Sequel
|
|
116
117
|
run("XA ROLLBACK #{literal(transaction_id)}", opts)
|
117
118
|
end
|
118
119
|
|
120
|
+
# Whether the database is MariaDB and not MySQL
|
121
|
+
def mariadb?
|
122
|
+
return @is_mariadb if defined?(@is_mariadb)
|
123
|
+
@is_mariadb = !(fetch('SELECT version()').single_value! !~ /mariadb/i)
|
124
|
+
end
|
125
|
+
|
119
126
|
# Get version of MySQL server, used for determined capabilities.
|
120
127
|
def server_version
|
121
128
|
@server_version ||= begin
|
122
|
-
m = /(\d+)\.(\d+)\.(\d+)/.match(
|
129
|
+
m = /(\d+)\.(\d+)\.(\d+)/.match(fetch('SELECT version()').single_value!)
|
123
130
|
(m[1].to_i * 10000) + (m[2].to_i * 100) + m[3].to_i
|
124
131
|
end
|
125
132
|
end
|
@@ -237,6 +244,10 @@ module Sequel
|
|
237
244
|
"DROP FOREIGN KEY #{quote_identifier(name)}"
|
238
245
|
when :unique
|
239
246
|
"DROP INDEX #{quote_identifier(op[:name])}"
|
247
|
+
when :check, nil
|
248
|
+
if supports_check_constraints?
|
249
|
+
"DROP CONSTRAINT #{quote_identifier(op[:name])}"
|
250
|
+
end
|
240
251
|
end
|
241
252
|
end
|
242
253
|
|
@@ -265,6 +276,11 @@ module Sequel
|
|
265
276
|
super(default, type)
|
266
277
|
end
|
267
278
|
|
279
|
+
def column_schema_to_ruby_default(default, type)
|
280
|
+
return Sequel::CURRENT_DATE if mariadb? && server_version >= 100200 && default == 'curdate()'
|
281
|
+
super
|
282
|
+
end
|
283
|
+
|
268
284
|
# Don't allow combining adding foreign key operations with other
|
269
285
|
# operations, since in some cases adding a foreign key constraint in
|
270
286
|
# the same query as other operations results in MySQL error 150.
|
@@ -390,6 +406,7 @@ module Sequel
|
|
390
406
|
/foreign key constraint fails/ => ForeignKeyConstraintViolation,
|
391
407
|
/cannot be null/ => NotNullConstraintViolation,
|
392
408
|
/Deadlock found when trying to get lock; try restarting transaction/ => SerializationFailure,
|
409
|
+
/CONSTRAINT .+ failed for/ => CheckConstraintViolation,
|
393
410
|
}.freeze
|
394
411
|
def database_error_regexps
|
395
412
|
DATABASE_ERROR_REGEXPS
|
@@ -470,6 +487,11 @@ module Sequel
|
|
470
487
|
server_version >= 50600 && (op[:op] == :drop_index || (op[:op] == :drop_constraint && op[:type] == :unique))
|
471
488
|
end
|
472
489
|
|
490
|
+
# Whether the database supports CHECK constraints
|
491
|
+
def supports_check_constraints?
|
492
|
+
mariadb? && server_version >= 100200
|
493
|
+
end
|
494
|
+
|
473
495
|
# MySQL can combine multiple alter table ops into a single query.
|
474
496
|
def supports_combining_alter_table_ops?
|
475
497
|
true
|
@@ -545,7 +567,7 @@ module Sequel
|
|
545
567
|
|
546
568
|
Dataset.def_sql_method(self, :delete, %w'delete from where order limit')
|
547
569
|
Dataset.def_sql_method(self, :insert, %w'insert ignore into columns values on_duplicate_key_update')
|
548
|
-
Dataset.def_sql_method(self, :select, %w'select distinct calc_found_rows columns from join where group having compounds order limit lock')
|
570
|
+
Dataset.def_sql_method(self, :select, %w'with select distinct calc_found_rows columns from join where group having compounds order limit lock')
|
549
571
|
Dataset.def_sql_method(self, :update, %w'update ignore table set where order limit')
|
550
572
|
|
551
573
|
include Sequel::Dataset::Replace
|
@@ -713,6 +735,10 @@ module Sequel
|
|
713
735
|
sql << '`' << c.to_s.gsub('`', '``') << '`'
|
714
736
|
end
|
715
737
|
|
738
|
+
def supports_cte?(type=:select)
|
739
|
+
type == :select && db.mariadb? && db.server_version >= 100200
|
740
|
+
end
|
741
|
+
|
716
742
|
# MySQL does not support derived column lists
|
717
743
|
def supports_derived_column_lists?
|
718
744
|
false
|
@@ -760,7 +786,11 @@ module Sequel
|
|
760
786
|
def supports_timestamp_usecs?
|
761
787
|
db.supports_timestamp_usecs?
|
762
788
|
end
|
763
|
-
|
789
|
+
|
790
|
+
def supports_window_functions?
|
791
|
+
db.mariadb? && db.server_version >= 100200
|
792
|
+
end
|
793
|
+
|
764
794
|
# Sets up the update methods to use UPDATE IGNORE.
|
765
795
|
# Useful if you have a unique key and want to just skip
|
766
796
|
# updating rows that violate the unique key restriction.
|
@@ -929,6 +959,11 @@ module Sequel
|
|
929
959
|
sql << ' SQL_CALC_FOUND_ROWS' if opts[:calc_found_rows]
|
930
960
|
end
|
931
961
|
|
962
|
+
# Use WITH RECURSIVE instead of WITH if any of the CTEs is recursive
|
963
|
+
def select_with_sql_base
|
964
|
+
opts[:with].any?{|w| w[:recursive]} ? "WITH RECURSIVE " : super
|
965
|
+
end
|
966
|
+
|
932
967
|
# MySQL uses WITH ROLLUP syntax.
|
933
968
|
def uses_with_rollup?
|
934
969
|
true
|
@@ -203,7 +203,6 @@ module Sequel
|
|
203
203
|
# This should be used for types without fixed OIDs, which includes all types that
|
204
204
|
# are not included in a default PostgreSQL installation.
|
205
205
|
def add_named_conversion_proc(name, &block)
|
206
|
-
name = name.to_s if name.is_a?(Symbol)
|
207
206
|
unless oid = from(:pg_type).where(:typtype=>['b', 'e'], :typname=>name.to_s).get(:oid)
|
208
207
|
raise Error, "No matching type in pg_type for #{name.inspect}"
|
209
208
|
end
|
@@ -411,10 +410,9 @@ module Sequel
|
|
411
410
|
else
|
412
411
|
range = 0...32
|
413
412
|
order = [Sequel[:indc][:relname], SQL::CaseExpression.new(range.map{|x| [SQL::Subscript.new(Sequel[:ind][:indkey], [x]), x]}, 32, Sequel[:att][:attnum])]
|
414
|
-
attnums = range.map{|x| SQL::Subscript.new(Sequel[:ind][:indkey], [x])} unless server_version >= 80100
|
415
413
|
end
|
416
414
|
|
417
|
-
attnums
|
415
|
+
attnums = SQL::Function.new(:ANY, Sequel[:ind][:indkey])
|
418
416
|
|
419
417
|
ds = metadata_dataset.
|
420
418
|
from{pg_class.as(:tab)}.
|
@@ -432,7 +430,8 @@ module Sequel
|
|
432
430
|
order(*order).
|
433
431
|
select{[indc[:relname].as(:name), ind[:indisunique].as(:unique), att[:attname].as(:column), con[:condeferrable].as(:deferrable)]}
|
434
432
|
|
435
|
-
ds = ds.where(:indisready=>true
|
433
|
+
ds = ds.where(:indisready=>true) if server_version >= 80300
|
434
|
+
ds = ds.where(:indislive=>true) if server_version >= 90300
|
436
435
|
|
437
436
|
indexes = {}
|
438
437
|
ds.each do |r|
|
@@ -506,10 +505,20 @@ module Sequel
|
|
506
505
|
return unless seq = primary_key_sequence(table)
|
507
506
|
pk = SQL::Identifier.new(primary_key(table))
|
508
507
|
db = self
|
509
|
-
seq_ds = db.from(LiteralString.new(seq))
|
510
508
|
s, t = schema_and_table(table)
|
511
509
|
table = Sequel.qualify(s, t) if s
|
512
|
-
|
510
|
+
|
511
|
+
if server_version >= 100000
|
512
|
+
seq_ds = metadata_dataset.from(:pg_sequence).where(:seqrelid=>regclass_oid(LiteralString.new(seq)))
|
513
|
+
increment_by = :seqincrement
|
514
|
+
min_value = :seqmin
|
515
|
+
else
|
516
|
+
seq_ds = metadata_dataset.from(LiteralString.new(seq))
|
517
|
+
increment_by = :increment_by
|
518
|
+
min_value = :min_value
|
519
|
+
end
|
520
|
+
|
521
|
+
get{setval(seq, db[table].select(coalesce(max(pk)+seq_ds.select(increment_by), seq_ds.select(min_value))), false)}
|
513
522
|
end
|
514
523
|
|
515
524
|
def rollback_prepared_transaction(transaction_id, opts=OPTS)
|