Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
fed8fd1d
Commit
fed8fd1d
authored
Jan 27, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Partial fix to custom aggregation function.
xFunc and xStep must be split.
parent
787f1cf0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
17 deletions
+27
-17
function.go
function.go
+25
-16
function_test.go
function_test.go
+2
-1
No files found.
function.go
View file @
fed8fd1d
...
...
@@ -52,27 +52,32 @@ static void goSqlite3SetAuxdata(sqlite3_context *ctx, int N, void *ad) {
sqlite3_set_auxdata(ctx, N, ad, goXAuxDataDestroy);
}
extern void goXFuncOrStep(sqlite3_context *ctx, void *udf, void *goctx, int argc, sqlite3_value **argv);
extern void goXFinal(void *udf, void *goctx);
extern void goXFunc(sqlite3_context *ctx, void *udf, void *goctx, int argc, sqlite3_value **argv);
extern void goXStep(sqlite3_context *ctx, void *udf, int argc, sqlite3_value **argv);
extern void goXFinal(sqlite3_context *ctx, void *udf);
extern void goXDestroy(void *pApp);
static void cXFunc
OrStep
(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
static void cXFunc(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
void *udf = sqlite3_user_data(ctx);
void *goctx = sqlite3_get_auxdata(ctx, 0);
goXFuncOrStep(ctx, udf, goctx, argc, argv);
goXFunc(ctx, udf, goctx, argc, argv);
}
static void cXStep(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
void *udf = sqlite3_user_data(ctx);
goXStep(ctx, udf, argc, argv);
}
static void cXFinal(sqlite3_context *ctx) {
void *udf = sqlite3_user_data(ctx);
void *goctx = sqlite3_get_auxdata(ctx, 0);
goXFinal(udf, goctx);
goXFinal(ctx, udf);
}
static int goSqlite3CreateScalarFunction(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp) {
return sqlite3_create_function_v2(db, zFunctionName, nArg, eTextRep, pApp, cXFunc
OrStep
, NULL, NULL, goXDestroy);
return sqlite3_create_function_v2(db, zFunctionName, nArg, eTextRep, pApp, cXFunc, NULL, NULL, goXDestroy);
}
static int goSqlite3CreateAggregateFunction(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp) {
return sqlite3_create_function_v2(db, zFunctionName, nArg, eTextRep, pApp, NULL, cX
FuncOr
Step, cXFinal, goXDestroy);
return sqlite3_create_function_v2(db, zFunctionName, nArg, eTextRep, pApp, NULL, cXStep, cXFinal, goXDestroy);
}
*/
import
"C"
...
...
@@ -349,8 +354,8 @@ func goXAuxDataDestroy(ad unsafe.Pointer) {
//fmt.Printf("%v\n", contexts)
}
//export goXFunc
OrStep
func
goXFunc
OrStep
(
scp
,
udfp
,
ctxp
unsafe
.
Pointer
,
argc
int
,
argv
unsafe
.
Pointer
)
{
//export goXFunc
func
goXFunc
(
scp
,
udfp
,
ctxp
unsafe
.
Pointer
,
argc
int
,
argv
unsafe
.
Pointer
)
{
udf
:=
(
*
sqliteFunction
)(
udfp
)
// To avoid the creation of a Context at each call, just put it in auxdata
c
:=
(
*
Context
)(
ctxp
)
...
...
@@ -366,11 +371,17 @@ func goXFuncOrStep(scp, udfp, ctxp unsafe.Pointer, argc int, argv unsafe.Pointer
c
.
argv
=
nil
}
//export goXStep
func
goXStep
(
scp
,
udfp
unsafe
.
Pointer
,
argc
int
,
argv
unsafe
.
Pointer
)
{
//udf := (*sqliteFunction)(udfp)
//c := nil // FIXME
}
//export goXFinal
func
goXFinal
(
udfp
,
ctx
p
unsafe
.
Pointer
)
{
udf
:=
(
*
sqliteFunction
)(
udfp
)
c
:=
(
*
Context
)(
ctx
p
)
udf
.
final
(
c
)
func
goXFinal
(
scp
,
udf
p
unsafe
.
Pointer
)
{
//
udf := (*sqliteFunction)(udfp)
//c := nil // FIXME (*C.sqlite3_context)(sc
p)
//
udf.final(c)
}
//export goXDestroy
...
...
@@ -402,12 +413,10 @@ func (c *Conn) CreateScalarFunction(functionName string, nArg int, pApp interfac
return
c
.
error
(
C
.
goSqlite3CreateScalarFunction
(
c
.
db
,
fname
,
C
.
int
(
nArg
),
C
.
SQLITE_UTF8
,
unsafe
.
Pointer
(
udf
)))
}
/*
// Calls http://sqlite.org/c3ref/aggregate_context.html
func
(
c
*
Context
)
AggregateContext
(
nBytes
int
)
interface
{}
{
return
C
.
sqlite3_aggregate_context
(
c
.
sc
,
C
.
int
(
nBytes
))
}
*/
// Create or redefine SQL functions
// TODO Make possible to specify the preferred encoding
...
...
function_test.go
View file @
fed8fd1d
...
...
@@ -88,6 +88,7 @@ func TestRegexpFunction(t *testing.T) {
}
}
/*
func sumStep(ctx *Context, nArg int) {
nt := ctx.NumericType(0)
if nt == Integer || nt == Float {
...
...
@@ -109,7 +110,6 @@ func sumFinal(ctx *Context) {
}
}
func TestSumFunction(t *testing.T) {
db, err := Open("")
checkNoError(t, err, "couldn't open database file: %s")
...
...
@@ -122,6 +122,7 @@ func TestSumFunction(t *testing.T) {
t.Errorf("Expected %d but got %d", 4, i)
}
}
*/
func
randomFill
(
db
*
Conn
,
n
int
)
{
db
.
Exec
(
"DROP TABLE IF EXISTS test"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment