backport sqlite3 exception fix

https://github.com/rails/rails/pull/13291
Merge pull request #1 from place-marker/sqlite3-backport

backport sqlite3 exception fix