go-sqlite3
go-sqlite3 copied to clipboard
Allow user-defined functions to accept pointers
See #728. There the user had defined a function that took a string
and SQLite tried to pass NULL
to it. That resulted in an error from this library stating argument must be BLOB or TEXT
. Changing the function to take a *string
instead didn't work and resulted in an error stating don't know how to convert to *string
. Please update the private callbackArg
func used by RegisterFunc
to properly handle an input type of kind reflect.Ptr
.
@rittneje I've implemented this feature request tested it only briefly. Could you add a test case for this to TestFunctionRegistration
?
About #728 This does not fix the issue with case #728 it only fixes "don't know how to convert to <reflect.Ptr>
.
I hope you can write some nice RegisterFunc
which uses Pointers as arguments.
@rittneje Code available in branch: feature-pointer-callback
Any updates on this?
@clarkmcc I don't believe a PR was ever raised. And I don't think the branch from @gjrtimmer will work without further changes. It needs to be something along these lines:
func callbackArg(typ reflect.Type) (callbackArgConverter, error) {
switch typ.Kind() {
case reflect.Ptr:
f := callbackArg(typ.Elem())
return func(v *C.sqlite3_value) (reflect.Value, error) {
if C.sqlite3_value_type(v) == C.SQLITE_NULL {
return reflect.Zero(typ), nil
}
rv, err := f(v)
if err != nil {
return reflect.Value{}, err
}
ptr := reflect.New(rv.Type())
ptr.Elem().Set(rv)
return ptr, nil
}
...
(Note: I have not tested or compiled this.)