1 /*
2  * SQLite3 example extension from wiki
3  * http://www.sqlite.org/cvstrac/wiki?p=LoadableExtensions
4  *
5  * Compile with
6  *   tcc -rdynamic -shared -o samplext.dll samplext.c
7  */
8 
9 #include <sqlite3ext.h>
10 
11 SQLITE_EXTENSION_INIT1
12 
13 /*
14  * The half() SQL function returns half of its input value.
15  */
halfFunc(sqlite3_context * context,int argc,sqlite3_value ** argv)16 static void halfFunc(
17   sqlite3_context *context,
18   int argc,
19   sqlite3_value **argv
20 ){
21   sqlite3_result_double(context, 0.5 * sqlite3_value_double(argv[0]));
22 }
23 
24 /*
25  * SQLite invokes this routine once when it loads the extension.
26  * Create new functions, collating sequences, and virtual table
27  * modules here.  This is usually the only exported symbol in
28  * the shared library.
29  */
sqlite3_extension_init(sqlite3 * db,char ** pzErrMsg,const sqlite3_api_routines * pApi)30 int sqlite3_extension_init(
31   sqlite3 *db,
32   char **pzErrMsg,
33   const sqlite3_api_routines *pApi
34 ){
35   SQLITE_EXTENSION_INIT2(pApi)
36   sqlite3_create_function(db, "half", 1, SQLITE_ANY, 0, halfFunc, 0, 0);
37   return 0;
38 }
39 
40