luislavena/sqlite3-ruby — pull request #80 by yuki24 (2013-02-03 17:00:28+00:00)
Title: Reset before CHECKing the status

Hi,

When `SQLite3::ConstraintException` is raised, the error message will always be `"constraint failed"`, which isn't helpful enough. So `sqlite3_reset()` should be called before CHECKing to get more specific error messages from `sqlite3_errmsg()`.

This design is described on `sqlite3_step()`'s documentation at: http://www.sqlite.org/c3ref/step.html

> In the legacy interface, the sqlite3_step() API always returns a generic error code, SQLITE_ERROR, following any error other than SQLITE_BUSY and SQLITE_MISUSE. You must call sqlite3_reset() or sqlite3_finalize() in order to find one of the specific error codes that better describes the error. We admit that this is a goofy design. The problem has been fixed with the "v2" interface. If you prepare all of your SQL statements using either sqlite3_prepare_v2() or sqlite3_prepare16_v2() instead of the legacy sqlite3_prepare() and sqlite3_prepare16() interfaces, then the more specific error codes are returned directly by sqlite3_step(). The use of the "v2" interface is recommended.