Provide more detailed error messages

Use the sqlite3_errmsg() API to retrieve more specific error
messages.

eg. Attempting to exec 'CREATE TABLE ExistingTableName (...)'
will now report 'table already exists: ExistingTableName' rather
than 'SQL logic error or missing database'
This commit is contained in:
Robert Knight
2013-11-19 09:13:19 +00:00
parent 056b49918a
commit 19cb26da92
3 changed files with 35 additions and 15 deletions

View File

@@ -4,6 +4,12 @@ import "C"
type ErrNo int
type Error struct {
Code ErrNo /* The error code returned by SQLite */
err string /* The error string returned by sqlite3_errmsg(),
this usually contains more specific details. */
}
// result codes from http://www.sqlite.org/c3ref/c_abort.html
var (
ErrError error = ErrNo(1) /* SQL error or missing database */
@@ -37,5 +43,13 @@ var (
)
func (err ErrNo) Error() string {
return errorString(err)
return Error{Code: err}.Error()
}
func (err Error) Error() string {
if err.err != "" {
return err.err
} else {
return errorString(err)
}
}