diff options
author | Robert Knight <robertknight@gmail.com> | 2013-11-19 09:13:19 +0000 |
---|---|---|
committer | Robert Knight <robertknight@gmail.com> | 2013-11-19 09:13:19 +0000 |
commit | 19cb26da92fe05f1eb1c0dd7268067cbc9b5421d (patch) | |
tree | aaea643f22972381b5c6420efb5235ce0ae8df38 /error.go | |
parent | Merge pull request #88 from hattya/close_v2 (diff) | |
download | golite-19cb26da92fe05f1eb1c0dd7268067cbc9b5421d.tar.gz golite-19cb26da92fe05f1eb1c0dd7268067cbc9b5421d.tar.xz |
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'
Diffstat (limited to 'error.go')
-rw-r--r-- | error.go | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -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) + } } |