1 /* 2 ** 2020-01-08 3 ** 4 ** The author disclaims copyright to this source code. In place of 5 ** a legal notice, here is a blessing: 6 ** 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. 10 ** 11 ****************************************************************************** 12 ** 13 ** This SQLite extension implements a noop() function used for testing. 14 ** 15 ** Variants: 16 ** 17 ** noop(X) The default. Deterministic. 18 ** noop_i(X) Deterministic and innocuous. 19 ** noop_do(X) Deterministic and direct-only. 20 ** noop_nd(X) Non-deterministic. 21 */ 22 #include "sqlite3ext.h" 23 SQLITE_EXTENSION_INIT1 24 #include <assert.h> 25 #include <string.h> 26 27 /* 28 ** Implementation of the noop() function. 29 ** 30 ** The function returns its argument, unchanged. 31 */ 32 static void noopfunc( 33 sqlite3_context *context, 34 int argc, 35 sqlite3_value **argv 36 ){ 37 assert( argc==1 ); 38 sqlite3_result_value(context, argv[0]); 39 } 40 41 #ifdef _WIN32 42 __declspec(dllexport) 43 #endif 44 int sqlite3_noop_init( 45 sqlite3 *db, 46 char **pzErrMsg, 47 const sqlite3_api_routines *pApi 48 ){ 49 int rc = SQLITE_OK; 50 SQLITE_EXTENSION_INIT2(pApi); 51 (void)pzErrMsg; /* Unused parameter */ 52 rc = sqlite3_create_function(db, "noop", 1, 53 SQLITE_UTF8 | SQLITE_DETERMINISTIC, 54 0, noopfunc, 0, 0); 55 if( rc ) return rc; 56 rc = sqlite3_create_function(db, "noop_i", 1, 57 SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_INNOCUOUS, 58 0, noopfunc, 0, 0); 59 if( rc ) return rc; 60 rc = sqlite3_create_function(db, "noop_do", 1, 61 SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_DIRECTONLY, 62 0, noopfunc, 0, 0); 63 if( rc ) return rc; 64 rc = sqlite3_create_function(db, "noop_nd", 1, 65 SQLITE_UTF8, 66 0, noopfunc, 0, 0); 67 return rc; 68 } 69