Skip to content

Commit

Permalink
refactor: define - define_free with and without caching
Browse files Browse the repository at this point in the history
  • Loading branch information
nalgeon committed Feb 6, 2023
1 parent 3acf94e commit 954528a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/define/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ int define_eval_init(sqlite3* db);
int define_manage_init(sqlite3* db);
int define_module_init(sqlite3* db);

#endif /* DEFINE_EXTENSION_H */
#endif /* DEFINE_EXTENSION_H */
11 changes: 8 additions & 3 deletions src/define/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ static void define_function(sqlite3_context* ctx, int argc, sqlite3_value** argv
}
}

/*
* No-op as nothing is cached.
*/
static void define_free(sqlite3_context* ctx, int argc, sqlite3_value** argv) {}

// custom cache
#elif DEFINE_CACHE == 2

Expand Down Expand Up @@ -248,7 +253,7 @@ static void define_function(sqlite3_context* ctx, int argc, sqlite3_value** argv
/*
* Frees prepared statements compiled by user-defined functions.
*/
static void free_compiled(sqlite3_context* ctx, int argc, sqlite3_value** argv) {
static void define_free(sqlite3_context* ctx, int argc, sqlite3_value** argv) {
cache_free();
}

Expand Down Expand Up @@ -310,8 +315,8 @@ static int load_functions(sqlite3* db) {
int define_manage_init(sqlite3* db) {
const int flags = SQLITE_UTF8 | SQLITE_DIRECTONLY;
sqlite3_create_function(db, "define", 2, flags, NULL, define_function, NULL, NULL);
sqlite3_create_function(db, "define_free", 0, flags, NULL, free_compiled, NULL, NULL);
sqlite3_create_function(db, "define_free", 0, flags, NULL, define_free, NULL, NULL);
sqlite3_create_function(db, "define_cache", 0, flags, NULL, print_cache, NULL, NULL);
sqlite3_create_function(db, "undefine", 1, flags, NULL, undefine_function, NULL, NULL);
return load_functions(db);
}
}
2 changes: 1 addition & 1 deletion src/define/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,4 @@ static sqlite3_module define_module = {
int define_module_init(sqlite3* db) {
sqlite3_create_module(db, "define", &define_module, NULL);
return SQLITE_OK;
}
}
5 changes: 3 additions & 2 deletions src/sqlite3-define.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ SQLITE_EXTENSION_INIT1
#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_define_init(sqlite3* db, char** pzErrMsg, const sqlite3_api_routines* pApi) {
SQLITE_EXTENSION_INIT2(pApi);
int sqlite3_define_init(sqlite3* db, char** errmsg_ptr, const sqlite3_api_routines* api) {
(void)errmsg_ptr;
SQLITE_EXTENSION_INIT2(api);
int status = define_manage_init(db);
define_eval_init(db);
define_module_init(db);
Expand Down

0 comments on commit 954528a

Please sign in to comment.