Commit f9f92f05 authored by gwenn's avatar gwenn

Adds a user() test function.

parent 85cfd686
......@@ -7,6 +7,7 @@ package sqlite_test
import (
. "github.com/gwenn/gosqlite"
"math/rand"
"os"
"regexp"
"testing"
)
......@@ -93,6 +94,27 @@ func TestRegexpFunction(t *testing.T) {
assert(t, "unexpected reused state", reused)
}
func user(ctx *ScalarContext, nArg int) {
login := os.Getenv("USER")
if len(login) == 0 {
login = "Anonymous"
}
ctx.ResultText(login)
}
func TestUserFunction(t *testing.T) {
db := open(t)
defer db.Close()
err := db.CreateScalarFunction("user", 0, nil, user, nil)
checkNoError(t, err, "couldn't create function: %s")
var name string
err = db.OneValue("select user()", &name)
checkNoError(t, err, "couldn't retrieve result: %s")
assert(t, "unexpected user name: %q", len(name) > 0)
err = db.CreateScalarFunction("user", 1, nil, nil, nil)
checkNoError(t, err, "couldn't destroy function: %s")
}
func sumStep(ctx *AggregateContext, nArg int) {
nt := ctx.NumericType(0)
if nt == Integer || nt == Float {
......
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