@@ -35,6 +35,26 @@ sqlreturn(context, val::Vector{UInt8}) = sqlite3_result_blob(context, val)
35
35
sqlreturn (context, val:: Bool ) = sqlreturn (context, int (val))
36
36
sqlreturn (context, val) = sqlreturn (context, sqlserialize (val))
37
37
38
+ # Internal method for generating an SQLite scalar function from
39
+ # a Julia function name
40
+ function scalarfunc (func,fsym= symbol (string (func)))
41
+ # check if name defined in Base so we don't clobber Base methods
42
+ nm = isdefined (Base,fsym) ? :(Base.$ fsym) : fsym
43
+ return quote
44
+ # nm needs to be a symbol or expr, i.e. :sin or :(Base.sin)
45
+ function $ (nm)(context:: Ptr{Void} , nargs:: Cint , values:: Ptr{Ptr{Void}} )
46
+ args = [SQLite. sqlvalue (values, i) for i in 1 : nargs]
47
+ ret = $ (func)(args... )
48
+ SQLite. sqlreturn (context, ret)
49
+ nothing
50
+ end
51
+ end
52
+ end
53
+ function scalarfunc (expr:: Expr )
54
+ f = eval (expr)
55
+ return scalarfunc (f)
56
+ end
57
+
38
58
# convert a bytearray to an int arr[1] is 256^0, arr[2] is 256^1...
39
59
# TODO : would making this a method of convert needlessly pollute the Base namespace?
40
60
function bytestoint (arr:: Vector{UInt8} )
@@ -120,9 +140,6 @@ function finalfunc(init, func, fsym=symbol(string(func)*"_final"))
120
140
nm = isdefined (Base,fsym) ? :(Base.$ fsym) : fsym
121
141
return quote
122
142
function $ (nm)(context:: Ptr{Void} , nargs:: Cint , values:: Ptr{Ptr{Void}} )
123
- # TODO : I don't think arguments are ever passed to this function,
124
- # should we leave them in anyway?
125
- args = [sqlvalue (context, i) for i in 1 : nargs]
126
143
acptr = sqlite3_aggregate_context (context, 0 )
127
144
# step function wasn't run
128
145
if acptr === C_NULL
@@ -145,7 +162,7 @@ function finalfunc(init, func, fsym=symbol(string(func)*"_final"))
145
162
unsafe_copy! (pointer (acvalbuf), valptr, valsize)
146
163
147
164
acval = sqldeserialize (acvalbuf)
148
- ret = $ (func)(acval, args ... )
165
+ ret = $ (func)(acval)
149
166
c_free (valptr)
150
167
sqlreturn (context, ret)
151
168
end
@@ -154,26 +171,6 @@ function finalfunc(init, func, fsym=symbol(string(func)*"_final"))
154
171
end
155
172
end
156
173
157
- # Internal method for generating an SQLite scalar function from
158
- # a Julia function name
159
- function scalarfunc (func,fsym= symbol (string (func)))
160
- # check if name defined in Base so we don't clobber Base methods
161
- nm = isdefined (Base,fsym) ? :(Base.$ fsym) : fsym
162
- return quote
163
- # nm needs to be a symbol or expr, i.e. :sin or :(Base.sin)
164
- function $ (nm)(context:: Ptr{Void} , nargs:: Cint , values:: Ptr{Ptr{Void}} )
165
- args = [SQLite. sqlvalue (values, i) for i in 1 : nargs]
166
- ret = $ (func)(args... )
167
- SQLite. sqlreturn (context, ret)
168
- nothing
169
- end
170
- end
171
- end
172
- function scalarfunc (expr:: Expr )
173
- f = eval (expr)
174
- return scalarfunc (f)
175
- end
176
-
177
174
# User-facing macro for convenience in registering a simple function
178
175
# with no configurations needed
179
176
macro register (db, func)
0 commit comments