39 lines
654 B
C
39 lines
654 B
C
#include <sqlite3ext.h>
|
|
|
|
SQLITE_EXTENSION_INIT1
|
|
|
|
static void add_func(
|
|
sqlite3_context *ctx,
|
|
int argc,
|
|
sqlite3_value **argv
|
|
) {
|
|
if (argc != 2) {
|
|
sqlite3_result_null(ctx);
|
|
return;
|
|
}
|
|
|
|
int a = sqlite3_value_int(argv[0]);
|
|
int b = sqlite3_value_int(argv[1]);
|
|
|
|
sqlite3_result_int(ctx, a + b);
|
|
}
|
|
|
|
int sqlite3_addext_init(
|
|
sqlite3 *db,
|
|
char **pzErrMsg,
|
|
const sqlite3_api_routines *pApi
|
|
) {
|
|
SQLITE_EXTENSION_INIT2(pApi);
|
|
|
|
return sqlite3_create_function(
|
|
db,
|
|
"add",
|
|
2,
|
|
SQLITE_UTF8 | SQLITE_DETERMINISTIC,
|
|
0,
|
|
add_func,
|
|
0,
|
|
0
|
|
);
|
|
}
|