aboutsummaryrefslogtreecommitdiff
path: root/error.go
diff options
context:
space:
mode:
authorrittneje <rittneje@gmail.com>2019-12-17 01:58:28 -0500
committermattn <mattn.jp@gmail.com>2019-12-17 15:58:28 +0900
commitb4f5cc77d1cca1470922e916c9f775ef17d2d78f (patch)
treef4c84d072f9b184a486c9d78edbe5e0cab21e2a2 /error.go
parentMerge pull request #744 from azavorotnii/ctx_cancel (diff)
downloadgolite-b4f5cc77d1cca1470922e916c9f775ef17d2d78f.tar.gz
golite-b4f5cc77d1cca1470922e916c9f775ef17d2d78f.tar.xz
add SystemErrno to Error (#740)
* adding SystemErrno to Error, and fixing error logic when open fails * fix for old versions of libsqlite3 that do not have sqlite3_system_errno defined * fixing pre-processor logic
Diffstat (limited to 'error.go')
-rw-r--r--error.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/error.go b/error.go
index 0c4992f..696281c 100644
--- a/error.go
+++ b/error.go
@@ -5,7 +5,15 @@
package sqlite3
+/*
+#ifndef USE_LIBSQLITE3
+#include <sqlite3-binding.h>
+#else
+#include <sqlite3.h>
+#endif
+*/
import "C"
+import "syscall"
// ErrNo inherit errno.
type ErrNo int
@@ -20,6 +28,7 @@ type ErrNoExtended int
type Error struct {
Code ErrNo /* The error code returned by SQLite */
ExtendedCode ErrNoExtended /* The extended error code returned by SQLite */
+ SystemErrno syscall.Errno /* The system errno returned by the OS through SQLite, if applicable */
err string /* The error string returned by sqlite3_errmsg(),
this usually contains more specific details. */
}
@@ -72,10 +81,16 @@ func (err ErrNoExtended) Error() string {
}
func (err Error) Error() string {
+ var str string
if err.err != "" {
- return err.err
+ str = err.err
+ } else {
+ str = C.GoString(C.sqlite3_errstr(C.int(err.Code)))
}
- return errorString(err)
+ if err.SystemErrno != 0 {
+ str += ": " + err.SystemErrno.Error()
+ }
+ return str
}
// result codes from http://www.sqlite.org/c3ref/c_abort_rollback.html