From b4f5cc77d1cca1470922e916c9f775ef17d2d78f Mon Sep 17 00:00:00 2001 From: rittneje Date: Tue, 17 Dec 2019 01:58:28 -0500 Subject: 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 --- error.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'error.go') 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 +#else +#include +#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 -- cgit v1.2.3