Skip to content

Commit 23737a6

Browse files
committed
Log.
1 parent af473c7 commit 23737a6

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sqlite3
22

33
import (
44
"context"
5+
"fmt"
56
"strconv"
67

78
"github.com/tetratelabs/wazero/api"
@@ -70,6 +71,15 @@ func logCallback(ctx context.Context, mod api.Module, _, iCode, zMsg uint32) {
7071
}
7172
}
7273

74+
// Log writes a message into the error log established by [Conn.ConfigLog].
75+
//
76+
// https://sqlite.org/c3ref/log.html
77+
func (c *Conn) Log(code ExtendedErrorCode, format string, a ...any) {
78+
if c.log != nil {
79+
c.log(code, fmt.Sprintf(format, a...))
80+
}
81+
}
82+
7383
// FileControl allows low-level control of database files.
7484
// Only a subset of opcodes are supported.
7585
//

error.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ func (e ErrorCode) Temporary() bool {
106106
return e == BUSY
107107
}
108108

109+
// ExtendedCode returns the extended error code for this error.
110+
func (e ErrorCode) ExtendedCode() ExtendedErrorCode {
111+
return ExtendedErrorCode(e)
112+
}
113+
109114
// Error implements the error interface.
110115
func (e ExtendedErrorCode) Error() string {
111116
return util.ErrorCodeString(uint32(e))
@@ -136,6 +141,11 @@ func (e ExtendedErrorCode) Timeout() bool {
136141
return e == BUSY_TIMEOUT
137142
}
138143

144+
// Code returns the primary error code for this error.
145+
func (e ExtendedErrorCode) Code() ErrorCode {
146+
return ErrorCode(e)
147+
}
148+
139149
func errorCode(err error, def ErrorCode) (msg string, code uint32) {
140150
switch code := err.(type) {
141151
case nil:

tests/config_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,15 @@ func TestConn_ConfigLog(t *testing.T) {
8787

8888
db.Prepare(`SELECT * FRM sqlite_schema`)
8989

90-
if code != sqlite3.ExtendedErrorCode(sqlite3.ERROR) {
90+
if code != sqlite3.ERROR.ExtendedCode() {
9191
t.Error("want sqlite3.ERROR")
9292
}
93+
94+
db.Log(sqlite3.NOTICE.ExtendedCode(), "")
95+
96+
if code.Code() != sqlite3.NOTICE {
97+
t.Error("want sqlite3.NOTICE")
98+
}
9399
}
94100

95101
func TestConn_FileControl(t *testing.T) {

0 commit comments

Comments
 (0)