@@ -244,7 +244,7 @@ class Database
244
244
@db = getValue (apiTemp, ' i32' )
245
245
RegisterExtensionFunctions (@db )
246
246
@statements = {} # A list of all prepared statements of the database
247
- @functions = [] # A list of all user function (created by create_function call) of the database
247
+ @functions = {} # A list of all user function of the database (created by create_function call)
248
248
249
249
### Execute an SQL query, ignoring the rows it returns.
250
250
@@ -396,7 +396,8 @@ class Database
396
396
###
397
397
' export ' : ->
398
398
stmt[' free' ]() for _,stmt of @statements
399
- removeFunction (func) for func in @functions
399
+ removeFunction (func) for _,func of @functions
400
+ @functions = {}
400
401
@ handleError sqlite3_close_v2 @db
401
402
binaryDb = FS .readFile @filename , encoding : ' binary'
402
403
@ handleError sqlite3_open @filename , apiTemp
@@ -416,7 +417,8 @@ class Database
416
417
###
417
418
' close ' : ->
418
419
stmt[' free' ]() for _,stmt of @statements
419
- removeFunction (func) for func in @functions
420
+ removeFunction (func) for _,func of @functions
421
+ @functions = {}
420
422
@ handleError sqlite3_close_v2 @db
421
423
FS .unlink ' /' + @filename
422
424
@db = null
@@ -481,9 +483,11 @@ class Database
481
483
switch typeof (result)
482
484
when ' number' then sqlite3_result_double (cx, result)
483
485
when ' string' then sqlite3_result_text (cx, result, - 1 , - 1 )
484
-
486
+ if (name of @functions )
487
+ removeFunction (@functions [name])
488
+ delete @functions [name]
485
489
# Generate a pointer to the wrapped, user defined function, and register with SQLite.
486
490
func_ptr = addFunction (wrapped_func)
487
- @functions . push ( func_ptr);
491
+ @functions [name] = func_ptr
488
492
@ handleError sqlite3_create_function_v2 @db , name, func .length , SQLite .UTF8 , 0 , func_ptr, 0 , 0 , 0
489
493
return @
0 commit comments