|
1 |
| -function registerfunc(db, name, nargs, func, step, final, isdeterm) |
2 |
| - #= |
3 |
| - Create a function in the database connection db. |
4 |
| - =# |
5 |
| - if func != C_NULL |
6 |
| - if !(step == final == C_NULL) |
7 |
| - msg = "step and final can not be defined for scalar functions" |
8 |
| - throw(SQLiteException(msg)) |
9 |
| - end |
10 |
| - else |
11 |
| - if step == C_NULL || final == C_NULL |
12 |
| - msg = "both step and final must be defined for aggregate functions" |
13 |
| - throw(SQLiteException(msg)) |
14 |
| - end |
15 |
| - if func != C_NULL |
16 |
| - msg = "func must not be defined for aggregate functions" |
17 |
| - throw(SQLiteException(msg)) |
18 |
| - end |
19 |
| - end |
20 |
| - |
| 1 | +# scalar functions |
| 2 | +function registerfunc(db::SQLiteDB, nargs::Integer, func::Function, isdeterm::Bool=true; name="") |
21 | 3 | @assert (-1 <= nargs <= 127) "nargs must follow the inequality -1 <= nargs <= 127"
|
22 | 4 |
|
23 |
| - cfunc = func == C_NULL ? C_NULL : cfunction( |
24 |
| - func, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}}) |
25 |
| - ) |
26 |
| - cstep = step == C_NULL ? C_NULL : cfunction( |
27 |
| - step, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}}) |
28 |
| - ) |
29 |
| - cfinal = final == C_NULL ? C_NULL : cfunction( |
30 |
| - step, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}}) |
31 |
| - ) |
| 5 | + name = isempty(name) ? string(func) : name::String |
| 6 | + cfunc = cfunction(func, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}})) |
32 | 7 |
|
33 | 8 | # TODO: allow the other encodings
|
34 | 9 | enc = SQLITE_UTF8
|
35 | 10 | enc = isdeterm ? enc | SQLITE_DETERMINISTIC : enc
|
36 | 11 |
|
37 | 12 | @CHECK db sqlite3_create_function_v2(
|
38 |
| - db.handle, name, nargs, enc, C_NULL, cfunc, cstep, cfinal, C_NULL |
| 13 | + db.handle, name, nargs, enc, C_NULL, cfunc, C_NULL, C_NULL, C_NULL |
39 | 14 | )
|
40 | 15 | end
|
41 | 16 |
|
42 |
| -# scalar functions |
43 |
| -function registerfunc(db::SQLiteDB, nargs::Integer, func::Function, |
44 |
| - isdeterm::Bool=true; name="") |
45 |
| - name = isempty(name) ? string(func) : name::String |
46 |
| - registerfunc(db, name, nargs, func, C_NULL, C_NULL, isdeterm) |
47 |
| -end |
48 |
| - |
49 | 17 | # aggregate functions
|
50 |
| -function registerfunc(db::SQLiteDB, nargs::Integer, step::Function, |
51 |
| - final::Function, isdeterm::Bool=true; name="") |
| 18 | +function registerfunc(db::SQLiteDB, nargs::Integer, step::Function, final::Function, isdeterm::Bool=true; name="") |
| 19 | + @assert (-1 <= nargs <= 127) "nargs must follow the inequality -1 <= nargs <= 127" |
| 20 | + |
52 | 21 | name = isempty(name) ? string(step) : name::String
|
53 |
| - registerfunc(db, name, nargs, C_NULL, step, final, isdeterm) |
| 22 | + cstep = cfunction(step, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}})) |
| 23 | + cfinal = cfunction(final, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}})) |
| 24 | + |
| 25 | + # TODO: allow the other encodings |
| 26 | + enc = SQLITE_UTF8 |
| 27 | + enc = isdeterm ? enc | SQLITE_DETERMINISTIC : enc |
| 28 | + |
| 29 | + @CHECK db sqlite3_create_function_v2( |
| 30 | + db.handle, name, nargs, enc, C_NULL, C_NULL, cstep, cfinal, C_NULL |
| 31 | + ) |
54 | 32 | end
|
55 | 33 |
|
56 | 34 | function sqlvalue(values, i)
|
|
0 commit comments