Skip to content

Commit 06f58c3

Browse files
committed
Fix Context.ResultPointer.
1 parent 28f225b commit 06f58c3

File tree

7 files changed

+83
-2
lines changed

7 files changed

+83
-2
lines changed

Diff for: context.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ func (ctx Context) resultRFC3339Nano(value time.Time) {
165165
// https://sqlite.org/c3ref/result_blob.html
166166
func (ctx Context) ResultPointer(ptr any) {
167167
valPtr := util.AddHandle(ctx.c.ctx, ptr)
168-
ctx.c.call("sqlite3_result_pointer_go", uint64(valPtr))
168+
ctx.c.call("sqlite3_result_pointer_go",
169+
uint64(ctx.handle), uint64(valPtr))
169170
}
170171

171172
// ResultJSON sets the result of the function to the JSON encoding of value.

Diff for: internal/util/error_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package util
2+
3+
import "testing"
4+
5+
func TestErrorJoiner(t *testing.T) {
6+
var errs ErrorJoiner
7+
errs.Join(NilErr, OOMErr)
8+
for i, e := range []error{NilErr, OOMErr} {
9+
if e != errs[i] {
10+
t.Fail()
11+
}
12+
}
13+
}

Diff for: tests/func_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,41 @@ func TestAnyCollationNeeded(t *testing.T) {
279279
t.Fatal(err)
280280
}
281281
}
282+
283+
func TestPointer(t *testing.T) {
284+
t.Parallel()
285+
286+
db, err := sqlite3.Open(":memory:")
287+
if err != nil {
288+
t.Fatal(err)
289+
}
290+
defer db.Close()
291+
292+
var want any = "xpto"
293+
294+
err = db.CreateFunction("ident", 1, 0, func(ctx sqlite3.Context, arg ...sqlite3.Value) {
295+
got := arg[0].Pointer()
296+
if got != want {
297+
t.Errorf("want %v, got %v", want, got)
298+
}
299+
ctx.ResultPointer(got)
300+
})
301+
if err != nil {
302+
t.Fatal(err)
303+
}
304+
305+
stmt, _, err := db.Prepare(`SELECT ident(ident(?))`)
306+
if err != nil {
307+
t.Fatal(err)
308+
}
309+
310+
err = stmt.BindPointer(1, want)
311+
if err != nil {
312+
t.Fatal(err)
313+
}
314+
315+
err = stmt.Exec()
316+
if err != nil {
317+
t.Error(err)
318+
}
319+
}

Diff for: vfs/const_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package vfs
2+
3+
import (
4+
"math"
5+
"testing"
6+
)
7+
8+
func Test_ErrorCode_Error(t *testing.T) {
9+
tests := []struct {
10+
code _ErrorCode
11+
want string
12+
}{
13+
{_OK, "sqlite3: not an error"},
14+
{_ERROR, "sqlite3: SQL logic error"},
15+
{math.MaxUint32, "sqlite3: unknown error"},
16+
}
17+
for _, tt := range tests {
18+
t.Run(tt.want, func(t *testing.T) {
19+
if got := tt.code.Error(); got != tt.want {
20+
t.Errorf("_ErrorCode.Error() = %v, want %v", got, tt.want)
21+
}
22+
})
23+
}
24+
}

Diff for: vfs/memdb/memdb.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (memVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag, err
3030
vfs.OPEN_TEMP_DB |
3131
vfs.OPEN_TEMP_JOURNAL
3232
if flags&types == 0 {
33-
// notest
33+
// notest // OPEN_MEMORY
3434
return nil, flags, sqlite3.CANTOPEN
3535
}
3636

@@ -270,6 +270,7 @@ func (m *memFile) Unlock(lock vfs.LockLevel) error {
270270
}
271271

272272
func (m *memFile) CheckReservedLock() (bool, error) {
273+
// notest // OPEN_MEMORY
273274
if m.lock >= vfs.LOCK_RESERVED {
274275
return true, nil
275276
}
@@ -279,6 +280,7 @@ func (m *memFile) CheckReservedLock() (bool, error) {
279280
}
280281

281282
func (m *memFile) SectorSize() int {
283+
// notest // IOCAP_POWERSAFE_OVERWRITE
282284
return sectorSize
283285
}
284286

Diff for: vfs/os_unix_lock.go

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func osDowngradeLock(file *os.File, state LockLevel) _ErrorCode {
5050
// indicates that the other process is not following the locking
5151
// protocol. If this happens, return IOERR_RDLOCK. Returning
5252
// BUSY would confuse the upper layer.
53+
// notest
5354
return _IOERR_RDLOCK
5455
}
5556
}
@@ -98,6 +99,7 @@ func osLockErrorCode(err error, def _ErrorCode) _ErrorCode {
9899
case unix.EPERM:
99100
return _PERM
100101
}
102+
// notest // usually EWOULDBLOCK == EAGAIN
101103
if errno == unix.EWOULDBLOCK && unix.EWOULDBLOCK != unix.EAGAIN {
102104
return _BUSY
103105
}

Diff for: vfs/os_windows.go

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func osDowngradeLock(file *os.File, state LockLevel) _ErrorCode {
6666
if rc := osReadLock(file, _SHARED_FIRST, _SHARED_SIZE, 0); rc != _OK {
6767
// This should never happen.
6868
// We should always be able to reacquire the read lock.
69+
// notest
6970
return _IOERR_RDLOCK
7071
}
7172
}

0 commit comments

Comments
 (0)