Compare commits

...

2 Commits

Author SHA1 Message Date
Nuno Cruces
38da27b5d1 Fix. 2024-11-06 12:10:48 +00:00
Nuno Cruces
23737a61ba Log. 2024-11-06 12:10:47 +00:00
7 changed files with 50 additions and 19 deletions

View File

@@ -162,8 +162,8 @@ jobs:
- name: Test ppc64le (interpreter)
run: GOARCH=ppc64le go test -v -short ./...
- name: Test s390x (big-endian, z/OS like)
run: GOARCH=s390x go test -v -short -tags sqlite3_flock ./...
- name: Test s390x (big-endian)
run: GOARCH=s390x go test -v -short -tags sqlite3_dotlk ./...
test-vm:
runs-on: ubuntu-latest

View File

@@ -2,6 +2,7 @@ package sqlite3
import (
"context"
"fmt"
"strconv"
"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.
// Only a subset of opcodes are supported.
//

View File

@@ -106,6 +106,11 @@ func (e ErrorCode) Temporary() bool {
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.
func (e ExtendedErrorCode) Error() string {
return util.ErrorCodeString(uint32(e))
@@ -136,6 +141,11 @@ func (e ExtendedErrorCode) Timeout() bool {
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) {
switch code := err.(type) {
case nil:

View File

@@ -87,9 +87,15 @@ func TestConn_ConfigLog(t *testing.T) {
db.Prepare(`SELECT * FRM sqlite_schema`)
if code != sqlite3.ExtendedErrorCode(sqlite3.ERROR) {
if code != sqlite3.ERROR.ExtendedCode() {
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) {

View File

@@ -114,6 +114,7 @@ func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, ext
defer s.Unlock()
defer s.shmAcquire()
// Extend shared memory.
if int(id) >= len(s.shared) {
if !extend {
return 0, _OK
@@ -121,10 +122,13 @@ func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, ext
s.shared = append(s.shared, make([][_WALINDEX_PGSZ]byte, int(id)-len(s.shared)+1)...)
}
// Allocate shadow memory.
if int(id) >= len(s.shadow) {
s.shadow = append(s.shadow, make([][_WALINDEX_PGSZ]byte, int(id)-len(s.shadow)+1)...)
s.shadow[0][4] = 1 // force invalidation
}
// Allocate local memory.
for int(id) >= len(s.ptrs) {
s.stack[0] = uint64(size)
if err := s.alloc.CallWithStack(ctx, s.stack[:]); err != nil {

View File

@@ -94,21 +94,20 @@ func (s *vfsShm) shmMap(ctx context.Context, mod api.Module, id, size int32, ext
}
}
// Map the region into memory.
r, err := util.MapRegion(ctx, mod, s.File, int64(id)*int64(size), size)
if err != nil {
return 0, _IOERR_SHMMAP
// Maps regions into memory.
for int(id) >= len(s.shared) {
r, err := util.MapRegion(ctx, mod, s.File, int64(id)*int64(size), size)
if err != nil {
return 0, _IOERR_SHMMAP
}
s.regions = append(s.regions, r)
s.shared = append(s.shared, r.Data)
}
s.regions = append(s.regions, r)
if int(id) >= len(s.shared) {
s.shared = append(s.shared, make([][]byte, int(id)-len(s.shared)+1)...)
}
s.shared[id] = r.Data
// Allocate shadow memory.
if int(id) >= len(s.shadow) {
s.shadow = append(s.shadow, make([][_WALINDEX_PGSZ]byte, int(id)-len(s.shadow)+1)...)
s.shadow[0][4] = 1 // force invalidation
}
// Allocate local memory.

View File

@@ -35,6 +35,8 @@ var compressed string
//go:embed testdata/*.*test
var scripts embed.FS
const qemuCI = runtime.GOARCH != "386" && runtime.GOARCH != "amd64" && runtime.GOARCH != "arm64"
var (
rt wazero.Runtime
module wazero.CompiledModule
@@ -160,8 +162,8 @@ func Test_crash01(t *testing.T) {
}
func Test_multiwrite01(t *testing.T) {
if testing.Short() {
t.Skip("skipping in short mode")
if os.Getenv("CI") != "" && qemuCI {
t.Skip("skipping in CI")
}
if !vfs.SupportsFileLocking {
t.Skip("skipping without locks")
@@ -190,8 +192,8 @@ func Test_config01_memory(t *testing.T) {
}
func Test_multiwrite01_memory(t *testing.T) {
if testing.Short() {
t.Skip("skipping in short mode")
if os.Getenv("CI") != "" && qemuCI {
t.Skip("skipping in CI")
}
memdb.Create("test.db", nil)
@@ -225,8 +227,8 @@ func Test_crash01_wal(t *testing.T) {
}
func Test_multiwrite01_wal(t *testing.T) {
if testing.Short() {
t.Skip("skipping in short mode")
if os.Getenv("CI") != "" && qemuCI {
t.Skip("skipping in CI")
}
if !vfs.SupportsSharedMemory {
t.Skip("skipping without shared memory")