package sqlite3
import (
"errors"
"time"
"github.com/ncruces/go-sqlite3/internal/errutil"
)
type Context struct {
c *Conn
handle ptr_t
}
func (ctx Context ) Conn () *Conn {
return ctx .c
}
func (ctx Context ) SetAuxData (n int , data any ) {
ptr := ctx .c .wrp .AddHandle (data )
ctx .c .wrp .Xsqlite3_set_auxdata_go (int32 (ctx .handle ), int32 (n ), int32 (ptr ))
}
func (ctx Context ) GetAuxData (n int ) any {
ptr := ptr_t (ctx .c .wrp .Xsqlite3_get_auxdata (int32 (ctx .handle ), int32 (n )))
return ctx .c .wrp .GetHandle (ptr )
}
func (ctx Context ) ResultBool (value bool ) {
var i int64
if value {
i = 1
}
ctx .ResultInt64 (i )
}
func (ctx Context ) ResultInt (value int ) {
ctx .ResultInt64 (int64 (value ))
}
func (ctx Context ) ResultInt64 (value int64 ) {
ctx .c .wrp .Xsqlite3_result_int64 (
int32 (ctx .handle ), value )
}
func (ctx Context ) ResultFloat (value float64 ) {
ctx .c .wrp .Xsqlite3_result_double (
int32 (ctx .handle ), value )
}
func (ctx Context ) ResultText (value string ) {
ptr := ctx .c .wrp .NewString (value )
ctx .c .wrp .Xsqlite3_result_text_go (
int32 (ctx .handle ), int32 (ptr ), int64 (len (value )))
}
func (ctx Context ) ResultRawText (value []byte ) {
ctx .ResultText (string (value ))
}
func (ctx Context ) ResultBlob (value []byte ) {
if len (value ) == 0 {
ctx .ResultZeroBlob (0 )
return
}
ptr := ctx .c .wrp .NewBytes (value )
ctx .c .wrp .Xsqlite3_result_blob_go (
int32 (ctx .handle ), int32 (ptr ), int64 (len (value )))
}
func (ctx Context ) ResultZeroBlob (n int64 ) {
ctx .c .wrp .Xsqlite3_result_zeroblob64 (
int32 (ctx .handle ), n )
}
func (ctx Context ) ResultNull () {
ctx .c .wrp .Xsqlite3_result_null (
int32 (ctx .handle ))
}
func (ctx Context ) ResultTime (value time .Time , format TimeFormat ) {
switch format {
case TimeFormatDefault , TimeFormatAuto , time .RFC3339Nano :
ctx .resultRFC3339Nano (value )
return
}
switch v := format .Encode (value ).(type ) {
case string :
ctx .ResultText (v )
case int64 :
ctx .ResultInt64 (v )
case float64 :
ctx .ResultFloat (v )
default :
panic (errutil .AssertErr ())
}
}
func (ctx Context ) resultRFC3339Nano (value time .Time ) {
const maxlen = 48
ptr := ctx .c .wrp .New (maxlen )
buf := ctx .c .wrp .Bytes (ptr , maxlen )
buf = value .AppendFormat (buf [:0 ], time .RFC3339Nano )
_ = append (buf , 0 )
ctx .c .wrp .Xsqlite3_result_text_go (
int32 (ctx .handle ), int32 (ptr ), int64 (len (buf )))
}
func (ctx Context ) ResultPointer (ptr any ) {
valPtr := ctx .c .wrp .AddHandle (ptr )
ctx .c .wrp .Xsqlite3_result_pointer_go (
int32 (ctx .handle ), int32 (valPtr ))
}
func (ctx Context ) ResultValue (value Value ) {
if value .c != ctx .c {
ctx .ResultError (MISUSE )
return
}
ctx .c .wrp .Xsqlite3_result_value (
int32 (ctx .handle ), int32 (value .handle ))
}
func (ctx Context ) ResultError (err error ) {
if errors .Is (err , NOMEM ) {
ctx .c .wrp .Xsqlite3_result_error_nomem (int32 (ctx .handle ))
return
}
if errors .Is (err , TOOBIG ) {
ctx .c .wrp .Xsqlite3_result_error_toobig (int32 (ctx .handle ))
return
}
msg , code := errorCode (err , ERROR )
if msg != "" {
defer ctx .c .arena .Mark ()()
ptr := ctx .c .arena .String (msg )
ctx .c .wrp .Xsqlite3_result_error (
int32 (ctx .handle ), int32 (ptr ), int32 (len (msg )))
}
if code != res_t (ERROR ) {
ctx .c .wrp .Xsqlite3_result_error_code (
int32 (ctx .handle ), int32 (code ))
}
}
func (ctx Context ) ResultSubtype (t uint ) {
ctx .c .wrp .Xsqlite3_result_subtype (
int32 (ctx .handle ), int32 (t ))
}
func (ctx Context ) VTabNoChange () bool {
b := int32 (ctx .c .wrp .Xsqlite3_vtab_nochange (int32 (ctx .handle )))
return b != 0
}
The pages are generated with Golds v0.8.4 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .