| 1 |
/* |
| 2 |
** This file implements a SQLite extension with multiple entrypoints. |
| 3 |
** |
| 4 |
** The default entrypoint, sqlite3_ext_init, has a single function "a". |
| 5 |
** The 1st alternate entrypoint, sqlite3_ext_b_init, has a single function "b". |
| 6 |
** The 2nd alternate entrypoint, sqlite3_ext_c_init, has a single function "c". |
| 7 |
** |
| 8 |
** Compiling instructions: |
| 9 |
** https://www.sqlite.org/loadext.html#compiling_a_loadable_extension |
| 10 |
** |
| 11 |
*/ |
| 12 |
|
| 13 |
#include "sqlite3ext.h" |
| 14 |
|
| 15 |
SQLITE_EXTENSION_INIT1 |
| 16 |
|
| 17 |
// SQL function that returns back the value supplied during sqlite3_create_function() |
| 18 |
static void func(sqlite3_context *context, int argc, sqlite3_value **argv) { |
| 19 |
sqlite3_result_text(context, (char *) sqlite3_user_data(context), -1, SQLITE_STATIC); |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
// The default entrypoint, since it matches the "ext.dylib"/"ext.so" name |
| 24 |
#ifdef _WIN32 |
| 25 |
__declspec(dllexport) |
| 26 |
#endif |
| 27 |
int sqlite3_ext_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi) { |
| 28 |
SQLITE_EXTENSION_INIT2(pApi); |
| 29 |
return sqlite3_create_function(db, "a", 0, 0, "a", func, 0, 0); |
| 30 |
} |
| 31 |
|
| 32 |
// Alternate entrypoint #1 |
| 33 |
#ifdef _WIN32 |
| 34 |
__declspec(dllexport) |
| 35 |
#endif |
| 36 |
int sqlite3_ext_b_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi) { |
| 37 |
SQLITE_EXTENSION_INIT2(pApi); |
| 38 |
return sqlite3_create_function(db, "b", 0, 0, "b", func, 0, 0); |
| 39 |
} |
| 40 |
|
| 41 |
// Alternate entrypoint #2 |
| 42 |
#ifdef _WIN32 |
| 43 |
__declspec(dllexport) |
| 44 |
#endif |
| 45 |
int sqlite3_ext_c_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi) { |
| 46 |
SQLITE_EXTENSION_INIT2(pApi); |
| 47 |
return sqlite3_create_function(db, "c", 0, 0, "c", func, 0, 0); |
| 48 |
} |