Skip to content

Commit a6f9c55

Browse files
committed
Make arguments of register keyword only.
name, nargs and isdeterm are now keyword only.
1 parent 927a556 commit a6f9c55

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

src/SQLite.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function SQLiteDB(file::AbstractString="";UTF16::Bool=false)
5454
file = isempty(file) ? file : expanduser(file)
5555
if @OK sqliteopen(utf(file),handle)
5656
db = SQLiteDB(utf(file),handle[1])
57-
register(db, regexp, 2)
57+
register(db, regexp, nargs=2)
5858
finalizer(db,close)
5959
return db
6060
else # error

src/UDF.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,8 @@ end
6161
macro register(db, func)
6262
:(register($(esc(db)), $(esc(func))))
6363
end
64-
# User-facing method with keyword arguments for registering a function
65-
# to be used within SQLite
66-
function register(db::SQLiteDB, func::Function; nargs::Int=-1, isdeterm::Bool=true, name::String=string(func))
67-
register(db, func, nargs, isdeterm, name)
68-
end
6964
# User-facing method for registering a Julia function to be used within SQLite
70-
function register(db::SQLiteDB, func::Function, nargs::Int=-1, isdeterm::Bool=true, name::String=string(func))
65+
function register(db::SQLiteDB, func::Function; nargs::Int=-1, name::AbstractString=string(func), isdeterm::Bool=true)
7166
@assert nargs <= 127 "use -1 if > 127 arguments are needed"
7267
# assume any negative number means a varargs function
7368
nargs < -1 && (nargs = -1)
@@ -86,6 +81,6 @@ function register(db::SQLiteDB, func::Function, nargs::Int=-1, isdeterm::Bool=tr
8681
end
8782

8883
# annotate types because the MethodError makes more sense that way
89-
regexp(r::String, s::String) = ismatch(Regex(r), s)
84+
regexp(r::AbstractString, s::AbstractString) = ismatch(Regex(r), s)
9085
# macro for preserving the special characters in a string
9186
macro sr_str(s) s end

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ r = query(db, sr"SELECT LastName FROM Employee WHERE BirthDate REGEXP '^\d{4}-08
131131
@test r.values[1][1] == "Peacock"
132132

133133
triple(x) = x * 3
134-
@test_throws ErrorException SQLite.register(db, triple, 186)
135-
SQLite.register(db, triple, 1)
134+
@test_throws ErrorException SQLite.register(db, triple, nargs=186)
135+
SQLite.register(db, triple, nargs=1)
136136
r = query(db, "SELECT triple(Total) FROM Invoice ORDER BY InvoiceId LIMIT 5")
137137
s = query(db, "SELECT Total FROM Invoice ORDER BY InvoiceId LIMIT 5")
138138
for (i, j) in zip(r.values[1], s.values[1])

0 commit comments

Comments
 (0)