Skip to content

Commit

Permalink
Handle disconnect errors in ibmdb and jdbc/db2 adapters (Fixes #2083)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyevans committed Sep 26, 2023
1 parent cd25a09 commit 856a918
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Handle disconnect errors in ibmdb and jdbc/db2 adapters (jeremyevans) (#2083)

* Support skipping transactions in Dataset#{import,paged_each} using :skip_transaction option (jeremyevans)

* Add Database#transaction :skip_transaction option to skip creating a transaction or savepoint (jeremyevans)
Expand Down
2 changes: 1 addition & 1 deletion lib/sequel/adapters/ibmdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def database_error_classes
end

def database_exception_sqlstate(exception, opts)
exception.sqlstate
exception.sqlstate if exception.respond_to?(:sqlstate)
end

def dataset_class_default
Expand Down
4 changes: 4 additions & 0 deletions lib/sequel/adapters/jdbc/db2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ module DatabaseMethods

private

def database_exception_sqlstate(exception, opts)
exception.sql_state if exception.respond_to?(:sql_state)
end

def set_ps_arg(cps, arg, i)
case arg
when Sequel::SQL::Blob
Expand Down
12 changes: 12 additions & 0 deletions lib/sequel/adapters/shared/db2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ def database_error_regexps
DATABASE_ERROR_REGEXPS
end

DISCONNECT_SQL_STATES = %w'40003 08001 08003'.freeze
def disconnect_error?(exception, opts)
sqlstate = database_exception_sqlstate(exception, opts)

case sqlstate
when *DISCONNECT_SQL_STATES
true
else
super
end
end

# DB2 has issues with quoted identifiers, so
# turn off database quoting by default.
def quote_identifiers_default
Expand Down

0 comments on commit 856a918

Please sign in to comment.