drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1 | /* |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 2 | ** 2001 September 15 |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 3 | ** |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 6 | ** |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 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. |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 10 | ** |
| 11 | ************************************************************************* |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 12 | ** Code for testing all sorts of SQLite interfaces. This code |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 13 | ** is not included in the SQLite library. It is used for automated |
| 14 | ** testing of the SQLite library. |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 15 | */ |
| 16 | #include "sqliteInt.h" |
mistachkin | f74b9e0 | 2013-11-26 01:00:31 +0000 | [diff] [blame] | 17 | #if SQLITE_OS_WIN |
| 18 | # include "os_win.h" |
| 19 | #endif |
| 20 | |
dan | d9495cd | 2011-04-27 12:08:04 +0000 | [diff] [blame] | 21 | #include "vdbeInt.h" |
mistachkin | 52b1dbb | 2016-07-28 14:37:04 +0000 | [diff] [blame] | 22 | #if defined(INCLUDE_SQLITE_TCL_H) |
| 23 | # include "sqlite_tcl.h" |
| 24 | #else |
| 25 | # include "tcl.h" |
| 26 | #endif |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
| 29 | |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 30 | /* |
| 31 | ** This is a copy of the first part of the SqliteDb structure in |
| 32 | ** tclsqlite.c. We need it here so that the get_sqlite_pointer routine |
| 33 | ** can extract the sqlite3* pointer from an existing Tcl SQLite |
| 34 | ** connection. |
| 35 | */ |
| 36 | struct SqliteDb { |
| 37 | sqlite3 *db; |
| 38 | }; |
| 39 | |
| 40 | /* |
drh | a315289 | 2007-05-05 11:48:52 +0000 | [diff] [blame] | 41 | ** Convert text generated by the "%p" conversion format back into |
| 42 | ** a pointer. |
| 43 | */ |
| 44 | static int testHexToInt(int h){ |
| 45 | if( h>='0' && h<='9' ){ |
| 46 | return h - '0'; |
| 47 | }else if( h>='a' && h<='f' ){ |
| 48 | return h - 'a' + 10; |
| 49 | }else{ |
| 50 | assert( h>='A' && h<='F' ); |
| 51 | return h - 'A' + 10; |
| 52 | } |
| 53 | } |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 54 | void *sqlite3TestTextToPtr(const char *z){ |
drh | a315289 | 2007-05-05 11:48:52 +0000 | [diff] [blame] | 55 | void *p; |
| 56 | u64 v; |
| 57 | u32 v2; |
| 58 | if( z[0]=='0' && z[1]=='x' ){ |
| 59 | z += 2; |
| 60 | } |
| 61 | v = 0; |
| 62 | while( *z ){ |
| 63 | v = (v<<4) + testHexToInt(*z); |
| 64 | z++; |
| 65 | } |
| 66 | if( sizeof(p)==sizeof(v) ){ |
| 67 | memcpy(&p, &v, sizeof(p)); |
| 68 | }else{ |
| 69 | assert( sizeof(p)==sizeof(v2) ); |
| 70 | v2 = (u32)v; |
| 71 | memcpy(&p, &v2, sizeof(p)); |
| 72 | } |
| 73 | return p; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | /* |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 78 | ** A TCL command that returns the address of the sqlite* pointer |
| 79 | ** for an sqlite connection instance. Bad things happen if the |
| 80 | ** input is not an sqlite connection. |
| 81 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 82 | static int SQLITE_TCLAPI get_sqlite_pointer( |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 83 | void * clientData, |
| 84 | Tcl_Interp *interp, |
| 85 | int objc, |
| 86 | Tcl_Obj *CONST objv[] |
| 87 | ){ |
| 88 | struct SqliteDb *p; |
| 89 | Tcl_CmdInfo cmdInfo; |
| 90 | char zBuf[100]; |
| 91 | if( objc!=2 ){ |
| 92 | Tcl_WrongNumArgs(interp, 1, objv, "SQLITE-CONNECTION"); |
| 93 | return TCL_ERROR; |
| 94 | } |
| 95 | if( !Tcl_GetCommandInfo(interp, Tcl_GetString(objv[1]), &cmdInfo) ){ |
| 96 | Tcl_AppendResult(interp, "command not found: ", |
| 97 | Tcl_GetString(objv[1]), (char*)0); |
| 98 | return TCL_ERROR; |
| 99 | } |
| 100 | p = (struct SqliteDb*)cmdInfo.objClientData; |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 101 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", p->db); |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 102 | Tcl_AppendResult(interp, zBuf, 0); |
| 103 | return TCL_OK; |
| 104 | } |
| 105 | |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 106 | /* |
| 107 | ** Decode a pointer to an sqlite3 object. |
| 108 | */ |
drh | 24b58dd | 2008-07-07 14:50:14 +0000 | [diff] [blame] | 109 | int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){ |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 110 | struct SqliteDb *p; |
| 111 | Tcl_CmdInfo cmdInfo; |
| 112 | if( Tcl_GetCommandInfo(interp, zA, &cmdInfo) ){ |
| 113 | p = (struct SqliteDb*)cmdInfo.objClientData; |
| 114 | *ppDb = p->db; |
| 115 | }else{ |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 116 | *ppDb = (sqlite3*)sqlite3TestTextToPtr(zA); |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 117 | } |
| 118 | return TCL_OK; |
| 119 | } |
| 120 | |
mistachkin | 6b98d67 | 2014-05-30 16:42:35 +0000 | [diff] [blame] | 121 | #if SQLITE_OS_WIN |
| 122 | /* |
| 123 | ** Decode a Win32 HANDLE object. |
| 124 | */ |
| 125 | int getWin32Handle(Tcl_Interp *interp, const char *zA, LPHANDLE phFile){ |
| 126 | *phFile = (HANDLE)sqlite3TestTextToPtr(zA); |
| 127 | return TCL_OK; |
| 128 | } |
| 129 | #endif |
| 130 | |
mistachkin | e84d8d3 | 2013-04-29 03:09:10 +0000 | [diff] [blame] | 131 | extern const char *sqlite3ErrName(int); |
| 132 | #define t1ErrorName sqlite3ErrName |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 133 | |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 134 | /* |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 135 | ** Convert an sqlite3_stmt* into an sqlite3*. This depends on the |
| 136 | ** fact that the sqlite3* is the first field in the Vdbe structure. |
| 137 | */ |
drh | 51942bc | 2005-06-12 22:01:42 +0000 | [diff] [blame] | 138 | #define StmtToDb(X) sqlite3_db_handle(X) |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 139 | |
| 140 | /* |
| 141 | ** Check a return value to make sure it agrees with the results |
| 142 | ** from sqlite3_errcode. |
| 143 | */ |
| 144 | int sqlite3TestErrCode(Tcl_Interp *interp, sqlite3 *db, int rc){ |
drh | b8613ab | 2009-01-19 17:40:12 +0000 | [diff] [blame] | 145 | if( sqlite3_threadsafe()==0 && rc!=SQLITE_MISUSE && rc!=SQLITE_OK |
| 146 | && sqlite3_errcode(db)!=rc ){ |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 147 | char zBuf[200]; |
| 148 | int r2 = sqlite3_errcode(db); |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 149 | sqlite3_snprintf(sizeof(zBuf), zBuf, |
| 150 | "error code %s (%d) does not match sqlite3_errcode %s (%d)", |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 151 | t1ErrorName(rc), rc, t1ErrorName(r2), r2); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 152 | Tcl_ResetResult(interp); |
| 153 | Tcl_AppendResult(interp, zBuf, 0); |
| 154 | return 1; |
| 155 | } |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | /* |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 160 | ** Decode a pointer to an sqlite3_stmt object. |
| 161 | */ |
| 162 | static int getStmtPointer( |
| 163 | Tcl_Interp *interp, |
| 164 | const char *zArg, |
| 165 | sqlite3_stmt **ppStmt |
| 166 | ){ |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 167 | *ppStmt = (sqlite3_stmt*)sqlite3TestTextToPtr(zArg); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 168 | return TCL_OK; |
| 169 | } |
| 170 | |
| 171 | /* |
drh | 7d8085a | 2003-04-26 13:19:38 +0000 | [diff] [blame] | 172 | ** Generate a text representation of a pointer that can be understood |
| 173 | ** by the getDbPointer and getVmPointer routines above. |
| 174 | ** |
| 175 | ** The problem is, on some machines (Solaris) if you do a printf with |
| 176 | ** "%p" you cannot turn around and do a scanf with the same "%p" and |
| 177 | ** get your pointer back. You have to prepend a "0x" before it will |
| 178 | ** work. Or at least that is what is reported to me (drh). But this |
| 179 | ** behavior varies from machine to machine. The solution used her is |
| 180 | ** to test the string right after it is generated to see if it can be |
| 181 | ** understood by scanf, and if not, try prepending an "0x" to see if |
| 182 | ** that helps. If nothing works, a fatal error is generated. |
| 183 | */ |
drh | 64b1bea | 2006-01-15 02:30:57 +0000 | [diff] [blame] | 184 | int sqlite3TestMakePointerStr(Tcl_Interp *interp, char *zPtr, void *p){ |
drh | fe63d1c | 2004-09-08 20:13:04 +0000 | [diff] [blame] | 185 | sqlite3_snprintf(100, zPtr, "%p", p); |
drh | 7d8085a | 2003-04-26 13:19:38 +0000 | [diff] [blame] | 186 | return TCL_OK; |
| 187 | } |
| 188 | |
| 189 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 190 | ** The callback routine for sqlite3_exec_printf(). |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 191 | */ |
| 192 | static int exec_printf_cb(void *pArg, int argc, char **argv, char **name){ |
| 193 | Tcl_DString *str = (Tcl_DString*)pArg; |
| 194 | int i; |
| 195 | |
| 196 | if( Tcl_DStringLength(str)==0 ){ |
| 197 | for(i=0; i<argc; i++){ |
| 198 | Tcl_DStringAppendElement(str, name[i] ? name[i] : "NULL"); |
| 199 | } |
| 200 | } |
| 201 | for(i=0; i<argc; i++){ |
| 202 | Tcl_DStringAppendElement(str, argv[i] ? argv[i] : "NULL"); |
| 203 | } |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | /* |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 208 | ** The I/O tracing callback. |
| 209 | */ |
shane | afdd23a | 2008-05-29 02:57:47 +0000 | [diff] [blame] | 210 | #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE) |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 211 | static FILE *iotrace_file = 0; |
| 212 | static void io_trace_callback(const char *zFormat, ...){ |
| 213 | va_list ap; |
| 214 | va_start(ap, zFormat); |
| 215 | vfprintf(iotrace_file, zFormat, ap); |
| 216 | va_end(ap); |
| 217 | fflush(iotrace_file); |
| 218 | } |
shane | afdd23a | 2008-05-29 02:57:47 +0000 | [diff] [blame] | 219 | #endif |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 220 | |
| 221 | /* |
| 222 | ** Usage: io_trace FILENAME |
| 223 | ** |
| 224 | ** Turn I/O tracing on or off. If FILENAME is not an empty string, |
| 225 | ** I/O tracing begins going into FILENAME. If FILENAME is an empty |
| 226 | ** string, I/O tracing is turned off. |
| 227 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 228 | static int SQLITE_TCLAPI test_io_trace( |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 229 | void *NotUsed, |
| 230 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 231 | int argc, /* Number of arguments */ |
| 232 | char **argv /* Text of each argument */ |
| 233 | ){ |
danielk1977 | 286d2f4 | 2008-05-05 11:33:47 +0000 | [diff] [blame] | 234 | #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE) |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 235 | if( argc!=2 ){ |
| 236 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 237 | " FILENAME\"", 0); |
| 238 | return TCL_ERROR; |
| 239 | } |
| 240 | if( iotrace_file ){ |
| 241 | if( iotrace_file!=stdout && iotrace_file!=stderr ){ |
| 242 | fclose(iotrace_file); |
| 243 | } |
| 244 | iotrace_file = 0; |
mlcreech | 3a00f90 | 2008-03-04 17:45:01 +0000 | [diff] [blame] | 245 | sqlite3IoTrace = 0; |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 246 | } |
| 247 | if( argv[1][0] ){ |
| 248 | if( strcmp(argv[1],"stdout")==0 ){ |
| 249 | iotrace_file = stdout; |
| 250 | }else if( strcmp(argv[1],"stderr")==0 ){ |
| 251 | iotrace_file = stderr; |
| 252 | }else{ |
| 253 | iotrace_file = fopen(argv[1], "w"); |
| 254 | } |
mlcreech | 3a00f90 | 2008-03-04 17:45:01 +0000 | [diff] [blame] | 255 | sqlite3IoTrace = io_trace_callback; |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 256 | } |
danielk1977 | 286d2f4 | 2008-05-05 11:33:47 +0000 | [diff] [blame] | 257 | #endif |
| 258 | return TCL_OK; |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 259 | } |
| 260 | |
dan | afcf9bd | 2014-01-23 14:44:08 +0000 | [diff] [blame] | 261 | /* |
| 262 | ** Usage: clang_sanitize_address |
| 263 | ** |
| 264 | ** Returns true if the program was compiled using clang with the |
| 265 | ** -fsanitize=address switch on the command line. False otherwise. |
drh | 32e1f27 | 2015-01-08 16:47:51 +0000 | [diff] [blame] | 266 | ** |
| 267 | ** Also return true if the OMIT_MISUSE environment variable exists. |
dan | afcf9bd | 2014-01-23 14:44:08 +0000 | [diff] [blame] | 268 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 269 | static int SQLITE_TCLAPI clang_sanitize_address( |
dan | afcf9bd | 2014-01-23 14:44:08 +0000 | [diff] [blame] | 270 | void *NotUsed, |
| 271 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 272 | int argc, /* Number of arguments */ |
| 273 | char **argv /* Text of each argument */ |
| 274 | ){ |
| 275 | int res = 0; |
| 276 | #if defined(__has_feature) |
| 277 | # if __has_feature(address_sanitizer) |
| 278 | res = 1; |
| 279 | # endif |
| 280 | #endif |
drh | 618ee61 | 2015-07-15 18:04:48 +0000 | [diff] [blame] | 281 | #ifdef __SANITIZE_ADDRESS__ |
| 282 | res = 1; |
| 283 | #endif |
drh | 32e1f27 | 2015-01-08 16:47:51 +0000 | [diff] [blame] | 284 | if( res==0 && getenv("OMIT_MISUSE")!=0 ) res = 1; |
dan | afcf9bd | 2014-01-23 14:44:08 +0000 | [diff] [blame] | 285 | Tcl_SetObjResult(interp, Tcl_NewIntObj(res)); |
| 286 | return TCL_OK; |
| 287 | } |
| 288 | |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 289 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 290 | ** Usage: sqlite3_exec_printf DB FORMAT STRING |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 291 | ** |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 292 | ** Invoke the sqlite3_exec_printf() interface using the open database |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 293 | ** DB. The SQL is the string FORMAT. The format string should contain |
| 294 | ** one %s or %q. STRING is the value inserted into %s or %q. |
| 295 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 296 | static int SQLITE_TCLAPI test_exec_printf( |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 297 | void *NotUsed, |
| 298 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 299 | int argc, /* Number of arguments */ |
| 300 | char **argv /* Text of each argument */ |
| 301 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 302 | sqlite3 *db; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 303 | Tcl_DString str; |
| 304 | int rc; |
| 305 | char *zErr = 0; |
drh | 1211de3 | 2004-07-26 12:24:22 +0000 | [diff] [blame] | 306 | char *zSql; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 307 | char zBuf[30]; |
| 308 | if( argc!=4 ){ |
| 309 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 310 | " DB FORMAT STRING", 0); |
| 311 | return TCL_ERROR; |
| 312 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 313 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 314 | Tcl_DStringInit(&str); |
drh | 1211de3 | 2004-07-26 12:24:22 +0000 | [diff] [blame] | 315 | zSql = sqlite3_mprintf(argv[2], argv[3]); |
| 316 | rc = sqlite3_exec(db, zSql, exec_printf_cb, &str, &zErr); |
| 317 | sqlite3_free(zSql); |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 318 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", rc); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 319 | Tcl_AppendElement(interp, zBuf); |
| 320 | Tcl_AppendElement(interp, rc==SQLITE_OK ? Tcl_DStringValue(&str) : zErr); |
| 321 | Tcl_DStringFree(&str); |
danielk1977 | 926aab2 | 2006-06-27 07:34:40 +0000 | [diff] [blame] | 322 | if( zErr ) sqlite3_free(zErr); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 323 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 324 | return TCL_OK; |
| 325 | } |
| 326 | |
| 327 | /* |
drh | 5bd98ae | 2009-01-07 18:24:03 +0000 | [diff] [blame] | 328 | ** Usage: sqlite3_exec_hex DB HEX |
| 329 | ** |
| 330 | ** Invoke the sqlite3_exec() on a string that is obtained by translating |
| 331 | ** HEX into ASCII. Most characters are translated as is. %HH becomes |
| 332 | ** a hex character. |
| 333 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 334 | static int SQLITE_TCLAPI test_exec_hex( |
drh | 5bd98ae | 2009-01-07 18:24:03 +0000 | [diff] [blame] | 335 | void *NotUsed, |
| 336 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 337 | int argc, /* Number of arguments */ |
| 338 | char **argv /* Text of each argument */ |
| 339 | ){ |
| 340 | sqlite3 *db; |
| 341 | Tcl_DString str; |
| 342 | int rc, i, j; |
| 343 | char *zErr = 0; |
| 344 | char *zHex; |
dan | dca9290 | 2015-08-05 08:01:46 +0000 | [diff] [blame] | 345 | char zSql[501]; |
drh | 5bd98ae | 2009-01-07 18:24:03 +0000 | [diff] [blame] | 346 | char zBuf[30]; |
| 347 | if( argc!=3 ){ |
| 348 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 349 | " DB HEX", 0); |
| 350 | return TCL_ERROR; |
| 351 | } |
| 352 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 353 | zHex = argv[2]; |
dan | dca9290 | 2015-08-05 08:01:46 +0000 | [diff] [blame] | 354 | for(i=j=0; i<(sizeof(zSql)-1) && zHex[j]; i++, j++){ |
drh | 5bd98ae | 2009-01-07 18:24:03 +0000 | [diff] [blame] | 355 | if( zHex[j]=='%' && zHex[j+2] && zHex[j+2] ){ |
| 356 | zSql[i] = (testHexToInt(zHex[j+1])<<4) + testHexToInt(zHex[j+2]); |
| 357 | j += 2; |
| 358 | }else{ |
| 359 | zSql[i] = zHex[j]; |
| 360 | } |
| 361 | } |
| 362 | zSql[i] = 0; |
| 363 | Tcl_DStringInit(&str); |
| 364 | rc = sqlite3_exec(db, zSql, exec_printf_cb, &str, &zErr); |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 365 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", rc); |
drh | 5bd98ae | 2009-01-07 18:24:03 +0000 | [diff] [blame] | 366 | Tcl_AppendElement(interp, zBuf); |
| 367 | Tcl_AppendElement(interp, rc==SQLITE_OK ? Tcl_DStringValue(&str) : zErr); |
| 368 | Tcl_DStringFree(&str); |
| 369 | if( zErr ) sqlite3_free(zErr); |
| 370 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
| 371 | return TCL_OK; |
| 372 | } |
| 373 | |
| 374 | /* |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 375 | ** Usage: db_enter DB |
| 376 | ** db_leave DB |
| 377 | ** |
| 378 | ** Enter or leave the mutex on a database connection. |
| 379 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 380 | static int SQLITE_TCLAPI db_enter( |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 381 | void *NotUsed, |
| 382 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 383 | int argc, /* Number of arguments */ |
| 384 | char **argv /* Text of each argument */ |
| 385 | ){ |
| 386 | sqlite3 *db; |
| 387 | if( argc!=2 ){ |
| 388 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 389 | " DB", 0); |
| 390 | return TCL_ERROR; |
| 391 | } |
| 392 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 393 | sqlite3_mutex_enter(db->mutex); |
| 394 | return TCL_OK; |
| 395 | } |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 396 | static int SQLITE_TCLAPI db_leave( |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 397 | void *NotUsed, |
| 398 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 399 | int argc, /* Number of arguments */ |
| 400 | char **argv /* Text of each argument */ |
| 401 | ){ |
| 402 | sqlite3 *db; |
| 403 | if( argc!=2 ){ |
| 404 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 405 | " DB", 0); |
| 406 | return TCL_ERROR; |
| 407 | } |
| 408 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 409 | sqlite3_mutex_leave(db->mutex); |
| 410 | return TCL_OK; |
| 411 | } |
| 412 | |
| 413 | /* |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 414 | ** Usage: sqlite3_exec DB SQL |
| 415 | ** |
| 416 | ** Invoke the sqlite3_exec interface using the open database DB |
| 417 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 418 | static int SQLITE_TCLAPI test_exec( |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 419 | void *NotUsed, |
| 420 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 421 | int argc, /* Number of arguments */ |
| 422 | char **argv /* Text of each argument */ |
| 423 | ){ |
| 424 | sqlite3 *db; |
| 425 | Tcl_DString str; |
| 426 | int rc; |
| 427 | char *zErr = 0; |
drh | 4e5dd85 | 2007-05-15 03:56:49 +0000 | [diff] [blame] | 428 | char *zSql; |
| 429 | int i, j; |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 430 | char zBuf[30]; |
| 431 | if( argc!=3 ){ |
| 432 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 433 | " DB SQL", 0); |
| 434 | return TCL_ERROR; |
| 435 | } |
| 436 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 437 | Tcl_DStringInit(&str); |
drh | 4e5dd85 | 2007-05-15 03:56:49 +0000 | [diff] [blame] | 438 | zSql = sqlite3_mprintf("%s", argv[2]); |
| 439 | for(i=j=0; zSql[i];){ |
| 440 | if( zSql[i]=='%' ){ |
| 441 | zSql[j++] = (testHexToInt(zSql[i+1])<<4) + testHexToInt(zSql[i+2]); |
| 442 | i += 3; |
| 443 | }else{ |
| 444 | zSql[j++] = zSql[i++]; |
| 445 | } |
| 446 | } |
| 447 | zSql[j] = 0; |
| 448 | rc = sqlite3_exec(db, zSql, exec_printf_cb, &str, &zErr); |
| 449 | sqlite3_free(zSql); |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 450 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", rc); |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 451 | Tcl_AppendElement(interp, zBuf); |
| 452 | Tcl_AppendElement(interp, rc==SQLITE_OK ? Tcl_DStringValue(&str) : zErr); |
| 453 | Tcl_DStringFree(&str); |
| 454 | if( zErr ) sqlite3_free(zErr); |
| 455 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
| 456 | return TCL_OK; |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | ** Usage: sqlite3_exec_nr DB SQL |
| 461 | ** |
| 462 | ** Invoke the sqlite3_exec interface using the open database DB. Discard |
| 463 | ** all results |
| 464 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 465 | static int SQLITE_TCLAPI test_exec_nr( |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 466 | void *NotUsed, |
| 467 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 468 | int argc, /* Number of arguments */ |
| 469 | char **argv /* Text of each argument */ |
| 470 | ){ |
| 471 | sqlite3 *db; |
| 472 | int rc; |
| 473 | char *zErr = 0; |
| 474 | if( argc!=3 ){ |
| 475 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 476 | " DB SQL", 0); |
| 477 | return TCL_ERROR; |
| 478 | } |
| 479 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 480 | rc = sqlite3_exec(db, argv[2], 0, 0, &zErr); |
| 481 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
| 482 | return TCL_OK; |
| 483 | } |
| 484 | |
| 485 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 486 | ** Usage: sqlite3_mprintf_z_test SEPARATOR ARG0 ARG1 ... |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 487 | ** |
drh | bc6160b | 2009-04-08 15:45:31 +0000 | [diff] [blame] | 488 | ** Test the %z format of sqlite_mprintf(). Use multiple mprintf() calls to |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 489 | ** concatenate arg0 through argn using separator as the separator. |
| 490 | ** Return the result. |
| 491 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 492 | static int SQLITE_TCLAPI test_mprintf_z( |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 493 | void *NotUsed, |
| 494 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 495 | int argc, /* Number of arguments */ |
| 496 | char **argv /* Text of each argument */ |
| 497 | ){ |
| 498 | char *zResult = 0; |
| 499 | int i; |
| 500 | |
danielk1977 | ca0c897 | 2007-09-01 09:02:53 +0000 | [diff] [blame] | 501 | for(i=2; i<argc && (i==2 || zResult); i++){ |
drh | bc6160b | 2009-04-08 15:45:31 +0000 | [diff] [blame] | 502 | zResult = sqlite3_mprintf("%z%s%s", zResult, argv[1], argv[i]); |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 503 | } |
| 504 | Tcl_AppendResult(interp, zResult, 0); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 505 | sqlite3_free(zResult); |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 506 | return TCL_OK; |
| 507 | } |
| 508 | |
| 509 | /* |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 510 | ** Usage: sqlite3_mprintf_n_test STRING |
| 511 | ** |
drh | bc6160b | 2009-04-08 15:45:31 +0000 | [diff] [blame] | 512 | ** Test the %n format of sqlite_mprintf(). Return the length of the |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 513 | ** input string. |
| 514 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 515 | static int SQLITE_TCLAPI test_mprintf_n( |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 516 | void *NotUsed, |
| 517 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 518 | int argc, /* Number of arguments */ |
| 519 | char **argv /* Text of each argument */ |
| 520 | ){ |
| 521 | char *zStr; |
| 522 | int n = 0; |
drh | bc6160b | 2009-04-08 15:45:31 +0000 | [diff] [blame] | 523 | zStr = sqlite3_mprintf("%s%n", argv[1], &n); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 524 | sqlite3_free(zStr); |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 525 | Tcl_SetObjResult(interp, Tcl_NewIntObj(n)); |
| 526 | return TCL_OK; |
| 527 | } |
| 528 | |
| 529 | /* |
drh | 6885390 | 2007-05-07 11:24:30 +0000 | [diff] [blame] | 530 | ** Usage: sqlite3_snprintf_int SIZE FORMAT INT |
| 531 | ** |
| 532 | ** Test the of sqlite3_snprintf() routine. SIZE is the size of the |
| 533 | ** output buffer in bytes. The maximum size is 100. FORMAT is the |
| 534 | ** format string. INT is a single integer argument. The FORMAT |
| 535 | ** string must require no more than this one integer argument. If |
| 536 | ** You pass in a format string that requires more than one argument, |
| 537 | ** bad things will happen. |
| 538 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 539 | static int SQLITE_TCLAPI test_snprintf_int( |
drh | 6885390 | 2007-05-07 11:24:30 +0000 | [diff] [blame] | 540 | void *NotUsed, |
| 541 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 542 | int argc, /* Number of arguments */ |
| 543 | char **argv /* Text of each argument */ |
| 544 | ){ |
| 545 | char zStr[100]; |
| 546 | int n = atoi(argv[1]); |
drh | 6885390 | 2007-05-07 11:24:30 +0000 | [diff] [blame] | 547 | const char *zFormat = argv[2]; |
| 548 | int a1 = atoi(argv[3]); |
drh | daf276d | 2007-06-15 18:53:14 +0000 | [diff] [blame] | 549 | if( n>sizeof(zStr) ) n = sizeof(zStr); |
drh | 7694574 | 2008-02-19 18:29:07 +0000 | [diff] [blame] | 550 | sqlite3_snprintf(sizeof(zStr), zStr, "abcdefghijklmnopqrstuvwxyz"); |
drh | 6885390 | 2007-05-07 11:24:30 +0000 | [diff] [blame] | 551 | sqlite3_snprintf(n, zStr, zFormat, a1); |
| 552 | Tcl_AppendResult(interp, zStr, 0); |
| 553 | return TCL_OK; |
| 554 | } |
| 555 | |
shane | 8225f5a | 2008-07-31 02:05:04 +0000 | [diff] [blame] | 556 | #ifndef SQLITE_OMIT_GET_TABLE |
| 557 | |
drh | 6885390 | 2007-05-07 11:24:30 +0000 | [diff] [blame] | 558 | /* |
drh | d2b3e23 | 2008-01-23 14:51:49 +0000 | [diff] [blame] | 559 | ** Usage: sqlite3_get_table_printf DB FORMAT STRING ?--no-counts? |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 560 | ** |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 561 | ** Invoke the sqlite3_get_table_printf() interface using the open database |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 562 | ** DB. The SQL is the string FORMAT. The format string should contain |
| 563 | ** one %s or %q. STRING is the value inserted into %s or %q. |
| 564 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 565 | static int SQLITE_TCLAPI test_get_table_printf( |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 566 | void *NotUsed, |
| 567 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 568 | int argc, /* Number of arguments */ |
| 569 | char **argv /* Text of each argument */ |
| 570 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 571 | sqlite3 *db; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 572 | Tcl_DString str; |
| 573 | int rc; |
| 574 | char *zErr = 0; |
mistachkin | 27b2f05 | 2015-01-12 19:49:46 +0000 | [diff] [blame] | 575 | int nRow = 0, nCol = 0; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 576 | char **aResult; |
| 577 | int i; |
| 578 | char zBuf[30]; |
drh | 1211de3 | 2004-07-26 12:24:22 +0000 | [diff] [blame] | 579 | char *zSql; |
drh | d2b3e23 | 2008-01-23 14:51:49 +0000 | [diff] [blame] | 580 | int resCount = -1; |
| 581 | if( argc==5 ){ |
| 582 | if( Tcl_GetInt(interp, argv[4], &resCount) ) return TCL_ERROR; |
| 583 | } |
| 584 | if( argc!=4 && argc!=5 ){ |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 585 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
drh | d2b3e23 | 2008-01-23 14:51:49 +0000 | [diff] [blame] | 586 | " DB FORMAT STRING ?COUNT?", 0); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 587 | return TCL_ERROR; |
| 588 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 589 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 590 | Tcl_DStringInit(&str); |
drh | 1211de3 | 2004-07-26 12:24:22 +0000 | [diff] [blame] | 591 | zSql = sqlite3_mprintf(argv[2],argv[3]); |
drh | d2b3e23 | 2008-01-23 14:51:49 +0000 | [diff] [blame] | 592 | if( argc==5 ){ |
| 593 | rc = sqlite3_get_table(db, zSql, &aResult, 0, 0, &zErr); |
| 594 | }else{ |
| 595 | rc = sqlite3_get_table(db, zSql, &aResult, &nRow, &nCol, &zErr); |
| 596 | resCount = (nRow+1)*nCol; |
| 597 | } |
drh | 1211de3 | 2004-07-26 12:24:22 +0000 | [diff] [blame] | 598 | sqlite3_free(zSql); |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 599 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", rc); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 600 | Tcl_AppendElement(interp, zBuf); |
| 601 | if( rc==SQLITE_OK ){ |
drh | d2b3e23 | 2008-01-23 14:51:49 +0000 | [diff] [blame] | 602 | if( argc==4 ){ |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 603 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", nRow); |
drh | d2b3e23 | 2008-01-23 14:51:49 +0000 | [diff] [blame] | 604 | Tcl_AppendElement(interp, zBuf); |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 605 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", nCol); |
drh | d2b3e23 | 2008-01-23 14:51:49 +0000 | [diff] [blame] | 606 | Tcl_AppendElement(interp, zBuf); |
| 607 | } |
| 608 | for(i=0; i<resCount; i++){ |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 609 | Tcl_AppendElement(interp, aResult[i] ? aResult[i] : "NULL"); |
| 610 | } |
| 611 | }else{ |
| 612 | Tcl_AppendElement(interp, zErr); |
| 613 | } |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 614 | sqlite3_free_table(aResult); |
danielk1977 | 926aab2 | 2006-06-27 07:34:40 +0000 | [diff] [blame] | 615 | if( zErr ) sqlite3_free(zErr); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 616 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 617 | return TCL_OK; |
| 618 | } |
| 619 | |
shane | 8225f5a | 2008-07-31 02:05:04 +0000 | [diff] [blame] | 620 | #endif /* SQLITE_OMIT_GET_TABLE */ |
| 621 | |
drh | af9ff33 | 2002-01-16 21:00:27 +0000 | [diff] [blame] | 622 | |
| 623 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 624 | ** Usage: sqlite3_last_insert_rowid DB |
drh | af9ff33 | 2002-01-16 21:00:27 +0000 | [diff] [blame] | 625 | ** |
| 626 | ** Returns the integer ROWID of the most recent insert. |
| 627 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 628 | static int SQLITE_TCLAPI test_last_rowid( |
drh | af9ff33 | 2002-01-16 21:00:27 +0000 | [diff] [blame] | 629 | void *NotUsed, |
| 630 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 631 | int argc, /* Number of arguments */ |
| 632 | char **argv /* Text of each argument */ |
| 633 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 634 | sqlite3 *db; |
drh | af9ff33 | 2002-01-16 21:00:27 +0000 | [diff] [blame] | 635 | char zBuf[30]; |
| 636 | |
| 637 | if( argc!=2 ){ |
| 638 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB\"", 0); |
| 639 | return TCL_ERROR; |
| 640 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 641 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 642 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", sqlite3_last_insert_rowid(db)); |
drh | af9ff33 | 2002-01-16 21:00:27 +0000 | [diff] [blame] | 643 | Tcl_AppendResult(interp, zBuf, 0); |
| 644 | return SQLITE_OK; |
| 645 | } |
| 646 | |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 647 | /* |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 648 | ** Usage: sqlite3_key DB KEY |
| 649 | ** |
| 650 | ** Set the codec key. |
| 651 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 652 | static int SQLITE_TCLAPI test_key( |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 653 | void *NotUsed, |
| 654 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 655 | int argc, /* Number of arguments */ |
| 656 | char **argv /* Text of each argument */ |
| 657 | ){ |
drh | 32f57d4 | 2016-03-16 01:03:10 +0000 | [diff] [blame] | 658 | #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL) |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 659 | sqlite3 *db; |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 660 | const char *zKey; |
| 661 | int nKey; |
| 662 | if( argc!=3 ){ |
| 663 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 664 | " FILENAME\"", 0); |
| 665 | return TCL_ERROR; |
| 666 | } |
| 667 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 668 | zKey = argv[2]; |
| 669 | nKey = strlen(zKey); |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 670 | sqlite3_key(db, zKey, nKey); |
| 671 | #endif |
| 672 | return TCL_OK; |
| 673 | } |
| 674 | |
| 675 | /* |
| 676 | ** Usage: sqlite3_rekey DB KEY |
| 677 | ** |
| 678 | ** Change the codec key. |
| 679 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 680 | static int SQLITE_TCLAPI test_rekey( |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 681 | void *NotUsed, |
| 682 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 683 | int argc, /* Number of arguments */ |
| 684 | char **argv /* Text of each argument */ |
| 685 | ){ |
drh | caffb1a | 2012-01-30 18:00:31 +0000 | [diff] [blame] | 686 | #ifdef SQLITE_HAS_CODEC |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 687 | sqlite3 *db; |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 688 | const char *zKey; |
| 689 | int nKey; |
| 690 | if( argc!=3 ){ |
| 691 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 692 | " FILENAME\"", 0); |
| 693 | return TCL_ERROR; |
| 694 | } |
| 695 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 696 | zKey = argv[2]; |
| 697 | nKey = strlen(zKey); |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 698 | sqlite3_rekey(db, zKey, nKey); |
| 699 | #endif |
| 700 | return TCL_OK; |
| 701 | } |
| 702 | |
| 703 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 704 | ** Usage: sqlite3_close DB |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 705 | ** |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 706 | ** Closes the database opened by sqlite3_open. |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 707 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 708 | static int SQLITE_TCLAPI sqlite_test_close( |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 709 | void *NotUsed, |
| 710 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 711 | int argc, /* Number of arguments */ |
| 712 | char **argv /* Text of each argument */ |
| 713 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 714 | sqlite3 *db; |
danielk1977 | 96d81f9 | 2004-06-19 03:33:57 +0000 | [diff] [blame] | 715 | int rc; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 716 | if( argc!=2 ){ |
| 717 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 718 | " FILENAME\"", 0); |
| 719 | return TCL_ERROR; |
| 720 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 721 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
danielk1977 | 96d81f9 | 2004-06-19 03:33:57 +0000 | [diff] [blame] | 722 | rc = sqlite3_close(db); |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 723 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 724 | return TCL_OK; |
| 725 | } |
| 726 | |
| 727 | /* |
dan | 617dc86 | 2013-05-16 11:57:28 +0000 | [diff] [blame] | 728 | ** Usage: sqlite3_close_v2 DB |
| 729 | ** |
| 730 | ** Closes the database opened by sqlite3_open. |
| 731 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 732 | static int SQLITE_TCLAPI sqlite_test_close_v2( |
dan | 617dc86 | 2013-05-16 11:57:28 +0000 | [diff] [blame] | 733 | void *NotUsed, |
| 734 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 735 | int argc, /* Number of arguments */ |
| 736 | char **argv /* Text of each argument */ |
| 737 | ){ |
| 738 | sqlite3 *db; |
| 739 | int rc; |
| 740 | if( argc!=2 ){ |
| 741 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 742 | " FILENAME\"", 0); |
| 743 | return TCL_ERROR; |
| 744 | } |
| 745 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 746 | rc = sqlite3_close_v2(db); |
| 747 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
| 748 | return TCL_OK; |
| 749 | } |
| 750 | |
| 751 | /* |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 752 | ** Implementation of the x_coalesce() function. |
| 753 | ** Return the first argument non-NULL argument. |
| 754 | */ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 755 | static void t1_ifnullFunc( |
| 756 | sqlite3_context *context, |
| 757 | int argc, |
| 758 | sqlite3_value **argv |
| 759 | ){ |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 760 | int i; |
| 761 | for(i=0; i<argc; i++){ |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 762 | if( SQLITE_NULL!=sqlite3_value_type(argv[i]) ){ |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 763 | int n = sqlite3_value_bytes(argv[i]); |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 764 | sqlite3_result_text(context, (char*)sqlite3_value_text(argv[i]), |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 765 | n, SQLITE_TRANSIENT); |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 766 | break; |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | /* |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 772 | ** These are test functions. hex8() interprets its argument as |
| 773 | ** UTF8 and returns a hex encoding. hex16le() interprets its argument |
| 774 | ** as UTF16le and returns a hex encoding. |
| 775 | */ |
| 776 | static void hex8Func(sqlite3_context *p, int argc, sqlite3_value **argv){ |
| 777 | const unsigned char *z; |
| 778 | int i; |
| 779 | char zBuf[200]; |
| 780 | z = sqlite3_value_text(argv[0]); |
| 781 | for(i=0; i<sizeof(zBuf)/2 - 2 && z[i]; i++){ |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 782 | sqlite3_snprintf(sizeof(zBuf)-i*2, &zBuf[i*2], "%02x", z[i]); |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 783 | } |
| 784 | zBuf[i*2] = 0; |
| 785 | sqlite3_result_text(p, (char*)zBuf, -1, SQLITE_TRANSIENT); |
| 786 | } |
drh | af30469 | 2007-04-23 23:56:31 +0000 | [diff] [blame] | 787 | #ifndef SQLITE_OMIT_UTF16 |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 788 | static void hex16Func(sqlite3_context *p, int argc, sqlite3_value **argv){ |
| 789 | const unsigned short int *z; |
| 790 | int i; |
| 791 | char zBuf[400]; |
| 792 | z = sqlite3_value_text16(argv[0]); |
| 793 | for(i=0; i<sizeof(zBuf)/4 - 4 && z[i]; i++){ |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 794 | sqlite3_snprintf(sizeof(zBuf)-i*4, &zBuf[i*4],"%04x", z[i]&0xff); |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 795 | } |
| 796 | zBuf[i*4] = 0; |
| 797 | sqlite3_result_text(p, (char*)zBuf, -1, SQLITE_TRANSIENT); |
| 798 | } |
drh | af30469 | 2007-04-23 23:56:31 +0000 | [diff] [blame] | 799 | #endif |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 800 | |
| 801 | /* |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 802 | ** A structure into which to accumulate text. |
| 803 | */ |
| 804 | struct dstr { |
| 805 | int nAlloc; /* Space allocated */ |
| 806 | int nUsed; /* Space used */ |
| 807 | char *z; /* The space */ |
| 808 | }; |
| 809 | |
| 810 | /* |
| 811 | ** Append text to a dstr |
| 812 | */ |
| 813 | static void dstrAppend(struct dstr *p, const char *z, int divider){ |
drh | 83cc139 | 2012-04-19 18:04:28 +0000 | [diff] [blame] | 814 | int n = (int)strlen(z); |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 815 | if( p->nUsed + n + 2 > p->nAlloc ){ |
| 816 | char *zNew; |
| 817 | p->nAlloc = p->nAlloc*2 + n + 200; |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 818 | zNew = sqlite3_realloc(p->z, p->nAlloc); |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 819 | if( zNew==0 ){ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 820 | sqlite3_free(p->z); |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 821 | memset(p, 0, sizeof(*p)); |
| 822 | return; |
| 823 | } |
| 824 | p->z = zNew; |
| 825 | } |
| 826 | if( divider && p->nUsed>0 ){ |
| 827 | p->z[p->nUsed++] = divider; |
| 828 | } |
| 829 | memcpy(&p->z[p->nUsed], z, n+1); |
| 830 | p->nUsed += n; |
| 831 | } |
| 832 | |
| 833 | /* |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 834 | ** Invoked for each callback from sqlite3ExecFunc |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 835 | */ |
| 836 | static int execFuncCallback(void *pData, int argc, char **argv, char **NotUsed){ |
| 837 | struct dstr *p = (struct dstr*)pData; |
| 838 | int i; |
| 839 | for(i=0; i<argc; i++){ |
| 840 | if( argv[i]==0 ){ |
| 841 | dstrAppend(p, "NULL", ' '); |
| 842 | }else{ |
| 843 | dstrAppend(p, argv[i], ' '); |
| 844 | } |
| 845 | } |
| 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | /* |
danielk1977 | e35ee19 | 2004-06-26 09:50:11 +0000 | [diff] [blame] | 850 | ** Implementation of the x_sqlite_exec() function. This function takes |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 851 | ** a single argument and attempts to execute that argument as SQL code. |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 852 | ** This is illegal and should set the SQLITE_MISUSE flag on the database. |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 853 | ** |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 854 | ** 2004-Jan-07: We have changed this to make it legal to call sqlite3_exec() |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 855 | ** from within a function call. |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 856 | ** |
| 857 | ** This routine simulates the effect of having two threads attempt to |
| 858 | ** use the same database at the same time. |
| 859 | */ |
danielk1977 | 51ad0ec | 2004-05-24 12:39:02 +0000 | [diff] [blame] | 860 | static void sqlite3ExecFunc( |
danielk1977 | 0ae8b83 | 2004-05-25 12:05:56 +0000 | [diff] [blame] | 861 | sqlite3_context *context, |
danielk1977 | 51ad0ec | 2004-05-24 12:39:02 +0000 | [diff] [blame] | 862 | int argc, |
| 863 | sqlite3_value **argv |
| 864 | ){ |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 865 | struct dstr x; |
| 866 | memset(&x, 0, sizeof(x)); |
drh | 3752785 | 2006-03-16 16:19:56 +0000 | [diff] [blame] | 867 | (void)sqlite3_exec((sqlite3*)sqlite3_user_data(context), |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 868 | (char*)sqlite3_value_text(argv[0]), |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 869 | execFuncCallback, &x, 0); |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 870 | sqlite3_result_text(context, x.z, x.nUsed, SQLITE_TRANSIENT); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 871 | sqlite3_free(x.z); |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /* |
danielk1977 | d726392 | 2007-02-05 14:21:47 +0000 | [diff] [blame] | 875 | ** Implementation of tkt2213func(), a scalar function that takes exactly |
| 876 | ** one argument. It has two interesting features: |
| 877 | ** |
| 878 | ** * It calls sqlite3_value_text() 3 times on the argument sqlite3_value*. |
| 879 | ** If the three pointers returned are not the same an SQL error is raised. |
| 880 | ** |
drh | 85b623f | 2007-12-13 21:54:09 +0000 | [diff] [blame] | 881 | ** * Otherwise it returns a copy of the text representation of its |
danielk1977 | d726392 | 2007-02-05 14:21:47 +0000 | [diff] [blame] | 882 | ** argument in such a way as the VDBE representation is a Mem* cell |
| 883 | ** with the MEM_Term flag clear. |
| 884 | ** |
| 885 | ** Ticket #2213 can therefore be tested by evaluating the following |
| 886 | ** SQL expression: |
| 887 | ** |
| 888 | ** tkt2213func(tkt2213func('a string')); |
| 889 | */ |
| 890 | static void tkt2213Function( |
| 891 | sqlite3_context *context, |
| 892 | int argc, |
| 893 | sqlite3_value **argv |
| 894 | ){ |
| 895 | int nText; |
| 896 | unsigned char const *zText1; |
| 897 | unsigned char const *zText2; |
| 898 | unsigned char const *zText3; |
| 899 | |
| 900 | nText = sqlite3_value_bytes(argv[0]); |
| 901 | zText1 = sqlite3_value_text(argv[0]); |
| 902 | zText2 = sqlite3_value_text(argv[0]); |
| 903 | zText3 = sqlite3_value_text(argv[0]); |
| 904 | |
| 905 | if( zText1!=zText2 || zText2!=zText3 ){ |
| 906 | sqlite3_result_error(context, "tkt2213 is not fixed", -1); |
| 907 | }else{ |
| 908 | char *zCopy = (char *)sqlite3_malloc(nText); |
| 909 | memcpy(zCopy, zText1, nText); |
| 910 | sqlite3_result_text(context, zCopy, nText, sqlite3_free); |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | /* |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 915 | ** The following SQL function takes 4 arguments. The 2nd and |
| 916 | ** 4th argument must be one of these strings: 'text', 'text16', |
| 917 | ** or 'blob' corresponding to API functions |
| 918 | ** |
| 919 | ** sqlite3_value_text() |
| 920 | ** sqlite3_value_text16() |
| 921 | ** sqlite3_value_blob() |
| 922 | ** |
| 923 | ** The third argument is a string, either 'bytes' or 'bytes16' or 'noop', |
| 924 | ** corresponding to APIs: |
| 925 | ** |
| 926 | ** sqlite3_value_bytes() |
| 927 | ** sqlite3_value_bytes16() |
| 928 | ** noop |
| 929 | ** |
| 930 | ** The APIs designated by the 2nd through 4th arguments are applied |
| 931 | ** to the first argument in order. If the pointers returned by the |
| 932 | ** second and fourth are different, this routine returns 1. Otherwise, |
| 933 | ** this routine returns 0. |
| 934 | ** |
| 935 | ** This function is used to test to see when returned pointers from |
| 936 | ** the _text(), _text16() and _blob() APIs become invalidated. |
| 937 | */ |
| 938 | static void ptrChngFunction( |
| 939 | sqlite3_context *context, |
| 940 | int argc, |
| 941 | sqlite3_value **argv |
| 942 | ){ |
| 943 | const void *p1, *p2; |
| 944 | const char *zCmd; |
| 945 | if( argc!=4 ) return; |
| 946 | zCmd = (const char*)sqlite3_value_text(argv[1]); |
| 947 | if( zCmd==0 ) return; |
| 948 | if( strcmp(zCmd,"text")==0 ){ |
| 949 | p1 = (const void*)sqlite3_value_text(argv[0]); |
| 950 | #ifndef SQLITE_OMIT_UTF16 |
| 951 | }else if( strcmp(zCmd, "text16")==0 ){ |
| 952 | p1 = (const void*)sqlite3_value_text16(argv[0]); |
| 953 | #endif |
| 954 | }else if( strcmp(zCmd, "blob")==0 ){ |
| 955 | p1 = (const void*)sqlite3_value_blob(argv[0]); |
| 956 | }else{ |
| 957 | return; |
| 958 | } |
| 959 | zCmd = (const char*)sqlite3_value_text(argv[2]); |
| 960 | if( zCmd==0 ) return; |
| 961 | if( strcmp(zCmd,"bytes")==0 ){ |
| 962 | sqlite3_value_bytes(argv[0]); |
| 963 | #ifndef SQLITE_OMIT_UTF16 |
| 964 | }else if( strcmp(zCmd, "bytes16")==0 ){ |
| 965 | sqlite3_value_bytes16(argv[0]); |
| 966 | #endif |
| 967 | }else if( strcmp(zCmd, "noop")==0 ){ |
| 968 | /* do nothing */ |
| 969 | }else{ |
| 970 | return; |
| 971 | } |
| 972 | zCmd = (const char*)sqlite3_value_text(argv[3]); |
| 973 | if( zCmd==0 ) return; |
| 974 | if( strcmp(zCmd,"text")==0 ){ |
| 975 | p2 = (const void*)sqlite3_value_text(argv[0]); |
| 976 | #ifndef SQLITE_OMIT_UTF16 |
| 977 | }else if( strcmp(zCmd, "text16")==0 ){ |
| 978 | p2 = (const void*)sqlite3_value_text16(argv[0]); |
| 979 | #endif |
| 980 | }else if( strcmp(zCmd, "blob")==0 ){ |
| 981 | p2 = (const void*)sqlite3_value_blob(argv[0]); |
| 982 | }else{ |
| 983 | return; |
| 984 | } |
| 985 | sqlite3_result_int(context, p1!=p2); |
| 986 | } |
| 987 | |
drh | 4a8ee3d | 2013-12-14 13:44:22 +0000 | [diff] [blame] | 988 | /* |
| 989 | ** This SQL function returns a different answer each time it is called, even if |
| 990 | ** the arguments are the same. |
| 991 | */ |
| 992 | static void nondeterministicFunction( |
| 993 | sqlite3_context *context, |
| 994 | int argc, |
| 995 | sqlite3_value **argv |
| 996 | ){ |
| 997 | static int cnt = 0; |
| 998 | sqlite3_result_int(context, cnt++); |
| 999 | } |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 1000 | |
| 1001 | /* |
drh | 4a8ee3d | 2013-12-14 13:44:22 +0000 | [diff] [blame] | 1002 | ** Usage: sqlite3_create_function DB |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1003 | ** |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1004 | ** Call the sqlite3_create_function API on the given database in order |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1005 | ** to create a function named "x_coalesce". This function does the same thing |
| 1006 | ** as the "coalesce" function. This function also registers an SQL function |
danielk1977 | e35ee19 | 2004-06-26 09:50:11 +0000 | [diff] [blame] | 1007 | ** named "x_sqlite_exec" that invokes sqlite3_exec(). Invoking sqlite3_exec() |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1008 | ** in this way is illegal recursion and should raise an SQLITE_MISUSE error. |
| 1009 | ** The effect is similar to trying to use the same database connection from |
| 1010 | ** two threads at the same time. |
| 1011 | ** |
| 1012 | ** The original motivation for this routine was to be able to call the |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1013 | ** sqlite3_create_function function while a query is in progress in order |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1014 | ** to test the SQLITE_MISUSE detection logic. |
| 1015 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1016 | static int SQLITE_TCLAPI test_create_function( |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1017 | void *NotUsed, |
| 1018 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1019 | int argc, /* Number of arguments */ |
| 1020 | char **argv /* Text of each argument */ |
| 1021 | ){ |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1022 | int rc; |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1023 | sqlite3 *db; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 1024 | |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1025 | if( argc!=2 ){ |
| 1026 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
danielk1977 | 4397de5 | 2005-01-12 12:44:03 +0000 | [diff] [blame] | 1027 | " DB\"", 0); |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1028 | return TCL_ERROR; |
| 1029 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 1030 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
drh | 4a8ee3d | 2013-12-14 13:44:22 +0000 | [diff] [blame] | 1031 | rc = sqlite3_create_function(db, "x_coalesce", -1, SQLITE_UTF8, 0, |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 1032 | t1_ifnullFunc, 0, 0); |
drh | 235a818 | 2006-09-13 19:21:28 +0000 | [diff] [blame] | 1033 | if( rc==SQLITE_OK ){ |
drh | 4a8ee3d | 2013-12-14 13:44:22 +0000 | [diff] [blame] | 1034 | rc = sqlite3_create_function(db, "hex8", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, |
| 1035 | 0, hex8Func, 0, 0); |
drh | 235a818 | 2006-09-13 19:21:28 +0000 | [diff] [blame] | 1036 | } |
drh | af30469 | 2007-04-23 23:56:31 +0000 | [diff] [blame] | 1037 | #ifndef SQLITE_OMIT_UTF16 |
drh | 235a818 | 2006-09-13 19:21:28 +0000 | [diff] [blame] | 1038 | if( rc==SQLITE_OK ){ |
drh | 4a8ee3d | 2013-12-14 13:44:22 +0000 | [diff] [blame] | 1039 | rc = sqlite3_create_function(db, "hex16", 1, SQLITE_UTF16 | SQLITE_DETERMINISTIC, |
| 1040 | 0, hex16Func, 0, 0); |
drh | 235a818 | 2006-09-13 19:21:28 +0000 | [diff] [blame] | 1041 | } |
drh | af30469 | 2007-04-23 23:56:31 +0000 | [diff] [blame] | 1042 | #endif |
danielk1977 | d726392 | 2007-02-05 14:21:47 +0000 | [diff] [blame] | 1043 | if( rc==SQLITE_OK ){ |
| 1044 | rc = sqlite3_create_function(db, "tkt2213func", 1, SQLITE_ANY, 0, |
| 1045 | tkt2213Function, 0, 0); |
| 1046 | } |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 1047 | if( rc==SQLITE_OK ){ |
| 1048 | rc = sqlite3_create_function(db, "pointer_change", 4, SQLITE_ANY, 0, |
| 1049 | ptrChngFunction, 0, 0); |
| 1050 | } |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 1051 | |
drh | 4a8ee3d | 2013-12-14 13:44:22 +0000 | [diff] [blame] | 1052 | /* Functions counter1() and counter2() have the same implementation - they |
| 1053 | ** both return an ascending integer with each call. But counter1() is marked |
| 1054 | ** as non-deterministic and counter2() is marked as deterministic. |
| 1055 | */ |
| 1056 | if( rc==SQLITE_OK ){ |
| 1057 | rc = sqlite3_create_function(db, "counter1", -1, SQLITE_UTF8, |
| 1058 | 0, nondeterministicFunction, 0, 0); |
| 1059 | } |
| 1060 | if( rc==SQLITE_OK ){ |
| 1061 | rc = sqlite3_create_function(db, "counter2", -1, SQLITE_UTF8|SQLITE_DETERMINISTIC, |
| 1062 | 0, nondeterministicFunction, 0, 0); |
| 1063 | } |
| 1064 | |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 1065 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 1066 | /* Use the sqlite3_create_function16() API here. Mainly for fun, but also |
| 1067 | ** because it is not tested anywhere else. */ |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1068 | if( rc==SQLITE_OK ){ |
drh | eee4c8c | 2008-02-18 22:24:57 +0000 | [diff] [blame] | 1069 | const void *zUtf16; |
danielk1977 | 576ec6b | 2005-01-21 11:55:25 +0000 | [diff] [blame] | 1070 | sqlite3_value *pVal; |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 1071 | sqlite3_mutex_enter(db->mutex); |
| 1072 | pVal = sqlite3ValueNew(db); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 1073 | sqlite3ValueSetStr(pVal, -1, "x_sqlite_exec", SQLITE_UTF8, SQLITE_STATIC); |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 1074 | zUtf16 = sqlite3ValueText(pVal, SQLITE_UTF16NATIVE); |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 1075 | if( db->mallocFailed ){ |
| 1076 | rc = SQLITE_NOMEM; |
| 1077 | }else{ |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 1078 | rc = sqlite3_create_function16(db, zUtf16, |
| 1079 | 1, SQLITE_UTF16, db, sqlite3ExecFunc, 0, 0); |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 1080 | } |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1081 | sqlite3ValueFree(pVal); |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 1082 | sqlite3_mutex_leave(db->mutex); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1083 | } |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 1084 | #endif |
| 1085 | |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1086 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 1087 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0); |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1088 | return TCL_OK; |
| 1089 | } |
| 1090 | |
| 1091 | /* |
| 1092 | ** Routines to implement the x_count() aggregate function. |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 1093 | ** |
| 1094 | ** x_count() counts the number of non-null arguments. But there are |
| 1095 | ** some twists for testing purposes. |
| 1096 | ** |
| 1097 | ** If the argument to x_count() is 40 then a UTF-8 error is reported |
| 1098 | ** on the step function. If x_count(41) is seen, then a UTF-16 error |
| 1099 | ** is reported on the step function. If the total count is 42, then |
| 1100 | ** a UTF-8 error is reported on the finalize function. |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1101 | */ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 1102 | typedef struct t1CountCtx t1CountCtx; |
| 1103 | struct t1CountCtx { |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1104 | int n; |
| 1105 | }; |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 1106 | static void t1CountStep( |
| 1107 | sqlite3_context *context, |
| 1108 | int argc, |
| 1109 | sqlite3_value **argv |
| 1110 | ){ |
| 1111 | t1CountCtx *p; |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 1112 | p = sqlite3_aggregate_context(context, sizeof(*p)); |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 1113 | if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0]) ) && p ){ |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1114 | p->n++; |
| 1115 | } |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 1116 | if( argc>0 ){ |
| 1117 | int v = sqlite3_value_int(argv[0]); |
| 1118 | if( v==40 ){ |
| 1119 | sqlite3_result_error(context, "value of 40 handed to x_count", -1); |
danielk1977 | a1686c9 | 2006-01-23 07:52:37 +0000 | [diff] [blame] | 1120 | #ifndef SQLITE_OMIT_UTF16 |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 1121 | }else if( v==41 ){ |
| 1122 | const char zUtf16ErrMsg[] = { 0, 0x61, 0, 0x62, 0, 0x63, 0, 0, 0}; |
| 1123 | sqlite3_result_error16(context, &zUtf16ErrMsg[1-SQLITE_BIGENDIAN], -1); |
danielk1977 | a1686c9 | 2006-01-23 07:52:37 +0000 | [diff] [blame] | 1124 | #endif |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 1125 | } |
| 1126 | } |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1127 | } |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 1128 | static void t1CountFinalize(sqlite3_context *context){ |
| 1129 | t1CountCtx *p; |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 1130 | p = sqlite3_aggregate_context(context, sizeof(*p)); |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 1131 | if( p ){ |
| 1132 | if( p->n==42 ){ |
| 1133 | sqlite3_result_error(context, "x_count totals to 42", -1); |
| 1134 | }else{ |
| 1135 | sqlite3_result_int(context, p ? p->n : 0); |
| 1136 | } |
| 1137 | } |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
danielk1977 | c551288 | 2009-08-10 04:37:49 +0000 | [diff] [blame] | 1140 | #ifndef SQLITE_OMIT_DEPRECATED |
danielk1977 | fa18bec | 2007-09-03 11:04:22 +0000 | [diff] [blame] | 1141 | static void legacyCountStep( |
| 1142 | sqlite3_context *context, |
| 1143 | int argc, |
| 1144 | sqlite3_value **argv |
| 1145 | ){ |
| 1146 | /* no-op */ |
| 1147 | } |
shane | eec556d | 2008-10-12 00:27:53 +0000 | [diff] [blame] | 1148 | |
danielk1977 | fa18bec | 2007-09-03 11:04:22 +0000 | [diff] [blame] | 1149 | static void legacyCountFinalize(sqlite3_context *context){ |
| 1150 | sqlite3_result_int(context, sqlite3_aggregate_count(context)); |
| 1151 | } |
shane | eec556d | 2008-10-12 00:27:53 +0000 | [diff] [blame] | 1152 | #endif |
danielk1977 | fa18bec | 2007-09-03 11:04:22 +0000 | [diff] [blame] | 1153 | |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1154 | /* |
danielk1977 | fa18bec | 2007-09-03 11:04:22 +0000 | [diff] [blame] | 1155 | ** Usage: sqlite3_create_aggregate DB |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1156 | ** |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1157 | ** Call the sqlite3_create_function API on the given database in order |
danielk1977 | fa18bec | 2007-09-03 11:04:22 +0000 | [diff] [blame] | 1158 | ** to create a function named "x_count". This function is similar |
| 1159 | ** to the built-in count() function, with a few special quirks |
| 1160 | ** for testing the sqlite3_result_error() APIs. |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1161 | ** |
| 1162 | ** The original motivation for this routine was to be able to call the |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1163 | ** sqlite3_create_aggregate function while a query is in progress in order |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 1164 | ** to test the SQLITE_MISUSE detection logic. See misuse.test. |
| 1165 | ** |
| 1166 | ** This routine was later extended to test the use of sqlite3_result_error() |
| 1167 | ** within aggregate functions. |
danielk1977 | fa18bec | 2007-09-03 11:04:22 +0000 | [diff] [blame] | 1168 | ** |
| 1169 | ** Later: It is now also extended to register the aggregate function |
| 1170 | ** "legacy_count()" with the supplied database handle. This is used |
| 1171 | ** to test the deprecated sqlite3_aggregate_count() API. |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1172 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1173 | static int SQLITE_TCLAPI test_create_aggregate( |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1174 | void *NotUsed, |
| 1175 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1176 | int argc, /* Number of arguments */ |
| 1177 | char **argv /* Text of each argument */ |
| 1178 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1179 | sqlite3 *db; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1180 | int rc; |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1181 | if( argc!=2 ){ |
| 1182 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1183 | " FILENAME\"", 0); |
| 1184 | return TCL_ERROR; |
| 1185 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 1186 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1187 | rc = sqlite3_create_function(db, "x_count", 0, SQLITE_UTF8, 0, 0, |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 1188 | t1CountStep,t1CountFinalize); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1189 | if( rc==SQLITE_OK ){ |
danielk1977 | fa18bec | 2007-09-03 11:04:22 +0000 | [diff] [blame] | 1190 | rc = sqlite3_create_function(db, "x_count", 1, SQLITE_UTF8, 0, 0, |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 1191 | t1CountStep,t1CountFinalize); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1192 | } |
shane | eec556d | 2008-10-12 00:27:53 +0000 | [diff] [blame] | 1193 | #ifndef SQLITE_OMIT_DEPRECATED |
danielk1977 | fa18bec | 2007-09-03 11:04:22 +0000 | [diff] [blame] | 1194 | if( rc==SQLITE_OK ){ |
| 1195 | rc = sqlite3_create_function(db, "legacy_count", 0, SQLITE_ANY, 0, 0, |
| 1196 | legacyCountStep, legacyCountFinalize |
| 1197 | ); |
| 1198 | } |
shane | eec556d | 2008-10-12 00:27:53 +0000 | [diff] [blame] | 1199 | #endif |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1200 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
danielk1977 | fa18bec | 2007-09-03 11:04:22 +0000 | [diff] [blame] | 1201 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0); |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1202 | return TCL_OK; |
| 1203 | } |
| 1204 | |
| 1205 | |
drh | 3c23a88 | 2007-01-09 14:01:13 +0000 | [diff] [blame] | 1206 | /* |
| 1207 | ** Usage: printf TEXT |
| 1208 | ** |
| 1209 | ** Send output to printf. Use this rather than puts to merge the output |
| 1210 | ** in the correct sequence with debugging printfs inserted into C code. |
| 1211 | ** Puts uses a separate buffer and debugging statements will be out of |
| 1212 | ** sequence if it is used. |
| 1213 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1214 | static int SQLITE_TCLAPI test_printf( |
drh | 3c23a88 | 2007-01-09 14:01:13 +0000 | [diff] [blame] | 1215 | void *NotUsed, |
| 1216 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1217 | int argc, /* Number of arguments */ |
| 1218 | char **argv /* Text of each argument */ |
| 1219 | ){ |
| 1220 | if( argc!=2 ){ |
| 1221 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1222 | " TEXT\"", 0); |
| 1223 | return TCL_ERROR; |
| 1224 | } |
| 1225 | printf("%s\n", argv[1]); |
| 1226 | return TCL_OK; |
| 1227 | } |
| 1228 | |
| 1229 | |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1230 | |
| 1231 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1232 | ** Usage: sqlite3_mprintf_int FORMAT INTEGER INTEGER INTEGER |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1233 | ** |
| 1234 | ** Call mprintf with three integer arguments |
| 1235 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1236 | static int SQLITE_TCLAPI sqlite3_mprintf_int( |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1237 | void *NotUsed, |
| 1238 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1239 | int argc, /* Number of arguments */ |
| 1240 | char **argv /* Text of each argument */ |
| 1241 | ){ |
| 1242 | int a[3], i; |
| 1243 | char *z; |
| 1244 | if( argc!=5 ){ |
| 1245 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1246 | " FORMAT INT INT INT\"", 0); |
| 1247 | return TCL_ERROR; |
| 1248 | } |
| 1249 | for(i=2; i<5; i++){ |
| 1250 | if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; |
| 1251 | } |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1252 | z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1253 | Tcl_AppendResult(interp, z, 0); |
drh | 3f4fedb | 2004-05-31 19:34:33 +0000 | [diff] [blame] | 1254 | sqlite3_free(z); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1255 | return TCL_OK; |
| 1256 | } |
| 1257 | |
| 1258 | /* |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 1259 | ** Usage: sqlite3_mprintf_int64 FORMAT INTEGER INTEGER INTEGER |
| 1260 | ** |
| 1261 | ** Call mprintf with three 64-bit integer arguments |
| 1262 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1263 | static int SQLITE_TCLAPI sqlite3_mprintf_int64( |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 1264 | void *NotUsed, |
| 1265 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1266 | int argc, /* Number of arguments */ |
| 1267 | char **argv /* Text of each argument */ |
| 1268 | ){ |
| 1269 | int i; |
| 1270 | sqlite_int64 a[3]; |
| 1271 | char *z; |
| 1272 | if( argc!=5 ){ |
| 1273 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1274 | " FORMAT INT INT INT\"", 0); |
| 1275 | return TCL_ERROR; |
| 1276 | } |
| 1277 | for(i=2; i<5; i++){ |
drh | 609d584 | 2016-04-28 00:32:16 +0000 | [diff] [blame] | 1278 | if( sqlite3Atoi64(argv[i], &a[i-2], sqlite3Strlen30(argv[i]), SQLITE_UTF8) ){ |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 1279 | Tcl_AppendResult(interp, "argument is not a valid 64-bit integer", 0); |
| 1280 | return TCL_ERROR; |
| 1281 | } |
| 1282 | } |
| 1283 | z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]); |
| 1284 | Tcl_AppendResult(interp, z, 0); |
| 1285 | sqlite3_free(z); |
| 1286 | return TCL_OK; |
| 1287 | } |
| 1288 | |
| 1289 | /* |
drh | c5cad1e | 2009-02-01 00:21:09 +0000 | [diff] [blame] | 1290 | ** Usage: sqlite3_mprintf_long FORMAT INTEGER INTEGER INTEGER |
| 1291 | ** |
| 1292 | ** Call mprintf with three long integer arguments. This might be the |
| 1293 | ** same as sqlite3_mprintf_int or sqlite3_mprintf_int64, depending on |
| 1294 | ** platform. |
| 1295 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1296 | static int SQLITE_TCLAPI sqlite3_mprintf_long( |
drh | c5cad1e | 2009-02-01 00:21:09 +0000 | [diff] [blame] | 1297 | void *NotUsed, |
| 1298 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1299 | int argc, /* Number of arguments */ |
| 1300 | char **argv /* Text of each argument */ |
| 1301 | ){ |
| 1302 | int i; |
| 1303 | long int a[3]; |
| 1304 | int b[3]; |
| 1305 | char *z; |
| 1306 | if( argc!=5 ){ |
| 1307 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1308 | " FORMAT INT INT INT\"", 0); |
| 1309 | return TCL_ERROR; |
| 1310 | } |
| 1311 | for(i=2; i<5; i++){ |
| 1312 | if( Tcl_GetInt(interp, argv[i], &b[i-2]) ) return TCL_ERROR; |
| 1313 | a[i-2] = (long int)b[i-2]; |
drh | 7ed0cae | 2009-02-03 16:25:47 +0000 | [diff] [blame] | 1314 | a[i-2] &= (((u64)1)<<(sizeof(int)*8))-1; |
drh | c5cad1e | 2009-02-01 00:21:09 +0000 | [diff] [blame] | 1315 | } |
| 1316 | z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]); |
| 1317 | Tcl_AppendResult(interp, z, 0); |
| 1318 | sqlite3_free(z); |
| 1319 | return TCL_OK; |
| 1320 | } |
| 1321 | |
| 1322 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1323 | ** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER STRING |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1324 | ** |
| 1325 | ** Call mprintf with two integer arguments and one string argument |
| 1326 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1327 | static int SQLITE_TCLAPI sqlite3_mprintf_str( |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1328 | void *NotUsed, |
| 1329 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1330 | int argc, /* Number of arguments */ |
| 1331 | char **argv /* Text of each argument */ |
| 1332 | ){ |
| 1333 | int a[3], i; |
| 1334 | char *z; |
chw | f220b24 | 2002-06-16 04:54:28 +0000 | [diff] [blame] | 1335 | if( argc<4 || argc>5 ){ |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1336 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
chw | f220b24 | 2002-06-16 04:54:28 +0000 | [diff] [blame] | 1337 | " FORMAT INT INT ?STRING?\"", 0); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1338 | return TCL_ERROR; |
| 1339 | } |
| 1340 | for(i=2; i<4; i++){ |
| 1341 | if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; |
| 1342 | } |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1343 | z = sqlite3_mprintf(argv[1], a[0], a[1], argc>4 ? argv[4] : NULL); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1344 | Tcl_AppendResult(interp, z, 0); |
drh | 3f4fedb | 2004-05-31 19:34:33 +0000 | [diff] [blame] | 1345 | sqlite3_free(z); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1346 | return TCL_OK; |
| 1347 | } |
| 1348 | |
| 1349 | /* |
drh | b3738b6 | 2007-03-31 15:02:49 +0000 | [diff] [blame] | 1350 | ** Usage: sqlite3_snprintf_str INTEGER FORMAT INTEGER INTEGER STRING |
| 1351 | ** |
| 1352 | ** Call mprintf with two integer arguments and one string argument |
| 1353 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1354 | static int SQLITE_TCLAPI sqlite3_snprintf_str( |
drh | b3738b6 | 2007-03-31 15:02:49 +0000 | [diff] [blame] | 1355 | void *NotUsed, |
| 1356 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1357 | int argc, /* Number of arguments */ |
| 1358 | char **argv /* Text of each argument */ |
| 1359 | ){ |
| 1360 | int a[3], i; |
| 1361 | int n; |
| 1362 | char *z; |
| 1363 | if( argc<5 || argc>6 ){ |
| 1364 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1365 | " INT FORMAT INT INT ?STRING?\"", 0); |
| 1366 | return TCL_ERROR; |
| 1367 | } |
| 1368 | if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR; |
| 1369 | if( n<0 ){ |
| 1370 | Tcl_AppendResult(interp, "N must be non-negative", 0); |
| 1371 | return TCL_ERROR; |
| 1372 | } |
| 1373 | for(i=3; i<5; i++){ |
| 1374 | if( Tcl_GetInt(interp, argv[i], &a[i-3]) ) return TCL_ERROR; |
| 1375 | } |
| 1376 | z = sqlite3_malloc( n+1 ); |
| 1377 | sqlite3_snprintf(n, z, argv[2], a[0], a[1], argc>4 ? argv[5] : NULL); |
| 1378 | Tcl_AppendResult(interp, z, 0); |
| 1379 | sqlite3_free(z); |
| 1380 | return TCL_OK; |
| 1381 | } |
| 1382 | |
| 1383 | /* |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 1384 | ** Usage: sqlite3_mprintf_double FORMAT INTEGER INTEGER DOUBLE |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1385 | ** |
| 1386 | ** Call mprintf with two integer arguments and one double argument |
| 1387 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1388 | static int SQLITE_TCLAPI sqlite3_mprintf_double( |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1389 | void *NotUsed, |
| 1390 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1391 | int argc, /* Number of arguments */ |
| 1392 | char **argv /* Text of each argument */ |
| 1393 | ){ |
| 1394 | int a[3], i; |
| 1395 | double r; |
| 1396 | char *z; |
| 1397 | if( argc!=5 ){ |
| 1398 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 1399 | " FORMAT INT INT DOUBLE\"", 0); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1400 | return TCL_ERROR; |
| 1401 | } |
| 1402 | for(i=2; i<4; i++){ |
| 1403 | if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; |
| 1404 | } |
| 1405 | if( Tcl_GetDouble(interp, argv[4], &r) ) return TCL_ERROR; |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1406 | z = sqlite3_mprintf(argv[1], a[0], a[1], r); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1407 | Tcl_AppendResult(interp, z, 0); |
drh | 3f4fedb | 2004-05-31 19:34:33 +0000 | [diff] [blame] | 1408 | sqlite3_free(z); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1409 | return TCL_OK; |
| 1410 | } |
| 1411 | |
| 1412 | /* |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 1413 | ** Usage: sqlite3_mprintf_scaled FORMAT DOUBLE DOUBLE |
drh | b621c23 | 2004-02-21 19:41:04 +0000 | [diff] [blame] | 1414 | ** |
| 1415 | ** Call mprintf with a single double argument which is the product of the |
| 1416 | ** two arguments given above. This is used to generate overflow and underflow |
| 1417 | ** doubles to test that they are converted properly. |
| 1418 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1419 | static int SQLITE_TCLAPI sqlite3_mprintf_scaled( |
drh | b621c23 | 2004-02-21 19:41:04 +0000 | [diff] [blame] | 1420 | void *NotUsed, |
| 1421 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1422 | int argc, /* Number of arguments */ |
| 1423 | char **argv /* Text of each argument */ |
| 1424 | ){ |
| 1425 | int i; |
| 1426 | double r[2]; |
| 1427 | char *z; |
| 1428 | if( argc!=4 ){ |
| 1429 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1430 | " FORMAT DOUBLE DOUBLE\"", 0); |
| 1431 | return TCL_ERROR; |
| 1432 | } |
| 1433 | for(i=2; i<4; i++){ |
| 1434 | if( Tcl_GetDouble(interp, argv[i], &r[i-2]) ) return TCL_ERROR; |
| 1435 | } |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1436 | z = sqlite3_mprintf(argv[1], r[0]*r[1]); |
drh | b621c23 | 2004-02-21 19:41:04 +0000 | [diff] [blame] | 1437 | Tcl_AppendResult(interp, z, 0); |
drh | 3f4fedb | 2004-05-31 19:34:33 +0000 | [diff] [blame] | 1438 | sqlite3_free(z); |
drh | b621c23 | 2004-02-21 19:41:04 +0000 | [diff] [blame] | 1439 | return TCL_OK; |
| 1440 | } |
| 1441 | |
| 1442 | /* |
drh | e29b1a0 | 2004-07-17 21:56:09 +0000 | [diff] [blame] | 1443 | ** Usage: sqlite3_mprintf_stronly FORMAT STRING |
| 1444 | ** |
| 1445 | ** Call mprintf with a single double argument which is the product of the |
| 1446 | ** two arguments given above. This is used to generate overflow and underflow |
| 1447 | ** doubles to test that they are converted properly. |
| 1448 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1449 | static int SQLITE_TCLAPI sqlite3_mprintf_stronly( |
drh | e29b1a0 | 2004-07-17 21:56:09 +0000 | [diff] [blame] | 1450 | void *NotUsed, |
| 1451 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1452 | int argc, /* Number of arguments */ |
| 1453 | char **argv /* Text of each argument */ |
| 1454 | ){ |
| 1455 | char *z; |
| 1456 | if( argc!=3 ){ |
| 1457 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1458 | " FORMAT STRING\"", 0); |
| 1459 | return TCL_ERROR; |
| 1460 | } |
| 1461 | z = sqlite3_mprintf(argv[1], argv[2]); |
| 1462 | Tcl_AppendResult(interp, z, 0); |
| 1463 | sqlite3_free(z); |
| 1464 | return TCL_OK; |
| 1465 | } |
| 1466 | |
| 1467 | /* |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 1468 | ** Usage: sqlite3_mprintf_hexdouble FORMAT HEX |
| 1469 | ** |
| 1470 | ** Call mprintf with a single double argument which is derived from the |
| 1471 | ** hexadecimal encoding of an IEEE double. |
| 1472 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1473 | static int SQLITE_TCLAPI sqlite3_mprintf_hexdouble( |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 1474 | void *NotUsed, |
| 1475 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1476 | int argc, /* Number of arguments */ |
| 1477 | char **argv /* Text of each argument */ |
| 1478 | ){ |
| 1479 | char *z; |
| 1480 | double r; |
shane | 5e73db3 | 2008-07-08 03:04:58 +0000 | [diff] [blame] | 1481 | unsigned int x1, x2; |
| 1482 | sqlite_uint64 d; |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 1483 | if( argc!=3 ){ |
| 1484 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1485 | " FORMAT STRING\"", 0); |
| 1486 | return TCL_ERROR; |
| 1487 | } |
| 1488 | if( sscanf(argv[2], "%08x%08x", &x2, &x1)!=2 ){ |
| 1489 | Tcl_AppendResult(interp, "2nd argument should be 16-characters of hex", 0); |
| 1490 | return TCL_ERROR; |
| 1491 | } |
| 1492 | d = x2; |
| 1493 | d = (d<<32) + x1; |
| 1494 | memcpy(&r, &d, sizeof(r)); |
| 1495 | z = sqlite3_mprintf(argv[1], r); |
| 1496 | Tcl_AppendResult(interp, z, 0); |
| 1497 | sqlite3_free(z); |
| 1498 | return TCL_OK; |
| 1499 | } |
| 1500 | |
| 1501 | /* |
danielk1977 | c1def3e | 2008-08-30 13:25:10 +0000 | [diff] [blame] | 1502 | ** Usage: sqlite3_enable_shared_cache ?BOOLEAN? |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1503 | ** |
| 1504 | */ |
drh | 6f7adc8 | 2006-01-11 21:41:20 +0000 | [diff] [blame] | 1505 | #if !defined(SQLITE_OMIT_SHARED_CACHE) |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1506 | static int SQLITE_TCLAPI test_enable_shared( |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 1507 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1508 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1509 | int objc, /* Number of arguments */ |
| 1510 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1511 | ){ |
| 1512 | int rc; |
| 1513 | int enable; |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 1514 | int ret = 0; |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1515 | |
danielk1977 | c1def3e | 2008-08-30 13:25:10 +0000 | [diff] [blame] | 1516 | if( objc!=2 && objc!=1 ){ |
| 1517 | Tcl_WrongNumArgs(interp, 1, objv, "?BOOLEAN?"); |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1518 | return TCL_ERROR; |
| 1519 | } |
danielk1977 | 502b4e0 | 2008-09-02 14:07:24 +0000 | [diff] [blame] | 1520 | ret = sqlite3GlobalConfig.sharedCacheEnabled; |
danielk1977 | c1def3e | 2008-08-30 13:25:10 +0000 | [diff] [blame] | 1521 | |
| 1522 | if( objc==2 ){ |
| 1523 | if( Tcl_GetBooleanFromObj(interp, objv[1], &enable) ){ |
| 1524 | return TCL_ERROR; |
| 1525 | } |
| 1526 | rc = sqlite3_enable_shared_cache(enable); |
| 1527 | if( rc!=SQLITE_OK ){ |
| 1528 | Tcl_SetResult(interp, (char *)sqlite3ErrStr(rc), TCL_STATIC); |
| 1529 | return TCL_ERROR; |
| 1530 | } |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1531 | } |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 1532 | Tcl_SetObjResult(interp, Tcl_NewBooleanObj(ret)); |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1533 | return TCL_OK; |
| 1534 | } |
| 1535 | #endif |
| 1536 | |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 1537 | |
| 1538 | |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1539 | /* |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 1540 | ** Usage: sqlite3_extended_result_codes DB BOOLEAN |
| 1541 | ** |
| 1542 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1543 | static int SQLITE_TCLAPI test_extended_result_codes( |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 1544 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 1545 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1546 | int objc, /* Number of arguments */ |
| 1547 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1548 | ){ |
| 1549 | int enable; |
| 1550 | sqlite3 *db; |
| 1551 | |
| 1552 | if( objc!=3 ){ |
| 1553 | Tcl_WrongNumArgs(interp, 1, objv, "DB BOOLEAN"); |
| 1554 | return TCL_ERROR; |
| 1555 | } |
| 1556 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 1557 | if( Tcl_GetBooleanFromObj(interp, objv[2], &enable) ) return TCL_ERROR; |
| 1558 | sqlite3_extended_result_codes(db, enable); |
| 1559 | return TCL_OK; |
| 1560 | } |
| 1561 | |
| 1562 | /* |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 1563 | ** Usage: sqlite3_libversion_number |
| 1564 | ** |
| 1565 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1566 | static int SQLITE_TCLAPI test_libversion_number( |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 1567 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 1568 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1569 | int objc, /* Number of arguments */ |
| 1570 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1571 | ){ |
| 1572 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_libversion_number())); |
| 1573 | return TCL_OK; |
| 1574 | } |
| 1575 | |
| 1576 | /* |
danielk1977 | deb802c | 2006-02-09 13:43:28 +0000 | [diff] [blame] | 1577 | ** Usage: sqlite3_table_column_metadata DB dbname tblname colname |
| 1578 | ** |
| 1579 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1580 | static int SQLITE_TCLAPI test_table_column_metadata( |
danielk1977 | deb802c | 2006-02-09 13:43:28 +0000 | [diff] [blame] | 1581 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 1582 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1583 | int objc, /* Number of arguments */ |
| 1584 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1585 | ){ |
| 1586 | sqlite3 *db; |
| 1587 | const char *zDb; |
| 1588 | const char *zTbl; |
| 1589 | const char *zCol; |
| 1590 | int rc; |
| 1591 | Tcl_Obj *pRet; |
| 1592 | |
| 1593 | const char *zDatatype; |
| 1594 | const char *zCollseq; |
| 1595 | int notnull; |
| 1596 | int primarykey; |
| 1597 | int autoincrement; |
| 1598 | |
drh | 45d1b20 | 2014-12-09 22:24:42 +0000 | [diff] [blame] | 1599 | if( objc!=5 && objc!=4 ){ |
danielk1977 | deb802c | 2006-02-09 13:43:28 +0000 | [diff] [blame] | 1600 | Tcl_WrongNumArgs(interp, 1, objv, "DB dbname tblname colname"); |
| 1601 | return TCL_ERROR; |
| 1602 | } |
| 1603 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 1604 | zDb = Tcl_GetString(objv[2]); |
| 1605 | zTbl = Tcl_GetString(objv[3]); |
drh | 45d1b20 | 2014-12-09 22:24:42 +0000 | [diff] [blame] | 1606 | zCol = objc==5 ? Tcl_GetString(objv[4]) : 0; |
danielk1977 | deb802c | 2006-02-09 13:43:28 +0000 | [diff] [blame] | 1607 | |
| 1608 | if( strlen(zDb)==0 ) zDb = 0; |
| 1609 | |
| 1610 | rc = sqlite3_table_column_metadata(db, zDb, zTbl, zCol, |
| 1611 | &zDatatype, &zCollseq, ¬null, &primarykey, &autoincrement); |
| 1612 | |
| 1613 | if( rc!=SQLITE_OK ){ |
| 1614 | Tcl_AppendResult(interp, sqlite3_errmsg(db), 0); |
| 1615 | return TCL_ERROR; |
| 1616 | } |
| 1617 | |
| 1618 | pRet = Tcl_NewObj(); |
| 1619 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zDatatype, -1)); |
| 1620 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zCollseq, -1)); |
| 1621 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(notnull)); |
| 1622 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(primarykey)); |
| 1623 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(autoincrement)); |
| 1624 | Tcl_SetObjResult(interp, pRet); |
| 1625 | |
| 1626 | return TCL_OK; |
| 1627 | } |
danielk1977 | deb802c | 2006-02-09 13:43:28 +0000 | [diff] [blame] | 1628 | |
danielk1977 | dcbb5d3 | 2007-05-04 18:36:44 +0000 | [diff] [blame] | 1629 | #ifndef SQLITE_OMIT_INCRBLOB |
| 1630 | |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1631 | static int SQLITE_TCLAPI blobHandleFromObj( |
dan | 61c7f59 | 2010-10-26 18:42:52 +0000 | [diff] [blame] | 1632 | Tcl_Interp *interp, |
| 1633 | Tcl_Obj *pObj, |
| 1634 | sqlite3_blob **ppBlob |
| 1635 | ){ |
| 1636 | char *z; |
| 1637 | int n; |
| 1638 | |
| 1639 | z = Tcl_GetStringFromObj(pObj, &n); |
| 1640 | if( n==0 ){ |
| 1641 | *ppBlob = 0; |
| 1642 | }else{ |
| 1643 | int notUsed; |
| 1644 | Tcl_Channel channel; |
| 1645 | ClientData instanceData; |
| 1646 | |
| 1647 | channel = Tcl_GetChannel(interp, z, ¬Used); |
| 1648 | if( !channel ) return TCL_ERROR; |
| 1649 | |
| 1650 | Tcl_Flush(channel); |
| 1651 | Tcl_Seek(channel, 0, SEEK_SET); |
| 1652 | |
| 1653 | instanceData = Tcl_GetChannelInstanceData(channel); |
| 1654 | *ppBlob = *((sqlite3_blob **)instanceData); |
| 1655 | } |
| 1656 | |
| 1657 | return TCL_OK; |
| 1658 | } |
| 1659 | |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1660 | static int SQLITE_TCLAPI test_blob_reopen( |
dan | 4e76cc3 | 2010-10-20 18:56:04 +0000 | [diff] [blame] | 1661 | ClientData clientData, /* Not used */ |
| 1662 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1663 | int objc, /* Number of arguments */ |
| 1664 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1665 | ){ |
| 1666 | Tcl_WideInt iRowid; |
dan | 4e76cc3 | 2010-10-20 18:56:04 +0000 | [diff] [blame] | 1667 | sqlite3_blob *pBlob; |
dan | 4e76cc3 | 2010-10-20 18:56:04 +0000 | [diff] [blame] | 1668 | int rc; |
| 1669 | |
dan | 4e76cc3 | 2010-10-20 18:56:04 +0000 | [diff] [blame] | 1670 | if( objc!=3 ){ |
| 1671 | Tcl_WrongNumArgs(interp, 1, objv, "CHANNEL ROWID"); |
| 1672 | return TCL_ERROR; |
| 1673 | } |
| 1674 | |
dan | 61c7f59 | 2010-10-26 18:42:52 +0000 | [diff] [blame] | 1675 | if( blobHandleFromObj(interp, objv[1], &pBlob) ) return TCL_ERROR; |
| 1676 | if( Tcl_GetWideIntFromObj(interp, objv[2], &iRowid) ) return TCL_ERROR; |
dan | 4e76cc3 | 2010-10-20 18:56:04 +0000 | [diff] [blame] | 1677 | |
| 1678 | rc = sqlite3_blob_reopen(pBlob, iRowid); |
| 1679 | if( rc!=SQLITE_OK ){ |
mistachkin | e84d8d3 | 2013-04-29 03:09:10 +0000 | [diff] [blame] | 1680 | Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE); |
dan | 4e76cc3 | 2010-10-20 18:56:04 +0000 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | return (rc==SQLITE_OK ? TCL_OK : TCL_ERROR); |
| 1684 | } |
| 1685 | |
danielk1977 | dcbb5d3 | 2007-05-04 18:36:44 +0000 | [diff] [blame] | 1686 | #endif |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 1687 | |
danielk1977 | deb802c | 2006-02-09 13:43:28 +0000 | [diff] [blame] | 1688 | /* |
danielk1977 | a393c03 | 2007-05-07 14:58:53 +0000 | [diff] [blame] | 1689 | ** Usage: sqlite3_create_collation_v2 DB-HANDLE NAME CMP-PROC DEL-PROC |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 1690 | ** |
| 1691 | ** This Tcl proc is used for testing the experimental |
danielk1977 | a393c03 | 2007-05-07 14:58:53 +0000 | [diff] [blame] | 1692 | ** sqlite3_create_collation_v2() interface. |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 1693 | */ |
| 1694 | struct TestCollationX { |
| 1695 | Tcl_Interp *interp; |
| 1696 | Tcl_Obj *pCmp; |
| 1697 | Tcl_Obj *pDel; |
| 1698 | }; |
| 1699 | typedef struct TestCollationX TestCollationX; |
| 1700 | static void testCreateCollationDel(void *pCtx){ |
| 1701 | TestCollationX *p = (TestCollationX *)pCtx; |
| 1702 | |
| 1703 | int rc = Tcl_EvalObjEx(p->interp, p->pDel, TCL_EVAL_DIRECT|TCL_EVAL_GLOBAL); |
| 1704 | if( rc!=TCL_OK ){ |
| 1705 | Tcl_BackgroundError(p->interp); |
| 1706 | } |
| 1707 | |
| 1708 | Tcl_DecrRefCount(p->pCmp); |
| 1709 | Tcl_DecrRefCount(p->pDel); |
| 1710 | sqlite3_free((void *)p); |
| 1711 | } |
| 1712 | static int testCreateCollationCmp( |
| 1713 | void *pCtx, |
| 1714 | int nLeft, |
| 1715 | const void *zLeft, |
| 1716 | int nRight, |
| 1717 | const void *zRight |
| 1718 | ){ |
| 1719 | TestCollationX *p = (TestCollationX *)pCtx; |
| 1720 | Tcl_Obj *pScript = Tcl_DuplicateObj(p->pCmp); |
| 1721 | int iRes = 0; |
| 1722 | |
| 1723 | Tcl_IncrRefCount(pScript); |
| 1724 | Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj((char *)zLeft, nLeft)); |
| 1725 | Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj((char *)zRight,nRight)); |
| 1726 | |
| 1727 | if( TCL_OK!=Tcl_EvalObjEx(p->interp, pScript, TCL_EVAL_DIRECT|TCL_EVAL_GLOBAL) |
| 1728 | || TCL_OK!=Tcl_GetIntFromObj(p->interp, Tcl_GetObjResult(p->interp), &iRes) |
| 1729 | ){ |
| 1730 | Tcl_BackgroundError(p->interp); |
| 1731 | } |
| 1732 | Tcl_DecrRefCount(pScript); |
| 1733 | |
| 1734 | return iRes; |
| 1735 | } |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1736 | static int SQLITE_TCLAPI test_create_collation_v2( |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 1737 | ClientData clientData, /* Not used */ |
| 1738 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1739 | int objc, /* Number of arguments */ |
| 1740 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1741 | ){ |
| 1742 | TestCollationX *p; |
| 1743 | sqlite3 *db; |
drh | d55d57e | 2008-07-07 17:53:07 +0000 | [diff] [blame] | 1744 | int rc; |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 1745 | |
| 1746 | if( objc!=5 ){ |
| 1747 | Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE NAME CMP-PROC DEL-PROC"); |
| 1748 | return TCL_ERROR; |
| 1749 | } |
| 1750 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 1751 | |
| 1752 | p = (TestCollationX *)sqlite3_malloc(sizeof(TestCollationX)); |
| 1753 | p->pCmp = objv[3]; |
| 1754 | p->pDel = objv[4]; |
| 1755 | p->interp = interp; |
| 1756 | Tcl_IncrRefCount(p->pCmp); |
| 1757 | Tcl_IncrRefCount(p->pDel); |
| 1758 | |
drh | d55d57e | 2008-07-07 17:53:07 +0000 | [diff] [blame] | 1759 | rc = sqlite3_create_collation_v2(db, Tcl_GetString(objv[2]), 16, |
| 1760 | (void *)p, testCreateCollationCmp, testCreateCollationDel |
| 1761 | ); |
| 1762 | if( rc!=SQLITE_MISUSE ){ |
| 1763 | Tcl_AppendResult(interp, "sqlite3_create_collate_v2() failed to detect " |
| 1764 | "an invalid encoding", (char*)0); |
| 1765 | return TCL_ERROR; |
| 1766 | } |
| 1767 | rc = sqlite3_create_collation_v2(db, Tcl_GetString(objv[2]), SQLITE_UTF8, |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 1768 | (void *)p, testCreateCollationCmp, testCreateCollationDel |
| 1769 | ); |
| 1770 | return TCL_OK; |
| 1771 | } |
| 1772 | |
| 1773 | /* |
dan | d2199f0 | 2010-08-27 17:48:52 +0000 | [diff] [blame] | 1774 | ** USAGE: sqlite3_create_function_v2 DB NAME NARG ENC ?SWITCHES? |
| 1775 | ** |
| 1776 | ** Available switches are: |
| 1777 | ** |
| 1778 | ** -func SCRIPT |
| 1779 | ** -step SCRIPT |
| 1780 | ** -final SCRIPT |
| 1781 | ** -destroy SCRIPT |
| 1782 | */ |
| 1783 | typedef struct CreateFunctionV2 CreateFunctionV2; |
| 1784 | struct CreateFunctionV2 { |
| 1785 | Tcl_Interp *interp; |
| 1786 | Tcl_Obj *pFunc; /* Script for function invocation */ |
| 1787 | Tcl_Obj *pStep; /* Script for agg. step invocation */ |
| 1788 | Tcl_Obj *pFinal; /* Script for agg. finalization invocation */ |
| 1789 | Tcl_Obj *pDestroy; /* Destructor script */ |
| 1790 | }; |
| 1791 | static void cf2Func(sqlite3_context *ctx, int nArg, sqlite3_value **aArg){ |
| 1792 | } |
| 1793 | static void cf2Step(sqlite3_context *ctx, int nArg, sqlite3_value **aArg){ |
| 1794 | } |
| 1795 | static void cf2Final(sqlite3_context *ctx){ |
| 1796 | } |
| 1797 | static void cf2Destroy(void *pUser){ |
| 1798 | CreateFunctionV2 *p = (CreateFunctionV2 *)pUser; |
| 1799 | |
| 1800 | if( p->interp && p->pDestroy ){ |
| 1801 | int rc = Tcl_EvalObjEx(p->interp, p->pDestroy, 0); |
| 1802 | if( rc!=TCL_OK ) Tcl_BackgroundError(p->interp); |
| 1803 | } |
| 1804 | |
| 1805 | if( p->pFunc ) Tcl_DecrRefCount(p->pFunc); |
| 1806 | if( p->pStep ) Tcl_DecrRefCount(p->pStep); |
| 1807 | if( p->pFinal ) Tcl_DecrRefCount(p->pFinal); |
| 1808 | if( p->pDestroy ) Tcl_DecrRefCount(p->pDestroy); |
| 1809 | sqlite3_free(p); |
| 1810 | } |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1811 | static int SQLITE_TCLAPI test_create_function_v2( |
dan | d2199f0 | 2010-08-27 17:48:52 +0000 | [diff] [blame] | 1812 | ClientData clientData, /* Not used */ |
| 1813 | Tcl_Interp *interp, /* The invoking TCL interpreter */ |
| 1814 | int objc, /* Number of arguments */ |
| 1815 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1816 | ){ |
| 1817 | sqlite3 *db; |
| 1818 | const char *zFunc; |
| 1819 | int nArg; |
| 1820 | int enc; |
| 1821 | CreateFunctionV2 *p; |
| 1822 | int i; |
| 1823 | int rc; |
| 1824 | |
| 1825 | struct EncTable { |
| 1826 | const char *zEnc; |
| 1827 | int enc; |
| 1828 | } aEnc[] = { |
| 1829 | {"utf8", SQLITE_UTF8 }, |
| 1830 | {"utf16", SQLITE_UTF16 }, |
| 1831 | {"utf16le", SQLITE_UTF16LE }, |
| 1832 | {"utf16be", SQLITE_UTF16BE }, |
| 1833 | {"any", SQLITE_ANY }, |
| 1834 | {"0", 0 } |
| 1835 | }; |
| 1836 | |
| 1837 | if( objc<5 || (objc%2)==0 ){ |
| 1838 | Tcl_WrongNumArgs(interp, 1, objv, "DB NAME NARG ENC SWITCHES..."); |
| 1839 | return TCL_ERROR; |
| 1840 | } |
| 1841 | |
| 1842 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 1843 | zFunc = Tcl_GetString(objv[2]); |
| 1844 | if( Tcl_GetIntFromObj(interp, objv[3], &nArg) ) return TCL_ERROR; |
| 1845 | if( Tcl_GetIndexFromObjStruct(interp, objv[4], aEnc, sizeof(aEnc[0]), |
| 1846 | "encoding", 0, &enc) |
| 1847 | ){ |
| 1848 | return TCL_ERROR; |
| 1849 | } |
| 1850 | enc = aEnc[enc].enc; |
| 1851 | |
| 1852 | p = sqlite3_malloc(sizeof(CreateFunctionV2)); |
| 1853 | assert( p ); |
| 1854 | memset(p, 0, sizeof(CreateFunctionV2)); |
| 1855 | p->interp = interp; |
| 1856 | |
| 1857 | for(i=5; i<objc; i+=2){ |
| 1858 | int iSwitch; |
| 1859 | const char *azSwitch[] = {"-func", "-step", "-final", "-destroy", 0}; |
| 1860 | if( Tcl_GetIndexFromObj(interp, objv[i], azSwitch, "switch", 0, &iSwitch) ){ |
| 1861 | sqlite3_free(p); |
| 1862 | return TCL_ERROR; |
| 1863 | } |
| 1864 | |
| 1865 | switch( iSwitch ){ |
| 1866 | case 0: p->pFunc = objv[i+1]; break; |
| 1867 | case 1: p->pStep = objv[i+1]; break; |
| 1868 | case 2: p->pFinal = objv[i+1]; break; |
| 1869 | case 3: p->pDestroy = objv[i+1]; break; |
| 1870 | } |
| 1871 | } |
| 1872 | if( p->pFunc ) p->pFunc = Tcl_DuplicateObj(p->pFunc); |
| 1873 | if( p->pStep ) p->pStep = Tcl_DuplicateObj(p->pStep); |
| 1874 | if( p->pFinal ) p->pFinal = Tcl_DuplicateObj(p->pFinal); |
| 1875 | if( p->pDestroy ) p->pDestroy = Tcl_DuplicateObj(p->pDestroy); |
| 1876 | |
| 1877 | if( p->pFunc ) Tcl_IncrRefCount(p->pFunc); |
| 1878 | if( p->pStep ) Tcl_IncrRefCount(p->pStep); |
| 1879 | if( p->pFinal ) Tcl_IncrRefCount(p->pFinal); |
| 1880 | if( p->pDestroy ) Tcl_IncrRefCount(p->pDestroy); |
| 1881 | |
| 1882 | rc = sqlite3_create_function_v2(db, zFunc, nArg, enc, (void *)p, |
| 1883 | (p->pFunc ? cf2Func : 0), |
| 1884 | (p->pStep ? cf2Step : 0), |
| 1885 | (p->pFinal ? cf2Final : 0), |
| 1886 | cf2Destroy |
| 1887 | ); |
| 1888 | if( rc!=SQLITE_OK ){ |
dan | d2199f0 | 2010-08-27 17:48:52 +0000 | [diff] [blame] | 1889 | Tcl_ResetResult(interp); |
mistachkin | e84d8d3 | 2013-04-29 03:09:10 +0000 | [diff] [blame] | 1890 | Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); |
dan | d2199f0 | 2010-08-27 17:48:52 +0000 | [diff] [blame] | 1891 | return TCL_ERROR; |
| 1892 | } |
| 1893 | return TCL_OK; |
| 1894 | } |
| 1895 | |
| 1896 | /* |
danielk1977 | 69e777f | 2006-06-14 10:38:02 +0000 | [diff] [blame] | 1897 | ** Usage: sqlite3_load_extension DB-HANDLE FILE ?PROC? |
| 1898 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1899 | static int SQLITE_TCLAPI test_load_extension( |
danielk1977 | 69e777f | 2006-06-14 10:38:02 +0000 | [diff] [blame] | 1900 | ClientData clientData, /* Not used */ |
| 1901 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1902 | int objc, /* Number of arguments */ |
| 1903 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1904 | ){ |
| 1905 | Tcl_CmdInfo cmdInfo; |
| 1906 | sqlite3 *db; |
| 1907 | int rc; |
| 1908 | char *zDb; |
| 1909 | char *zFile; |
| 1910 | char *zProc = 0; |
| 1911 | char *zErr = 0; |
| 1912 | |
| 1913 | if( objc!=4 && objc!=3 ){ |
| 1914 | Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE FILE ?PROC?"); |
| 1915 | return TCL_ERROR; |
| 1916 | } |
| 1917 | zDb = Tcl_GetString(objv[1]); |
| 1918 | zFile = Tcl_GetString(objv[2]); |
| 1919 | if( objc==4 ){ |
| 1920 | zProc = Tcl_GetString(objv[3]); |
| 1921 | } |
| 1922 | |
| 1923 | /* Extract the C database handle from the Tcl command name */ |
| 1924 | if( !Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){ |
| 1925 | Tcl_AppendResult(interp, "command not found: ", zDb, (char*)0); |
| 1926 | return TCL_ERROR; |
| 1927 | } |
| 1928 | db = ((struct SqliteDb*)cmdInfo.objClientData)->db; |
| 1929 | assert(db); |
| 1930 | |
| 1931 | /* Call the underlying C function. If an error occurs, set rc to |
| 1932 | ** TCL_ERROR and load any error string into the interpreter. If no |
| 1933 | ** error occurs, set rc to TCL_OK. |
| 1934 | */ |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 1935 | #ifdef SQLITE_OMIT_LOAD_EXTENSION |
| 1936 | rc = SQLITE_ERROR; |
| 1937 | zErr = sqlite3_mprintf("this build omits sqlite3_load_extension()"); |
drh | 9493caf | 2016-03-17 23:16:37 +0000 | [diff] [blame] | 1938 | (void)zProc; |
| 1939 | (void)zFile; |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 1940 | #else |
danielk1977 | 69e777f | 2006-06-14 10:38:02 +0000 | [diff] [blame] | 1941 | rc = sqlite3_load_extension(db, zFile, zProc, &zErr); |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 1942 | #endif |
danielk1977 | 69e777f | 2006-06-14 10:38:02 +0000 | [diff] [blame] | 1943 | if( rc!=SQLITE_OK ){ |
| 1944 | Tcl_SetResult(interp, zErr ? zErr : "", TCL_VOLATILE); |
| 1945 | rc = TCL_ERROR; |
| 1946 | }else{ |
| 1947 | rc = TCL_OK; |
| 1948 | } |
| 1949 | sqlite3_free(zErr); |
| 1950 | |
| 1951 | return rc; |
| 1952 | } |
| 1953 | |
| 1954 | /* |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 1955 | ** Usage: sqlite3_enable_load_extension DB-HANDLE ONOFF |
| 1956 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 1957 | static int SQLITE_TCLAPI test_enable_load( |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 1958 | ClientData clientData, /* Not used */ |
| 1959 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1960 | int objc, /* Number of arguments */ |
| 1961 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1962 | ){ |
| 1963 | Tcl_CmdInfo cmdInfo; |
| 1964 | sqlite3 *db; |
| 1965 | char *zDb; |
| 1966 | int onoff; |
| 1967 | |
| 1968 | if( objc!=3 ){ |
| 1969 | Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE ONOFF"); |
| 1970 | return TCL_ERROR; |
| 1971 | } |
| 1972 | zDb = Tcl_GetString(objv[1]); |
| 1973 | |
| 1974 | /* Extract the C database handle from the Tcl command name */ |
| 1975 | if( !Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){ |
| 1976 | Tcl_AppendResult(interp, "command not found: ", zDb, (char*)0); |
| 1977 | return TCL_ERROR; |
| 1978 | } |
| 1979 | db = ((struct SqliteDb*)cmdInfo.objClientData)->db; |
| 1980 | assert(db); |
| 1981 | |
| 1982 | /* Get the onoff parameter */ |
| 1983 | if( Tcl_GetBooleanFromObj(interp, objv[2], &onoff) ){ |
| 1984 | return TCL_ERROR; |
| 1985 | } |
| 1986 | |
| 1987 | #ifdef SQLITE_OMIT_LOAD_EXTENSION |
| 1988 | Tcl_AppendResult(interp, "this build omits sqlite3_load_extension()"); |
| 1989 | return TCL_ERROR; |
| 1990 | #else |
| 1991 | sqlite3_enable_load_extension(db, onoff); |
| 1992 | return TCL_OK; |
| 1993 | #endif |
| 1994 | } |
| 1995 | |
| 1996 | /* |
drh | 28b4e48 | 2002-03-11 02:06:13 +0000 | [diff] [blame] | 1997 | ** Usage: sqlite_abort |
| 1998 | ** |
| 1999 | ** Shutdown the process immediately. This is not a clean shutdown. |
| 2000 | ** This command is used to test the recoverability of a database in |
| 2001 | ** the event of a program crash. |
| 2002 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2003 | static int SQLITE_TCLAPI sqlite_abort( |
drh | 28b4e48 | 2002-03-11 02:06:13 +0000 | [diff] [blame] | 2004 | void *NotUsed, |
| 2005 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 2006 | int argc, /* Number of arguments */ |
| 2007 | char **argv /* Text of each argument */ |
| 2008 | ){ |
shaneh | 2ceced1 | 2010-07-07 16:51:36 +0000 | [diff] [blame] | 2009 | #if defined(_MSC_VER) |
| 2010 | /* We do this, otherwise the test will halt with a popup message |
| 2011 | * that we have to click away before the test will continue. |
| 2012 | */ |
| 2013 | _set_abort_behavior( 0, _CALL_REPORTFAULT ); |
| 2014 | #endif |
dan | d3f6b81 | 2010-07-19 12:44:14 +0000 | [diff] [blame] | 2015 | exit(255); |
drh | 28b4e48 | 2002-03-11 02:06:13 +0000 | [diff] [blame] | 2016 | assert( interp==0 ); /* This will always fail */ |
| 2017 | return TCL_OK; |
| 2018 | } |
| 2019 | |
| 2020 | /* |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 2021 | ** The following routine is a user-defined SQL function whose purpose |
| 2022 | ** is to test the sqlite_set_result() API. |
| 2023 | */ |
danielk1977 | 0ae8b83 | 2004-05-25 12:05:56 +0000 | [diff] [blame] | 2024 | static void testFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 2025 | while( argc>=2 ){ |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 2026 | const char *zArg0 = (char*)sqlite3_value_text(argv[0]); |
danielk1977 | 6d88bad | 2004-05-27 14:23:36 +0000 | [diff] [blame] | 2027 | if( zArg0 ){ |
| 2028 | if( 0==sqlite3StrICmp(zArg0, "int") ){ |
| 2029 | sqlite3_result_int(context, sqlite3_value_int(argv[1])); |
| 2030 | }else if( sqlite3StrICmp(zArg0,"int64")==0 ){ |
| 2031 | sqlite3_result_int64(context, sqlite3_value_int64(argv[1])); |
| 2032 | }else if( sqlite3StrICmp(zArg0,"string")==0 ){ |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 2033 | sqlite3_result_text(context, (char*)sqlite3_value_text(argv[1]), -1, |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 2034 | SQLITE_TRANSIENT); |
danielk1977 | 6d88bad | 2004-05-27 14:23:36 +0000 | [diff] [blame] | 2035 | }else if( sqlite3StrICmp(zArg0,"double")==0 ){ |
| 2036 | sqlite3_result_double(context, sqlite3_value_double(argv[1])); |
| 2037 | }else if( sqlite3StrICmp(zArg0,"null")==0 ){ |
| 2038 | sqlite3_result_null(context); |
| 2039 | }else if( sqlite3StrICmp(zArg0,"value")==0 ){ |
| 2040 | sqlite3_result_value(context, argv[sqlite3_value_int(argv[1])]); |
| 2041 | }else{ |
| 2042 | goto error_out; |
| 2043 | } |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 2044 | }else{ |
danielk1977 | 6d88bad | 2004-05-27 14:23:36 +0000 | [diff] [blame] | 2045 | goto error_out; |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 2046 | } |
| 2047 | argc -= 2; |
| 2048 | argv += 2; |
| 2049 | } |
danielk1977 | 6d88bad | 2004-05-27 14:23:36 +0000 | [diff] [blame] | 2050 | return; |
| 2051 | |
| 2052 | error_out: |
| 2053 | sqlite3_result_error(context,"first argument should be one of: " |
| 2054 | "int int64 string double null value", -1); |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | /* |
| 2058 | ** Usage: sqlite_register_test_function DB NAME |
| 2059 | ** |
| 2060 | ** Register the test SQL function on the database DB under the name NAME. |
| 2061 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2062 | static int SQLITE_TCLAPI test_register_func( |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 2063 | void *NotUsed, |
| 2064 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 2065 | int argc, /* Number of arguments */ |
| 2066 | char **argv /* Text of each argument */ |
| 2067 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 2068 | sqlite3 *db; |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 2069 | int rc; |
| 2070 | if( argc!=3 ){ |
| 2071 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 2072 | " DB FUNCTION-NAME", 0); |
| 2073 | return TCL_ERROR; |
| 2074 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 2075 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
danielk1977 | f9d64d2 | 2004-06-19 08:18:07 +0000 | [diff] [blame] | 2076 | rc = sqlite3_create_function(db, argv[2], -1, SQLITE_UTF8, 0, |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 2077 | testFunc, 0, 0); |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 2078 | if( rc!=0 ){ |
danielk1977 | f20b21c | 2004-05-31 23:56:42 +0000 | [diff] [blame] | 2079 | Tcl_AppendResult(interp, sqlite3ErrStr(rc), 0); |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 2080 | return TCL_ERROR; |
| 2081 | } |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2082 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 2083 | return TCL_OK; |
| 2084 | } |
| 2085 | |
| 2086 | /* |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 2087 | ** Usage: sqlite3_finalize STMT |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 2088 | ** |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 2089 | ** Finalize a statement handle. |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 2090 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2091 | static int SQLITE_TCLAPI test_finalize( |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 2092 | void * clientData, |
| 2093 | Tcl_Interp *interp, |
| 2094 | int objc, |
| 2095 | Tcl_Obj *CONST objv[] |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 2096 | ){ |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 2097 | sqlite3_stmt *pStmt; |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 2098 | int rc; |
drh | dddb2f2 | 2007-01-03 23:37:28 +0000 | [diff] [blame] | 2099 | sqlite3 *db = 0; |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 2100 | |
| 2101 | if( objc!=2 ){ |
| 2102 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2103 | Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0); |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 2104 | return TCL_ERROR; |
| 2105 | } |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 2106 | |
| 2107 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2108 | |
danielk1977 | 4397de5 | 2005-01-12 12:44:03 +0000 | [diff] [blame] | 2109 | if( pStmt ){ |
| 2110 | db = StmtToDb(pStmt); |
| 2111 | } |
danielk1977 | fc57d7b | 2004-05-26 02:04:57 +0000 | [diff] [blame] | 2112 | rc = sqlite3_finalize(pStmt); |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 2113 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 4397de5 | 2005-01-12 12:44:03 +0000 | [diff] [blame] | 2114 | if( db && sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 2115 | return TCL_OK; |
| 2116 | } |
| 2117 | |
| 2118 | /* |
drh | d1d3848 | 2008-10-07 23:46:38 +0000 | [diff] [blame] | 2119 | ** Usage: sqlite3_stmt_status STMT CODE RESETFLAG |
| 2120 | ** |
| 2121 | ** Get the value of a status counter from a statement. |
| 2122 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2123 | static int SQLITE_TCLAPI test_stmt_status( |
drh | d1d3848 | 2008-10-07 23:46:38 +0000 | [diff] [blame] | 2124 | void * clientData, |
| 2125 | Tcl_Interp *interp, |
| 2126 | int objc, |
| 2127 | Tcl_Obj *CONST objv[] |
| 2128 | ){ |
| 2129 | int iValue; |
mistachkin | 27b2f05 | 2015-01-12 19:49:46 +0000 | [diff] [blame] | 2130 | int i, op = 0, resetFlag; |
drh | d1d3848 | 2008-10-07 23:46:38 +0000 | [diff] [blame] | 2131 | const char *zOpName; |
| 2132 | sqlite3_stmt *pStmt; |
| 2133 | |
| 2134 | static const struct { |
| 2135 | const char *zName; |
| 2136 | int op; |
| 2137 | } aOp[] = { |
| 2138 | { "SQLITE_STMTSTATUS_FULLSCAN_STEP", SQLITE_STMTSTATUS_FULLSCAN_STEP }, |
| 2139 | { "SQLITE_STMTSTATUS_SORT", SQLITE_STMTSTATUS_SORT }, |
drh | a21a64d | 2010-04-06 22:33:55 +0000 | [diff] [blame] | 2140 | { "SQLITE_STMTSTATUS_AUTOINDEX", SQLITE_STMTSTATUS_AUTOINDEX }, |
drh | bf159fa | 2013-06-25 22:01:22 +0000 | [diff] [blame] | 2141 | { "SQLITE_STMTSTATUS_VM_STEP", SQLITE_STMTSTATUS_VM_STEP }, |
drh | d1d3848 | 2008-10-07 23:46:38 +0000 | [diff] [blame] | 2142 | }; |
| 2143 | if( objc!=4 ){ |
| 2144 | Tcl_WrongNumArgs(interp, 1, objv, "STMT PARAMETER RESETFLAG"); |
| 2145 | return TCL_ERROR; |
| 2146 | } |
| 2147 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2148 | zOpName = Tcl_GetString(objv[2]); |
| 2149 | for(i=0; i<ArraySize(aOp); i++){ |
| 2150 | if( strcmp(aOp[i].zName, zOpName)==0 ){ |
| 2151 | op = aOp[i].op; |
| 2152 | break; |
| 2153 | } |
| 2154 | } |
| 2155 | if( i>=ArraySize(aOp) ){ |
| 2156 | if( Tcl_GetIntFromObj(interp, objv[2], &op) ) return TCL_ERROR; |
| 2157 | } |
| 2158 | if( Tcl_GetBooleanFromObj(interp, objv[3], &resetFlag) ) return TCL_ERROR; |
| 2159 | iValue = sqlite3_stmt_status(pStmt, op, resetFlag); |
| 2160 | Tcl_SetObjResult(interp, Tcl_NewIntObj(iValue)); |
| 2161 | return TCL_OK; |
| 2162 | } |
| 2163 | |
dan | 04489b6 | 2014-10-31 20:11:32 +0000 | [diff] [blame] | 2164 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 2165 | /* |
| 2166 | ** Usage: sqlite3_stmt_scanstatus STMT IDX |
| 2167 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2168 | static int SQLITE_TCLAPI test_stmt_scanstatus( |
dan | 04489b6 | 2014-10-31 20:11:32 +0000 | [diff] [blame] | 2169 | void * clientData, |
| 2170 | Tcl_Interp *interp, |
| 2171 | int objc, |
| 2172 | Tcl_Obj *CONST objv[] |
| 2173 | ){ |
| 2174 | sqlite3_stmt *pStmt; /* First argument */ |
| 2175 | int idx; /* Second argument */ |
| 2176 | |
| 2177 | const char *zName; |
| 2178 | const char *zExplain; |
| 2179 | sqlite3_int64 nLoop; |
| 2180 | sqlite3_int64 nVisit; |
drh | 518140e | 2014-11-06 03:55:10 +0000 | [diff] [blame] | 2181 | double rEst; |
dan | 04489b6 | 2014-10-31 20:11:32 +0000 | [diff] [blame] | 2182 | int res; |
| 2183 | |
| 2184 | if( objc!=3 ){ |
| 2185 | Tcl_WrongNumArgs(interp, 1, objv, "STMT IDX"); |
| 2186 | return TCL_ERROR; |
| 2187 | } |
| 2188 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2189 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 2190 | |
drh | d1a1c23 | 2014-11-03 16:35:55 +0000 | [diff] [blame] | 2191 | res = sqlite3_stmt_scanstatus(pStmt, idx, SQLITE_SCANSTAT_NLOOP, (void*)&nLoop); |
dan | 04489b6 | 2014-10-31 20:11:32 +0000 | [diff] [blame] | 2192 | if( res==0 ){ |
| 2193 | Tcl_Obj *pRet = Tcl_NewObj(); |
| 2194 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj("nLoop", -1)); |
| 2195 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewWideIntObj(nLoop)); |
drh | d1a1c23 | 2014-11-03 16:35:55 +0000 | [diff] [blame] | 2196 | sqlite3_stmt_scanstatus(pStmt, idx, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit); |
dan | 04489b6 | 2014-10-31 20:11:32 +0000 | [diff] [blame] | 2197 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj("nVisit", -1)); |
| 2198 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewWideIntObj(nVisit)); |
drh | 518140e | 2014-11-06 03:55:10 +0000 | [diff] [blame] | 2199 | sqlite3_stmt_scanstatus(pStmt, idx, SQLITE_SCANSTAT_EST, (void*)&rEst); |
dan | 04489b6 | 2014-10-31 20:11:32 +0000 | [diff] [blame] | 2200 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj("nEst", -1)); |
drh | 518140e | 2014-11-06 03:55:10 +0000 | [diff] [blame] | 2201 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewDoubleObj(rEst)); |
drh | d1a1c23 | 2014-11-03 16:35:55 +0000 | [diff] [blame] | 2202 | sqlite3_stmt_scanstatus(pStmt, idx, SQLITE_SCANSTAT_NAME, (void*)&zName); |
dan | 04489b6 | 2014-10-31 20:11:32 +0000 | [diff] [blame] | 2203 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj("zName", -1)); |
| 2204 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zName, -1)); |
drh | d1a1c23 | 2014-11-03 16:35:55 +0000 | [diff] [blame] | 2205 | sqlite3_stmt_scanstatus(pStmt, idx, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain); |
dan | 04489b6 | 2014-10-31 20:11:32 +0000 | [diff] [blame] | 2206 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj("zExplain", -1)); |
| 2207 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zExplain, -1)); |
| 2208 | Tcl_SetObjResult(interp, pRet); |
| 2209 | }else{ |
| 2210 | Tcl_ResetResult(interp); |
| 2211 | } |
| 2212 | return TCL_OK; |
| 2213 | } |
| 2214 | |
| 2215 | /* |
| 2216 | ** Usage: sqlite3_stmt_scanstatus_reset STMT |
| 2217 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2218 | static int SQLITE_TCLAPI test_stmt_scanstatus_reset( |
dan | 04489b6 | 2014-10-31 20:11:32 +0000 | [diff] [blame] | 2219 | void * clientData, |
| 2220 | Tcl_Interp *interp, |
| 2221 | int objc, |
| 2222 | Tcl_Obj *CONST objv[] |
| 2223 | ){ |
| 2224 | sqlite3_stmt *pStmt; /* First argument */ |
| 2225 | if( objc!=2 ){ |
| 2226 | Tcl_WrongNumArgs(interp, 1, objv, "STMT"); |
| 2227 | return TCL_ERROR; |
| 2228 | } |
| 2229 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2230 | sqlite3_stmt_scanstatus_reset(pStmt); |
| 2231 | return TCL_OK; |
| 2232 | } |
| 2233 | #endif |
| 2234 | |
dan | d83f7ca | 2015-11-12 20:12:51 +0000 | [diff] [blame] | 2235 | #ifdef SQLITE_ENABLE_SQLLOG |
| 2236 | /* |
| 2237 | ** Usage: sqlite3_config_sqllog |
| 2238 | ** |
| 2239 | ** Zero the SQLITE_CONFIG_SQLLOG configuration |
| 2240 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2241 | static int SQLITE_TCLAPI test_config_sqllog( |
dan | d83f7ca | 2015-11-12 20:12:51 +0000 | [diff] [blame] | 2242 | void * clientData, |
| 2243 | Tcl_Interp *interp, |
| 2244 | int objc, |
| 2245 | Tcl_Obj *CONST objv[] |
| 2246 | ){ |
dan | d83f7ca | 2015-11-12 20:12:51 +0000 | [diff] [blame] | 2247 | if( objc!=1 ){ |
| 2248 | Tcl_WrongNumArgs(interp, 1, objv, ""); |
| 2249 | return TCL_ERROR; |
| 2250 | } |
| 2251 | sqlite3_config(SQLITE_CONFIG_SQLLOG, 0, 0); |
| 2252 | return TCL_OK; |
| 2253 | } |
| 2254 | #endif |
| 2255 | |
drh | d1d3848 | 2008-10-07 23:46:38 +0000 | [diff] [blame] | 2256 | /* |
dan | e4e416e | 2015-11-16 15:28:54 +0000 | [diff] [blame] | 2257 | ** Usage: vfs_current_time_int64 |
| 2258 | ** |
| 2259 | ** Return the value returned by the default VFS's xCurrentTimeInt64 method. |
| 2260 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2261 | static int SQLITE_TCLAPI vfsCurrentTimeInt64( |
dan | e4e416e | 2015-11-16 15:28:54 +0000 | [diff] [blame] | 2262 | void * clientData, |
| 2263 | Tcl_Interp *interp, |
| 2264 | int objc, |
| 2265 | Tcl_Obj *CONST objv[] |
| 2266 | ){ |
| 2267 | i64 t; |
| 2268 | sqlite3_vfs *pVfs = sqlite3_vfs_find(0); |
| 2269 | if( objc!=1 ){ |
| 2270 | Tcl_WrongNumArgs(interp, 1, objv, ""); |
| 2271 | return TCL_ERROR; |
| 2272 | } |
| 2273 | pVfs->xCurrentTimeInt64(pVfs, &t); |
| 2274 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj(t)); |
| 2275 | return TCL_OK; |
| 2276 | } |
| 2277 | |
drh | ee3b7a2 | 2015-12-09 16:04:06 +0000 | [diff] [blame] | 2278 | #ifdef SQLITE_ENABLE_SNAPSHOT |
dan | e4e416e | 2015-11-16 15:28:54 +0000 | [diff] [blame] | 2279 | /* |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 2280 | ** Usage: sqlite3_snapshot_get DB DBNAME |
| 2281 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2282 | static int SQLITE_TCLAPI test_snapshot_get( |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 2283 | void * clientData, |
| 2284 | Tcl_Interp *interp, |
| 2285 | int objc, |
| 2286 | Tcl_Obj *CONST objv[] |
| 2287 | ){ |
| 2288 | int rc; |
| 2289 | sqlite3 *db; |
| 2290 | char *zName; |
| 2291 | sqlite3_snapshot *pSnapshot = 0; |
| 2292 | |
| 2293 | if( objc!=3 ){ |
| 2294 | Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME"); |
| 2295 | return TCL_ERROR; |
| 2296 | } |
| 2297 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2298 | zName = Tcl_GetString(objv[2]); |
| 2299 | |
| 2300 | rc = sqlite3_snapshot_get(db, zName, &pSnapshot); |
| 2301 | if( rc!=SQLITE_OK ){ |
| 2302 | Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); |
| 2303 | return TCL_ERROR; |
| 2304 | }else{ |
| 2305 | char zBuf[100]; |
| 2306 | if( sqlite3TestMakePointerStr(interp, zBuf, pSnapshot) ) return TCL_ERROR; |
| 2307 | Tcl_SetObjResult(interp, Tcl_NewStringObj(zBuf, -1)); |
| 2308 | } |
| 2309 | return TCL_OK; |
| 2310 | } |
drh | ee3b7a2 | 2015-12-09 16:04:06 +0000 | [diff] [blame] | 2311 | #endif /* SQLITE_ENABLE_SNAPSHOT */ |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 2312 | |
drh | ee3b7a2 | 2015-12-09 16:04:06 +0000 | [diff] [blame] | 2313 | #ifdef SQLITE_ENABLE_SNAPSHOT |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 2314 | /* |
dan | 1158498 | 2016-11-18 20:49:43 +0000 | [diff] [blame] | 2315 | ** Usage: sqlite3_snapshot_recover DB DBNAME |
| 2316 | */ |
| 2317 | static int SQLITE_TCLAPI test_snapshot_recover( |
| 2318 | void * clientData, |
| 2319 | Tcl_Interp *interp, |
| 2320 | int objc, |
| 2321 | Tcl_Obj *CONST objv[] |
| 2322 | ){ |
| 2323 | int rc; |
| 2324 | sqlite3 *db; |
| 2325 | char *zName; |
| 2326 | |
| 2327 | if( objc!=3 ){ |
| 2328 | Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME"); |
| 2329 | return TCL_ERROR; |
| 2330 | } |
| 2331 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2332 | zName = Tcl_GetString(objv[2]); |
| 2333 | |
| 2334 | rc = sqlite3_snapshot_recover(db, zName); |
| 2335 | if( rc!=SQLITE_OK ){ |
| 2336 | Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); |
| 2337 | return TCL_ERROR; |
| 2338 | }else{ |
| 2339 | Tcl_ResetResult(interp); |
| 2340 | } |
| 2341 | return TCL_OK; |
| 2342 | } |
| 2343 | #endif /* SQLITE_ENABLE_SNAPSHOT */ |
| 2344 | |
| 2345 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 2346 | /* |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 2347 | ** Usage: sqlite3_snapshot_open DB DBNAME SNAPSHOT |
| 2348 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2349 | static int SQLITE_TCLAPI test_snapshot_open( |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 2350 | void * clientData, |
| 2351 | Tcl_Interp *interp, |
| 2352 | int objc, |
| 2353 | Tcl_Obj *CONST objv[] |
| 2354 | ){ |
| 2355 | int rc; |
| 2356 | sqlite3 *db; |
| 2357 | char *zName; |
| 2358 | sqlite3_snapshot *pSnapshot; |
| 2359 | |
| 2360 | if( objc!=4 ){ |
| 2361 | Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME SNAPSHOT"); |
| 2362 | return TCL_ERROR; |
| 2363 | } |
| 2364 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2365 | zName = Tcl_GetString(objv[2]); |
| 2366 | pSnapshot = (sqlite3_snapshot*)sqlite3TestTextToPtr(Tcl_GetString(objv[3])); |
| 2367 | |
| 2368 | rc = sqlite3_snapshot_open(db, zName, pSnapshot); |
| 2369 | if( rc!=SQLITE_OK ){ |
| 2370 | Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); |
| 2371 | return TCL_ERROR; |
| 2372 | } |
| 2373 | return TCL_OK; |
| 2374 | } |
drh | ee3b7a2 | 2015-12-09 16:04:06 +0000 | [diff] [blame] | 2375 | #endif /* SQLITE_ENABLE_SNAPSHOT */ |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 2376 | |
drh | ee3b7a2 | 2015-12-09 16:04:06 +0000 | [diff] [blame] | 2377 | #ifdef SQLITE_ENABLE_SNAPSHOT |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 2378 | /* |
| 2379 | ** Usage: sqlite3_snapshot_free SNAPSHOT |
| 2380 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2381 | static int SQLITE_TCLAPI test_snapshot_free( |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 2382 | void * clientData, |
| 2383 | Tcl_Interp *interp, |
| 2384 | int objc, |
| 2385 | Tcl_Obj *CONST objv[] |
| 2386 | ){ |
| 2387 | sqlite3_snapshot *pSnapshot; |
| 2388 | if( objc!=2 ){ |
| 2389 | Tcl_WrongNumArgs(interp, 1, objv, "SNAPSHOT"); |
| 2390 | return TCL_ERROR; |
| 2391 | } |
| 2392 | pSnapshot = (sqlite3_snapshot*)sqlite3TestTextToPtr(Tcl_GetString(objv[1])); |
| 2393 | sqlite3_snapshot_free(pSnapshot); |
| 2394 | return TCL_OK; |
| 2395 | } |
drh | ee3b7a2 | 2015-12-09 16:04:06 +0000 | [diff] [blame] | 2396 | #endif /* SQLITE_ENABLE_SNAPSHOT */ |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 2397 | |
dan | ad2d5ba | 2016-04-11 19:59:52 +0000 | [diff] [blame] | 2398 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 2399 | /* |
| 2400 | ** Usage: sqlite3_snapshot_cmp SNAPSHOT1 SNAPSHOT2 |
| 2401 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2402 | static int SQLITE_TCLAPI test_snapshot_cmp( |
dan | ad2d5ba | 2016-04-11 19:59:52 +0000 | [diff] [blame] | 2403 | void * clientData, |
| 2404 | Tcl_Interp *interp, |
| 2405 | int objc, |
| 2406 | Tcl_Obj *CONST objv[] |
| 2407 | ){ |
| 2408 | int res; |
| 2409 | sqlite3_snapshot *p1; |
| 2410 | sqlite3_snapshot *p2; |
| 2411 | if( objc!=3 ){ |
| 2412 | Tcl_WrongNumArgs(interp, 1, objv, "SNAPSHOT1 SNAPSHOT2"); |
| 2413 | return TCL_ERROR; |
| 2414 | } |
| 2415 | p1 = (sqlite3_snapshot*)sqlite3TestTextToPtr(Tcl_GetString(objv[1])); |
| 2416 | p2 = (sqlite3_snapshot*)sqlite3TestTextToPtr(Tcl_GetString(objv[2])); |
| 2417 | res = sqlite3_snapshot_cmp(p1, p2); |
| 2418 | Tcl_SetObjResult(interp, Tcl_NewIntObj(res)); |
| 2419 | return TCL_OK; |
| 2420 | } |
| 2421 | #endif /* SQLITE_ENABLE_SNAPSHOT */ |
| 2422 | |
dan | 25accbc | 2016-11-18 14:38:41 +0000 | [diff] [blame] | 2423 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 2424 | /* |
| 2425 | ** Usage: sqlite3_snapshot_get_blob DB DBNAME |
| 2426 | */ |
| 2427 | static int SQLITE_TCLAPI test_snapshot_get_blob( |
| 2428 | void * clientData, |
| 2429 | Tcl_Interp *interp, |
| 2430 | int objc, |
| 2431 | Tcl_Obj *CONST objv[] |
| 2432 | ){ |
| 2433 | int rc; |
| 2434 | sqlite3 *db; |
| 2435 | char *zName; |
| 2436 | sqlite3_snapshot *pSnapshot = 0; |
| 2437 | |
| 2438 | if( objc!=3 ){ |
| 2439 | Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME"); |
| 2440 | return TCL_ERROR; |
| 2441 | } |
| 2442 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2443 | zName = Tcl_GetString(objv[2]); |
| 2444 | |
| 2445 | rc = sqlite3_snapshot_get(db, zName, &pSnapshot); |
| 2446 | if( rc!=SQLITE_OK ){ |
| 2447 | Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); |
| 2448 | return TCL_ERROR; |
| 2449 | }else{ |
| 2450 | Tcl_SetObjResult(interp, |
| 2451 | Tcl_NewByteArrayObj((unsigned char*)pSnapshot, sizeof(sqlite3_snapshot)) |
| 2452 | ); |
| 2453 | sqlite3_snapshot_free(pSnapshot); |
| 2454 | } |
| 2455 | return TCL_OK; |
| 2456 | } |
| 2457 | #endif /* SQLITE_ENABLE_SNAPSHOT */ |
| 2458 | |
| 2459 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 2460 | /* |
| 2461 | ** Usage: sqlite3_snapshot_open_blob DB DBNAME SNAPSHOT |
| 2462 | */ |
| 2463 | static int SQLITE_TCLAPI test_snapshot_open_blob( |
| 2464 | void * clientData, |
| 2465 | Tcl_Interp *interp, |
| 2466 | int objc, |
| 2467 | Tcl_Obj *CONST objv[] |
| 2468 | ){ |
| 2469 | int rc; |
| 2470 | sqlite3 *db; |
| 2471 | char *zName; |
| 2472 | unsigned char *pBlob; |
| 2473 | int nBlob; |
| 2474 | |
| 2475 | if( objc!=4 ){ |
| 2476 | Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME SNAPSHOT"); |
| 2477 | return TCL_ERROR; |
| 2478 | } |
| 2479 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2480 | zName = Tcl_GetString(objv[2]); |
| 2481 | pBlob = Tcl_GetByteArrayFromObj(objv[3], &nBlob); |
| 2482 | if( nBlob!=sizeof(sqlite3_snapshot) ){ |
| 2483 | Tcl_AppendResult(interp, "bad SNAPSHOT", 0); |
| 2484 | return TCL_ERROR; |
| 2485 | } |
| 2486 | rc = sqlite3_snapshot_open(db, zName, (sqlite3_snapshot*)pBlob); |
| 2487 | if( rc!=SQLITE_OK ){ |
| 2488 | Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); |
| 2489 | return TCL_ERROR; |
| 2490 | } |
| 2491 | return TCL_OK; |
| 2492 | } |
| 2493 | #endif /* SQLITE_ENABLE_SNAPSHOT */ |
| 2494 | |
| 2495 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 2496 | /* |
| 2497 | ** Usage: sqlite3_snapshot_cmp_blob SNAPSHOT1 SNAPSHOT2 |
| 2498 | */ |
| 2499 | static int SQLITE_TCLAPI test_snapshot_cmp_blob( |
| 2500 | void * clientData, |
| 2501 | Tcl_Interp *interp, |
| 2502 | int objc, |
| 2503 | Tcl_Obj *CONST objv[] |
| 2504 | ){ |
| 2505 | int res; |
| 2506 | unsigned char *p1; |
| 2507 | unsigned char *p2; |
| 2508 | int n1; |
| 2509 | int n2; |
| 2510 | |
| 2511 | if( objc!=3 ){ |
| 2512 | Tcl_WrongNumArgs(interp, 1, objv, "SNAPSHOT1 SNAPSHOT2"); |
| 2513 | return TCL_ERROR; |
| 2514 | } |
| 2515 | |
| 2516 | p1 = Tcl_GetByteArrayFromObj(objv[1], &n1); |
| 2517 | p2 = Tcl_GetByteArrayFromObj(objv[2], &n2); |
| 2518 | |
| 2519 | if( n1!=sizeof(sqlite3_snapshot) || n1!=n2 ){ |
| 2520 | Tcl_AppendResult(interp, "bad SNAPSHOT", 0); |
| 2521 | return TCL_ERROR; |
| 2522 | } |
| 2523 | |
| 2524 | res = sqlite3_snapshot_cmp((sqlite3_snapshot*)p1, (sqlite3_snapshot*)p2); |
| 2525 | Tcl_SetObjResult(interp, Tcl_NewIntObj(res)); |
| 2526 | return TCL_OK; |
| 2527 | } |
| 2528 | #endif /* SQLITE_ENABLE_SNAPSHOT */ |
| 2529 | |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 2530 | /* |
dan | 000f95b | 2016-09-09 20:00:40 +0000 | [diff] [blame] | 2531 | ** Usage: sqlite3_delete_database FILENAME |
| 2532 | */ |
| 2533 | int sqlite3_delete_database(const char*); /* in test_delete.c */ |
| 2534 | static int SQLITE_TCLAPI test_delete_database( |
| 2535 | void * clientData, |
| 2536 | Tcl_Interp *interp, |
| 2537 | int objc, |
| 2538 | Tcl_Obj *CONST objv[] |
| 2539 | ){ |
| 2540 | int rc; |
| 2541 | const char *zFile; |
| 2542 | if( objc!=2 ){ |
| 2543 | Tcl_WrongNumArgs(interp, 1, objv, "FILE"); |
| 2544 | return TCL_ERROR; |
| 2545 | } |
| 2546 | zFile = (const char*)Tcl_GetString(objv[1]); |
| 2547 | rc = sqlite3_delete_database(zFile); |
| 2548 | |
| 2549 | Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1)); |
| 2550 | return TCL_OK; |
| 2551 | } |
| 2552 | |
| 2553 | /* |
drh | bb5a9c3 | 2008-06-19 02:52:25 +0000 | [diff] [blame] | 2554 | ** Usage: sqlite3_next_stmt DB STMT |
| 2555 | ** |
| 2556 | ** Return the next statment in sequence after STMT. |
| 2557 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2558 | static int SQLITE_TCLAPI test_next_stmt( |
drh | bb5a9c3 | 2008-06-19 02:52:25 +0000 | [diff] [blame] | 2559 | void * clientData, |
| 2560 | Tcl_Interp *interp, |
| 2561 | int objc, |
| 2562 | Tcl_Obj *CONST objv[] |
| 2563 | ){ |
| 2564 | sqlite3_stmt *pStmt; |
| 2565 | sqlite3 *db = 0; |
| 2566 | char zBuf[50]; |
| 2567 | |
| 2568 | if( objc!=3 ){ |
| 2569 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2570 | Tcl_GetStringFromObj(objv[0], 0), " DB STMT", 0); |
| 2571 | return TCL_ERROR; |
| 2572 | } |
| 2573 | |
| 2574 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2575 | if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt) ) return TCL_ERROR; |
| 2576 | pStmt = sqlite3_next_stmt(db, pStmt); |
| 2577 | if( pStmt ){ |
| 2578 | if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; |
| 2579 | Tcl_AppendResult(interp, zBuf, 0); |
| 2580 | } |
| 2581 | return TCL_OK; |
| 2582 | } |
| 2583 | |
drh | f03d9cc | 2010-11-16 23:10:25 +0000 | [diff] [blame] | 2584 | /* |
| 2585 | ** Usage: sqlite3_stmt_readonly STMT |
| 2586 | ** |
| 2587 | ** Return true if STMT is a NULL pointer or a pointer to a statement |
| 2588 | ** that is guaranteed to leave the database unmodified. |
| 2589 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2590 | static int SQLITE_TCLAPI test_stmt_readonly( |
drh | f03d9cc | 2010-11-16 23:10:25 +0000 | [diff] [blame] | 2591 | void * clientData, |
| 2592 | Tcl_Interp *interp, |
| 2593 | int objc, |
| 2594 | Tcl_Obj *CONST objv[] |
| 2595 | ){ |
| 2596 | sqlite3_stmt *pStmt; |
| 2597 | int rc; |
| 2598 | |
| 2599 | if( objc!=2 ){ |
| 2600 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2601 | Tcl_GetStringFromObj(objv[0], 0), " STMT", 0); |
| 2602 | return TCL_ERROR; |
| 2603 | } |
| 2604 | |
| 2605 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2606 | rc = sqlite3_stmt_readonly(pStmt); |
| 2607 | Tcl_SetObjResult(interp, Tcl_NewBooleanObj(rc)); |
| 2608 | return TCL_OK; |
| 2609 | } |
| 2610 | |
dan | d9495cd | 2011-04-27 12:08:04 +0000 | [diff] [blame] | 2611 | /* |
drh | 2fb6693 | 2011-11-25 17:21:47 +0000 | [diff] [blame] | 2612 | ** Usage: sqlite3_stmt_busy STMT |
| 2613 | ** |
| 2614 | ** Return true if STMT is a non-NULL pointer to a statement |
| 2615 | ** that has been stepped but not to completion. |
| 2616 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2617 | static int SQLITE_TCLAPI test_stmt_busy( |
drh | 2fb6693 | 2011-11-25 17:21:47 +0000 | [diff] [blame] | 2618 | void * clientData, |
| 2619 | Tcl_Interp *interp, |
| 2620 | int objc, |
| 2621 | Tcl_Obj *CONST objv[] |
| 2622 | ){ |
| 2623 | sqlite3_stmt *pStmt; |
| 2624 | int rc; |
| 2625 | |
| 2626 | if( objc!=2 ){ |
| 2627 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2628 | Tcl_GetStringFromObj(objv[0], 0), " STMT", 0); |
| 2629 | return TCL_ERROR; |
| 2630 | } |
| 2631 | |
| 2632 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2633 | rc = sqlite3_stmt_busy(pStmt); |
| 2634 | Tcl_SetObjResult(interp, Tcl_NewBooleanObj(rc)); |
| 2635 | return TCL_OK; |
| 2636 | } |
| 2637 | |
| 2638 | /* |
dan | d9495cd | 2011-04-27 12:08:04 +0000 | [diff] [blame] | 2639 | ** Usage: uses_stmt_journal STMT |
| 2640 | ** |
| 2641 | ** Return true if STMT uses a statement journal. |
| 2642 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2643 | static int SQLITE_TCLAPI uses_stmt_journal( |
dan | d9495cd | 2011-04-27 12:08:04 +0000 | [diff] [blame] | 2644 | void * clientData, |
| 2645 | Tcl_Interp *interp, |
| 2646 | int objc, |
| 2647 | Tcl_Obj *CONST objv[] |
| 2648 | ){ |
| 2649 | sqlite3_stmt *pStmt; |
dan | d9495cd | 2011-04-27 12:08:04 +0000 | [diff] [blame] | 2650 | |
| 2651 | if( objc!=2 ){ |
| 2652 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2653 | Tcl_GetStringFromObj(objv[0], 0), " STMT", 0); |
| 2654 | return TCL_ERROR; |
| 2655 | } |
| 2656 | |
| 2657 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
drh | caffb1a | 2012-01-30 18:00:31 +0000 | [diff] [blame] | 2658 | sqlite3_stmt_readonly(pStmt); |
dan | d9495cd | 2011-04-27 12:08:04 +0000 | [diff] [blame] | 2659 | Tcl_SetObjResult(interp, Tcl_NewBooleanObj(((Vdbe *)pStmt)->usesStmtJournal)); |
| 2660 | return TCL_OK; |
| 2661 | } |
| 2662 | |
drh | bb5a9c3 | 2008-06-19 02:52:25 +0000 | [diff] [blame] | 2663 | |
| 2664 | /* |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 2665 | ** Usage: sqlite3_reset STMT |
| 2666 | ** |
danielk1977 | 261919c | 2005-12-06 12:52:59 +0000 | [diff] [blame] | 2667 | ** Reset a statement handle. |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 2668 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2669 | static int SQLITE_TCLAPI test_reset( |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 2670 | void * clientData, |
| 2671 | Tcl_Interp *interp, |
| 2672 | int objc, |
| 2673 | Tcl_Obj *CONST objv[] |
| 2674 | ){ |
| 2675 | sqlite3_stmt *pStmt; |
| 2676 | int rc; |
| 2677 | |
| 2678 | if( objc!=2 ){ |
| 2679 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2680 | Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0); |
| 2681 | return TCL_ERROR; |
| 2682 | } |
| 2683 | |
| 2684 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2685 | |
danielk1977 | fc57d7b | 2004-05-26 02:04:57 +0000 | [diff] [blame] | 2686 | rc = sqlite3_reset(pStmt); |
danielk1977 | 261919c | 2005-12-06 12:52:59 +0000 | [diff] [blame] | 2687 | if( pStmt && sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ){ |
| 2688 | return TCL_ERROR; |
| 2689 | } |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 2690 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 261919c | 2005-12-06 12:52:59 +0000 | [diff] [blame] | 2691 | /* |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 2692 | if( rc ){ |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 2693 | return TCL_ERROR; |
| 2694 | } |
danielk1977 | 261919c | 2005-12-06 12:52:59 +0000 | [diff] [blame] | 2695 | */ |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 2696 | return TCL_OK; |
| 2697 | } |
| 2698 | |
drh | 5a38705 | 2003-01-11 14:19:51 +0000 | [diff] [blame] | 2699 | /* |
drh | d89bd00 | 2005-01-22 03:03:54 +0000 | [diff] [blame] | 2700 | ** Usage: sqlite3_expired STMT |
| 2701 | ** |
| 2702 | ** Return TRUE if a recompilation of the statement is recommended. |
| 2703 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2704 | static int SQLITE_TCLAPI test_expired( |
drh | d89bd00 | 2005-01-22 03:03:54 +0000 | [diff] [blame] | 2705 | void * clientData, |
| 2706 | Tcl_Interp *interp, |
| 2707 | int objc, |
| 2708 | Tcl_Obj *CONST objv[] |
| 2709 | ){ |
shane | eec556d | 2008-10-12 00:27:53 +0000 | [diff] [blame] | 2710 | #ifndef SQLITE_OMIT_DEPRECATED |
drh | d89bd00 | 2005-01-22 03:03:54 +0000 | [diff] [blame] | 2711 | sqlite3_stmt *pStmt; |
| 2712 | if( objc!=2 ){ |
| 2713 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2714 | Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0); |
| 2715 | return TCL_ERROR; |
| 2716 | } |
| 2717 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2718 | Tcl_SetObjResult(interp, Tcl_NewBooleanObj(sqlite3_expired(pStmt))); |
shane | eec556d | 2008-10-12 00:27:53 +0000 | [diff] [blame] | 2719 | #endif |
drh | d89bd00 | 2005-01-22 03:03:54 +0000 | [diff] [blame] | 2720 | return TCL_OK; |
| 2721 | } |
| 2722 | |
| 2723 | /* |
drh | f8db1bc | 2005-04-22 02:38:37 +0000 | [diff] [blame] | 2724 | ** Usage: sqlite3_transfer_bindings FROMSTMT TOSTMT |
| 2725 | ** |
| 2726 | ** Transfer all bindings from FROMSTMT over to TOSTMT |
| 2727 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2728 | static int SQLITE_TCLAPI test_transfer_bind( |
drh | f8db1bc | 2005-04-22 02:38:37 +0000 | [diff] [blame] | 2729 | void * clientData, |
| 2730 | Tcl_Interp *interp, |
| 2731 | int objc, |
| 2732 | Tcl_Obj *CONST objv[] |
| 2733 | ){ |
shane | eec556d | 2008-10-12 00:27:53 +0000 | [diff] [blame] | 2734 | #ifndef SQLITE_OMIT_DEPRECATED |
drh | f8db1bc | 2005-04-22 02:38:37 +0000 | [diff] [blame] | 2735 | sqlite3_stmt *pStmt1, *pStmt2; |
| 2736 | if( objc!=3 ){ |
| 2737 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2738 | Tcl_GetStringFromObj(objv[0], 0), " FROM-STMT TO-STMT", 0); |
| 2739 | return TCL_ERROR; |
| 2740 | } |
| 2741 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt1)) return TCL_ERROR; |
| 2742 | if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt2)) return TCL_ERROR; |
| 2743 | Tcl_SetObjResult(interp, |
| 2744 | Tcl_NewIntObj(sqlite3_transfer_bindings(pStmt1,pStmt2))); |
shane | eec556d | 2008-10-12 00:27:53 +0000 | [diff] [blame] | 2745 | #endif |
drh | f8db1bc | 2005-04-22 02:38:37 +0000 | [diff] [blame] | 2746 | return TCL_OK; |
| 2747 | } |
| 2748 | |
| 2749 | /* |
danielk1977 | fbcd585 | 2004-06-15 02:44:18 +0000 | [diff] [blame] | 2750 | ** Usage: sqlite3_changes DB |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2751 | ** |
danielk1977 | fbcd585 | 2004-06-15 02:44:18 +0000 | [diff] [blame] | 2752 | ** Return the number of changes made to the database by the last SQL |
| 2753 | ** execution. |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2754 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2755 | static int SQLITE_TCLAPI test_changes( |
danielk1977 | fbcd585 | 2004-06-15 02:44:18 +0000 | [diff] [blame] | 2756 | void * clientData, |
| 2757 | Tcl_Interp *interp, |
| 2758 | int objc, |
| 2759 | Tcl_Obj *CONST objv[] |
| 2760 | ){ |
| 2761 | sqlite3 *db; |
| 2762 | if( objc!=2 ){ |
| 2763 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2764 | Tcl_GetString(objv[0]), " DB", 0); |
| 2765 | return TCL_ERROR; |
| 2766 | } |
| 2767 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2768 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_changes(db))); |
| 2769 | return TCL_OK; |
| 2770 | } |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2771 | |
| 2772 | /* |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2773 | ** This is the "static_bind_value" that variables are bound to when |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 2774 | ** the FLAG option of sqlite3_bind is "static" |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2775 | */ |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2776 | static char *sqlite_static_bind_value = 0; |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 2777 | static int sqlite_static_bind_nbyte = 0; |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2778 | |
| 2779 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 2780 | ** Usage: sqlite3_bind VM IDX VALUE FLAGS |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2781 | ** |
drh | f7b5496 | 2013-05-28 12:11:54 +0000 | [diff] [blame] | 2782 | ** Sets the value of the IDX-th occurrence of "?" in the original SQL |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2783 | ** string. VALUE is the new value. If FLAGS=="null" then VALUE is |
| 2784 | ** ignored and the value is set to NULL. If FLAGS=="static" then |
| 2785 | ** the value is set to the value of a static variable named |
| 2786 | ** "sqlite_static_bind_value". If FLAGS=="normal" then a copy |
drh | bf8aa2a | 2005-12-02 02:44:05 +0000 | [diff] [blame] | 2787 | ** of the VALUE is made. If FLAGS=="blob10" then a VALUE is ignored |
| 2788 | ** an a 10-byte blob "abc\000xyz\000pq" is inserted. |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2789 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2790 | static int SQLITE_TCLAPI test_bind( |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2791 | void *NotUsed, |
| 2792 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 2793 | int argc, /* Number of arguments */ |
| 2794 | char **argv /* Text of each argument */ |
| 2795 | ){ |
danielk1977 | fc57d7b | 2004-05-26 02:04:57 +0000 | [diff] [blame] | 2796 | sqlite3_stmt *pStmt; |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2797 | int rc; |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2798 | int idx; |
| 2799 | if( argc!=5 ){ |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2800 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2801 | " VM IDX VALUE (null|static|normal)\"", 0); |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2802 | return TCL_ERROR; |
| 2803 | } |
danielk1977 | fc57d7b | 2004-05-26 02:04:57 +0000 | [diff] [blame] | 2804 | if( getStmtPointer(interp, argv[1], &pStmt) ) return TCL_ERROR; |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2805 | if( Tcl_GetInt(interp, argv[2], &idx) ) return TCL_ERROR; |
| 2806 | if( strcmp(argv[4],"null")==0 ){ |
danielk1977 | fc57d7b | 2004-05-26 02:04:57 +0000 | [diff] [blame] | 2807 | rc = sqlite3_bind_null(pStmt, idx); |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2808 | }else if( strcmp(argv[4],"static")==0 ){ |
danielk1977 | fc57d7b | 2004-05-26 02:04:57 +0000 | [diff] [blame] | 2809 | rc = sqlite3_bind_text(pStmt, idx, sqlite_static_bind_value, -1, 0); |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 2810 | }else if( strcmp(argv[4],"static-nbytes")==0 ){ |
| 2811 | rc = sqlite3_bind_text(pStmt, idx, sqlite_static_bind_value, |
| 2812 | sqlite_static_bind_nbyte, 0); |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2813 | }else if( strcmp(argv[4],"normal")==0 ){ |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 2814 | rc = sqlite3_bind_text(pStmt, idx, argv[3], -1, SQLITE_TRANSIENT); |
drh | bf8aa2a | 2005-12-02 02:44:05 +0000 | [diff] [blame] | 2815 | }else if( strcmp(argv[4],"blob10")==0 ){ |
| 2816 | rc = sqlite3_bind_text(pStmt, idx, "abc\000xyz\000pq", 10, SQLITE_STATIC); |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2817 | }else{ |
| 2818 | Tcl_AppendResult(interp, "4th argument should be " |
| 2819 | "\"null\" or \"static\" or \"normal\"", 0); |
| 2820 | return TCL_ERROR; |
| 2821 | } |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2822 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2823 | if( rc ){ |
| 2824 | char zBuf[50]; |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 2825 | sqlite3_snprintf(sizeof(zBuf), zBuf, "(%d) ", rc); |
danielk1977 | f20b21c | 2004-05-31 23:56:42 +0000 | [diff] [blame] | 2826 | Tcl_AppendResult(interp, zBuf, sqlite3ErrStr(rc), 0); |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2827 | return TCL_ERROR; |
| 2828 | } |
| 2829 | return TCL_OK; |
| 2830 | } |
| 2831 | |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 2832 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2833 | /* |
| 2834 | ** Usage: add_test_collate <db ptr> <utf8> <utf16le> <utf16be> |
| 2835 | ** |
| 2836 | ** This function is used to test that SQLite selects the correct collation |
| 2837 | ** sequence callback when multiple versions (for different text encodings) |
| 2838 | ** are available. |
| 2839 | ** |
| 2840 | ** Calling this routine registers the collation sequence "test_collate" |
| 2841 | ** with database handle <db>. The second argument must be a list of three |
| 2842 | ** boolean values. If the first is true, then a version of test_collate is |
| 2843 | ** registered for UTF-8, if the second is true, a version is registered for |
| 2844 | ** UTF-16le, if the third is true, a UTF-16be version is available. |
| 2845 | ** Previous versions of test_collate are deleted. |
| 2846 | ** |
| 2847 | ** The collation sequence test_collate is implemented by calling the |
| 2848 | ** following TCL script: |
| 2849 | ** |
| 2850 | ** "test_collate <enc> <lhs> <rhs>" |
| 2851 | ** |
| 2852 | ** The <lhs> and <rhs> are the two values being compared, encoded in UTF-8. |
| 2853 | ** The <enc> parameter is the encoding of the collation function that |
| 2854 | ** SQLite selected to call. The TCL test script implements the |
| 2855 | ** "test_collate" proc. |
| 2856 | ** |
peter.d.reid | 60ec914 | 2014-09-06 16:39:46 +0000 | [diff] [blame] | 2857 | ** Note that this will only work with one interpreter at a time, as the |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2858 | ** interp pointer to use when evaluating the TCL script is stored in |
| 2859 | ** pTestCollateInterp. |
| 2860 | */ |
| 2861 | static Tcl_Interp* pTestCollateInterp; |
| 2862 | static int test_collate_func( |
| 2863 | void *pCtx, |
| 2864 | int nA, const void *zA, |
| 2865 | int nB, const void *zB |
| 2866 | ){ |
| 2867 | Tcl_Interp *i = pTestCollateInterp; |
dan | d2199f0 | 2010-08-27 17:48:52 +0000 | [diff] [blame] | 2868 | int encin = SQLITE_PTR_TO_INT(pCtx); |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2869 | int res; |
drh | 4db38a7 | 2005-09-01 12:16:28 +0000 | [diff] [blame] | 2870 | int n; |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2871 | |
| 2872 | sqlite3_value *pVal; |
| 2873 | Tcl_Obj *pX; |
| 2874 | |
| 2875 | pX = Tcl_NewStringObj("test_collate", -1); |
| 2876 | Tcl_IncrRefCount(pX); |
| 2877 | |
| 2878 | switch( encin ){ |
| 2879 | case SQLITE_UTF8: |
| 2880 | Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-8",-1)); |
| 2881 | break; |
| 2882 | case SQLITE_UTF16LE: |
| 2883 | Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-16LE",-1)); |
| 2884 | break; |
| 2885 | case SQLITE_UTF16BE: |
| 2886 | Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-16BE",-1)); |
| 2887 | break; |
| 2888 | default: |
| 2889 | assert(0); |
| 2890 | } |
| 2891 | |
dan | 02fa469 | 2009-08-17 17:06:58 +0000 | [diff] [blame] | 2892 | sqlite3BeginBenignMalloc(); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 2893 | pVal = sqlite3ValueNew(0); |
dan | 02fa469 | 2009-08-17 17:06:58 +0000 | [diff] [blame] | 2894 | if( pVal ){ |
| 2895 | sqlite3ValueSetStr(pVal, nA, zA, encin, SQLITE_STATIC); |
| 2896 | n = sqlite3_value_bytes(pVal); |
| 2897 | Tcl_ListObjAppendElement(i,pX, |
| 2898 | Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n)); |
| 2899 | sqlite3ValueSetStr(pVal, nB, zB, encin, SQLITE_STATIC); |
| 2900 | n = sqlite3_value_bytes(pVal); |
| 2901 | Tcl_ListObjAppendElement(i,pX, |
| 2902 | Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n)); |
| 2903 | sqlite3ValueFree(pVal); |
| 2904 | } |
| 2905 | sqlite3EndBenignMalloc(); |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2906 | |
| 2907 | Tcl_EvalObjEx(i, pX, 0); |
| 2908 | Tcl_DecrRefCount(pX); |
| 2909 | Tcl_GetIntFromObj(i, Tcl_GetObjResult(i), &res); |
| 2910 | return res; |
| 2911 | } |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2912 | static int SQLITE_TCLAPI test_collate( |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2913 | void * clientData, |
| 2914 | Tcl_Interp *interp, |
| 2915 | int objc, |
| 2916 | Tcl_Obj *CONST objv[] |
| 2917 | ){ |
| 2918 | sqlite3 *db; |
| 2919 | int val; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2920 | sqlite3_value *pVal; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2921 | int rc; |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2922 | |
| 2923 | if( objc!=5 ) goto bad_args; |
| 2924 | pTestCollateInterp = interp; |
| 2925 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2926 | |
| 2927 | if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2928 | rc = sqlite3_create_collation(db, "test_collate", SQLITE_UTF8, |
| 2929 | (void *)SQLITE_UTF8, val?test_collate_func:0); |
| 2930 | if( rc==SQLITE_OK ){ |
drh | eee4c8c | 2008-02-18 22:24:57 +0000 | [diff] [blame] | 2931 | const void *zUtf16; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2932 | if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR; |
| 2933 | rc = sqlite3_create_collation(db, "test_collate", SQLITE_UTF16LE, |
| 2934 | (void *)SQLITE_UTF16LE, val?test_collate_func:0); |
| 2935 | if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2936 | |
drh | 86f8c19 | 2007-08-22 00:39:19 +0000 | [diff] [blame] | 2937 | #if 0 |
danielk1977 | 9a30cf6 | 2006-01-18 04:26:07 +0000 | [diff] [blame] | 2938 | if( sqlite3_iMallocFail>0 ){ |
| 2939 | sqlite3_iMallocFail++; |
| 2940 | } |
| 2941 | #endif |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 2942 | sqlite3_mutex_enter(db->mutex); |
| 2943 | pVal = sqlite3ValueNew(db); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 2944 | sqlite3ValueSetStr(pVal, -1, "test_collate", SQLITE_UTF8, SQLITE_STATIC); |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 2945 | zUtf16 = sqlite3ValueText(pVal, SQLITE_UTF16NATIVE); |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 2946 | if( db->mallocFailed ){ |
| 2947 | rc = SQLITE_NOMEM; |
| 2948 | }else{ |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 2949 | rc = sqlite3_create_collation16(db, zUtf16, SQLITE_UTF16BE, |
danielk1977 | 9a30cf6 | 2006-01-18 04:26:07 +0000 | [diff] [blame] | 2950 | (void *)SQLITE_UTF16BE, val?test_collate_func:0); |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 2951 | } |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2952 | sqlite3ValueFree(pVal); |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame] | 2953 | sqlite3_mutex_leave(db->mutex); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2954 | } |
| 2955 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
danielk1977 | 9a30cf6 | 2006-01-18 04:26:07 +0000 | [diff] [blame] | 2956 | |
| 2957 | if( rc!=SQLITE_OK ){ |
mistachkin | e84d8d3 | 2013-04-29 03:09:10 +0000 | [diff] [blame] | 2958 | Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); |
danielk1977 | 9a30cf6 | 2006-01-18 04:26:07 +0000 | [diff] [blame] | 2959 | return TCL_ERROR; |
| 2960 | } |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2961 | return TCL_OK; |
| 2962 | |
| 2963 | bad_args: |
| 2964 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2965 | Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0); |
| 2966 | return TCL_ERROR; |
| 2967 | } |
| 2968 | |
drh | 268803a | 2005-12-14 20:11:30 +0000 | [diff] [blame] | 2969 | /* |
dan | 38fdead | 2014-04-01 10:19:02 +0000 | [diff] [blame] | 2970 | ** Usage: add_test_utf16bin_collate <db ptr> |
| 2971 | ** |
| 2972 | ** Add a utf-16 collation sequence named "utf16bin" to the database |
| 2973 | ** handle. This collation sequence compares arguments in the same way as the |
| 2974 | ** built-in collation "binary". |
| 2975 | */ |
| 2976 | static int test_utf16bin_collate_func( |
| 2977 | void *pCtx, |
| 2978 | int nA, const void *zA, |
| 2979 | int nB, const void *zB |
| 2980 | ){ |
| 2981 | int nCmp = (nA>nB ? nB : nA); |
| 2982 | int res = memcmp(zA, zB, nCmp); |
| 2983 | if( res==0 ) res = nA - nB; |
| 2984 | return res; |
| 2985 | } |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 2986 | static int SQLITE_TCLAPI test_utf16bin_collate( |
dan | 38fdead | 2014-04-01 10:19:02 +0000 | [diff] [blame] | 2987 | void * clientData, |
| 2988 | Tcl_Interp *interp, |
| 2989 | int objc, |
| 2990 | Tcl_Obj *CONST objv[] |
| 2991 | ){ |
| 2992 | sqlite3 *db; |
| 2993 | int rc; |
| 2994 | |
| 2995 | if( objc!=2 ) goto bad_args; |
| 2996 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2997 | |
| 2998 | rc = sqlite3_create_collation(db, "utf16bin", SQLITE_UTF16, 0, |
| 2999 | test_utf16bin_collate_func |
| 3000 | ); |
| 3001 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
| 3002 | return TCL_OK; |
| 3003 | |
| 3004 | bad_args: |
| 3005 | Tcl_WrongNumArgs(interp, 1, objv, "DB"); |
| 3006 | return TCL_ERROR; |
| 3007 | } |
| 3008 | |
| 3009 | /* |
drh | 268803a | 2005-12-14 20:11:30 +0000 | [diff] [blame] | 3010 | ** When the collation needed callback is invoked, record the name of |
| 3011 | ** the requested collating function here. The recorded name is linked |
| 3012 | ** to a TCL variable and used to make sure that the requested collation |
| 3013 | ** name is correct. |
| 3014 | */ |
| 3015 | static char zNeededCollation[200]; |
| 3016 | static char *pzNeededCollation = zNeededCollation; |
| 3017 | |
| 3018 | |
| 3019 | /* |
| 3020 | ** Called when a collating sequence is needed. Registered using |
| 3021 | ** sqlite3_collation_needed16(). |
| 3022 | */ |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 3023 | static void test_collate_needed_cb( |
| 3024 | void *pCtx, |
| 3025 | sqlite3 *db, |
| 3026 | int eTextRep, |
drh | 268803a | 2005-12-14 20:11:30 +0000 | [diff] [blame] | 3027 | const void *pName |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 3028 | ){ |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 3029 | int enc = ENC(db); |
drh | 268803a | 2005-12-14 20:11:30 +0000 | [diff] [blame] | 3030 | int i; |
| 3031 | char *z; |
| 3032 | for(z = (char*)pName, i=0; *z || z[1]; z++){ |
| 3033 | if( *z ) zNeededCollation[i++] = *z; |
| 3034 | } |
| 3035 | zNeededCollation[i] = 0; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 3036 | sqlite3_create_collation( |
dan | d2199f0 | 2010-08-27 17:48:52 +0000 | [diff] [blame] | 3037 | db, "test_collate", ENC(db), SQLITE_INT_TO_PTR(enc), test_collate_func); |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | /* |
| 3041 | ** Usage: add_test_collate_needed DB |
| 3042 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3043 | static int SQLITE_TCLAPI test_collate_needed( |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 3044 | void * clientData, |
| 3045 | Tcl_Interp *interp, |
| 3046 | int objc, |
| 3047 | Tcl_Obj *CONST objv[] |
| 3048 | ){ |
| 3049 | sqlite3 *db; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3050 | int rc; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 3051 | |
| 3052 | if( objc!=2 ) goto bad_args; |
| 3053 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3054 | rc = sqlite3_collation_needed16(db, 0, test_collate_needed_cb); |
drh | 268803a | 2005-12-14 20:11:30 +0000 | [diff] [blame] | 3055 | zNeededCollation[0] = 0; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3056 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 3057 | return TCL_OK; |
| 3058 | |
| 3059 | bad_args: |
| 3060 | Tcl_WrongNumArgs(interp, 1, objv, "DB"); |
| 3061 | return TCL_ERROR; |
| 3062 | } |
drh | 7d9bd4e | 2006-02-16 18:16:36 +0000 | [diff] [blame] | 3063 | |
| 3064 | /* |
| 3065 | ** tclcmd: add_alignment_test_collations DB |
| 3066 | ** |
| 3067 | ** Add two new collating sequences to the database DB |
| 3068 | ** |
| 3069 | ** utf16_aligned |
| 3070 | ** utf16_unaligned |
| 3071 | ** |
| 3072 | ** Both collating sequences use the same sort order as BINARY. |
| 3073 | ** The only difference is that the utf16_aligned collating |
| 3074 | ** sequence is declared with the SQLITE_UTF16_ALIGNED flag. |
| 3075 | ** Both collating functions increment the unaligned utf16 counter |
| 3076 | ** whenever they see a string that begins on an odd byte boundary. |
| 3077 | */ |
| 3078 | static int unaligned_string_counter = 0; |
| 3079 | static int alignmentCollFunc( |
| 3080 | void *NotUsed, |
| 3081 | int nKey1, const void *pKey1, |
| 3082 | int nKey2, const void *pKey2 |
| 3083 | ){ |
| 3084 | int rc, n; |
| 3085 | n = nKey1<nKey2 ? nKey1 : nKey2; |
dan | d2199f0 | 2010-08-27 17:48:52 +0000 | [diff] [blame] | 3086 | if( nKey1>0 && 1==(1&(SQLITE_PTR_TO_INT(pKey1))) ) unaligned_string_counter++; |
| 3087 | if( nKey2>0 && 1==(1&(SQLITE_PTR_TO_INT(pKey2))) ) unaligned_string_counter++; |
drh | 7d9bd4e | 2006-02-16 18:16:36 +0000 | [diff] [blame] | 3088 | rc = memcmp(pKey1, pKey2, n); |
| 3089 | if( rc==0 ){ |
| 3090 | rc = nKey1 - nKey2; |
| 3091 | } |
| 3092 | return rc; |
| 3093 | } |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3094 | static int SQLITE_TCLAPI add_alignment_test_collations( |
drh | 7d9bd4e | 2006-02-16 18:16:36 +0000 | [diff] [blame] | 3095 | void * clientData, |
| 3096 | Tcl_Interp *interp, |
| 3097 | int objc, |
| 3098 | Tcl_Obj *CONST objv[] |
| 3099 | ){ |
| 3100 | sqlite3 *db; |
| 3101 | if( objc>=2 ){ |
| 3102 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
danielk1977 | ebb3293 | 2009-04-28 15:35:38 +0000 | [diff] [blame] | 3103 | sqlite3_create_collation(db, "utf16_unaligned", SQLITE_UTF16, |
drh | 7d9bd4e | 2006-02-16 18:16:36 +0000 | [diff] [blame] | 3104 | 0, alignmentCollFunc); |
danielk1977 | ebb3293 | 2009-04-28 15:35:38 +0000 | [diff] [blame] | 3105 | sqlite3_create_collation(db, "utf16_aligned", SQLITE_UTF16_ALIGNED, |
drh | 7d9bd4e | 2006-02-16 18:16:36 +0000 | [diff] [blame] | 3106 | 0, alignmentCollFunc); |
| 3107 | } |
| 3108 | return SQLITE_OK; |
| 3109 | } |
| 3110 | #endif /* !defined(SQLITE_OMIT_UTF16) */ |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 3111 | |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3112 | /* |
| 3113 | ** Usage: add_test_function <db ptr> <utf8> <utf16le> <utf16be> |
| 3114 | ** |
| 3115 | ** This function is used to test that SQLite selects the correct user |
| 3116 | ** function callback when multiple versions (for different text encodings) |
| 3117 | ** are available. |
| 3118 | ** |
| 3119 | ** Calling this routine registers up to three versions of the user function |
| 3120 | ** "test_function" with database handle <db>. If the second argument is |
| 3121 | ** true, then a version of test_function is registered for UTF-8, if the |
| 3122 | ** third is true, a version is registered for UTF-16le, if the fourth is |
| 3123 | ** true, a UTF-16be version is available. Previous versions of |
| 3124 | ** test_function are deleted. |
| 3125 | ** |
| 3126 | ** The user function is implemented by calling the following TCL script: |
| 3127 | ** |
| 3128 | ** "test_function <enc> <arg>" |
| 3129 | ** |
| 3130 | ** Where <enc> is one of UTF-8, UTF-16LE or UTF16BE, and <arg> is the |
| 3131 | ** single argument passed to the SQL function. The value returned by |
| 3132 | ** the TCL script is used as the return value of the SQL function. It |
| 3133 | ** is passed to SQLite using UTF-16BE for a UTF-8 test_function(), UTF-8 |
| 3134 | ** for a UTF-16LE test_function(), and UTF-16LE for an implementation that |
| 3135 | ** prefers UTF-16BE. |
| 3136 | */ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 3137 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3138 | static void test_function_utf8( |
| 3139 | sqlite3_context *pCtx, |
| 3140 | int nArg, |
| 3141 | sqlite3_value **argv |
| 3142 | ){ |
| 3143 | Tcl_Interp *interp; |
| 3144 | Tcl_Obj *pX; |
| 3145 | sqlite3_value *pVal; |
| 3146 | interp = (Tcl_Interp *)sqlite3_user_data(pCtx); |
| 3147 | pX = Tcl_NewStringObj("test_function", -1); |
| 3148 | Tcl_IncrRefCount(pX); |
| 3149 | Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-8", -1)); |
| 3150 | Tcl_ListObjAppendElement(interp, pX, |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 3151 | Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1)); |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3152 | Tcl_EvalObjEx(interp, pX, 0); |
| 3153 | Tcl_DecrRefCount(pX); |
| 3154 | sqlite3_result_text(pCtx, Tcl_GetStringResult(interp), -1, SQLITE_TRANSIENT); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 3155 | pVal = sqlite3ValueNew(0); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 3156 | sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3157 | SQLITE_UTF8, SQLITE_STATIC); |
| 3158 | sqlite3_result_text16be(pCtx, sqlite3_value_text16be(pVal), |
| 3159 | -1, SQLITE_TRANSIENT); |
| 3160 | sqlite3ValueFree(pVal); |
| 3161 | } |
| 3162 | static void test_function_utf16le( |
| 3163 | sqlite3_context *pCtx, |
| 3164 | int nArg, |
| 3165 | sqlite3_value **argv |
| 3166 | ){ |
| 3167 | Tcl_Interp *interp; |
| 3168 | Tcl_Obj *pX; |
| 3169 | sqlite3_value *pVal; |
| 3170 | interp = (Tcl_Interp *)sqlite3_user_data(pCtx); |
| 3171 | pX = Tcl_NewStringObj("test_function", -1); |
| 3172 | Tcl_IncrRefCount(pX); |
| 3173 | Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16LE", -1)); |
| 3174 | Tcl_ListObjAppendElement(interp, pX, |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 3175 | Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1)); |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3176 | Tcl_EvalObjEx(interp, pX, 0); |
| 3177 | Tcl_DecrRefCount(pX); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 3178 | pVal = sqlite3ValueNew(0); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 3179 | sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3180 | SQLITE_UTF8, SQLITE_STATIC); |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 3181 | sqlite3_result_text(pCtx,(char*)sqlite3_value_text(pVal),-1,SQLITE_TRANSIENT); |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3182 | sqlite3ValueFree(pVal); |
| 3183 | } |
| 3184 | static void test_function_utf16be( |
| 3185 | sqlite3_context *pCtx, |
| 3186 | int nArg, |
| 3187 | sqlite3_value **argv |
| 3188 | ){ |
| 3189 | Tcl_Interp *interp; |
| 3190 | Tcl_Obj *pX; |
| 3191 | sqlite3_value *pVal; |
| 3192 | interp = (Tcl_Interp *)sqlite3_user_data(pCtx); |
| 3193 | pX = Tcl_NewStringObj("test_function", -1); |
| 3194 | Tcl_IncrRefCount(pX); |
| 3195 | Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16BE", -1)); |
| 3196 | Tcl_ListObjAppendElement(interp, pX, |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 3197 | Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1)); |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3198 | Tcl_EvalObjEx(interp, pX, 0); |
| 3199 | Tcl_DecrRefCount(pX); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 3200 | pVal = sqlite3ValueNew(0); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 3201 | sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3202 | SQLITE_UTF8, SQLITE_STATIC); |
drh | de4fcfd | 2008-01-19 23:50:26 +0000 | [diff] [blame] | 3203 | sqlite3_result_text16(pCtx, sqlite3_value_text16le(pVal), |
| 3204 | -1, SQLITE_TRANSIENT); |
| 3205 | sqlite3_result_text16be(pCtx, sqlite3_value_text16le(pVal), |
| 3206 | -1, SQLITE_TRANSIENT); |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3207 | sqlite3_result_text16le(pCtx, sqlite3_value_text16le(pVal), |
| 3208 | -1, SQLITE_TRANSIENT); |
| 3209 | sqlite3ValueFree(pVal); |
| 3210 | } |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 3211 | #endif /* SQLITE_OMIT_UTF16 */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3212 | static int SQLITE_TCLAPI test_function( |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3213 | void * clientData, |
| 3214 | Tcl_Interp *interp, |
| 3215 | int objc, |
| 3216 | Tcl_Obj *CONST objv[] |
| 3217 | ){ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 3218 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3219 | sqlite3 *db; |
| 3220 | int val; |
| 3221 | |
| 3222 | if( objc!=5 ) goto bad_args; |
| 3223 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 3224 | |
| 3225 | if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR; |
| 3226 | if( val ){ |
| 3227 | sqlite3_create_function(db, "test_function", 1, SQLITE_UTF8, |
| 3228 | interp, test_function_utf8, 0, 0); |
| 3229 | } |
| 3230 | if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR; |
| 3231 | if( val ){ |
| 3232 | sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16LE, |
| 3233 | interp, test_function_utf16le, 0, 0); |
| 3234 | } |
| 3235 | if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR; |
| 3236 | if( val ){ |
| 3237 | sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16BE, |
| 3238 | interp, test_function_utf16be, 0, 0); |
| 3239 | } |
| 3240 | |
| 3241 | return TCL_OK; |
| 3242 | bad_args: |
| 3243 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3244 | Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0); |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 3245 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 3246 | return TCL_ERROR; |
| 3247 | } |
| 3248 | |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 3249 | /* |
dan | ba3cbf3 | 2010-06-30 04:29:03 +0000 | [diff] [blame] | 3250 | ** Usage: sqlite3_test_errstr <err code> |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 3251 | ** |
| 3252 | ** Test that the english language string equivalents for sqlite error codes |
| 3253 | ** are sane. The parameter is an integer representing an sqlite error code. |
| 3254 | ** The result is a list of two elements, the string representation of the |
| 3255 | ** error code and the english language explanation. |
| 3256 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3257 | static int SQLITE_TCLAPI test_errstr( |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 3258 | void * clientData, |
| 3259 | Tcl_Interp *interp, |
| 3260 | int objc, |
| 3261 | Tcl_Obj *CONST objv[] |
| 3262 | ){ |
| 3263 | char *zCode; |
| 3264 | int i; |
| 3265 | if( objc!=1 ){ |
| 3266 | Tcl_WrongNumArgs(interp, 1, objv, "<error code>"); |
| 3267 | } |
| 3268 | |
| 3269 | zCode = Tcl_GetString(objv[1]); |
| 3270 | for(i=0; i<200; i++){ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 3271 | if( 0==strcmp(t1ErrorName(i), zCode) ) break; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 3272 | } |
| 3273 | Tcl_SetResult(interp, (char *)sqlite3ErrStr(i), 0); |
| 3274 | return TCL_OK; |
| 3275 | } |
| 3276 | |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 3277 | /* |
drh | 99ee360 | 2003-02-16 19:13:36 +0000 | [diff] [blame] | 3278 | ** Usage: breakpoint |
| 3279 | ** |
| 3280 | ** This routine exists for one purpose - to provide a place to put a |
| 3281 | ** breakpoint with GDB that can be triggered using TCL code. The use |
| 3282 | ** for this is when a particular test fails on (say) the 1485th iteration. |
| 3283 | ** In the TCL test script, we can add code like this: |
| 3284 | ** |
| 3285 | ** if {$i==1485} breakpoint |
| 3286 | ** |
| 3287 | ** Then run testfixture in the debugger and wait for the breakpoint to |
| 3288 | ** fire. Then additional breakpoints can be set to trace down the bug. |
| 3289 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3290 | static int SQLITE_TCLAPI test_breakpoint( |
drh | 99ee360 | 2003-02-16 19:13:36 +0000 | [diff] [blame] | 3291 | void *NotUsed, |
| 3292 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 3293 | int argc, /* Number of arguments */ |
| 3294 | char **argv /* Text of each argument */ |
| 3295 | ){ |
| 3296 | return TCL_OK; /* Do nothing */ |
| 3297 | } |
| 3298 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3299 | /* |
drh | b026e05 | 2007-05-02 01:34:31 +0000 | [diff] [blame] | 3300 | ** Usage: sqlite3_bind_zeroblob STMT IDX N |
| 3301 | ** |
| 3302 | ** Test the sqlite3_bind_zeroblob interface. STMT is a prepared statement. |
| 3303 | ** IDX is the index of a wildcard in the prepared statement. This command |
| 3304 | ** binds a N-byte zero-filled BLOB to the wildcard. |
| 3305 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3306 | static int SQLITE_TCLAPI test_bind_zeroblob( |
drh | b026e05 | 2007-05-02 01:34:31 +0000 | [diff] [blame] | 3307 | void * clientData, |
| 3308 | Tcl_Interp *interp, |
| 3309 | int objc, |
| 3310 | Tcl_Obj *CONST objv[] |
| 3311 | ){ |
| 3312 | sqlite3_stmt *pStmt; |
| 3313 | int idx; |
| 3314 | int n; |
| 3315 | int rc; |
| 3316 | |
| 3317 | if( objc!=4 ){ |
danielk1977 | 28c6630 | 2007-09-01 11:04:26 +0000 | [diff] [blame] | 3318 | Tcl_WrongNumArgs(interp, 1, objv, "STMT IDX N"); |
drh | b026e05 | 2007-05-02 01:34:31 +0000 | [diff] [blame] | 3319 | return TCL_ERROR; |
| 3320 | } |
| 3321 | |
| 3322 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3323 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 3324 | if( Tcl_GetIntFromObj(interp, objv[3], &n) ) return TCL_ERROR; |
| 3325 | |
| 3326 | rc = sqlite3_bind_zeroblob(pStmt, idx, n); |
| 3327 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
| 3328 | if( rc!=SQLITE_OK ){ |
| 3329 | return TCL_ERROR; |
| 3330 | } |
| 3331 | |
| 3332 | return TCL_OK; |
| 3333 | } |
| 3334 | |
| 3335 | /* |
dan | 80c0302 | 2015-07-24 17:36:34 +0000 | [diff] [blame] | 3336 | ** Usage: sqlite3_bind_zeroblob64 STMT IDX N |
| 3337 | ** |
| 3338 | ** Test the sqlite3_bind_zeroblob64 interface. STMT is a prepared statement. |
| 3339 | ** IDX is the index of a wildcard in the prepared statement. This command |
| 3340 | ** binds a N-byte zero-filled BLOB to the wildcard. |
| 3341 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3342 | static int SQLITE_TCLAPI test_bind_zeroblob64( |
dan | 80c0302 | 2015-07-24 17:36:34 +0000 | [diff] [blame] | 3343 | void * clientData, |
| 3344 | Tcl_Interp *interp, |
| 3345 | int objc, |
| 3346 | Tcl_Obj *CONST objv[] |
| 3347 | ){ |
| 3348 | sqlite3_stmt *pStmt; |
| 3349 | int idx; |
drh | 9a1e85e | 2016-02-19 13:29:52 +0000 | [diff] [blame] | 3350 | Tcl_WideInt n; |
dan | 80c0302 | 2015-07-24 17:36:34 +0000 | [diff] [blame] | 3351 | int rc; |
| 3352 | |
| 3353 | if( objc!=4 ){ |
| 3354 | Tcl_WrongNumArgs(interp, 1, objv, "STMT IDX N"); |
| 3355 | return TCL_ERROR; |
| 3356 | } |
| 3357 | |
| 3358 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3359 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 3360 | if( Tcl_GetWideIntFromObj(interp, objv[3], &n) ) return TCL_ERROR; |
| 3361 | |
| 3362 | rc = sqlite3_bind_zeroblob64(pStmt, idx, n); |
| 3363 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
| 3364 | if( rc!=SQLITE_OK ){ |
| 3365 | Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); |
| 3366 | return TCL_ERROR; |
| 3367 | } |
| 3368 | |
| 3369 | return TCL_OK; |
| 3370 | } |
| 3371 | |
| 3372 | /* |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3373 | ** Usage: sqlite3_bind_int STMT N VALUE |
| 3374 | ** |
| 3375 | ** Test the sqlite3_bind_int interface. STMT is a prepared statement. |
| 3376 | ** N is the index of a wildcard in the prepared statement. This command |
| 3377 | ** binds a 32-bit integer VALUE to that wildcard. |
| 3378 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3379 | static int SQLITE_TCLAPI test_bind_int( |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3380 | void * clientData, |
| 3381 | Tcl_Interp *interp, |
| 3382 | int objc, |
| 3383 | Tcl_Obj *CONST objv[] |
| 3384 | ){ |
| 3385 | sqlite3_stmt *pStmt; |
| 3386 | int idx; |
| 3387 | int value; |
| 3388 | int rc; |
| 3389 | |
| 3390 | if( objc!=4 ){ |
| 3391 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3392 | Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3393 | return TCL_ERROR; |
| 3394 | } |
| 3395 | |
| 3396 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3397 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 3398 | if( Tcl_GetIntFromObj(interp, objv[3], &value) ) return TCL_ERROR; |
| 3399 | |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 3400 | rc = sqlite3_bind_int(pStmt, idx, value); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3401 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3402 | if( rc!=SQLITE_OK ){ |
| 3403 | return TCL_ERROR; |
| 3404 | } |
| 3405 | |
| 3406 | return TCL_OK; |
| 3407 | } |
| 3408 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3409 | |
| 3410 | /* |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 3411 | ** Usage: intarray_addr INT ... |
drh | 4841624 | 2016-06-29 05:00:30 +0000 | [diff] [blame] | 3412 | ** |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 3413 | ** Return the address of a C-language array of 32-bit integers. |
| 3414 | ** |
| 3415 | ** Space to hold the array is obtained from malloc(). Call this procedure once |
| 3416 | ** with no arguments in order to release memory. Each call to this procedure |
| 3417 | ** overwrites the previous array. |
drh | 4841624 | 2016-06-29 05:00:30 +0000 | [diff] [blame] | 3418 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3419 | static int SQLITE_TCLAPI test_intarray_addr( |
drh | 4841624 | 2016-06-29 05:00:30 +0000 | [diff] [blame] | 3420 | void * clientData, |
| 3421 | Tcl_Interp *interp, |
| 3422 | int objc, |
| 3423 | Tcl_Obj *CONST objv[] |
| 3424 | ){ |
drh | 4841624 | 2016-06-29 05:00:30 +0000 | [diff] [blame] | 3425 | int i; |
| 3426 | static int *p = 0; |
| 3427 | |
| 3428 | sqlite3_free(p); |
| 3429 | p = 0; |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 3430 | if( objc>1 ){ |
| 3431 | p = sqlite3_malloc( sizeof(p[0])*(objc-1) ); |
| 3432 | if( p==0 ) return TCL_ERROR; |
| 3433 | for(i=0; i<objc-1; i++){ |
| 3434 | if( Tcl_GetIntFromObj(interp, objv[1+i], &p[i]) ){ |
| 3435 | sqlite3_free(p); |
| 3436 | p = 0; |
| 3437 | return TCL_ERROR; |
| 3438 | } |
drh | 4841624 | 2016-06-29 05:00:30 +0000 | [diff] [blame] | 3439 | } |
| 3440 | } |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 3441 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj((sqlite3_int64)p)); |
| 3442 | return TCL_OK; |
| 3443 | } |
| 3444 | /* |
| 3445 | ** Usage: intarray_addr INT ... |
| 3446 | ** |
| 3447 | ** Return the address of a C-language array of 32-bit integers. |
| 3448 | ** |
| 3449 | ** Space to hold the array is obtained from malloc(). Call this procedure once |
| 3450 | ** with no arguments in order to release memory. Each call to this procedure |
| 3451 | ** overwrites the previous array. |
| 3452 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3453 | static int SQLITE_TCLAPI test_int64array_addr( |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 3454 | void * clientData, |
| 3455 | Tcl_Interp *interp, |
| 3456 | int objc, |
| 3457 | Tcl_Obj *CONST objv[] |
| 3458 | ){ |
| 3459 | int i; |
| 3460 | static sqlite3_int64 *p = 0; |
| 3461 | |
| 3462 | sqlite3_free(p); |
| 3463 | p = 0; |
| 3464 | if( objc>1 ){ |
| 3465 | p = sqlite3_malloc( sizeof(p[0])*(objc-1) ); |
| 3466 | if( p==0 ) return TCL_ERROR; |
| 3467 | for(i=0; i<objc-1; i++){ |
drh | a912348 | 2016-07-09 17:15:05 +0000 | [diff] [blame] | 3468 | Tcl_WideInt v; |
| 3469 | if( Tcl_GetWideIntFromObj(interp, objv[1+i], &v) ){ |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 3470 | sqlite3_free(p); |
| 3471 | p = 0; |
| 3472 | return TCL_ERROR; |
| 3473 | } |
drh | a912348 | 2016-07-09 17:15:05 +0000 | [diff] [blame] | 3474 | p[i] = v; |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 3475 | } |
| 3476 | } |
| 3477 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj((sqlite3_int64)p)); |
| 3478 | return TCL_OK; |
| 3479 | } |
| 3480 | /* |
| 3481 | ** Usage: doublearray_addr INT ... |
| 3482 | ** |
| 3483 | ** Return the address of a C-language array of doubles. |
| 3484 | ** |
| 3485 | ** Space to hold the array is obtained from malloc(). Call this procedure once |
| 3486 | ** with no arguments in order to release memory. Each call to this procedure |
| 3487 | ** overwrites the previous array. |
| 3488 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3489 | static int SQLITE_TCLAPI test_doublearray_addr( |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 3490 | void * clientData, |
| 3491 | Tcl_Interp *interp, |
| 3492 | int objc, |
| 3493 | Tcl_Obj *CONST objv[] |
| 3494 | ){ |
| 3495 | int i; |
| 3496 | static double *p = 0; |
| 3497 | |
| 3498 | sqlite3_free(p); |
| 3499 | p = 0; |
| 3500 | if( objc>1 ){ |
| 3501 | p = sqlite3_malloc( sizeof(p[0])*(objc-1) ); |
| 3502 | if( p==0 ) return TCL_ERROR; |
| 3503 | for(i=0; i<objc-1; i++){ |
| 3504 | if( Tcl_GetDoubleFromObj(interp, objv[1+i], &p[i]) ){ |
| 3505 | sqlite3_free(p); |
| 3506 | p = 0; |
| 3507 | return TCL_ERROR; |
| 3508 | } |
| 3509 | } |
| 3510 | } |
| 3511 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj((sqlite3_int64)p)); |
| 3512 | return TCL_OK; |
| 3513 | } |
| 3514 | /* |
| 3515 | ** Usage: textarray_addr TEXT ... |
| 3516 | ** |
| 3517 | ** Return the address of a C-language array of strings. |
| 3518 | ** |
| 3519 | ** Space to hold the array is obtained from malloc(). Call this procedure once |
| 3520 | ** with no arguments in order to release memory. Each call to this procedure |
| 3521 | ** overwrites the previous array. |
| 3522 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3523 | static int SQLITE_TCLAPI test_textarray_addr( |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 3524 | void * clientData, |
| 3525 | Tcl_Interp *interp, |
| 3526 | int objc, |
| 3527 | Tcl_Obj *CONST objv[] |
| 3528 | ){ |
| 3529 | int i; |
| 3530 | static int n = 0; |
| 3531 | static char **p = 0; |
| 3532 | |
| 3533 | for(i=0; i<n; i++) sqlite3_free(p[i]); |
| 3534 | sqlite3_free(p); |
| 3535 | p = 0; |
| 3536 | if( objc>1 ){ |
| 3537 | p = sqlite3_malloc( sizeof(p[0])*(objc-1) ); |
| 3538 | if( p==0 ) return TCL_ERROR; |
| 3539 | for(i=0; i<objc-1; i++){ |
| 3540 | p[i] = sqlite3_mprintf("%s", Tcl_GetString(objv[1+i])); |
| 3541 | } |
dan | 5068743 | 2016-07-06 09:19:14 +0000 | [diff] [blame] | 3542 | } |
| 3543 | n = objc-1; |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 3544 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj((sqlite3_int64)p)); |
drh | 4841624 | 2016-06-29 05:00:30 +0000 | [diff] [blame] | 3545 | return TCL_OK; |
| 3546 | } |
| 3547 | |
| 3548 | |
| 3549 | /* |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3550 | ** Usage: sqlite3_bind_int64 STMT N VALUE |
| 3551 | ** |
| 3552 | ** Test the sqlite3_bind_int64 interface. STMT is a prepared statement. |
| 3553 | ** N is the index of a wildcard in the prepared statement. This command |
| 3554 | ** binds a 64-bit integer VALUE to that wildcard. |
| 3555 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3556 | static int SQLITE_TCLAPI test_bind_int64( |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3557 | void * clientData, |
| 3558 | Tcl_Interp *interp, |
| 3559 | int objc, |
| 3560 | Tcl_Obj *CONST objv[] |
| 3561 | ){ |
| 3562 | sqlite3_stmt *pStmt; |
| 3563 | int idx; |
drh | b3f787f | 2012-09-29 14:45:54 +0000 | [diff] [blame] | 3564 | Tcl_WideInt value; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3565 | int rc; |
| 3566 | |
| 3567 | if( objc!=4 ){ |
| 3568 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3569 | Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3570 | return TCL_ERROR; |
| 3571 | } |
| 3572 | |
| 3573 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3574 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 3575 | if( Tcl_GetWideIntFromObj(interp, objv[3], &value) ) return TCL_ERROR; |
| 3576 | |
| 3577 | rc = sqlite3_bind_int64(pStmt, idx, value); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3578 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3579 | if( rc!=SQLITE_OK ){ |
| 3580 | return TCL_ERROR; |
| 3581 | } |
| 3582 | |
| 3583 | return TCL_OK; |
| 3584 | } |
| 3585 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3586 | |
| 3587 | /* |
| 3588 | ** Usage: sqlite3_bind_double STMT N VALUE |
| 3589 | ** |
| 3590 | ** Test the sqlite3_bind_double interface. STMT is a prepared statement. |
| 3591 | ** N is the index of a wildcard in the prepared statement. This command |
| 3592 | ** binds a 64-bit integer VALUE to that wildcard. |
| 3593 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3594 | static int SQLITE_TCLAPI test_bind_double( |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3595 | void * clientData, |
| 3596 | Tcl_Interp *interp, |
| 3597 | int objc, |
| 3598 | Tcl_Obj *CONST objv[] |
| 3599 | ){ |
| 3600 | sqlite3_stmt *pStmt; |
| 3601 | int idx; |
mistachkin | 27b2f05 | 2015-01-12 19:49:46 +0000 | [diff] [blame] | 3602 | double value = 0; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3603 | int rc; |
drh | a06f17f | 2008-05-11 11:07:06 +0000 | [diff] [blame] | 3604 | const char *zVal; |
| 3605 | int i; |
| 3606 | static const struct { |
| 3607 | const char *zName; /* Name of the special floating point value */ |
| 3608 | unsigned int iUpper; /* Upper 32 bits */ |
| 3609 | unsigned int iLower; /* Lower 32 bits */ |
| 3610 | } aSpecialFp[] = { |
| 3611 | { "NaN", 0x7fffffff, 0xffffffff }, |
| 3612 | { "SNaN", 0x7ff7ffff, 0xffffffff }, |
| 3613 | { "-NaN", 0xffffffff, 0xffffffff }, |
| 3614 | { "-SNaN", 0xfff7ffff, 0xffffffff }, |
| 3615 | { "+Inf", 0x7ff00000, 0x00000000 }, |
| 3616 | { "-Inf", 0xfff00000, 0x00000000 }, |
| 3617 | { "Epsilon", 0x00000000, 0x00000001 }, |
| 3618 | { "-Epsilon", 0x80000000, 0x00000001 }, |
| 3619 | { "NaN0", 0x7ff80000, 0x00000000 }, |
| 3620 | { "-NaN0", 0xfff80000, 0x00000000 }, |
| 3621 | }; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3622 | |
| 3623 | if( objc!=4 ){ |
| 3624 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3625 | Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3626 | return TCL_ERROR; |
| 3627 | } |
| 3628 | |
| 3629 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3630 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3631 | |
drh | 394f07e | 2008-04-28 15:23:02 +0000 | [diff] [blame] | 3632 | /* Intercept the string "NaN" and generate a NaN value for it. |
| 3633 | ** All other strings are passed through to Tcl_GetDoubleFromObj(). |
| 3634 | ** Tcl_GetDoubleFromObj() should understand "NaN" but some versions |
| 3635 | ** contain a bug. |
| 3636 | */ |
drh | a06f17f | 2008-05-11 11:07:06 +0000 | [diff] [blame] | 3637 | zVal = Tcl_GetString(objv[3]); |
| 3638 | for(i=0; i<sizeof(aSpecialFp)/sizeof(aSpecialFp[0]); i++){ |
| 3639 | if( strcmp(aSpecialFp[i].zName, zVal)==0 ){ |
| 3640 | sqlite3_uint64 x; |
| 3641 | x = aSpecialFp[i].iUpper; |
| 3642 | x <<= 32; |
| 3643 | x |= aSpecialFp[i].iLower; |
drh | 0a66733 | 2008-05-11 17:22:01 +0000 | [diff] [blame] | 3644 | assert( sizeof(value)==8 ); |
| 3645 | assert( sizeof(x)==8 ); |
| 3646 | memcpy(&value, &x, 8); |
drh | a06f17f | 2008-05-11 11:07:06 +0000 | [diff] [blame] | 3647 | break; |
| 3648 | } |
| 3649 | } |
| 3650 | if( i>=sizeof(aSpecialFp)/sizeof(aSpecialFp[0]) && |
| 3651 | Tcl_GetDoubleFromObj(interp, objv[3], &value) ){ |
drh | 394f07e | 2008-04-28 15:23:02 +0000 | [diff] [blame] | 3652 | return TCL_ERROR; |
| 3653 | } |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3654 | rc = sqlite3_bind_double(pStmt, idx, value); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3655 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3656 | if( rc!=SQLITE_OK ){ |
| 3657 | return TCL_ERROR; |
| 3658 | } |
| 3659 | |
| 3660 | return TCL_OK; |
| 3661 | } |
| 3662 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3663 | /* |
| 3664 | ** Usage: sqlite3_bind_null STMT N |
| 3665 | ** |
| 3666 | ** Test the sqlite3_bind_null interface. STMT is a prepared statement. |
| 3667 | ** N is the index of a wildcard in the prepared statement. This command |
| 3668 | ** binds a NULL to the wildcard. |
| 3669 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3670 | static int SQLITE_TCLAPI test_bind_null( |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3671 | void * clientData, |
| 3672 | Tcl_Interp *interp, |
| 3673 | int objc, |
| 3674 | Tcl_Obj *CONST objv[] |
| 3675 | ){ |
| 3676 | sqlite3_stmt *pStmt; |
| 3677 | int idx; |
| 3678 | int rc; |
| 3679 | |
| 3680 | if( objc!=3 ){ |
| 3681 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3682 | Tcl_GetStringFromObj(objv[0], 0), " STMT N", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3683 | return TCL_ERROR; |
| 3684 | } |
| 3685 | |
| 3686 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3687 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 3688 | |
| 3689 | rc = sqlite3_bind_null(pStmt, idx); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3690 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3691 | if( rc!=SQLITE_OK ){ |
| 3692 | return TCL_ERROR; |
| 3693 | } |
| 3694 | |
| 3695 | return TCL_OK; |
| 3696 | } |
| 3697 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3698 | /* |
| 3699 | ** Usage: sqlite3_bind_text STMT N STRING BYTES |
| 3700 | ** |
| 3701 | ** Test the sqlite3_bind_text interface. STMT is a prepared statement. |
| 3702 | ** N is the index of a wildcard in the prepared statement. This command |
| 3703 | ** binds a UTF-8 string STRING to the wildcard. The string is BYTES bytes |
| 3704 | ** long. |
| 3705 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3706 | static int SQLITE_TCLAPI test_bind_text( |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3707 | void * clientData, |
| 3708 | Tcl_Interp *interp, |
| 3709 | int objc, |
| 3710 | Tcl_Obj *CONST objv[] |
| 3711 | ){ |
| 3712 | sqlite3_stmt *pStmt; |
| 3713 | int idx; |
| 3714 | int bytes; |
| 3715 | char *value; |
| 3716 | int rc; |
| 3717 | |
| 3718 | if( objc!=5 ){ |
| 3719 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3720 | Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE BYTES", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3721 | return TCL_ERROR; |
| 3722 | } |
| 3723 | |
| 3724 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3725 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
drh | 10dfbbb | 2008-04-16 12:58:53 +0000 | [diff] [blame] | 3726 | value = (char*)Tcl_GetByteArrayFromObj(objv[3], &bytes); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3727 | if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR; |
| 3728 | |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 3729 | rc = sqlite3_bind_text(pStmt, idx, value, bytes, SQLITE_TRANSIENT); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3730 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3731 | if( rc!=SQLITE_OK ){ |
mistachkin | e84d8d3 | 2013-04-29 03:09:10 +0000 | [diff] [blame] | 3732 | Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3733 | return TCL_ERROR; |
| 3734 | } |
| 3735 | |
| 3736 | return TCL_OK; |
| 3737 | } |
| 3738 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3739 | /* |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 3740 | ** Usage: sqlite3_bind_text16 ?-static? STMT N STRING BYTES |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3741 | ** |
| 3742 | ** Test the sqlite3_bind_text16 interface. STMT is a prepared statement. |
| 3743 | ** N is the index of a wildcard in the prepared statement. This command |
| 3744 | ** binds a UTF-16 string STRING to the wildcard. The string is BYTES bytes |
| 3745 | ** long. |
| 3746 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3747 | static int SQLITE_TCLAPI test_bind_text16( |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3748 | void * clientData, |
| 3749 | Tcl_Interp *interp, |
| 3750 | int objc, |
| 3751 | Tcl_Obj *CONST objv[] |
| 3752 | ){ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 3753 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3754 | sqlite3_stmt *pStmt; |
| 3755 | int idx; |
| 3756 | int bytes; |
| 3757 | char *value; |
| 3758 | int rc; |
| 3759 | |
drh | 7da5fcb | 2012-03-30 14:59:43 +0000 | [diff] [blame] | 3760 | void (*xDel)(void*) = (objc==6?SQLITE_STATIC:SQLITE_TRANSIENT); |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 3761 | Tcl_Obj *oStmt = objv[objc-4]; |
| 3762 | Tcl_Obj *oN = objv[objc-3]; |
| 3763 | Tcl_Obj *oString = objv[objc-2]; |
| 3764 | Tcl_Obj *oBytes = objv[objc-1]; |
| 3765 | |
| 3766 | if( objc!=5 && objc!=6){ |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3767 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3768 | Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE BYTES", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3769 | return TCL_ERROR; |
| 3770 | } |
| 3771 | |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 3772 | if( getStmtPointer(interp, Tcl_GetString(oStmt), &pStmt) ) return TCL_ERROR; |
| 3773 | if( Tcl_GetIntFromObj(interp, oN, &idx) ) return TCL_ERROR; |
| 3774 | value = (char*)Tcl_GetByteArrayFromObj(oString, 0); |
| 3775 | if( Tcl_GetIntFromObj(interp, oBytes, &bytes) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3776 | |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 3777 | rc = sqlite3_bind_text16(pStmt, idx, (void *)value, bytes, xDel); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3778 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3779 | if( rc!=SQLITE_OK ){ |
mistachkin | e84d8d3 | 2013-04-29 03:09:10 +0000 | [diff] [blame] | 3780 | Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3781 | return TCL_ERROR; |
| 3782 | } |
| 3783 | |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 3784 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3785 | return TCL_OK; |
| 3786 | } |
| 3787 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3788 | /* |
danielk1977 | 5b159dc | 2007-05-17 16:34:43 +0000 | [diff] [blame] | 3789 | ** Usage: sqlite3_bind_blob ?-static? STMT N DATA BYTES |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3790 | ** |
| 3791 | ** Test the sqlite3_bind_blob interface. STMT is a prepared statement. |
| 3792 | ** N is the index of a wildcard in the prepared statement. This command |
| 3793 | ** binds a BLOB to the wildcard. The BLOB is BYTES bytes in size. |
| 3794 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3795 | static int SQLITE_TCLAPI test_bind_blob( |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3796 | void * clientData, |
| 3797 | Tcl_Interp *interp, |
| 3798 | int objc, |
| 3799 | Tcl_Obj *CONST objv[] |
| 3800 | ){ |
| 3801 | sqlite3_stmt *pStmt; |
mistachkin | de6fde6 | 2016-07-15 01:49:25 +0000 | [diff] [blame] | 3802 | int len, idx; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3803 | int bytes; |
| 3804 | char *value; |
| 3805 | int rc; |
danielk1977 | 5b159dc | 2007-05-17 16:34:43 +0000 | [diff] [blame] | 3806 | sqlite3_destructor_type xDestructor = SQLITE_TRANSIENT; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3807 | |
danielk1977 | 5b159dc | 2007-05-17 16:34:43 +0000 | [diff] [blame] | 3808 | if( objc!=5 && objc!=6 ){ |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3809 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3810 | Tcl_GetStringFromObj(objv[0], 0), " STMT N DATA BYTES", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3811 | return TCL_ERROR; |
| 3812 | } |
| 3813 | |
danielk1977 | 5b159dc | 2007-05-17 16:34:43 +0000 | [diff] [blame] | 3814 | if( objc==6 ){ |
| 3815 | xDestructor = SQLITE_STATIC; |
| 3816 | objv++; |
| 3817 | } |
| 3818 | |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3819 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3820 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
mistachkin | de6fde6 | 2016-07-15 01:49:25 +0000 | [diff] [blame] | 3821 | |
drh | 8d85364 | 2016-07-15 10:01:06 +0000 | [diff] [blame] | 3822 | value = (char*)Tcl_GetByteArrayFromObj(objv[3], &len); |
danielk1977 | 49e4643 | 2004-05-27 13:55:27 +0000 | [diff] [blame] | 3823 | if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3824 | |
mistachkin | de6fde6 | 2016-07-15 01:49:25 +0000 | [diff] [blame] | 3825 | if( bytes>len ){ |
| 3826 | char zBuf[200]; |
| 3827 | sqlite3_snprintf(sizeof(zBuf), zBuf, |
| 3828 | "cannot use %d blob bytes, have %d", bytes, len); |
| 3829 | Tcl_AppendResult(interp, zBuf, -1); |
| 3830 | return TCL_ERROR; |
| 3831 | } |
| 3832 | |
danielk1977 | 5b159dc | 2007-05-17 16:34:43 +0000 | [diff] [blame] | 3833 | rc = sqlite3_bind_blob(pStmt, idx, value, bytes, xDestructor); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3834 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 3835 | if( rc!=SQLITE_OK ){ |
| 3836 | return TCL_ERROR; |
| 3837 | } |
| 3838 | |
| 3839 | return TCL_OK; |
| 3840 | } |
| 3841 | |
drh | 99ee360 | 2003-02-16 19:13:36 +0000 | [diff] [blame] | 3842 | /* |
drh | 75f6a03 | 2004-07-15 14:15:00 +0000 | [diff] [blame] | 3843 | ** Usage: sqlite3_bind_parameter_count STMT |
| 3844 | ** |
| 3845 | ** Return the number of wildcards in the given statement. |
| 3846 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3847 | static int SQLITE_TCLAPI test_bind_parameter_count( |
drh | 75f6a03 | 2004-07-15 14:15:00 +0000 | [diff] [blame] | 3848 | void * clientData, |
| 3849 | Tcl_Interp *interp, |
| 3850 | int objc, |
| 3851 | Tcl_Obj *CONST objv[] |
| 3852 | ){ |
| 3853 | sqlite3_stmt *pStmt; |
| 3854 | |
| 3855 | if( objc!=2 ){ |
| 3856 | Tcl_WrongNumArgs(interp, 1, objv, "STMT"); |
| 3857 | return TCL_ERROR; |
| 3858 | } |
| 3859 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3860 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_bind_parameter_count(pStmt))); |
| 3861 | return TCL_OK; |
| 3862 | } |
| 3863 | |
| 3864 | /* |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 3865 | ** Usage: sqlite3_bind_parameter_name STMT N |
| 3866 | ** |
| 3867 | ** Return the name of the Nth wildcard. The first wildcard is 1. |
| 3868 | ** An empty string is returned if N is out of range or if the wildcard |
| 3869 | ** is nameless. |
| 3870 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3871 | static int SQLITE_TCLAPI test_bind_parameter_name( |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 3872 | void * clientData, |
| 3873 | Tcl_Interp *interp, |
| 3874 | int objc, |
| 3875 | Tcl_Obj *CONST objv[] |
| 3876 | ){ |
| 3877 | sqlite3_stmt *pStmt; |
| 3878 | int i; |
| 3879 | |
| 3880 | if( objc!=3 ){ |
| 3881 | Tcl_WrongNumArgs(interp, 1, objv, "STMT N"); |
| 3882 | return TCL_ERROR; |
| 3883 | } |
| 3884 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3885 | if( Tcl_GetIntFromObj(interp, objv[2], &i) ) return TCL_ERROR; |
| 3886 | Tcl_SetObjResult(interp, |
| 3887 | Tcl_NewStringObj(sqlite3_bind_parameter_name(pStmt,i),-1) |
| 3888 | ); |
| 3889 | return TCL_OK; |
| 3890 | } |
| 3891 | |
| 3892 | /* |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 3893 | ** Usage: sqlite3_bind_parameter_index STMT NAME |
| 3894 | ** |
| 3895 | ** Return the index of the wildcard called NAME. Return 0 if there is |
| 3896 | ** no such wildcard. |
| 3897 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3898 | static int SQLITE_TCLAPI test_bind_parameter_index( |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 3899 | void * clientData, |
| 3900 | Tcl_Interp *interp, |
| 3901 | int objc, |
| 3902 | Tcl_Obj *CONST objv[] |
| 3903 | ){ |
| 3904 | sqlite3_stmt *pStmt; |
| 3905 | |
| 3906 | if( objc!=3 ){ |
| 3907 | Tcl_WrongNumArgs(interp, 1, objv, "STMT NAME"); |
| 3908 | return TCL_ERROR; |
| 3909 | } |
| 3910 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3911 | Tcl_SetObjResult(interp, |
| 3912 | Tcl_NewIntObj( |
| 3913 | sqlite3_bind_parameter_index(pStmt,Tcl_GetString(objv[2])) |
| 3914 | ) |
| 3915 | ); |
| 3916 | return TCL_OK; |
| 3917 | } |
| 3918 | |
| 3919 | /* |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 3920 | ** Usage: sqlite3_clear_bindings STMT |
| 3921 | ** |
| 3922 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3923 | static int SQLITE_TCLAPI test_clear_bindings( |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 3924 | void * clientData, |
| 3925 | Tcl_Interp *interp, |
| 3926 | int objc, |
| 3927 | Tcl_Obj *CONST objv[] |
| 3928 | ){ |
| 3929 | sqlite3_stmt *pStmt; |
| 3930 | |
| 3931 | if( objc!=2 ){ |
| 3932 | Tcl_WrongNumArgs(interp, 1, objv, "STMT"); |
| 3933 | return TCL_ERROR; |
| 3934 | } |
| 3935 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3936 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_clear_bindings(pStmt))); |
| 3937 | return TCL_OK; |
| 3938 | } |
drh | f9cb7f5 | 2006-06-27 20:06:44 +0000 | [diff] [blame] | 3939 | |
| 3940 | /* |
| 3941 | ** Usage: sqlite3_sleep MILLISECONDS |
| 3942 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3943 | static int SQLITE_TCLAPI test_sleep( |
drh | f9cb7f5 | 2006-06-27 20:06:44 +0000 | [diff] [blame] | 3944 | void * clientData, |
| 3945 | Tcl_Interp *interp, |
| 3946 | int objc, |
| 3947 | Tcl_Obj *CONST objv[] |
| 3948 | ){ |
| 3949 | int ms; |
| 3950 | |
| 3951 | if( objc!=2 ){ |
| 3952 | Tcl_WrongNumArgs(interp, 1, objv, "MILLISECONDS"); |
| 3953 | return TCL_ERROR; |
| 3954 | } |
| 3955 | if( Tcl_GetIntFromObj(interp, objv[1], &ms) ){ |
| 3956 | return TCL_ERROR; |
| 3957 | } |
| 3958 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_sleep(ms))); |
| 3959 | return TCL_OK; |
| 3960 | } |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 3961 | |
| 3962 | /* |
drh | 99dfe5e | 2008-10-30 15:03:15 +0000 | [diff] [blame] | 3963 | ** Usage: sqlite3_extended_errcode DB |
| 3964 | ** |
| 3965 | ** Return the string representation of the most recent sqlite3_* API |
| 3966 | ** error code. e.g. "SQLITE_ERROR". |
| 3967 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3968 | static int SQLITE_TCLAPI test_ex_errcode( |
drh | 99dfe5e | 2008-10-30 15:03:15 +0000 | [diff] [blame] | 3969 | void * clientData, |
| 3970 | Tcl_Interp *interp, |
| 3971 | int objc, |
| 3972 | Tcl_Obj *CONST objv[] |
| 3973 | ){ |
| 3974 | sqlite3 *db; |
| 3975 | int rc; |
| 3976 | |
| 3977 | if( objc!=2 ){ |
| 3978 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3979 | Tcl_GetString(objv[0]), " DB", 0); |
| 3980 | return TCL_ERROR; |
| 3981 | } |
| 3982 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 3983 | rc = sqlite3_extended_errcode(db); |
| 3984 | Tcl_AppendResult(interp, (char *)t1ErrorName(rc), 0); |
| 3985 | return TCL_OK; |
| 3986 | } |
| 3987 | |
| 3988 | |
| 3989 | /* |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3990 | ** Usage: sqlite3_errcode DB |
| 3991 | ** |
| 3992 | ** Return the string representation of the most recent sqlite3_* API |
| 3993 | ** error code. e.g. "SQLITE_ERROR". |
| 3994 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 3995 | static int SQLITE_TCLAPI test_errcode( |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3996 | void * clientData, |
| 3997 | Tcl_Interp *interp, |
| 3998 | int objc, |
| 3999 | Tcl_Obj *CONST objv[] |
| 4000 | ){ |
| 4001 | sqlite3 *db; |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 4002 | int rc; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4003 | |
| 4004 | if( objc!=2 ){ |
| 4005 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4006 | Tcl_GetString(objv[0]), " DB", 0); |
| 4007 | return TCL_ERROR; |
| 4008 | } |
| 4009 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 4010 | rc = sqlite3_errcode(db); |
drh | 99dfe5e | 2008-10-30 15:03:15 +0000 | [diff] [blame] | 4011 | Tcl_AppendResult(interp, (char *)t1ErrorName(rc), 0); |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4012 | return TCL_OK; |
| 4013 | } |
| 4014 | |
| 4015 | /* |
danielk1977 | 0410302 | 2009-02-03 16:51:24 +0000 | [diff] [blame] | 4016 | ** Usage: sqlite3_errmsg DB |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4017 | ** |
| 4018 | ** Returns the UTF-8 representation of the error message string for the |
| 4019 | ** most recent sqlite3_* API call. |
| 4020 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4021 | static int SQLITE_TCLAPI test_errmsg( |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4022 | void * clientData, |
| 4023 | Tcl_Interp *interp, |
| 4024 | int objc, |
| 4025 | Tcl_Obj *CONST objv[] |
| 4026 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 4027 | sqlite3 *db; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4028 | const char *zErr; |
| 4029 | |
| 4030 | if( objc!=2 ){ |
| 4031 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4032 | Tcl_GetString(objv[0]), " DB", 0); |
| 4033 | return TCL_ERROR; |
| 4034 | } |
| 4035 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 4036 | |
| 4037 | zErr = sqlite3_errmsg(db); |
| 4038 | Tcl_SetObjResult(interp, Tcl_NewStringObj(zErr, -1)); |
| 4039 | return TCL_OK; |
| 4040 | } |
| 4041 | |
| 4042 | /* |
| 4043 | ** Usage: test_errmsg16 DB |
| 4044 | ** |
| 4045 | ** Returns the UTF-16 representation of the error message string for the |
| 4046 | ** most recent sqlite3_* API call. This is a byte array object at the TCL |
| 4047 | ** level, and it includes the 0x00 0x00 terminator bytes at the end of the |
| 4048 | ** UTF-16 string. |
| 4049 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4050 | static int SQLITE_TCLAPI test_errmsg16( |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4051 | void * clientData, |
| 4052 | Tcl_Interp *interp, |
| 4053 | int objc, |
| 4054 | Tcl_Obj *CONST objv[] |
| 4055 | ){ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 4056 | #ifndef SQLITE_OMIT_UTF16 |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 4057 | sqlite3 *db; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4058 | const void *zErr; |
drh | aed382f | 2009-04-01 18:40:32 +0000 | [diff] [blame] | 4059 | const char *z; |
danielk1977 | 950f054 | 2006-01-18 05:51:57 +0000 | [diff] [blame] | 4060 | int bytes = 0; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4061 | |
| 4062 | if( objc!=2 ){ |
| 4063 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4064 | Tcl_GetString(objv[0]), " DB", 0); |
| 4065 | return TCL_ERROR; |
| 4066 | } |
| 4067 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 4068 | |
| 4069 | zErr = sqlite3_errmsg16(db); |
danielk1977 | 950f054 | 2006-01-18 05:51:57 +0000 | [diff] [blame] | 4070 | if( zErr ){ |
drh | aed382f | 2009-04-01 18:40:32 +0000 | [diff] [blame] | 4071 | z = zErr; |
| 4072 | for(bytes=0; z[bytes] || z[bytes+1]; bytes+=2){} |
danielk1977 | 950f054 | 2006-01-18 05:51:57 +0000 | [diff] [blame] | 4073 | } |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4074 | Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(zErr, bytes)); |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 4075 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4076 | return TCL_OK; |
| 4077 | } |
| 4078 | |
| 4079 | /* |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4080 | ** Usage: sqlite3_prepare DB sql bytes ?tailvar? |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4081 | ** |
| 4082 | ** Compile up to <bytes> bytes of the supplied SQL string <sql> using |
| 4083 | ** database handle <DB>. The parameter <tailval> is the name of a global |
| 4084 | ** variable that is set to the unused portion of <sql> (if any). A |
| 4085 | ** STMT handle is returned. |
| 4086 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4087 | static int SQLITE_TCLAPI test_prepare( |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4088 | void * clientData, |
| 4089 | Tcl_Interp *interp, |
| 4090 | int objc, |
| 4091 | Tcl_Obj *CONST objv[] |
| 4092 | ){ |
| 4093 | sqlite3 *db; |
| 4094 | const char *zSql; |
| 4095 | int bytes; |
| 4096 | const char *zTail = 0; |
| 4097 | sqlite3_stmt *pStmt = 0; |
| 4098 | char zBuf[50]; |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4099 | int rc; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4100 | |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4101 | if( objc!=5 && objc!=4 ){ |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4102 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4103 | Tcl_GetString(objv[0]), " DB sql bytes ?tailvar?", 0); |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4104 | return TCL_ERROR; |
| 4105 | } |
| 4106 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 4107 | zSql = Tcl_GetString(objv[2]); |
| 4108 | if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; |
| 4109 | |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4110 | rc = sqlite3_prepare(db, zSql, bytes, &pStmt, objc>=5 ? &zTail : 0); |
dan | 937d0de | 2009-10-15 18:35:38 +0000 | [diff] [blame] | 4111 | Tcl_ResetResult(interp); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 4112 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4113 | if( zTail && objc>=5 ){ |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4114 | if( bytes>=0 ){ |
drh | 83cc139 | 2012-04-19 18:04:28 +0000 | [diff] [blame] | 4115 | bytes = bytes - (int)(zTail-zSql); |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4116 | } |
drh | 7da5fcb | 2012-03-30 14:59:43 +0000 | [diff] [blame] | 4117 | if( (int)strlen(zTail)<bytes ){ |
drh | 83cc139 | 2012-04-19 18:04:28 +0000 | [diff] [blame] | 4118 | bytes = (int)strlen(zTail); |
danielk1977 | 3a2c8c8 | 2008-04-03 14:36:25 +0000 | [diff] [blame] | 4119 | } |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4120 | Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0); |
| 4121 | } |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4122 | if( rc!=SQLITE_OK ){ |
| 4123 | assert( pStmt==0 ); |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 4124 | sqlite3_snprintf(sizeof(zBuf), zBuf, "(%d) ", rc); |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4125 | Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0); |
| 4126 | return TCL_ERROR; |
| 4127 | } |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4128 | |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4129 | if( pStmt ){ |
drh | 64b1bea | 2006-01-15 02:30:57 +0000 | [diff] [blame] | 4130 | if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4131 | Tcl_AppendResult(interp, zBuf, 0); |
| 4132 | } |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4133 | return TCL_OK; |
| 4134 | } |
| 4135 | |
| 4136 | /* |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4137 | ** Usage: sqlite3_prepare_v2 DB sql bytes ?tailvar? |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4138 | ** |
| 4139 | ** Compile up to <bytes> bytes of the supplied SQL string <sql> using |
| 4140 | ** database handle <DB>. The parameter <tailval> is the name of a global |
| 4141 | ** variable that is set to the unused portion of <sql> (if any). A |
| 4142 | ** STMT handle is returned. |
| 4143 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4144 | static int SQLITE_TCLAPI test_prepare_v2( |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4145 | void * clientData, |
| 4146 | Tcl_Interp *interp, |
| 4147 | int objc, |
| 4148 | Tcl_Obj *CONST objv[] |
| 4149 | ){ |
| 4150 | sqlite3 *db; |
| 4151 | const char *zSql; |
dan | d89b834 | 2014-11-27 11:36:36 +0000 | [diff] [blame] | 4152 | char *zCopy = 0; /* malloc() copy of zSql */ |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4153 | int bytes; |
| 4154 | const char *zTail = 0; |
| 4155 | sqlite3_stmt *pStmt = 0; |
| 4156 | char zBuf[50]; |
| 4157 | int rc; |
| 4158 | |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4159 | if( objc!=5 && objc!=4 ){ |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4160 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4161 | Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0); |
| 4162 | return TCL_ERROR; |
| 4163 | } |
| 4164 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 4165 | zSql = Tcl_GetString(objv[2]); |
| 4166 | if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; |
| 4167 | |
dan | d89b834 | 2014-11-27 11:36:36 +0000 | [diff] [blame] | 4168 | /* Instead of using zSql directly, make a copy into a buffer obtained |
| 4169 | ** directly from malloc(). The idea is to make it easier for valgrind |
| 4170 | ** to spot buffer overreads. */ |
| 4171 | if( bytes>=0 ){ |
| 4172 | zCopy = malloc(bytes); |
| 4173 | memcpy(zCopy, zSql, bytes); |
| 4174 | }else{ |
drh | 2c3abeb | 2014-12-05 00:32:09 +0000 | [diff] [blame] | 4175 | int n = (int)strlen(zSql) + 1; |
dan | d89b834 | 2014-11-27 11:36:36 +0000 | [diff] [blame] | 4176 | zCopy = malloc(n); |
| 4177 | memcpy(zCopy, zSql, n); |
| 4178 | } |
| 4179 | rc = sqlite3_prepare_v2(db, zCopy, bytes, &pStmt, objc>=5 ? &zTail : 0); |
| 4180 | free(zCopy); |
| 4181 | zTail = &zSql[(zTail - zCopy)]; |
| 4182 | |
danielk1977 | 7e29e95 | 2007-04-19 11:09:01 +0000 | [diff] [blame] | 4183 | assert(rc==SQLITE_OK || pStmt==0); |
dan | 937d0de | 2009-10-15 18:35:38 +0000 | [diff] [blame] | 4184 | Tcl_ResetResult(interp); |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4185 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
drh | e5d7bf1 | 2014-12-23 20:05:19 +0000 | [diff] [blame] | 4186 | if( rc==SQLITE_OK && zTail && objc>=5 ){ |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4187 | if( bytes>=0 ){ |
drh | 83cc139 | 2012-04-19 18:04:28 +0000 | [diff] [blame] | 4188 | bytes = bytes - (int)(zTail-zSql); |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4189 | } |
| 4190 | Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0); |
| 4191 | } |
| 4192 | if( rc!=SQLITE_OK ){ |
| 4193 | assert( pStmt==0 ); |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 4194 | sqlite3_snprintf(sizeof(zBuf), zBuf, "(%d) ", rc); |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4195 | Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0); |
| 4196 | return TCL_ERROR; |
| 4197 | } |
| 4198 | |
| 4199 | if( pStmt ){ |
| 4200 | if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; |
| 4201 | Tcl_AppendResult(interp, zBuf, 0); |
| 4202 | } |
| 4203 | return TCL_OK; |
| 4204 | } |
| 4205 | |
| 4206 | /* |
drh | 4837f53 | 2008-05-23 14:49:49 +0000 | [diff] [blame] | 4207 | ** Usage: sqlite3_prepare_tkt3134 DB |
| 4208 | ** |
| 4209 | ** Generate a prepared statement for a zero-byte string as a test |
peter.d.reid | 60ec914 | 2014-09-06 16:39:46 +0000 | [diff] [blame] | 4210 | ** for ticket #3134. The string should be preceded by a zero byte. |
drh | 4837f53 | 2008-05-23 14:49:49 +0000 | [diff] [blame] | 4211 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4212 | static int SQLITE_TCLAPI test_prepare_tkt3134( |
drh | 4837f53 | 2008-05-23 14:49:49 +0000 | [diff] [blame] | 4213 | void * clientData, |
| 4214 | Tcl_Interp *interp, |
| 4215 | int objc, |
| 4216 | Tcl_Obj *CONST objv[] |
| 4217 | ){ |
| 4218 | sqlite3 *db; |
| 4219 | static const char zSql[] = "\000SELECT 1"; |
| 4220 | sqlite3_stmt *pStmt = 0; |
| 4221 | char zBuf[50]; |
| 4222 | int rc; |
| 4223 | |
| 4224 | if( objc!=2 ){ |
| 4225 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4226 | Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0); |
| 4227 | return TCL_ERROR; |
| 4228 | } |
| 4229 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 4230 | rc = sqlite3_prepare_v2(db, &zSql[1], 0, &pStmt, 0); |
| 4231 | assert(rc==SQLITE_OK || pStmt==0); |
| 4232 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
| 4233 | if( rc!=SQLITE_OK ){ |
| 4234 | assert( pStmt==0 ); |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 4235 | sqlite3_snprintf(sizeof(zBuf), zBuf, "(%d) ", rc); |
drh | 4837f53 | 2008-05-23 14:49:49 +0000 | [diff] [blame] | 4236 | Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0); |
| 4237 | return TCL_ERROR; |
| 4238 | } |
| 4239 | |
| 4240 | if( pStmt ){ |
| 4241 | if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; |
| 4242 | Tcl_AppendResult(interp, zBuf, 0); |
| 4243 | } |
| 4244 | return TCL_OK; |
| 4245 | } |
| 4246 | |
| 4247 | /* |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4248 | ** Usage: sqlite3_prepare16 DB sql bytes tailvar |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4249 | ** |
| 4250 | ** Compile up to <bytes> bytes of the supplied SQL string <sql> using |
| 4251 | ** database handle <DB>. The parameter <tailval> is the name of a global |
| 4252 | ** variable that is set to the unused portion of <sql> (if any). A |
| 4253 | ** STMT handle is returned. |
| 4254 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4255 | static int SQLITE_TCLAPI test_prepare16( |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4256 | void * clientData, |
| 4257 | Tcl_Interp *interp, |
| 4258 | int objc, |
| 4259 | Tcl_Obj *CONST objv[] |
| 4260 | ){ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 4261 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4262 | sqlite3 *db; |
| 4263 | const void *zSql; |
| 4264 | const void *zTail = 0; |
| 4265 | Tcl_Obj *pTail = 0; |
| 4266 | sqlite3_stmt *pStmt = 0; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 4267 | char zBuf[50]; |
| 4268 | int rc; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4269 | int bytes; /* The integer specified as arg 3 */ |
| 4270 | int objlen; /* The byte-array length of arg 2 */ |
| 4271 | |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4272 | if( objc!=5 && objc!=4 ){ |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4273 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4274 | Tcl_GetString(objv[0]), " DB sql bytes ?tailvar?", 0); |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4275 | return TCL_ERROR; |
| 4276 | } |
| 4277 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 4278 | zSql = Tcl_GetByteArrayFromObj(objv[2], &objlen); |
| 4279 | if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; |
| 4280 | |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4281 | rc = sqlite3_prepare16(db, zSql, bytes, &pStmt, objc>=5 ? &zTail : 0); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 4282 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
| 4283 | if( rc ){ |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4284 | return TCL_ERROR; |
| 4285 | } |
| 4286 | |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4287 | if( objc>=5 ){ |
| 4288 | if( zTail ){ |
drh | 83cc139 | 2012-04-19 18:04:28 +0000 | [diff] [blame] | 4289 | objlen = objlen - (int)((u8 *)zTail-(u8 *)zSql); |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4290 | }else{ |
| 4291 | objlen = 0; |
| 4292 | } |
| 4293 | pTail = Tcl_NewByteArrayObj((u8 *)zTail, objlen); |
| 4294 | Tcl_IncrRefCount(pTail); |
| 4295 | Tcl_ObjSetVar2(interp, objv[4], 0, pTail, 0); |
| 4296 | Tcl_DecrRefCount(pTail); |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4297 | } |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4298 | |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4299 | if( pStmt ){ |
drh | 64b1bea | 2006-01-15 02:30:57 +0000 | [diff] [blame] | 4300 | if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4301 | } |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4302 | Tcl_AppendResult(interp, zBuf, 0); |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 4303 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4304 | return TCL_OK; |
| 4305 | } |
| 4306 | |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4307 | /* |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4308 | ** Usage: sqlite3_prepare16_v2 DB sql bytes ?tailvar? |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4309 | ** |
| 4310 | ** Compile up to <bytes> bytes of the supplied SQL string <sql> using |
| 4311 | ** database handle <DB>. The parameter <tailval> is the name of a global |
| 4312 | ** variable that is set to the unused portion of <sql> (if any). A |
| 4313 | ** STMT handle is returned. |
| 4314 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4315 | static int SQLITE_TCLAPI test_prepare16_v2( |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4316 | void * clientData, |
| 4317 | Tcl_Interp *interp, |
| 4318 | int objc, |
| 4319 | Tcl_Obj *CONST objv[] |
| 4320 | ){ |
| 4321 | #ifndef SQLITE_OMIT_UTF16 |
| 4322 | sqlite3 *db; |
| 4323 | const void *zSql; |
| 4324 | const void *zTail = 0; |
| 4325 | Tcl_Obj *pTail = 0; |
| 4326 | sqlite3_stmt *pStmt = 0; |
| 4327 | char zBuf[50]; |
| 4328 | int rc; |
| 4329 | int bytes; /* The integer specified as arg 3 */ |
| 4330 | int objlen; /* The byte-array length of arg 2 */ |
| 4331 | |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4332 | if( objc!=5 && objc!=4 ){ |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4333 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4334 | Tcl_GetString(objv[0]), " DB sql bytes ?tailvar?", 0); |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4335 | return TCL_ERROR; |
| 4336 | } |
| 4337 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 4338 | zSql = Tcl_GetByteArrayFromObj(objv[2], &objlen); |
| 4339 | if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; |
| 4340 | |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4341 | rc = sqlite3_prepare16_v2(db, zSql, bytes, &pStmt, objc>=5 ? &zTail : 0); |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4342 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
| 4343 | if( rc ){ |
| 4344 | return TCL_ERROR; |
| 4345 | } |
| 4346 | |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4347 | if( objc>=5 ){ |
| 4348 | if( zTail ){ |
drh | 83cc139 | 2012-04-19 18:04:28 +0000 | [diff] [blame] | 4349 | objlen = objlen - (int)((u8 *)zTail-(u8 *)zSql); |
drh | 1c767f0 | 2009-01-09 02:49:31 +0000 | [diff] [blame] | 4350 | }else{ |
| 4351 | objlen = 0; |
| 4352 | } |
| 4353 | pTail = Tcl_NewByteArrayObj((u8 *)zTail, objlen); |
| 4354 | Tcl_IncrRefCount(pTail); |
| 4355 | Tcl_ObjSetVar2(interp, objv[4], 0, pTail, 0); |
| 4356 | Tcl_DecrRefCount(pTail); |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4357 | } |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4358 | |
| 4359 | if( pStmt ){ |
| 4360 | if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; |
| 4361 | } |
| 4362 | Tcl_AppendResult(interp, zBuf, 0); |
| 4363 | #endif /* SQLITE_OMIT_UTF16 */ |
| 4364 | return TCL_OK; |
| 4365 | } |
| 4366 | |
| 4367 | /* |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4368 | ** Usage: sqlite3_open filename ?options-list? |
| 4369 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4370 | static int SQLITE_TCLAPI test_open( |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4371 | void * clientData, |
| 4372 | Tcl_Interp *interp, |
| 4373 | int objc, |
| 4374 | Tcl_Obj *CONST objv[] |
| 4375 | ){ |
| 4376 | const char *zFilename; |
| 4377 | sqlite3 *db; |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4378 | char zBuf[100]; |
| 4379 | |
drh | afc9104 | 2008-02-21 02:09:45 +0000 | [diff] [blame] | 4380 | if( objc!=3 && objc!=2 && objc!=1 ){ |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4381 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4382 | Tcl_GetString(objv[0]), " filename options-list", 0); |
| 4383 | return TCL_ERROR; |
| 4384 | } |
| 4385 | |
drh | afc9104 | 2008-02-21 02:09:45 +0000 | [diff] [blame] | 4386 | zFilename = objc>1 ? Tcl_GetString(objv[1]) : 0; |
drh | caffb1a | 2012-01-30 18:00:31 +0000 | [diff] [blame] | 4387 | sqlite3_open(zFilename, &db); |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4388 | |
drh | 64b1bea | 2006-01-15 02:30:57 +0000 | [diff] [blame] | 4389 | if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR; |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4390 | Tcl_AppendResult(interp, zBuf, 0); |
| 4391 | return TCL_OK; |
| 4392 | } |
| 4393 | |
| 4394 | /* |
dan | 286ab7c | 2011-05-06 18:34:54 +0000 | [diff] [blame] | 4395 | ** Usage: sqlite3_open_v2 FILENAME FLAGS VFS |
| 4396 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4397 | static int SQLITE_TCLAPI test_open_v2( |
dan | 286ab7c | 2011-05-06 18:34:54 +0000 | [diff] [blame] | 4398 | void * clientData, |
| 4399 | Tcl_Interp *interp, |
| 4400 | int objc, |
| 4401 | Tcl_Obj *CONST objv[] |
| 4402 | ){ |
| 4403 | const char *zFilename; |
| 4404 | const char *zVfs; |
| 4405 | int flags = 0; |
| 4406 | sqlite3 *db; |
| 4407 | int rc; |
| 4408 | char zBuf[100]; |
| 4409 | |
| 4410 | int nFlag; |
| 4411 | Tcl_Obj **apFlag; |
| 4412 | int i; |
| 4413 | |
| 4414 | if( objc!=4 ){ |
| 4415 | Tcl_WrongNumArgs(interp, 1, objv, "FILENAME FLAGS VFS"); |
| 4416 | return TCL_ERROR; |
| 4417 | } |
| 4418 | zFilename = Tcl_GetString(objv[1]); |
| 4419 | zVfs = Tcl_GetString(objv[3]); |
| 4420 | if( zVfs[0]==0x00 ) zVfs = 0; |
| 4421 | |
| 4422 | rc = Tcl_ListObjGetElements(interp, objv[2], &nFlag, &apFlag); |
| 4423 | if( rc!=TCL_OK ) return rc; |
| 4424 | for(i=0; i<nFlag; i++){ |
| 4425 | int iFlag; |
| 4426 | struct OpenFlag { |
| 4427 | const char *zFlag; |
| 4428 | int flag; |
| 4429 | } aFlag[] = { |
| 4430 | { "SQLITE_OPEN_READONLY", SQLITE_OPEN_READONLY }, |
| 4431 | { "SQLITE_OPEN_READWRITE", SQLITE_OPEN_READWRITE }, |
| 4432 | { "SQLITE_OPEN_CREATE", SQLITE_OPEN_CREATE }, |
| 4433 | { "SQLITE_OPEN_DELETEONCLOSE", SQLITE_OPEN_DELETEONCLOSE }, |
| 4434 | { "SQLITE_OPEN_EXCLUSIVE", SQLITE_OPEN_EXCLUSIVE }, |
| 4435 | { "SQLITE_OPEN_AUTOPROXY", SQLITE_OPEN_AUTOPROXY }, |
| 4436 | { "SQLITE_OPEN_MAIN_DB", SQLITE_OPEN_MAIN_DB }, |
| 4437 | { "SQLITE_OPEN_TEMP_DB", SQLITE_OPEN_TEMP_DB }, |
| 4438 | { "SQLITE_OPEN_TRANSIENT_DB", SQLITE_OPEN_TRANSIENT_DB }, |
| 4439 | { "SQLITE_OPEN_MAIN_JOURNAL", SQLITE_OPEN_MAIN_JOURNAL }, |
| 4440 | { "SQLITE_OPEN_TEMP_JOURNAL", SQLITE_OPEN_TEMP_JOURNAL }, |
| 4441 | { "SQLITE_OPEN_SUBJOURNAL", SQLITE_OPEN_SUBJOURNAL }, |
| 4442 | { "SQLITE_OPEN_MASTER_JOURNAL", SQLITE_OPEN_MASTER_JOURNAL }, |
| 4443 | { "SQLITE_OPEN_NOMUTEX", SQLITE_OPEN_NOMUTEX }, |
| 4444 | { "SQLITE_OPEN_FULLMUTEX", SQLITE_OPEN_FULLMUTEX }, |
| 4445 | { "SQLITE_OPEN_SHAREDCACHE", SQLITE_OPEN_SHAREDCACHE }, |
| 4446 | { "SQLITE_OPEN_PRIVATECACHE", SQLITE_OPEN_PRIVATECACHE }, |
| 4447 | { "SQLITE_OPEN_WAL", SQLITE_OPEN_WAL }, |
| 4448 | { "SQLITE_OPEN_URI", SQLITE_OPEN_URI }, |
| 4449 | { 0, 0 } |
| 4450 | }; |
| 4451 | rc = Tcl_GetIndexFromObjStruct(interp, apFlag[i], aFlag, sizeof(aFlag[0]), |
| 4452 | "flag", 0, &iFlag |
| 4453 | ); |
| 4454 | if( rc!=TCL_OK ) return rc; |
| 4455 | flags |= aFlag[iFlag].flag; |
| 4456 | } |
| 4457 | |
| 4458 | rc = sqlite3_open_v2(zFilename, &db, flags, zVfs); |
| 4459 | if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR; |
| 4460 | Tcl_AppendResult(interp, zBuf, 0); |
| 4461 | return TCL_OK; |
| 4462 | } |
| 4463 | |
| 4464 | /* |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4465 | ** Usage: sqlite3_open16 filename options |
| 4466 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4467 | static int SQLITE_TCLAPI test_open16( |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4468 | void * clientData, |
| 4469 | Tcl_Interp *interp, |
| 4470 | int objc, |
| 4471 | Tcl_Obj *CONST objv[] |
| 4472 | ){ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 4473 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4474 | const void *zFilename; |
| 4475 | sqlite3 *db; |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4476 | char zBuf[100]; |
| 4477 | |
| 4478 | if( objc!=3 ){ |
| 4479 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4480 | Tcl_GetString(objv[0]), " filename options-list", 0); |
| 4481 | return TCL_ERROR; |
| 4482 | } |
| 4483 | |
| 4484 | zFilename = Tcl_GetByteArrayFromObj(objv[1], 0); |
drh | caffb1a | 2012-01-30 18:00:31 +0000 | [diff] [blame] | 4485 | sqlite3_open16(zFilename, &db); |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4486 | |
drh | 64b1bea | 2006-01-15 02:30:57 +0000 | [diff] [blame] | 4487 | if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR; |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4488 | Tcl_AppendResult(interp, zBuf, 0); |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 4489 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 4490 | return TCL_OK; |
| 4491 | } |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 4492 | |
| 4493 | /* |
danielk1977 | bc6ada4 | 2004-06-30 08:20:16 +0000 | [diff] [blame] | 4494 | ** Usage: sqlite3_complete16 <UTF-16 string> |
| 4495 | ** |
| 4496 | ** Return 1 if the supplied argument is a complete SQL statement, or zero |
| 4497 | ** otherwise. |
| 4498 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4499 | static int SQLITE_TCLAPI test_complete16( |
danielk1977 | bc6ada4 | 2004-06-30 08:20:16 +0000 | [diff] [blame] | 4500 | void * clientData, |
| 4501 | Tcl_Interp *interp, |
| 4502 | int objc, |
| 4503 | Tcl_Obj *CONST objv[] |
| 4504 | ){ |
drh | ccae602 | 2005-02-26 17:31:26 +0000 | [diff] [blame] | 4505 | #if !defined(SQLITE_OMIT_COMPLETE) && !defined(SQLITE_OMIT_UTF16) |
danielk1977 | bc6ada4 | 2004-06-30 08:20:16 +0000 | [diff] [blame] | 4506 | char *zBuf; |
| 4507 | |
| 4508 | if( objc!=2 ){ |
| 4509 | Tcl_WrongNumArgs(interp, 1, objv, "<utf-16 sql>"); |
| 4510 | return TCL_ERROR; |
| 4511 | } |
| 4512 | |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 4513 | zBuf = (char*)Tcl_GetByteArrayFromObj(objv[1], 0); |
danielk1977 | bc6ada4 | 2004-06-30 08:20:16 +0000 | [diff] [blame] | 4514 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_complete16(zBuf))); |
drh | ccae602 | 2005-02-26 17:31:26 +0000 | [diff] [blame] | 4515 | #endif /* SQLITE_OMIT_COMPLETE && SQLITE_OMIT_UTF16 */ |
danielk1977 | bc6ada4 | 2004-06-30 08:20:16 +0000 | [diff] [blame] | 4516 | return TCL_OK; |
| 4517 | } |
| 4518 | |
| 4519 | /* |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 4520 | ** Usage: sqlite3_step STMT |
| 4521 | ** |
| 4522 | ** Advance the statement to the next row. |
| 4523 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4524 | static int SQLITE_TCLAPI test_step( |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 4525 | void * clientData, |
| 4526 | Tcl_Interp *interp, |
| 4527 | int objc, |
| 4528 | Tcl_Obj *CONST objv[] |
| 4529 | ){ |
| 4530 | sqlite3_stmt *pStmt; |
| 4531 | int rc; |
| 4532 | |
danielk1977 | e1cd987 | 2004-05-22 10:33:04 +0000 | [diff] [blame] | 4533 | if( objc!=2 ){ |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 4534 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4535 | Tcl_GetString(objv[0]), " STMT", 0); |
| 4536 | return TCL_ERROR; |
| 4537 | } |
| 4538 | |
| 4539 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
danielk1977 | 17240fd | 2004-05-26 00:07:25 +0000 | [diff] [blame] | 4540 | rc = sqlite3_step(pStmt); |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 4541 | |
danielk1977 | fbcd585 | 2004-06-15 02:44:18 +0000 | [diff] [blame] | 4542 | /* if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; */ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 4543 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0); |
danielk1977 | e1cd987 | 2004-05-22 10:33:04 +0000 | [diff] [blame] | 4544 | return TCL_OK; |
| 4545 | } |
| 4546 | |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4547 | static int SQLITE_TCLAPI test_sql( |
danielk1977 | 404ca07 | 2009-03-16 13:19:36 +0000 | [diff] [blame] | 4548 | void * clientData, |
| 4549 | Tcl_Interp *interp, |
| 4550 | int objc, |
| 4551 | Tcl_Obj *CONST objv[] |
| 4552 | ){ |
| 4553 | sqlite3_stmt *pStmt; |
| 4554 | |
| 4555 | if( objc!=2 ){ |
| 4556 | Tcl_WrongNumArgs(interp, 1, objv, "STMT"); |
| 4557 | return TCL_ERROR; |
| 4558 | } |
| 4559 | |
| 4560 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 4561 | Tcl_SetResult(interp, (char *)sqlite3_sql(pStmt), TCL_VOLATILE); |
| 4562 | return TCL_OK; |
| 4563 | } |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4564 | static int SQLITE_TCLAPI test_ex_sql( |
drh | fca760c | 2016-07-14 01:09:08 +0000 | [diff] [blame] | 4565 | void * clientData, |
| 4566 | Tcl_Interp *interp, |
| 4567 | int objc, |
| 4568 | Tcl_Obj *CONST objv[] |
| 4569 | ){ |
| 4570 | sqlite3_stmt *pStmt; |
| 4571 | char *z; |
| 4572 | |
| 4573 | if( objc!=2 ){ |
| 4574 | Tcl_WrongNumArgs(interp, 1, objv, "STMT"); |
| 4575 | return TCL_ERROR; |
| 4576 | } |
| 4577 | |
| 4578 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 4579 | z = sqlite3_expanded_sql(pStmt); |
| 4580 | Tcl_SetResult(interp, z, TCL_VOLATILE); |
| 4581 | sqlite3_free(z); |
| 4582 | return TCL_OK; |
| 4583 | } |
danielk1977 | 404ca07 | 2009-03-16 13:19:36 +0000 | [diff] [blame] | 4584 | |
danielk1977 | e1cd987 | 2004-05-22 10:33:04 +0000 | [diff] [blame] | 4585 | /* |
danielk1977 | 17240fd | 2004-05-26 00:07:25 +0000 | [diff] [blame] | 4586 | ** Usage: sqlite3_column_count STMT |
| 4587 | ** |
| 4588 | ** Return the number of columns returned by the sql statement STMT. |
| 4589 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4590 | static int SQLITE_TCLAPI test_column_count( |
danielk1977 | 17240fd | 2004-05-26 00:07:25 +0000 | [diff] [blame] | 4591 | void * clientData, |
| 4592 | Tcl_Interp *interp, |
| 4593 | int objc, |
| 4594 | Tcl_Obj *CONST objv[] |
| 4595 | ){ |
| 4596 | sqlite3_stmt *pStmt; |
| 4597 | |
| 4598 | if( objc!=2 ){ |
| 4599 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4600 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 4601 | return TCL_ERROR; |
| 4602 | } |
| 4603 | |
| 4604 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 4605 | |
| 4606 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_column_count(pStmt))); |
| 4607 | return TCL_OK; |
| 4608 | } |
| 4609 | |
| 4610 | /* |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 4611 | ** Usage: sqlite3_column_type STMT column |
| 4612 | ** |
| 4613 | ** Return the type of the data in column 'column' of the current row. |
| 4614 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4615 | static int SQLITE_TCLAPI test_column_type( |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 4616 | void * clientData, |
| 4617 | Tcl_Interp *interp, |
| 4618 | int objc, |
| 4619 | Tcl_Obj *CONST objv[] |
| 4620 | ){ |
| 4621 | sqlite3_stmt *pStmt; |
| 4622 | int col; |
| 4623 | int tp; |
| 4624 | |
| 4625 | if( objc!=3 ){ |
| 4626 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4627 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 4628 | return TCL_ERROR; |
| 4629 | } |
| 4630 | |
| 4631 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 4632 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
| 4633 | |
| 4634 | tp = sqlite3_column_type(pStmt, col); |
| 4635 | switch( tp ){ |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 4636 | case SQLITE_INTEGER: |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 4637 | Tcl_SetResult(interp, "INTEGER", TCL_STATIC); |
| 4638 | break; |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 4639 | case SQLITE_NULL: |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 4640 | Tcl_SetResult(interp, "NULL", TCL_STATIC); |
| 4641 | break; |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 4642 | case SQLITE_FLOAT: |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 4643 | Tcl_SetResult(interp, "FLOAT", TCL_STATIC); |
| 4644 | break; |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 4645 | case SQLITE_TEXT: |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 4646 | Tcl_SetResult(interp, "TEXT", TCL_STATIC); |
| 4647 | break; |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 4648 | case SQLITE_BLOB: |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 4649 | Tcl_SetResult(interp, "BLOB", TCL_STATIC); |
| 4650 | break; |
| 4651 | default: |
| 4652 | assert(0); |
| 4653 | } |
| 4654 | |
| 4655 | return TCL_OK; |
| 4656 | } |
| 4657 | |
| 4658 | /* |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4659 | ** Usage: sqlite3_column_int64 STMT column |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 4660 | ** |
| 4661 | ** Return the data in column 'column' of the current row cast as an |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4662 | ** wide (64-bit) integer. |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 4663 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4664 | static int SQLITE_TCLAPI test_column_int64( |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 4665 | void * clientData, |
| 4666 | Tcl_Interp *interp, |
| 4667 | int objc, |
| 4668 | Tcl_Obj *CONST objv[] |
| 4669 | ){ |
| 4670 | sqlite3_stmt *pStmt; |
| 4671 | int col; |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4672 | i64 iVal; |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 4673 | |
| 4674 | if( objc!=3 ){ |
| 4675 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4676 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 4677 | return TCL_ERROR; |
| 4678 | } |
| 4679 | |
| 4680 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 4681 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
| 4682 | |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4683 | iVal = sqlite3_column_int64(pStmt, col); |
| 4684 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj(iVal)); |
| 4685 | return TCL_OK; |
| 4686 | } |
| 4687 | |
| 4688 | /* |
danielk1977 | ea61b2c | 2004-05-27 01:49:51 +0000 | [diff] [blame] | 4689 | ** Usage: sqlite3_column_blob STMT column |
| 4690 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4691 | static int SQLITE_TCLAPI test_column_blob( |
danielk1977 | ea61b2c | 2004-05-27 01:49:51 +0000 | [diff] [blame] | 4692 | void * clientData, |
| 4693 | Tcl_Interp *interp, |
| 4694 | int objc, |
| 4695 | Tcl_Obj *CONST objv[] |
| 4696 | ){ |
| 4697 | sqlite3_stmt *pStmt; |
| 4698 | int col; |
| 4699 | |
| 4700 | int len; |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 4701 | const void *pBlob; |
danielk1977 | ea61b2c | 2004-05-27 01:49:51 +0000 | [diff] [blame] | 4702 | |
| 4703 | if( objc!=3 ){ |
| 4704 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4705 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 4706 | return TCL_ERROR; |
| 4707 | } |
| 4708 | |
| 4709 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 4710 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
| 4711 | |
danielk1977 | ea61b2c | 2004-05-27 01:49:51 +0000 | [diff] [blame] | 4712 | len = sqlite3_column_bytes(pStmt, col); |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 4713 | pBlob = sqlite3_column_blob(pStmt, col); |
danielk1977 | ea61b2c | 2004-05-27 01:49:51 +0000 | [diff] [blame] | 4714 | Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pBlob, len)); |
| 4715 | return TCL_OK; |
| 4716 | } |
| 4717 | |
| 4718 | /* |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4719 | ** Usage: sqlite3_column_double STMT column |
| 4720 | ** |
| 4721 | ** Return the data in column 'column' of the current row cast as a double. |
| 4722 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4723 | static int SQLITE_TCLAPI test_column_double( |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4724 | void * clientData, |
| 4725 | Tcl_Interp *interp, |
| 4726 | int objc, |
| 4727 | Tcl_Obj *CONST objv[] |
| 4728 | ){ |
| 4729 | sqlite3_stmt *pStmt; |
| 4730 | int col; |
| 4731 | double rVal; |
| 4732 | |
| 4733 | if( objc!=3 ){ |
| 4734 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4735 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 4736 | return TCL_ERROR; |
| 4737 | } |
| 4738 | |
| 4739 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 4740 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
| 4741 | |
| 4742 | rVal = sqlite3_column_double(pStmt, col); |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 4743 | Tcl_SetObjResult(interp, Tcl_NewDoubleObj(rVal)); |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 4744 | return TCL_OK; |
| 4745 | } |
| 4746 | |
| 4747 | /* |
danielk1977 | 17240fd | 2004-05-26 00:07:25 +0000 | [diff] [blame] | 4748 | ** Usage: sqlite3_data_count STMT |
| 4749 | ** |
| 4750 | ** Return the number of columns returned by the sql statement STMT. |
| 4751 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4752 | static int SQLITE_TCLAPI test_data_count( |
danielk1977 | 17240fd | 2004-05-26 00:07:25 +0000 | [diff] [blame] | 4753 | void * clientData, |
| 4754 | Tcl_Interp *interp, |
| 4755 | int objc, |
| 4756 | Tcl_Obj *CONST objv[] |
| 4757 | ){ |
| 4758 | sqlite3_stmt *pStmt; |
| 4759 | |
| 4760 | if( objc!=2 ){ |
| 4761 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4762 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 4763 | return TCL_ERROR; |
| 4764 | } |
| 4765 | |
| 4766 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 4767 | |
| 4768 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_data_count(pStmt))); |
| 4769 | return TCL_OK; |
| 4770 | } |
| 4771 | |
| 4772 | /* |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4773 | ** Usage: sqlite3_column_text STMT column |
| 4774 | ** |
| 4775 | ** Usage: sqlite3_column_decltype STMT column |
| 4776 | ** |
| 4777 | ** Usage: sqlite3_column_name STMT column |
| 4778 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4779 | static int SQLITE_TCLAPI test_stmt_utf8( |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 4780 | void * clientData, /* Pointer to SQLite API function to be invoke */ |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4781 | Tcl_Interp *interp, |
| 4782 | int objc, |
| 4783 | Tcl_Obj *CONST objv[] |
| 4784 | ){ |
| 4785 | sqlite3_stmt *pStmt; |
| 4786 | int col; |
danielk1977 | 44a376f | 2008-08-12 15:04:58 +0000 | [diff] [blame] | 4787 | const char *(*xFunc)(sqlite3_stmt*, int); |
danielk1977 | f93bbbe | 2004-05-27 10:30:52 +0000 | [diff] [blame] | 4788 | const char *zRet; |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4789 | |
danielk1977 | 44a376f | 2008-08-12 15:04:58 +0000 | [diff] [blame] | 4790 | xFunc = (const char *(*)(sqlite3_stmt*, int))clientData; |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4791 | if( objc!=3 ){ |
| 4792 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4793 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 4794 | return TCL_ERROR; |
| 4795 | } |
| 4796 | |
| 4797 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 4798 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
danielk1977 | f93bbbe | 2004-05-27 10:30:52 +0000 | [diff] [blame] | 4799 | zRet = xFunc(pStmt, col); |
| 4800 | if( zRet ){ |
| 4801 | Tcl_SetResult(interp, (char *)zRet, 0); |
| 4802 | } |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4803 | return TCL_OK; |
| 4804 | } |
| 4805 | |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4806 | static int SQLITE_TCLAPI test_global_recover( |
danielk1977 | 6b456a2 | 2005-03-21 04:04:02 +0000 | [diff] [blame] | 4807 | void * clientData, |
| 4808 | Tcl_Interp *interp, |
| 4809 | int objc, |
| 4810 | Tcl_Obj *CONST objv[] |
| 4811 | ){ |
shane | eec556d | 2008-10-12 00:27:53 +0000 | [diff] [blame] | 4812 | #ifndef SQLITE_OMIT_DEPRECATED |
danielk1977 | 6b456a2 | 2005-03-21 04:04:02 +0000 | [diff] [blame] | 4813 | int rc; |
| 4814 | if( objc!=1 ){ |
| 4815 | Tcl_WrongNumArgs(interp, 1, objv, ""); |
| 4816 | return TCL_ERROR; |
| 4817 | } |
| 4818 | rc = sqlite3_global_recover(); |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 4819 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 6b456a2 | 2005-03-21 04:04:02 +0000 | [diff] [blame] | 4820 | #endif |
| 4821 | return TCL_OK; |
| 4822 | } |
| 4823 | |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4824 | /* |
| 4825 | ** Usage: sqlite3_column_text STMT column |
| 4826 | ** |
| 4827 | ** Usage: sqlite3_column_decltype STMT column |
| 4828 | ** |
| 4829 | ** Usage: sqlite3_column_name STMT column |
| 4830 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4831 | static int SQLITE_TCLAPI test_stmt_utf16( |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 4832 | void * clientData, /* Pointer to SQLite API function to be invoked */ |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4833 | Tcl_Interp *interp, |
| 4834 | int objc, |
| 4835 | Tcl_Obj *CONST objv[] |
| 4836 | ){ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 4837 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4838 | sqlite3_stmt *pStmt; |
| 4839 | int col; |
| 4840 | Tcl_Obj *pRet; |
| 4841 | const void *zName16; |
danielk1977 | 44a376f | 2008-08-12 15:04:58 +0000 | [diff] [blame] | 4842 | const void *(*xFunc)(sqlite3_stmt*, int); |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4843 | |
danielk1977 | 44a376f | 2008-08-12 15:04:58 +0000 | [diff] [blame] | 4844 | xFunc = (const void *(*)(sqlite3_stmt*, int))clientData; |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4845 | if( objc!=3 ){ |
| 4846 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4847 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 4848 | return TCL_ERROR; |
| 4849 | } |
| 4850 | |
| 4851 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 4852 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
| 4853 | |
| 4854 | zName16 = xFunc(pStmt, col); |
danielk1977 | f93bbbe | 2004-05-27 10:30:52 +0000 | [diff] [blame] | 4855 | if( zName16 ){ |
drh | aed382f | 2009-04-01 18:40:32 +0000 | [diff] [blame] | 4856 | int n; |
| 4857 | const char *z = zName16; |
| 4858 | for(n=0; z[n] || z[n+1]; n+=2){} |
| 4859 | pRet = Tcl_NewByteArrayObj(zName16, n+2); |
danielk1977 | f93bbbe | 2004-05-27 10:30:52 +0000 | [diff] [blame] | 4860 | Tcl_SetObjResult(interp, pRet); |
| 4861 | } |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 4862 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4863 | |
| 4864 | return TCL_OK; |
| 4865 | } |
| 4866 | |
| 4867 | /* |
| 4868 | ** Usage: sqlite3_column_int STMT column |
| 4869 | ** |
| 4870 | ** Usage: sqlite3_column_bytes STMT column |
| 4871 | ** |
| 4872 | ** Usage: sqlite3_column_bytes16 STMT column |
| 4873 | ** |
| 4874 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4875 | static int SQLITE_TCLAPI test_stmt_int( |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 4876 | void * clientData, /* Pointer to SQLite API function to be invoked */ |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4877 | Tcl_Interp *interp, |
| 4878 | int objc, |
| 4879 | Tcl_Obj *CONST objv[] |
| 4880 | ){ |
| 4881 | sqlite3_stmt *pStmt; |
| 4882 | int col; |
danielk1977 | 44a376f | 2008-08-12 15:04:58 +0000 | [diff] [blame] | 4883 | int (*xFunc)(sqlite3_stmt*, int); |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4884 | |
danielk1977 | 55a25a1 | 2008-09-11 10:29:15 +0000 | [diff] [blame] | 4885 | xFunc = (int (*)(sqlite3_stmt*, int))clientData; |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4886 | if( objc!=3 ){ |
| 4887 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 4888 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 4889 | return TCL_ERROR; |
| 4890 | } |
| 4891 | |
| 4892 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 4893 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
| 4894 | |
| 4895 | Tcl_SetObjResult(interp, Tcl_NewIntObj(xFunc(pStmt, col))); |
| 4896 | return TCL_OK; |
| 4897 | } |
| 4898 | |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 4899 | /* |
drh | cacb208 | 2005-01-11 15:28:33 +0000 | [diff] [blame] | 4900 | ** Usage: sqlite_set_magic DB MAGIC-NUMBER |
| 4901 | ** |
| 4902 | ** Set the db->magic value. This is used to test error recovery logic. |
| 4903 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4904 | static int SQLITE_TCLAPI sqlite_set_magic( |
drh | cacb208 | 2005-01-11 15:28:33 +0000 | [diff] [blame] | 4905 | void * clientData, |
| 4906 | Tcl_Interp *interp, |
| 4907 | int argc, |
| 4908 | char **argv |
| 4909 | ){ |
| 4910 | sqlite3 *db; |
| 4911 | if( argc!=3 ){ |
| 4912 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 4913 | " DB MAGIC", 0); |
| 4914 | return TCL_ERROR; |
| 4915 | } |
| 4916 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 4917 | if( strcmp(argv[2], "SQLITE_MAGIC_OPEN")==0 ){ |
| 4918 | db->magic = SQLITE_MAGIC_OPEN; |
| 4919 | }else if( strcmp(argv[2], "SQLITE_MAGIC_CLOSED")==0 ){ |
| 4920 | db->magic = SQLITE_MAGIC_CLOSED; |
| 4921 | }else if( strcmp(argv[2], "SQLITE_MAGIC_BUSY")==0 ){ |
| 4922 | db->magic = SQLITE_MAGIC_BUSY; |
| 4923 | }else if( strcmp(argv[2], "SQLITE_MAGIC_ERROR")==0 ){ |
| 4924 | db->magic = SQLITE_MAGIC_ERROR; |
drh | 902b9ee | 2008-12-05 17:17:07 +0000 | [diff] [blame] | 4925 | }else if( Tcl_GetInt(interp, argv[2], (int*)&db->magic) ){ |
drh | cacb208 | 2005-01-11 15:28:33 +0000 | [diff] [blame] | 4926 | return TCL_ERROR; |
| 4927 | } |
| 4928 | return TCL_OK; |
| 4929 | } |
| 4930 | |
| 4931 | /* |
drh | c5cdca6 | 2005-01-11 16:54:14 +0000 | [diff] [blame] | 4932 | ** Usage: sqlite3_interrupt DB |
| 4933 | ** |
| 4934 | ** Trigger an interrupt on DB |
| 4935 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4936 | static int SQLITE_TCLAPI test_interrupt( |
drh | c5cdca6 | 2005-01-11 16:54:14 +0000 | [diff] [blame] | 4937 | void * clientData, |
| 4938 | Tcl_Interp *interp, |
| 4939 | int argc, |
| 4940 | char **argv |
| 4941 | ){ |
| 4942 | sqlite3 *db; |
| 4943 | if( argc!=2 ){ |
| 4944 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB", 0); |
| 4945 | return TCL_ERROR; |
| 4946 | } |
| 4947 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 4948 | sqlite3_interrupt(db); |
| 4949 | return TCL_OK; |
| 4950 | } |
| 4951 | |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 4952 | static u8 *sqlite3_stack_baseline = 0; |
| 4953 | |
drh | c5cdca6 | 2005-01-11 16:54:14 +0000 | [diff] [blame] | 4954 | /* |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 4955 | ** Fill the stack with a known bitpattern. |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 4956 | */ |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 4957 | static void prepStack(void){ |
| 4958 | int i; |
| 4959 | u32 bigBuf[65536]; |
drh | bc2be0c | 2011-08-30 00:53:50 +0000 | [diff] [blame] | 4960 | for(i=0; i<sizeof(bigBuf)/sizeof(bigBuf[0]); i++) bigBuf[i] = 0xdeadbeef; |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 4961 | sqlite3_stack_baseline = (u8*)&bigBuf[65536]; |
| 4962 | } |
| 4963 | |
| 4964 | /* |
| 4965 | ** Get the current stack depth. Used for debugging only. |
| 4966 | */ |
| 4967 | u64 sqlite3StackDepth(void){ |
| 4968 | u8 x; |
| 4969 | return (u64)(sqlite3_stack_baseline - &x); |
| 4970 | } |
| 4971 | |
| 4972 | /* |
| 4973 | ** Usage: sqlite3_stack_used DB SQL |
| 4974 | ** |
| 4975 | ** Try to measure the amount of stack space used by a call to sqlite3_exec |
| 4976 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 4977 | static int SQLITE_TCLAPI test_stack_used( |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 4978 | void * clientData, |
| 4979 | Tcl_Interp *interp, |
| 4980 | int argc, |
| 4981 | char **argv |
| 4982 | ){ |
| 4983 | sqlite3 *db; |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 4984 | int i; |
| 4985 | if( argc!=3 ){ |
| 4986 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 4987 | " DB SQL", 0); |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 4988 | return TCL_ERROR; |
| 4989 | } |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 4990 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 4991 | prepStack(); |
drh | 3752785 | 2006-03-16 16:19:56 +0000 | [diff] [blame] | 4992 | (void)sqlite3_exec(db, argv[2], 0, 0, 0); |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 4993 | for(i=65535; i>=0 && ((u32*)sqlite3_stack_baseline)[-i]==0xdeadbeef; i--){} |
| 4994 | Tcl_SetObjResult(interp, Tcl_NewIntObj(i*4)); |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 4995 | return TCL_OK; |
| 4996 | } |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 4997 | |
| 4998 | /* |
danielk1977 | 9636c4e | 2005-01-25 04:27:54 +0000 | [diff] [blame] | 4999 | ** Usage: sqlite_delete_function DB function-name |
| 5000 | ** |
| 5001 | ** Delete the user function 'function-name' from database handle DB. It |
| 5002 | ** is assumed that the user function was created as UTF8, any number of |
| 5003 | ** arguments (the way the TCL interface does it). |
| 5004 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5005 | static int SQLITE_TCLAPI delete_function( |
danielk1977 | 9636c4e | 2005-01-25 04:27:54 +0000 | [diff] [blame] | 5006 | void * clientData, |
| 5007 | Tcl_Interp *interp, |
| 5008 | int argc, |
| 5009 | char **argv |
| 5010 | ){ |
| 5011 | int rc; |
| 5012 | sqlite3 *db; |
| 5013 | if( argc!=3 ){ |
| 5014 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 5015 | " DB function-name", 0); |
| 5016 | return TCL_ERROR; |
| 5017 | } |
| 5018 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 5019 | rc = sqlite3_create_function(db, argv[2], -1, SQLITE_UTF8, 0, 0, 0, 0); |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 5020 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 9636c4e | 2005-01-25 04:27:54 +0000 | [diff] [blame] | 5021 | return TCL_OK; |
| 5022 | } |
| 5023 | |
| 5024 | /* |
| 5025 | ** Usage: sqlite_delete_collation DB collation-name |
| 5026 | ** |
| 5027 | ** Delete the collation sequence 'collation-name' from database handle |
| 5028 | ** DB. It is assumed that the collation sequence was created as UTF8 (the |
| 5029 | ** way the TCL interface does it). |
| 5030 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5031 | static int SQLITE_TCLAPI delete_collation( |
danielk1977 | 9636c4e | 2005-01-25 04:27:54 +0000 | [diff] [blame] | 5032 | void * clientData, |
| 5033 | Tcl_Interp *interp, |
| 5034 | int argc, |
| 5035 | char **argv |
| 5036 | ){ |
| 5037 | int rc; |
| 5038 | sqlite3 *db; |
| 5039 | if( argc!=3 ){ |
| 5040 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 5041 | " DB function-name", 0); |
| 5042 | return TCL_ERROR; |
| 5043 | } |
| 5044 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 5045 | rc = sqlite3_create_collation(db, argv[2], SQLITE_UTF8, 0, 0); |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 5046 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 9636c4e | 2005-01-25 04:27:54 +0000 | [diff] [blame] | 5047 | return TCL_OK; |
| 5048 | } |
| 5049 | |
| 5050 | /* |
drh | 3e1d8e6 | 2005-05-26 16:23:34 +0000 | [diff] [blame] | 5051 | ** Usage: sqlite3_get_autocommit DB |
| 5052 | ** |
| 5053 | ** Return true if the database DB is currently in auto-commit mode. |
| 5054 | ** Return false if not. |
| 5055 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5056 | static int SQLITE_TCLAPI get_autocommit( |
drh | 3e1d8e6 | 2005-05-26 16:23:34 +0000 | [diff] [blame] | 5057 | void * clientData, |
| 5058 | Tcl_Interp *interp, |
| 5059 | int argc, |
| 5060 | char **argv |
| 5061 | ){ |
| 5062 | char zBuf[30]; |
| 5063 | sqlite3 *db; |
| 5064 | if( argc!=2 ){ |
| 5065 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 5066 | " DB", 0); |
| 5067 | return TCL_ERROR; |
| 5068 | } |
| 5069 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 5070 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", sqlite3_get_autocommit(db)); |
drh | 3e1d8e6 | 2005-05-26 16:23:34 +0000 | [diff] [blame] | 5071 | Tcl_AppendResult(interp, zBuf, 0); |
| 5072 | return TCL_OK; |
| 5073 | } |
| 5074 | |
| 5075 | /* |
drh | 3086765 | 2006-07-06 10:59:57 +0000 | [diff] [blame] | 5076 | ** Usage: sqlite3_busy_timeout DB MS |
| 5077 | ** |
| 5078 | ** Set the busy timeout. This is more easily done using the timeout |
| 5079 | ** method of the TCL interface. But we need a way to test the case |
| 5080 | ** where it returns SQLITE_MISUSE. |
| 5081 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5082 | static int SQLITE_TCLAPI test_busy_timeout( |
drh | 3086765 | 2006-07-06 10:59:57 +0000 | [diff] [blame] | 5083 | void * clientData, |
| 5084 | Tcl_Interp *interp, |
| 5085 | int argc, |
| 5086 | char **argv |
| 5087 | ){ |
| 5088 | int rc, ms; |
| 5089 | sqlite3 *db; |
| 5090 | if( argc!=3 ){ |
| 5091 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 5092 | " DB", 0); |
| 5093 | return TCL_ERROR; |
| 5094 | } |
| 5095 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 5096 | if( Tcl_GetInt(interp, argv[2], &ms) ) return TCL_ERROR; |
| 5097 | rc = sqlite3_busy_timeout(db, ms); |
mistachkin | e84d8d3 | 2013-04-29 03:09:10 +0000 | [diff] [blame] | 5098 | Tcl_AppendResult(interp, sqlite3ErrName(rc), 0); |
drh | 3086765 | 2006-07-06 10:59:57 +0000 | [diff] [blame] | 5099 | return TCL_OK; |
| 5100 | } |
| 5101 | |
| 5102 | /* |
drh | 92febd9 | 2004-08-20 18:34:20 +0000 | [diff] [blame] | 5103 | ** Usage: tcl_variable_type VARIABLENAME |
| 5104 | ** |
| 5105 | ** Return the name of the internal representation for the |
| 5106 | ** value of the given variable. |
| 5107 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5108 | static int SQLITE_TCLAPI tcl_variable_type( |
drh | 92febd9 | 2004-08-20 18:34:20 +0000 | [diff] [blame] | 5109 | void * clientData, |
| 5110 | Tcl_Interp *interp, |
| 5111 | int objc, |
| 5112 | Tcl_Obj *CONST objv[] |
| 5113 | ){ |
| 5114 | Tcl_Obj *pVar; |
| 5115 | if( objc!=2 ){ |
| 5116 | Tcl_WrongNumArgs(interp, 1, objv, "VARIABLE"); |
| 5117 | return TCL_ERROR; |
| 5118 | } |
| 5119 | pVar = Tcl_GetVar2Ex(interp, Tcl_GetString(objv[1]), 0, TCL_LEAVE_ERR_MSG); |
| 5120 | if( pVar==0 ) return TCL_ERROR; |
| 5121 | if( pVar->typePtr ){ |
| 5122 | Tcl_SetObjResult(interp, Tcl_NewStringObj(pVar->typePtr->name, -1)); |
| 5123 | } |
| 5124 | return TCL_OK; |
| 5125 | } |
| 5126 | |
| 5127 | /* |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 5128 | ** Usage: sqlite3_release_memory ?N? |
| 5129 | ** |
| 5130 | ** Attempt to release memory currently held but not actually required. |
| 5131 | ** The integer N is the number of bytes we are trying to release. The |
| 5132 | ** return value is the amount of memory actually released. |
| 5133 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5134 | static int SQLITE_TCLAPI test_release_memory( |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 5135 | void * clientData, |
| 5136 | Tcl_Interp *interp, |
| 5137 | int objc, |
| 5138 | Tcl_Obj *CONST objv[] |
| 5139 | ){ |
drh | 6f7adc8 | 2006-01-11 21:41:20 +0000 | [diff] [blame] | 5140 | #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO) |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 5141 | int N; |
| 5142 | int amt; |
| 5143 | if( objc!=1 && objc!=2 ){ |
| 5144 | Tcl_WrongNumArgs(interp, 1, objv, "?N?"); |
| 5145 | return TCL_ERROR; |
| 5146 | } |
| 5147 | if( objc==2 ){ |
| 5148 | if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR; |
| 5149 | }else{ |
| 5150 | N = -1; |
| 5151 | } |
| 5152 | amt = sqlite3_release_memory(N); |
| 5153 | Tcl_SetObjResult(interp, Tcl_NewIntObj(amt)); |
| 5154 | #endif |
| 5155 | return TCL_OK; |
| 5156 | } |
| 5157 | |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 5158 | |
| 5159 | /* |
| 5160 | ** Usage: sqlite3_db_release_memory DB |
| 5161 | ** |
| 5162 | ** Attempt to release memory currently held by database DB. Return the |
| 5163 | ** result code (which in the current implementation is always zero). |
| 5164 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5165 | static int SQLITE_TCLAPI test_db_release_memory( |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 5166 | void * clientData, |
| 5167 | Tcl_Interp *interp, |
| 5168 | int objc, |
| 5169 | Tcl_Obj *CONST objv[] |
| 5170 | ){ |
| 5171 | sqlite3 *db; |
| 5172 | int rc; |
| 5173 | if( objc!=2 ){ |
| 5174 | Tcl_WrongNumArgs(interp, 1, objv, "DB"); |
| 5175 | return TCL_ERROR; |
| 5176 | } |
| 5177 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 5178 | rc = sqlite3_db_release_memory(db); |
| 5179 | Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
| 5180 | return TCL_OK; |
| 5181 | } |
| 5182 | |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 5183 | /* |
dan | 6fa255f | 2015-10-28 19:46:57 +0000 | [diff] [blame] | 5184 | ** Usage: sqlite3_db_cacheflush DB |
| 5185 | ** |
| 5186 | ** Attempt to flush any dirty pages to disk. |
| 5187 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5188 | static int SQLITE_TCLAPI test_db_cacheflush( |
dan | 6fa255f | 2015-10-28 19:46:57 +0000 | [diff] [blame] | 5189 | void * clientData, |
| 5190 | Tcl_Interp *interp, |
| 5191 | int objc, |
| 5192 | Tcl_Obj *CONST objv[] |
| 5193 | ){ |
| 5194 | sqlite3 *db; |
| 5195 | int rc; |
| 5196 | if( objc!=2 ){ |
| 5197 | Tcl_WrongNumArgs(interp, 1, objv, "DB"); |
| 5198 | return TCL_ERROR; |
| 5199 | } |
| 5200 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 5201 | rc = sqlite3_db_cacheflush(db); |
| 5202 | if( rc ){ |
| 5203 | Tcl_SetResult(interp, (char *)sqlite3ErrStr(rc), TCL_STATIC); |
| 5204 | return TCL_ERROR; |
| 5205 | } |
| 5206 | |
| 5207 | Tcl_ResetResult(interp); |
| 5208 | return TCL_OK; |
| 5209 | } |
| 5210 | |
| 5211 | /* |
drh | 0e80e50 | 2016-03-17 17:23:11 +0000 | [diff] [blame] | 5212 | ** Usage: sqlite3_system_errno DB |
| 5213 | ** |
| 5214 | ** Return the low-level system errno value. |
| 5215 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5216 | static int SQLITE_TCLAPI test_system_errno( |
drh | 0e80e50 | 2016-03-17 17:23:11 +0000 | [diff] [blame] | 5217 | void * clientData, |
| 5218 | Tcl_Interp *interp, |
| 5219 | int objc, |
| 5220 | Tcl_Obj *CONST objv[] |
| 5221 | ){ |
| 5222 | sqlite3 *db; |
| 5223 | int iErrno; |
| 5224 | if( objc!=2 ){ |
| 5225 | Tcl_WrongNumArgs(interp, 1, objv, "DB"); |
| 5226 | return TCL_ERROR; |
| 5227 | } |
| 5228 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 5229 | iErrno = sqlite3_system_errno(db); |
| 5230 | Tcl_SetObjResult(interp, Tcl_NewIntObj(iErrno)); |
| 5231 | return TCL_OK; |
| 5232 | } |
| 5233 | |
| 5234 | /* |
drh | 283829c | 2011-11-17 00:56:20 +0000 | [diff] [blame] | 5235 | ** Usage: sqlite3_db_filename DB DBNAME |
| 5236 | ** |
| 5237 | ** Return the name of a file associated with a database. |
| 5238 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5239 | static int SQLITE_TCLAPI test_db_filename( |
drh | 283829c | 2011-11-17 00:56:20 +0000 | [diff] [blame] | 5240 | void * clientData, |
| 5241 | Tcl_Interp *interp, |
| 5242 | int objc, |
| 5243 | Tcl_Obj *CONST objv[] |
| 5244 | ){ |
| 5245 | sqlite3 *db; |
| 5246 | const char *zDbName; |
| 5247 | if( objc!=3 ){ |
| 5248 | Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME"); |
| 5249 | return TCL_ERROR; |
| 5250 | } |
| 5251 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 5252 | zDbName = Tcl_GetString(objv[2]); |
| 5253 | Tcl_AppendResult(interp, sqlite3_db_filename(db, zDbName), (void*)0); |
| 5254 | return TCL_OK; |
| 5255 | } |
| 5256 | |
| 5257 | /* |
drh | 421377e | 2012-03-15 21:28:54 +0000 | [diff] [blame] | 5258 | ** Usage: sqlite3_db_readonly DB DBNAME |
| 5259 | ** |
| 5260 | ** Return 1 or 0 if DBNAME is readonly or not. Return -1 if DBNAME does |
| 5261 | ** not exist. |
| 5262 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5263 | static int SQLITE_TCLAPI test_db_readonly( |
drh | 421377e | 2012-03-15 21:28:54 +0000 | [diff] [blame] | 5264 | void * clientData, |
| 5265 | Tcl_Interp *interp, |
| 5266 | int objc, |
| 5267 | Tcl_Obj *CONST objv[] |
| 5268 | ){ |
| 5269 | sqlite3 *db; |
| 5270 | const char *zDbName; |
| 5271 | if( objc!=3 ){ |
| 5272 | Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME"); |
| 5273 | return TCL_ERROR; |
| 5274 | } |
| 5275 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 5276 | zDbName = Tcl_GetString(objv[2]); |
| 5277 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_db_readonly(db, zDbName))); |
| 5278 | return TCL_OK; |
| 5279 | } |
| 5280 | |
| 5281 | /* |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 5282 | ** Usage: sqlite3_soft_heap_limit ?N? |
| 5283 | ** |
| 5284 | ** Query or set the soft heap limit for the current thread. The |
| 5285 | ** limit is only changed if the N is present. The previous limit |
| 5286 | ** is returned. |
| 5287 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5288 | static int SQLITE_TCLAPI test_soft_heap_limit( |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 5289 | void * clientData, |
| 5290 | Tcl_Interp *interp, |
| 5291 | int objc, |
| 5292 | Tcl_Obj *CONST objv[] |
| 5293 | ){ |
drh | f82ccf6 | 2010-09-15 17:54:31 +0000 | [diff] [blame] | 5294 | sqlite3_int64 amt; |
drh | b3f787f | 2012-09-29 14:45:54 +0000 | [diff] [blame] | 5295 | Tcl_WideInt N = -1; |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 5296 | if( objc!=1 && objc!=2 ){ |
| 5297 | Tcl_WrongNumArgs(interp, 1, objv, "?N?"); |
| 5298 | return TCL_ERROR; |
| 5299 | } |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 5300 | if( objc==2 ){ |
drh | f82ccf6 | 2010-09-15 17:54:31 +0000 | [diff] [blame] | 5301 | if( Tcl_GetWideIntFromObj(interp, objv[1], &N) ) return TCL_ERROR; |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 5302 | } |
drh | f82ccf6 | 2010-09-15 17:54:31 +0000 | [diff] [blame] | 5303 | amt = sqlite3_soft_heap_limit64(N); |
| 5304 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj(amt)); |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 5305 | return TCL_OK; |
| 5306 | } |
| 5307 | |
| 5308 | /* |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 5309 | ** Usage: sqlite3_thread_cleanup |
| 5310 | ** |
| 5311 | ** Call the sqlite3_thread_cleanup API. |
| 5312 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5313 | static int SQLITE_TCLAPI test_thread_cleanup( |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 5314 | void * clientData, |
| 5315 | Tcl_Interp *interp, |
| 5316 | int objc, |
| 5317 | Tcl_Obj *CONST objv[] |
| 5318 | ){ |
shane | eec556d | 2008-10-12 00:27:53 +0000 | [diff] [blame] | 5319 | #ifndef SQLITE_OMIT_DEPRECATED |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 5320 | sqlite3_thread_cleanup(); |
shane | eec556d | 2008-10-12 00:27:53 +0000 | [diff] [blame] | 5321 | #endif |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 5322 | return TCL_OK; |
| 5323 | } |
| 5324 | |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 5325 | /* |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 5326 | ** Usage: sqlite3_pager_refcounts DB |
| 5327 | ** |
drh | f534544 | 2007-04-09 12:45:02 +0000 | [diff] [blame] | 5328 | ** Return a list of numbers which are the PagerRefcount for all |
| 5329 | ** pagers on each database connection. |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 5330 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5331 | static int SQLITE_TCLAPI test_pager_refcounts( |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 5332 | void * clientData, |
| 5333 | Tcl_Interp *interp, |
| 5334 | int objc, |
| 5335 | Tcl_Obj *CONST objv[] |
| 5336 | ){ |
| 5337 | sqlite3 *db; |
| 5338 | int i; |
| 5339 | int v, *a; |
| 5340 | Tcl_Obj *pResult; |
| 5341 | |
| 5342 | if( objc!=2 ){ |
| 5343 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | f534544 | 2007-04-09 12:45:02 +0000 | [diff] [blame] | 5344 | Tcl_GetStringFromObj(objv[0], 0), " DB", 0); |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 5345 | return TCL_ERROR; |
| 5346 | } |
| 5347 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 5348 | pResult = Tcl_NewObj(); |
| 5349 | for(i=0; i<db->nDb; i++){ |
| 5350 | if( db->aDb[i].pBt==0 ){ |
| 5351 | v = -1; |
| 5352 | }else{ |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 5353 | sqlite3_mutex_enter(db->mutex); |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 5354 | a = sqlite3PagerStats(sqlite3BtreePager(db->aDb[i].pBt)); |
| 5355 | v = a[0]; |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 5356 | sqlite3_mutex_leave(db->mutex); |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 5357 | } |
| 5358 | Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(v)); |
| 5359 | } |
| 5360 | Tcl_SetObjResult(interp, pResult); |
| 5361 | return TCL_OK; |
| 5362 | } |
| 5363 | |
| 5364 | |
| 5365 | /* |
drh | 80788d8 | 2006-09-02 14:50:23 +0000 | [diff] [blame] | 5366 | ** tclcmd: working_64bit_int |
| 5367 | ** |
| 5368 | ** Some TCL builds (ex: cygwin) do not support 64-bit integers. This |
| 5369 | ** leads to a number of test failures. The present command checks the |
| 5370 | ** TCL build to see whether or not it supports 64-bit integers. It |
| 5371 | ** returns TRUE if it does and FALSE if not. |
| 5372 | ** |
| 5373 | ** This command is used to warn users that their TCL build is defective |
| 5374 | ** and that the errors they are seeing in the test scripts might be |
| 5375 | ** a result of their defective TCL rather than problems in SQLite. |
| 5376 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5377 | static int SQLITE_TCLAPI working_64bit_int( |
drh | 80788d8 | 2006-09-02 14:50:23 +0000 | [diff] [blame] | 5378 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5379 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5380 | int objc, /* Number of arguments */ |
| 5381 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5382 | ){ |
| 5383 | Tcl_Obj *pTestObj; |
| 5384 | int working = 0; |
| 5385 | |
| 5386 | pTestObj = Tcl_NewWideIntObj(1000000*(i64)1234567890); |
| 5387 | working = strcmp(Tcl_GetString(pTestObj), "1234567890000000")==0; |
| 5388 | Tcl_DecrRefCount(pTestObj); |
| 5389 | Tcl_SetObjResult(interp, Tcl_NewBooleanObj(working)); |
| 5390 | return TCL_OK; |
| 5391 | } |
| 5392 | |
| 5393 | |
| 5394 | /* |
drh | 9bc5449 | 2007-10-23 14:49:59 +0000 | [diff] [blame] | 5395 | ** tclcmd: vfs_unlink_test |
| 5396 | ** |
| 5397 | ** This TCL command unregisters the primary VFS and then registers |
| 5398 | ** it back again. This is used to test the ability to register a |
| 5399 | ** VFS when none are previously registered, and the ability to |
| 5400 | ** unregister the only available VFS. Ticket #2738 |
| 5401 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5402 | static int SQLITE_TCLAPI vfs_unlink_test( |
drh | 9bc5449 | 2007-10-23 14:49:59 +0000 | [diff] [blame] | 5403 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5404 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5405 | int objc, /* Number of arguments */ |
| 5406 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5407 | ){ |
| 5408 | int i; |
drh | 91fd4d4 | 2008-01-19 20:11:25 +0000 | [diff] [blame] | 5409 | sqlite3_vfs *pMain; |
drh | 9bc5449 | 2007-10-23 14:49:59 +0000 | [diff] [blame] | 5410 | sqlite3_vfs *apVfs[20]; |
drh | 91fd4d4 | 2008-01-19 20:11:25 +0000 | [diff] [blame] | 5411 | sqlite3_vfs one, two; |
drh | 9bc5449 | 2007-10-23 14:49:59 +0000 | [diff] [blame] | 5412 | |
drh | 91fd4d4 | 2008-01-19 20:11:25 +0000 | [diff] [blame] | 5413 | sqlite3_vfs_unregister(0); /* Unregister of NULL is harmless */ |
| 5414 | one.zName = "__one"; |
| 5415 | two.zName = "__two"; |
| 5416 | |
| 5417 | /* Calling sqlite3_vfs_register with 2nd argument of 0 does not |
| 5418 | ** change the default VFS |
| 5419 | */ |
| 5420 | pMain = sqlite3_vfs_find(0); |
| 5421 | sqlite3_vfs_register(&one, 0); |
| 5422 | assert( pMain==0 || pMain==sqlite3_vfs_find(0) ); |
| 5423 | sqlite3_vfs_register(&two, 0); |
| 5424 | assert( pMain==0 || pMain==sqlite3_vfs_find(0) ); |
| 5425 | |
| 5426 | /* We can find a VFS by its name */ |
| 5427 | assert( sqlite3_vfs_find("__one")==&one ); |
| 5428 | assert( sqlite3_vfs_find("__two")==&two ); |
| 5429 | |
| 5430 | /* Calling sqlite_vfs_register with non-zero second parameter changes the |
| 5431 | ** default VFS, even if the 1st parameter is an existig VFS that is |
| 5432 | ** previously registered as the non-default. |
| 5433 | */ |
| 5434 | sqlite3_vfs_register(&one, 1); |
| 5435 | assert( sqlite3_vfs_find("__one")==&one ); |
| 5436 | assert( sqlite3_vfs_find("__two")==&two ); |
| 5437 | assert( sqlite3_vfs_find(0)==&one ); |
| 5438 | sqlite3_vfs_register(&two, 1); |
| 5439 | assert( sqlite3_vfs_find("__one")==&one ); |
| 5440 | assert( sqlite3_vfs_find("__two")==&two ); |
| 5441 | assert( sqlite3_vfs_find(0)==&two ); |
| 5442 | if( pMain ){ |
| 5443 | sqlite3_vfs_register(pMain, 1); |
| 5444 | assert( sqlite3_vfs_find("__one")==&one ); |
| 5445 | assert( sqlite3_vfs_find("__two")==&two ); |
| 5446 | assert( sqlite3_vfs_find(0)==pMain ); |
| 5447 | } |
| 5448 | |
| 5449 | /* Unlink the default VFS. Repeat until there are no more VFSes |
| 5450 | ** registered. |
| 5451 | */ |
drh | 9bc5449 | 2007-10-23 14:49:59 +0000 | [diff] [blame] | 5452 | for(i=0; i<sizeof(apVfs)/sizeof(apVfs[0]); i++){ |
| 5453 | apVfs[i] = sqlite3_vfs_find(0); |
| 5454 | if( apVfs[i] ){ |
| 5455 | assert( apVfs[i]==sqlite3_vfs_find(apVfs[i]->zName) ); |
| 5456 | sqlite3_vfs_unregister(apVfs[i]); |
| 5457 | assert( 0==sqlite3_vfs_find(apVfs[i]->zName) ); |
| 5458 | } |
| 5459 | } |
| 5460 | assert( 0==sqlite3_vfs_find(0) ); |
mlcreech | 1f04533 | 2008-04-08 03:07:54 +0000 | [diff] [blame] | 5461 | |
| 5462 | /* Register the main VFS as non-default (will be made default, since |
| 5463 | ** it'll be the only one in existence). |
| 5464 | */ |
| 5465 | sqlite3_vfs_register(pMain, 0); |
| 5466 | assert( sqlite3_vfs_find(0)==pMain ); |
| 5467 | |
| 5468 | /* Un-register the main VFS again to restore an empty VFS list */ |
| 5469 | sqlite3_vfs_unregister(pMain); |
| 5470 | assert( 0==sqlite3_vfs_find(0) ); |
drh | 91fd4d4 | 2008-01-19 20:11:25 +0000 | [diff] [blame] | 5471 | |
| 5472 | /* Relink all VFSes in reverse order. */ |
drh | 9bc5449 | 2007-10-23 14:49:59 +0000 | [diff] [blame] | 5473 | for(i=sizeof(apVfs)/sizeof(apVfs[0])-1; i>=0; i--){ |
| 5474 | if( apVfs[i] ){ |
| 5475 | sqlite3_vfs_register(apVfs[i], 1); |
| 5476 | assert( apVfs[i]==sqlite3_vfs_find(0) ); |
| 5477 | assert( apVfs[i]==sqlite3_vfs_find(apVfs[i]->zName) ); |
| 5478 | } |
| 5479 | } |
drh | 91fd4d4 | 2008-01-19 20:11:25 +0000 | [diff] [blame] | 5480 | |
| 5481 | /* Unregister out sample VFSes. */ |
| 5482 | sqlite3_vfs_unregister(&one); |
| 5483 | sqlite3_vfs_unregister(&two); |
| 5484 | |
| 5485 | /* Unregistering a VFS that is not currently registered is harmless */ |
| 5486 | sqlite3_vfs_unregister(&one); |
| 5487 | sqlite3_vfs_unregister(&two); |
| 5488 | assert( sqlite3_vfs_find("__one")==0 ); |
| 5489 | assert( sqlite3_vfs_find("__two")==0 ); |
| 5490 | |
| 5491 | /* We should be left with the original default VFS back as the |
| 5492 | ** original */ |
| 5493 | assert( sqlite3_vfs_find(0)==pMain ); |
| 5494 | |
drh | 9bc5449 | 2007-10-23 14:49:59 +0000 | [diff] [blame] | 5495 | return TCL_OK; |
| 5496 | } |
| 5497 | |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 5498 | /* |
drh | c8d7567 | 2008-07-08 02:12:37 +0000 | [diff] [blame] | 5499 | ** tclcmd: vfs_initfail_test |
| 5500 | ** |
| 5501 | ** This TCL command attempts to vfs_find and vfs_register when the |
| 5502 | ** sqlite3_initialize() interface is failing. All calls should fail. |
| 5503 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5504 | static int SQLITE_TCLAPI vfs_initfail_test( |
drh | c8d7567 | 2008-07-08 02:12:37 +0000 | [diff] [blame] | 5505 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5506 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5507 | int objc, /* Number of arguments */ |
| 5508 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5509 | ){ |
| 5510 | sqlite3_vfs one; |
| 5511 | one.zName = "__one"; |
| 5512 | |
| 5513 | if( sqlite3_vfs_find(0) ) return TCL_ERROR; |
| 5514 | sqlite3_vfs_register(&one, 0); |
| 5515 | if( sqlite3_vfs_find(0) ) return TCL_ERROR; |
| 5516 | sqlite3_vfs_register(&one, 1); |
| 5517 | if( sqlite3_vfs_find(0) ) return TCL_ERROR; |
| 5518 | return TCL_OK; |
| 5519 | } |
| 5520 | |
| 5521 | /* |
drh | a282097 | 2008-07-07 13:31:58 +0000 | [diff] [blame] | 5522 | ** Saved VFSes |
| 5523 | */ |
| 5524 | static sqlite3_vfs *apVfs[20]; |
| 5525 | static int nVfs = 0; |
| 5526 | |
| 5527 | /* |
| 5528 | ** tclcmd: vfs_unregister_all |
| 5529 | ** |
| 5530 | ** Unregister all VFSes. |
| 5531 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5532 | static int SQLITE_TCLAPI vfs_unregister_all( |
drh | a282097 | 2008-07-07 13:31:58 +0000 | [diff] [blame] | 5533 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5534 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5535 | int objc, /* Number of arguments */ |
| 5536 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5537 | ){ |
| 5538 | int i; |
| 5539 | for(i=0; i<ArraySize(apVfs); i++){ |
| 5540 | apVfs[i] = sqlite3_vfs_find(0); |
| 5541 | if( apVfs[i]==0 ) break; |
| 5542 | sqlite3_vfs_unregister(apVfs[i]); |
| 5543 | } |
| 5544 | nVfs = i; |
| 5545 | return TCL_OK; |
| 5546 | } |
| 5547 | /* |
| 5548 | ** tclcmd: vfs_reregister_all |
| 5549 | ** |
dan | 05accd2 | 2016-04-27 18:54:49 +0000 | [diff] [blame] | 5550 | ** Restore all VFSes that were removed using vfs_unregister_all. Taking |
| 5551 | ** care to put the linked list back together in the same order as it was |
| 5552 | ** in before vfs_unregister_all was invoked. |
drh | a282097 | 2008-07-07 13:31:58 +0000 | [diff] [blame] | 5553 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5554 | static int SQLITE_TCLAPI vfs_reregister_all( |
drh | a282097 | 2008-07-07 13:31:58 +0000 | [diff] [blame] | 5555 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5556 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5557 | int objc, /* Number of arguments */ |
| 5558 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5559 | ){ |
| 5560 | int i; |
dan | 05accd2 | 2016-04-27 18:54:49 +0000 | [diff] [blame] | 5561 | for(i=nVfs-1; i>=0; i--){ |
| 5562 | sqlite3_vfs_register(apVfs[i], 1); |
drh | a282097 | 2008-07-07 13:31:58 +0000 | [diff] [blame] | 5563 | } |
| 5564 | return TCL_OK; |
| 5565 | } |
| 5566 | |
| 5567 | |
| 5568 | /* |
drh | 5517625 | 2008-01-22 14:50:16 +0000 | [diff] [blame] | 5569 | ** tclcmd: file_control_test DB |
| 5570 | ** |
| 5571 | ** This TCL command runs the sqlite3_file_control interface and |
| 5572 | ** verifies correct operation of the same. |
| 5573 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5574 | static int SQLITE_TCLAPI file_control_test( |
drh | 5517625 | 2008-01-22 14:50:16 +0000 | [diff] [blame] | 5575 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5576 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5577 | int objc, /* Number of arguments */ |
| 5578 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5579 | ){ |
| 5580 | int iArg = 0; |
| 5581 | sqlite3 *db; |
| 5582 | int rc; |
| 5583 | |
| 5584 | if( objc!=2 ){ |
| 5585 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 5586 | Tcl_GetStringFromObj(objv[0], 0), " DB", 0); |
| 5587 | return TCL_ERROR; |
| 5588 | } |
| 5589 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 5590 | rc = sqlite3_file_control(db, 0, 0, &iArg); |
drh | 0b52b7d | 2011-01-26 19:46:22 +0000 | [diff] [blame] | 5591 | assert( rc==SQLITE_NOTFOUND ); |
drh | 5517625 | 2008-01-22 14:50:16 +0000 | [diff] [blame] | 5592 | rc = sqlite3_file_control(db, "notadatabase", SQLITE_FCNTL_LOCKSTATE, &iArg); |
| 5593 | assert( rc==SQLITE_ERROR ); |
| 5594 | rc = sqlite3_file_control(db, "main", -1, &iArg); |
drh | 0b52b7d | 2011-01-26 19:46:22 +0000 | [diff] [blame] | 5595 | assert( rc==SQLITE_NOTFOUND ); |
drh | 5517625 | 2008-01-22 14:50:16 +0000 | [diff] [blame] | 5596 | rc = sqlite3_file_control(db, "temp", -1, &iArg); |
drh | 0b52b7d | 2011-01-26 19:46:22 +0000 | [diff] [blame] | 5597 | assert( rc==SQLITE_NOTFOUND || rc==SQLITE_ERROR ); |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5598 | |
| 5599 | return TCL_OK; |
| 5600 | } |
| 5601 | |
| 5602 | |
| 5603 | /* |
| 5604 | ** tclcmd: file_control_lasterrno_test DB |
| 5605 | ** |
| 5606 | ** This TCL command runs the sqlite3_file_control interface and |
| 5607 | ** verifies correct operation of the SQLITE_LAST_ERRNO verb. |
| 5608 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5609 | static int SQLITE_TCLAPI file_control_lasterrno_test( |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5610 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5611 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5612 | int objc, /* Number of arguments */ |
| 5613 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5614 | ){ |
| 5615 | int iArg = 0; |
| 5616 | sqlite3 *db; |
| 5617 | int rc; |
| 5618 | |
| 5619 | if( objc!=2 ){ |
| 5620 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 5621 | Tcl_GetStringFromObj(objv[0], 0), " DB", 0); |
| 5622 | return TCL_ERROR; |
| 5623 | } |
shane | 9db299f | 2009-01-30 05:59:10 +0000 | [diff] [blame] | 5624 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 5625 | return TCL_ERROR; |
| 5626 | } |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5627 | rc = sqlite3_file_control(db, NULL, SQLITE_LAST_ERRNO, &iArg); |
shane | 9db299f | 2009-01-30 05:59:10 +0000 | [diff] [blame] | 5628 | if( rc ){ |
| 5629 | Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
| 5630 | return TCL_ERROR; |
| 5631 | } |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5632 | if( iArg!=0 ) { |
| 5633 | Tcl_AppendResult(interp, "Unexpected non-zero errno: ", |
| 5634 | Tcl_GetStringFromObj(Tcl_NewIntObj(iArg), 0), " ", 0); |
| 5635 | return TCL_ERROR; |
| 5636 | } |
drh | 5517625 | 2008-01-22 14:50:16 +0000 | [diff] [blame] | 5637 | return TCL_OK; |
| 5638 | } |
| 5639 | |
| 5640 | /* |
dan | 6e09d69 | 2010-07-27 18:34:15 +0000 | [diff] [blame] | 5641 | ** tclcmd: file_control_chunksize_test DB DBNAME SIZE |
| 5642 | ** |
| 5643 | ** This TCL command runs the sqlite3_file_control interface and |
| 5644 | ** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and |
| 5645 | ** SQLITE_SET_LOCKPROXYFILE verbs. |
| 5646 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5647 | static int SQLITE_TCLAPI file_control_chunksize_test( |
dan | 6e09d69 | 2010-07-27 18:34:15 +0000 | [diff] [blame] | 5648 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5649 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5650 | int objc, /* Number of arguments */ |
| 5651 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5652 | ){ |
| 5653 | int nSize; /* New chunk size */ |
| 5654 | char *zDb; /* Db name ("main", "temp" etc.) */ |
| 5655 | sqlite3 *db; /* Database handle */ |
| 5656 | int rc; /* file_control() return code */ |
| 5657 | |
| 5658 | if( objc!=4 ){ |
| 5659 | Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME SIZE"); |
| 5660 | return TCL_ERROR; |
| 5661 | } |
| 5662 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) |
| 5663 | || Tcl_GetIntFromObj(interp, objv[3], &nSize) |
| 5664 | ){ |
| 5665 | return TCL_ERROR; |
| 5666 | } |
| 5667 | zDb = Tcl_GetString(objv[2]); |
| 5668 | if( zDb[0]=='\0' ) zDb = NULL; |
| 5669 | |
| 5670 | rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_CHUNK_SIZE, (void *)&nSize); |
| 5671 | if( rc ){ |
mistachkin | e84d8d3 | 2013-04-29 03:09:10 +0000 | [diff] [blame] | 5672 | Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC); |
dan | 6e09d69 | 2010-07-27 18:34:15 +0000 | [diff] [blame] | 5673 | return TCL_ERROR; |
| 5674 | } |
| 5675 | return TCL_OK; |
| 5676 | } |
| 5677 | |
| 5678 | /* |
dan | 661d71a | 2011-03-30 19:08:03 +0000 | [diff] [blame] | 5679 | ** tclcmd: file_control_sizehint_test DB DBNAME SIZE |
| 5680 | ** |
drh | fdd7f71 | 2011-08-13 10:47:51 +0000 | [diff] [blame] | 5681 | ** This TCL command runs the sqlite3_file_control interface |
| 5682 | ** with SQLITE_FCNTL_SIZE_HINT |
dan | 661d71a | 2011-03-30 19:08:03 +0000 | [diff] [blame] | 5683 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5684 | static int SQLITE_TCLAPI file_control_sizehint_test( |
dan | 661d71a | 2011-03-30 19:08:03 +0000 | [diff] [blame] | 5685 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5686 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5687 | int objc, /* Number of arguments */ |
| 5688 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5689 | ){ |
drh | b3f787f | 2012-09-29 14:45:54 +0000 | [diff] [blame] | 5690 | Tcl_WideInt nSize; /* Hinted size */ |
dan | 661d71a | 2011-03-30 19:08:03 +0000 | [diff] [blame] | 5691 | char *zDb; /* Db name ("main", "temp" etc.) */ |
| 5692 | sqlite3 *db; /* Database handle */ |
| 5693 | int rc; /* file_control() return code */ |
| 5694 | |
| 5695 | if( objc!=4 ){ |
| 5696 | Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME SIZE"); |
| 5697 | return TCL_ERROR; |
| 5698 | } |
| 5699 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) |
| 5700 | || Tcl_GetWideIntFromObj(interp, objv[3], &nSize) |
| 5701 | ){ |
| 5702 | return TCL_ERROR; |
| 5703 | } |
| 5704 | zDb = Tcl_GetString(objv[2]); |
| 5705 | if( zDb[0]=='\0' ) zDb = NULL; |
| 5706 | |
| 5707 | rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_SIZE_HINT, (void *)&nSize); |
| 5708 | if( rc ){ |
mistachkin | e84d8d3 | 2013-04-29 03:09:10 +0000 | [diff] [blame] | 5709 | Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC); |
dan | 661d71a | 2011-03-30 19:08:03 +0000 | [diff] [blame] | 5710 | return TCL_ERROR; |
| 5711 | } |
| 5712 | return TCL_OK; |
| 5713 | } |
| 5714 | |
| 5715 | /* |
drh | ad24581 | 2010-06-01 00:28:42 +0000 | [diff] [blame] | 5716 | ** tclcmd: file_control_lockproxy_test DB PWD |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5717 | ** |
| 5718 | ** This TCL command runs the sqlite3_file_control interface and |
| 5719 | ** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and |
| 5720 | ** SQLITE_SET_LOCKPROXYFILE verbs. |
| 5721 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5722 | static int SQLITE_TCLAPI file_control_lockproxy_test( |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5723 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5724 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5725 | int objc, /* Number of arguments */ |
| 5726 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5727 | ){ |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5728 | sqlite3 *db; |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5729 | |
drh | ad24581 | 2010-06-01 00:28:42 +0000 | [diff] [blame] | 5730 | if( objc!=3 ){ |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5731 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | ad24581 | 2010-06-01 00:28:42 +0000 | [diff] [blame] | 5732 | Tcl_GetStringFromObj(objv[0], 0), " DB PWD", 0); |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5733 | return TCL_ERROR; |
| 5734 | } |
shane | 9db299f | 2009-01-30 05:59:10 +0000 | [diff] [blame] | 5735 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 5736 | return TCL_ERROR; |
| 5737 | } |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5738 | |
drh | 9b35ea6 | 2008-11-29 02:20:26 +0000 | [diff] [blame] | 5739 | #if !defined(SQLITE_ENABLE_LOCKING_STYLE) |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 5740 | # if defined(__APPLE__) |
drh | 9b35ea6 | 2008-11-29 02:20:26 +0000 | [diff] [blame] | 5741 | # define SQLITE_ENABLE_LOCKING_STYLE 1 |
| 5742 | # else |
| 5743 | # define SQLITE_ENABLE_LOCKING_STYLE 0 |
| 5744 | # endif |
| 5745 | #endif |
drh | d2cb50b | 2009-01-09 21:41:17 +0000 | [diff] [blame] | 5746 | #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) |
drh | 7708e97 | 2008-11-29 00:56:52 +0000 | [diff] [blame] | 5747 | { |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5748 | char *testPath; |
drh | 103fe74 | 2008-12-11 02:56:07 +0000 | [diff] [blame] | 5749 | int rc; |
drh | caffb1a | 2012-01-30 18:00:31 +0000 | [diff] [blame] | 5750 | int nPwd; |
| 5751 | const char *zPwd; |
drh | ad24581 | 2010-06-01 00:28:42 +0000 | [diff] [blame] | 5752 | char proxyPath[400]; |
| 5753 | |
drh | caffb1a | 2012-01-30 18:00:31 +0000 | [diff] [blame] | 5754 | zPwd = Tcl_GetStringFromObj(objv[2], &nPwd); |
drh | ad24581 | 2010-06-01 00:28:42 +0000 | [diff] [blame] | 5755 | if( sizeof(proxyPath)<nPwd+20 ){ |
| 5756 | Tcl_AppendResult(interp, "PWD too big", (void*)0); |
| 5757 | return TCL_ERROR; |
| 5758 | } |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 5759 | sqlite3_snprintf(sizeof(proxyPath), proxyPath, "%s/test.proxy", zPwd); |
drh | 7708e97 | 2008-11-29 00:56:52 +0000 | [diff] [blame] | 5760 | rc = sqlite3_file_control(db, NULL, SQLITE_SET_LOCKPROXYFILE, proxyPath); |
| 5761 | if( rc ){ |
shane | 9db299f | 2009-01-30 05:59:10 +0000 | [diff] [blame] | 5762 | Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
| 5763 | return TCL_ERROR; |
drh | 7708e97 | 2008-11-29 00:56:52 +0000 | [diff] [blame] | 5764 | } |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5765 | rc = sqlite3_file_control(db, NULL, SQLITE_GET_LOCKPROXYFILE, &testPath); |
shane | 9db299f | 2009-01-30 05:59:10 +0000 | [diff] [blame] | 5766 | if( strncmp(proxyPath,testPath,11) ){ |
drh | 7708e97 | 2008-11-29 00:56:52 +0000 | [diff] [blame] | 5767 | Tcl_AppendResult(interp, "Lock proxy file did not match the " |
| 5768 | "previously assigned value", 0); |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5769 | return TCL_ERROR; |
| 5770 | } |
drh | 7708e97 | 2008-11-29 00:56:52 +0000 | [diff] [blame] | 5771 | if( rc ){ |
| 5772 | Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
| 5773 | return TCL_ERROR; |
| 5774 | } |
| 5775 | rc = sqlite3_file_control(db, NULL, SQLITE_SET_LOCKPROXYFILE, proxyPath); |
| 5776 | if( rc ){ |
| 5777 | Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
| 5778 | return TCL_ERROR; |
| 5779 | } |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5780 | } |
| 5781 | #endif |
| 5782 | return TCL_OK; |
| 5783 | } |
| 5784 | |
mistachkin | 6b98d67 | 2014-05-30 16:42:35 +0000 | [diff] [blame] | 5785 | #if SQLITE_OS_WIN |
drh | d0cdf01 | 2011-07-13 16:03:46 +0000 | [diff] [blame] | 5786 | /* |
| 5787 | ** tclcmd: file_control_win32_av_retry DB NRETRY DELAY |
| 5788 | ** |
| 5789 | ** This TCL command runs the sqlite3_file_control interface with |
| 5790 | ** the SQLITE_FCNTL_WIN32_AV_RETRY opcode. |
| 5791 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5792 | static int SQLITE_TCLAPI file_control_win32_av_retry( |
drh | d0cdf01 | 2011-07-13 16:03:46 +0000 | [diff] [blame] | 5793 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5794 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5795 | int objc, /* Number of arguments */ |
| 5796 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5797 | ){ |
| 5798 | sqlite3 *db; |
| 5799 | int rc; |
| 5800 | int a[2]; |
| 5801 | char z[100]; |
| 5802 | |
| 5803 | if( objc!=4 ){ |
| 5804 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 5805 | Tcl_GetStringFromObj(objv[0], 0), " DB NRETRY DELAY", 0); |
| 5806 | return TCL_ERROR; |
| 5807 | } |
| 5808 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 5809 | return TCL_ERROR; |
| 5810 | } |
| 5811 | if( Tcl_GetIntFromObj(interp, objv[2], &a[0]) ) return TCL_ERROR; |
| 5812 | if( Tcl_GetIntFromObj(interp, objv[3], &a[1]) ) return TCL_ERROR; |
| 5813 | rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_WIN32_AV_RETRY, (void*)a); |
| 5814 | sqlite3_snprintf(sizeof(z), z, "%d %d %d", rc, a[0], a[1]); |
| 5815 | Tcl_AppendResult(interp, z, (char*)0); |
| 5816 | return TCL_OK; |
| 5817 | } |
| 5818 | |
drh | 253cea5 | 2011-07-26 16:23:25 +0000 | [diff] [blame] | 5819 | /* |
mistachkin | 1b361ff | 2016-05-03 19:36:54 +0000 | [diff] [blame] | 5820 | ** tclcmd: file_control_win32_get_handle DB |
| 5821 | ** |
| 5822 | ** This TCL command runs the sqlite3_file_control interface with |
| 5823 | ** the SQLITE_FCNTL_WIN32_GET_HANDLE opcode. |
| 5824 | */ |
| 5825 | static int file_control_win32_get_handle( |
| 5826 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5827 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5828 | int objc, /* Number of arguments */ |
| 5829 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5830 | ){ |
| 5831 | sqlite3 *db; |
| 5832 | int rc; |
| 5833 | HANDLE hFile = NULL; |
| 5834 | char z[100]; |
| 5835 | |
| 5836 | if( objc!=2 ){ |
| 5837 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 5838 | Tcl_GetStringFromObj(objv[0], 0), " DB", 0); |
| 5839 | return TCL_ERROR; |
| 5840 | } |
| 5841 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 5842 | return TCL_ERROR; |
| 5843 | } |
| 5844 | rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_WIN32_GET_HANDLE, |
| 5845 | (void*)&hFile); |
| 5846 | sqlite3_snprintf(sizeof(z), z, "%d %p", rc, (void*)hFile); |
| 5847 | Tcl_AppendResult(interp, z, (char*)0); |
mistachkin | 8705f86 | 2016-10-14 21:27:50 +0000 | [diff] [blame] | 5848 | return TCL_OK; |
mistachkin | 1b361ff | 2016-05-03 19:36:54 +0000 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | /* |
mistachkin | 6b98d67 | 2014-05-30 16:42:35 +0000 | [diff] [blame] | 5852 | ** tclcmd: file_control_win32_set_handle DB HANDLE |
| 5853 | ** |
| 5854 | ** This TCL command runs the sqlite3_file_control interface with |
| 5855 | ** the SQLITE_FCNTL_WIN32_SET_HANDLE opcode. |
| 5856 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5857 | static int SQLITE_TCLAPI file_control_win32_set_handle( |
mistachkin | 6b98d67 | 2014-05-30 16:42:35 +0000 | [diff] [blame] | 5858 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5859 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5860 | int objc, /* Number of arguments */ |
| 5861 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5862 | ){ |
| 5863 | sqlite3 *db; |
| 5864 | int rc; |
| 5865 | HANDLE hFile = NULL; |
| 5866 | char z[100]; |
| 5867 | |
| 5868 | if( objc!=3 ){ |
| 5869 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 5870 | Tcl_GetStringFromObj(objv[0], 0), " DB HANDLE", 0); |
| 5871 | return TCL_ERROR; |
| 5872 | } |
| 5873 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 5874 | return TCL_ERROR; |
| 5875 | } |
| 5876 | if( getWin32Handle(interp, Tcl_GetString(objv[2]), &hFile) ){ |
| 5877 | return TCL_ERROR; |
| 5878 | } |
| 5879 | rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_WIN32_SET_HANDLE, |
| 5880 | (void*)&hFile); |
| 5881 | sqlite3_snprintf(sizeof(z), z, "%d %p", rc, (void*)hFile); |
| 5882 | Tcl_AppendResult(interp, z, (char*)0); |
| 5883 | return TCL_OK; |
| 5884 | } |
| 5885 | #endif |
| 5886 | |
| 5887 | /* |
drh | 253cea5 | 2011-07-26 16:23:25 +0000 | [diff] [blame] | 5888 | ** tclcmd: file_control_persist_wal DB PERSIST-FLAG |
| 5889 | ** |
| 5890 | ** This TCL command runs the sqlite3_file_control interface with |
| 5891 | ** the SQLITE_FCNTL_PERSIST_WAL opcode. |
| 5892 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5893 | static int SQLITE_TCLAPI file_control_persist_wal( |
drh | 253cea5 | 2011-07-26 16:23:25 +0000 | [diff] [blame] | 5894 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5895 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5896 | int objc, /* Number of arguments */ |
| 5897 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5898 | ){ |
| 5899 | sqlite3 *db; |
| 5900 | int rc; |
| 5901 | int bPersist; |
| 5902 | char z[100]; |
| 5903 | |
| 5904 | if( objc!=3 ){ |
| 5905 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 5906 | Tcl_GetStringFromObj(objv[0], 0), " DB FLAG", 0); |
| 5907 | return TCL_ERROR; |
| 5908 | } |
| 5909 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 5910 | return TCL_ERROR; |
| 5911 | } |
| 5912 | if( Tcl_GetIntFromObj(interp, objv[2], &bPersist) ) return TCL_ERROR; |
| 5913 | rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_PERSIST_WAL, (void*)&bPersist); |
| 5914 | sqlite3_snprintf(sizeof(z), z, "%d %d", rc, bPersist); |
| 5915 | Tcl_AppendResult(interp, z, (char*)0); |
| 5916 | return TCL_OK; |
| 5917 | } |
| 5918 | |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 5919 | /* |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame] | 5920 | ** tclcmd: file_control_powersafe_overwrite DB PSOW-FLAG |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 5921 | ** |
| 5922 | ** This TCL command runs the sqlite3_file_control interface with |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame] | 5923 | ** the SQLITE_FCNTL_POWERSAFE_OVERWRITE opcode. |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 5924 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5925 | static int SQLITE_TCLAPI file_control_powersafe_overwrite( |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 5926 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5927 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5928 | int objc, /* Number of arguments */ |
| 5929 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5930 | ){ |
| 5931 | sqlite3 *db; |
| 5932 | int rc; |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame] | 5933 | int b; |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 5934 | char z[100]; |
| 5935 | |
| 5936 | if( objc!=3 ){ |
| 5937 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 5938 | Tcl_GetStringFromObj(objv[0], 0), " DB FLAG", 0); |
| 5939 | return TCL_ERROR; |
| 5940 | } |
| 5941 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 5942 | return TCL_ERROR; |
| 5943 | } |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame] | 5944 | if( Tcl_GetIntFromObj(interp, objv[2], &b) ) return TCL_ERROR; |
| 5945 | rc = sqlite3_file_control(db,NULL,SQLITE_FCNTL_POWERSAFE_OVERWRITE,(void*)&b); |
| 5946 | sqlite3_snprintf(sizeof(z), z, "%d %d", rc, b); |
drh | f12b3f6 | 2011-12-21 14:42:29 +0000 | [diff] [blame] | 5947 | Tcl_AppendResult(interp, z, (char*)0); |
| 5948 | return TCL_OK; |
| 5949 | } |
| 5950 | |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 5951 | |
| 5952 | /* |
drh | de60fc2 | 2011-12-14 17:53:36 +0000 | [diff] [blame] | 5953 | ** tclcmd: file_control_vfsname DB ?AUXDB? |
| 5954 | ** |
| 5955 | ** Return a string that describes the stack of VFSes. |
| 5956 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5957 | static int SQLITE_TCLAPI file_control_vfsname( |
drh | de60fc2 | 2011-12-14 17:53:36 +0000 | [diff] [blame] | 5958 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5959 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5960 | int objc, /* Number of arguments */ |
| 5961 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5962 | ){ |
| 5963 | sqlite3 *db; |
| 5964 | const char *zDbName = "main"; |
| 5965 | char *zVfsName = 0; |
| 5966 | |
| 5967 | if( objc!=2 && objc!=3 ){ |
| 5968 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 5969 | Tcl_GetStringFromObj(objv[0], 0), " DB ?AUXDB?", 0); |
| 5970 | return TCL_ERROR; |
| 5971 | } |
| 5972 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 5973 | return TCL_ERROR; |
| 5974 | } |
| 5975 | if( objc==3 ){ |
| 5976 | zDbName = Tcl_GetString(objv[2]); |
| 5977 | } |
| 5978 | sqlite3_file_control(db, zDbName, SQLITE_FCNTL_VFSNAME,(void*)&zVfsName); |
| 5979 | Tcl_AppendResult(interp, zVfsName, (char*)0); |
| 5980 | sqlite3_free(zVfsName); |
| 5981 | return TCL_OK; |
| 5982 | } |
| 5983 | |
drh | 696b33e | 2012-12-06 19:01:42 +0000 | [diff] [blame] | 5984 | /* |
| 5985 | ** tclcmd: file_control_tempfilename DB ?AUXDB? |
| 5986 | ** |
| 5987 | ** Return a string that is a temporary filename |
| 5988 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 5989 | static int SQLITE_TCLAPI file_control_tempfilename( |
drh | 696b33e | 2012-12-06 19:01:42 +0000 | [diff] [blame] | 5990 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 5991 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 5992 | int objc, /* Number of arguments */ |
| 5993 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 5994 | ){ |
| 5995 | sqlite3 *db; |
| 5996 | const char *zDbName = "main"; |
| 5997 | char *zTName = 0; |
| 5998 | |
| 5999 | if( objc!=2 && objc!=3 ){ |
| 6000 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 6001 | Tcl_GetStringFromObj(objv[0], 0), " DB ?AUXDB?", 0); |
| 6002 | return TCL_ERROR; |
| 6003 | } |
| 6004 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 6005 | return TCL_ERROR; |
| 6006 | } |
| 6007 | if( objc==3 ){ |
| 6008 | zDbName = Tcl_GetString(objv[2]); |
| 6009 | } |
| 6010 | sqlite3_file_control(db, zDbName, SQLITE_FCNTL_TEMPFILENAME, (void*)&zTName); |
| 6011 | Tcl_AppendResult(interp, zTName, (char*)0); |
| 6012 | sqlite3_free(zTName); |
| 6013 | return TCL_OK; |
| 6014 | } |
| 6015 | |
drh | de60fc2 | 2011-12-14 17:53:36 +0000 | [diff] [blame] | 6016 | |
| 6017 | /* |
danielk1977 | e339d65 | 2008-06-28 11:23:00 +0000 | [diff] [blame] | 6018 | ** tclcmd: sqlite3_vfs_list |
| 6019 | ** |
| 6020 | ** Return a tcl list containing the names of all registered vfs's. |
| 6021 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6022 | static int SQLITE_TCLAPI vfs_list( |
danielk1977 | e339d65 | 2008-06-28 11:23:00 +0000 | [diff] [blame] | 6023 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 6024 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6025 | int objc, /* Number of arguments */ |
| 6026 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6027 | ){ |
| 6028 | sqlite3_vfs *pVfs; |
| 6029 | Tcl_Obj *pRet = Tcl_NewObj(); |
| 6030 | if( objc!=1 ){ |
| 6031 | Tcl_WrongNumArgs(interp, 1, objv, ""); |
| 6032 | return TCL_ERROR; |
| 6033 | } |
| 6034 | for(pVfs=sqlite3_vfs_find(0); pVfs; pVfs=pVfs->pNext){ |
| 6035 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(pVfs->zName, -1)); |
| 6036 | } |
| 6037 | Tcl_SetObjResult(interp, pRet); |
| 6038 | return TCL_OK; |
| 6039 | } |
| 6040 | |
| 6041 | /* |
drh | b1a6c3c | 2008-03-20 16:30:17 +0000 | [diff] [blame] | 6042 | ** tclcmd: sqlite3_limit DB ID VALUE |
| 6043 | ** |
| 6044 | ** This TCL command runs the sqlite3_limit interface and |
| 6045 | ** verifies correct operation of the same. |
| 6046 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6047 | static int SQLITE_TCLAPI test_limit( |
drh | b1a6c3c | 2008-03-20 16:30:17 +0000 | [diff] [blame] | 6048 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 6049 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6050 | int objc, /* Number of arguments */ |
| 6051 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6052 | ){ |
| 6053 | sqlite3 *db; |
| 6054 | int rc; |
| 6055 | static const struct { |
| 6056 | char *zName; |
| 6057 | int id; |
| 6058 | } aId[] = { |
| 6059 | { "SQLITE_LIMIT_LENGTH", SQLITE_LIMIT_LENGTH }, |
| 6060 | { "SQLITE_LIMIT_SQL_LENGTH", SQLITE_LIMIT_SQL_LENGTH }, |
| 6061 | { "SQLITE_LIMIT_COLUMN", SQLITE_LIMIT_COLUMN }, |
| 6062 | { "SQLITE_LIMIT_EXPR_DEPTH", SQLITE_LIMIT_EXPR_DEPTH }, |
| 6063 | { "SQLITE_LIMIT_COMPOUND_SELECT", SQLITE_LIMIT_COMPOUND_SELECT }, |
| 6064 | { "SQLITE_LIMIT_VDBE_OP", SQLITE_LIMIT_VDBE_OP }, |
| 6065 | { "SQLITE_LIMIT_FUNCTION_ARG", SQLITE_LIMIT_FUNCTION_ARG }, |
| 6066 | { "SQLITE_LIMIT_ATTACHED", SQLITE_LIMIT_ATTACHED }, |
| 6067 | { "SQLITE_LIMIT_LIKE_PATTERN_LENGTH", SQLITE_LIMIT_LIKE_PATTERN_LENGTH }, |
| 6068 | { "SQLITE_LIMIT_VARIABLE_NUMBER", SQLITE_LIMIT_VARIABLE_NUMBER }, |
drh | 417168a | 2009-09-07 18:14:02 +0000 | [diff] [blame] | 6069 | { "SQLITE_LIMIT_TRIGGER_DEPTH", SQLITE_LIMIT_TRIGGER_DEPTH }, |
drh | 3705ef6 | 2014-10-08 15:53:21 +0000 | [diff] [blame] | 6070 | { "SQLITE_LIMIT_WORKER_THREADS", SQLITE_LIMIT_WORKER_THREADS }, |
drh | 521cc84 | 2008-04-15 02:36:33 +0000 | [diff] [blame] | 6071 | |
| 6072 | /* Out of range test cases */ |
| 6073 | { "SQLITE_LIMIT_TOOSMALL", -1, }, |
drh | 3705ef6 | 2014-10-08 15:53:21 +0000 | [diff] [blame] | 6074 | { "SQLITE_LIMIT_TOOBIG", SQLITE_LIMIT_WORKER_THREADS+1 }, |
drh | b1a6c3c | 2008-03-20 16:30:17 +0000 | [diff] [blame] | 6075 | }; |
mistachkin | 27b2f05 | 2015-01-12 19:49:46 +0000 | [diff] [blame] | 6076 | int i, id = 0; |
drh | b1a6c3c | 2008-03-20 16:30:17 +0000 | [diff] [blame] | 6077 | int val; |
| 6078 | const char *zId; |
| 6079 | |
| 6080 | if( objc!=4 ){ |
| 6081 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 6082 | Tcl_GetStringFromObj(objv[0], 0), " DB ID VALUE", 0); |
| 6083 | return TCL_ERROR; |
| 6084 | } |
| 6085 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 6086 | zId = Tcl_GetString(objv[2]); |
| 6087 | for(i=0; i<sizeof(aId)/sizeof(aId[0]); i++){ |
| 6088 | if( strcmp(zId, aId[i].zName)==0 ){ |
| 6089 | id = aId[i].id; |
| 6090 | break; |
| 6091 | } |
| 6092 | } |
| 6093 | if( i>=sizeof(aId)/sizeof(aId[0]) ){ |
| 6094 | Tcl_AppendResult(interp, "unknown limit type: ", zId, (char*)0); |
| 6095 | return TCL_ERROR; |
| 6096 | } |
| 6097 | if( Tcl_GetIntFromObj(interp, objv[3], &val) ) return TCL_ERROR; |
| 6098 | rc = sqlite3_limit(db, id, val); |
| 6099 | Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
| 6100 | return TCL_OK; |
| 6101 | } |
| 6102 | |
| 6103 | /* |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 6104 | ** tclcmd: save_prng_state |
drh | a282097 | 2008-07-07 13:31:58 +0000 | [diff] [blame] | 6105 | ** |
| 6106 | ** Save the state of the pseudo-random number generator. |
| 6107 | ** At the same time, verify that sqlite3_test_control works even when |
| 6108 | ** called with an out-of-range opcode. |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 6109 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6110 | static int SQLITE_TCLAPI save_prng_state( |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 6111 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 6112 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6113 | int objc, /* Number of arguments */ |
| 6114 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6115 | ){ |
drh | a282097 | 2008-07-07 13:31:58 +0000 | [diff] [blame] | 6116 | int rc = sqlite3_test_control(9999); |
| 6117 | assert( rc==0 ); |
| 6118 | rc = sqlite3_test_control(-1); |
| 6119 | assert( rc==0 ); |
drh | 2fa1868 | 2008-03-19 14:15:34 +0000 | [diff] [blame] | 6120 | sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SAVE); |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 6121 | return TCL_OK; |
| 6122 | } |
| 6123 | /* |
| 6124 | ** tclcmd: restore_prng_state |
| 6125 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6126 | static int SQLITE_TCLAPI restore_prng_state( |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 6127 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 6128 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6129 | int objc, /* Number of arguments */ |
| 6130 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6131 | ){ |
drh | 2fa1868 | 2008-03-19 14:15:34 +0000 | [diff] [blame] | 6132 | sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESTORE); |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 6133 | return TCL_OK; |
| 6134 | } |
| 6135 | /* |
| 6136 | ** tclcmd: reset_prng_state |
| 6137 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6138 | static int SQLITE_TCLAPI reset_prng_state( |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 6139 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 6140 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6141 | int objc, /* Number of arguments */ |
| 6142 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6143 | ){ |
drh | 2fa1868 | 2008-03-19 14:15:34 +0000 | [diff] [blame] | 6144 | sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESET); |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 6145 | return TCL_OK; |
| 6146 | } |
| 6147 | |
danielk1977 | 062d4cb | 2008-08-29 09:10:02 +0000 | [diff] [blame] | 6148 | /* |
drh | 09fe614 | 2013-11-29 15:06:27 +0000 | [diff] [blame] | 6149 | ** tclcmd: database_may_be_corrupt |
| 6150 | ** |
| 6151 | ** Indicate that database files might be corrupt. In other words, set the normal |
| 6152 | ** state of operation. |
| 6153 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6154 | static int SQLITE_TCLAPI database_may_be_corrupt( |
drh | 09fe614 | 2013-11-29 15:06:27 +0000 | [diff] [blame] | 6155 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 6156 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6157 | int objc, /* Number of arguments */ |
| 6158 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6159 | ){ |
| 6160 | sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, 0); |
| 6161 | return TCL_OK; |
| 6162 | } |
| 6163 | /* |
| 6164 | ** tclcmd: database_never_corrupt |
| 6165 | ** |
| 6166 | ** Indicate that database files are always well-formed. This enables extra assert() |
| 6167 | ** statements that test conditions that are always true for well-formed databases. |
| 6168 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6169 | static int SQLITE_TCLAPI database_never_corrupt( |
drh | 09fe614 | 2013-11-29 15:06:27 +0000 | [diff] [blame] | 6170 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 6171 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6172 | int objc, /* Number of arguments */ |
| 6173 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6174 | ){ |
| 6175 | sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, 1); |
| 6176 | return TCL_OK; |
| 6177 | } |
| 6178 | |
| 6179 | /* |
danielk1977 | 062d4cb | 2008-08-29 09:10:02 +0000 | [diff] [blame] | 6180 | ** tclcmd: pcache_stats |
| 6181 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6182 | static int SQLITE_TCLAPI test_pcache_stats( |
danielk1977 | 062d4cb | 2008-08-29 09:10:02 +0000 | [diff] [blame] | 6183 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 6184 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6185 | int objc, /* Number of arguments */ |
| 6186 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6187 | ){ |
| 6188 | int nMin; |
| 6189 | int nMax; |
| 6190 | int nCurrent; |
| 6191 | int nRecyclable; |
| 6192 | Tcl_Obj *pRet; |
| 6193 | |
| 6194 | sqlite3PcacheStats(&nCurrent, &nMax, &nMin, &nRecyclable); |
| 6195 | |
| 6196 | pRet = Tcl_NewObj(); |
| 6197 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("current", -1)); |
| 6198 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nCurrent)); |
| 6199 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("max", -1)); |
| 6200 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nMax)); |
| 6201 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("min", -1)); |
| 6202 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nMin)); |
| 6203 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("recyclable", -1)); |
| 6204 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nRecyclable)); |
| 6205 | |
| 6206 | Tcl_SetObjResult(interp, pRet); |
| 6207 | |
| 6208 | return TCL_OK; |
| 6209 | } |
| 6210 | |
drh | 69910da | 2009-03-27 12:32:54 +0000 | [diff] [blame] | 6211 | #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY |
danielk1977 | 404ca07 | 2009-03-16 13:19:36 +0000 | [diff] [blame] | 6212 | static void test_unlock_notify_cb(void **aArg, int nArg){ |
| 6213 | int ii; |
| 6214 | for(ii=0; ii<nArg; ii++){ |
| 6215 | Tcl_EvalEx((Tcl_Interp *)aArg[ii], "unlock_notify", -1, TCL_EVAL_GLOBAL); |
| 6216 | } |
| 6217 | } |
drh | 69910da | 2009-03-27 12:32:54 +0000 | [diff] [blame] | 6218 | #endif /* SQLITE_ENABLE_UNLOCK_NOTIFY */ |
danielk1977 | 404ca07 | 2009-03-16 13:19:36 +0000 | [diff] [blame] | 6219 | |
| 6220 | /* |
| 6221 | ** tclcmd: sqlite3_unlock_notify db |
| 6222 | */ |
| 6223 | #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6224 | static int SQLITE_TCLAPI test_unlock_notify( |
danielk1977 | 404ca07 | 2009-03-16 13:19:36 +0000 | [diff] [blame] | 6225 | ClientData clientData, /* Unused */ |
| 6226 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6227 | int objc, /* Number of arguments */ |
| 6228 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6229 | ){ |
| 6230 | sqlite3 *db; |
| 6231 | int rc; |
| 6232 | |
| 6233 | if( objc!=2 ){ |
| 6234 | Tcl_WrongNumArgs(interp, 1, objv, "DB"); |
| 6235 | return TCL_ERROR; |
| 6236 | } |
| 6237 | |
| 6238 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 6239 | return TCL_ERROR; |
| 6240 | } |
| 6241 | rc = sqlite3_unlock_notify(db, test_unlock_notify_cb, (void *)interp); |
| 6242 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
| 6243 | return TCL_OK; |
| 6244 | } |
| 6245 | #endif |
| 6246 | |
dan | 87c1fe1 | 2010-05-03 12:14:15 +0000 | [diff] [blame] | 6247 | /* |
| 6248 | ** tclcmd: sqlite3_wal_checkpoint db ?NAME? |
| 6249 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6250 | static int SQLITE_TCLAPI test_wal_checkpoint( |
dan | 87c1fe1 | 2010-05-03 12:14:15 +0000 | [diff] [blame] | 6251 | ClientData clientData, /* Unused */ |
| 6252 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6253 | int objc, /* Number of arguments */ |
| 6254 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6255 | ){ |
| 6256 | char *zDb = 0; |
| 6257 | sqlite3 *db; |
| 6258 | int rc; |
| 6259 | |
| 6260 | if( objc!=3 && objc!=2 ){ |
| 6261 | Tcl_WrongNumArgs(interp, 1, objv, "DB ?NAME?"); |
| 6262 | return TCL_ERROR; |
| 6263 | } |
| 6264 | |
| 6265 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 6266 | return TCL_ERROR; |
| 6267 | } |
| 6268 | if( objc==3 ){ |
| 6269 | zDb = Tcl_GetString(objv[2]); |
| 6270 | } |
| 6271 | rc = sqlite3_wal_checkpoint(db, zDb); |
| 6272 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
| 6273 | return TCL_OK; |
| 6274 | } |
| 6275 | |
dan | eb8763d | 2010-08-17 14:52:22 +0000 | [diff] [blame] | 6276 | /* |
dan | 9c5e368 | 2011-02-07 15:12:12 +0000 | [diff] [blame] | 6277 | ** tclcmd: sqlite3_wal_checkpoint_v2 db MODE ?NAME? |
| 6278 | ** |
| 6279 | ** This command calls the wal_checkpoint_v2() function with the specified |
| 6280 | ** mode argument (passive, full or restart). If present, the database name |
| 6281 | ** NAME is passed as the second argument to wal_checkpoint_v2(). If it the |
| 6282 | ** NAME argument is not present, a NULL pointer is passed instead. |
| 6283 | ** |
| 6284 | ** If wal_checkpoint_v2() returns any value other than SQLITE_BUSY or |
| 6285 | ** SQLITE_OK, then this command returns TCL_ERROR. The Tcl result is set |
| 6286 | ** to the error message obtained from sqlite3_errmsg(). |
| 6287 | ** |
| 6288 | ** Otherwise, this command returns a list of three integers. The first integer |
| 6289 | ** is 1 if SQLITE_BUSY was returned, or 0 otherwise. The following two integers |
drh | f7b5496 | 2013-05-28 12:11:54 +0000 | [diff] [blame] | 6290 | ** are the values returned via the output parameters by wal_checkpoint_v2() - |
dan | 9c5e368 | 2011-02-07 15:12:12 +0000 | [diff] [blame] | 6291 | ** the number of frames in the log and the number of frames in the log |
| 6292 | ** that have been checkpointed. |
| 6293 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6294 | static int SQLITE_TCLAPI test_wal_checkpoint_v2( |
dan | 9c5e368 | 2011-02-07 15:12:12 +0000 | [diff] [blame] | 6295 | ClientData clientData, /* Unused */ |
| 6296 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6297 | int objc, /* Number of arguments */ |
| 6298 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6299 | ){ |
| 6300 | char *zDb = 0; |
| 6301 | sqlite3 *db; |
| 6302 | int rc; |
| 6303 | |
| 6304 | int eMode; |
| 6305 | int nLog = -555; |
| 6306 | int nCkpt = -555; |
| 6307 | Tcl_Obj *pRet; |
| 6308 | |
dan | f26a154 | 2014-12-02 19:04:54 +0000 | [diff] [blame] | 6309 | const char * aMode[] = { "passive", "full", "restart", "truncate", 0 }; |
dan | 9c5e368 | 2011-02-07 15:12:12 +0000 | [diff] [blame] | 6310 | assert( SQLITE_CHECKPOINT_PASSIVE==0 ); |
| 6311 | assert( SQLITE_CHECKPOINT_FULL==1 ); |
| 6312 | assert( SQLITE_CHECKPOINT_RESTART==2 ); |
dan | f26a154 | 2014-12-02 19:04:54 +0000 | [diff] [blame] | 6313 | assert( SQLITE_CHECKPOINT_TRUNCATE==3 ); |
dan | 9c5e368 | 2011-02-07 15:12:12 +0000 | [diff] [blame] | 6314 | |
| 6315 | if( objc!=3 && objc!=4 ){ |
| 6316 | Tcl_WrongNumArgs(interp, 1, objv, "DB MODE ?NAME?"); |
| 6317 | return TCL_ERROR; |
| 6318 | } |
| 6319 | |
| 6320 | if( objc==4 ){ |
| 6321 | zDb = Tcl_GetString(objv[3]); |
| 6322 | } |
dan | 2928d32 | 2014-12-05 20:46:19 +0000 | [diff] [blame] | 6323 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) || ( |
| 6324 | TCL_OK!=Tcl_GetIntFromObj(0, objv[2], &eMode) |
| 6325 | && TCL_OK!=Tcl_GetIndexFromObj(interp, objv[2], aMode, "mode", 0, &eMode) |
| 6326 | )){ |
dan | 9c5e368 | 2011-02-07 15:12:12 +0000 | [diff] [blame] | 6327 | return TCL_ERROR; |
| 6328 | } |
| 6329 | |
| 6330 | rc = sqlite3_wal_checkpoint_v2(db, zDb, eMode, &nLog, &nCkpt); |
| 6331 | if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){ |
dan | 2928d32 | 2014-12-05 20:46:19 +0000 | [diff] [blame] | 6332 | const char *zErrCode = sqlite3ErrName(rc); |
dan | 9778bd7 | 2014-12-09 20:13:40 +0000 | [diff] [blame] | 6333 | Tcl_ResetResult(interp); |
dan | 2928d32 | 2014-12-05 20:46:19 +0000 | [diff] [blame] | 6334 | Tcl_AppendResult(interp, zErrCode, " - ", (char *)sqlite3_errmsg(db), 0); |
dan | 9c5e368 | 2011-02-07 15:12:12 +0000 | [diff] [blame] | 6335 | return TCL_ERROR; |
| 6336 | } |
| 6337 | |
| 6338 | pRet = Tcl_NewObj(); |
| 6339 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(rc==SQLITE_BUSY?1:0)); |
| 6340 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nLog)); |
| 6341 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nCkpt)); |
| 6342 | Tcl_SetObjResult(interp, pRet); |
| 6343 | |
| 6344 | return TCL_OK; |
| 6345 | } |
| 6346 | |
| 6347 | /* |
dan | 9af1062 | 2014-12-15 16:27:12 +0000 | [diff] [blame] | 6348 | ** tclcmd: sqlite3_wal_autocheckpoint db VALUE |
| 6349 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6350 | static int SQLITE_TCLAPI test_wal_autocheckpoint( |
dan | 9af1062 | 2014-12-15 16:27:12 +0000 | [diff] [blame] | 6351 | ClientData clientData, /* Unused */ |
| 6352 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6353 | int objc, /* Number of arguments */ |
| 6354 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6355 | ){ |
| 6356 | sqlite3 *db; |
| 6357 | int rc; |
| 6358 | int iVal; |
| 6359 | |
| 6360 | |
| 6361 | if( objc!=3 ){ |
| 6362 | Tcl_WrongNumArgs(interp, 1, objv, "DB VALUE"); |
| 6363 | return TCL_ERROR; |
| 6364 | } |
| 6365 | |
| 6366 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) |
| 6367 | || Tcl_GetIntFromObj(0, objv[2], &iVal) |
| 6368 | ){ |
| 6369 | return TCL_ERROR; |
| 6370 | } |
| 6371 | |
| 6372 | rc = sqlite3_wal_autocheckpoint(db, iVal); |
| 6373 | Tcl_ResetResult(interp); |
| 6374 | if( rc!=SQLITE_OK ){ |
| 6375 | const char *zErrCode = sqlite3ErrName(rc); |
| 6376 | Tcl_SetObjResult(interp, Tcl_NewStringObj(zErrCode, -1)); |
| 6377 | return TCL_ERROR; |
| 6378 | } |
| 6379 | |
| 6380 | return TCL_OK; |
| 6381 | } |
| 6382 | |
| 6383 | |
| 6384 | /* |
dan | eb8763d | 2010-08-17 14:52:22 +0000 | [diff] [blame] | 6385 | ** tclcmd: test_sqlite3_log ?SCRIPT? |
| 6386 | */ |
| 6387 | static struct LogCallback { |
| 6388 | Tcl_Interp *pInterp; |
| 6389 | Tcl_Obj *pObj; |
| 6390 | } logcallback = {0, 0}; |
| 6391 | static void xLogcallback(void *unused, int err, char *zMsg){ |
| 6392 | Tcl_Obj *pNew = Tcl_DuplicateObj(logcallback.pObj); |
| 6393 | Tcl_IncrRefCount(pNew); |
| 6394 | Tcl_ListObjAppendElement( |
mistachkin | e84d8d3 | 2013-04-29 03:09:10 +0000 | [diff] [blame] | 6395 | 0, pNew, Tcl_NewStringObj(sqlite3ErrName(err), -1) |
dan | eb8763d | 2010-08-17 14:52:22 +0000 | [diff] [blame] | 6396 | ); |
| 6397 | Tcl_ListObjAppendElement(0, pNew, Tcl_NewStringObj(zMsg, -1)); |
| 6398 | Tcl_EvalObjEx(logcallback.pInterp, pNew, TCL_EVAL_GLOBAL|TCL_EVAL_DIRECT); |
| 6399 | Tcl_DecrRefCount(pNew); |
| 6400 | } |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6401 | static int SQLITE_TCLAPI test_sqlite3_log( |
dan | eb8763d | 2010-08-17 14:52:22 +0000 | [diff] [blame] | 6402 | ClientData clientData, |
| 6403 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 6404 | int objc, /* Number of arguments */ |
| 6405 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 6406 | ){ |
| 6407 | if( objc>2 ){ |
| 6408 | Tcl_WrongNumArgs(interp, 1, objv, "SCRIPT"); |
| 6409 | return TCL_ERROR; |
| 6410 | } |
| 6411 | if( logcallback.pObj ){ |
| 6412 | Tcl_DecrRefCount(logcallback.pObj); |
| 6413 | logcallback.pObj = 0; |
| 6414 | logcallback.pInterp = 0; |
drh | d797a9b | 2015-12-07 16:43:44 +0000 | [diff] [blame] | 6415 | sqlite3_config(SQLITE_CONFIG_LOG, (void*)0, (void*)0); |
dan | eb8763d | 2010-08-17 14:52:22 +0000 | [diff] [blame] | 6416 | } |
| 6417 | if( objc>1 ){ |
| 6418 | logcallback.pObj = objv[1]; |
| 6419 | Tcl_IncrRefCount(logcallback.pObj); |
| 6420 | logcallback.pInterp = interp; |
drh | d797a9b | 2015-12-07 16:43:44 +0000 | [diff] [blame] | 6421 | sqlite3_config(SQLITE_CONFIG_LOG, xLogcallback, (void*)0); |
dan | eb8763d | 2010-08-17 14:52:22 +0000 | [diff] [blame] | 6422 | } |
| 6423 | return TCL_OK; |
| 6424 | } |
drh | 9bc5449 | 2007-10-23 14:49:59 +0000 | [diff] [blame] | 6425 | |
| 6426 | /* |
drh | a2c8a95 | 2009-10-13 18:38:34 +0000 | [diff] [blame] | 6427 | ** tcl_objproc COMMANDNAME ARGS... |
| 6428 | ** |
| 6429 | ** Run a TCL command using its objProc interface. Throw an error if |
| 6430 | ** the command has no objProc interface. |
| 6431 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6432 | static int SQLITE_TCLAPI runAsObjProc( |
drh | a2c8a95 | 2009-10-13 18:38:34 +0000 | [diff] [blame] | 6433 | void * clientData, |
| 6434 | Tcl_Interp *interp, |
| 6435 | int objc, |
| 6436 | Tcl_Obj *CONST objv[] |
| 6437 | ){ |
| 6438 | Tcl_CmdInfo cmdInfo; |
| 6439 | if( objc<2 ){ |
| 6440 | Tcl_WrongNumArgs(interp, 1, objv, "COMMAND ..."); |
| 6441 | return TCL_ERROR; |
| 6442 | } |
| 6443 | if( !Tcl_GetCommandInfo(interp, Tcl_GetString(objv[1]), &cmdInfo) ){ |
| 6444 | Tcl_AppendResult(interp, "command not found: ", |
| 6445 | Tcl_GetString(objv[1]), (char*)0); |
| 6446 | return TCL_ERROR; |
| 6447 | } |
| 6448 | if( cmdInfo.objProc==0 ){ |
| 6449 | Tcl_AppendResult(interp, "command has no objProc: ", |
| 6450 | Tcl_GetString(objv[1]), (char*)0); |
| 6451 | return TCL_ERROR; |
| 6452 | } |
| 6453 | return cmdInfo.objProc(cmdInfo.objClientData, interp, objc-1, objv+1); |
| 6454 | } |
| 6455 | |
dan | 91da6b8 | 2010-11-15 14:51:33 +0000 | [diff] [blame] | 6456 | #ifndef SQLITE_OMIT_EXPLAIN |
| 6457 | /* |
| 6458 | ** WARNING: The following function, printExplainQueryPlan() is an exact |
| 6459 | ** copy of example code from eqp.in (eqp.html). If this code is modified, |
| 6460 | ** then the documentation copy needs to be modified as well. |
| 6461 | */ |
| 6462 | /* |
| 6463 | ** Argument pStmt is a prepared SQL statement. This function compiles |
| 6464 | ** an EXPLAIN QUERY PLAN command to report on the prepared statement, |
| 6465 | ** and prints the report to stdout using printf(). |
| 6466 | */ |
| 6467 | int printExplainQueryPlan(sqlite3_stmt *pStmt){ |
| 6468 | const char *zSql; /* Input SQL */ |
| 6469 | char *zExplain; /* SQL with EXPLAIN QUERY PLAN prepended */ |
| 6470 | sqlite3_stmt *pExplain; /* Compiled EXPLAIN QUERY PLAN command */ |
| 6471 | int rc; /* Return code from sqlite3_prepare_v2() */ |
| 6472 | |
| 6473 | zSql = sqlite3_sql(pStmt); |
| 6474 | if( zSql==0 ) return SQLITE_ERROR; |
| 6475 | |
| 6476 | zExplain = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zSql); |
| 6477 | if( zExplain==0 ) return SQLITE_NOMEM; |
| 6478 | |
| 6479 | rc = sqlite3_prepare_v2(sqlite3_db_handle(pStmt), zExplain, -1, &pExplain, 0); |
| 6480 | sqlite3_free(zExplain); |
| 6481 | if( rc!=SQLITE_OK ) return rc; |
| 6482 | |
| 6483 | while( SQLITE_ROW==sqlite3_step(pExplain) ){ |
| 6484 | int iSelectid = sqlite3_column_int(pExplain, 0); |
| 6485 | int iOrder = sqlite3_column_int(pExplain, 1); |
| 6486 | int iFrom = sqlite3_column_int(pExplain, 2); |
| 6487 | const char *zDetail = (const char *)sqlite3_column_text(pExplain, 3); |
| 6488 | |
| 6489 | printf("%d %d %d %s\n", iSelectid, iOrder, iFrom, zDetail); |
| 6490 | } |
| 6491 | |
| 6492 | return sqlite3_finalize(pExplain); |
| 6493 | } |
| 6494 | |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6495 | static int SQLITE_TCLAPI test_print_eqp( |
dan | 91da6b8 | 2010-11-15 14:51:33 +0000 | [diff] [blame] | 6496 | void * clientData, |
| 6497 | Tcl_Interp *interp, |
| 6498 | int objc, |
| 6499 | Tcl_Obj *CONST objv[] |
| 6500 | ){ |
| 6501 | int rc; |
| 6502 | sqlite3_stmt *pStmt; |
| 6503 | |
| 6504 | if( objc!=2 ){ |
| 6505 | Tcl_WrongNumArgs(interp, 1, objv, "STMT"); |
| 6506 | return TCL_ERROR; |
| 6507 | } |
| 6508 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 6509 | rc = printExplainQueryPlan(pStmt); |
shaneh | 7c5d8fb | 2011-06-22 14:21:31 +0000 | [diff] [blame] | 6510 | /* This is needed on Windows so that a test case using this |
| 6511 | ** function can open a read pipe and get the output of |
| 6512 | ** printExplainQueryPlan() immediately. |
| 6513 | */ |
| 6514 | fflush(stdout); |
dan | 91da6b8 | 2010-11-15 14:51:33 +0000 | [diff] [blame] | 6515 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0); |
| 6516 | return TCL_OK; |
| 6517 | } |
| 6518 | #endif /* SQLITE_OMIT_EXPLAIN */ |
drh | a2c8a95 | 2009-10-13 18:38:34 +0000 | [diff] [blame] | 6519 | |
| 6520 | /* |
dan | c17d696 | 2011-06-21 12:47:30 +0000 | [diff] [blame] | 6521 | ** sqlite3_test_control VERB ARGS... |
| 6522 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6523 | static int SQLITE_TCLAPI test_test_control( |
dan | c17d696 | 2011-06-21 12:47:30 +0000 | [diff] [blame] | 6524 | void * clientData, |
| 6525 | Tcl_Interp *interp, |
| 6526 | int objc, |
| 6527 | Tcl_Obj *CONST objv[] |
| 6528 | ){ |
| 6529 | struct Verb { |
| 6530 | const char *zName; |
| 6531 | int i; |
| 6532 | } aVerb[] = { |
| 6533 | { "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT }, |
drh | 917682a | 2015-01-30 15:40:15 +0000 | [diff] [blame] | 6534 | { "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP }, |
drh | 1ffede8 | 2015-01-30 20:59:27 +0000 | [diff] [blame] | 6535 | { "SQLITE_TESTCTRL_IMPOSTER", SQLITE_TESTCTRL_IMPOSTER }, |
dan | c17d696 | 2011-06-21 12:47:30 +0000 | [diff] [blame] | 6536 | }; |
| 6537 | int iVerb; |
| 6538 | int iFlag; |
| 6539 | int rc; |
| 6540 | |
| 6541 | if( objc<2 ){ |
| 6542 | Tcl_WrongNumArgs(interp, 1, objv, "VERB ARGS..."); |
| 6543 | return TCL_ERROR; |
| 6544 | } |
| 6545 | |
| 6546 | rc = Tcl_GetIndexFromObjStruct( |
| 6547 | interp, objv[1], aVerb, sizeof(aVerb[0]), "VERB", 0, &iVerb |
| 6548 | ); |
| 6549 | if( rc!=TCL_OK ) return rc; |
| 6550 | |
| 6551 | iFlag = aVerb[iVerb].i; |
| 6552 | switch( iFlag ){ |
| 6553 | case SQLITE_TESTCTRL_LOCALTIME_FAULT: { |
| 6554 | int val; |
| 6555 | if( objc!=3 ){ |
| 6556 | Tcl_WrongNumArgs(interp, 2, objv, "ONOFF"); |
| 6557 | return TCL_ERROR; |
| 6558 | } |
| 6559 | if( Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR; |
| 6560 | sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, val); |
| 6561 | break; |
| 6562 | } |
dan | 8930c2a | 2014-04-03 16:25:29 +0000 | [diff] [blame] | 6563 | |
| 6564 | case SQLITE_TESTCTRL_SORTER_MMAP: { |
| 6565 | int val; |
| 6566 | sqlite3 *db; |
| 6567 | if( objc!=4 ){ |
| 6568 | Tcl_WrongNumArgs(interp, 2, objv, "DB LIMIT"); |
| 6569 | return TCL_ERROR; |
| 6570 | } |
| 6571 | if( getDbPointer(interp, Tcl_GetString(objv[2]), &db) ) return TCL_ERROR; |
| 6572 | if( Tcl_GetIntFromObj(interp, objv[3], &val) ) return TCL_ERROR; |
| 6573 | sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, val); |
| 6574 | break; |
| 6575 | } |
drh | 917682a | 2015-01-30 15:40:15 +0000 | [diff] [blame] | 6576 | |
drh | 1ffede8 | 2015-01-30 20:59:27 +0000 | [diff] [blame] | 6577 | case SQLITE_TESTCTRL_IMPOSTER: { |
| 6578 | int onOff, tnum; |
| 6579 | const char *zDbName; |
drh | 917682a | 2015-01-30 15:40:15 +0000 | [diff] [blame] | 6580 | sqlite3 *db; |
| 6581 | if( objc!=6 ){ |
drh | 1ffede8 | 2015-01-30 20:59:27 +0000 | [diff] [blame] | 6582 | Tcl_WrongNumArgs(interp, 2, objv, "DB dbName onOff tnum"); |
drh | 917682a | 2015-01-30 15:40:15 +0000 | [diff] [blame] | 6583 | return TCL_ERROR; |
| 6584 | } |
| 6585 | if( getDbPointer(interp, Tcl_GetString(objv[2]), &db) ) return TCL_ERROR; |
drh | 1ffede8 | 2015-01-30 20:59:27 +0000 | [diff] [blame] | 6586 | zDbName = Tcl_GetString(objv[3]); |
| 6587 | if( Tcl_GetIntFromObj(interp, objv[4], &onOff) ) return TCL_ERROR; |
| 6588 | if( Tcl_GetIntFromObj(interp, objv[5], &tnum) ) return TCL_ERROR; |
| 6589 | sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, zDbName, onOff, tnum); |
drh | 917682a | 2015-01-30 15:40:15 +0000 | [diff] [blame] | 6590 | break; |
| 6591 | } |
dan | c17d696 | 2011-06-21 12:47:30 +0000 | [diff] [blame] | 6592 | } |
| 6593 | |
| 6594 | Tcl_ResetResult(interp); |
| 6595 | return TCL_OK; |
| 6596 | } |
| 6597 | |
mistachkin | daf9a5a | 2013-03-23 09:56:39 +0000 | [diff] [blame] | 6598 | #if SQLITE_OS_UNIX |
dan | a72014f | 2013-03-16 20:19:21 +0000 | [diff] [blame] | 6599 | #include <sys/time.h> |
| 6600 | #include <sys/resource.h> |
| 6601 | |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6602 | static int SQLITE_TCLAPI test_getrusage( |
dan | a72014f | 2013-03-16 20:19:21 +0000 | [diff] [blame] | 6603 | void * clientData, |
| 6604 | Tcl_Interp *interp, |
| 6605 | int objc, |
| 6606 | Tcl_Obj *CONST objv[] |
| 6607 | ){ |
| 6608 | char buf[1024]; |
| 6609 | struct rusage r; |
| 6610 | memset(&r, 0, sizeof(r)); |
| 6611 | getrusage(RUSAGE_SELF, &r); |
| 6612 | |
drh | 65545b5 | 2015-01-19 00:35:53 +0000 | [diff] [blame] | 6613 | sqlite3_snprintf(sizeof(buf), buf, |
| 6614 | "ru_utime=%d.%06d ru_stime=%d.%06d ru_minflt=%d ru_majflt=%d", |
dan | 5d8a137 | 2013-03-19 19:28:06 +0000 | [diff] [blame] | 6615 | (int)r.ru_utime.tv_sec, (int)r.ru_utime.tv_usec, |
| 6616 | (int)r.ru_stime.tv_sec, (int)r.ru_stime.tv_usec, |
| 6617 | (int)r.ru_minflt, (int)r.ru_majflt |
dan | a72014f | 2013-03-16 20:19:21 +0000 | [diff] [blame] | 6618 | ); |
| 6619 | Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1)); |
| 6620 | return TCL_OK; |
| 6621 | } |
mistachkin | daf9a5a | 2013-03-23 09:56:39 +0000 | [diff] [blame] | 6622 | #endif |
dan | a72014f | 2013-03-16 20:19:21 +0000 | [diff] [blame] | 6623 | |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6624 | #if SQLITE_OS_WIN |
| 6625 | /* |
| 6626 | ** Information passed from the main thread into the windows file locker |
| 6627 | ** background thread. |
| 6628 | */ |
| 6629 | struct win32FileLocker { |
mistachkin | 176f1b4 | 2011-08-02 23:34:00 +0000 | [diff] [blame] | 6630 | char *evName; /* Name of event to signal thread startup */ |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6631 | HANDLE h; /* Handle of the file to be locked */ |
| 6632 | int delay1; /* Delay before locking */ |
| 6633 | int delay2; /* Delay before unlocking */ |
| 6634 | int ok; /* Finished ok */ |
| 6635 | int err; /* True if an error occurs */ |
| 6636 | }; |
| 6637 | #endif |
| 6638 | |
| 6639 | |
| 6640 | #if SQLITE_OS_WIN |
drh | 7da5fcb | 2012-03-30 14:59:43 +0000 | [diff] [blame] | 6641 | #include <process.h> |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6642 | /* |
| 6643 | ** The background thread that does file locking. |
| 6644 | */ |
mistachkin | 69def7f | 2016-07-28 04:14:37 +0000 | [diff] [blame] | 6645 | static void SQLITE_CDECL win32_file_locker(void *pAppData){ |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6646 | struct win32FileLocker *p = (struct win32FileLocker*)pAppData; |
mistachkin | 176f1b4 | 2011-08-02 23:34:00 +0000 | [diff] [blame] | 6647 | if( p->evName ){ |
| 6648 | HANDLE ev = OpenEvent(EVENT_MODIFY_STATE, FALSE, p->evName); |
| 6649 | if ( ev ){ |
| 6650 | SetEvent(ev); |
| 6651 | CloseHandle(ev); |
| 6652 | } |
| 6653 | } |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6654 | if( p->delay1 ) Sleep(p->delay1); |
| 6655 | if( LockFile(p->h, 0, 0, 100000000, 0) ){ |
| 6656 | Sleep(p->delay2); |
| 6657 | UnlockFile(p->h, 0, 0, 100000000, 0); |
| 6658 | p->ok = 1; |
| 6659 | }else{ |
| 6660 | p->err = 1; |
| 6661 | } |
| 6662 | CloseHandle(p->h); |
| 6663 | p->h = 0; |
| 6664 | p->delay1 = 0; |
| 6665 | p->delay2 = 0; |
| 6666 | } |
| 6667 | #endif |
| 6668 | |
| 6669 | #if SQLITE_OS_WIN |
| 6670 | /* |
| 6671 | ** lock_win32_file FILENAME DELAY1 DELAY2 |
| 6672 | ** |
| 6673 | ** Get an exclusive manditory lock on file for DELAY2 milliseconds. |
| 6674 | ** Wait DELAY1 milliseconds before acquiring the lock. |
| 6675 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6676 | static int SQLITE_TCLAPI win32_file_lock( |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6677 | void * clientData, |
| 6678 | Tcl_Interp *interp, |
| 6679 | int objc, |
| 6680 | Tcl_Obj *CONST objv[] |
| 6681 | ){ |
mistachkin | 176f1b4 | 2011-08-02 23:34:00 +0000 | [diff] [blame] | 6682 | static struct win32FileLocker x = { "win32_file_lock", 0, 0, 0, 0, 0 }; |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6683 | const char *zFilename; |
mistachkin | 176f1b4 | 2011-08-02 23:34:00 +0000 | [diff] [blame] | 6684 | char zBuf[200]; |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6685 | int retry = 0; |
mistachkin | 176f1b4 | 2011-08-02 23:34:00 +0000 | [diff] [blame] | 6686 | HANDLE ev; |
| 6687 | DWORD wResult; |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6688 | |
| 6689 | if( objc!=4 && objc!=1 ){ |
| 6690 | Tcl_WrongNumArgs(interp, 1, objv, "FILENAME DELAY1 DELAY2"); |
| 6691 | return TCL_ERROR; |
| 6692 | } |
| 6693 | if( objc==1 ){ |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6694 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%d %d %d %d %d", |
| 6695 | x.ok, x.err, x.delay1, x.delay2, x.h); |
| 6696 | Tcl_AppendResult(interp, zBuf, (char*)0); |
| 6697 | return TCL_OK; |
| 6698 | } |
drh | d0cdf01 | 2011-07-13 16:03:46 +0000 | [diff] [blame] | 6699 | while( x.h && retry<30 ){ |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6700 | retry++; |
| 6701 | Sleep(100); |
| 6702 | } |
| 6703 | if( x.h ){ |
| 6704 | Tcl_AppendResult(interp, "busy", (char*)0); |
| 6705 | return TCL_ERROR; |
| 6706 | } |
| 6707 | if( Tcl_GetIntFromObj(interp, objv[2], &x.delay1) ) return TCL_ERROR; |
| 6708 | if( Tcl_GetIntFromObj(interp, objv[3], &x.delay2) ) return TCL_ERROR; |
| 6709 | zFilename = Tcl_GetString(objv[1]); |
| 6710 | x.h = CreateFile(zFilename, GENERIC_READ|GENERIC_WRITE, |
| 6711 | FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_ALWAYS, |
| 6712 | FILE_ATTRIBUTE_NORMAL, 0); |
| 6713 | if( !x.h ){ |
| 6714 | Tcl_AppendResult(interp, "cannot open file: ", zFilename, (char*)0); |
| 6715 | return TCL_ERROR; |
| 6716 | } |
mistachkin | 176f1b4 | 2011-08-02 23:34:00 +0000 | [diff] [blame] | 6717 | ev = CreateEvent(NULL, TRUE, FALSE, x.evName); |
| 6718 | if ( !ev ){ |
| 6719 | Tcl_AppendResult(interp, "cannot create event: ", x.evName, (char*)0); |
| 6720 | return TCL_ERROR; |
| 6721 | } |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6722 | _beginthread(win32_file_locker, 0, (void*)&x); |
| 6723 | Sleep(0); |
mistachkin | 176f1b4 | 2011-08-02 23:34:00 +0000 | [diff] [blame] | 6724 | if ( (wResult = WaitForSingleObject(ev, 10000))!=WAIT_OBJECT_0 ){ |
| 6725 | sqlite3_snprintf(sizeof(zBuf), zBuf, "0x%x", wResult); |
| 6726 | Tcl_AppendResult(interp, "wait failed: ", zBuf, (char*)0); |
| 6727 | CloseHandle(ev); |
| 6728 | return TCL_ERROR; |
| 6729 | } |
| 6730 | CloseHandle(ev); |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6731 | return TCL_OK; |
| 6732 | } |
mistachkin | 3741827 | 2013-08-28 05:49:39 +0000 | [diff] [blame] | 6733 | |
| 6734 | /* |
| 6735 | ** exists_win32_path PATH |
| 6736 | ** |
| 6737 | ** Returns non-zero if the specified path exists, whose fully qualified name |
mistachkin | 3259fe7 | 2013-08-28 17:59:38 +0000 | [diff] [blame] | 6738 | ** may exceed 260 characters if it is prefixed with "\\?\". |
mistachkin | 3741827 | 2013-08-28 05:49:39 +0000 | [diff] [blame] | 6739 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6740 | static int SQLITE_TCLAPI win32_exists_path( |
mistachkin | 3741827 | 2013-08-28 05:49:39 +0000 | [diff] [blame] | 6741 | void *clientData, |
| 6742 | Tcl_Interp *interp, |
| 6743 | int objc, |
| 6744 | Tcl_Obj *CONST objv[] |
| 6745 | ){ |
| 6746 | if( objc!=2 ){ |
| 6747 | Tcl_WrongNumArgs(interp, 1, objv, "PATH"); |
| 6748 | return TCL_ERROR; |
| 6749 | } |
| 6750 | Tcl_SetObjResult(interp, Tcl_NewBooleanObj( |
| 6751 | GetFileAttributesW( Tcl_GetUnicode(objv[1]))!=INVALID_FILE_ATTRIBUTES )); |
| 6752 | return TCL_OK; |
| 6753 | } |
| 6754 | |
| 6755 | /* |
| 6756 | ** find_win32_file PATTERN |
| 6757 | ** |
| 6758 | ** Returns a list of entries in a directory that match the specified pattern, |
| 6759 | ** whose fully qualified name may exceed 248 characters if it is prefixed with |
| 6760 | ** "\\?\". |
| 6761 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6762 | static int SQLITE_TCLAPI win32_find_file( |
mistachkin | 3741827 | 2013-08-28 05:49:39 +0000 | [diff] [blame] | 6763 | void *clientData, |
| 6764 | Tcl_Interp *interp, |
| 6765 | int objc, |
| 6766 | Tcl_Obj *CONST objv[] |
| 6767 | ){ |
| 6768 | HANDLE hFindFile = INVALID_HANDLE_VALUE; |
| 6769 | WIN32_FIND_DATAW findData; |
| 6770 | Tcl_Obj *listObj; |
| 6771 | DWORD lastErrno; |
| 6772 | if( objc!=2 ){ |
| 6773 | Tcl_WrongNumArgs(interp, 1, objv, "PATTERN"); |
| 6774 | return TCL_ERROR; |
| 6775 | } |
| 6776 | hFindFile = FindFirstFileW(Tcl_GetUnicode(objv[1]), &findData); |
| 6777 | if( hFindFile==INVALID_HANDLE_VALUE ){ |
| 6778 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError())); |
| 6779 | return TCL_ERROR; |
| 6780 | } |
| 6781 | listObj = Tcl_NewObj(); |
| 6782 | Tcl_IncrRefCount(listObj); |
| 6783 | do { |
| 6784 | Tcl_ListObjAppendElement(interp, listObj, Tcl_NewUnicodeObj( |
| 6785 | findData.cFileName, -1)); |
| 6786 | Tcl_ListObjAppendElement(interp, listObj, Tcl_NewWideIntObj( |
| 6787 | findData.dwFileAttributes)); |
| 6788 | } while( FindNextFileW(hFindFile, &findData) ); |
| 6789 | lastErrno = GetLastError(); |
| 6790 | if( lastErrno!=NO_ERROR && lastErrno!=ERROR_NO_MORE_FILES ){ |
| 6791 | FindClose(hFindFile); |
| 6792 | Tcl_DecrRefCount(listObj); |
| 6793 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError())); |
| 6794 | return TCL_ERROR; |
| 6795 | } |
| 6796 | FindClose(hFindFile); |
| 6797 | Tcl_SetObjResult(interp, listObj); |
| 6798 | return TCL_OK; |
| 6799 | } |
| 6800 | |
| 6801 | /* |
| 6802 | ** delete_win32_file FILENAME |
| 6803 | ** |
mistachkin | 3259fe7 | 2013-08-28 17:59:38 +0000 | [diff] [blame] | 6804 | ** Deletes the specified file, whose fully qualified name may exceed 260 |
mistachkin | 3741827 | 2013-08-28 05:49:39 +0000 | [diff] [blame] | 6805 | ** characters if it is prefixed with "\\?\". |
| 6806 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6807 | static int SQLITE_TCLAPI win32_delete_file( |
mistachkin | 3741827 | 2013-08-28 05:49:39 +0000 | [diff] [blame] | 6808 | void *clientData, |
| 6809 | Tcl_Interp *interp, |
| 6810 | int objc, |
| 6811 | Tcl_Obj *CONST objv[] |
| 6812 | ){ |
| 6813 | if( objc!=2 ){ |
| 6814 | Tcl_WrongNumArgs(interp, 1, objv, "FILENAME"); |
| 6815 | return TCL_ERROR; |
| 6816 | } |
| 6817 | if( !DeleteFileW(Tcl_GetUnicode(objv[1])) ){ |
| 6818 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError())); |
| 6819 | return TCL_ERROR; |
| 6820 | } |
| 6821 | Tcl_ResetResult(interp); |
| 6822 | return TCL_OK; |
| 6823 | } |
| 6824 | |
| 6825 | /* |
| 6826 | ** make_win32_dir DIRECTORY |
| 6827 | ** |
| 6828 | ** Creates the specified directory, whose fully qualified name may exceed 248 |
| 6829 | ** characters if it is prefixed with "\\?\". |
| 6830 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6831 | static int SQLITE_TCLAPI win32_mkdir( |
mistachkin | 3741827 | 2013-08-28 05:49:39 +0000 | [diff] [blame] | 6832 | void *clientData, |
| 6833 | Tcl_Interp *interp, |
| 6834 | int objc, |
| 6835 | Tcl_Obj *CONST objv[] |
| 6836 | ){ |
| 6837 | if( objc!=2 ){ |
| 6838 | Tcl_WrongNumArgs(interp, 1, objv, "DIRECTORY"); |
| 6839 | return TCL_ERROR; |
| 6840 | } |
| 6841 | if( !CreateDirectoryW(Tcl_GetUnicode(objv[1]), NULL) ){ |
| 6842 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError())); |
| 6843 | return TCL_ERROR; |
| 6844 | } |
| 6845 | Tcl_ResetResult(interp); |
| 6846 | return TCL_OK; |
| 6847 | } |
| 6848 | |
| 6849 | /* |
| 6850 | ** remove_win32_dir DIRECTORY |
| 6851 | ** |
| 6852 | ** Removes the specified directory, whose fully qualified name may exceed 248 |
| 6853 | ** characters if it is prefixed with "\\?\". |
| 6854 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6855 | static int SQLITE_TCLAPI win32_rmdir( |
mistachkin | 3741827 | 2013-08-28 05:49:39 +0000 | [diff] [blame] | 6856 | void *clientData, |
| 6857 | Tcl_Interp *interp, |
| 6858 | int objc, |
| 6859 | Tcl_Obj *CONST objv[] |
| 6860 | ){ |
| 6861 | if( objc!=2 ){ |
| 6862 | Tcl_WrongNumArgs(interp, 1, objv, "DIRECTORY"); |
| 6863 | return TCL_ERROR; |
| 6864 | } |
| 6865 | if( !RemoveDirectoryW(Tcl_GetUnicode(objv[1])) ){ |
| 6866 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError())); |
| 6867 | return TCL_ERROR; |
| 6868 | } |
| 6869 | Tcl_ResetResult(interp); |
| 6870 | return TCL_OK; |
| 6871 | } |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 6872 | #endif |
dan | c17d696 | 2011-06-21 12:47:30 +0000 | [diff] [blame] | 6873 | |
drh | d0cdf01 | 2011-07-13 16:03:46 +0000 | [diff] [blame] | 6874 | |
dan | c17d696 | 2011-06-21 12:47:30 +0000 | [diff] [blame] | 6875 | /* |
drh | f58ee7f | 2010-12-06 21:06:09 +0000 | [diff] [blame] | 6876 | ** optimization_control DB OPT BOOLEAN |
| 6877 | ** |
| 6878 | ** Enable or disable query optimizations using the sqlite3_test_control() |
| 6879 | ** interface. Disable if BOOLEAN is false and enable if BOOLEAN is true. |
| 6880 | ** OPT is the name of the optimization to be disabled. |
| 6881 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6882 | static int SQLITE_TCLAPI optimization_control( |
drh | f58ee7f | 2010-12-06 21:06:09 +0000 | [diff] [blame] | 6883 | void * clientData, |
| 6884 | Tcl_Interp *interp, |
| 6885 | int objc, |
| 6886 | Tcl_Obj *CONST objv[] |
| 6887 | ){ |
| 6888 | int i; |
| 6889 | sqlite3 *db; |
| 6890 | const char *zOpt; |
| 6891 | int onoff; |
drh | fc30b04 | 2012-08-20 16:08:29 +0000 | [diff] [blame] | 6892 | int mask = 0; |
drh | f58ee7f | 2010-12-06 21:06:09 +0000 | [diff] [blame] | 6893 | static const struct { |
| 6894 | const char *zOptName; |
| 6895 | int mask; |
| 6896 | } aOpt[] = { |
drh | 9d5a579 | 2013-06-28 13:43:33 +0000 | [diff] [blame] | 6897 | { "all", SQLITE_AllOpts }, |
| 6898 | { "none", 0 }, |
| 6899 | { "query-flattener", SQLITE_QueryFlattener }, |
| 6900 | { "column-cache", SQLITE_ColumnCache }, |
| 6901 | { "groupby-order", SQLITE_GroupByOrder }, |
| 6902 | { "factor-constants", SQLITE_FactorOutConst }, |
drh | 9d5a579 | 2013-06-28 13:43:33 +0000 | [diff] [blame] | 6903 | { "distinct-opt", SQLITE_DistinctOpt }, |
| 6904 | { "cover-idx-scan", SQLITE_CoverIdxScan }, |
| 6905 | { "order-by-idx-join", SQLITE_OrderByIdxJoin }, |
| 6906 | { "transitive", SQLITE_Transitive }, |
| 6907 | { "subquery-coroutine", SQLITE_SubqCoroutine }, |
| 6908 | { "omit-noop-join", SQLITE_OmitNoopJoin }, |
drh | d7d7147 | 2014-10-22 19:57:16 +0000 | [diff] [blame] | 6909 | { "stat3", SQLITE_Stat34 }, |
| 6910 | { "stat4", SQLITE_Stat34 }, |
drh | f58ee7f | 2010-12-06 21:06:09 +0000 | [diff] [blame] | 6911 | }; |
| 6912 | |
| 6913 | if( objc!=4 ){ |
| 6914 | Tcl_WrongNumArgs(interp, 1, objv, "DB OPT BOOLEAN"); |
| 6915 | return TCL_ERROR; |
| 6916 | } |
| 6917 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 6918 | if( Tcl_GetBooleanFromObj(interp, objv[3], &onoff) ) return TCL_ERROR; |
| 6919 | zOpt = Tcl_GetString(objv[2]); |
| 6920 | for(i=0; i<sizeof(aOpt)/sizeof(aOpt[0]); i++){ |
| 6921 | if( strcmp(zOpt, aOpt[i].zOptName)==0 ){ |
| 6922 | mask = aOpt[i].mask; |
| 6923 | break; |
| 6924 | } |
| 6925 | } |
| 6926 | if( onoff ) mask = ~mask; |
| 6927 | if( i>=sizeof(aOpt)/sizeof(aOpt[0]) ){ |
| 6928 | Tcl_AppendResult(interp, "unknown optimization - should be one of:", |
| 6929 | (char*)0); |
| 6930 | for(i=0; i<sizeof(aOpt)/sizeof(aOpt[0]); i++){ |
drh | 9d5a579 | 2013-06-28 13:43:33 +0000 | [diff] [blame] | 6931 | Tcl_AppendResult(interp, " ", aOpt[i].zOptName, (char*)0); |
drh | f58ee7f | 2010-12-06 21:06:09 +0000 | [diff] [blame] | 6932 | } |
| 6933 | return TCL_ERROR; |
| 6934 | } |
| 6935 | sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, db, mask); |
| 6936 | return TCL_OK; |
| 6937 | } |
| 6938 | |
drh | 248f2be | 2013-04-23 20:10:13 +0000 | [diff] [blame] | 6939 | /* |
drh | ea41dc4 | 2013-04-25 19:31:33 +0000 | [diff] [blame] | 6940 | ** load_static_extension DB NAME ... |
drh | 248f2be | 2013-04-23 20:10:13 +0000 | [diff] [blame] | 6941 | ** |
drh | ea41dc4 | 2013-04-25 19:31:33 +0000 | [diff] [blame] | 6942 | ** Load one or more statically linked extensions. |
drh | 248f2be | 2013-04-23 20:10:13 +0000 | [diff] [blame] | 6943 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 6944 | static int SQLITE_TCLAPI tclLoadStaticExtensionCmd( |
drh | 248f2be | 2013-04-23 20:10:13 +0000 | [diff] [blame] | 6945 | void * clientData, |
| 6946 | Tcl_Interp *interp, |
| 6947 | int objc, |
| 6948 | Tcl_Obj *CONST objv[] |
| 6949 | ){ |
drh | 8416fc7 | 2013-04-25 16:42:55 +0000 | [diff] [blame] | 6950 | extern int sqlite3_amatch_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 6951 | extern int sqlite3_carray_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | 8416fc7 | 2013-04-25 16:42:55 +0000 | [diff] [blame] | 6952 | extern int sqlite3_closure_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | 35db31b | 2016-06-02 23:13:21 +0000 | [diff] [blame] | 6953 | extern int sqlite3_csv_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | 1728bcb | 2014-11-10 16:49:56 +0000 | [diff] [blame] | 6954 | extern int sqlite3_eval_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | 51ed298 | 2014-06-16 12:44:32 +0000 | [diff] [blame] | 6955 | extern int sqlite3_fileio_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | e50db1c | 2013-04-25 14:31:46 +0000 | [diff] [blame] | 6956 | extern int sqlite3_fuzzer_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | 8416fc7 | 2013-04-25 16:42:55 +0000 | [diff] [blame] | 6957 | extern int sqlite3_ieee_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | ea41dc4 | 2013-04-25 19:31:33 +0000 | [diff] [blame] | 6958 | extern int sqlite3_nextchar_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | def3367 | 2013-05-28 20:25:54 +0000 | [diff] [blame] | 6959 | extern int sqlite3_percentile_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | 248f2be | 2013-04-23 20:10:13 +0000 | [diff] [blame] | 6960 | extern int sqlite3_regexp_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | 6bada27 | 2016-08-09 21:08:42 +0000 | [diff] [blame] | 6961 | extern int sqlite3_remember_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | 398f872 | 2015-08-19 13:54:20 +0000 | [diff] [blame] | 6962 | extern int sqlite3_series_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | b7045ab | 2013-04-25 14:59:01 +0000 | [diff] [blame] | 6963 | extern int sqlite3_spellfix_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | 5f8cdac | 2013-10-14 21:14:42 +0000 | [diff] [blame] | 6964 | extern int sqlite3_totype_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | 24b6422 | 2013-04-25 11:58:36 +0000 | [diff] [blame] | 6965 | extern int sqlite3_wholenumber_init(sqlite3*,char**,const sqlite3_api_routines*); |
drh | 248f2be | 2013-04-23 20:10:13 +0000 | [diff] [blame] | 6966 | static const struct { |
| 6967 | const char *zExtName; |
| 6968 | int (*pInit)(sqlite3*,char**,const sqlite3_api_routines*); |
| 6969 | } aExtension[] = { |
drh | 8416fc7 | 2013-04-25 16:42:55 +0000 | [diff] [blame] | 6970 | { "amatch", sqlite3_amatch_init }, |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 6971 | { "carray", sqlite3_carray_init }, |
drh | 8416fc7 | 2013-04-25 16:42:55 +0000 | [diff] [blame] | 6972 | { "closure", sqlite3_closure_init }, |
drh | 35db31b | 2016-06-02 23:13:21 +0000 | [diff] [blame] | 6973 | { "csv", sqlite3_csv_init }, |
drh | 1728bcb | 2014-11-10 16:49:56 +0000 | [diff] [blame] | 6974 | { "eval", sqlite3_eval_init }, |
drh | 51ed298 | 2014-06-16 12:44:32 +0000 | [diff] [blame] | 6975 | { "fileio", sqlite3_fileio_init }, |
drh | e50db1c | 2013-04-25 14:31:46 +0000 | [diff] [blame] | 6976 | { "fuzzer", sqlite3_fuzzer_init }, |
drh | 8416fc7 | 2013-04-25 16:42:55 +0000 | [diff] [blame] | 6977 | { "ieee754", sqlite3_ieee_init }, |
drh | ea41dc4 | 2013-04-25 19:31:33 +0000 | [diff] [blame] | 6978 | { "nextchar", sqlite3_nextchar_init }, |
drh | def3367 | 2013-05-28 20:25:54 +0000 | [diff] [blame] | 6979 | { "percentile", sqlite3_percentile_init }, |
drh | 24b6422 | 2013-04-25 11:58:36 +0000 | [diff] [blame] | 6980 | { "regexp", sqlite3_regexp_init }, |
drh | 6bada27 | 2016-08-09 21:08:42 +0000 | [diff] [blame] | 6981 | { "remember", sqlite3_remember_init }, |
drh | 398f872 | 2015-08-19 13:54:20 +0000 | [diff] [blame] | 6982 | { "series", sqlite3_series_init }, |
drh | b7045ab | 2013-04-25 14:59:01 +0000 | [diff] [blame] | 6983 | { "spellfix", sqlite3_spellfix_init }, |
drh | 5f8cdac | 2013-10-14 21:14:42 +0000 | [diff] [blame] | 6984 | { "totype", sqlite3_totype_init }, |
drh | 24b6422 | 2013-04-25 11:58:36 +0000 | [diff] [blame] | 6985 | { "wholenumber", sqlite3_wholenumber_init }, |
drh | 248f2be | 2013-04-23 20:10:13 +0000 | [diff] [blame] | 6986 | }; |
| 6987 | sqlite3 *db; |
| 6988 | const char *zName; |
drh | ea41dc4 | 2013-04-25 19:31:33 +0000 | [diff] [blame] | 6989 | int i, j, rc; |
drh | 248f2be | 2013-04-23 20:10:13 +0000 | [diff] [blame] | 6990 | char *zErrMsg = 0; |
drh | ea41dc4 | 2013-04-25 19:31:33 +0000 | [diff] [blame] | 6991 | if( objc<3 ){ |
| 6992 | Tcl_WrongNumArgs(interp, 1, objv, "DB NAME ..."); |
drh | 248f2be | 2013-04-23 20:10:13 +0000 | [diff] [blame] | 6993 | return TCL_ERROR; |
| 6994 | } |
| 6995 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
drh | ea41dc4 | 2013-04-25 19:31:33 +0000 | [diff] [blame] | 6996 | for(j=2; j<objc; j++){ |
| 6997 | zName = Tcl_GetString(objv[j]); |
| 6998 | for(i=0; i<ArraySize(aExtension); i++){ |
| 6999 | if( strcmp(zName, aExtension[i].zExtName)==0 ) break; |
| 7000 | } |
| 7001 | if( i>=ArraySize(aExtension) ){ |
| 7002 | Tcl_AppendResult(interp, "no such extension: ", zName, (char*)0); |
| 7003 | return TCL_ERROR; |
| 7004 | } |
drh | c306e08 | 2015-10-08 23:37:00 +0000 | [diff] [blame] | 7005 | if( aExtension[i].pInit ){ |
| 7006 | rc = aExtension[i].pInit(db, &zErrMsg, 0); |
| 7007 | }else{ |
| 7008 | rc = SQLITE_OK; |
| 7009 | } |
drh | ea41dc4 | 2013-04-25 19:31:33 +0000 | [diff] [blame] | 7010 | if( rc!=SQLITE_OK || zErrMsg ){ |
| 7011 | Tcl_AppendResult(interp, "initialization of ", zName, " failed: ", zErrMsg, |
| 7012 | (char*)0); |
| 7013 | sqlite3_free(zErrMsg); |
| 7014 | return TCL_ERROR; |
| 7015 | } |
drh | 248f2be | 2013-04-23 20:10:13 +0000 | [diff] [blame] | 7016 | } |
| 7017 | return TCL_OK; |
| 7018 | } |
| 7019 | |
dan | 0d51def | 2014-05-03 14:28:14 +0000 | [diff] [blame] | 7020 | /* |
| 7021 | ** sorter_test_fakeheap BOOL |
| 7022 | ** |
| 7023 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 7024 | static int SQLITE_TCLAPI sorter_test_fakeheap( |
dan | 0d51def | 2014-05-03 14:28:14 +0000 | [diff] [blame] | 7025 | void * clientData, |
| 7026 | Tcl_Interp *interp, |
| 7027 | int objc, |
| 7028 | Tcl_Obj *CONST objv[] |
| 7029 | ){ |
| 7030 | int bArg; |
| 7031 | if( objc!=2 ){ |
| 7032 | Tcl_WrongNumArgs(interp, 1, objv, "BOOL"); |
| 7033 | return TCL_ERROR; |
| 7034 | } |
| 7035 | |
| 7036 | if( Tcl_GetBooleanFromObj(interp, objv[1], &bArg) ){ |
| 7037 | return TCL_ERROR; |
| 7038 | } |
| 7039 | |
| 7040 | if( bArg ){ |
| 7041 | if( sqlite3GlobalConfig.pHeap==0 ){ |
| 7042 | sqlite3GlobalConfig.pHeap = SQLITE_INT_TO_PTR(-1); |
| 7043 | } |
| 7044 | }else{ |
| 7045 | if( sqlite3GlobalConfig.pHeap==SQLITE_INT_TO_PTR(-1) ){ |
| 7046 | sqlite3GlobalConfig.pHeap = 0; |
| 7047 | } |
| 7048 | } |
| 7049 | |
| 7050 | Tcl_ResetResult(interp); |
| 7051 | return TCL_OK; |
| 7052 | } |
| 7053 | |
dan | dfea453 | 2014-05-06 15:38:07 +0000 | [diff] [blame] | 7054 | /* |
| 7055 | ** sorter_test_sort4_helper DB SQL1 NSTEP SQL2 |
| 7056 | ** |
| 7057 | ** Compile SQL statement $SQL1 and step it $NSTEP times. For each row, |
| 7058 | ** check that the leftmost and rightmost columns returned are both integers, |
| 7059 | ** and that both contain the same value. |
| 7060 | ** |
| 7061 | ** Then execute statement $SQL2. Check that the statement returns the same |
| 7062 | ** set of integers in the same order as in the previous step (using $SQL1). |
| 7063 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 7064 | static int SQLITE_TCLAPI sorter_test_sort4_helper( |
dan | dfea453 | 2014-05-06 15:38:07 +0000 | [diff] [blame] | 7065 | void * clientData, |
| 7066 | Tcl_Interp *interp, |
| 7067 | int objc, |
| 7068 | Tcl_Obj *CONST objv[] |
| 7069 | ){ |
| 7070 | const char *zSql1; |
| 7071 | const char *zSql2; |
| 7072 | int nStep; |
| 7073 | int iStep; |
drh | 48cd59a | 2016-05-03 00:04:55 +0000 | [diff] [blame] | 7074 | unsigned int iCksum1 = 0; |
| 7075 | unsigned int iCksum2 = 0; |
dan | dfea453 | 2014-05-06 15:38:07 +0000 | [diff] [blame] | 7076 | int rc; |
| 7077 | int iB; |
| 7078 | sqlite3 *db; |
| 7079 | sqlite3_stmt *pStmt; |
| 7080 | |
| 7081 | if( objc!=5 ){ |
| 7082 | Tcl_WrongNumArgs(interp, 1, objv, "DB SQL1 NSTEP SQL2"); |
| 7083 | return TCL_ERROR; |
| 7084 | } |
| 7085 | |
| 7086 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 7087 | zSql1 = Tcl_GetString(objv[2]); |
| 7088 | if( Tcl_GetIntFromObj(interp, objv[3], &nStep) ) return TCL_ERROR; |
| 7089 | zSql2 = Tcl_GetString(objv[4]); |
| 7090 | |
| 7091 | rc = sqlite3_prepare_v2(db, zSql1, -1, &pStmt, 0); |
| 7092 | if( rc!=SQLITE_OK ) goto sql_error; |
| 7093 | |
| 7094 | iB = sqlite3_column_count(pStmt)-1; |
| 7095 | for(iStep=0; iStep<nStep && SQLITE_ROW==sqlite3_step(pStmt); iStep++){ |
| 7096 | int a = sqlite3_column_int(pStmt, 0); |
| 7097 | if( a!=sqlite3_column_int(pStmt, iB) ){ |
| 7098 | Tcl_AppendResult(interp, "data error: (a!=b)", 0); |
| 7099 | return TCL_ERROR; |
| 7100 | } |
| 7101 | |
drh | 48cd59a | 2016-05-03 00:04:55 +0000 | [diff] [blame] | 7102 | iCksum1 += (iCksum1 << 3) + (unsigned int)a; |
dan | dfea453 | 2014-05-06 15:38:07 +0000 | [diff] [blame] | 7103 | } |
| 7104 | rc = sqlite3_finalize(pStmt); |
| 7105 | if( rc!=SQLITE_OK ) goto sql_error; |
| 7106 | |
| 7107 | rc = sqlite3_prepare_v2(db, zSql2, -1, &pStmt, 0); |
| 7108 | if( rc!=SQLITE_OK ) goto sql_error; |
| 7109 | for(iStep=0; SQLITE_ROW==sqlite3_step(pStmt); iStep++){ |
| 7110 | int a = sqlite3_column_int(pStmt, 0); |
drh | 48cd59a | 2016-05-03 00:04:55 +0000 | [diff] [blame] | 7111 | iCksum2 += (iCksum2 << 3) + (unsigned int)a; |
dan | dfea453 | 2014-05-06 15:38:07 +0000 | [diff] [blame] | 7112 | } |
| 7113 | rc = sqlite3_finalize(pStmt); |
| 7114 | if( rc!=SQLITE_OK ) goto sql_error; |
| 7115 | |
| 7116 | if( iCksum1!=iCksum2 ){ |
| 7117 | Tcl_AppendResult(interp, "checksum mismatch", 0); |
| 7118 | return TCL_ERROR; |
| 7119 | } |
| 7120 | |
| 7121 | return TCL_OK; |
| 7122 | sql_error: |
| 7123 | Tcl_AppendResult(interp, "sql error: ", sqlite3_errmsg(db), 0); |
| 7124 | return TCL_ERROR; |
| 7125 | } |
| 7126 | |
drh | 248f2be | 2013-04-23 20:10:13 +0000 | [diff] [blame] | 7127 | |
drh | d39c40f | 2014-09-11 00:27:53 +0000 | [diff] [blame] | 7128 | #ifdef SQLITE_USER_AUTHENTICATION |
| 7129 | #include "sqlite3userauth.h" |
| 7130 | /* |
| 7131 | ** tclcmd: sqlite3_user_authenticate DB USERNAME PASSWORD |
| 7132 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 7133 | static int SQLITE_TCLAPI test_user_authenticate( |
drh | d39c40f | 2014-09-11 00:27:53 +0000 | [diff] [blame] | 7134 | ClientData clientData, /* Unused */ |
| 7135 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 7136 | int objc, /* Number of arguments */ |
| 7137 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 7138 | ){ |
| 7139 | char *zUser = 0; |
| 7140 | char *zPasswd = 0; |
| 7141 | int nPasswd = 0; |
| 7142 | sqlite3 *db; |
| 7143 | int rc; |
| 7144 | |
| 7145 | if( objc!=4 ){ |
| 7146 | Tcl_WrongNumArgs(interp, 1, objv, "DB USERNAME PASSWORD"); |
| 7147 | return TCL_ERROR; |
| 7148 | } |
| 7149 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 7150 | return TCL_ERROR; |
| 7151 | } |
| 7152 | zUser = Tcl_GetString(objv[2]); |
| 7153 | zPasswd = Tcl_GetStringFromObj(objv[3], &nPasswd); |
| 7154 | rc = sqlite3_user_authenticate(db, zUser, zPasswd, nPasswd); |
| 7155 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
| 7156 | return TCL_OK; |
| 7157 | } |
| 7158 | #endif /* SQLITE_USER_AUTHENTICATION */ |
| 7159 | |
| 7160 | #ifdef SQLITE_USER_AUTHENTICATION |
| 7161 | /* |
| 7162 | ** tclcmd: sqlite3_user_add DB USERNAME PASSWORD ISADMIN |
| 7163 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 7164 | static int SQLITE_TCLAPI test_user_add( |
drh | d39c40f | 2014-09-11 00:27:53 +0000 | [diff] [blame] | 7165 | ClientData clientData, /* Unused */ |
| 7166 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 7167 | int objc, /* Number of arguments */ |
| 7168 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 7169 | ){ |
| 7170 | char *zUser = 0; |
| 7171 | char *zPasswd = 0; |
| 7172 | int nPasswd = 0; |
| 7173 | int isAdmin = 0; |
| 7174 | sqlite3 *db; |
| 7175 | int rc; |
| 7176 | |
| 7177 | if( objc!=5 ){ |
| 7178 | Tcl_WrongNumArgs(interp, 1, objv, "DB USERNAME PASSWORD ISADMIN"); |
| 7179 | return TCL_ERROR; |
| 7180 | } |
| 7181 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 7182 | return TCL_ERROR; |
| 7183 | } |
| 7184 | zUser = Tcl_GetString(objv[2]); |
| 7185 | zPasswd = Tcl_GetStringFromObj(objv[3], &nPasswd); |
| 7186 | Tcl_GetBooleanFromObj(interp, objv[4], &isAdmin); |
| 7187 | rc = sqlite3_user_add(db, zUser, zPasswd, nPasswd, isAdmin); |
| 7188 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
| 7189 | return TCL_OK; |
| 7190 | } |
| 7191 | #endif /* SQLITE_USER_AUTHENTICATION */ |
| 7192 | |
| 7193 | #ifdef SQLITE_USER_AUTHENTICATION |
| 7194 | /* |
| 7195 | ** tclcmd: sqlite3_user_change DB USERNAME PASSWORD ISADMIN |
| 7196 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 7197 | static int SQLITE_TCLAPI test_user_change( |
drh | d39c40f | 2014-09-11 00:27:53 +0000 | [diff] [blame] | 7198 | ClientData clientData, /* Unused */ |
| 7199 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 7200 | int objc, /* Number of arguments */ |
| 7201 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 7202 | ){ |
| 7203 | char *zUser = 0; |
| 7204 | char *zPasswd = 0; |
| 7205 | int nPasswd = 0; |
| 7206 | int isAdmin = 0; |
| 7207 | sqlite3 *db; |
| 7208 | int rc; |
| 7209 | |
| 7210 | if( objc!=5 ){ |
| 7211 | Tcl_WrongNumArgs(interp, 1, objv, "DB USERNAME PASSWORD ISADMIN"); |
| 7212 | return TCL_ERROR; |
| 7213 | } |
| 7214 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 7215 | return TCL_ERROR; |
| 7216 | } |
| 7217 | zUser = Tcl_GetString(objv[2]); |
| 7218 | zPasswd = Tcl_GetStringFromObj(objv[3], &nPasswd); |
| 7219 | Tcl_GetBooleanFromObj(interp, objv[4], &isAdmin); |
| 7220 | rc = sqlite3_user_change(db, zUser, zPasswd, nPasswd, isAdmin); |
| 7221 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
| 7222 | return TCL_OK; |
| 7223 | } |
| 7224 | #endif /* SQLITE_USER_AUTHENTICATION */ |
| 7225 | |
| 7226 | #ifdef SQLITE_USER_AUTHENTICATION |
| 7227 | /* |
| 7228 | ** tclcmd: sqlite3_user_delete DB USERNAME |
| 7229 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 7230 | static int SQLITE_TCLAPI test_user_delete( |
drh | d39c40f | 2014-09-11 00:27:53 +0000 | [diff] [blame] | 7231 | ClientData clientData, /* Unused */ |
| 7232 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 7233 | int objc, /* Number of arguments */ |
| 7234 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 7235 | ){ |
| 7236 | char *zUser = 0; |
| 7237 | sqlite3 *db; |
| 7238 | int rc; |
| 7239 | |
| 7240 | if( objc!=3 ){ |
| 7241 | Tcl_WrongNumArgs(interp, 1, objv, "DB USERNAME"); |
| 7242 | return TCL_ERROR; |
| 7243 | } |
| 7244 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){ |
| 7245 | return TCL_ERROR; |
| 7246 | } |
| 7247 | zUser = Tcl_GetString(objv[2]); |
| 7248 | rc = sqlite3_user_delete(db, zUser); |
| 7249 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
| 7250 | return TCL_OK; |
| 7251 | } |
| 7252 | #endif /* SQLITE_USER_AUTHENTICATION */ |
| 7253 | |
drh | f58ee7f | 2010-12-06 21:06:09 +0000 | [diff] [blame] | 7254 | /* |
drh | edb31cd | 2015-01-08 02:15:11 +0000 | [diff] [blame] | 7255 | ** tclcmd: bad_behavior TYPE |
| 7256 | ** |
| 7257 | ** Do some things that should trigger a valgrind or -fsanitize=undefined |
| 7258 | ** warning. This is used to verify that errors and warnings output by those |
| 7259 | ** tools are detected by the test scripts. |
| 7260 | ** |
| 7261 | ** TYPE BEHAVIOR |
| 7262 | ** 1 Overflow a signed integer |
| 7263 | ** 2 Jump based on an uninitialized variable |
| 7264 | ** 3 Read after free |
drh | db6bafa | 2015-01-09 21:54:58 +0000 | [diff] [blame] | 7265 | ** 4 Panic |
drh | edb31cd | 2015-01-08 02:15:11 +0000 | [diff] [blame] | 7266 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 7267 | static int SQLITE_TCLAPI test_bad_behavior( |
drh | edb31cd | 2015-01-08 02:15:11 +0000 | [diff] [blame] | 7268 | ClientData clientData, /* Pointer to an integer containing zero */ |
| 7269 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 7270 | int objc, /* Number of arguments */ |
| 7271 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 7272 | ){ |
| 7273 | int iType; |
| 7274 | int xyz; |
| 7275 | int i = *(int*)clientData; |
| 7276 | int j; |
| 7277 | int w[10]; |
| 7278 | int *a; |
| 7279 | if( objc!=2 ){ |
| 7280 | Tcl_WrongNumArgs(interp, 1, objv, "TYPE"); |
| 7281 | return TCL_ERROR; |
| 7282 | } |
| 7283 | if( Tcl_GetIntFromObj(interp, objv[1], &iType) ) return TCL_ERROR; |
| 7284 | switch( iType ){ |
| 7285 | case 1: { |
| 7286 | xyz = 0x7fffff00 - i; |
| 7287 | xyz += 0x100; |
| 7288 | Tcl_SetObjResult(interp, Tcl_NewIntObj(xyz)); |
| 7289 | break; |
| 7290 | } |
| 7291 | case 2: { |
| 7292 | w[1] = 5; |
| 7293 | if( w[i]>0 ) w[1]++; |
| 7294 | Tcl_SetObjResult(interp, Tcl_NewIntObj(w[1])); |
| 7295 | break; |
| 7296 | } |
| 7297 | case 3: { |
| 7298 | a = malloc( sizeof(int)*10 ); |
| 7299 | for(j=0; j<10; j++) a[j] = j; |
| 7300 | free(a); |
| 7301 | Tcl_SetObjResult(interp, Tcl_NewIntObj(a[i])); |
| 7302 | break; |
| 7303 | } |
drh | db6bafa | 2015-01-09 21:54:58 +0000 | [diff] [blame] | 7304 | case 4: { |
| 7305 | Tcl_Panic("Deliberate panic"); |
| 7306 | break; |
| 7307 | } |
drh | edb31cd | 2015-01-08 02:15:11 +0000 | [diff] [blame] | 7308 | } |
| 7309 | return TCL_OK; |
| 7310 | } |
drh | 3e0327d | 2015-05-11 11:59:15 +0000 | [diff] [blame] | 7311 | |
| 7312 | /* |
| 7313 | ** tclcmd: register_dbstat_vtab DB |
| 7314 | ** |
| 7315 | ** Cause the dbstat virtual table to be available on the connection DB |
| 7316 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 7317 | static int SQLITE_TCLAPI test_register_dbstat_vtab( |
drh | 3e0327d | 2015-05-11 11:59:15 +0000 | [diff] [blame] | 7318 | void *clientData, |
| 7319 | Tcl_Interp *interp, |
| 7320 | int objc, |
| 7321 | Tcl_Obj *CONST objv[] |
| 7322 | ){ |
| 7323 | #ifdef SQLITE_OMIT_VIRTUALTABLE |
| 7324 | Tcl_AppendResult(interp, "dbstat not available because of " |
| 7325 | "SQLITE_OMIT_VIRTUALTABLE", (void*)0); |
| 7326 | return TCL_ERROR; |
| 7327 | #else |
| 7328 | struct SqliteDb { sqlite3 *db; }; |
| 7329 | char *zDb; |
| 7330 | Tcl_CmdInfo cmdInfo; |
| 7331 | |
| 7332 | if( objc!=2 ){ |
| 7333 | Tcl_WrongNumArgs(interp, 1, objv, "DB"); |
| 7334 | return TCL_ERROR; |
| 7335 | } |
| 7336 | |
| 7337 | zDb = Tcl_GetString(objv[1]); |
| 7338 | if( Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){ |
| 7339 | sqlite3* db = ((struct SqliteDb*)cmdInfo.objClientData)->db; |
| 7340 | sqlite3DbstatRegister(db); |
| 7341 | } |
| 7342 | return TCL_OK; |
| 7343 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 7344 | } |
drh | edb31cd | 2015-01-08 02:15:11 +0000 | [diff] [blame] | 7345 | |
| 7346 | /* |
drh | d42908f | 2016-02-26 15:38:24 +0000 | [diff] [blame] | 7347 | ** tclcmd: sqlite3_db_config DB SETTING VALUE |
| 7348 | ** |
| 7349 | ** Invoke sqlite3_db_config() for one of the setting values. |
| 7350 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 7351 | static int SQLITE_TCLAPI test_sqlite3_db_config( |
drh | d42908f | 2016-02-26 15:38:24 +0000 | [diff] [blame] | 7352 | void *clientData, |
| 7353 | Tcl_Interp *interp, |
| 7354 | int objc, |
| 7355 | Tcl_Obj *CONST objv[] |
| 7356 | ){ |
| 7357 | static const struct { |
| 7358 | const char *zName; |
| 7359 | int eVal; |
| 7360 | } aSetting[] = { |
| 7361 | { "FKEY", SQLITE_DBCONFIG_ENABLE_FKEY }, |
| 7362 | { "TRIGGER", SQLITE_DBCONFIG_ENABLE_TRIGGER }, |
| 7363 | { "FTS3_TOKENIZER", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER }, |
drh | 191dd06 | 2016-04-21 01:30:09 +0000 | [diff] [blame] | 7364 | { "LOAD_EXTENSION", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION }, |
dan | 298af02 | 2016-10-31 16:16:49 +0000 | [diff] [blame] | 7365 | { "NO_CKPT_ON_CLOSE",SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE }, |
drh | d42908f | 2016-02-26 15:38:24 +0000 | [diff] [blame] | 7366 | }; |
| 7367 | int i; |
| 7368 | int v; |
| 7369 | const char *zSetting; |
| 7370 | sqlite3 *db; |
| 7371 | |
| 7372 | if( objc!=4 ){ |
| 7373 | Tcl_WrongNumArgs(interp, 1, objv, "DB SETTING VALUE"); |
| 7374 | return TCL_ERROR; |
| 7375 | } |
| 7376 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 7377 | zSetting = Tcl_GetString(objv[2]); |
| 7378 | if( sqlite3_strglob("SQLITE_*", zSetting)==0 ) zSetting += 7; |
| 7379 | if( sqlite3_strglob("DBCONFIG_*", zSetting)==0 ) zSetting += 9; |
| 7380 | if( sqlite3_strglob("ENABLE_*", zSetting)==0 ) zSetting += 7; |
| 7381 | for(i=0; i<ArraySize(aSetting); i++){ |
| 7382 | if( strcmp(zSetting, aSetting[i].zName)==0 ) break; |
| 7383 | } |
| 7384 | if( i>=ArraySize(aSetting) ){ |
| 7385 | Tcl_SetObjResult(interp, |
| 7386 | Tcl_NewStringObj("unknown sqlite3_db_config setting", -1)); |
| 7387 | return TCL_ERROR; |
| 7388 | } |
| 7389 | if( Tcl_GetIntFromObj(interp, objv[3], &v) ) return TCL_ERROR; |
| 7390 | sqlite3_db_config(db, aSetting[i].eVal, v, &v); |
| 7391 | Tcl_SetObjResult(interp, Tcl_NewIntObj(v)); |
| 7392 | return TCL_OK; |
| 7393 | } |
| 7394 | |
| 7395 | /* |
drh | da84dca | 2016-08-18 22:44:22 +0000 | [diff] [blame] | 7396 | ** Change the name of the main database schema from "main" to "icecube". |
| 7397 | */ |
| 7398 | static int SQLITE_TCLAPI test_dbconfig_maindbname_icecube( |
| 7399 | void * clientData, |
| 7400 | Tcl_Interp *interp, |
| 7401 | int objc, |
| 7402 | Tcl_Obj *CONST objv[] |
| 7403 | ){ |
| 7404 | int rc; |
| 7405 | sqlite3 *db; |
| 7406 | extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**); |
| 7407 | if( objc!=2 ){ |
| 7408 | Tcl_WrongNumArgs(interp, 1, objv, "DB"); |
| 7409 | return TCL_ERROR; |
| 7410 | }else{ |
| 7411 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 7412 | rc = sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, "icecube"); |
| 7413 | Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); |
| 7414 | return TCL_OK; |
| 7415 | } |
| 7416 | } |
| 7417 | |
| 7418 | /* |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 7419 | ** Register commands with the TCL interpreter. |
| 7420 | */ |
| 7421 | int Sqlitetest1_Init(Tcl_Interp *interp){ |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 7422 | extern int sqlite3_search_count; |
dan | 0ff297e | 2009-09-25 17:03:14 +0000 | [diff] [blame] | 7423 | extern int sqlite3_found_count; |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 7424 | extern int sqlite3_interrupt_count; |
| 7425 | extern int sqlite3_open_file_count; |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame] | 7426 | extern int sqlite3_sort_count; |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 7427 | extern int sqlite3_current_time; |
drh | 84a2bf6 | 2010-03-05 13:41:06 +0000 | [diff] [blame] | 7428 | #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 7429 | extern int sqlite3_hostid_num; |
pweilbacher | aabbed2 | 2008-11-21 23:35:02 +0000 | [diff] [blame] | 7430 | #endif |
drh | ae7e151 | 2007-05-02 16:51:59 +0000 | [diff] [blame] | 7431 | extern int sqlite3_max_blobsize; |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 7432 | extern int SQLITE_TCLAPI sqlite3BtreeSharedCacheReport(void*, |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 7433 | Tcl_Interp*,int,Tcl_Obj*CONST*); |
drh | edb31cd | 2015-01-08 02:15:11 +0000 | [diff] [blame] | 7434 | static int iZero = 0; |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 7435 | static struct { |
| 7436 | char *zName; |
| 7437 | Tcl_CmdProc *xProc; |
| 7438 | } aCmd[] = { |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 7439 | { "db_enter", (Tcl_CmdProc*)db_enter }, |
| 7440 | { "db_leave", (Tcl_CmdProc*)db_leave }, |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 7441 | { "sqlite3_mprintf_int", (Tcl_CmdProc*)sqlite3_mprintf_int }, |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 7442 | { "sqlite3_mprintf_int64", (Tcl_CmdProc*)sqlite3_mprintf_int64 }, |
drh | c5cad1e | 2009-02-01 00:21:09 +0000 | [diff] [blame] | 7443 | { "sqlite3_mprintf_long", (Tcl_CmdProc*)sqlite3_mprintf_long }, |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 7444 | { "sqlite3_mprintf_str", (Tcl_CmdProc*)sqlite3_mprintf_str }, |
drh | b3738b6 | 2007-03-31 15:02:49 +0000 | [diff] [blame] | 7445 | { "sqlite3_snprintf_str", (Tcl_CmdProc*)sqlite3_snprintf_str }, |
drh | e29b1a0 | 2004-07-17 21:56:09 +0000 | [diff] [blame] | 7446 | { "sqlite3_mprintf_stronly", (Tcl_CmdProc*)sqlite3_mprintf_stronly}, |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 7447 | { "sqlite3_mprintf_double", (Tcl_CmdProc*)sqlite3_mprintf_double }, |
| 7448 | { "sqlite3_mprintf_scaled", (Tcl_CmdProc*)sqlite3_mprintf_scaled }, |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 7449 | { "sqlite3_mprintf_hexdouble", (Tcl_CmdProc*)sqlite3_mprintf_hexdouble}, |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 7450 | { "sqlite3_mprintf_z_test", (Tcl_CmdProc*)test_mprintf_z }, |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 7451 | { "sqlite3_mprintf_n_test", (Tcl_CmdProc*)test_mprintf_n }, |
drh | 6885390 | 2007-05-07 11:24:30 +0000 | [diff] [blame] | 7452 | { "sqlite3_snprintf_int", (Tcl_CmdProc*)test_snprintf_int }, |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 7453 | { "sqlite3_last_insert_rowid", (Tcl_CmdProc*)test_last_rowid }, |
| 7454 | { "sqlite3_exec_printf", (Tcl_CmdProc*)test_exec_printf }, |
drh | 5bd98ae | 2009-01-07 18:24:03 +0000 | [diff] [blame] | 7455 | { "sqlite3_exec_hex", (Tcl_CmdProc*)test_exec_hex }, |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 7456 | { "sqlite3_exec", (Tcl_CmdProc*)test_exec }, |
| 7457 | { "sqlite3_exec_nr", (Tcl_CmdProc*)test_exec_nr }, |
shane | 8225f5a | 2008-07-31 02:05:04 +0000 | [diff] [blame] | 7458 | #ifndef SQLITE_OMIT_GET_TABLE |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 7459 | { "sqlite3_get_table_printf", (Tcl_CmdProc*)test_get_table_printf }, |
shane | 8225f5a | 2008-07-31 02:05:04 +0000 | [diff] [blame] | 7460 | #endif |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 7461 | { "sqlite3_close", (Tcl_CmdProc*)sqlite_test_close }, |
dan | 617dc86 | 2013-05-16 11:57:28 +0000 | [diff] [blame] | 7462 | { "sqlite3_close_v2", (Tcl_CmdProc*)sqlite_test_close_v2 }, |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 7463 | { "sqlite3_create_function", (Tcl_CmdProc*)test_create_function }, |
| 7464 | { "sqlite3_create_aggregate", (Tcl_CmdProc*)test_create_aggregate }, |
| 7465 | { "sqlite_register_test_function", (Tcl_CmdProc*)test_register_func }, |
| 7466 | { "sqlite_abort", (Tcl_CmdProc*)sqlite_abort }, |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 7467 | { "sqlite_bind", (Tcl_CmdProc*)test_bind }, |
| 7468 | { "breakpoint", (Tcl_CmdProc*)test_breakpoint }, |
| 7469 | { "sqlite3_key", (Tcl_CmdProc*)test_key }, |
| 7470 | { "sqlite3_rekey", (Tcl_CmdProc*)test_rekey }, |
drh | cacb208 | 2005-01-11 15:28:33 +0000 | [diff] [blame] | 7471 | { "sqlite_set_magic", (Tcl_CmdProc*)sqlite_set_magic }, |
drh | c5cdca6 | 2005-01-11 16:54:14 +0000 | [diff] [blame] | 7472 | { "sqlite3_interrupt", (Tcl_CmdProc*)test_interrupt }, |
drh | 3e1d8e6 | 2005-05-26 16:23:34 +0000 | [diff] [blame] | 7473 | { "sqlite_delete_function", (Tcl_CmdProc*)delete_function }, |
| 7474 | { "sqlite_delete_collation", (Tcl_CmdProc*)delete_collation }, |
| 7475 | { "sqlite3_get_autocommit", (Tcl_CmdProc*)get_autocommit }, |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 7476 | { "sqlite3_stack_used", (Tcl_CmdProc*)test_stack_used }, |
drh | 3086765 | 2006-07-06 10:59:57 +0000 | [diff] [blame] | 7477 | { "sqlite3_busy_timeout", (Tcl_CmdProc*)test_busy_timeout }, |
drh | 3c23a88 | 2007-01-09 14:01:13 +0000 | [diff] [blame] | 7478 | { "printf", (Tcl_CmdProc*)test_printf }, |
mlcreech | 3a00f90 | 2008-03-04 17:45:01 +0000 | [diff] [blame] | 7479 | { "sqlite3IoTrace", (Tcl_CmdProc*)test_io_trace }, |
dan | afcf9bd | 2014-01-23 14:44:08 +0000 | [diff] [blame] | 7480 | { "clang_sanitize_address", (Tcl_CmdProc*)clang_sanitize_address }, |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 7481 | }; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 7482 | static struct { |
| 7483 | char *zName; |
| 7484 | Tcl_ObjCmdProc *xProc; |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 7485 | void *clientData; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 7486 | } aObjCmd[] = { |
drh | d42908f | 2016-02-26 15:38:24 +0000 | [diff] [blame] | 7487 | { "sqlite3_db_config", test_sqlite3_db_config, 0 }, |
drh | edb31cd | 2015-01-08 02:15:11 +0000 | [diff] [blame] | 7488 | { "bad_behavior", test_bad_behavior, (void*)&iZero }, |
drh | 3e0327d | 2015-05-11 11:59:15 +0000 | [diff] [blame] | 7489 | { "register_dbstat_vtab", test_register_dbstat_vtab }, |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 7490 | { "sqlite3_connection_pointer", get_sqlite_pointer, 0 }, |
drh | 2e3f87a | 2016-07-03 02:35:47 +0000 | [diff] [blame] | 7491 | { "intarray_addr", test_intarray_addr, 0 }, |
| 7492 | { "int64array_addr", test_int64array_addr, 0 }, |
| 7493 | { "doublearray_addr", test_doublearray_addr, 0 }, |
| 7494 | { "textarray_addr", test_textarray_addr, 0 }, |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 7495 | { "sqlite3_bind_int", test_bind_int, 0 }, |
drh | b026e05 | 2007-05-02 01:34:31 +0000 | [diff] [blame] | 7496 | { "sqlite3_bind_zeroblob", test_bind_zeroblob, 0 }, |
dan | 80c0302 | 2015-07-24 17:36:34 +0000 | [diff] [blame] | 7497 | { "sqlite3_bind_zeroblob64", test_bind_zeroblob64, 0 }, |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 7498 | { "sqlite3_bind_int64", test_bind_int64, 0 }, |
| 7499 | { "sqlite3_bind_double", test_bind_double, 0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 7500 | { "sqlite3_bind_null", test_bind_null ,0 }, |
| 7501 | { "sqlite3_bind_text", test_bind_text ,0 }, |
| 7502 | { "sqlite3_bind_text16", test_bind_text16 ,0 }, |
| 7503 | { "sqlite3_bind_blob", test_bind_blob ,0 }, |
drh | 75f6a03 | 2004-07-15 14:15:00 +0000 | [diff] [blame] | 7504 | { "sqlite3_bind_parameter_count", test_bind_parameter_count, 0}, |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 7505 | { "sqlite3_bind_parameter_name", test_bind_parameter_name, 0}, |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 7506 | { "sqlite3_bind_parameter_index", test_bind_parameter_index, 0}, |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 7507 | { "sqlite3_clear_bindings", test_clear_bindings, 0}, |
drh | f9cb7f5 | 2006-06-27 20:06:44 +0000 | [diff] [blame] | 7508 | { "sqlite3_sleep", test_sleep, 0}, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 7509 | { "sqlite3_errcode", test_errcode ,0 }, |
drh | 99dfe5e | 2008-10-30 15:03:15 +0000 | [diff] [blame] | 7510 | { "sqlite3_extended_errcode", test_ex_errcode ,0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 7511 | { "sqlite3_errmsg", test_errmsg ,0 }, |
| 7512 | { "sqlite3_errmsg16", test_errmsg16 ,0 }, |
| 7513 | { "sqlite3_open", test_open ,0 }, |
| 7514 | { "sqlite3_open16", test_open16 ,0 }, |
dan | 286ab7c | 2011-05-06 18:34:54 +0000 | [diff] [blame] | 7515 | { "sqlite3_open_v2", test_open_v2 ,0 }, |
danielk1977 | bc6ada4 | 2004-06-30 08:20:16 +0000 | [diff] [blame] | 7516 | { "sqlite3_complete16", test_complete16 ,0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 7517 | |
| 7518 | { "sqlite3_prepare", test_prepare ,0 }, |
| 7519 | { "sqlite3_prepare16", test_prepare16 ,0 }, |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 7520 | { "sqlite3_prepare_v2", test_prepare_v2 ,0 }, |
drh | 4837f53 | 2008-05-23 14:49:49 +0000 | [diff] [blame] | 7521 | { "sqlite3_prepare_tkt3134", test_prepare_tkt3134, 0}, |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 7522 | { "sqlite3_prepare16_v2", test_prepare16_v2 ,0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 7523 | { "sqlite3_finalize", test_finalize ,0 }, |
drh | d1d3848 | 2008-10-07 23:46:38 +0000 | [diff] [blame] | 7524 | { "sqlite3_stmt_status", test_stmt_status ,0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 7525 | { "sqlite3_reset", test_reset ,0 }, |
drh | d89bd00 | 2005-01-22 03:03:54 +0000 | [diff] [blame] | 7526 | { "sqlite3_expired", test_expired ,0 }, |
drh | f8db1bc | 2005-04-22 02:38:37 +0000 | [diff] [blame] | 7527 | { "sqlite3_transfer_bindings", test_transfer_bind ,0 }, |
danielk1977 | fbcd585 | 2004-06-15 02:44:18 +0000 | [diff] [blame] | 7528 | { "sqlite3_changes", test_changes ,0 }, |
| 7529 | { "sqlite3_step", test_step ,0 }, |
danielk1977 | 404ca07 | 2009-03-16 13:19:36 +0000 | [diff] [blame] | 7530 | { "sqlite3_sql", test_sql ,0 }, |
drh | fca760c | 2016-07-14 01:09:08 +0000 | [diff] [blame] | 7531 | { "sqlite3_expanded_sql", test_ex_sql ,0 }, |
drh | bb5a9c3 | 2008-06-19 02:52:25 +0000 | [diff] [blame] | 7532 | { "sqlite3_next_stmt", test_next_stmt ,0 }, |
drh | f03d9cc | 2010-11-16 23:10:25 +0000 | [diff] [blame] | 7533 | { "sqlite3_stmt_readonly", test_stmt_readonly ,0 }, |
drh | 2fb6693 | 2011-11-25 17:21:47 +0000 | [diff] [blame] | 7534 | { "sqlite3_stmt_busy", test_stmt_busy ,0 }, |
dan | d9495cd | 2011-04-27 12:08:04 +0000 | [diff] [blame] | 7535 | { "uses_stmt_journal", uses_stmt_journal ,0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 7536 | |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 7537 | { "sqlite3_release_memory", test_release_memory, 0}, |
drh | 09419b4 | 2011-11-16 19:29:17 +0000 | [diff] [blame] | 7538 | { "sqlite3_db_release_memory", test_db_release_memory, 0}, |
dan | 6fa255f | 2015-10-28 19:46:57 +0000 | [diff] [blame] | 7539 | { "sqlite3_db_cacheflush", test_db_cacheflush, 0}, |
drh | 0e80e50 | 2016-03-17 17:23:11 +0000 | [diff] [blame] | 7540 | { "sqlite3_system_errno", test_system_errno, 0}, |
drh | 283829c | 2011-11-17 00:56:20 +0000 | [diff] [blame] | 7541 | { "sqlite3_db_filename", test_db_filename, 0}, |
drh | 421377e | 2012-03-15 21:28:54 +0000 | [diff] [blame] | 7542 | { "sqlite3_db_readonly", test_db_readonly, 0}, |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 7543 | { "sqlite3_soft_heap_limit", test_soft_heap_limit, 0}, |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 7544 | { "sqlite3_thread_cleanup", test_thread_cleanup, 0}, |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 7545 | { "sqlite3_pager_refcounts", test_pager_refcounts, 0}, |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 7546 | |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 7547 | { "sqlite3_load_extension", test_load_extension, 0}, |
| 7548 | { "sqlite3_enable_load_extension", test_enable_load, 0}, |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 7549 | { "sqlite3_extended_result_codes", test_extended_result_codes, 0}, |
drh | b1a6c3c | 2008-03-20 16:30:17 +0000 | [diff] [blame] | 7550 | { "sqlite3_limit", test_limit, 0}, |
drh | da84dca | 2016-08-18 22:44:22 +0000 | [diff] [blame] | 7551 | { "dbconfig_maindbname_icecube", test_dbconfig_maindbname_icecube }, |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 7552 | |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 7553 | { "save_prng_state", save_prng_state, 0 }, |
| 7554 | { "restore_prng_state", restore_prng_state, 0 }, |
| 7555 | { "reset_prng_state", reset_prng_state, 0 }, |
drh | 09fe614 | 2013-11-29 15:06:27 +0000 | [diff] [blame] | 7556 | { "database_never_corrupt", database_never_corrupt, 0}, |
| 7557 | { "database_may_be_corrupt", database_may_be_corrupt, 0}, |
drh | f58ee7f | 2010-12-06 21:06:09 +0000 | [diff] [blame] | 7558 | { "optimization_control", optimization_control,0}, |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 7559 | #if SQLITE_OS_WIN |
| 7560 | { "lock_win32_file", win32_file_lock, 0 }, |
mistachkin | 3741827 | 2013-08-28 05:49:39 +0000 | [diff] [blame] | 7561 | { "exists_win32_path", win32_exists_path, 0 }, |
| 7562 | { "find_win32_file", win32_find_file, 0 }, |
| 7563 | { "delete_win32_file", win32_delete_file, 0 }, |
| 7564 | { "make_win32_dir", win32_mkdir, 0 }, |
| 7565 | { "remove_win32_dir", win32_rmdir, 0 }, |
drh | 80084ca | 2011-07-11 23:45:44 +0000 | [diff] [blame] | 7566 | #endif |
drh | a2c8a95 | 2009-10-13 18:38:34 +0000 | [diff] [blame] | 7567 | { "tcl_objproc", runAsObjProc, 0 }, |
drh | 93aed5a | 2008-01-16 17:46:38 +0000 | [diff] [blame] | 7568 | |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 7569 | /* sqlite3_column_*() API */ |
| 7570 | { "sqlite3_column_count", test_column_count ,0 }, |
| 7571 | { "sqlite3_data_count", test_data_count ,0 }, |
| 7572 | { "sqlite3_column_type", test_column_type ,0 }, |
danielk1977 | ea61b2c | 2004-05-27 01:49:51 +0000 | [diff] [blame] | 7573 | { "sqlite3_column_blob", test_column_blob ,0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 7574 | { "sqlite3_column_double", test_column_double ,0 }, |
| 7575 | { "sqlite3_column_int64", test_column_int64 ,0 }, |
danielk1977 | 44a376f | 2008-08-12 15:04:58 +0000 | [diff] [blame] | 7576 | { "sqlite3_column_text", test_stmt_utf8, (void*)sqlite3_column_text }, |
| 7577 | { "sqlite3_column_name", test_stmt_utf8, (void*)sqlite3_column_name }, |
| 7578 | { "sqlite3_column_int", test_stmt_int, (void*)sqlite3_column_int }, |
| 7579 | { "sqlite3_column_bytes", test_stmt_int, (void*)sqlite3_column_bytes}, |
drh | 3f91357 | 2008-03-22 01:07:17 +0000 | [diff] [blame] | 7580 | #ifndef SQLITE_OMIT_DECLTYPE |
danielk1977 | 44a376f | 2008-08-12 15:04:58 +0000 | [diff] [blame] | 7581 | { "sqlite3_column_decltype",test_stmt_utf8,(void*)sqlite3_column_decltype}, |
drh | 3f91357 | 2008-03-22 01:07:17 +0000 | [diff] [blame] | 7582 | #endif |
danielk1977 | 4b1ae99 | 2006-02-10 03:06:10 +0000 | [diff] [blame] | 7583 | #ifdef SQLITE_ENABLE_COLUMN_METADATA |
danielk1977 | 44a376f | 2008-08-12 15:04:58 +0000 | [diff] [blame] | 7584 | { "sqlite3_column_database_name",test_stmt_utf8,(void*)sqlite3_column_database_name}, |
| 7585 | { "sqlite3_column_table_name",test_stmt_utf8,(void*)sqlite3_column_table_name}, |
| 7586 | { "sqlite3_column_origin_name",test_stmt_utf8,(void*)sqlite3_column_origin_name}, |
danielk1977 | 4b1ae99 | 2006-02-10 03:06:10 +0000 | [diff] [blame] | 7587 | #endif |
danielk1977 | 955de52 | 2006-02-10 02:27:42 +0000 | [diff] [blame] | 7588 | |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 7589 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 44a376f | 2008-08-12 15:04:58 +0000 | [diff] [blame] | 7590 | { "sqlite3_column_bytes16", test_stmt_int, (void*)sqlite3_column_bytes16 }, |
| 7591 | { "sqlite3_column_text16", test_stmt_utf16, (void*)sqlite3_column_text16}, |
| 7592 | { "sqlite3_column_name16", test_stmt_utf16, (void*)sqlite3_column_name16}, |
drh | 7d9bd4e | 2006-02-16 18:16:36 +0000 | [diff] [blame] | 7593 | { "add_alignment_test_collations", add_alignment_test_collations, 0 }, |
drh | 3f91357 | 2008-03-22 01:07:17 +0000 | [diff] [blame] | 7594 | #ifndef SQLITE_OMIT_DECLTYPE |
danielk1977 | 44a376f | 2008-08-12 15:04:58 +0000 | [diff] [blame] | 7595 | { "sqlite3_column_decltype16",test_stmt_utf16,(void*)sqlite3_column_decltype16}, |
drh | 3f91357 | 2008-03-22 01:07:17 +0000 | [diff] [blame] | 7596 | #endif |
danielk1977 | 4b1ae99 | 2006-02-10 03:06:10 +0000 | [diff] [blame] | 7597 | #ifdef SQLITE_ENABLE_COLUMN_METADATA |
danielk1977 | 955de52 | 2006-02-10 02:27:42 +0000 | [diff] [blame] | 7598 | {"sqlite3_column_database_name16", |
drh | 7da5fcb | 2012-03-30 14:59:43 +0000 | [diff] [blame] | 7599 | test_stmt_utf16, (void*)sqlite3_column_database_name16}, |
danielk1977 | 44a376f | 2008-08-12 15:04:58 +0000 | [diff] [blame] | 7600 | {"sqlite3_column_table_name16", test_stmt_utf16, (void*)sqlite3_column_table_name16}, |
| 7601 | {"sqlite3_column_origin_name16", test_stmt_utf16, (void*)sqlite3_column_origin_name16}, |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 7602 | #endif |
danielk1977 | 4b1ae99 | 2006-02-10 03:06:10 +0000 | [diff] [blame] | 7603 | #endif |
danielk1977 | a393c03 | 2007-05-07 14:58:53 +0000 | [diff] [blame] | 7604 | { "sqlite3_create_collation_v2", test_create_collation_v2, 0 }, |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 7605 | { "sqlite3_global_recover", test_global_recover, 0 }, |
| 7606 | { "working_64bit_int", working_64bit_int, 0 }, |
drh | 9bc5449 | 2007-10-23 14:49:59 +0000 | [diff] [blame] | 7607 | { "vfs_unlink_test", vfs_unlink_test, 0 }, |
drh | c8d7567 | 2008-07-08 02:12:37 +0000 | [diff] [blame] | 7608 | { "vfs_initfail_test", vfs_initfail_test, 0 }, |
drh | a282097 | 2008-07-07 13:31:58 +0000 | [diff] [blame] | 7609 | { "vfs_unregister_all", vfs_unregister_all, 0 }, |
| 7610 | { "vfs_reregister_all", vfs_reregister_all, 0 }, |
drh | 5517625 | 2008-01-22 14:50:16 +0000 | [diff] [blame] | 7611 | { "file_control_test", file_control_test, 0 }, |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 7612 | { "file_control_lasterrno_test", file_control_lasterrno_test, 0 }, |
| 7613 | { "file_control_lockproxy_test", file_control_lockproxy_test, 0 }, |
dan | 6e09d69 | 2010-07-27 18:34:15 +0000 | [diff] [blame] | 7614 | { "file_control_chunksize_test", file_control_chunksize_test, 0 }, |
drh | d0cdf01 | 2011-07-13 16:03:46 +0000 | [diff] [blame] | 7615 | { "file_control_sizehint_test", file_control_sizehint_test, 0 }, |
mistachkin | 6b98d67 | 2014-05-30 16:42:35 +0000 | [diff] [blame] | 7616 | #if SQLITE_OS_WIN |
drh | d0cdf01 | 2011-07-13 16:03:46 +0000 | [diff] [blame] | 7617 | { "file_control_win32_av_retry", file_control_win32_av_retry, 0 }, |
mistachkin | 1b361ff | 2016-05-03 19:36:54 +0000 | [diff] [blame] | 7618 | { "file_control_win32_get_handle", file_control_win32_get_handle, 0 }, |
mistachkin | 6b98d67 | 2014-05-30 16:42:35 +0000 | [diff] [blame] | 7619 | { "file_control_win32_set_handle", file_control_win32_set_handle, 0 }, |
| 7620 | #endif |
drh | 253cea5 | 2011-07-26 16:23:25 +0000 | [diff] [blame] | 7621 | { "file_control_persist_wal", file_control_persist_wal, 0 }, |
drh | cb15f35 | 2011-12-23 01:04:17 +0000 | [diff] [blame] | 7622 | { "file_control_powersafe_overwrite",file_control_powersafe_overwrite,0}, |
drh | de60fc2 | 2011-12-14 17:53:36 +0000 | [diff] [blame] | 7623 | { "file_control_vfsname", file_control_vfsname, 0 }, |
drh | 696b33e | 2012-12-06 19:01:42 +0000 | [diff] [blame] | 7624 | { "file_control_tempfilename", file_control_tempfilename, 0 }, |
danielk1977 | e339d65 | 2008-06-28 11:23:00 +0000 | [diff] [blame] | 7625 | { "sqlite3_vfs_list", vfs_list, 0 }, |
dan | d2199f0 | 2010-08-27 17:48:52 +0000 | [diff] [blame] | 7626 | { "sqlite3_create_function_v2", test_create_function_v2, 0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 7627 | |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 7628 | /* Functions from os.h */ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 7629 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 7630 | { "add_test_collate", test_collate, 0 }, |
| 7631 | { "add_test_collate_needed", test_collate_needed, 0 }, |
| 7632 | { "add_test_function", test_function, 0 }, |
dan | 38fdead | 2014-04-01 10:19:02 +0000 | [diff] [blame] | 7633 | { "add_test_utf16bin_collate", test_utf16bin_collate, 0 }, |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 7634 | #endif |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 7635 | { "sqlite3_test_errstr", test_errstr, 0 }, |
drh | 92febd9 | 2004-08-20 18:34:20 +0000 | [diff] [blame] | 7636 | { "tcl_variable_type", tcl_variable_type, 0 }, |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 7637 | #ifndef SQLITE_OMIT_SHARED_CACHE |
drh | 6f7adc8 | 2006-01-11 21:41:20 +0000 | [diff] [blame] | 7638 | { "sqlite3_enable_shared_cache", test_enable_shared, 0 }, |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 7639 | { "sqlite3_shared_cache_report", sqlite3BtreeSharedCacheReport, 0}, |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 7640 | #endif |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 7641 | { "sqlite3_libversion_number", test_libversion_number, 0 }, |
danielk1977 | deb802c | 2006-02-09 13:43:28 +0000 | [diff] [blame] | 7642 | { "sqlite3_table_column_metadata", test_table_column_metadata, 0 }, |
danielk1977 | dcbb5d3 | 2007-05-04 18:36:44 +0000 | [diff] [blame] | 7643 | #ifndef SQLITE_OMIT_INCRBLOB |
dan | 4e76cc3 | 2010-10-20 18:56:04 +0000 | [diff] [blame] | 7644 | { "sqlite3_blob_reopen", test_blob_reopen, 0 }, |
danielk1977 | dcbb5d3 | 2007-05-04 18:36:44 +0000 | [diff] [blame] | 7645 | #endif |
danielk1977 | 062d4cb | 2008-08-29 09:10:02 +0000 | [diff] [blame] | 7646 | { "pcache_stats", test_pcache_stats, 0 }, |
danielk1977 | 404ca07 | 2009-03-16 13:19:36 +0000 | [diff] [blame] | 7647 | #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY |
| 7648 | { "sqlite3_unlock_notify", test_unlock_notify, 0 }, |
| 7649 | #endif |
dan | 91da6b8 | 2010-11-15 14:51:33 +0000 | [diff] [blame] | 7650 | { "sqlite3_wal_checkpoint", test_wal_checkpoint, 0 }, |
dan | 9c5e368 | 2011-02-07 15:12:12 +0000 | [diff] [blame] | 7651 | { "sqlite3_wal_checkpoint_v2",test_wal_checkpoint_v2, 0 }, |
dan | 9af1062 | 2014-12-15 16:27:12 +0000 | [diff] [blame] | 7652 | { "sqlite3_wal_autocheckpoint",test_wal_autocheckpoint, 0 }, |
dan | 91da6b8 | 2010-11-15 14:51:33 +0000 | [diff] [blame] | 7653 | { "test_sqlite3_log", test_sqlite3_log, 0 }, |
shaneh | bb20134 | 2011-02-09 19:55:20 +0000 | [diff] [blame] | 7654 | #ifndef SQLITE_OMIT_EXPLAIN |
dan | 91da6b8 | 2010-11-15 14:51:33 +0000 | [diff] [blame] | 7655 | { "print_explain_query_plan", test_print_eqp, 0 }, |
shaneh | bb20134 | 2011-02-09 19:55:20 +0000 | [diff] [blame] | 7656 | #endif |
dan | c17d696 | 2011-06-21 12:47:30 +0000 | [diff] [blame] | 7657 | { "sqlite3_test_control", test_test_control }, |
mistachkin | daf9a5a | 2013-03-23 09:56:39 +0000 | [diff] [blame] | 7658 | #if SQLITE_OS_UNIX |
dan | a72014f | 2013-03-16 20:19:21 +0000 | [diff] [blame] | 7659 | { "getrusage", test_getrusage }, |
mistachkin | daf9a5a | 2013-03-23 09:56:39 +0000 | [diff] [blame] | 7660 | #endif |
drh | 248f2be | 2013-04-23 20:10:13 +0000 | [diff] [blame] | 7661 | { "load_static_extension", tclLoadStaticExtensionCmd }, |
dan | 0d51def | 2014-05-03 14:28:14 +0000 | [diff] [blame] | 7662 | { "sorter_test_fakeheap", sorter_test_fakeheap }, |
dan | dfea453 | 2014-05-06 15:38:07 +0000 | [diff] [blame] | 7663 | { "sorter_test_sort4_helper", sorter_test_sort4_helper }, |
drh | d39c40f | 2014-09-11 00:27:53 +0000 | [diff] [blame] | 7664 | #ifdef SQLITE_USER_AUTHENTICATION |
| 7665 | { "sqlite3_user_authenticate", test_user_authenticate, 0 }, |
| 7666 | { "sqlite3_user_add", test_user_add, 0 }, |
| 7667 | { "sqlite3_user_change", test_user_change, 0 }, |
| 7668 | { "sqlite3_user_delete", test_user_delete, 0 }, |
| 7669 | #endif |
dan | 04489b6 | 2014-10-31 20:11:32 +0000 | [diff] [blame] | 7670 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 7671 | { "sqlite3_stmt_scanstatus", test_stmt_scanstatus, 0 }, |
| 7672 | { "sqlite3_stmt_scanstatus_reset", test_stmt_scanstatus_reset, 0 }, |
| 7673 | #endif |
dan | d83f7ca | 2015-11-12 20:12:51 +0000 | [diff] [blame] | 7674 | #ifdef SQLITE_ENABLE_SQLLOG |
| 7675 | { "sqlite3_config_sqllog", test_config_sqllog, 0 }, |
| 7676 | #endif |
dan | e4e416e | 2015-11-16 15:28:54 +0000 | [diff] [blame] | 7677 | { "vfs_current_time_int64", vfsCurrentTimeInt64, 0 }, |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 7678 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 7679 | { "sqlite3_snapshot_get", test_snapshot_get, 0 }, |
| 7680 | { "sqlite3_snapshot_open", test_snapshot_open, 0 }, |
| 7681 | { "sqlite3_snapshot_free", test_snapshot_free, 0 }, |
dan | ad2d5ba | 2016-04-11 19:59:52 +0000 | [diff] [blame] | 7682 | { "sqlite3_snapshot_cmp", test_snapshot_cmp, 0 }, |
dan | 1158498 | 2016-11-18 20:49:43 +0000 | [diff] [blame] | 7683 | { "sqlite3_snapshot_recover", test_snapshot_recover, 0 }, |
dan | 25accbc | 2016-11-18 14:38:41 +0000 | [diff] [blame] | 7684 | { "sqlite3_snapshot_get_blob", test_snapshot_get_blob, 0 }, |
| 7685 | { "sqlite3_snapshot_open_blob", test_snapshot_open_blob, 0 }, |
| 7686 | { "sqlite3_snapshot_cmp_blob", test_snapshot_cmp_blob, 0 }, |
dan | fc1acf3 | 2015-12-05 20:51:54 +0000 | [diff] [blame] | 7687 | #endif |
dan | 000f95b | 2016-09-09 20:00:40 +0000 | [diff] [blame] | 7688 | { "sqlite3_delete_database", test_delete_database, 0 }, |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 7689 | }; |
drh | 1398ad3 | 2005-01-19 23:24:50 +0000 | [diff] [blame] | 7690 | static int bitmask_size = sizeof(Bitmask)*8; |
drh | 2ab410a | 2015-11-06 14:59:07 +0000 | [diff] [blame] | 7691 | static int longdouble_size = sizeof(LONGDOUBLE_TYPE); |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 7692 | int i; |
drh | b851b2c | 2005-03-10 14:11:12 +0000 | [diff] [blame] | 7693 | extern int sqlite3_sync_count, sqlite3_fullsync_count; |
drh | af6df11 | 2005-06-07 02:12:30 +0000 | [diff] [blame] | 7694 | extern int sqlite3_opentemp_count; |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 7695 | extern int sqlite3_like_count; |
drh | dd73521 | 2007-02-24 13:53:05 +0000 | [diff] [blame] | 7696 | extern int sqlite3_xferopt_count; |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 7697 | extern int sqlite3_pager_readdb_count; |
| 7698 | extern int sqlite3_pager_writedb_count; |
| 7699 | extern int sqlite3_pager_writej_count; |
danielk1977 | 29bafea | 2008-06-26 10:41:19 +0000 | [diff] [blame] | 7700 | #if SQLITE_OS_WIN |
mistachkin | 202cb64 | 2014-07-31 18:54:01 +0000 | [diff] [blame] | 7701 | extern LONG volatile sqlite3_os_type; |
drh | c092998 | 2005-09-05 19:08:29 +0000 | [diff] [blame] | 7702 | #endif |
drh | 8b3d990 | 2005-08-19 00:14:42 +0000 | [diff] [blame] | 7703 | #ifdef SQLITE_DEBUG |
mlcreech | 3a00f90 | 2008-03-04 17:45:01 +0000 | [diff] [blame] | 7704 | extern int sqlite3WhereTrace; |
| 7705 | extern int sqlite3OSTrace; |
drh | c74c333 | 2010-05-31 12:15:19 +0000 | [diff] [blame] | 7706 | extern int sqlite3WalTrace; |
drh | 549c8b6 | 2005-09-19 13:15:23 +0000 | [diff] [blame] | 7707 | #endif |
| 7708 | #ifdef SQLITE_TEST |
danielk1977 | 33e8903 | 2008-12-17 15:18:17 +0000 | [diff] [blame] | 7709 | #ifdef SQLITE_ENABLE_FTS3 |
| 7710 | extern int sqlite3_fts3_enable_parentheses; |
| 7711 | #endif |
drh | 48083ce | 2005-09-19 12:37:27 +0000 | [diff] [blame] | 7712 | #endif |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 7713 | |
| 7714 | for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ |
| 7715 | Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); |
| 7716 | } |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 7717 | for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){ |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 7718 | Tcl_CreateObjCommand(interp, aObjCmd[i].zName, |
| 7719 | aObjCmd[i].xProc, aObjCmd[i].clientData, 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 7720 | } |
danielk1977 | 6490beb | 2004-05-11 06:17:21 +0000 | [diff] [blame] | 7721 | Tcl_LinkVar(interp, "sqlite_search_count", |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 7722 | (char*)&sqlite3_search_count, TCL_LINK_INT); |
dan | 0ff297e | 2009-09-25 17:03:14 +0000 | [diff] [blame] | 7723 | Tcl_LinkVar(interp, "sqlite_found_count", |
| 7724 | (char*)&sqlite3_found_count, TCL_LINK_INT); |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame] | 7725 | Tcl_LinkVar(interp, "sqlite_sort_count", |
| 7726 | (char*)&sqlite3_sort_count, TCL_LINK_INT); |
drh | ae7e151 | 2007-05-02 16:51:59 +0000 | [diff] [blame] | 7727 | Tcl_LinkVar(interp, "sqlite3_max_blobsize", |
| 7728 | (char*)&sqlite3_max_blobsize, TCL_LINK_INT); |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 7729 | Tcl_LinkVar(interp, "sqlite_like_count", |
| 7730 | (char*)&sqlite3_like_count, TCL_LINK_INT); |
danielk1977 | 6490beb | 2004-05-11 06:17:21 +0000 | [diff] [blame] | 7731 | Tcl_LinkVar(interp, "sqlite_interrupt_count", |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 7732 | (char*)&sqlite3_interrupt_count, TCL_LINK_INT); |
danielk1977 | 6490beb | 2004-05-11 06:17:21 +0000 | [diff] [blame] | 7733 | Tcl_LinkVar(interp, "sqlite_open_file_count", |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 7734 | (char*)&sqlite3_open_file_count, TCL_LINK_INT); |
danielk1977 | 6490beb | 2004-05-11 06:17:21 +0000 | [diff] [blame] | 7735 | Tcl_LinkVar(interp, "sqlite_current_time", |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 7736 | (char*)&sqlite3_current_time, TCL_LINK_INT); |
drh | 84a2bf6 | 2010-03-05 13:41:06 +0000 | [diff] [blame] | 7737 | #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE |
aswift | aebf413 | 2008-11-21 00:10:35 +0000 | [diff] [blame] | 7738 | Tcl_LinkVar(interp, "sqlite_hostid_num", |
| 7739 | (char*)&sqlite3_hostid_num, TCL_LINK_INT); |
pweilbacher | aabbed2 | 2008-11-21 23:35:02 +0000 | [diff] [blame] | 7740 | #endif |
drh | dd73521 | 2007-02-24 13:53:05 +0000 | [diff] [blame] | 7741 | Tcl_LinkVar(interp, "sqlite3_xferopt_count", |
| 7742 | (char*)&sqlite3_xferopt_count, TCL_LINK_INT); |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 7743 | Tcl_LinkVar(interp, "sqlite3_pager_readdb_count", |
| 7744 | (char*)&sqlite3_pager_readdb_count, TCL_LINK_INT); |
| 7745 | Tcl_LinkVar(interp, "sqlite3_pager_writedb_count", |
| 7746 | (char*)&sqlite3_pager_writedb_count, TCL_LINK_INT); |
| 7747 | Tcl_LinkVar(interp, "sqlite3_pager_writej_count", |
| 7748 | (char*)&sqlite3_pager_writej_count, TCL_LINK_INT); |
danielk1977 | 4b2688a | 2006-06-20 11:01:07 +0000 | [diff] [blame] | 7749 | #ifndef SQLITE_OMIT_UTF16 |
drh | 7d9bd4e | 2006-02-16 18:16:36 +0000 | [diff] [blame] | 7750 | Tcl_LinkVar(interp, "unaligned_string_counter", |
| 7751 | (char*)&unaligned_string_counter, TCL_LINK_INT); |
danielk1977 | 4b2688a | 2006-06-20 11:01:07 +0000 | [diff] [blame] | 7752 | #endif |
drh | 268803a | 2005-12-14 20:11:30 +0000 | [diff] [blame] | 7753 | #ifndef SQLITE_OMIT_UTF16 |
| 7754 | Tcl_LinkVar(interp, "sqlite_last_needed_collation", |
| 7755 | (char*)&pzNeededCollation, TCL_LINK_STRING|TCL_LINK_READ_ONLY); |
| 7756 | #endif |
danielk1977 | 29bafea | 2008-06-26 10:41:19 +0000 | [diff] [blame] | 7757 | #if SQLITE_OS_WIN |
drh | c092998 | 2005-09-05 19:08:29 +0000 | [diff] [blame] | 7758 | Tcl_LinkVar(interp, "sqlite_os_type", |
mistachkin | 202cb64 | 2014-07-31 18:54:01 +0000 | [diff] [blame] | 7759 | (char*)&sqlite3_os_type, TCL_LINK_LONG); |
drh | c092998 | 2005-09-05 19:08:29 +0000 | [diff] [blame] | 7760 | #endif |
drh | 549c8b6 | 2005-09-19 13:15:23 +0000 | [diff] [blame] | 7761 | #ifdef SQLITE_TEST |
drh | 6fa978d | 2013-05-30 19:29:19 +0000 | [diff] [blame] | 7762 | { |
| 7763 | static const char *query_plan = "*** OBSOLETE VARIABLE ***"; |
| 7764 | Tcl_LinkVar(interp, "sqlite_query_plan", |
| 7765 | (char*)&query_plan, TCL_LINK_STRING|TCL_LINK_READ_ONLY); |
| 7766 | } |
drh | 549c8b6 | 2005-09-19 13:15:23 +0000 | [diff] [blame] | 7767 | #endif |
drh | 8b3d990 | 2005-08-19 00:14:42 +0000 | [diff] [blame] | 7768 | #ifdef SQLITE_DEBUG |
drh | 48083ce | 2005-09-19 12:37:27 +0000 | [diff] [blame] | 7769 | Tcl_LinkVar(interp, "sqlite_where_trace", |
mlcreech | 3a00f90 | 2008-03-04 17:45:01 +0000 | [diff] [blame] | 7770 | (char*)&sqlite3WhereTrace, TCL_LINK_INT); |
drh | 73be501 | 2007-08-08 12:11:21 +0000 | [diff] [blame] | 7771 | Tcl_LinkVar(interp, "sqlite_os_trace", |
mlcreech | 3a00f90 | 2008-03-04 17:45:01 +0000 | [diff] [blame] | 7772 | (char*)&sqlite3OSTrace, TCL_LINK_INT); |
dan | 38e1a27 | 2010-06-28 11:23:09 +0000 | [diff] [blame] | 7773 | #ifndef SQLITE_OMIT_WAL |
drh | c74c333 | 2010-05-31 12:15:19 +0000 | [diff] [blame] | 7774 | Tcl_LinkVar(interp, "sqlite_wal_trace", |
| 7775 | (char*)&sqlite3WalTrace, TCL_LINK_INT); |
drh | 8b3d990 | 2005-08-19 00:14:42 +0000 | [diff] [blame] | 7776 | #endif |
dan | 38e1a27 | 2010-06-28 11:23:09 +0000 | [diff] [blame] | 7777 | #endif |
danielk1977 | cbe21be | 2005-06-07 07:58:48 +0000 | [diff] [blame] | 7778 | #ifndef SQLITE_OMIT_DISKIO |
drh | af6df11 | 2005-06-07 02:12:30 +0000 | [diff] [blame] | 7779 | Tcl_LinkVar(interp, "sqlite_opentemp_count", |
| 7780 | (char*)&sqlite3_opentemp_count, TCL_LINK_INT); |
danielk1977 | cbe21be | 2005-06-07 07:58:48 +0000 | [diff] [blame] | 7781 | #endif |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 7782 | Tcl_LinkVar(interp, "sqlite_static_bind_value", |
| 7783 | (char*)&sqlite_static_bind_value, TCL_LINK_STRING); |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 7784 | Tcl_LinkVar(interp, "sqlite_static_bind_nbyte", |
| 7785 | (char*)&sqlite_static_bind_nbyte, TCL_LINK_INT); |
drh | ab3f9fe | 2004-08-14 17:10:10 +0000 | [diff] [blame] | 7786 | Tcl_LinkVar(interp, "sqlite_temp_directory", |
drh | effd02b | 2004-08-29 23:42:13 +0000 | [diff] [blame] | 7787 | (char*)&sqlite3_temp_directory, TCL_LINK_STRING); |
mistachkin | a112d14 | 2012-03-14 00:44:01 +0000 | [diff] [blame] | 7788 | Tcl_LinkVar(interp, "sqlite_data_directory", |
| 7789 | (char*)&sqlite3_data_directory, TCL_LINK_STRING); |
drh | 1398ad3 | 2005-01-19 23:24:50 +0000 | [diff] [blame] | 7790 | Tcl_LinkVar(interp, "bitmask_size", |
| 7791 | (char*)&bitmask_size, TCL_LINK_INT|TCL_LINK_READ_ONLY); |
drh | 2ab410a | 2015-11-06 14:59:07 +0000 | [diff] [blame] | 7792 | Tcl_LinkVar(interp, "longdouble_size", |
| 7793 | (char*)&longdouble_size, TCL_LINK_INT|TCL_LINK_READ_ONLY); |
drh | b851b2c | 2005-03-10 14:11:12 +0000 | [diff] [blame] | 7794 | Tcl_LinkVar(interp, "sqlite_sync_count", |
| 7795 | (char*)&sqlite3_sync_count, TCL_LINK_INT); |
| 7796 | Tcl_LinkVar(interp, "sqlite_fullsync_count", |
| 7797 | (char*)&sqlite3_fullsync_count, TCL_LINK_INT); |
drh | d1fa7bc | 2009-01-10 13:24:50 +0000 | [diff] [blame] | 7798 | #if defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_TEST) |
danielk1977 | 33e8903 | 2008-12-17 15:18:17 +0000 | [diff] [blame] | 7799 | Tcl_LinkVar(interp, "sqlite_fts3_enable_parentheses", |
| 7800 | (char*)&sqlite3_fts3_enable_parentheses, TCL_LINK_INT); |
| 7801 | #endif |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 7802 | return TCL_OK; |
| 7803 | } |