77 "strconv"
88
99 "github.com/ncruces/go-sqlite3/internal/errutil"
10+ "github.com/ncruces/go-sqlite3/internal/sqlite3_wrap"
1011 "github.com/ncruces/go-sqlite3/internal/util"
1112)
1213
@@ -23,29 +24,29 @@ func JSON(value any) any {
2324//
2425// https://sqlite.org/c3ref/result_blob.html
2526func (ctx Context ) ResultJSON (value any ) {
26- w := bytesWriter {sqlite : ctx .c .sqlite }
27+ w := bytesWriter {wrp : ctx .c .wrp }
2728 if err := json .MarshalWrite (& w , value ); err != nil {
28- ctx .c .free (w .ptr )
29+ ctx .c .wrp . Free (w .ptr )
2930 ctx .ResultError (err )
3031 return // notest
3132 }
32- ctx .c .ctx .Xsqlite3_result_text_go (
33- int32 (ctx .handle ), int32 (w .ptr ), int32 (len (w .buf )))
33+ ctx .c .wrp .Xsqlite3_result_text_go (
34+ int32 (ctx .handle ), int32 (w .ptr ), int64 (len (w .buf )))
3435}
3536
3637// BindJSON binds the JSON encoding of value to the prepared statement.
3738// The leftmost SQL parameter has an index of 1.
3839//
3940// https://sqlite.org/c3ref/bind_blob.html
4041func (s * Stmt ) BindJSON (param int , value any ) error {
41- w := bytesWriter {sqlite : s .c .sqlite }
42+ w := bytesWriter {wrp : s .c .wrp }
4243 if err := json .MarshalWrite (& w , value ); err != nil {
43- s .c .free (w .ptr )
44+ s .c .wrp . Free (w .ptr )
4445 return err // notest
4546 }
46- rc := res_t (s .c .ctx .Xsqlite3_bind_text_go (
47+ rc := res_t (s .c .wrp .Xsqlite3_bind_text_go (
4748 int32 (s .handle ), int32 (param ),
48- int32 (w .ptr ), int32 (len (w .buf ))))
49+ int32 (w .ptr ), int64 (len (w .buf ))))
4950 return s .c .error (rc )
5051}
5152
@@ -95,7 +96,7 @@ func (v Value) JSON(ptr any) error {
9596}
9697
9798type bytesWriter struct {
98- * sqlite
99+ wrp * sqlite3_wrap. Wrapper
99100 buf []byte
100101 ptr ptr_t
101102}
@@ -106,8 +107,8 @@ func (b *bytesWriter) Write(p []byte) (n int, err error) {
106107 grow := int64 (cap (b .buf ))
107108 grow += grow >> 1
108109 want = max (want , grow )
109- b .ptr = b .realloc (b .ptr , want )
110- b .buf = b .mod .Slice (b .ptr , want )[:len (b .buf )]
110+ b .ptr = b .wrp . Realloc (b .ptr , want )
111+ b .buf = b .wrp .Slice (b .ptr , want )[:len (b .buf )]
111112 }
112113 b .buf = append (b .buf , p ... )
113114 _ = append (b .buf , 0 )
0 commit comments