Commit d1b8699e authored by gwenn's avatar gwenn

Add Context#Result.

parent 92e3a38c
......@@ -62,6 +62,8 @@ static int goSqlite3CreateFunctionV2(sqlite3 *db, const char *zFunctionName, int
import "C"
import (
"fmt"
"reflect"
"unsafe"
)
......@@ -77,6 +79,37 @@ type Context struct {
argv **C.sqlite3_value
}
func (c *Context) Result(r interface{}) {
switch r := r.(type) {
case nil:
c.ResultNull()
case string:
c.ResultText(r)
case int:
c.ResultInt(r)
case int64:
c.ResultInt64(r)
case byte:
c.ResultInt(int(r))
case bool:
c.ResultBool(r)
case float32:
c.ResultDouble(float64(r))
case float64:
c.ResultDouble(r)
case []byte:
c.ResultBlob(r)
case ZeroBlobLength:
c.ResultZeroblob(r)
case error:
c.ResultError(r.Error())
case Errno:
c.ResultErrorCode(r)
default:
panic(fmt.Sprintf("unsupported type in Result: %s", reflect.TypeOf(r)))
}
}
// Set the result of an SQL function
func (c *Context) ResultBool(b bool) {
if b {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment