LV2: modul zesilovače, dle oficiálního příkladu, ale bez závislosti na Pythonu – stačí gcc a make
2 #include <sqlite3ext.h>
6 * This is just an example – use official documentation: https://www.sqlite.org/loadext.html
9 #define C_API extern "C"
10 #define SQL_FN(functionName) void functionName (sqlite3_context* ctx, int valueCount, sqlite3_value** values)
12 SQLITE_EXTENSION_INIT1
15 * Returns number of values passed to the SQL function.
18 sqlite3_result_int(ctx, valueCount);
22 * Returns current PID (process id).
25 sqlite3_result_int(ctx, getpid());
29 * Returns multiplication of all arguments or zero, if there are no arguments.
32 sqlite3_int64 result = valueCount == 0 ? 0 : 1;
33 for (int i = 0; i < valueCount; i++) result *= sqlite3_value_int64(values[i]);
34 sqlite3_result_int64(ctx, result);
38 * Function name should match the library file name: libdemo.so → sqlite3_demo_init.
39 * Or we can specify different entry point when loading the module.
41 C_API int sqlite3_demo_init(sqlite3* db, char** error, const sqlite3_api_routines* api) {
42 SQLITE_EXTENSION_INIT2(api);
44 sqlite3_create_function(db, "value_count", -1, SQLITE_UTF8, nullptr, valueCount, nullptr, nullptr);
45 sqlite3_create_function(db, "get_pid", 0, SQLITE_UTF8, nullptr, getPID, nullptr, nullptr);
46 sqlite3_create_function(db, "multiply", -1, SQLITE_UTF8, nullptr, multiply, nullptr, nullptr);
47 // -1 = function accepts arbitrary number of arguments