4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 *************************************************************************
12 ** Test extension for testing the sqlite3_load_extension() function.
15 #include "sqlite3ext.h"
16 SQLITE_EXTENSION_INIT1
19 ** The half() SQL function returns half of its input value.
22 sqlite3_context
*context
,
26 sqlite3_result_double(context
, 0.5*sqlite3_value_double(argv
[0]));
30 ** SQL functions to call the sqlite3_status function and return results.
32 static void statusFunc(
33 sqlite3_context
*context
,
37 int op
, mx
, cur
, resetFlag
, rc
;
38 if( sqlite3_value_type(argv
[0])==SQLITE_INTEGER
){
39 op
= sqlite3_value_int(argv
[0]);
40 }else if( sqlite3_value_type(argv
[0])==SQLITE_TEXT
){
47 { "MEMORY_USED", SQLITE_STATUS_MEMORY_USED
},
48 { "PAGECACHE_USED", SQLITE_STATUS_PAGECACHE_USED
},
49 { "PAGECACHE_OVERFLOW", SQLITE_STATUS_PAGECACHE_OVERFLOW
},
50 { "SCRATCH_USED", SQLITE_STATUS_SCRATCH_USED
},
51 { "SCRATCH_OVERFLOW", SQLITE_STATUS_SCRATCH_OVERFLOW
},
52 { "MALLOC_SIZE", SQLITE_STATUS_MALLOC_SIZE
},
54 int nOp
= sizeof(aOp
)/sizeof(aOp
[0]);
55 zName
= (const char*)sqlite3_value_text(argv
[0]);
57 if( strcmp(aOp
[i
].zName
, zName
)==0 ){
63 char *zMsg
= sqlite3_mprintf("unknown status property: %s", zName
);
64 sqlite3_result_error(context
, zMsg
, -1);
69 sqlite3_result_error(context
, "unknown status type", -1);
73 resetFlag
= sqlite3_value_int(argv
[1]);
77 rc
= sqlite3_status(op
, &cur
, &mx
, resetFlag
);
79 char *zMsg
= sqlite3_mprintf("sqlite3_status(%d,...) returns %d", op
, rc
);
80 sqlite3_result_error(context
, zMsg
, -1);
85 sqlite3_result_int(context
, mx
);
87 sqlite3_result_int(context
, cur
);
92 ** Extension load function.
97 const sqlite3_api_routines
*pApi
100 SQLITE_EXTENSION_INIT2(pApi
);
101 nErr
|= sqlite3_create_function(db
, "half", 1, SQLITE_ANY
, 0, halfFunc
, 0, 0);
102 nErr
|= sqlite3_create_function(db
, "sqlite3_status", 1, SQLITE_ANY
, 0,
104 nErr
|= sqlite3_create_function(db
, "sqlite3_status", 2, SQLITE_ANY
, 0,
106 return nErr
? SQLITE_ERROR
: SQLITE_OK
;
110 ** Another extension entry point. This one always fails.
112 int testbrokenext_init(
115 const sqlite3_api_routines
*pApi
118 SQLITE_EXTENSION_INIT2(pApi
);
119 zErr
= sqlite3_mprintf("broken!");