diff options
author | David Anderson <dave@natulte.net> | 2015-08-21 16:34:55 -0700 |
---|---|---|
committer | David Anderson <dave@natulte.net> | 2015-08-21 16:38:23 -0700 |
commit | 566f63a43a314f8dcd758dba8c40dc11edc27a5e (patch) | |
tree | 51068f3eb538f6eb5ace5c326626ca2c322f7c63 /sqlite3_test.go | |
parent | Move argument converters to callback.go, and optimize return value handling. (diff) | |
download | golite-566f63a43a314f8dcd758dba8c40dc11edc27a5e.tar.gz golite-566f63a43a314f8dcd758dba8c40dc11edc27a5e.tar.xz |
Implement support for variadic functions.
Currently, the variadic part must all be the same type, because there's
no "generic" arg converter.
Diffstat (limited to '')
-rw-r--r-- | sqlite3_test.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/sqlite3_test.go b/sqlite3_test.go index e8dfe5c..a563c08 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -1071,6 +1071,13 @@ func TestFunctionRegistration(t *testing.T) { regex := func(re, s string) (bool, error) { return regexp.MatchString(re, s) } + variadic := func(a, b int64, c ...int64) int64 { + ret := a + b + for _, d := range c { + ret += d + } + return ret + } sql.Register("sqlite3_FunctionRegistration", &SQLiteDriver{ ConnectHook: func(conn *SQLiteConn) error { @@ -1098,6 +1105,9 @@ func TestFunctionRegistration(t *testing.T) { if err := conn.RegisterFunc("regex", regex, true); err != nil { return err } + if err := conn.RegisterFunc("variadic", variadic, true); err != nil { + return err + } return nil }, }) @@ -1121,6 +1131,9 @@ func TestFunctionRegistration(t *testing.T) { {"SELECT not(0)", true}, {`SELECT regex("^foo.*", "foobar")`, true}, {`SELECT regex("^foo.*", "barfoobar")`, false}, + {"SELECT variadic(1,2)", int64(3)}, + {"SELECT variadic(1,2,3,4)", int64(10)}, + {"SELECT variadic(1,1,1,1,1,1,1,1,1,1)", int64(10)}, } for _, op := range ops { |