Skip to content

Commit

Permalink
Recognize constraint violation exceptions on swift/sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyevans committed Jul 26, 2015
1 parent 0c0f5a9 commit 9891eba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG
@@ -1,6 +1,8 @@
=== HEAD

* Recognize another check constraint failure message on SQLite (jeremyevans)
* Recognize constraint violation exceptions on swift/sqlite (jeremyevans)

* Recognize another check constraint violation exception message on SQLite (jeremyevans)

* Allow =~ and !~ to be used on ComplexExpressions (janko-m) (#1050)

Expand Down
12 changes: 12 additions & 0 deletions lib/sequel/adapters/swift/sqlite.rb
Expand Up @@ -11,6 +11,18 @@ module DatabaseMethods
extend Sequel::Database::ResetIdentifierMangling
include Sequel::SQLite::DatabaseMethods

DATABASE_ERROR_REGEXPS = {
/\AUNIQUE constraint failed: / => UniqueConstraintViolation,
/\AFOREIGN KEY constraint failed/ => ForeignKeyConstraintViolation,
/\ACHECK constraint failed/ => CheckConstraintViolation,
/\A(SQLITE ERROR 19 \(CONSTRAINT\) : )?constraint failed/ => ConstraintViolation,
/may not be NULL\z|NOT NULL constraint failed: .+/ => NotNullConstraintViolation,
/\ASQLITE ERROR \d+ \(\) : CHECK constraint failed: / => CheckConstraintViolation
}.freeze
def database_error_regexps
DATABASE_ERROR_REGEXPS
end

# Set the correct pragmas on the connection.
def connect(opts)
c = super
Expand Down

0 comments on commit 9891eba

Please sign in to comment.