This commit is contained in:
Nuno Cruces
2024-07-10 15:41:28 +01:00
parent 88b5b409df
commit f537ab9a94
6 changed files with 46 additions and 5 deletions

View File

@@ -231,6 +231,7 @@ func (c *conn) Raw() *sqlite3.Conn {
// Deprecated: use BeginTx instead.
func (c *conn) Begin() (driver.Tx, error) {
// notest
return c.BeginTx(context.Background(), driver.TxOptions{})
}
@@ -287,6 +288,7 @@ func (c *conn) Rollback() error {
}
func (c *conn) Prepare(query string) (driver.Stmt, error) {
// notest
return c.PrepareContext(context.Background(), query)
}
@@ -363,11 +365,13 @@ func (s *stmt) NumInput() int {
// Deprecated: use ExecContext instead.
func (s *stmt) Exec(args []driver.Value) (driver.Result, error) {
// notest
return s.ExecContext(context.Background(), namedValues(args))
}
// Deprecated: use QueryContext instead.
func (s *stmt) Query(args []driver.Value) (driver.Rows, error) {
// notest
return s.QueryContext(context.Background(), namedValues(args))
}

View File

@@ -328,6 +328,7 @@ func (c *cursor) EOF() bool {
}
func (c *cursor) RowID() (int64, error) {
// notest // WITHOUT ROWID
return 0, nil
}

View File

@@ -144,6 +144,11 @@ func TestRegister(t *testing.T) {
t.Errorf("got %d, want 3", got)
}
}
err = db.Exec(`ALTER TABLE v_x RENAME TO v_y`)
if err != nil {
t.Fatal(err)
}
}
func TestRegister_errors(t *testing.T) {

View File

@@ -20,17 +20,17 @@ func Register(db *sqlite3.Conn) error {
func zorder(ctx sqlite3.Context, arg ...sqlite3.Value) {
var x [63]int64
for i := range arg {
x[i] = arg[i].Int64()
}
if len(arg) > len(x) {
ctx.ResultError(util.ErrorString("zorder: too many parameters"))
return
}
for i := range arg {
x[i] = arg[i].Int64()
}
var z int64
if len(arg) > 0 {
for i := 0; i < 63; i++ {
for i := range x {
j := i % len(arg)
z |= (x[j] & 1) << i
x[j] >>= 1

View File

@@ -1,6 +1,8 @@
package zorder_test
import (
"strconv"
"strings"
"testing"
"github.com/ncruces/go-sqlite3/driver"
@@ -94,4 +96,16 @@ func TestRegister_error(t *testing.T) {
if err == nil {
t.Error("want error")
}
var buf strings.Builder
buf.WriteString("SELECT zorder(0")
for i := 1; i < 80; i++ {
buf.WriteByte(',')
buf.WriteString(strconv.Itoa(0))
}
buf.WriteByte(')')
err = db.QueryRow(buf.String()).Scan(&got)
if err == nil {
t.Error("want error")
}
}

View File

@@ -172,6 +172,11 @@ func TestConn_SetInterrupt(t *testing.T) {
if err != nil {
t.Fatal(err)
}
db.SetInterrupt(ctx)
if got := db.GetInterrupt(); got != ctx {
t.Errorf("got %v, want %v", got, ctx)
}
}
func TestConn_Prepare_empty(t *testing.T) {
@@ -372,13 +377,25 @@ func TestConn_SetAuthorizer(t *testing.T) {
defer db.Close()
err = db.SetAuthorizer(func(action sqlite3.AuthorizerActionCode, name3rd, name4th, schema, nameInner string) sqlite3.AuthorizerReturnCode {
if action != sqlite3.AUTH_PRAGMA {
t.Errorf("got %v, want PRAGMA", action)
}
if name3rd != "busy_timeout" {
t.Errorf("got %q, want busy_timeout", name3rd)
}
if name4th != "5000" {
t.Errorf("got %q, want 5000", name4th)
}
if schema != "main" {
t.Errorf("got %q, want main", schema)
}
return sqlite3.AUTH_DENY
})
if err != nil {
t.Fatal(err)
}
err = db.Exec(`SELECT * FROM sqlite_schema`)
err = db.Exec(`PRAGMA main.busy_timeout=5000`)
if !errors.Is(err, sqlite3.AUTH) {
t.Errorf("got %v, want sqlite3.AUTH", err)
}