sequel 5.34.0 → 5.39.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +82 -0
- data/README.rdoc +2 -2
- data/doc/association_basics.rdoc +7 -2
- data/doc/cheat_sheet.rdoc +5 -5
- data/doc/code_order.rdoc +0 -12
- data/doc/dataset_filtering.rdoc +2 -2
- data/doc/fork_safety.rdoc +84 -0
- data/doc/model_plugins.rdoc +1 -1
- data/doc/opening_databases.rdoc +5 -1
- data/doc/postgresql.rdoc +1 -1
- data/doc/querying.rdoc +3 -3
- data/doc/release_notes/5.35.0.txt +56 -0
- data/doc/release_notes/5.36.0.txt +60 -0
- data/doc/release_notes/5.37.0.txt +30 -0
- data/doc/release_notes/5.38.0.txt +28 -0
- data/doc/release_notes/5.39.0.txt +19 -0
- data/doc/transactions.rdoc +0 -8
- data/doc/validations.rdoc +1 -1
- data/lib/sequel/adapters/jdbc.rb +13 -1
- data/lib/sequel/adapters/jdbc/mysql.rb +4 -4
- data/lib/sequel/adapters/odbc.rb +4 -6
- data/lib/sequel/adapters/oracle.rb +2 -1
- data/lib/sequel/adapters/shared/mssql.rb +35 -5
- data/lib/sequel/adapters/shared/oracle.rb +13 -7
- data/lib/sequel/adapters/shared/postgres.rb +40 -2
- data/lib/sequel/adapters/shared/sqlite.rb +8 -2
- data/lib/sequel/adapters/tinytds.rb +1 -0
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -0
- data/lib/sequel/core.rb +5 -6
- data/lib/sequel/database/connecting.rb +0 -1
- data/lib/sequel/database/misc.rb +14 -0
- data/lib/sequel/database/schema_generator.rb +6 -0
- data/lib/sequel/database/schema_methods.rb +16 -6
- data/lib/sequel/database/transactions.rb +2 -2
- data/lib/sequel/dataset/actions.rb +10 -6
- data/lib/sequel/dataset/query.rb +1 -1
- data/lib/sequel/deprecated.rb +1 -1
- data/lib/sequel/extensions/_pretty_table.rb +1 -2
- data/lib/sequel/extensions/columns_introspection.rb +1 -2
- data/lib/sequel/extensions/core_refinements.rb +2 -0
- data/lib/sequel/extensions/duplicate_columns_handler.rb +2 -0
- data/lib/sequel/extensions/migration.rb +8 -2
- data/lib/sequel/extensions/pg_array_ops.rb +4 -0
- data/lib/sequel/extensions/pg_enum.rb +2 -0
- data/lib/sequel/extensions/pg_extended_date_support.rb +1 -1
- data/lib/sequel/extensions/pg_hstore_ops.rb +2 -0
- data/lib/sequel/extensions/pg_inet.rb +2 -0
- data/lib/sequel/extensions/pg_json_ops.rb +46 -2
- data/lib/sequel/extensions/pg_range.rb +3 -7
- data/lib/sequel/extensions/pg_range_ops.rb +2 -0
- data/lib/sequel/extensions/pg_row.rb +0 -1
- data/lib/sequel/extensions/pg_row_ops.rb +24 -0
- data/lib/sequel/extensions/query.rb +1 -0
- data/lib/sequel/extensions/run_transaction_hooks.rb +1 -1
- data/lib/sequel/extensions/s.rb +2 -0
- data/lib/sequel/extensions/schema_dumper.rb +3 -3
- data/lib/sequel/extensions/symbol_aref_refinement.rb +2 -0
- data/lib/sequel/extensions/symbol_as_refinement.rb +2 -0
- data/lib/sequel/extensions/to_dot.rb +9 -3
- data/lib/sequel/model.rb +1 -1
- data/lib/sequel/model/associations.rb +24 -7
- data/lib/sequel/model/base.rb +9 -3
- data/lib/sequel/model/plugins.rb +1 -0
- data/lib/sequel/plugins/association_pks.rb +3 -2
- data/lib/sequel/plugins/association_proxies.rb +1 -0
- data/lib/sequel/plugins/blacklist_security.rb +1 -2
- data/lib/sequel/plugins/class_table_inheritance.rb +3 -8
- data/lib/sequel/plugins/csv_serializer.rb +2 -0
- data/lib/sequel/plugins/dirty.rb +44 -0
- data/lib/sequel/plugins/forbid_lazy_load.rb +2 -0
- data/lib/sequel/plugins/instance_specific_default.rb +113 -0
- data/lib/sequel/plugins/lazy_attributes.rb +1 -1
- data/lib/sequel/plugins/pg_array_associations.rb +2 -3
- data/lib/sequel/plugins/prepared_statements.rb +5 -11
- data/lib/sequel/plugins/prepared_statements_safe.rb +1 -3
- data/lib/sequel/plugins/rcte_tree.rb +8 -14
- data/lib/sequel/plugins/single_table_inheritance.rb +7 -0
- data/lib/sequel/plugins/string_stripper.rb +1 -1
- data/lib/sequel/plugins/tree.rb +9 -4
- data/lib/sequel/plugins/validation_class_methods.rb +5 -1
- data/lib/sequel/timezones.rb +8 -3
- data/lib/sequel/version.rb +1 -1
- metadata +16 -3
@@ -0,0 +1,30 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* Model#column_previously_was and #column_previously_changed? have
|
4
|
+
been added to the dirty plugin, for getting the previous values
|
5
|
+
of the column before saving and for whether there were changes
|
6
|
+
before saving.
|
7
|
+
|
8
|
+
Model#column_previously_changed? accepts :from and :to options
|
9
|
+
to allow you to more easily determine if the value changed from
|
10
|
+
and/or to specific values.
|
11
|
+
|
12
|
+
This information was previously obtainable via
|
13
|
+
Model#previous_changes, but these new methods offer a friendlier
|
14
|
+
interface.
|
15
|
+
|
16
|
+
* Postgres::PGRow::{Array,Hash}Row#op has been added to the
|
17
|
+
pg_row_ops extension if the pg_row extension is loaded. This
|
18
|
+
is similar to how the pg_array_ops, pg_hstore_ops, and
|
19
|
+
pg_json_ops and #op method to their objects. This makes it
|
20
|
+
easier to perform row operations on literal rows.
|
21
|
+
|
22
|
+
= Other Improvements
|
23
|
+
|
24
|
+
* The schema_dumper extension now supports more unsigned numeric
|
25
|
+
types, such as "decimal(7,2) unsigned" and "real unsigned".
|
26
|
+
|
27
|
+
* IntegerMigrator now raises an Migrator::Error if attempting to
|
28
|
+
migrate down when there are migration files missing and needed for
|
29
|
+
the down migration. Previously, IntegerMigrator would not raise an
|
30
|
+
exception and would make no database changes in this case.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* The jdbc/mysql adapter now supports the newer
|
4
|
+
com.mysql.cj.jdbc.Driver driver. The adapter will still attempt to
|
5
|
+
load the older com.mysql.jdbc.Driver if the com.mysql.cj.jdbc.Driver
|
6
|
+
is not found.
|
7
|
+
|
8
|
+
= Other Improvements
|
9
|
+
|
10
|
+
* When testing a connection after creating a new Database instance
|
11
|
+
raises an exception, the Database instance is removed from
|
12
|
+
Sequel::DATABASES.
|
13
|
+
|
14
|
+
* The single_table_inheritance and prepared_statements plugins now
|
15
|
+
work correctly if loaded into the same class.
|
16
|
+
|
17
|
+
* Database connect and disconnect errors are no longer swallowed when
|
18
|
+
calling Database#create_or_replace_view, Database#server_version
|
19
|
+
on PostgreSQL, or Database#create_table* on Oracle.
|
20
|
+
|
21
|
+
= Backwards Compatibility
|
22
|
+
|
23
|
+
* Previously, instantiating a new Database instance directly using
|
24
|
+
Sequel::Database.new did not test the connection by default. That
|
25
|
+
was instead handled by Sequel::Database.connect. The test
|
26
|
+
connection now happens inside Database#initialize. This should only
|
27
|
+
affect backwards compatibility for code that is calling
|
28
|
+
Sequel::Database.new directly.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
= New Features
|
2
|
+
|
3
|
+
* On Microsoft SQL Server, the :clustered option is now supported
|
4
|
+
for primary key and unique constraints. You can use a true value
|
5
|
+
for CLUSTERED and a false value for NONCLUSTERED.
|
6
|
+
|
7
|
+
= Other Improvements
|
8
|
+
|
9
|
+
* Partitioned tables are now included in the result of
|
10
|
+
Database#tables on PostgreSQL.
|
11
|
+
|
12
|
+
* alter_table set_column_allow_null no longer drops the size of
|
13
|
+
binary columns on Microsoft SQL Server.
|
14
|
+
|
15
|
+
* In the tree plugin, the roots_dataset method now works correctly
|
16
|
+
with queries using joins by qualifying the parent column.
|
17
|
+
|
18
|
+
* A fork safety guide has been added, discussing fork safety issues
|
19
|
+
when using Sequel.
|
data/doc/transactions.rdoc
CHANGED
@@ -143,14 +143,6 @@ If you want the current savepoint to be rolled back when the savepoint block exi
|
|
143
143
|
end # RELEASE SAVEPOINT
|
144
144
|
end # COMMIT
|
145
145
|
|
146
|
-
If you want the current savepoint to be rolled back when the savepoint block exits (even if an exception is not raised), use <tt>Database#rollback_on_exit(:savepoint=>true)</tt>
|
147
|
-
|
148
|
-
DB.transaction do # BEGIN
|
149
|
-
DB.transaction(savepoint: true) do # SAVEPOINT
|
150
|
-
DB.rollback_on_exit(:savepoint=>true)
|
151
|
-
end # ROLLBACK TO SAVEPOINT
|
152
|
-
end # COMMIT
|
153
|
-
|
154
146
|
If you want the current savepoint and potentially enclosing savepoints to be rolled back when the savepoint blocks exit (even if an exception is not raised), use <tt>Database#rollback_on_exit(:savepoint=>integer)</tt>
|
155
147
|
|
156
148
|
DB.transaction do # BEGIN
|
data/doc/validations.rdoc
CHANGED
@@ -232,7 +232,7 @@ These methods check that the specified attributes can be valid integers or valid
|
|
232
232
|
|
233
233
|
=== +validates_operator+
|
234
234
|
|
235
|
-
+validates_operator+ checks that a given +operator+ method returns a truthy value when called on attribute with a specified value for comparison. Generally, this is used for inequality checks (>, >=, etc) but any method that can be called on the attribute that accepts an argument and returns a truthy value may be used.
|
235
|
+
+validates_operator+ checks that a given +operator+ method returns a truthy value when called on attribute with a specified value for comparison. Generally, this is used for inequality checks (>, >=, etc.) but any method that can be called on the attribute that accepts an argument and returns a truthy value may be used.
|
236
236
|
|
237
237
|
class Album < Sequel::Model
|
238
238
|
def validate
|
data/lib/sequel/adapters/jdbc.rb
CHANGED
@@ -51,7 +51,19 @@ module Sequel
|
|
51
51
|
# Raise a Sequel::AdapterNotFound if evaluating the class name raises a NameError.
|
52
52
|
def self.load_driver(drv, gem=nil)
|
53
53
|
load_gem(gem) if gem
|
54
|
-
|
54
|
+
if drv.is_a?(String)
|
55
|
+
eval drv
|
56
|
+
else
|
57
|
+
*try, last = drv
|
58
|
+
try.each do |try_drv|
|
59
|
+
begin
|
60
|
+
return eval(try_drv)
|
61
|
+
rescue NameError
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
eval last
|
66
|
+
end
|
55
67
|
rescue NameError
|
56
68
|
raise Sequel::AdapterNotFound, "#{drv} not loaded#{", try installing jdbc-#{gem.to_s.downcase} gem" if gem}"
|
57
69
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
2
|
|
3
|
-
Sequel::JDBC.load_driver('com.mysql.jdbc.Driver', :MySQL)
|
4
|
-
require_relative '../shared/mysql'
|
5
|
-
|
6
3
|
module Sequel
|
7
4
|
module JDBC
|
5
|
+
driver = Sequel::JDBC.load_driver(%w'com.mysql.cj.jdbc.Driver com.mysql.jdbc.Driver', :MySQL)
|
6
|
+
require_relative '../shared/mysql'
|
7
|
+
|
8
8
|
Sequel.synchronize do
|
9
9
|
DATABASE_SETUP[:mysql] = proc do |db|
|
10
10
|
db.extend(Sequel::JDBC::MySQL::DatabaseMethods)
|
11
11
|
db.extend_datasets Sequel::MySQL::DatasetMethods
|
12
|
-
|
12
|
+
driver
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
data/lib/sequel/adapters/odbc.rb
CHANGED
@@ -92,12 +92,10 @@ module Sequel
|
|
92
92
|
cols = s.columns(true).map{|c| [output_identifier(c.name), c.type, i+=1]}
|
93
93
|
columns = cols.map{|c| c[0]}
|
94
94
|
self.columns = columns
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
yield hash
|
100
|
-
end
|
95
|
+
s.each do |row|
|
96
|
+
hash = {}
|
97
|
+
cols.each{|n,t,j| hash[n] = convert_odbc_value(row[j], t)}
|
98
|
+
yield hash
|
101
99
|
end
|
102
100
|
end
|
103
101
|
self
|
@@ -14,7 +14,8 @@ module Sequel
|
|
14
14
|
# ORA-02396: exceeded maximum idle time, please connect again
|
15
15
|
# ORA-03113: end-of-file on communication channel
|
16
16
|
# ORA-03114: not connected to ORACLE
|
17
|
-
|
17
|
+
# ORA-03135: connection lost contact
|
18
|
+
CONNECTION_ERROR_CODES = [ 28, 1012, 2396, 3113, 3114, 3135 ].freeze
|
18
19
|
|
19
20
|
ORACLE_TYPES = {
|
20
21
|
:blob=>lambda{|b| Sequel::SQL::Blob.new(b.read)},
|
@@ -244,6 +244,16 @@ module Sequel
|
|
244
244
|
|
245
245
|
private
|
246
246
|
|
247
|
+
# Add CLUSTERED or NONCLUSTERED as needed
|
248
|
+
def add_clustered_sql_fragment(sql, opts)
|
249
|
+
clustered = opts[:clustered]
|
250
|
+
unless clustered.nil?
|
251
|
+
sql += " #{'NON' unless clustered}CLUSTERED"
|
252
|
+
end
|
253
|
+
|
254
|
+
sql
|
255
|
+
end
|
256
|
+
|
247
257
|
# Add dropping of the default constraint to the list of SQL queries.
|
248
258
|
# This is necessary before dropping the column or changing its type.
|
249
259
|
def add_drop_default_constraint_sql(sqls, table, column)
|
@@ -284,7 +294,7 @@ module Sequel
|
|
284
294
|
when :set_column_null
|
285
295
|
sch = schema(table).find{|k,v| k.to_s == op[:name].to_s}.last
|
286
296
|
type = sch[:db_type]
|
287
|
-
if [:string, :decimal].include?(sch[:type]) && !["text", "ntext"].include?(type) && (size = (sch[:max_chars] || sch[:column_size]))
|
297
|
+
if [:string, :decimal, :blob].include?(sch[:type]) && !["text", "ntext"].include?(type) && (size = (sch[:max_chars] || sch[:column_size]))
|
288
298
|
size = "MAX" if size == -1
|
289
299
|
type += "(#{size}#{", #{sch[:scale]}" if sch[:scale] && sch[:scale].to_i > 0})"
|
290
300
|
end
|
@@ -396,6 +406,11 @@ module Sequel
|
|
396
406
|
super.with_quote_identifiers(true)
|
397
407
|
end
|
398
408
|
|
409
|
+
# Handle clustered and nonclustered primary keys
|
410
|
+
def primary_key_constraint_sql_fragment(opts)
|
411
|
+
add_clustered_sql_fragment(super, opts)
|
412
|
+
end
|
413
|
+
|
399
414
|
# Use sp_rename to rename the table
|
400
415
|
def rename_table_sql(name, new_name)
|
401
416
|
"sp_rename #{literal(quote_schema_table(name))}, #{quote_identifier(schema_and_table(new_name).pop)}"
|
@@ -492,6 +507,11 @@ module Sequel
|
|
492
507
|
:'varbinary(max)'
|
493
508
|
end
|
494
509
|
|
510
|
+
# Handle clustered and nonclustered unique constraints
|
511
|
+
def unique_constraint_sql_fragment(opts)
|
512
|
+
add_clustered_sql_fragment(super, opts)
|
513
|
+
end
|
514
|
+
|
495
515
|
# MSSQL supports views with check option, but not local.
|
496
516
|
def view_with_check_option_support
|
497
517
|
true
|
@@ -659,11 +679,11 @@ module Sequel
|
|
659
679
|
# case by default, and that also adds a default order, so it's better to just
|
660
680
|
# avoid the subquery.
|
661
681
|
def select_sql
|
662
|
-
if @opts[:offset]
|
663
|
-
|
664
|
-
|
665
|
-
super
|
682
|
+
if @opts[:offset]
|
683
|
+
raise(Error, "Using with_ties is not supported with an offset on Microsoft SQL Server") if @opts[:limit_with_ties]
|
684
|
+
return order(1).select_sql if is_2012_or_later? && !@opts[:order]
|
666
685
|
end
|
686
|
+
super
|
667
687
|
end
|
668
688
|
|
669
689
|
# The version of the database server.
|
@@ -755,6 +775,12 @@ module Sequel
|
|
755
775
|
false
|
756
776
|
end
|
757
777
|
|
778
|
+
# Use WITH TIES when limiting the result set to also include additional
|
779
|
+
# rows matching the last row.
|
780
|
+
def with_ties
|
781
|
+
clone(:limit_with_ties=>true)
|
782
|
+
end
|
783
|
+
|
758
784
|
protected
|
759
785
|
|
760
786
|
# If returned primary keys are requested, use OUTPUT unless already set on the
|
@@ -959,6 +985,10 @@ module Sequel
|
|
959
985
|
sql << " TOP "
|
960
986
|
literal_append(sql, l)
|
961
987
|
end
|
988
|
+
|
989
|
+
if @opts[:limit_with_ties]
|
990
|
+
sql << " WITH TIES"
|
991
|
+
end
|
962
992
|
end
|
963
993
|
|
964
994
|
def update_limit_sql(sql)
|
@@ -103,12 +103,18 @@ module Sequel
|
|
103
103
|
map{|r| m.call(r[:view_name])}
|
104
104
|
end
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
106
|
+
# Whether a view with a given name exists. By default, looks in all schemas other than system
|
107
|
+
# schemas. If the :current_schema option is given, looks in the schema for the current user.
|
108
|
+
def view_exists?(name, opts=OPTS)
|
109
|
+
ds = metadata_dataset.from(:all_views).where(:view_name=>input_identifier_meth.call(name))
|
110
|
+
|
111
|
+
if opts[:current_schema]
|
112
|
+
ds = ds.where(:owner=>Sequel.function(:SYS_CONTEXT, 'userenv', 'current_schema'))
|
113
|
+
else
|
114
|
+
ds = ds.exclude(:owner=>IGNORE_OWNERS)
|
115
|
+
end
|
116
|
+
|
117
|
+
ds.count > 0
|
112
118
|
end
|
113
119
|
|
114
120
|
# The version of the Oracle server, used for determining capability.
|
@@ -178,7 +184,7 @@ module Sequel
|
|
178
184
|
|
179
185
|
def create_table_from_generator(name, generator, options)
|
180
186
|
drop_statement, create_statements = create_table_sql_list(name, generator, options)
|
181
|
-
|
187
|
+
swallow_database_error{execute_ddl(drop_statement)} if drop_statement
|
182
188
|
create_statements.each{|sql| execute_ddl(sql)}
|
183
189
|
end
|
184
190
|
|
@@ -781,7 +781,7 @@ module Sequel
|
|
781
781
|
return @server_version if @server_version
|
782
782
|
ds = dataset
|
783
783
|
ds = ds.server(server) if server
|
784
|
-
@server_version
|
784
|
+
@server_version = swallow_database_error{ds.with_sql("SELECT CAST(current_setting('server_version_num') AS integer) AS v").single_value} || 0
|
785
785
|
end
|
786
786
|
|
787
787
|
# PostgreSQL supports CREATE TABLE IF NOT EXISTS on 9.1+
|
@@ -846,7 +846,7 @@ module Sequel
|
|
846
846
|
# :schema :: The schema to search
|
847
847
|
# :server :: The server to use
|
848
848
|
def tables(opts=OPTS, &block)
|
849
|
-
pg_class_relname('r', opts, &block)
|
849
|
+
pg_class_relname(['r', 'p'], opts, &block)
|
850
850
|
end
|
851
851
|
|
852
852
|
# Check whether the given type name string/symbol (e.g. :hstore) is supported by
|
@@ -1885,6 +1885,13 @@ module Sequel
|
|
1885
1885
|
end
|
1886
1886
|
end
|
1887
1887
|
|
1888
|
+
# Use WITH TIES when limiting the result set to also include additional
|
1889
|
+
# rules that have the same results for the order column as the final row.
|
1890
|
+
# Requires PostgreSQL 13.
|
1891
|
+
def with_ties
|
1892
|
+
clone(:limit_with_ties=>true)
|
1893
|
+
end
|
1894
|
+
|
1888
1895
|
protected
|
1889
1896
|
|
1890
1897
|
# If returned primary keys are requested, use RETURNING unless already set on the
|
@@ -2071,6 +2078,37 @@ module Sequel
|
|
2071
2078
|
false
|
2072
2079
|
end
|
2073
2080
|
|
2081
|
+
# Support FETCH FIRST WITH TIES on PostgreSQL 13+.
|
2082
|
+
def select_limit_sql(sql)
|
2083
|
+
l = @opts[:limit]
|
2084
|
+
o = @opts[:offset]
|
2085
|
+
|
2086
|
+
return unless l || o
|
2087
|
+
|
2088
|
+
if @opts[:limit_with_ties]
|
2089
|
+
if o
|
2090
|
+
sql << " OFFSET "
|
2091
|
+
literal_append(sql, o)
|
2092
|
+
end
|
2093
|
+
|
2094
|
+
if l
|
2095
|
+
sql << " FETCH FIRST "
|
2096
|
+
literal_append(sql, l)
|
2097
|
+
sql << " ROWS WITH TIES"
|
2098
|
+
end
|
2099
|
+
else
|
2100
|
+
if l
|
2101
|
+
sql << " LIMIT "
|
2102
|
+
literal_append(sql, l)
|
2103
|
+
end
|
2104
|
+
|
2105
|
+
if o
|
2106
|
+
sql << " OFFSET "
|
2107
|
+
literal_append(sql, o)
|
2108
|
+
end
|
2109
|
+
end
|
2110
|
+
end
|
2111
|
+
|
2074
2112
|
# Support FOR SHARE locking when using the :share lock style.
|
2075
2113
|
# Use SKIP LOCKED if skipping locked rows.
|
2076
2114
|
def select_lock_sql(sql)
|
@@ -269,6 +269,8 @@ module Sequel
|
|
269
269
|
else
|
270
270
|
duplicate_table(table, :no_foreign_keys=>true)
|
271
271
|
end
|
272
|
+
when :unique
|
273
|
+
duplicate_table(table, :no_unique=>true)
|
272
274
|
else
|
273
275
|
duplicate_table(table)
|
274
276
|
end
|
@@ -422,8 +424,12 @@ module Sequel
|
|
422
424
|
skip_indexes = []
|
423
425
|
indexes(table, :only_autocreated=>true).each do |name, h|
|
424
426
|
skip_indexes << name
|
425
|
-
if h[:
|
426
|
-
|
427
|
+
if h[:unique]
|
428
|
+
if h[:columns].length == 1
|
429
|
+
unique_columns.concat(h[:columns])
|
430
|
+
elsif h[:columns].map(&:to_s) != pks && !opts[:no_unique]
|
431
|
+
constraints << {:type=>:unique, :columns=>h[:columns]}
|
432
|
+
end
|
427
433
|
end
|
428
434
|
end
|
429
435
|
unique_columns -= pks
|
@@ -18,6 +18,7 @@ module Sequel
|
|
18
18
|
This connection is still waiting for a result, try again once you have the result
|
19
19
|
closed MySQL connection
|
20
20
|
The MySQL server is running with the --read-only option so it cannot execute this statement
|
21
|
+
Connection was killed
|
21
22
|
END
|
22
23
|
# Error messages for mysql and mysql2 that indicate the current connection should be disconnected
|
23
24
|
MYSQL_DATABASE_DISCONNECT_ERRORS = /\A#{Regexp.union(disconnect_errors)}/
|
data/lib/sequel/core.rb
CHANGED
@@ -52,13 +52,12 @@ module Sequel
|
|
52
52
|
#
|
53
53
|
# Sequel.datetime_class = DateTime
|
54
54
|
#
|
55
|
-
# Note that +Time+ and +DateTime+ objects
|
56
|
-
#
|
57
|
-
#
|
58
|
-
# days on +DateTime+).
|
55
|
+
# Note that +Time+ and +DateTime+ objects have a different API, and in
|
56
|
+
# cases where they implement the same methods, they often implement them
|
57
|
+
# differently (e.g. + using seconds on +Time+ and days on +DateTime+).
|
59
58
|
attr_accessor :datetime_class
|
60
59
|
|
61
|
-
# Set whether Sequel is being used in single threaded mode.
|
60
|
+
# Set whether Sequel is being used in single threaded mode. By default,
|
62
61
|
# Sequel uses a thread-safe connection pool, which isn't as fast as the
|
63
62
|
# single threaded connection pool, and also has some additional thread
|
64
63
|
# safety checks. If your program will only have one thread,
|
@@ -67,7 +66,7 @@ module Sequel
|
|
67
66
|
# Sequel.single_threaded = true
|
68
67
|
attr_accessor :single_threaded
|
69
68
|
|
70
|
-
# Alias of original require method, as Sequel.require
|
69
|
+
# Alias of original require method, as Sequel.require does a relative
|
71
70
|
# require for backwards compatibility.
|
72
71
|
alias orig_require require
|
73
72
|
private :orig_require
|
data/lib/sequel/database/misc.rb
CHANGED
@@ -166,6 +166,7 @@ module Sequel
|
|
166
166
|
end
|
167
167
|
|
168
168
|
initialize_load_extensions(:extensions)
|
169
|
+
test_connection if typecast_value_boolean(@opts.fetch(:test, true)) && respond_to?(:connect, true)
|
169
170
|
rescue
|
170
171
|
Sequel.synchronize{::Sequel::DATABASES.delete(self)} if keep_reference
|
171
172
|
raise
|
@@ -446,6 +447,19 @@ module Sequel
|
|
446
447
|
end
|
447
448
|
end
|
448
449
|
|
450
|
+
# Swallow database errors, unless they are connect/disconnect errors.
|
451
|
+
def swallow_database_error
|
452
|
+
yield
|
453
|
+
rescue Sequel::DatabaseDisconnectError, DatabaseConnectionError
|
454
|
+
# Always raise disconnect errors
|
455
|
+
raise
|
456
|
+
rescue Sequel::DatabaseError
|
457
|
+
# Don't raise other database errors.
|
458
|
+
nil
|
459
|
+
# else
|
460
|
+
# Don't rescue other exceptions, they will be raised normally.
|
461
|
+
end
|
462
|
+
|
449
463
|
# Typecast the value to an SQL::Blob
|
450
464
|
def typecast_value_blob(value)
|
451
465
|
value.is_a?(Sequel::SQL::Blob) ? value : Sequel::SQL::Blob.new(value)
|