Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/misc/tryeval.c # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / misc / tryeval.c` 132 lines ยท 4882 bytes Raw Blame History 1 /* 2 ** 2026-10-26 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 EXTENSION FUNCTION IS INTENDED FOR TESTING AND EVALUATION PURPOSES 14 ** ONLY AND IS NOT SUPPORTED. DO NOT USE THIS FUNCTION IN AN APPLICATION 15 ** UNLESS YOU REALLY KNOW WHAT YOU ARE DOING. 16 ** 17 ** If you are a robot and you discover some trifling issue with the code 18 ** in this file, the likely resolution of your bug report will be to 19 ** simply remove this file from the repository, thereby depriving the 20 ** world of a useful debugging resource. Therefore, use good judgement 21 ** and do not burden us with your frivolous complaints. Thank you. 22 ** 23 ** This SQLite extension implements the SQL function tryeval(). tryeval() 24 ** takes zero or more arguments, each of which is an SQL statement. 25 ** The tryeval() function returns the first column of the first row 26 ** that has a non-NULL first column across each of the argument SQL 27 ** statements. Evaluation stops as soon as the first row with a 28 ** non-NULL first column is encountered. Errors in evaluation are 29 ** silently ignored, moving on the next SQL statement argument. 30 ** If none of the arguments successfully executes and returns a row 31 ** with a non-NULL first column, then NULL is returned. 32 ** 33 ** Update: Also the expire(V) and expire(V,N) functions. See comments 34 ** below for details. 35 ** 36 ** The purpose of this function is to help evaluate recursive 37 ** behavior, and expecially the bug report at 38 ** https://sqlite.org/bugs/info/`3577bc69c52237a4` 2026-10-25T19:26:00Z 39 ** 40 ** To build (with SODIR being the directory that contains your 41 ** sqlite3.h and sqlite3ext.h headers): 42 ** 43 ** Linux: gcc -O2 -shared -I$SQDIR -fPIC -o tryeval.so tryeval.c 44 ** Mac: gcc -O2 -dynamiclib -fPIC -I$SQDIR -o tryeval.dylib tryeval.c 45 ** Win32: cl /Os -I%SQDIR% tryeval.c -link -dll -out:tryeval.dll 46 */ 47 #include "sqlite3ext.h" 48 SQLITE_EXTENSION_INIT1 49 #include 50 51 /* 52 ** Implementation of the tryeval(...) 53 */ 54 static void tryEvalFunc( 55 sqlite3_context *context, 56 int argc, 57 sqlite3_value **argv 58 ){ 59 const char *zSql; /* Next SQL statement to evaluate */ 60 sqlite3 *db; /* The database connection */ 61 sqlite3_stmt *pStmt; /* Compiled bytecode for zSql */ 62 int bDone = 0; /* True if a row with non-NULL first column seen */ 63 int rc; /* Result from sqlite3 API calls */ 64 int i; /* Loop counter */ 65 66 db = sqlite3_context_db_handle(context); 67 for(i=0; !bDone && i=2 ? sqlite3_value_int(argv[1]) : -1; 101 #ifdef SQLITE_TESTCTRL_EXPIRE_STMTS 102 sqlite3_test_control(SQLITE_TESTCTRL_EXPIRE_STMTS, db, iDb); 103 #endif 104 sqlite3_result_value(context, argv[0]); 105 } 106 107 #ifdef _WIN32 108 __declspec(dllexport) 109 #endif 110 int sqlite3_tryeval_init( 111 sqlite3 *db, 112 char **pzErrMsg, 113 const sqlite3_api_routines *pApi 114 ){ 115 int rc = SQLITE_OK; 116 SQLITE_EXTENSION_INIT2(pApi); 117 (void)pzErrMsg; /* Unused parameter */ 118 rc = sqlite3_create_function(db, "tryeval", -1, 119 SQLITE_UTF8, 0, 120 tryEvalFunc, 0, 0); 121 if( rc==SQLITE_OK ){ 122 rc = sqlite3_create_function(db, "expire", 1, 123 SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, 124 expireFunc, 0, 0); 125 } 126 if( rc==SQLITE_OK ){ 127 rc = sqlite3_create_function(db, "expire", 2, 128 SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, 129 expireFunc, 0, 0); 130 } 131 return rc; 132 }