aboutsummaryrefslogtreecommitdiff
path: root/error.go
diff options
context:
space:
mode:
authorRobert Knight <robertknight@gmail.com>2013-11-19 09:13:19 +0000
committerRobert Knight <robertknight@gmail.com>2013-11-19 09:13:19 +0000
commit19cb26da92fe05f1eb1c0dd7268067cbc9b5421d (patch)
treeaaea643f22972381b5c6420efb5235ce0ae8df38 /error.go
parentMerge pull request #88 from hattya/close_v2 (diff)
downloadgolite-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.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/error.go b/error.go
index 15c843e..7568505 100644
--- a/error.go
+++ b/error.go
@@ -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)
+ }
}