diff --git a/blob.go b/blob.go index bb10c5f..6e4f7d9 100644 --- a/blob.go +++ b/blob.go @@ -143,6 +143,7 @@ func (b *Blob) WriteTo(w io.Writer) (n int64, err error) { return n, err } if int64(m) != want { + // notest // Write misbehaving return n, io.ErrShortWrite } diff --git a/context.go b/context.go index a18211d..6c254d1 100644 --- a/context.go +++ b/context.go @@ -176,7 +176,7 @@ func (ctx Context) ResultJSON(value any) { data, err := json.Marshal(value) if err != nil { ctx.ResultError(err) - return + return // notest } ctx.ResultRawText(data) } diff --git a/ext/blobio/blob.go b/ext/blobio/blob.go index 7649ff0..97d3943 100644 --- a/ext/blobio/blob.go +++ b/ext/blobio/blob.go @@ -81,7 +81,11 @@ func writeblob(ctx sqlite3.Context, arg ...sqlite3.Value) { return // notest } - _, err = blob.Write(arg[5].RawBlob()) + if p, ok := arg[5].Pointer().(io.Reader); ok { + _, err = blob.ReadFrom(p) + } else { + _, err = blob.Write(arg[5].RawBlob()) + } if err != nil { ctx.ResultError(err) return // notest diff --git a/ext/blobio/blob_test.go b/ext/blobio/blob_test.go index f20ff42..52cdd68 100644 --- a/ext/blobio/blob_test.go +++ b/ext/blobio/blob_test.go @@ -5,6 +5,7 @@ import ( "log" "os" "reflect" + "strings" "testing" "github.com/ncruces/go-sqlite3" @@ -47,7 +48,7 @@ func Example() { // Read the BLOB. _, err = db.Exec(`SELECT openblob('main', 'test', 'col', rowid, false, ?) FROM test`, sqlite3.Pointer[blobio.OpenCallback](func(blob *sqlite3.Blob, _ ...sqlite3.Value) error { - _, err = io.Copy(os.Stdout, blob) + _, err = blob.WriteTo(os.Stdout) return err })) if err != nil { @@ -181,7 +182,6 @@ func Test_writeblob(t *testing.T) { err = db.Exec(` CREATE TABLE test (col); INSERT INTO test VALUES (x'cafe'); - -- INSERT INTO test2 VALUES (x'babe'); `) if err != nil { t.Fatal(err) @@ -194,7 +194,18 @@ func Test_writeblob(t *testing.T) { t.Log(err) } - err = db.Exec(`SELECT writeblob('main', 'test', 'col', 1, 0, x'babe')`) + stmt, _, err := db.Prepare(`SELECT writeblob('main', 'test', 'col', 1, 0, ?)`) + if err != nil { + t.Log(err) + } + defer stmt.Close() + + err = stmt.BindPointer(1, strings.NewReader("\xba\xbe")) + if err != nil { + t.Log(err) + } + + err = stmt.Exec() if err != nil { t.Log(err) } diff --git a/ext/fileio/write.go b/ext/fileio/write.go index af7d966..e12fe4d 100644 --- a/ext/fileio/write.go +++ b/ext/fileio/write.go @@ -29,7 +29,7 @@ func writefile(ctx sqlite3.Context, arg ...sqlite3.Value) { n, err := createFileAndDir(file, mode, arg[1]) if err != nil { if len(arg) > 2 { - ctx.ResultError(fmt.Errorf("writefile: %w", err)) + ctx.ResultError(fmt.Errorf("writefile: %w", err)) // notest } return } diff --git a/txn.go b/txn.go index 6fe288e..7121778 100644 --- a/txn.go +++ b/txn.go @@ -230,7 +230,7 @@ func (c *Conn) txnExecInterrupted(sql string) error { return err } -// TxnState starts a deferred transaction. +// TxnState determines the transaction state of a database. // // https://sqlite.org/c3ref/txn_state.html func (c *Conn) TxnState(schema string) TxnState {