Permalink
Browse files

Fix constraint violation detection on SQLite

The general "constraint failed" is not necessarily indicative of
a check constraint failure, and it looks like some versions of
SQLite use the text for non-check constraint violations, so use
the more general ConstraintViolation exception.
  • Loading branch information...
1 parent 9200887 commit 9bca383851431a7cf74f95572b404982d3b8e29a @jeremyevans committed Jan 25, 2013
Showing with 2 additions and 2 deletions.
  1. +1 −1 lib/sequel/adapters/shared/sqlite.rb
  2. +1 −1 spec/integration/database_test.rb
@@ -315,7 +315,7 @@ def connection_pragmas
DATABASE_ERROR_REGEXPS = {
/is not unique\z/ => UniqueConstraintViolation,
/foreign key constraint failed\z/ => ForeignKeyConstraintViolation,
- /\A(SQLITE ERROR 19 \(CONSTRAINT\) : )?constraint failed\z/ => CheckConstraintViolation,
+ /\A(SQLITE ERROR 19 \(CONSTRAINT\) : )?constraint failed\z/ => ConstraintViolation,
/may not be NULL\z/ => NotNullConstraintViolation,
}.freeze
def database_error_regexps
@@ -40,7 +40,7 @@
proc{@db[:test].update(:a=>'1')}.should raise_error(Sequel::UniqueConstraintViolation)
end
- cspecify "should raise Sequel::CheckConstraintViolation when a check constraint is violated", :mysql, [:jdbc, :sqlite], [:db2] do
+ cspecify "should raise Sequel::CheckConstraintViolation when a check constraint is violated", :mysql, :sqlite, [:db2] do
@db.create_table!(:test){String :a; check Sequel.~(:a=>'1')}
proc{@db[:test].insert('1')}.should raise_error(Sequel::CheckConstraintViolation)
@db[:test].insert('2')

0 comments on commit 9bca383

Please sign in to comment.