diff options
Diffstat (limited to 'src/golite.go')
| -rw-r--r-- | src/golite.go | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/src/golite.go b/src/golite.go index d3e2f19..b374fd3 100644 --- a/src/golite.go +++ b/src/golite.go @@ -1314,91 +1314,6 @@ func (c *SQLiteConn) RegisterUpdateHook(callback func(int, string, string, int64 } } -// RegisterFunc makes a Go function available as a SQLite function. -// -// The Go function can have arguments of the following types: any -// numeric type except complex, bool, []byte, string and any. -// any arguments are given the direct translation of the SQLite data type: -// int64 for INTEGER, float64 for FLOAT, []byte for BLOB, string for TEXT. -// -// The function can additionally be variadic, as long as the type of -// the variadic argument is one of the above. -// -// If pure is true. SQLite will assume that the function's return -// value depends only on its inputs, and make more aggressive -// optimizations in its queries. -// -// See _example/go_custom_funcs for a detailed example. -func (c *SQLiteConn) RegisterFunc(name string, impl any, pure bool) error { - var fi functionInfo - fi.f = reflect.ValueOf(impl) - t := fi.f.Type() - if t.Kind() != reflect.Func { - return errors.New("Non-function passed to RegisterFunc") - } - if t.NumOut() != 1 && t.NumOut() != 2 { - return errors.New("SQLite functions must return 1 or 2 values") - } - if t.NumOut() == 2 && !t.Out(1).Implements(reflect.TypeOf((*error)(nil)).Elem()) { - return errors.New("Second return value of SQLite function must be error") - } - - numArgs := t.NumIn() - if t.IsVariadic() { - numArgs-- - } - - for i := 0; i < numArgs; i++ { - conv, err := callbackArg(t.In(i)) - if err != nil { - return err - } - fi.argConverters = append(fi.argConverters, conv) - } - - if t.IsVariadic() { - conv, err := callbackArg(t.In(numArgs).Elem()) - if err != nil { - return err - } - fi.variadicConverter = conv - // Pass -1 to sqlite so that it allows any number of - // arguments. The call helper verifies that the minimum number - // of arguments is present for variadic functions. - numArgs = -1 - } - - conv, err := callbackRet(t.Out(0)) - if err != nil { - return err - } - fi.retConverter = conv - - // fi must outlast the database connection, or we'll have dangling pointers. - c.funcs = append(c.funcs, &fi) - - cname := C.CString(name) - defer C.free(unsafe.Pointer(cname)) - opts := C.SQLITE_UTF8 - if pure { - opts |= C.SQLITE_DETERMINISTIC - } - rv := C.sqlite3_create_function( - c.db, - cname, - C.int(numArgs), - C.int(opts), - newHandle(c, &fi), - (*[0]byte)(C.callbackTrampoline), - nil, - nil, - ) - if rv != C.SQLITE_OK { - return c.lastError() - } - return nil -} - // RegisterAggregator makes a Go type available as a SQLite aggregation function. // // Because aggregation is incremental, it's implemented in Go with a @@ -2979,49 +2894,6 @@ func (c *SQLiteConn) Deserialize(b []byte, schema string) error { return nil } -type unlock_notify_table struct { - sync.Mutex - seqnum uint - table map[uint]chan struct{} -} - -var unt unlock_notify_table = unlock_notify_table{table: make(map[uint]chan struct{})} - -func (t *unlock_notify_table) add(c chan struct{}) uint { - t.Lock() - defer t.Unlock() - h := t.seqnum - t.table[h] = c - t.seqnum++ - return h -} - -func (t *unlock_notify_table) remove(h uint) { - t.Lock() - defer t.Unlock() - delete(t.table, h) -} - -func (t *unlock_notify_table) get(h uint) chan struct{} { - t.Lock() - defer t.Unlock() - c, ok := t.table[h] - if !ok { - panic(fmt.Sprintf("Non-existent key for unlcok-notify channel: %d", h)) - } - return c -} - -func unlock_notify_callback(argv unsafe.Pointer, argc C.int) { - for i := 0; i < int(argc); i++ { - parg := ((*(*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.uint)(nil))]*[1]uint)(argv))[i]) - arg := *parg - h := arg[0] - c := unt.get(h) - c <- struct{}{} - } -} - // Op is type of operations. type Op uint8 |
