Translate new unique constraint error message for sqlite >= 3.8.2 #13291

Merged
merged 1 commit into from Dec 12, 2013

Projects

None yet

3 participants

@strzibny
Contributor

The new version of sqlite (3.8.2) is handling the error message for unique constraint differently so the old check is not enough.

I was getting the following test failure using sqlite 3.8.2 (and using sqlite3 gem at 1.3.7 and rails at 4.0.2):

1) Failure:
ActiveRecord::AdapterTest#test_uniqueness_violations_are_translated_to_specific_exception [/builddir/build/BUILD/rubygem-activerecord-4.0.2/usr/share/gems/gems/activerecord-4.0.2/test/cases/adapter_test.rb:141]:
[ActiveRecord::RecordNotUnique] exception expected, not
Class: <ActiveRecord::StatementInvalid>
Message: <"SQLite3::ConstraintException: UNIQUE constraint failed: subscribers.nick: INSERT INTO subscribers(nick) VALUES('me')">
---Backtrace---
/usr/share/gems/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:108:in `step'
/usr/share/gems/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:108:in `block in each'
/usr/share/gems/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:107:in `loop'
/usr/share/gems/gems/sqlite3-1.3.7/lib/sqlite3/statement.rb:107:in `each'
/usr/share/gems/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:149:in `map'
/usr/share/gems/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:149:in `block in execute'
/usr/share/gems/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:95:in `prepare'
/usr/share/gems/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:134:in `execute'

This PR resolves this issue by checking the new returning error message as well.

@senny
Member
senny commented Dec 12, 2013

@strzibny can we add both messages as comments to the source?

@carlosantoniodasilva

Bad news is that they do not mention that in their changelogs 😄, but I found a commit fixing their test suite related to the same change (didn't find the source commit yet though).

@strzibny
Contributor

@carlosantoniodasilva Same here, otherwise I would reference it already.

@strzibny
Contributor

@senny Done.

@senny
Member
senny commented Dec 12, 2013

@strzibny thanks! I'll verify it on my machine and will give it a merge after that. Thanks you 💛

@senny
Member
senny commented Dec 12, 2013

tested and works like a charm with both versions.

@senny senny merged commit 02a81b8 into rails:master Dec 12, 2013
@jormon jormon added a commit to place-marker/rails that referenced this pull request Nov 25, 2014
@jormon jormon backport sqlite3 exception fix 54a262a
@jormon jormon referenced this pull request in place-marker/rails Nov 25, 2014
Merged

backport sqlite3 exception fix #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment