sequel 5.7.1 → 5.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +53 -1
  3. data/doc/association_basics.rdoc +2 -2
  4. data/doc/migration.rdoc +11 -10
  5. data/doc/postgresql.rdoc +71 -0
  6. data/doc/release_notes/5.8.0.txt +170 -0
  7. data/lib/sequel/adapters/jdbc.rb +6 -1
  8. data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
  9. data/lib/sequel/adapters/mysql2.rb +2 -1
  10. data/lib/sequel/adapters/postgres.rb +32 -10
  11. data/lib/sequel/adapters/shared/mssql.rb +11 -11
  12. data/lib/sequel/adapters/shared/mysql.rb +51 -6
  13. data/lib/sequel/adapters/shared/oracle.rb +12 -2
  14. data/lib/sequel/adapters/shared/postgres.rb +97 -30
  15. data/lib/sequel/adapters/shared/sqlanywhere.rb +2 -2
  16. data/lib/sequel/adapters/shared/sqlite.rb +6 -1
  17. data/lib/sequel/dataset/features.rb +5 -0
  18. data/lib/sequel/dataset/query.rb +48 -19
  19. data/lib/sequel/exceptions.rb +7 -0
  20. data/lib/sequel/extensions/connection_expiration.rb +8 -3
  21. data/lib/sequel/extensions/pg_enum.rb +28 -5
  22. data/lib/sequel/plugins/association_proxies.rb +16 -4
  23. data/lib/sequel/plugins/error_splitter.rb +16 -11
  24. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +260 -0
  25. data/lib/sequel/plugins/subclasses.rb +1 -1
  26. data/lib/sequel/plugins/tactical_eager_loading.rb +1 -1
  27. data/lib/sequel/version.rb +2 -2
  28. data/spec/adapters/mysql_spec.rb +0 -1
  29. data/spec/adapters/postgres_spec.rb +169 -4
  30. data/spec/adapters/sqlite_spec.rb +13 -0
  31. data/spec/core/dataset_spec.rb +21 -0
  32. data/spec/extensions/association_proxies_spec.rb +21 -7
  33. data/spec/extensions/connection_expiration_spec.rb +13 -1
  34. data/spec/extensions/pg_auto_constraint_validations_spec.rb +165 -0
  35. data/spec/extensions/pg_enum_spec.rb +26 -22
  36. data/spec/extensions/tactical_eager_loading_spec.rb +11 -0
  37. data/spec/integration/dataset_test.rb +30 -6
  38. data/spec/integration/plugin_test.rb +2 -2
  39. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a08d35934b3f831634bb0f33f7cab46262242c453f42e1991926d35d7420c17f
4
- data.tar.gz: 530c498255c985753b5a2b2411d77d9087606f6f43f91a0e915299b1579c2e67
3
+ metadata.gz: 5802a8e3fdb50b3d51f78111c604c86c64f0a3705bcf272423f0b9281800720b
4
+ data.tar.gz: 2257a05863d62c70a871032ecc5fdff36196ab717094af98c096570c08f380a7
5
5
  SHA512:
6
- metadata.gz: d285a38669b61c579e5388fcd215637ca2f523cdfcf3e4d8290165883e3d567d91bacb3a3212d494aabecb022afa90be2bd0767393429cdc0035566fc9f702de
7
- data.tar.gz: 8a81806f41fee72c293aa70b68023e3f3ec79413906649e3deea13198a8c588825166fe70b0bd37f9c77c39aadc77678415a3fea2f00ad7f912036e4861b6982
6
+ metadata.gz: 3caabfec31c2953c4f0dd57e68dc58466ff416ab80276ae5ac111fffde7a6dcdddf068b074e33e8df4ea6f41ca941f59f60ec1507d5de2a07ce7b3cdb9016c82
7
+ data.tar.gz: 811720c5223a1e2113b47fb0430870dec6377f8d6d1408f0b61dd52abacd596f26af6077c77cf619692c80a43224f06e44633d5c8bd2ee403eafac3a5e7050db
data/CHANGELOG CHANGED
@@ -1,7 +1,59 @@
1
- === 5.7.1 (2018-04-04)
1
+ === 5.8.0 (2018-05-01)
2
+
3
+ * Don't mark SQLAnywhere as supporting WITH in INSERT statement (jeremyevans)
4
+
5
+ * Support :search_path as a shard option on PostgreSQL (jeremyevans)
6
+
7
+ * Add Dataset#nowait for raising a Sequel::DatabaseLockTimeout when a locked row is encountered, supported on PostgreSQL, MySQL 8+, MSSQL, and Oracle (jeremyevans)
8
+
9
+ * Support Dataset#skip_locked on MySQL 8+ (jeremyevans)
10
+
11
+ * Make schema modification methods in the pg_enum extension work on a frozen Database object (jeremyevans)
12
+
13
+ * Support common table expressions and window functions on MySQL 8+ (jeremyevans)
14
+
15
+ * Ignore Dataset#explain :extended option on MySQL 5.7+, since extended output is then the MySQL default (jeremyevans)
16
+
17
+ * Work around REGEXP BINARY not working correctly on MySQL 8+ by using REGEXP_LIKE with the 'c' match_type (jeremyevans)
18
+
19
+ * Force correct column order in Database#foreign_key_list on MySQL (jeremyevans)
20
+
21
+ * Add ConnectionPool#connection_expiration_random_delay to connection_expiration extension, to avoid thundering herd if preallocating connections (hex2a, jeremyevans) (#1503)
22
+
23
+ * Emit deprecation warning in association_proxies plugin if using #filter on an association proxy, since behavior will change on ruby 2.6+ (utilum) (#1497)
24
+
25
+ * Handle multiple add_constraint calls and a set_column_null call in the same alter_table block on SQLite (jeremyevans) (#1498)
26
+
27
+ * Add Database#rename_enum to the pg_enum extension (AlexWayfer) (#1495)
28
+
29
+ * Make tactical_eager_loading plugin respect the :allow_eager association option (jeremyevans) (#1494)
30
+
31
+ * Add pg_auto_constraint_validations plugin, for automatically converting constraint violations to validation failures on PostgreSQL (jeremyevans)
32
+
33
+ * Don't make Model#_valid? public in the error_splitter plugin (jeremyevans)
34
+
35
+ * Support Database#indexes :include_partial option on PostgreSQL for including partial indexes (jeremyevans)
36
+
37
+ * Include more diagnostic information in Database#error_info on PostgreSQL (jeremyevans)
38
+
39
+ * Support Database#foreign_key_list :reverse option on PostgreSQL for parsing foreign key constraints that reference a given table (jeremyevans)
40
+
41
+ * Add Database#check_constraints on PostgreSQL for parsing CHECK constraints (jeremyevans)
2
42
 
3
43
  * Don't use identity columns if :serial=>true or :type=>:serial|:bigserial column options are used (#1490) (jeremyevans)
4
44
 
45
+ * Cache Dataset#select_all datasets if no arguments are given (jeremyevans)
46
+
47
+ * Cache Dataset#returning datasets if no arguments are given (jeremyevans)
48
+
49
+ * Cache Dataset#qualify datasets if no argument is given (jeremyevans)
50
+
51
+ * Cache Dataset#lateral datasets (jeremyevans)
52
+
53
+ * Cache Dataset#from_self datasets if no options are given (jeremyevans)
54
+
55
+ * Cache Dataset#distinct datasets if no arguments or block is given (jeremyevans)
56
+
5
57
  === 5.7.0 (2018-04-01)
6
58
 
7
59
  * Add Sequel.start_timer and .elapsed_seconds_since for more accurate elapsed time calculations on ruby 2.1+ (jeremyevans)
@@ -859,13 +859,13 @@ The defaults for any of these options can be set at the class level using
859
859
  <tt>Sequel::Model.default_association_options</tt>. To make
860
860
  associations read only by default:
861
861
 
862
- Sequel::Model.default_association_options[:read_only] = true
862
+ Sequel::Model.default_association_options[:read_only] = true
863
863
 
864
864
  Many of these options are specific to particular association types, and
865
865
  the defaults can be set on a per association type basis. To make one_to_many
866
866
  associations read only by default:
867
867
 
868
- Sequel::Model.default_association_type_options[:one_to_many] = {read_only: true}
868
+ Sequel::Model.default_association_type_options[:one_to_many] = {read_only: true}
869
869
 
870
870
  === Association Dataset Modification Options
871
871
 
@@ -469,21 +469,16 @@ or equal to that version will be migrated up.
469
469
 
470
470
  == Running migrations from a Rake task
471
471
 
472
- You can also incorporate migrations into a Rakefile. Here's an example
473
- using integer migration versions.
472
+ You can also incorporate migrations into a Rakefile:
474
473
 
475
474
  namespace :db do
476
475
  desc "Run migrations"
477
476
  task :migrate, [:version] do |t, args|
478
- require "sequel"
477
+ require "sequel/core"
479
478
  Sequel.extension :migration
480
- db = Sequel.connect(ENV.fetch("DATABASE_URL"))
481
- if args[:version]
482
- puts "Migrating to version #{args[:version]}"
483
- Sequel::Migrator.run(db, "db/migrations", target: args[:version].to_i)
484
- else
485
- puts "Migrating to latest"
486
- Sequel::Migrator.run(db, "db/migrations")
479
+ version = args[:version].to_i if args[:version]
480
+ Sequel.connect(ENV.fetch("DATABASE_URL")) do |db|
481
+ Sequel::Migrator.run(db, "db/migrations", target: version)
487
482
  end
488
483
  end
489
484
  end
@@ -506,6 +501,12 @@ migration takes, you can use the <tt>-E</tt> option to +sequel+ to set up a
506
501
  +Database+ logger that logs to +STDOUT+. You can also log that same output to
507
502
  a file using the <tt>-l</tt> option with a log file name.
508
503
 
504
+ If you want to include a logger in the rake task above, add a +:logger+ option
505
+ when calling Sequel.connect:
506
+
507
+ require "logger"
508
+ Sequel.connect(ENV.fetch("DATABASE_URL"), logger: Logger.new($stderr))
509
+
509
510
  == Using models in your migrations
510
511
 
511
512
  Just don't do it.
@@ -189,6 +189,49 @@ Sequel has built in support for creating and dropping PostgreSQL schemas, proced
189
189
 
190
190
  However, you may want to consider just use <tt>Database#run</tt> with the necessary SQL code, at least for functions and triggers.
191
191
 
192
+ === Parsing Check Constraints
193
+
194
+ Sequel has support for parsing CHECK constraints on PostgreSQL using <tt>Sequel::Database#check_constraints</tt>:
195
+
196
+ DB.create_table(:foo) do
197
+ Integer :i
198
+ Integer :j
199
+ constraint(:ic, Sequel[:i] > 2)
200
+ constraint(:jc, Sequel[:j] > 2)
201
+ constraint(:ijc, Sequel[:i] - Sequel[:j] > 2)
202
+ end
203
+ DB.check_constraints(:foo)
204
+ # => {
205
+ # :ic=>{:definition=>"CHECK ((i > 2))", :columns=>[:i]},
206
+ # :jc=>{:definition=>"CHECK ((j > 2))", :columns=>[:j]},
207
+ # :ijc=>{:definition=>"CHECK (((i - j) > 2))", :columns=>[:i, :j]}
208
+ # }
209
+
210
+ === Parsing Foreign Key Constraints Referencing A Given Table
211
+
212
+ Sequel has support for parsing FOREIGN KEY constraints that reference a given table, using the +:reverse+
213
+ option to +foreign_key_list+:
214
+
215
+ DB.create_table!(:a) do
216
+ primary_key :id
217
+ Integer :i
218
+ Integer :j
219
+ foreign_key :a_id, :a, :foreign_key_constraint_name=>:a_a
220
+ unique [:i, :j]
221
+ end
222
+ DB.create_table!(:b) do
223
+ foreign_key :a_id, :a, :foreign_key_constraint_name=>:a_a
224
+ Integer :c
225
+ Integer :d
226
+ foreign_key [:c, :d], :a, :key=>[:j, :i], :name=>:a_c_d
227
+ end
228
+ DB.foreign_key_list(:a, :reverse=>true)
229
+ # => [
230
+ # {:name=>:a_a, :columns=>[:a_id], :key=>[:id], :on_update=>:no_action, :on_delete=>:no_action, :deferrable=>false, :table=>:a, :schema=>:public},
231
+ # {:name=>:a_a, :columns=>[:a_id], :key=>[:id], :on_update=>:no_action, :on_delete=>:no_action, :deferrable=>false, :table=>:b, :schema=>:public},
232
+ # {:name=>:a_c_d, :columns=>[:c, :d], :key=>[:j, :i], :on_update=>:no_action, :on_delete=>:no_action, :deferrable=>false, :table=>:b, :schema=>:public}
233
+ # ]
234
+
192
235
  == PostgreSQL-specific DML Support
193
236
 
194
237
  === Returning Rows From Insert, Update, and Delete Statements
@@ -397,6 +440,34 @@ handle locking:
397
440
  # INSERT INTO "table" ("id") VALUES (2) RETURNING NULL;
398
441
  # COMMIT;
399
442
 
443
+ == Extended Error Info (<tt>postgres/pg only</tt>)
444
+
445
+ If you run a query that raises a Sequel::DatabaseError, you can pass the exception object to
446
+ <tt>Database#error_info</tt>, and that will return a hash with metadata regarding the error,
447
+ such as the related table and column or constraint.
448
+
449
+ DB.create_table(:test1){primary_key :id}
450
+ DB.create_table(:test2){primary_key :id; foreign_key :test1_id, :test1}
451
+ DB[:test2].insert(:test1_id=>1) rescue DB.error_info($!)
452
+ # => {
453
+ # :schema=>"public",
454
+ # :table=>"test2",
455
+ # :column=>nil,
456
+ # :constraint=>"test2_test1_id_fkey",
457
+ # :type=>nil,
458
+ # :severity=>"ERROR",
459
+ # :sql_state=>"23503",
460
+ # :message_primary=>"insert or update on table \"test2\" violates foreign key constraint \"test2_test1_id_fkey\"",
461
+ # :message_detail=>"Key (test1_id)=(1) is not present in table \"test1\"."
462
+ # :message_hint=>nil,
463
+ # :statement_position=>nil,
464
+ # :internal_position=>nil,
465
+ # :internal_query=>nil,
466
+ # :source_file=>"ri_triggers.c",
467
+ # :source_line=>"3321",
468
+ # :source_function=>"ri_ReportViolation"
469
+ # }
470
+
400
471
  == sequel_pg (<tt>postgres/pg only</tt>)
401
472
 
402
473
  When the postgres adapter is used with the pg driver, Sequel automatically checks for sequel_pg, and
@@ -0,0 +1,170 @@
1
+ = New Features
2
+
3
+ * A pg_auto_constraint_validations plugin has been added, which
4
+ automatically converts many constraint violations raised as
5
+ exceptions to ValidationFailed exceptions when saving a model
6
+ instance.
7
+
8
+ The following constraint violation types are recognized and
9
+ supported:
10
+
11
+ * NOT NULL
12
+ * CHECK
13
+ * UNIQUE (except expression/functional indexes)
14
+ * FOREIGN KEY (both referencing and referenced by)
15
+
16
+ In the cases where the plugin cannot determine an appropriate
17
+ validation failure for the constraint violation, it just
18
+ reraises the original exception.
19
+
20
+ This plugin is not intended as a replacement for other validations,
21
+ it is intended as a last resort. The purpose of validations is to
22
+ provide nice error messages for the user, and the error messages
23
+ generated by this plugin are fairly generic. The error messages can
24
+ be customized using the :messages plugin option, but there is only a
25
+ single message used per constraint type.
26
+
27
+ * Database#check_constraints has been added on PostgreSQL. This
28
+ returns metadata related to each check constraint on a table:
29
+
30
+ DB.create_table(:foo) do
31
+ Integer :i
32
+ Integer :j
33
+ constraint(:ic, Sequel[:i] > 2)
34
+ constraint(:jc, Sequel[:j] > 2)
35
+ constraint(:ijc, Sequel[:i] - Sequel[:j] > 2)
36
+ end
37
+ DB.check_constraints(:foo)
38
+ # => {
39
+ # :ic=>{:definition=>"CHECK ((i > 2))", :columns=>[:i]},
40
+ # :jc=>{:definition=>"CHECK ((j > 2))", :columns=>[:j]},
41
+ # :ijc=>{:definition=>"CHECK (((i - j) > 2))", :columns=>[:i, :j]}
42
+ # }
43
+
44
+ * Database#foreign_key_list now supports a :reverse option on
45
+ PostgreSQL, which returns foreign keys referencing the given table,
46
+ instead of of foreign keys in the given table referencing other
47
+ tables:
48
+
49
+ DB.create_table!(:a) do
50
+ primary_key :id
51
+ Integer :i
52
+ Integer :j
53
+ foreign_key :a_id, :a, :foreign_key_constraint_name=>:a_a
54
+ unique [:i, :j]
55
+ end
56
+ DB.create_table!(:b) do
57
+ foreign_key :a_id, :a, :foreign_key_constraint_name=>:a_a
58
+ Integer :c
59
+ Integer :d
60
+ foreign_key [:c, :d], :a, :key=>[:j, :i], :name=>:a_c_d
61
+ end
62
+ DB.foreign_key_list(:a, :reverse=>true)
63
+ # => [
64
+ # {:name=>:a_a, :columns=>[:a_id], :key=>[:id], :on_update=>:no_action,
65
+ # :on_delete=>:no_action, :deferrable=>false, :table=>:a, :schema=>:public},
66
+ # {:name=>:a_a, :columns=>[:a_id], :key=>[:id], :on_update=>:no_action,
67
+ # :on_delete=>:no_action, :deferrable=>false, :table=>:b, :schema=>:public},
68
+ # {:name=>:a_c_d, :columns=>[:c, :d], :key=>[:j, :i], :on_update=>:no_action,
69
+ # :on_delete=>:no_action, :deferrable=>false, :table=>:b, :schema=>:public}
70
+ # ]
71
+
72
+ * Dataset#nowait has been added, which will make the query fail
73
+ with a Sequel::DatabaseLockTimeout exception if it encounters
74
+ a locked row, overriding the default database behavior that
75
+ would wait until the lock was released. This method is supported
76
+ on PostgreSQL, Microsoft SQL Server, Oracle, and MySQL 8+.
77
+
78
+ * Database#indexes now supports an :include_partial option on
79
+ PostgreSQL, which will include partial indexes in the output (Sequel
80
+ by default excludes partial indexes).
81
+
82
+ * Common table expressions and window functions are now supported when
83
+ using MySQL 8+.
84
+
85
+ * Dataset#skip_locked is now supported on MySQL 8+.
86
+
87
+ * The connection_expiration extension now supports a
88
+ Database#connection_expiration_random_delay attribute, which is used
89
+ to randomize the expiration times, avoiding the thundering herd
90
+ problem.
91
+
92
+ * The pg_enum extension now supports a rename_enum method for renaming
93
+ existing enum types.
94
+
95
+ * Database#error_info on PostgreSQL now returns much more metadata
96
+ regarding the error.
97
+
98
+ = Other Improvements
99
+
100
+ * The dataset returned by the following dataset methods is cached,
101
+ which can improve performance significantly in certain cases:
102
+
103
+ * #distinct (without arguments or block)
104
+ * #from_self (without options)
105
+ * #lateral
106
+ * #qualify (without argument)
107
+ * #returning (without arguments)
108
+ * #select_all (without arguments)
109
+
110
+ * If the primary_key serial: true, type: :serial, or type: :bigserial
111
+ options are given on PostgreSQL 10.2+, use a serial primary key
112
+ instead of an identity primary key. This change was included in
113
+ Sequel 5.7.1.
114
+
115
+ * The :search_path Database option is now supported as a shard
116
+ option on PostgreSQL, so different shards can use different
117
+ search paths.
118
+
119
+ * The correct column order in Database#foreign_key_list on MySQL is
120
+ now forced, fixing issues on MySQL 8+.
121
+
122
+ * When using case sensitive regexp matches on MySQL 8+, Sequel now
123
+ uses the REGEXP_LIKE function instead of the REGEXP BINARY
124
+ operator, to work around what appears to be a bug in MySQL 8+
125
+ related to the change in MySQL's regexp engine.
126
+
127
+ * On MySQL 5.7+, the :extended option to Dataset#explain is now
128
+ ignored, since the :extended option's behavior in previous
129
+ MySQL versions is now the default behavior.
130
+
131
+ * The MySQL HY000 generic SQL state error code is now ignored
132
+ in the mysql2 adapter, so it falls back to using the more
133
+ accurate backup error mapping in that case.
134
+
135
+ * The pg_enum extension's schema modification methods now work
136
+ correctly if the Database instance is frozen.
137
+
138
+ * The tactical_eager_loading plugin now respects the :allow_eager
139
+ association option, and will not attempt to eagerly load
140
+ associations when :allow_eager is false.
141
+
142
+ * Using multiple add_constraint calls and a set_column_null call in
143
+ the same alter_table block on SQLite now works correctly. Note
144
+ that if you are planning on ever modifying existing tables beyond
145
+ adding columns, you should probably choose a database that natively
146
+ supports such modification (SQLite does not).
147
+
148
+ * Hashes returned by Database#foreign_key_list on PostgreSQL now
149
+ include a :schema entry, unless the support has been enabled
150
+ to make the :table entry be a qualified identifier.
151
+
152
+ * Dataset#support_cte?(:insert) no longer returns true on
153
+ SQLAnywhere. SQLAnywhere only supports common table
154
+ expressions for INSERT ... SELECT, not for all INSERT
155
+ statements. INSERT ... WITH ... SELECT is already
156
+ supported in Sequel using:
157
+
158
+ DB[:t1].insert(DB[:t2].with(DB[:t3]))
159
+
160
+ * Model#_valid? is no longer made a public method in the
161
+ error_splitter plugin.
162
+
163
+ = Backwards Compatibility
164
+
165
+ * Calling the filter method on a proxy object returned by the
166
+ association_proxies plugin now warns on ruby <2.6. This is
167
+ because starting in ruby 2.6, the behavior will change and the
168
+ method will be called on the array of associated objects
169
+ instead of on the dataset, as Enumerable#filter is being added
170
+ in ruby 2.6.
@@ -211,7 +211,7 @@ module Sequel
211
211
  end
212
212
  end
213
213
  end
214
- setup_connection(conn)
214
+ setup_connection_with_opts(conn, opts)
215
215
  end
216
216
 
217
217
  # Close given adapter connections, and delete any related prepared statements.
@@ -585,6 +585,11 @@ module Sequel
585
585
  conn
586
586
  end
587
587
 
588
+ # Setup the connection using the given connection options. Return the connection. Can be overridden in subadapters for database specific setup.
589
+ def setup_connection_with_opts(conn, opts)
590
+ setup_connection(conn)
591
+ end
592
+
588
593
  def schema_column_set_db_type(schema)
589
594
  case schema[:type]
590
595
  when :string
@@ -187,10 +187,10 @@ module Sequel
187
187
  end
188
188
 
189
189
  # Execute the connection configuration SQL queries on the connection.
190
- def setup_connection(conn)
191
- conn = super(conn)
190
+ def setup_connection_with_opts(conn, opts)
191
+ conn = super
192
192
  statement(conn) do |stmt|
193
- connection_configuration_sqls.each{|sql| log_connection_yield(sql, conn){stmt.execute(sql)}}
193
+ connection_configuration_sqls(opts).each{|sql| log_connection_yield(sql, conn){stmt.execute(sql)}}
194
194
  end
195
195
  conn
196
196
  end
@@ -195,7 +195,8 @@ module Sequel
195
195
  end
196
196
 
197
197
  def database_exception_sqlstate(exception, opts)
198
- exception.sql_state
198
+ state = exception.sql_state
199
+ state unless state == 'HY000'
199
200
  end
200
201
 
201
202
  def dataset_class_default
@@ -220,7 +220,7 @@ module Sequel
220
220
  end
221
221
  end
222
222
 
223
- connection_configuration_sqls.each{|sql| conn.execute(sql)}
223
+ connection_configuration_sqls(opts).each{|sql| conn.execute(sql)}
224
224
  conn
225
225
  end
226
226
 
@@ -247,26 +247,48 @@ module Sequel
247
247
 
248
248
  if USES_PG && Object.const_defined?(:PG) && ::PG.const_defined?(:Constants) && ::PG::Constants.const_defined?(:PG_DIAG_SCHEMA_NAME)
249
249
  # Return a hash of information about the related PGError (or Sequel::DatabaseError that
250
- # wraps a PGError), with the following entries:
250
+ # wraps a PGError), with the following entries (any of which may be +nil+):
251
251
  #
252
252
  # :schema :: The schema name related to the error
253
253
  # :table :: The table name related to the error
254
254
  # :column :: the column name related to the error
255
255
  # :constraint :: The constraint name related to the error
256
256
  # :type :: The datatype name related to the error
257
+ # :severity :: The severity of the error (e.g. "ERROR")
258
+ # :sql_state :: The SQL state code related to the error
259
+ # :message_primary :: A single line message related to the error
260
+ # :message_detail :: Any detail supplementing the primary message
261
+ # :message_hint :: Possible suggestion about how to fix the problem
262
+ # :statement_position :: Character offset in statement submitted by client where error occurred (starting at 1)
263
+ # :internal_position :: Character offset in internal statement where error occurred (starting at 1)
264
+ # :internal_query :: Text of internally-generated statement where error occurred
265
+ # :source_file :: PostgreSQL source file where the error occurred
266
+ # :source_line :: Line number of PostgreSQL source file where the error occurred
267
+ # :source_function :: Function in PostgreSQL source file where the error occurred
257
268
  #
258
269
  # This requires a PostgreSQL 9.3+ server and 9.3+ client library,
259
270
  # and ruby-pg 0.16.0+ to be supported.
260
271
  def error_info(e)
261
272
  e = e.wrapped_exception if e.is_a?(DatabaseError)
262
273
  r = e.result
263
- h = {}
264
- h[:schema] = r.error_field(::PG::PG_DIAG_SCHEMA_NAME)
265
- h[:table] = r.error_field(::PG::PG_DIAG_TABLE_NAME)
266
- h[:column] = r.error_field(::PG::PG_DIAG_COLUMN_NAME)
267
- h[:constraint] = r.error_field(::PG::PG_DIAG_CONSTRAINT_NAME)
268
- h[:type] = r.error_field(::PG::PG_DIAG_DATATYPE_NAME)
269
- h
274
+ h = {
275
+ :schema => r.error_field(::PG::PG_DIAG_SCHEMA_NAME),
276
+ :table => r.error_field(::PG::PG_DIAG_TABLE_NAME),
277
+ :column => r.error_field(::PG::PG_DIAG_COLUMN_NAME),
278
+ :constraint => r.error_field(::PG::PG_DIAG_CONSTRAINT_NAME),
279
+ :type => r.error_field(::PG::PG_DIAG_DATATYPE_NAME),
280
+ :severity => r.error_field(::PG::PG_DIAG_SEVERITY),
281
+ :sql_state => r.error_field(::PG::PG_DIAG_SQLSTATE),
282
+ :message_primary => r.error_field(::PG::PG_DIAG_MESSAGE_PRIMARY),
283
+ :message_detail => r.error_field(::PG::PG_DIAG_MESSAGE_DETAIL),
284
+ :message_hint => r.error_field(::PG::PG_DIAG_MESSAGE_HINT),
285
+ :statement_position => r.error_field(::PG::PG_DIAG_STATEMENT_POSITION),
286
+ :internal_position => r.error_field(::PG::PG_DIAG_INTERNAL_POSITION),
287
+ :internal_query => r.error_field(::PG::PG_DIAG_INTERNAL_QUERY),
288
+ :source_file => r.error_field(::PG::PG_DIAG_SOURCE_FILE),
289
+ :source_line => r.error_field(::PG::PG_DIAG_SOURCE_LINE),
290
+ :source_function => r.error_field(::PG::PG_DIAG_SOURCE_FUNCTION)
291
+ }
270
292
  end
271
293
  end
272
294
 
@@ -482,7 +504,7 @@ module Sequel
482
504
  end
483
505
 
484
506
  # Set the DateStyle to ISO if configured, for faster date parsing.
485
- def connection_configuration_sqls
507
+ def connection_configuration_sqls(opts=@opts)
486
508
  sqls = super
487
509
  sqls << "SET DateStyle = 'ISO'" if @use_iso_date_format
488
510
  sqls