mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-11 21:49:13 +00:00
Log.
This commit is contained in:
10
config.go
10
config.go
@@ -2,6 +2,7 @@ package sqlite3
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/tetratelabs/wazero/api"
|
"github.com/tetratelabs/wazero/api"
|
||||||
@@ -70,6 +71,15 @@ func logCallback(ctx context.Context, mod api.Module, _, iCode, zMsg uint32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log writes a message into the error log established by [Conn.ConfigLog].
|
||||||
|
//
|
||||||
|
// https://sqlite.org/c3ref/log.html
|
||||||
|
func (c *Conn) Log(code ExtendedErrorCode, format string, a ...any) {
|
||||||
|
if c.log != nil {
|
||||||
|
c.log(code, fmt.Sprintf(format, a...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FileControl allows low-level control of database files.
|
// FileControl allows low-level control of database files.
|
||||||
// Only a subset of opcodes are supported.
|
// Only a subset of opcodes are supported.
|
||||||
//
|
//
|
||||||
|
|||||||
10
error.go
10
error.go
@@ -106,6 +106,11 @@ func (e ErrorCode) Temporary() bool {
|
|||||||
return e == BUSY
|
return e == BUSY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExtendedCode returns the extended error code for this error.
|
||||||
|
func (e ErrorCode) ExtendedCode() ExtendedErrorCode {
|
||||||
|
return ExtendedErrorCode(e)
|
||||||
|
}
|
||||||
|
|
||||||
// Error implements the error interface.
|
// Error implements the error interface.
|
||||||
func (e ExtendedErrorCode) Error() string {
|
func (e ExtendedErrorCode) Error() string {
|
||||||
return util.ErrorCodeString(uint32(e))
|
return util.ErrorCodeString(uint32(e))
|
||||||
@@ -136,6 +141,11 @@ func (e ExtendedErrorCode) Timeout() bool {
|
|||||||
return e == BUSY_TIMEOUT
|
return e == BUSY_TIMEOUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Code returns the primary error code for this error.
|
||||||
|
func (e ExtendedErrorCode) Code() ErrorCode {
|
||||||
|
return ErrorCode(e)
|
||||||
|
}
|
||||||
|
|
||||||
func errorCode(err error, def ErrorCode) (msg string, code uint32) {
|
func errorCode(err error, def ErrorCode) (msg string, code uint32) {
|
||||||
switch code := err.(type) {
|
switch code := err.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
|
|||||||
@@ -87,9 +87,15 @@ func TestConn_ConfigLog(t *testing.T) {
|
|||||||
|
|
||||||
db.Prepare(`SELECT * FRM sqlite_schema`)
|
db.Prepare(`SELECT * FRM sqlite_schema`)
|
||||||
|
|
||||||
if code != sqlite3.ExtendedErrorCode(sqlite3.ERROR) {
|
if code != sqlite3.ERROR.ExtendedCode() {
|
||||||
t.Error("want sqlite3.ERROR")
|
t.Error("want sqlite3.ERROR")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db.Log(sqlite3.NOTICE.ExtendedCode(), "")
|
||||||
|
|
||||||
|
if code.Code() != sqlite3.NOTICE {
|
||||||
|
t.Error("want sqlite3.NOTICE")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConn_FileControl(t *testing.T) {
|
func TestConn_FileControl(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user