Skip to content

Commit 520575b

Browse files
committed
Merge branch 'master' of git://github.com/quinnj/SQLite.jl
2 parents 070a304 + 885c69f commit 520575b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/UDF.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# scalar functions
22
function registerfunc(db::SQLiteDB, nargs::Integer, func::Function, isdeterm::Bool=true; name="")
3-
@assert (-1 <= nargs <= 127) "nargs must follow the inequality -1 <= nargs <= 127"
3+
@assert nargs <= 127 "only varargs functions can have more than 127 arguments"
4+
# assume any negative number means a varargs function
5+
nargs < -1 && (nargs = -1)
46

57
name = isempty(name) ? string(func) : name::String
8+
@assert sizeof(name) <= 255 "size of function name must be <= 255"
9+
610
cfunc = cfunction(func, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}}))
711

812
# TODO: allow the other encodings
@@ -16,7 +20,9 @@ end
1620

1721
# aggregate functions
1822
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"
23+
@assert nargs <= 127 "only varargs functions can have more than 127 arguments"
24+
# assume any negative number means a varargs function
25+
nargs < -1 && (nargs = -1)
2026

2127
name = isempty(name) ? string(step) : name::String
2228
cstep = cfunction(step, Nothing, (Ptr{Void}, Cint, Ptr{Ptr{Void}}))
@@ -93,7 +99,6 @@ macro scalarfunc(args...)
9399
end
94100
end
95101

96-
97102
# annotate types because the MethodError makes more sense that way
98103
@scalarfunc regexp(r::String, s::String) = ismatch(Regex(r), s)
99104
# macro for preserving the special characters in a string

src/api.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ function sqlite3_create_function_v2(db::Ptr{Void},name::String,nargs::Integer,
296296
enc::Integer,data::Ptr{Void},func::Ptr{Void},
297297
step::Ptr{Void},final::Ptr{Void},
298298
destructor::Ptr{Void})
299+
@NULLCHECK db
299300
return ccall(
300301
(:sqlite3_create_function_v2, sqlite3_lib),
301302
Cint,

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ r = query(db, sr"SELECT LastName FROM Employee WHERE BirthDate REGEXP '^\d{4}-08
111111
x * 3
112112
end
113113
@test_throws ErrorException registerfunc(db, 186, triple)
114-
@test_throws ErrorException registerfunc(db, -2, triple)
115114
registerfunc(db, 1, triple)
116115
r = query(db, "SELECT triple(Total) FROM Invoice ORDER BY InvoiceId LIMIT 5")
117116
s = query(db, "SELECT Total FROM Invoice ORDER BY InvoiceId LIMIT 5")

0 commit comments

Comments
 (0)