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. |
| 15 | ** |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame^] | 16 | ** $Id: test1.c,v 1.270 2007/08/22 20:18:22 drh Exp $ |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 17 | */ |
| 18 | #include "sqliteInt.h" |
| 19 | #include "tcl.h" |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
| 22 | |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 23 | /* |
| 24 | ** This is a copy of the first part of the SqliteDb structure in |
| 25 | ** tclsqlite.c. We need it here so that the get_sqlite_pointer routine |
| 26 | ** can extract the sqlite3* pointer from an existing Tcl SQLite |
| 27 | ** connection. |
| 28 | */ |
| 29 | struct SqliteDb { |
| 30 | sqlite3 *db; |
| 31 | }; |
| 32 | |
| 33 | /* |
drh | a315289 | 2007-05-05 11:48:52 +0000 | [diff] [blame] | 34 | ** Convert text generated by the "%p" conversion format back into |
| 35 | ** a pointer. |
| 36 | */ |
| 37 | static int testHexToInt(int h){ |
| 38 | if( h>='0' && h<='9' ){ |
| 39 | return h - '0'; |
| 40 | }else if( h>='a' && h<='f' ){ |
| 41 | return h - 'a' + 10; |
| 42 | }else{ |
| 43 | assert( h>='A' && h<='F' ); |
| 44 | return h - 'A' + 10; |
| 45 | } |
| 46 | } |
| 47 | void *sqlite3TextToPtr(const char *z){ |
| 48 | void *p; |
| 49 | u64 v; |
| 50 | u32 v2; |
| 51 | if( z[0]=='0' && z[1]=='x' ){ |
| 52 | z += 2; |
| 53 | } |
| 54 | v = 0; |
| 55 | while( *z ){ |
| 56 | v = (v<<4) + testHexToInt(*z); |
| 57 | z++; |
| 58 | } |
| 59 | if( sizeof(p)==sizeof(v) ){ |
| 60 | memcpy(&p, &v, sizeof(p)); |
| 61 | }else{ |
| 62 | assert( sizeof(p)==sizeof(v2) ); |
| 63 | v2 = (u32)v; |
| 64 | memcpy(&p, &v2, sizeof(p)); |
| 65 | } |
| 66 | return p; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | /* |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 71 | ** A TCL command that returns the address of the sqlite* pointer |
| 72 | ** for an sqlite connection instance. Bad things happen if the |
| 73 | ** input is not an sqlite connection. |
| 74 | */ |
| 75 | static int get_sqlite_pointer( |
| 76 | void * clientData, |
| 77 | Tcl_Interp *interp, |
| 78 | int objc, |
| 79 | Tcl_Obj *CONST objv[] |
| 80 | ){ |
| 81 | struct SqliteDb *p; |
| 82 | Tcl_CmdInfo cmdInfo; |
| 83 | char zBuf[100]; |
| 84 | if( objc!=2 ){ |
| 85 | Tcl_WrongNumArgs(interp, 1, objv, "SQLITE-CONNECTION"); |
| 86 | return TCL_ERROR; |
| 87 | } |
| 88 | if( !Tcl_GetCommandInfo(interp, Tcl_GetString(objv[1]), &cmdInfo) ){ |
| 89 | Tcl_AppendResult(interp, "command not found: ", |
| 90 | Tcl_GetString(objv[1]), (char*)0); |
| 91 | return TCL_ERROR; |
| 92 | } |
| 93 | p = (struct SqliteDb*)cmdInfo.objClientData; |
| 94 | sprintf(zBuf, "%p", p->db); |
| 95 | if( strncmp(zBuf,"0x",2) ){ |
| 96 | sprintf(zBuf, "0x%p", p->db); |
| 97 | } |
| 98 | Tcl_AppendResult(interp, zBuf, 0); |
| 99 | return TCL_OK; |
| 100 | } |
| 101 | |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 102 | /* |
| 103 | ** Decode a pointer to an sqlite3 object. |
| 104 | */ |
| 105 | static int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){ |
| 106 | struct SqliteDb *p; |
| 107 | Tcl_CmdInfo cmdInfo; |
| 108 | if( Tcl_GetCommandInfo(interp, zA, &cmdInfo) ){ |
| 109 | p = (struct SqliteDb*)cmdInfo.objClientData; |
| 110 | *ppDb = p->db; |
| 111 | }else{ |
| 112 | *ppDb = (sqlite3*)sqlite3TextToPtr(zA); |
| 113 | } |
| 114 | return TCL_OK; |
| 115 | } |
| 116 | |
| 117 | |
drh | 2e66f0b | 2005-04-28 17:18:48 +0000 | [diff] [blame] | 118 | const char *sqlite3TestErrorName(int rc){ |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 119 | const char *zName = 0; |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 120 | switch( rc & 0xff ){ |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 121 | case SQLITE_OK: zName = "SQLITE_OK"; break; |
| 122 | case SQLITE_ERROR: zName = "SQLITE_ERROR"; break; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 123 | case SQLITE_PERM: zName = "SQLITE_PERM"; break; |
| 124 | case SQLITE_ABORT: zName = "SQLITE_ABORT"; break; |
| 125 | case SQLITE_BUSY: zName = "SQLITE_BUSY"; break; |
| 126 | case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break; |
| 127 | case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break; |
| 128 | case SQLITE_READONLY: zName = "SQLITE_READONLY"; break; |
| 129 | case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break; |
| 130 | case SQLITE_IOERR: zName = "SQLITE_IOERR"; break; |
| 131 | case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 132 | case SQLITE_FULL: zName = "SQLITE_FULL"; break; |
| 133 | case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break; |
| 134 | case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break; |
| 135 | case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break; |
| 136 | case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 137 | case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break; |
| 138 | case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break; |
| 139 | case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break; |
| 140 | case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break; |
| 141 | case SQLITE_AUTH: zName = "SQLITE_AUTH"; break; |
| 142 | case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break; |
| 143 | case SQLITE_RANGE: zName = "SQLITE_RANGE"; break; |
| 144 | case SQLITE_ROW: zName = "SQLITE_ROW"; break; |
| 145 | case SQLITE_DONE: zName = "SQLITE_DONE"; break; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 146 | case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 147 | default: zName = "SQLITE_Unknown"; break; |
| 148 | } |
| 149 | return zName; |
| 150 | } |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 151 | #define t1ErrorName sqlite3TestErrorName |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 152 | |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 153 | /* |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 154 | ** Convert an sqlite3_stmt* into an sqlite3*. This depends on the |
| 155 | ** fact that the sqlite3* is the first field in the Vdbe structure. |
| 156 | */ |
drh | 51942bc | 2005-06-12 22:01:42 +0000 | [diff] [blame] | 157 | #define StmtToDb(X) sqlite3_db_handle(X) |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 158 | |
| 159 | /* |
| 160 | ** Check a return value to make sure it agrees with the results |
| 161 | ** from sqlite3_errcode. |
| 162 | */ |
| 163 | int sqlite3TestErrCode(Tcl_Interp *interp, sqlite3 *db, int rc){ |
| 164 | if( rc!=SQLITE_MISUSE && rc!=SQLITE_OK && sqlite3_errcode(db)!=rc ){ |
| 165 | char zBuf[200]; |
| 166 | int r2 = sqlite3_errcode(db); |
| 167 | sprintf(zBuf, "error code %s (%d) does not match sqlite3_errcode %s (%d)", |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 168 | t1ErrorName(rc), rc, t1ErrorName(r2), r2); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 169 | Tcl_ResetResult(interp); |
| 170 | Tcl_AppendResult(interp, zBuf, 0); |
| 171 | return 1; |
| 172 | } |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | /* |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 177 | ** Decode a pointer to an sqlite3_stmt object. |
| 178 | */ |
| 179 | static int getStmtPointer( |
| 180 | Tcl_Interp *interp, |
| 181 | const char *zArg, |
| 182 | sqlite3_stmt **ppStmt |
| 183 | ){ |
drh | fe63d1c | 2004-09-08 20:13:04 +0000 | [diff] [blame] | 184 | *ppStmt = (sqlite3_stmt*)sqlite3TextToPtr(zArg); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 185 | return TCL_OK; |
| 186 | } |
| 187 | |
| 188 | /* |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 189 | ** Decode a pointer to an sqlite3_stmt object. |
| 190 | */ |
| 191 | static int getFilePointer( |
| 192 | Tcl_Interp *interp, |
| 193 | const char *zArg, |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 194 | sqlite3_file **ppFile |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 195 | ){ |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 196 | *ppFile = (sqlite3_file*)sqlite3TextToPtr(zArg); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 197 | return TCL_OK; |
| 198 | } |
| 199 | |
| 200 | /* |
drh | 7d8085a | 2003-04-26 13:19:38 +0000 | [diff] [blame] | 201 | ** Generate a text representation of a pointer that can be understood |
| 202 | ** by the getDbPointer and getVmPointer routines above. |
| 203 | ** |
| 204 | ** The problem is, on some machines (Solaris) if you do a printf with |
| 205 | ** "%p" you cannot turn around and do a scanf with the same "%p" and |
| 206 | ** get your pointer back. You have to prepend a "0x" before it will |
| 207 | ** work. Or at least that is what is reported to me (drh). But this |
| 208 | ** behavior varies from machine to machine. The solution used her is |
| 209 | ** to test the string right after it is generated to see if it can be |
| 210 | ** understood by scanf, and if not, try prepending an "0x" to see if |
| 211 | ** that helps. If nothing works, a fatal error is generated. |
| 212 | */ |
drh | 64b1bea | 2006-01-15 02:30:57 +0000 | [diff] [blame] | 213 | int sqlite3TestMakePointerStr(Tcl_Interp *interp, char *zPtr, void *p){ |
drh | fe63d1c | 2004-09-08 20:13:04 +0000 | [diff] [blame] | 214 | sqlite3_snprintf(100, zPtr, "%p", p); |
drh | 7d8085a | 2003-04-26 13:19:38 +0000 | [diff] [blame] | 215 | return TCL_OK; |
| 216 | } |
| 217 | |
| 218 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 219 | ** The callback routine for sqlite3_exec_printf(). |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 220 | */ |
| 221 | static int exec_printf_cb(void *pArg, int argc, char **argv, char **name){ |
| 222 | Tcl_DString *str = (Tcl_DString*)pArg; |
| 223 | int i; |
| 224 | |
| 225 | if( Tcl_DStringLength(str)==0 ){ |
| 226 | for(i=0; i<argc; i++){ |
| 227 | Tcl_DStringAppendElement(str, name[i] ? name[i] : "NULL"); |
| 228 | } |
| 229 | } |
| 230 | for(i=0; i<argc; i++){ |
| 231 | Tcl_DStringAppendElement(str, argv[i] ? argv[i] : "NULL"); |
| 232 | } |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | /* |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 237 | ** The I/O tracing callback. |
| 238 | */ |
| 239 | static FILE *iotrace_file = 0; |
| 240 | static void io_trace_callback(const char *zFormat, ...){ |
| 241 | va_list ap; |
| 242 | va_start(ap, zFormat); |
| 243 | vfprintf(iotrace_file, zFormat, ap); |
| 244 | va_end(ap); |
| 245 | fflush(iotrace_file); |
| 246 | } |
| 247 | |
| 248 | /* |
| 249 | ** Usage: io_trace FILENAME |
| 250 | ** |
| 251 | ** Turn I/O tracing on or off. If FILENAME is not an empty string, |
| 252 | ** I/O tracing begins going into FILENAME. If FILENAME is an empty |
| 253 | ** string, I/O tracing is turned off. |
| 254 | */ |
| 255 | static int test_io_trace( |
| 256 | void *NotUsed, |
| 257 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 258 | int argc, /* Number of arguments */ |
| 259 | char **argv /* Text of each argument */ |
| 260 | ){ |
| 261 | if( argc!=2 ){ |
| 262 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 263 | " FILENAME\"", 0); |
| 264 | return TCL_ERROR; |
| 265 | } |
| 266 | if( iotrace_file ){ |
| 267 | if( iotrace_file!=stdout && iotrace_file!=stderr ){ |
| 268 | fclose(iotrace_file); |
| 269 | } |
| 270 | iotrace_file = 0; |
| 271 | sqlite3_io_trace = 0; |
| 272 | } |
| 273 | if( argv[1][0] ){ |
| 274 | if( strcmp(argv[1],"stdout")==0 ){ |
| 275 | iotrace_file = stdout; |
| 276 | }else if( strcmp(argv[1],"stderr")==0 ){ |
| 277 | iotrace_file = stderr; |
| 278 | }else{ |
| 279 | iotrace_file = fopen(argv[1], "w"); |
| 280 | } |
| 281 | sqlite3_io_trace = io_trace_callback; |
| 282 | } |
| 283 | return SQLITE_OK; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 288 | ** Usage: sqlite3_exec_printf DB FORMAT STRING |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 289 | ** |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 290 | ** Invoke the sqlite3_exec_printf() interface using the open database |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 291 | ** DB. The SQL is the string FORMAT. The format string should contain |
| 292 | ** one %s or %q. STRING is the value inserted into %s or %q. |
| 293 | */ |
| 294 | static int test_exec_printf( |
| 295 | void *NotUsed, |
| 296 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 297 | int argc, /* Number of arguments */ |
| 298 | char **argv /* Text of each argument */ |
| 299 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 300 | sqlite3 *db; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 301 | Tcl_DString str; |
| 302 | int rc; |
| 303 | char *zErr = 0; |
drh | 1211de3 | 2004-07-26 12:24:22 +0000 | [diff] [blame] | 304 | char *zSql; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 305 | char zBuf[30]; |
| 306 | if( argc!=4 ){ |
| 307 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 308 | " DB FORMAT STRING", 0); |
| 309 | return TCL_ERROR; |
| 310 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 311 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 312 | Tcl_DStringInit(&str); |
drh | 1211de3 | 2004-07-26 12:24:22 +0000 | [diff] [blame] | 313 | zSql = sqlite3_mprintf(argv[2], argv[3]); |
| 314 | rc = sqlite3_exec(db, zSql, exec_printf_cb, &str, &zErr); |
| 315 | sqlite3_free(zSql); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 316 | sprintf(zBuf, "%d", rc); |
| 317 | Tcl_AppendElement(interp, zBuf); |
| 318 | Tcl_AppendElement(interp, rc==SQLITE_OK ? Tcl_DStringValue(&str) : zErr); |
| 319 | Tcl_DStringFree(&str); |
danielk1977 | 926aab2 | 2006-06-27 07:34:40 +0000 | [diff] [blame] | 320 | if( zErr ) sqlite3_free(zErr); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 321 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 322 | return TCL_OK; |
| 323 | } |
| 324 | |
| 325 | /* |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 326 | ** Usage: db_enter DB |
| 327 | ** db_leave DB |
| 328 | ** |
| 329 | ** Enter or leave the mutex on a database connection. |
| 330 | */ |
| 331 | static int db_enter( |
| 332 | void *NotUsed, |
| 333 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 334 | int argc, /* Number of arguments */ |
| 335 | char **argv /* Text of each argument */ |
| 336 | ){ |
| 337 | sqlite3 *db; |
| 338 | if( argc!=2 ){ |
| 339 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 340 | " DB", 0); |
| 341 | return TCL_ERROR; |
| 342 | } |
| 343 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 344 | sqlite3_mutex_enter(db->mutex); |
| 345 | return TCL_OK; |
| 346 | } |
| 347 | static int db_leave( |
| 348 | void *NotUsed, |
| 349 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 350 | int argc, /* Number of arguments */ |
| 351 | char **argv /* Text of each argument */ |
| 352 | ){ |
| 353 | sqlite3 *db; |
| 354 | if( argc!=2 ){ |
| 355 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 356 | " DB", 0); |
| 357 | return TCL_ERROR; |
| 358 | } |
| 359 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 360 | sqlite3_mutex_leave(db->mutex); |
| 361 | return TCL_OK; |
| 362 | } |
| 363 | |
| 364 | /* |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 365 | ** Usage: sqlite3_exec DB SQL |
| 366 | ** |
| 367 | ** Invoke the sqlite3_exec interface using the open database DB |
| 368 | */ |
| 369 | static int test_exec( |
| 370 | void *NotUsed, |
| 371 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 372 | int argc, /* Number of arguments */ |
| 373 | char **argv /* Text of each argument */ |
| 374 | ){ |
| 375 | sqlite3 *db; |
| 376 | Tcl_DString str; |
| 377 | int rc; |
| 378 | char *zErr = 0; |
drh | 4e5dd85 | 2007-05-15 03:56:49 +0000 | [diff] [blame] | 379 | char *zSql; |
| 380 | int i, j; |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 381 | char zBuf[30]; |
| 382 | if( argc!=3 ){ |
| 383 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 384 | " DB SQL", 0); |
| 385 | return TCL_ERROR; |
| 386 | } |
| 387 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 388 | Tcl_DStringInit(&str); |
drh | 4e5dd85 | 2007-05-15 03:56:49 +0000 | [diff] [blame] | 389 | zSql = sqlite3_mprintf("%s", argv[2]); |
| 390 | for(i=j=0; zSql[i];){ |
| 391 | if( zSql[i]=='%' ){ |
| 392 | zSql[j++] = (testHexToInt(zSql[i+1])<<4) + testHexToInt(zSql[i+2]); |
| 393 | i += 3; |
| 394 | }else{ |
| 395 | zSql[j++] = zSql[i++]; |
| 396 | } |
| 397 | } |
| 398 | zSql[j] = 0; |
| 399 | rc = sqlite3_exec(db, zSql, exec_printf_cb, &str, &zErr); |
| 400 | sqlite3_free(zSql); |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 401 | sprintf(zBuf, "%d", rc); |
| 402 | Tcl_AppendElement(interp, zBuf); |
| 403 | Tcl_AppendElement(interp, rc==SQLITE_OK ? Tcl_DStringValue(&str) : zErr); |
| 404 | Tcl_DStringFree(&str); |
| 405 | if( zErr ) sqlite3_free(zErr); |
| 406 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
| 407 | return TCL_OK; |
| 408 | } |
| 409 | |
| 410 | /* |
| 411 | ** Usage: sqlite3_exec_nr DB SQL |
| 412 | ** |
| 413 | ** Invoke the sqlite3_exec interface using the open database DB. Discard |
| 414 | ** all results |
| 415 | */ |
| 416 | static int test_exec_nr( |
| 417 | void *NotUsed, |
| 418 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 419 | int argc, /* Number of arguments */ |
| 420 | char **argv /* Text of each argument */ |
| 421 | ){ |
| 422 | sqlite3 *db; |
| 423 | int rc; |
| 424 | char *zErr = 0; |
| 425 | if( argc!=3 ){ |
| 426 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 427 | " DB SQL", 0); |
| 428 | return TCL_ERROR; |
| 429 | } |
| 430 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 431 | rc = sqlite3_exec(db, argv[2], 0, 0, &zErr); |
| 432 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
| 433 | return TCL_OK; |
| 434 | } |
| 435 | |
| 436 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 437 | ** Usage: sqlite3_mprintf_z_test SEPARATOR ARG0 ARG1 ... |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 438 | ** |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 439 | ** Test the %z format of sqliteMPrintf(). Use multiple mprintf() calls to |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 440 | ** concatenate arg0 through argn using separator as the separator. |
| 441 | ** Return the result. |
| 442 | */ |
| 443 | static int test_mprintf_z( |
| 444 | void *NotUsed, |
| 445 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 446 | int argc, /* Number of arguments */ |
| 447 | char **argv /* Text of each argument */ |
| 448 | ){ |
| 449 | char *zResult = 0; |
| 450 | int i; |
| 451 | |
| 452 | for(i=2; i<argc; i++){ |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 453 | zResult = sqlite3MPrintf(0, "%z%s%s", zResult, argv[1], argv[i]); |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 454 | } |
| 455 | Tcl_AppendResult(interp, zResult, 0); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 456 | sqlite3_free(zResult); |
drh | d93d8a8 | 2003-06-16 03:08:18 +0000 | [diff] [blame] | 457 | return TCL_OK; |
| 458 | } |
| 459 | |
| 460 | /* |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 461 | ** Usage: sqlite3_mprintf_n_test STRING |
| 462 | ** |
| 463 | ** Test the %n format of sqliteMPrintf(). Return the length of the |
| 464 | ** input string. |
| 465 | */ |
| 466 | static int test_mprintf_n( |
| 467 | void *NotUsed, |
| 468 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 469 | int argc, /* Number of arguments */ |
| 470 | char **argv /* Text of each argument */ |
| 471 | ){ |
| 472 | char *zStr; |
| 473 | int n = 0; |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 474 | zStr = sqlite3MPrintf(0, "%s%n", argv[1], &n); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 475 | sqlite3_free(zStr); |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 476 | Tcl_SetObjResult(interp, Tcl_NewIntObj(n)); |
| 477 | return TCL_OK; |
| 478 | } |
| 479 | |
| 480 | /* |
drh | 6885390 | 2007-05-07 11:24:30 +0000 | [diff] [blame] | 481 | ** Usage: sqlite3_snprintf_int SIZE FORMAT INT |
| 482 | ** |
| 483 | ** Test the of sqlite3_snprintf() routine. SIZE is the size of the |
| 484 | ** output buffer in bytes. The maximum size is 100. FORMAT is the |
| 485 | ** format string. INT is a single integer argument. The FORMAT |
| 486 | ** string must require no more than this one integer argument. If |
| 487 | ** You pass in a format string that requires more than one argument, |
| 488 | ** bad things will happen. |
| 489 | */ |
| 490 | static int test_snprintf_int( |
| 491 | void *NotUsed, |
| 492 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 493 | int argc, /* Number of arguments */ |
| 494 | char **argv /* Text of each argument */ |
| 495 | ){ |
| 496 | char zStr[100]; |
| 497 | int n = atoi(argv[1]); |
drh | 6885390 | 2007-05-07 11:24:30 +0000 | [diff] [blame] | 498 | const char *zFormat = argv[2]; |
| 499 | int a1 = atoi(argv[3]); |
drh | daf276d | 2007-06-15 18:53:14 +0000 | [diff] [blame] | 500 | if( n>sizeof(zStr) ) n = sizeof(zStr); |
drh | 6885390 | 2007-05-07 11:24:30 +0000 | [diff] [blame] | 501 | strcpy(zStr, "abcdefghijklmnopqrstuvwxyz"); |
| 502 | sqlite3_snprintf(n, zStr, zFormat, a1); |
| 503 | Tcl_AppendResult(interp, zStr, 0); |
| 504 | return TCL_OK; |
| 505 | } |
| 506 | |
| 507 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 508 | ** Usage: sqlite3_get_table_printf DB FORMAT STRING |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 509 | ** |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 510 | ** Invoke the sqlite3_get_table_printf() interface using the open database |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 511 | ** DB. The SQL is the string FORMAT. The format string should contain |
| 512 | ** one %s or %q. STRING is the value inserted into %s or %q. |
| 513 | */ |
| 514 | static int test_get_table_printf( |
| 515 | void *NotUsed, |
| 516 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 517 | int argc, /* Number of arguments */ |
| 518 | char **argv /* Text of each argument */ |
| 519 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 520 | sqlite3 *db; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 521 | Tcl_DString str; |
| 522 | int rc; |
| 523 | char *zErr = 0; |
| 524 | int nRow, nCol; |
| 525 | char **aResult; |
| 526 | int i; |
| 527 | char zBuf[30]; |
drh | 1211de3 | 2004-07-26 12:24:22 +0000 | [diff] [blame] | 528 | char *zSql; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 529 | if( argc!=4 ){ |
| 530 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 531 | " DB FORMAT STRING", 0); |
| 532 | return TCL_ERROR; |
| 533 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 534 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 535 | Tcl_DStringInit(&str); |
drh | 1211de3 | 2004-07-26 12:24:22 +0000 | [diff] [blame] | 536 | zSql = sqlite3_mprintf(argv[2],argv[3]); |
| 537 | rc = sqlite3_get_table(db, zSql, &aResult, &nRow, &nCol, &zErr); |
| 538 | sqlite3_free(zSql); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 539 | sprintf(zBuf, "%d", rc); |
| 540 | Tcl_AppendElement(interp, zBuf); |
| 541 | if( rc==SQLITE_OK ){ |
| 542 | sprintf(zBuf, "%d", nRow); |
| 543 | Tcl_AppendElement(interp, zBuf); |
| 544 | sprintf(zBuf, "%d", nCol); |
| 545 | Tcl_AppendElement(interp, zBuf); |
| 546 | for(i=0; i<(nRow+1)*nCol; i++){ |
| 547 | Tcl_AppendElement(interp, aResult[i] ? aResult[i] : "NULL"); |
| 548 | } |
| 549 | }else{ |
| 550 | Tcl_AppendElement(interp, zErr); |
| 551 | } |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 552 | sqlite3_free_table(aResult); |
danielk1977 | 926aab2 | 2006-06-27 07:34:40 +0000 | [diff] [blame] | 553 | if( zErr ) sqlite3_free(zErr); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 554 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 555 | return TCL_OK; |
| 556 | } |
| 557 | |
drh | af9ff33 | 2002-01-16 21:00:27 +0000 | [diff] [blame] | 558 | |
| 559 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 560 | ** Usage: sqlite3_last_insert_rowid DB |
drh | af9ff33 | 2002-01-16 21:00:27 +0000 | [diff] [blame] | 561 | ** |
| 562 | ** Returns the integer ROWID of the most recent insert. |
| 563 | */ |
| 564 | static int test_last_rowid( |
| 565 | void *NotUsed, |
| 566 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 567 | int argc, /* Number of arguments */ |
| 568 | char **argv /* Text of each argument */ |
| 569 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 570 | sqlite3 *db; |
drh | af9ff33 | 2002-01-16 21:00:27 +0000 | [diff] [blame] | 571 | char zBuf[30]; |
| 572 | |
| 573 | if( argc!=2 ){ |
| 574 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB\"", 0); |
| 575 | return TCL_ERROR; |
| 576 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 577 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 578 | sprintf(zBuf, "%lld", sqlite3_last_insert_rowid(db)); |
drh | af9ff33 | 2002-01-16 21:00:27 +0000 | [diff] [blame] | 579 | Tcl_AppendResult(interp, zBuf, 0); |
| 580 | return SQLITE_OK; |
| 581 | } |
| 582 | |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 583 | /* |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 584 | ** Usage: sqlite3_key DB KEY |
| 585 | ** |
| 586 | ** Set the codec key. |
| 587 | */ |
| 588 | static int test_key( |
| 589 | void *NotUsed, |
| 590 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 591 | int argc, /* Number of arguments */ |
| 592 | char **argv /* Text of each argument */ |
| 593 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 594 | sqlite3 *db; |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 595 | const char *zKey; |
| 596 | int nKey; |
| 597 | if( argc!=3 ){ |
| 598 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 599 | " FILENAME\"", 0); |
| 600 | return TCL_ERROR; |
| 601 | } |
| 602 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 603 | zKey = argv[2]; |
| 604 | nKey = strlen(zKey); |
| 605 | #ifdef SQLITE_HAS_CODEC |
| 606 | sqlite3_key(db, zKey, nKey); |
| 607 | #endif |
| 608 | return TCL_OK; |
| 609 | } |
| 610 | |
| 611 | /* |
| 612 | ** Usage: sqlite3_rekey DB KEY |
| 613 | ** |
| 614 | ** Change the codec key. |
| 615 | */ |
| 616 | static int test_rekey( |
| 617 | void *NotUsed, |
| 618 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 619 | int argc, /* Number of arguments */ |
| 620 | char **argv /* Text of each argument */ |
| 621 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 622 | sqlite3 *db; |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 623 | const char *zKey; |
| 624 | int nKey; |
| 625 | if( argc!=3 ){ |
| 626 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 627 | " FILENAME\"", 0); |
| 628 | return TCL_ERROR; |
| 629 | } |
| 630 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 631 | zKey = argv[2]; |
| 632 | nKey = strlen(zKey); |
| 633 | #ifdef SQLITE_HAS_CODEC |
| 634 | sqlite3_rekey(db, zKey, nKey); |
| 635 | #endif |
| 636 | return TCL_OK; |
| 637 | } |
| 638 | |
| 639 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 640 | ** Usage: sqlite3_close DB |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 641 | ** |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 642 | ** Closes the database opened by sqlite3_open. |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 643 | */ |
| 644 | static int sqlite_test_close( |
| 645 | void *NotUsed, |
| 646 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 647 | int argc, /* Number of arguments */ |
| 648 | char **argv /* Text of each argument */ |
| 649 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 650 | sqlite3 *db; |
danielk1977 | 96d81f9 | 2004-06-19 03:33:57 +0000 | [diff] [blame] | 651 | int rc; |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 652 | if( argc!=2 ){ |
| 653 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 654 | " FILENAME\"", 0); |
| 655 | return TCL_ERROR; |
| 656 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 657 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
danielk1977 | 96d81f9 | 2004-06-19 03:33:57 +0000 | [diff] [blame] | 658 | rc = sqlite3_close(db); |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 659 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 660 | return TCL_OK; |
| 661 | } |
| 662 | |
| 663 | /* |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 664 | ** Implementation of the x_coalesce() function. |
| 665 | ** Return the first argument non-NULL argument. |
| 666 | */ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 667 | static void t1_ifnullFunc( |
| 668 | sqlite3_context *context, |
| 669 | int argc, |
| 670 | sqlite3_value **argv |
| 671 | ){ |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 672 | int i; |
| 673 | for(i=0; i<argc; i++){ |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 674 | if( SQLITE_NULL!=sqlite3_value_type(argv[i]) ){ |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 675 | int n = sqlite3_value_bytes(argv[i]); |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 676 | sqlite3_result_text(context, (char*)sqlite3_value_text(argv[i]), |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 677 | n, SQLITE_TRANSIENT); |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 678 | break; |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | /* |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 684 | ** These are test functions. hex8() interprets its argument as |
| 685 | ** UTF8 and returns a hex encoding. hex16le() interprets its argument |
| 686 | ** as UTF16le and returns a hex encoding. |
| 687 | */ |
| 688 | static void hex8Func(sqlite3_context *p, int argc, sqlite3_value **argv){ |
| 689 | const unsigned char *z; |
| 690 | int i; |
| 691 | char zBuf[200]; |
| 692 | z = sqlite3_value_text(argv[0]); |
| 693 | for(i=0; i<sizeof(zBuf)/2 - 2 && z[i]; i++){ |
| 694 | sprintf(&zBuf[i*2], "%02x", z[i]&0xff); |
| 695 | } |
| 696 | zBuf[i*2] = 0; |
| 697 | sqlite3_result_text(p, (char*)zBuf, -1, SQLITE_TRANSIENT); |
| 698 | } |
drh | af30469 | 2007-04-23 23:56:31 +0000 | [diff] [blame] | 699 | #ifndef SQLITE_OMIT_UTF16 |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 700 | static void hex16Func(sqlite3_context *p, int argc, sqlite3_value **argv){ |
| 701 | const unsigned short int *z; |
| 702 | int i; |
| 703 | char zBuf[400]; |
| 704 | z = sqlite3_value_text16(argv[0]); |
| 705 | for(i=0; i<sizeof(zBuf)/4 - 4 && z[i]; i++){ |
| 706 | sprintf(&zBuf[i*4], "%04x", z[i]&0xff); |
| 707 | } |
| 708 | zBuf[i*4] = 0; |
| 709 | sqlite3_result_text(p, (char*)zBuf, -1, SQLITE_TRANSIENT); |
| 710 | } |
drh | af30469 | 2007-04-23 23:56:31 +0000 | [diff] [blame] | 711 | #endif |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 712 | |
| 713 | /* |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 714 | ** A structure into which to accumulate text. |
| 715 | */ |
| 716 | struct dstr { |
| 717 | int nAlloc; /* Space allocated */ |
| 718 | int nUsed; /* Space used */ |
| 719 | char *z; /* The space */ |
| 720 | }; |
| 721 | |
| 722 | /* |
| 723 | ** Append text to a dstr |
| 724 | */ |
| 725 | static void dstrAppend(struct dstr *p, const char *z, int divider){ |
| 726 | int n = strlen(z); |
| 727 | if( p->nUsed + n + 2 > p->nAlloc ){ |
| 728 | char *zNew; |
| 729 | p->nAlloc = p->nAlloc*2 + n + 200; |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 730 | zNew = sqlite3_realloc(p->z, p->nAlloc); |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 731 | if( zNew==0 ){ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 732 | sqlite3_free(p->z); |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 733 | memset(p, 0, sizeof(*p)); |
| 734 | return; |
| 735 | } |
| 736 | p->z = zNew; |
| 737 | } |
| 738 | if( divider && p->nUsed>0 ){ |
| 739 | p->z[p->nUsed++] = divider; |
| 740 | } |
| 741 | memcpy(&p->z[p->nUsed], z, n+1); |
| 742 | p->nUsed += n; |
| 743 | } |
| 744 | |
| 745 | /* |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 746 | ** Invoked for each callback from sqlite3ExecFunc |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 747 | */ |
| 748 | static int execFuncCallback(void *pData, int argc, char **argv, char **NotUsed){ |
| 749 | struct dstr *p = (struct dstr*)pData; |
| 750 | int i; |
| 751 | for(i=0; i<argc; i++){ |
| 752 | if( argv[i]==0 ){ |
| 753 | dstrAppend(p, "NULL", ' '); |
| 754 | }else{ |
| 755 | dstrAppend(p, argv[i], ' '); |
| 756 | } |
| 757 | } |
| 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | /* |
danielk1977 | e35ee19 | 2004-06-26 09:50:11 +0000 | [diff] [blame] | 762 | ** Implementation of the x_sqlite_exec() function. This function takes |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 763 | ** a single argument and attempts to execute that argument as SQL code. |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 764 | ** This is illegal and should set the SQLITE_MISUSE flag on the database. |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 765 | ** |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 766 | ** 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] | 767 | ** from within a function call. |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 768 | ** |
| 769 | ** This routine simulates the effect of having two threads attempt to |
| 770 | ** use the same database at the same time. |
| 771 | */ |
danielk1977 | 51ad0ec | 2004-05-24 12:39:02 +0000 | [diff] [blame] | 772 | static void sqlite3ExecFunc( |
danielk1977 | 0ae8b83 | 2004-05-25 12:05:56 +0000 | [diff] [blame] | 773 | sqlite3_context *context, |
danielk1977 | 51ad0ec | 2004-05-24 12:39:02 +0000 | [diff] [blame] | 774 | int argc, |
| 775 | sqlite3_value **argv |
| 776 | ){ |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 777 | struct dstr x; |
| 778 | memset(&x, 0, sizeof(x)); |
drh | 3752785 | 2006-03-16 16:19:56 +0000 | [diff] [blame] | 779 | (void)sqlite3_exec((sqlite3*)sqlite3_user_data(context), |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 780 | (char*)sqlite3_value_text(argv[0]), |
drh | d1d9fc3 | 2004-01-07 19:24:48 +0000 | [diff] [blame] | 781 | execFuncCallback, &x, 0); |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 782 | sqlite3_result_text(context, x.z, x.nUsed, SQLITE_TRANSIENT); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 783 | sqlite3_free(x.z); |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | /* |
danielk1977 | d726392 | 2007-02-05 14:21:47 +0000 | [diff] [blame] | 787 | ** Implementation of tkt2213func(), a scalar function that takes exactly |
| 788 | ** one argument. It has two interesting features: |
| 789 | ** |
| 790 | ** * It calls sqlite3_value_text() 3 times on the argument sqlite3_value*. |
| 791 | ** If the three pointers returned are not the same an SQL error is raised. |
| 792 | ** |
| 793 | ** * Otherwise it returns a copy of the text representation of it's |
| 794 | ** argument in such a way as the VDBE representation is a Mem* cell |
| 795 | ** with the MEM_Term flag clear. |
| 796 | ** |
| 797 | ** Ticket #2213 can therefore be tested by evaluating the following |
| 798 | ** SQL expression: |
| 799 | ** |
| 800 | ** tkt2213func(tkt2213func('a string')); |
| 801 | */ |
| 802 | static void tkt2213Function( |
| 803 | sqlite3_context *context, |
| 804 | int argc, |
| 805 | sqlite3_value **argv |
| 806 | ){ |
| 807 | int nText; |
| 808 | unsigned char const *zText1; |
| 809 | unsigned char const *zText2; |
| 810 | unsigned char const *zText3; |
| 811 | |
| 812 | nText = sqlite3_value_bytes(argv[0]); |
| 813 | zText1 = sqlite3_value_text(argv[0]); |
| 814 | zText2 = sqlite3_value_text(argv[0]); |
| 815 | zText3 = sqlite3_value_text(argv[0]); |
| 816 | |
| 817 | if( zText1!=zText2 || zText2!=zText3 ){ |
| 818 | sqlite3_result_error(context, "tkt2213 is not fixed", -1); |
| 819 | }else{ |
| 820 | char *zCopy = (char *)sqlite3_malloc(nText); |
| 821 | memcpy(zCopy, zText1, nText); |
| 822 | sqlite3_result_text(context, zCopy, nText, sqlite3_free); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | /* |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 827 | ** The following SQL function takes 4 arguments. The 2nd and |
| 828 | ** 4th argument must be one of these strings: 'text', 'text16', |
| 829 | ** or 'blob' corresponding to API functions |
| 830 | ** |
| 831 | ** sqlite3_value_text() |
| 832 | ** sqlite3_value_text16() |
| 833 | ** sqlite3_value_blob() |
| 834 | ** |
| 835 | ** The third argument is a string, either 'bytes' or 'bytes16' or 'noop', |
| 836 | ** corresponding to APIs: |
| 837 | ** |
| 838 | ** sqlite3_value_bytes() |
| 839 | ** sqlite3_value_bytes16() |
| 840 | ** noop |
| 841 | ** |
| 842 | ** The APIs designated by the 2nd through 4th arguments are applied |
| 843 | ** to the first argument in order. If the pointers returned by the |
| 844 | ** second and fourth are different, this routine returns 1. Otherwise, |
| 845 | ** this routine returns 0. |
| 846 | ** |
| 847 | ** This function is used to test to see when returned pointers from |
| 848 | ** the _text(), _text16() and _blob() APIs become invalidated. |
| 849 | */ |
| 850 | static void ptrChngFunction( |
| 851 | sqlite3_context *context, |
| 852 | int argc, |
| 853 | sqlite3_value **argv |
| 854 | ){ |
| 855 | const void *p1, *p2; |
| 856 | const char *zCmd; |
| 857 | if( argc!=4 ) return; |
| 858 | zCmd = (const char*)sqlite3_value_text(argv[1]); |
| 859 | if( zCmd==0 ) return; |
| 860 | if( strcmp(zCmd,"text")==0 ){ |
| 861 | p1 = (const void*)sqlite3_value_text(argv[0]); |
| 862 | #ifndef SQLITE_OMIT_UTF16 |
| 863 | }else if( strcmp(zCmd, "text16")==0 ){ |
| 864 | p1 = (const void*)sqlite3_value_text16(argv[0]); |
| 865 | #endif |
| 866 | }else if( strcmp(zCmd, "blob")==0 ){ |
| 867 | p1 = (const void*)sqlite3_value_blob(argv[0]); |
| 868 | }else{ |
| 869 | return; |
| 870 | } |
| 871 | zCmd = (const char*)sqlite3_value_text(argv[2]); |
| 872 | if( zCmd==0 ) return; |
| 873 | if( strcmp(zCmd,"bytes")==0 ){ |
| 874 | sqlite3_value_bytes(argv[0]); |
| 875 | #ifndef SQLITE_OMIT_UTF16 |
| 876 | }else if( strcmp(zCmd, "bytes16")==0 ){ |
| 877 | sqlite3_value_bytes16(argv[0]); |
| 878 | #endif |
| 879 | }else if( strcmp(zCmd, "noop")==0 ){ |
| 880 | /* do nothing */ |
| 881 | }else{ |
| 882 | return; |
| 883 | } |
| 884 | zCmd = (const char*)sqlite3_value_text(argv[3]); |
| 885 | if( zCmd==0 ) return; |
| 886 | if( strcmp(zCmd,"text")==0 ){ |
| 887 | p2 = (const void*)sqlite3_value_text(argv[0]); |
| 888 | #ifndef SQLITE_OMIT_UTF16 |
| 889 | }else if( strcmp(zCmd, "text16")==0 ){ |
| 890 | p2 = (const void*)sqlite3_value_text16(argv[0]); |
| 891 | #endif |
| 892 | }else if( strcmp(zCmd, "blob")==0 ){ |
| 893 | p2 = (const void*)sqlite3_value_blob(argv[0]); |
| 894 | }else{ |
| 895 | return; |
| 896 | } |
| 897 | sqlite3_result_int(context, p1!=p2); |
| 898 | } |
| 899 | |
| 900 | |
| 901 | /* |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 902 | ** Usage: sqlite_test_create_function DB |
| 903 | ** |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 904 | ** Call the sqlite3_create_function API on the given database in order |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 905 | ** to create a function named "x_coalesce". This function does the same thing |
| 906 | ** as the "coalesce" function. This function also registers an SQL function |
danielk1977 | e35ee19 | 2004-06-26 09:50:11 +0000 | [diff] [blame] | 907 | ** named "x_sqlite_exec" that invokes sqlite3_exec(). Invoking sqlite3_exec() |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 908 | ** in this way is illegal recursion and should raise an SQLITE_MISUSE error. |
| 909 | ** The effect is similar to trying to use the same database connection from |
| 910 | ** two threads at the same time. |
| 911 | ** |
| 912 | ** The original motivation for this routine was to be able to call the |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 913 | ** sqlite3_create_function function while a query is in progress in order |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 914 | ** to test the SQLITE_MISUSE detection logic. |
| 915 | */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 916 | static int test_create_function( |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 917 | void *NotUsed, |
| 918 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 919 | int argc, /* Number of arguments */ |
| 920 | char **argv /* Text of each argument */ |
| 921 | ){ |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 922 | int rc; |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 923 | sqlite3 *db; |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 924 | extern void Md5_Register(sqlite3*); |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 925 | |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 926 | if( argc!=2 ){ |
| 927 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
danielk1977 | 4397de5 | 2005-01-12 12:44:03 +0000 | [diff] [blame] | 928 | " DB\"", 0); |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 929 | return TCL_ERROR; |
| 930 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 931 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 932 | rc = sqlite3_create_function(db, "x_coalesce", -1, SQLITE_ANY, 0, |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 933 | t1_ifnullFunc, 0, 0); |
drh | 235a818 | 2006-09-13 19:21:28 +0000 | [diff] [blame] | 934 | if( rc==SQLITE_OK ){ |
| 935 | rc = sqlite3_create_function(db, "hex8", 1, SQLITE_ANY, 0, |
| 936 | hex8Func, 0, 0); |
| 937 | } |
drh | af30469 | 2007-04-23 23:56:31 +0000 | [diff] [blame] | 938 | #ifndef SQLITE_OMIT_UTF16 |
drh | 235a818 | 2006-09-13 19:21:28 +0000 | [diff] [blame] | 939 | if( rc==SQLITE_OK ){ |
| 940 | rc = sqlite3_create_function(db, "hex16", 1, SQLITE_ANY, 0, |
| 941 | hex16Func, 0, 0); |
| 942 | } |
drh | af30469 | 2007-04-23 23:56:31 +0000 | [diff] [blame] | 943 | #endif |
danielk1977 | d726392 | 2007-02-05 14:21:47 +0000 | [diff] [blame] | 944 | if( rc==SQLITE_OK ){ |
| 945 | rc = sqlite3_create_function(db, "tkt2213func", 1, SQLITE_ANY, 0, |
| 946 | tkt2213Function, 0, 0); |
| 947 | } |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 948 | if( rc==SQLITE_OK ){ |
| 949 | rc = sqlite3_create_function(db, "pointer_change", 4, SQLITE_ANY, 0, |
| 950 | ptrChngFunction, 0, 0); |
| 951 | } |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 952 | |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 953 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 954 | /* Use the sqlite3_create_function16() API here. Mainly for fun, but also |
| 955 | ** because it is not tested anywhere else. */ |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 956 | if( rc==SQLITE_OK ){ |
danielk1977 | 576ec6b | 2005-01-21 11:55:25 +0000 | [diff] [blame] | 957 | sqlite3_value *pVal; |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame^] | 958 | sqlite3_mutex_enter(db->mutex); |
| 959 | pVal = sqlite3ValueNew(db); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 960 | sqlite3ValueSetStr(pVal, -1, "x_sqlite_exec", SQLITE_UTF8, SQLITE_STATIC); |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame^] | 961 | if( db->mallocFailed ){ |
| 962 | rc = SQLITE_NOMEM; |
| 963 | }else{ |
| 964 | rc = sqlite3_create_function16(db, |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 965 | sqlite3ValueText(pVal, SQLITE_UTF16NATIVE), |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 966 | 1, SQLITE_UTF16, db, sqlite3ExecFunc, 0, 0); |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame^] | 967 | } |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 968 | sqlite3ValueFree(pVal); |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame^] | 969 | sqlite3_mutex_leave(db->mutex); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 970 | } |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 971 | #endif |
| 972 | |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 973 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 974 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0); |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 975 | return TCL_OK; |
| 976 | } |
| 977 | |
| 978 | /* |
| 979 | ** Routines to implement the x_count() aggregate function. |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 980 | ** |
| 981 | ** x_count() counts the number of non-null arguments. But there are |
| 982 | ** some twists for testing purposes. |
| 983 | ** |
| 984 | ** If the argument to x_count() is 40 then a UTF-8 error is reported |
| 985 | ** on the step function. If x_count(41) is seen, then a UTF-16 error |
| 986 | ** is reported on the step function. If the total count is 42, then |
| 987 | ** a UTF-8 error is reported on the finalize function. |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 988 | */ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 989 | typedef struct t1CountCtx t1CountCtx; |
| 990 | struct t1CountCtx { |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 991 | int n; |
| 992 | }; |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 993 | static void t1CountStep( |
| 994 | sqlite3_context *context, |
| 995 | int argc, |
| 996 | sqlite3_value **argv |
| 997 | ){ |
| 998 | t1CountCtx *p; |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 999 | p = sqlite3_aggregate_context(context, sizeof(*p)); |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 1000 | if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0]) ) && p ){ |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1001 | p->n++; |
| 1002 | } |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 1003 | if( argc>0 ){ |
| 1004 | int v = sqlite3_value_int(argv[0]); |
| 1005 | if( v==40 ){ |
| 1006 | sqlite3_result_error(context, "value of 40 handed to x_count", -1); |
danielk1977 | a1686c9 | 2006-01-23 07:52:37 +0000 | [diff] [blame] | 1007 | #ifndef SQLITE_OMIT_UTF16 |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 1008 | }else if( v==41 ){ |
| 1009 | const char zUtf16ErrMsg[] = { 0, 0x61, 0, 0x62, 0, 0x63, 0, 0, 0}; |
| 1010 | sqlite3_result_error16(context, &zUtf16ErrMsg[1-SQLITE_BIGENDIAN], -1); |
danielk1977 | a1686c9 | 2006-01-23 07:52:37 +0000 | [diff] [blame] | 1011 | #endif |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 1012 | } |
| 1013 | } |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1014 | } |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 1015 | static void t1CountFinalize(sqlite3_context *context){ |
| 1016 | t1CountCtx *p; |
drh | 4f26d6c | 2004-05-26 23:25:30 +0000 | [diff] [blame] | 1017 | p = sqlite3_aggregate_context(context, sizeof(*p)); |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 1018 | if( p ){ |
| 1019 | if( p->n==42 ){ |
| 1020 | sqlite3_result_error(context, "x_count totals to 42", -1); |
| 1021 | }else{ |
| 1022 | sqlite3_result_int(context, p ? p->n : 0); |
| 1023 | } |
| 1024 | } |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /* |
| 1028 | ** Usage: sqlite_test_create_aggregate DB |
| 1029 | ** |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1030 | ** Call the sqlite3_create_function API on the given database in order |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1031 | ** to create a function named "x_count". This function does the same thing |
| 1032 | ** as the "md5sum" function. |
| 1033 | ** |
| 1034 | ** The original motivation for this routine was to be able to call the |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1035 | ** sqlite3_create_aggregate function while a query is in progress in order |
drh | 90669c1 | 2006-01-20 15:45:36 +0000 | [diff] [blame] | 1036 | ** to test the SQLITE_MISUSE detection logic. See misuse.test. |
| 1037 | ** |
| 1038 | ** This routine was later extended to test the use of sqlite3_result_error() |
| 1039 | ** within aggregate functions. |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1040 | */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 1041 | static int test_create_aggregate( |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1042 | void *NotUsed, |
| 1043 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1044 | int argc, /* Number of arguments */ |
| 1045 | char **argv /* Text of each argument */ |
| 1046 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1047 | sqlite3 *db; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1048 | int rc; |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1049 | if( argc!=2 ){ |
| 1050 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1051 | " FILENAME\"", 0); |
| 1052 | return TCL_ERROR; |
| 1053 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 1054 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1055 | rc = sqlite3_create_function(db, "x_count", 0, SQLITE_UTF8, 0, 0, |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 1056 | t1CountStep,t1CountFinalize); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1057 | if( rc==SQLITE_OK ){ |
| 1058 | sqlite3_create_function(db, "x_count", 1, SQLITE_UTF8, 0, 0, |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 1059 | t1CountStep,t1CountFinalize); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1060 | } |
| 1061 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1062 | return TCL_OK; |
| 1063 | } |
| 1064 | |
| 1065 | |
drh | 3c23a88 | 2007-01-09 14:01:13 +0000 | [diff] [blame] | 1066 | /* |
| 1067 | ** Usage: printf TEXT |
| 1068 | ** |
| 1069 | ** Send output to printf. Use this rather than puts to merge the output |
| 1070 | ** in the correct sequence with debugging printfs inserted into C code. |
| 1071 | ** Puts uses a separate buffer and debugging statements will be out of |
| 1072 | ** sequence if it is used. |
| 1073 | */ |
| 1074 | static int test_printf( |
| 1075 | void *NotUsed, |
| 1076 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1077 | int argc, /* Number of arguments */ |
| 1078 | char **argv /* Text of each argument */ |
| 1079 | ){ |
| 1080 | if( argc!=2 ){ |
| 1081 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1082 | " TEXT\"", 0); |
| 1083 | return TCL_ERROR; |
| 1084 | } |
| 1085 | printf("%s\n", argv[1]); |
| 1086 | return TCL_OK; |
| 1087 | } |
| 1088 | |
| 1089 | |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 1090 | |
| 1091 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1092 | ** Usage: sqlite3_mprintf_int FORMAT INTEGER INTEGER INTEGER |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1093 | ** |
| 1094 | ** Call mprintf with three integer arguments |
| 1095 | */ |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1096 | static int sqlite3_mprintf_int( |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1097 | void *NotUsed, |
| 1098 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1099 | int argc, /* Number of arguments */ |
| 1100 | char **argv /* Text of each argument */ |
| 1101 | ){ |
| 1102 | int a[3], i; |
| 1103 | char *z; |
| 1104 | if( argc!=5 ){ |
| 1105 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1106 | " FORMAT INT INT INT\"", 0); |
| 1107 | return TCL_ERROR; |
| 1108 | } |
| 1109 | for(i=2; i<5; i++){ |
| 1110 | if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; |
| 1111 | } |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1112 | z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1113 | Tcl_AppendResult(interp, z, 0); |
drh | 3f4fedb | 2004-05-31 19:34:33 +0000 | [diff] [blame] | 1114 | sqlite3_free(z); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1115 | return TCL_OK; |
| 1116 | } |
| 1117 | |
| 1118 | /* |
drh | 9d213ef | 2004-06-30 04:02:11 +0000 | [diff] [blame] | 1119 | ** If zNum represents an integer that will fit in 64-bits, then set |
| 1120 | ** *pValue to that integer and return true. Otherwise return false. |
| 1121 | */ |
| 1122 | static int sqlite3GetInt64(const char *zNum, i64 *pValue){ |
| 1123 | if( sqlite3FitsIn64Bits(zNum) ){ |
drh | b6a9ece | 2007-06-26 00:37:27 +0000 | [diff] [blame] | 1124 | sqlite3Atoi64(zNum, pValue); |
drh | 9d213ef | 2004-06-30 04:02:11 +0000 | [diff] [blame] | 1125 | return 1; |
| 1126 | } |
| 1127 | return 0; |
| 1128 | } |
| 1129 | |
| 1130 | /* |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 1131 | ** Usage: sqlite3_mprintf_int64 FORMAT INTEGER INTEGER INTEGER |
| 1132 | ** |
| 1133 | ** Call mprintf with three 64-bit integer arguments |
| 1134 | */ |
| 1135 | static int sqlite3_mprintf_int64( |
| 1136 | void *NotUsed, |
| 1137 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1138 | int argc, /* Number of arguments */ |
| 1139 | char **argv /* Text of each argument */ |
| 1140 | ){ |
| 1141 | int i; |
| 1142 | sqlite_int64 a[3]; |
| 1143 | char *z; |
| 1144 | if( argc!=5 ){ |
| 1145 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1146 | " FORMAT INT INT INT\"", 0); |
| 1147 | return TCL_ERROR; |
| 1148 | } |
| 1149 | for(i=2; i<5; i++){ |
| 1150 | if( !sqlite3GetInt64(argv[i], &a[i-2]) ){ |
| 1151 | Tcl_AppendResult(interp, "argument is not a valid 64-bit integer", 0); |
| 1152 | return TCL_ERROR; |
| 1153 | } |
| 1154 | } |
| 1155 | z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]); |
| 1156 | Tcl_AppendResult(interp, z, 0); |
| 1157 | sqlite3_free(z); |
| 1158 | return TCL_OK; |
| 1159 | } |
| 1160 | |
| 1161 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1162 | ** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER STRING |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1163 | ** |
| 1164 | ** Call mprintf with two integer arguments and one string argument |
| 1165 | */ |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1166 | static int sqlite3_mprintf_str( |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1167 | void *NotUsed, |
| 1168 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1169 | int argc, /* Number of arguments */ |
| 1170 | char **argv /* Text of each argument */ |
| 1171 | ){ |
| 1172 | int a[3], i; |
| 1173 | char *z; |
chw | f220b24 | 2002-06-16 04:54:28 +0000 | [diff] [blame] | 1174 | if( argc<4 || argc>5 ){ |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1175 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
chw | f220b24 | 2002-06-16 04:54:28 +0000 | [diff] [blame] | 1176 | " FORMAT INT INT ?STRING?\"", 0); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1177 | return TCL_ERROR; |
| 1178 | } |
| 1179 | for(i=2; i<4; i++){ |
| 1180 | if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; |
| 1181 | } |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1182 | 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] | 1183 | Tcl_AppendResult(interp, z, 0); |
drh | 3f4fedb | 2004-05-31 19:34:33 +0000 | [diff] [blame] | 1184 | sqlite3_free(z); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1185 | return TCL_OK; |
| 1186 | } |
| 1187 | |
| 1188 | /* |
drh | b3738b6 | 2007-03-31 15:02:49 +0000 | [diff] [blame] | 1189 | ** Usage: sqlite3_snprintf_str INTEGER FORMAT INTEGER INTEGER STRING |
| 1190 | ** |
| 1191 | ** Call mprintf with two integer arguments and one string argument |
| 1192 | */ |
| 1193 | static int sqlite3_snprintf_str( |
| 1194 | void *NotUsed, |
| 1195 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1196 | int argc, /* Number of arguments */ |
| 1197 | char **argv /* Text of each argument */ |
| 1198 | ){ |
| 1199 | int a[3], i; |
| 1200 | int n; |
| 1201 | char *z; |
| 1202 | if( argc<5 || argc>6 ){ |
| 1203 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1204 | " INT FORMAT INT INT ?STRING?\"", 0); |
| 1205 | return TCL_ERROR; |
| 1206 | } |
| 1207 | if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR; |
| 1208 | if( n<0 ){ |
| 1209 | Tcl_AppendResult(interp, "N must be non-negative", 0); |
| 1210 | return TCL_ERROR; |
| 1211 | } |
| 1212 | for(i=3; i<5; i++){ |
| 1213 | if( Tcl_GetInt(interp, argv[i], &a[i-3]) ) return TCL_ERROR; |
| 1214 | } |
| 1215 | z = sqlite3_malloc( n+1 ); |
| 1216 | sqlite3_snprintf(n, z, argv[2], a[0], a[1], argc>4 ? argv[5] : NULL); |
| 1217 | Tcl_AppendResult(interp, z, 0); |
| 1218 | sqlite3_free(z); |
| 1219 | return TCL_OK; |
| 1220 | } |
| 1221 | |
| 1222 | /* |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 1223 | ** Usage: sqlite3_mprintf_double FORMAT INTEGER INTEGER DOUBLE |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1224 | ** |
| 1225 | ** Call mprintf with two integer arguments and one double argument |
| 1226 | */ |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1227 | static int sqlite3_mprintf_double( |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1228 | void *NotUsed, |
| 1229 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1230 | int argc, /* Number of arguments */ |
| 1231 | char **argv /* Text of each argument */ |
| 1232 | ){ |
| 1233 | int a[3], i; |
| 1234 | double r; |
| 1235 | char *z; |
| 1236 | if( argc!=5 ){ |
| 1237 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 1238 | " FORMAT INT INT DOUBLE\"", 0); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1239 | return TCL_ERROR; |
| 1240 | } |
| 1241 | for(i=2; i<4; i++){ |
| 1242 | if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR; |
| 1243 | } |
| 1244 | if( Tcl_GetDouble(interp, argv[4], &r) ) return TCL_ERROR; |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1245 | z = sqlite3_mprintf(argv[1], a[0], a[1], r); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1246 | Tcl_AppendResult(interp, z, 0); |
drh | 3f4fedb | 2004-05-31 19:34:33 +0000 | [diff] [blame] | 1247 | sqlite3_free(z); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1248 | return TCL_OK; |
| 1249 | } |
| 1250 | |
| 1251 | /* |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 1252 | ** Usage: sqlite3_mprintf_scaled FORMAT DOUBLE DOUBLE |
drh | b621c23 | 2004-02-21 19:41:04 +0000 | [diff] [blame] | 1253 | ** |
| 1254 | ** Call mprintf with a single double argument which is the product of the |
| 1255 | ** two arguments given above. This is used to generate overflow and underflow |
| 1256 | ** doubles to test that they are converted properly. |
| 1257 | */ |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1258 | static int sqlite3_mprintf_scaled( |
drh | b621c23 | 2004-02-21 19:41:04 +0000 | [diff] [blame] | 1259 | void *NotUsed, |
| 1260 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1261 | int argc, /* Number of arguments */ |
| 1262 | char **argv /* Text of each argument */ |
| 1263 | ){ |
| 1264 | int i; |
| 1265 | double r[2]; |
| 1266 | char *z; |
| 1267 | if( argc!=4 ){ |
| 1268 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1269 | " FORMAT DOUBLE DOUBLE\"", 0); |
| 1270 | return TCL_ERROR; |
| 1271 | } |
| 1272 | for(i=2; i<4; i++){ |
| 1273 | if( Tcl_GetDouble(interp, argv[i], &r[i-2]) ) return TCL_ERROR; |
| 1274 | } |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1275 | z = sqlite3_mprintf(argv[1], r[0]*r[1]); |
drh | b621c23 | 2004-02-21 19:41:04 +0000 | [diff] [blame] | 1276 | Tcl_AppendResult(interp, z, 0); |
drh | 3f4fedb | 2004-05-31 19:34:33 +0000 | [diff] [blame] | 1277 | sqlite3_free(z); |
drh | b621c23 | 2004-02-21 19:41:04 +0000 | [diff] [blame] | 1278 | return TCL_OK; |
| 1279 | } |
| 1280 | |
| 1281 | /* |
drh | e29b1a0 | 2004-07-17 21:56:09 +0000 | [diff] [blame] | 1282 | ** Usage: sqlite3_mprintf_stronly FORMAT STRING |
| 1283 | ** |
| 1284 | ** Call mprintf with a single double argument which is the product of the |
| 1285 | ** two arguments given above. This is used to generate overflow and underflow |
| 1286 | ** doubles to test that they are converted properly. |
| 1287 | */ |
| 1288 | static int sqlite3_mprintf_stronly( |
| 1289 | void *NotUsed, |
| 1290 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1291 | int argc, /* Number of arguments */ |
| 1292 | char **argv /* Text of each argument */ |
| 1293 | ){ |
| 1294 | char *z; |
| 1295 | if( argc!=3 ){ |
| 1296 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1297 | " FORMAT STRING\"", 0); |
| 1298 | return TCL_ERROR; |
| 1299 | } |
| 1300 | z = sqlite3_mprintf(argv[1], argv[2]); |
| 1301 | Tcl_AppendResult(interp, z, 0); |
| 1302 | sqlite3_free(z); |
| 1303 | return TCL_OK; |
| 1304 | } |
| 1305 | |
| 1306 | /* |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 1307 | ** Usage: sqlite3_mprintf_hexdouble FORMAT HEX |
| 1308 | ** |
| 1309 | ** Call mprintf with a single double argument which is derived from the |
| 1310 | ** hexadecimal encoding of an IEEE double. |
| 1311 | */ |
| 1312 | static int sqlite3_mprintf_hexdouble( |
| 1313 | void *NotUsed, |
| 1314 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1315 | int argc, /* Number of arguments */ |
| 1316 | char **argv /* Text of each argument */ |
| 1317 | ){ |
| 1318 | char *z; |
| 1319 | double r; |
| 1320 | unsigned x1, x2; |
| 1321 | long long unsigned d; |
| 1322 | if( argc!=3 ){ |
| 1323 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1324 | " FORMAT STRING\"", 0); |
| 1325 | return TCL_ERROR; |
| 1326 | } |
| 1327 | if( sscanf(argv[2], "%08x%08x", &x2, &x1)!=2 ){ |
| 1328 | Tcl_AppendResult(interp, "2nd argument should be 16-characters of hex", 0); |
| 1329 | return TCL_ERROR; |
| 1330 | } |
| 1331 | d = x2; |
| 1332 | d = (d<<32) + x1; |
| 1333 | memcpy(&r, &d, sizeof(r)); |
| 1334 | z = sqlite3_mprintf(argv[1], r); |
| 1335 | Tcl_AppendResult(interp, z, 0); |
| 1336 | sqlite3_free(z); |
| 1337 | return TCL_OK; |
| 1338 | } |
| 1339 | |
| 1340 | /* |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 1341 | ** Usage: sqlite3_enable_shared_cache BOOLEAN |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1342 | ** |
| 1343 | */ |
drh | 6f7adc8 | 2006-01-11 21:41:20 +0000 | [diff] [blame] | 1344 | #if !defined(SQLITE_OMIT_SHARED_CACHE) |
| 1345 | static int test_enable_shared( |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 1346 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1347 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1348 | int objc, /* Number of arguments */ |
| 1349 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1350 | ){ |
| 1351 | int rc; |
| 1352 | int enable; |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 1353 | int ret = 0; |
drh | e53831d | 2007-08-17 01:14:38 +0000 | [diff] [blame] | 1354 | extern int sqlite3SharedCacheEnabled; |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1355 | |
| 1356 | if( objc!=2 ){ |
| 1357 | Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN"); |
| 1358 | return TCL_ERROR; |
| 1359 | } |
| 1360 | if( Tcl_GetBooleanFromObj(interp, objv[1], &enable) ){ |
| 1361 | return TCL_ERROR; |
| 1362 | } |
drh | e53831d | 2007-08-17 01:14:38 +0000 | [diff] [blame] | 1363 | ret = sqlite3SharedCacheEnabled; |
drh | 6f7adc8 | 2006-01-11 21:41:20 +0000 | [diff] [blame] | 1364 | rc = sqlite3_enable_shared_cache(enable); |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1365 | if( rc!=SQLITE_OK ){ |
| 1366 | Tcl_SetResult(interp, (char *)sqlite3ErrStr(rc), TCL_STATIC); |
| 1367 | return TCL_ERROR; |
| 1368 | } |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 1369 | Tcl_SetObjResult(interp, Tcl_NewBooleanObj(ret)); |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1370 | return TCL_OK; |
| 1371 | } |
| 1372 | #endif |
| 1373 | |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 1374 | |
| 1375 | |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 1376 | /* |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 1377 | ** Usage: sqlite3_extended_result_codes DB BOOLEAN |
| 1378 | ** |
| 1379 | */ |
| 1380 | static int test_extended_result_codes( |
| 1381 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 1382 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1383 | int objc, /* Number of arguments */ |
| 1384 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1385 | ){ |
| 1386 | int enable; |
| 1387 | sqlite3 *db; |
| 1388 | |
| 1389 | if( objc!=3 ){ |
| 1390 | Tcl_WrongNumArgs(interp, 1, objv, "DB BOOLEAN"); |
| 1391 | return TCL_ERROR; |
| 1392 | } |
| 1393 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 1394 | if( Tcl_GetBooleanFromObj(interp, objv[2], &enable) ) return TCL_ERROR; |
| 1395 | sqlite3_extended_result_codes(db, enable); |
| 1396 | return TCL_OK; |
| 1397 | } |
| 1398 | |
| 1399 | /* |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 1400 | ** Usage: sqlite3_libversion_number |
| 1401 | ** |
| 1402 | */ |
| 1403 | static int test_libversion_number( |
| 1404 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 1405 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1406 | int objc, /* Number of arguments */ |
| 1407 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1408 | ){ |
| 1409 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_libversion_number())); |
| 1410 | return TCL_OK; |
| 1411 | } |
| 1412 | |
| 1413 | /* |
danielk1977 | deb802c | 2006-02-09 13:43:28 +0000 | [diff] [blame] | 1414 | ** Usage: sqlite3_table_column_metadata DB dbname tblname colname |
| 1415 | ** |
| 1416 | */ |
| 1417 | #ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 1418 | static int test_table_column_metadata( |
| 1419 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 1420 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1421 | int objc, /* Number of arguments */ |
| 1422 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1423 | ){ |
| 1424 | sqlite3 *db; |
| 1425 | const char *zDb; |
| 1426 | const char *zTbl; |
| 1427 | const char *zCol; |
| 1428 | int rc; |
| 1429 | Tcl_Obj *pRet; |
| 1430 | |
| 1431 | const char *zDatatype; |
| 1432 | const char *zCollseq; |
| 1433 | int notnull; |
| 1434 | int primarykey; |
| 1435 | int autoincrement; |
| 1436 | |
| 1437 | if( objc!=5 ){ |
| 1438 | Tcl_WrongNumArgs(interp, 1, objv, "DB dbname tblname colname"); |
| 1439 | return TCL_ERROR; |
| 1440 | } |
| 1441 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 1442 | zDb = Tcl_GetString(objv[2]); |
| 1443 | zTbl = Tcl_GetString(objv[3]); |
| 1444 | zCol = Tcl_GetString(objv[4]); |
| 1445 | |
| 1446 | if( strlen(zDb)==0 ) zDb = 0; |
| 1447 | |
| 1448 | rc = sqlite3_table_column_metadata(db, zDb, zTbl, zCol, |
| 1449 | &zDatatype, &zCollseq, ¬null, &primarykey, &autoincrement); |
| 1450 | |
| 1451 | if( rc!=SQLITE_OK ){ |
| 1452 | Tcl_AppendResult(interp, sqlite3_errmsg(db), 0); |
| 1453 | return TCL_ERROR; |
| 1454 | } |
| 1455 | |
| 1456 | pRet = Tcl_NewObj(); |
| 1457 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zDatatype, -1)); |
| 1458 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zCollseq, -1)); |
| 1459 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(notnull)); |
| 1460 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(primarykey)); |
| 1461 | Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(autoincrement)); |
| 1462 | Tcl_SetObjResult(interp, pRet); |
| 1463 | |
| 1464 | return TCL_OK; |
| 1465 | } |
| 1466 | #endif |
| 1467 | |
danielk1977 | dcbb5d3 | 2007-05-04 18:36:44 +0000 | [diff] [blame] | 1468 | #ifndef SQLITE_OMIT_INCRBLOB |
| 1469 | |
| 1470 | /* |
| 1471 | ** sqlite3_blob_read CHANNEL OFFSET N |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 1472 | ** |
| 1473 | ** This command is used to test the sqlite3_blob_read() in ways that |
| 1474 | ** the Tcl channel interface does not. The first argument should |
| 1475 | ** be the name of a valid channel created by the [incrblob] method |
| 1476 | ** of a database handle. This function calls sqlite3_blob_read() |
| 1477 | ** to read N bytes from offset OFFSET from the underlying SQLite |
| 1478 | ** blob handle. |
| 1479 | ** |
| 1480 | ** On success, a byte-array object containing the read data is |
| 1481 | ** returned. On failure, the interpreter result is set to the |
| 1482 | ** text representation of the returned error code (i.e. "SQLITE_NOMEM") |
| 1483 | ** and a Tcl exception is thrown. |
danielk1977 | dcbb5d3 | 2007-05-04 18:36:44 +0000 | [diff] [blame] | 1484 | */ |
| 1485 | static int test_blob_read( |
| 1486 | ClientData clientData, /* Not used */ |
| 1487 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1488 | int objc, /* Number of arguments */ |
| 1489 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1490 | ){ |
| 1491 | Tcl_Channel channel; |
| 1492 | ClientData instanceData; |
| 1493 | sqlite3_blob *pBlob; |
| 1494 | int notUsed; |
| 1495 | int nByte; |
| 1496 | int iOffset; |
| 1497 | unsigned char *zBuf; |
| 1498 | int rc; |
| 1499 | |
| 1500 | if( objc!=4 ){ |
| 1501 | Tcl_WrongNumArgs(interp, 1, objv, "CHANNEL OFFSET N"); |
| 1502 | return TCL_ERROR; |
| 1503 | } |
| 1504 | |
| 1505 | channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), ¬Used); |
| 1506 | if( !channel |
| 1507 | || TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &iOffset) |
| 1508 | || TCL_OK!=Tcl_GetIntFromObj(interp, objv[3], &nByte) |
| 1509 | || nByte<0 || iOffset<0 |
| 1510 | ){ |
| 1511 | return TCL_ERROR; |
| 1512 | } |
| 1513 | |
| 1514 | instanceData = Tcl_GetChannelInstanceData(channel); |
| 1515 | pBlob = *((sqlite3_blob **)instanceData); |
| 1516 | |
| 1517 | zBuf = (unsigned char *)Tcl_Alloc(nByte); |
| 1518 | rc = sqlite3_blob_read(pBlob, zBuf, nByte, iOffset); |
| 1519 | if( rc==SQLITE_OK ){ |
| 1520 | Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(zBuf, nByte)); |
| 1521 | }else{ |
| 1522 | Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE); |
| 1523 | } |
| 1524 | Tcl_Free((char *)zBuf); |
| 1525 | |
| 1526 | return (rc==SQLITE_OK ? TCL_OK : TCL_ERROR); |
| 1527 | } |
| 1528 | |
| 1529 | /* |
| 1530 | ** sqlite3_blob_write CHANNEL OFFSET DATA |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 1531 | ** |
| 1532 | ** This command is used to test the sqlite3_blob_write() in ways that |
| 1533 | ** the Tcl channel interface does not. The first argument should |
| 1534 | ** be the name of a valid channel created by the [incrblob] method |
| 1535 | ** of a database handle. This function calls sqlite3_blob_write() |
| 1536 | ** to write the DATA byte-array to the underlying SQLite blob handle. |
| 1537 | ** at offset OFFSET. |
| 1538 | ** |
| 1539 | ** On success, an empty string is returned. On failure, the interpreter |
| 1540 | ** result is set to the text representation of the returned error code |
| 1541 | ** (i.e. "SQLITE_NOMEM") and a Tcl exception is thrown. |
danielk1977 | dcbb5d3 | 2007-05-04 18:36:44 +0000 | [diff] [blame] | 1542 | */ |
| 1543 | static int test_blob_write( |
| 1544 | ClientData clientData, /* Not used */ |
| 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 | Tcl_Channel channel; |
| 1550 | ClientData instanceData; |
| 1551 | sqlite3_blob *pBlob; |
| 1552 | int notUsed; |
| 1553 | int iOffset; |
| 1554 | int rc; |
| 1555 | |
| 1556 | unsigned char *zBuf; |
| 1557 | int nBuf; |
| 1558 | |
| 1559 | if( objc!=4 ){ |
| 1560 | Tcl_WrongNumArgs(interp, 1, objv, "CHANNEL OFFSET DATA"); |
| 1561 | return TCL_ERROR; |
| 1562 | } |
| 1563 | |
| 1564 | channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), ¬Used); |
| 1565 | if( !channel |
| 1566 | || TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &iOffset) |
| 1567 | || iOffset<0 |
| 1568 | ){ |
| 1569 | return TCL_ERROR; |
| 1570 | } |
| 1571 | |
| 1572 | instanceData = Tcl_GetChannelInstanceData(channel); |
| 1573 | pBlob = *((sqlite3_blob **)instanceData); |
| 1574 | |
| 1575 | zBuf = Tcl_GetByteArrayFromObj(objv[3], &nBuf); |
| 1576 | rc = sqlite3_blob_write(pBlob, zBuf, nBuf, iOffset); |
| 1577 | if( rc!=SQLITE_OK ){ |
| 1578 | Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE); |
| 1579 | } |
| 1580 | |
| 1581 | return (rc==SQLITE_OK ? TCL_OK : TCL_ERROR); |
| 1582 | } |
| 1583 | #endif |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 1584 | |
danielk1977 | deb802c | 2006-02-09 13:43:28 +0000 | [diff] [blame] | 1585 | /* |
danielk1977 | a393c03 | 2007-05-07 14:58:53 +0000 | [diff] [blame] | 1586 | ** Usage: sqlite3_create_collation_v2 DB-HANDLE NAME CMP-PROC DEL-PROC |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 1587 | ** |
| 1588 | ** This Tcl proc is used for testing the experimental |
danielk1977 | a393c03 | 2007-05-07 14:58:53 +0000 | [diff] [blame] | 1589 | ** sqlite3_create_collation_v2() interface. |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 1590 | */ |
| 1591 | struct TestCollationX { |
| 1592 | Tcl_Interp *interp; |
| 1593 | Tcl_Obj *pCmp; |
| 1594 | Tcl_Obj *pDel; |
| 1595 | }; |
| 1596 | typedef struct TestCollationX TestCollationX; |
| 1597 | static void testCreateCollationDel(void *pCtx){ |
| 1598 | TestCollationX *p = (TestCollationX *)pCtx; |
| 1599 | |
| 1600 | int rc = Tcl_EvalObjEx(p->interp, p->pDel, TCL_EVAL_DIRECT|TCL_EVAL_GLOBAL); |
| 1601 | if( rc!=TCL_OK ){ |
| 1602 | Tcl_BackgroundError(p->interp); |
| 1603 | } |
| 1604 | |
| 1605 | Tcl_DecrRefCount(p->pCmp); |
| 1606 | Tcl_DecrRefCount(p->pDel); |
| 1607 | sqlite3_free((void *)p); |
| 1608 | } |
| 1609 | static int testCreateCollationCmp( |
| 1610 | void *pCtx, |
| 1611 | int nLeft, |
| 1612 | const void *zLeft, |
| 1613 | int nRight, |
| 1614 | const void *zRight |
| 1615 | ){ |
| 1616 | TestCollationX *p = (TestCollationX *)pCtx; |
| 1617 | Tcl_Obj *pScript = Tcl_DuplicateObj(p->pCmp); |
| 1618 | int iRes = 0; |
| 1619 | |
| 1620 | Tcl_IncrRefCount(pScript); |
| 1621 | Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj((char *)zLeft, nLeft)); |
| 1622 | Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj((char *)zRight,nRight)); |
| 1623 | |
| 1624 | if( TCL_OK!=Tcl_EvalObjEx(p->interp, pScript, TCL_EVAL_DIRECT|TCL_EVAL_GLOBAL) |
| 1625 | || TCL_OK!=Tcl_GetIntFromObj(p->interp, Tcl_GetObjResult(p->interp), &iRes) |
| 1626 | ){ |
| 1627 | Tcl_BackgroundError(p->interp); |
| 1628 | } |
| 1629 | Tcl_DecrRefCount(pScript); |
| 1630 | |
| 1631 | return iRes; |
| 1632 | } |
danielk1977 | a393c03 | 2007-05-07 14:58:53 +0000 | [diff] [blame] | 1633 | static int test_create_collation_v2( |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 1634 | ClientData clientData, /* Not used */ |
| 1635 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1636 | int objc, /* Number of arguments */ |
| 1637 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1638 | ){ |
| 1639 | TestCollationX *p; |
| 1640 | sqlite3 *db; |
| 1641 | |
| 1642 | if( objc!=5 ){ |
| 1643 | Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE NAME CMP-PROC DEL-PROC"); |
| 1644 | return TCL_ERROR; |
| 1645 | } |
| 1646 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 1647 | |
| 1648 | p = (TestCollationX *)sqlite3_malloc(sizeof(TestCollationX)); |
| 1649 | p->pCmp = objv[3]; |
| 1650 | p->pDel = objv[4]; |
| 1651 | p->interp = interp; |
| 1652 | Tcl_IncrRefCount(p->pCmp); |
| 1653 | Tcl_IncrRefCount(p->pDel); |
| 1654 | |
danielk1977 | a393c03 | 2007-05-07 14:58:53 +0000 | [diff] [blame] | 1655 | sqlite3_create_collation_v2(db, Tcl_GetString(objv[2]), SQLITE_UTF8, |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 1656 | (void *)p, testCreateCollationCmp, testCreateCollationDel |
| 1657 | ); |
| 1658 | return TCL_OK; |
| 1659 | } |
| 1660 | |
| 1661 | /* |
danielk1977 | 69e777f | 2006-06-14 10:38:02 +0000 | [diff] [blame] | 1662 | ** Usage: sqlite3_load_extension DB-HANDLE FILE ?PROC? |
| 1663 | */ |
| 1664 | static int test_load_extension( |
| 1665 | ClientData clientData, /* Not used */ |
| 1666 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1667 | int objc, /* Number of arguments */ |
| 1668 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1669 | ){ |
| 1670 | Tcl_CmdInfo cmdInfo; |
| 1671 | sqlite3 *db; |
| 1672 | int rc; |
| 1673 | char *zDb; |
| 1674 | char *zFile; |
| 1675 | char *zProc = 0; |
| 1676 | char *zErr = 0; |
| 1677 | |
| 1678 | if( objc!=4 && objc!=3 ){ |
| 1679 | Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE FILE ?PROC?"); |
| 1680 | return TCL_ERROR; |
| 1681 | } |
| 1682 | zDb = Tcl_GetString(objv[1]); |
| 1683 | zFile = Tcl_GetString(objv[2]); |
| 1684 | if( objc==4 ){ |
| 1685 | zProc = Tcl_GetString(objv[3]); |
| 1686 | } |
| 1687 | |
| 1688 | /* Extract the C database handle from the Tcl command name */ |
| 1689 | if( !Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){ |
| 1690 | Tcl_AppendResult(interp, "command not found: ", zDb, (char*)0); |
| 1691 | return TCL_ERROR; |
| 1692 | } |
| 1693 | db = ((struct SqliteDb*)cmdInfo.objClientData)->db; |
| 1694 | assert(db); |
| 1695 | |
| 1696 | /* Call the underlying C function. If an error occurs, set rc to |
| 1697 | ** TCL_ERROR and load any error string into the interpreter. If no |
| 1698 | ** error occurs, set rc to TCL_OK. |
| 1699 | */ |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 1700 | #ifdef SQLITE_OMIT_LOAD_EXTENSION |
| 1701 | rc = SQLITE_ERROR; |
| 1702 | zErr = sqlite3_mprintf("this build omits sqlite3_load_extension()"); |
| 1703 | #else |
danielk1977 | 69e777f | 2006-06-14 10:38:02 +0000 | [diff] [blame] | 1704 | rc = sqlite3_load_extension(db, zFile, zProc, &zErr); |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 1705 | #endif |
danielk1977 | 69e777f | 2006-06-14 10:38:02 +0000 | [diff] [blame] | 1706 | if( rc!=SQLITE_OK ){ |
| 1707 | Tcl_SetResult(interp, zErr ? zErr : "", TCL_VOLATILE); |
| 1708 | rc = TCL_ERROR; |
| 1709 | }else{ |
| 1710 | rc = TCL_OK; |
| 1711 | } |
| 1712 | sqlite3_free(zErr); |
| 1713 | |
| 1714 | return rc; |
| 1715 | } |
| 1716 | |
| 1717 | /* |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 1718 | ** Usage: sqlite3_enable_load_extension DB-HANDLE ONOFF |
| 1719 | */ |
| 1720 | static int test_enable_load( |
| 1721 | ClientData clientData, /* Not used */ |
| 1722 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1723 | int objc, /* Number of arguments */ |
| 1724 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 1725 | ){ |
| 1726 | Tcl_CmdInfo cmdInfo; |
| 1727 | sqlite3 *db; |
| 1728 | char *zDb; |
| 1729 | int onoff; |
| 1730 | |
| 1731 | if( objc!=3 ){ |
| 1732 | Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE ONOFF"); |
| 1733 | return TCL_ERROR; |
| 1734 | } |
| 1735 | zDb = Tcl_GetString(objv[1]); |
| 1736 | |
| 1737 | /* Extract the C database handle from the Tcl command name */ |
| 1738 | if( !Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){ |
| 1739 | Tcl_AppendResult(interp, "command not found: ", zDb, (char*)0); |
| 1740 | return TCL_ERROR; |
| 1741 | } |
| 1742 | db = ((struct SqliteDb*)cmdInfo.objClientData)->db; |
| 1743 | assert(db); |
| 1744 | |
| 1745 | /* Get the onoff parameter */ |
| 1746 | if( Tcl_GetBooleanFromObj(interp, objv[2], &onoff) ){ |
| 1747 | return TCL_ERROR; |
| 1748 | } |
| 1749 | |
| 1750 | #ifdef SQLITE_OMIT_LOAD_EXTENSION |
| 1751 | Tcl_AppendResult(interp, "this build omits sqlite3_load_extension()"); |
| 1752 | return TCL_ERROR; |
| 1753 | #else |
| 1754 | sqlite3_enable_load_extension(db, onoff); |
| 1755 | return TCL_OK; |
| 1756 | #endif |
| 1757 | } |
| 1758 | |
| 1759 | /* |
drh | 28b4e48 | 2002-03-11 02:06:13 +0000 | [diff] [blame] | 1760 | ** Usage: sqlite_abort |
| 1761 | ** |
| 1762 | ** Shutdown the process immediately. This is not a clean shutdown. |
| 1763 | ** This command is used to test the recoverability of a database in |
| 1764 | ** the event of a program crash. |
| 1765 | */ |
| 1766 | static int sqlite_abort( |
| 1767 | void *NotUsed, |
| 1768 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1769 | int argc, /* Number of arguments */ |
| 1770 | char **argv /* Text of each argument */ |
| 1771 | ){ |
| 1772 | assert( interp==0 ); /* This will always fail */ |
| 1773 | return TCL_OK; |
| 1774 | } |
| 1775 | |
| 1776 | /* |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 1777 | ** The following routine is a user-defined SQL function whose purpose |
| 1778 | ** is to test the sqlite_set_result() API. |
| 1779 | */ |
danielk1977 | 0ae8b83 | 2004-05-25 12:05:56 +0000 | [diff] [blame] | 1780 | static void testFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 1781 | while( argc>=2 ){ |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 1782 | const char *zArg0 = (char*)sqlite3_value_text(argv[0]); |
danielk1977 | 6d88bad | 2004-05-27 14:23:36 +0000 | [diff] [blame] | 1783 | if( zArg0 ){ |
| 1784 | if( 0==sqlite3StrICmp(zArg0, "int") ){ |
| 1785 | sqlite3_result_int(context, sqlite3_value_int(argv[1])); |
| 1786 | }else if( sqlite3StrICmp(zArg0,"int64")==0 ){ |
| 1787 | sqlite3_result_int64(context, sqlite3_value_int64(argv[1])); |
| 1788 | }else if( sqlite3StrICmp(zArg0,"string")==0 ){ |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 1789 | sqlite3_result_text(context, (char*)sqlite3_value_text(argv[1]), -1, |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 1790 | SQLITE_TRANSIENT); |
danielk1977 | 6d88bad | 2004-05-27 14:23:36 +0000 | [diff] [blame] | 1791 | }else if( sqlite3StrICmp(zArg0,"double")==0 ){ |
| 1792 | sqlite3_result_double(context, sqlite3_value_double(argv[1])); |
| 1793 | }else if( sqlite3StrICmp(zArg0,"null")==0 ){ |
| 1794 | sqlite3_result_null(context); |
| 1795 | }else if( sqlite3StrICmp(zArg0,"value")==0 ){ |
| 1796 | sqlite3_result_value(context, argv[sqlite3_value_int(argv[1])]); |
| 1797 | }else{ |
| 1798 | goto error_out; |
| 1799 | } |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 1800 | }else{ |
danielk1977 | 6d88bad | 2004-05-27 14:23:36 +0000 | [diff] [blame] | 1801 | goto error_out; |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 1802 | } |
| 1803 | argc -= 2; |
| 1804 | argv += 2; |
| 1805 | } |
danielk1977 | 6d88bad | 2004-05-27 14:23:36 +0000 | [diff] [blame] | 1806 | return; |
| 1807 | |
| 1808 | error_out: |
| 1809 | sqlite3_result_error(context,"first argument should be one of: " |
| 1810 | "int int64 string double null value", -1); |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | /* |
| 1814 | ** Usage: sqlite_register_test_function DB NAME |
| 1815 | ** |
| 1816 | ** Register the test SQL function on the database DB under the name NAME. |
| 1817 | */ |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 1818 | static int test_register_func( |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 1819 | void *NotUsed, |
| 1820 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1821 | int argc, /* Number of arguments */ |
| 1822 | char **argv /* Text of each argument */ |
| 1823 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 1824 | sqlite3 *db; |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 1825 | int rc; |
| 1826 | if( argc!=3 ){ |
| 1827 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 1828 | " DB FUNCTION-NAME", 0); |
| 1829 | return TCL_ERROR; |
| 1830 | } |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 1831 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
danielk1977 | f9d64d2 | 2004-06-19 08:18:07 +0000 | [diff] [blame] | 1832 | rc = sqlite3_create_function(db, argv[2], -1, SQLITE_UTF8, 0, |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 1833 | testFunc, 0, 0); |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 1834 | if( rc!=0 ){ |
danielk1977 | f20b21c | 2004-05-31 23:56:42 +0000 | [diff] [blame] | 1835 | Tcl_AppendResult(interp, sqlite3ErrStr(rc), 0); |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 1836 | return TCL_ERROR; |
| 1837 | } |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 1838 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
drh | 6cbe1f1 | 2002-07-01 00:31:36 +0000 | [diff] [blame] | 1839 | return TCL_OK; |
| 1840 | } |
| 1841 | |
| 1842 | /* |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 1843 | ** Usage: sqlite3_finalize STMT |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 1844 | ** |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 1845 | ** Finalize a statement handle. |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 1846 | */ |
| 1847 | static int test_finalize( |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 1848 | void * clientData, |
| 1849 | Tcl_Interp *interp, |
| 1850 | int objc, |
| 1851 | Tcl_Obj *CONST objv[] |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 1852 | ){ |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 1853 | sqlite3_stmt *pStmt; |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 1854 | int rc; |
drh | dddb2f2 | 2007-01-03 23:37:28 +0000 | [diff] [blame] | 1855 | sqlite3 *db = 0; |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 1856 | |
| 1857 | if( objc!=2 ){ |
| 1858 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 1859 | Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0); |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 1860 | return TCL_ERROR; |
| 1861 | } |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 1862 | |
| 1863 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 1864 | |
danielk1977 | 4397de5 | 2005-01-12 12:44:03 +0000 | [diff] [blame] | 1865 | if( pStmt ){ |
| 1866 | db = StmtToDb(pStmt); |
| 1867 | } |
danielk1977 | fc57d7b | 2004-05-26 02:04:57 +0000 | [diff] [blame] | 1868 | rc = sqlite3_finalize(pStmt); |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 1869 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 4397de5 | 2005-01-12 12:44:03 +0000 | [diff] [blame] | 1870 | if( db && sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 1871 | return TCL_OK; |
| 1872 | } |
| 1873 | |
| 1874 | /* |
| 1875 | ** Usage: sqlite3_reset STMT |
| 1876 | ** |
danielk1977 | 261919c | 2005-12-06 12:52:59 +0000 | [diff] [blame] | 1877 | ** Reset a statement handle. |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 1878 | */ |
| 1879 | static int test_reset( |
| 1880 | void * clientData, |
| 1881 | Tcl_Interp *interp, |
| 1882 | int objc, |
| 1883 | Tcl_Obj *CONST objv[] |
| 1884 | ){ |
| 1885 | sqlite3_stmt *pStmt; |
| 1886 | int rc; |
| 1887 | |
| 1888 | if( objc!=2 ){ |
| 1889 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 1890 | Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0); |
| 1891 | return TCL_ERROR; |
| 1892 | } |
| 1893 | |
| 1894 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 1895 | |
danielk1977 | fc57d7b | 2004-05-26 02:04:57 +0000 | [diff] [blame] | 1896 | rc = sqlite3_reset(pStmt); |
danielk1977 | 261919c | 2005-12-06 12:52:59 +0000 | [diff] [blame] | 1897 | if( pStmt && sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ){ |
| 1898 | return TCL_ERROR; |
| 1899 | } |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 1900 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 261919c | 2005-12-06 12:52:59 +0000 | [diff] [blame] | 1901 | /* |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 1902 | if( rc ){ |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 1903 | return TCL_ERROR; |
| 1904 | } |
danielk1977 | 261919c | 2005-12-06 12:52:59 +0000 | [diff] [blame] | 1905 | */ |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 1906 | return TCL_OK; |
| 1907 | } |
| 1908 | |
drh | 5a38705 | 2003-01-11 14:19:51 +0000 | [diff] [blame] | 1909 | /* |
drh | d89bd00 | 2005-01-22 03:03:54 +0000 | [diff] [blame] | 1910 | ** Usage: sqlite3_expired STMT |
| 1911 | ** |
| 1912 | ** Return TRUE if a recompilation of the statement is recommended. |
| 1913 | */ |
| 1914 | static int test_expired( |
| 1915 | void * clientData, |
| 1916 | Tcl_Interp *interp, |
| 1917 | int objc, |
| 1918 | Tcl_Obj *CONST objv[] |
| 1919 | ){ |
| 1920 | sqlite3_stmt *pStmt; |
| 1921 | if( objc!=2 ){ |
| 1922 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 1923 | Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0); |
| 1924 | return TCL_ERROR; |
| 1925 | } |
| 1926 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 1927 | Tcl_SetObjResult(interp, Tcl_NewBooleanObj(sqlite3_expired(pStmt))); |
| 1928 | return TCL_OK; |
| 1929 | } |
| 1930 | |
| 1931 | /* |
drh | f8db1bc | 2005-04-22 02:38:37 +0000 | [diff] [blame] | 1932 | ** Usage: sqlite3_transfer_bindings FROMSTMT TOSTMT |
| 1933 | ** |
| 1934 | ** Transfer all bindings from FROMSTMT over to TOSTMT |
| 1935 | */ |
| 1936 | static int test_transfer_bind( |
| 1937 | void * clientData, |
| 1938 | Tcl_Interp *interp, |
| 1939 | int objc, |
| 1940 | Tcl_Obj *CONST objv[] |
| 1941 | ){ |
| 1942 | sqlite3_stmt *pStmt1, *pStmt2; |
| 1943 | if( objc!=3 ){ |
| 1944 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 1945 | Tcl_GetStringFromObj(objv[0], 0), " FROM-STMT TO-STMT", 0); |
| 1946 | return TCL_ERROR; |
| 1947 | } |
| 1948 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt1)) return TCL_ERROR; |
| 1949 | if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt2)) return TCL_ERROR; |
| 1950 | Tcl_SetObjResult(interp, |
| 1951 | Tcl_NewIntObj(sqlite3_transfer_bindings(pStmt1,pStmt2))); |
| 1952 | return TCL_OK; |
| 1953 | } |
| 1954 | |
| 1955 | /* |
danielk1977 | fbcd585 | 2004-06-15 02:44:18 +0000 | [diff] [blame] | 1956 | ** Usage: sqlite3_changes DB |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 1957 | ** |
danielk1977 | fbcd585 | 2004-06-15 02:44:18 +0000 | [diff] [blame] | 1958 | ** Return the number of changes made to the database by the last SQL |
| 1959 | ** execution. |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 1960 | */ |
danielk1977 | fbcd585 | 2004-06-15 02:44:18 +0000 | [diff] [blame] | 1961 | static int test_changes( |
| 1962 | void * clientData, |
| 1963 | Tcl_Interp *interp, |
| 1964 | int objc, |
| 1965 | Tcl_Obj *CONST objv[] |
| 1966 | ){ |
| 1967 | sqlite3 *db; |
| 1968 | if( objc!=2 ){ |
| 1969 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 1970 | Tcl_GetString(objv[0]), " DB", 0); |
| 1971 | return TCL_ERROR; |
| 1972 | } |
| 1973 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 1974 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_changes(db))); |
| 1975 | return TCL_OK; |
| 1976 | } |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 1977 | |
| 1978 | /* |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 1979 | ** This is the "static_bind_value" that variables are bound to when |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1980 | ** the FLAG option of sqlite3_bind is "static" |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 1981 | */ |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 1982 | static char *sqlite_static_bind_value = 0; |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 1983 | static int sqlite_static_bind_nbyte = 0; |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 1984 | |
| 1985 | /* |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 1986 | ** Usage: sqlite3_bind VM IDX VALUE FLAGS |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 1987 | ** |
| 1988 | ** Sets the value of the IDX-th occurance of "?" in the original SQL |
| 1989 | ** string. VALUE is the new value. If FLAGS=="null" then VALUE is |
| 1990 | ** ignored and the value is set to NULL. If FLAGS=="static" then |
| 1991 | ** the value is set to the value of a static variable named |
| 1992 | ** "sqlite_static_bind_value". If FLAGS=="normal" then a copy |
drh | bf8aa2a | 2005-12-02 02:44:05 +0000 | [diff] [blame] | 1993 | ** of the VALUE is made. If FLAGS=="blob10" then a VALUE is ignored |
| 1994 | ** an a 10-byte blob "abc\000xyz\000pq" is inserted. |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 1995 | */ |
| 1996 | static int test_bind( |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 1997 | void *NotUsed, |
| 1998 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 1999 | int argc, /* Number of arguments */ |
| 2000 | char **argv /* Text of each argument */ |
| 2001 | ){ |
danielk1977 | fc57d7b | 2004-05-26 02:04:57 +0000 | [diff] [blame] | 2002 | sqlite3_stmt *pStmt; |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2003 | int rc; |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2004 | int idx; |
| 2005 | if( argc!=5 ){ |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2006 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2007 | " VM IDX VALUE (null|static|normal)\"", 0); |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2008 | return TCL_ERROR; |
| 2009 | } |
danielk1977 | fc57d7b | 2004-05-26 02:04:57 +0000 | [diff] [blame] | 2010 | if( getStmtPointer(interp, argv[1], &pStmt) ) return TCL_ERROR; |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2011 | if( Tcl_GetInt(interp, argv[2], &idx) ) return TCL_ERROR; |
| 2012 | if( strcmp(argv[4],"null")==0 ){ |
danielk1977 | fc57d7b | 2004-05-26 02:04:57 +0000 | [diff] [blame] | 2013 | rc = sqlite3_bind_null(pStmt, idx); |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2014 | }else if( strcmp(argv[4],"static")==0 ){ |
danielk1977 | fc57d7b | 2004-05-26 02:04:57 +0000 | [diff] [blame] | 2015 | rc = sqlite3_bind_text(pStmt, idx, sqlite_static_bind_value, -1, 0); |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 2016 | }else if( strcmp(argv[4],"static-nbytes")==0 ){ |
| 2017 | rc = sqlite3_bind_text(pStmt, idx, sqlite_static_bind_value, |
| 2018 | sqlite_static_bind_nbyte, 0); |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2019 | }else if( strcmp(argv[4],"normal")==0 ){ |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 2020 | rc = sqlite3_bind_text(pStmt, idx, argv[3], -1, SQLITE_TRANSIENT); |
drh | bf8aa2a | 2005-12-02 02:44:05 +0000 | [diff] [blame] | 2021 | }else if( strcmp(argv[4],"blob10")==0 ){ |
| 2022 | rc = sqlite3_bind_text(pStmt, idx, "abc\000xyz\000pq", 10, SQLITE_STATIC); |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 2023 | }else{ |
| 2024 | Tcl_AppendResult(interp, "4th argument should be " |
| 2025 | "\"null\" or \"static\" or \"normal\"", 0); |
| 2026 | return TCL_ERROR; |
| 2027 | } |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2028 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2029 | if( rc ){ |
| 2030 | char zBuf[50]; |
| 2031 | sprintf(zBuf, "(%d) ", rc); |
danielk1977 | f20b21c | 2004-05-31 23:56:42 +0000 | [diff] [blame] | 2032 | Tcl_AppendResult(interp, zBuf, sqlite3ErrStr(rc), 0); |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2033 | return TCL_ERROR; |
| 2034 | } |
| 2035 | return TCL_OK; |
| 2036 | } |
| 2037 | |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 2038 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2039 | /* |
| 2040 | ** Usage: add_test_collate <db ptr> <utf8> <utf16le> <utf16be> |
| 2041 | ** |
| 2042 | ** This function is used to test that SQLite selects the correct collation |
| 2043 | ** sequence callback when multiple versions (for different text encodings) |
| 2044 | ** are available. |
| 2045 | ** |
| 2046 | ** Calling this routine registers the collation sequence "test_collate" |
| 2047 | ** with database handle <db>. The second argument must be a list of three |
| 2048 | ** boolean values. If the first is true, then a version of test_collate is |
| 2049 | ** registered for UTF-8, if the second is true, a version is registered for |
| 2050 | ** UTF-16le, if the third is true, a UTF-16be version is available. |
| 2051 | ** Previous versions of test_collate are deleted. |
| 2052 | ** |
| 2053 | ** The collation sequence test_collate is implemented by calling the |
| 2054 | ** following TCL script: |
| 2055 | ** |
| 2056 | ** "test_collate <enc> <lhs> <rhs>" |
| 2057 | ** |
| 2058 | ** The <lhs> and <rhs> are the two values being compared, encoded in UTF-8. |
| 2059 | ** The <enc> parameter is the encoding of the collation function that |
| 2060 | ** SQLite selected to call. The TCL test script implements the |
| 2061 | ** "test_collate" proc. |
| 2062 | ** |
| 2063 | ** Note that this will only work with one intepreter at a time, as the |
| 2064 | ** interp pointer to use when evaluating the TCL script is stored in |
| 2065 | ** pTestCollateInterp. |
| 2066 | */ |
| 2067 | static Tcl_Interp* pTestCollateInterp; |
| 2068 | static int test_collate_func( |
| 2069 | void *pCtx, |
| 2070 | int nA, const void *zA, |
| 2071 | int nB, const void *zB |
| 2072 | ){ |
| 2073 | Tcl_Interp *i = pTestCollateInterp; |
| 2074 | int encin = (int)pCtx; |
| 2075 | int res; |
drh | 4db38a7 | 2005-09-01 12:16:28 +0000 | [diff] [blame] | 2076 | int n; |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2077 | |
| 2078 | sqlite3_value *pVal; |
| 2079 | Tcl_Obj *pX; |
| 2080 | |
| 2081 | pX = Tcl_NewStringObj("test_collate", -1); |
| 2082 | Tcl_IncrRefCount(pX); |
| 2083 | |
| 2084 | switch( encin ){ |
| 2085 | case SQLITE_UTF8: |
| 2086 | Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-8",-1)); |
| 2087 | break; |
| 2088 | case SQLITE_UTF16LE: |
| 2089 | Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-16LE",-1)); |
| 2090 | break; |
| 2091 | case SQLITE_UTF16BE: |
| 2092 | Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-16BE",-1)); |
| 2093 | break; |
| 2094 | default: |
| 2095 | assert(0); |
| 2096 | } |
| 2097 | |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 2098 | pVal = sqlite3ValueNew(0); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 2099 | sqlite3ValueSetStr(pVal, nA, zA, encin, SQLITE_STATIC); |
drh | 4db38a7 | 2005-09-01 12:16:28 +0000 | [diff] [blame] | 2100 | n = sqlite3_value_bytes(pVal); |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 2101 | Tcl_ListObjAppendElement(i,pX, |
| 2102 | Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n)); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 2103 | sqlite3ValueSetStr(pVal, nB, zB, encin, SQLITE_STATIC); |
drh | 4db38a7 | 2005-09-01 12:16:28 +0000 | [diff] [blame] | 2104 | n = sqlite3_value_bytes(pVal); |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 2105 | Tcl_ListObjAppendElement(i,pX, |
| 2106 | Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n)); |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2107 | sqlite3ValueFree(pVal); |
| 2108 | |
| 2109 | Tcl_EvalObjEx(i, pX, 0); |
| 2110 | Tcl_DecrRefCount(pX); |
| 2111 | Tcl_GetIntFromObj(i, Tcl_GetObjResult(i), &res); |
| 2112 | return res; |
| 2113 | } |
| 2114 | static int test_collate( |
| 2115 | void * clientData, |
| 2116 | Tcl_Interp *interp, |
| 2117 | int objc, |
| 2118 | Tcl_Obj *CONST objv[] |
| 2119 | ){ |
| 2120 | sqlite3 *db; |
| 2121 | int val; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2122 | sqlite3_value *pVal; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2123 | int rc; |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2124 | |
| 2125 | if( objc!=5 ) goto bad_args; |
| 2126 | pTestCollateInterp = interp; |
| 2127 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2128 | |
| 2129 | if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2130 | rc = sqlite3_create_collation(db, "test_collate", SQLITE_UTF8, |
| 2131 | (void *)SQLITE_UTF8, val?test_collate_func:0); |
| 2132 | if( rc==SQLITE_OK ){ |
| 2133 | if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR; |
| 2134 | rc = sqlite3_create_collation(db, "test_collate", SQLITE_UTF16LE, |
| 2135 | (void *)SQLITE_UTF16LE, val?test_collate_func:0); |
| 2136 | if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2137 | |
drh | 86f8c19 | 2007-08-22 00:39:19 +0000 | [diff] [blame] | 2138 | #if 0 |
danielk1977 | 9a30cf6 | 2006-01-18 04:26:07 +0000 | [diff] [blame] | 2139 | if( sqlite3_iMallocFail>0 ){ |
| 2140 | sqlite3_iMallocFail++; |
| 2141 | } |
| 2142 | #endif |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame^] | 2143 | sqlite3_mutex_enter(db->mutex); |
| 2144 | pVal = sqlite3ValueNew(db); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 2145 | sqlite3ValueSetStr(pVal, -1, "test_collate", SQLITE_UTF8, SQLITE_STATIC); |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame^] | 2146 | if( db->mallocFailed ){ |
| 2147 | rc = SQLITE_NOMEM; |
| 2148 | }else{ |
| 2149 | rc = sqlite3_create_collation16(db, |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 2150 | sqlite3ValueText(pVal, SQLITE_UTF16NATIVE), SQLITE_UTF16BE, |
danielk1977 | 9a30cf6 | 2006-01-18 04:26:07 +0000 | [diff] [blame] | 2151 | (void *)SQLITE_UTF16BE, val?test_collate_func:0); |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame^] | 2152 | } |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2153 | sqlite3ValueFree(pVal); |
drh | f3a65f7 | 2007-08-22 20:18:21 +0000 | [diff] [blame^] | 2154 | sqlite3_mutex_leave(db->mutex); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2155 | } |
| 2156 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
danielk1977 | 9a30cf6 | 2006-01-18 04:26:07 +0000 | [diff] [blame] | 2157 | |
| 2158 | if( rc!=SQLITE_OK ){ |
| 2159 | Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0); |
| 2160 | return TCL_ERROR; |
| 2161 | } |
danielk1977 | 4e6af13 | 2004-06-10 14:01:08 +0000 | [diff] [blame] | 2162 | return TCL_OK; |
| 2163 | |
| 2164 | bad_args: |
| 2165 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2166 | Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0); |
| 2167 | return TCL_ERROR; |
| 2168 | } |
| 2169 | |
drh | 268803a | 2005-12-14 20:11:30 +0000 | [diff] [blame] | 2170 | /* |
| 2171 | ** When the collation needed callback is invoked, record the name of |
| 2172 | ** the requested collating function here. The recorded name is linked |
| 2173 | ** to a TCL variable and used to make sure that the requested collation |
| 2174 | ** name is correct. |
| 2175 | */ |
| 2176 | static char zNeededCollation[200]; |
| 2177 | static char *pzNeededCollation = zNeededCollation; |
| 2178 | |
| 2179 | |
| 2180 | /* |
| 2181 | ** Called when a collating sequence is needed. Registered using |
| 2182 | ** sqlite3_collation_needed16(). |
| 2183 | */ |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2184 | static void test_collate_needed_cb( |
| 2185 | void *pCtx, |
| 2186 | sqlite3 *db, |
| 2187 | int eTextRep, |
drh | 268803a | 2005-12-14 20:11:30 +0000 | [diff] [blame] | 2188 | const void *pName |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2189 | ){ |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 2190 | int enc = ENC(db); |
drh | 268803a | 2005-12-14 20:11:30 +0000 | [diff] [blame] | 2191 | int i; |
| 2192 | char *z; |
| 2193 | for(z = (char*)pName, i=0; *z || z[1]; z++){ |
| 2194 | if( *z ) zNeededCollation[i++] = *z; |
| 2195 | } |
| 2196 | zNeededCollation[i] = 0; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2197 | sqlite3_create_collation( |
danielk1977 | 14db266 | 2006-01-09 16:12:04 +0000 | [diff] [blame] | 2198 | db, "test_collate", ENC(db), (void *)enc, test_collate_func); |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | /* |
| 2202 | ** Usage: add_test_collate_needed DB |
| 2203 | */ |
| 2204 | static int test_collate_needed( |
| 2205 | void * clientData, |
| 2206 | Tcl_Interp *interp, |
| 2207 | int objc, |
| 2208 | Tcl_Obj *CONST objv[] |
| 2209 | ){ |
| 2210 | sqlite3 *db; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2211 | int rc; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2212 | |
| 2213 | if( objc!=2 ) goto bad_args; |
| 2214 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2215 | rc = sqlite3_collation_needed16(db, 0, test_collate_needed_cb); |
drh | 268803a | 2005-12-14 20:11:30 +0000 | [diff] [blame] | 2216 | zNeededCollation[0] = 0; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2217 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2218 | return TCL_OK; |
| 2219 | |
| 2220 | bad_args: |
| 2221 | Tcl_WrongNumArgs(interp, 1, objv, "DB"); |
| 2222 | return TCL_ERROR; |
| 2223 | } |
drh | 7d9bd4e | 2006-02-16 18:16:36 +0000 | [diff] [blame] | 2224 | |
| 2225 | /* |
| 2226 | ** tclcmd: add_alignment_test_collations DB |
| 2227 | ** |
| 2228 | ** Add two new collating sequences to the database DB |
| 2229 | ** |
| 2230 | ** utf16_aligned |
| 2231 | ** utf16_unaligned |
| 2232 | ** |
| 2233 | ** Both collating sequences use the same sort order as BINARY. |
| 2234 | ** The only difference is that the utf16_aligned collating |
| 2235 | ** sequence is declared with the SQLITE_UTF16_ALIGNED flag. |
| 2236 | ** Both collating functions increment the unaligned utf16 counter |
| 2237 | ** whenever they see a string that begins on an odd byte boundary. |
| 2238 | */ |
| 2239 | static int unaligned_string_counter = 0; |
| 2240 | static int alignmentCollFunc( |
| 2241 | void *NotUsed, |
| 2242 | int nKey1, const void *pKey1, |
| 2243 | int nKey2, const void *pKey2 |
| 2244 | ){ |
| 2245 | int rc, n; |
| 2246 | n = nKey1<nKey2 ? nKey1 : nKey2; |
| 2247 | if( nKey1>0 && 1==(1&(int)pKey1) ) unaligned_string_counter++; |
| 2248 | if( nKey2>0 && 1==(1&(int)pKey2) ) unaligned_string_counter++; |
| 2249 | rc = memcmp(pKey1, pKey2, n); |
| 2250 | if( rc==0 ){ |
| 2251 | rc = nKey1 - nKey2; |
| 2252 | } |
| 2253 | return rc; |
| 2254 | } |
| 2255 | static int add_alignment_test_collations( |
| 2256 | void * clientData, |
| 2257 | Tcl_Interp *interp, |
| 2258 | int objc, |
| 2259 | Tcl_Obj *CONST objv[] |
| 2260 | ){ |
| 2261 | sqlite3 *db; |
| 2262 | if( objc>=2 ){ |
| 2263 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2264 | sqlite3_create_collation(db, "utf16_unaligned", |
| 2265 | SQLITE_UTF16, |
| 2266 | 0, alignmentCollFunc); |
| 2267 | sqlite3_create_collation(db, "utf16_aligned", |
| 2268 | SQLITE_UTF16 | SQLITE_UTF16_ALIGNED, |
| 2269 | 0, alignmentCollFunc); |
| 2270 | } |
| 2271 | return SQLITE_OK; |
| 2272 | } |
| 2273 | #endif /* !defined(SQLITE_OMIT_UTF16) */ |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2274 | |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 2275 | /* |
| 2276 | ** Usage: add_test_function <db ptr> <utf8> <utf16le> <utf16be> |
| 2277 | ** |
| 2278 | ** This function is used to test that SQLite selects the correct user |
| 2279 | ** function callback when multiple versions (for different text encodings) |
| 2280 | ** are available. |
| 2281 | ** |
| 2282 | ** Calling this routine registers up to three versions of the user function |
| 2283 | ** "test_function" with database handle <db>. If the second argument is |
| 2284 | ** true, then a version of test_function is registered for UTF-8, if the |
| 2285 | ** third is true, a version is registered for UTF-16le, if the fourth is |
| 2286 | ** true, a UTF-16be version is available. Previous versions of |
| 2287 | ** test_function are deleted. |
| 2288 | ** |
| 2289 | ** The user function is implemented by calling the following TCL script: |
| 2290 | ** |
| 2291 | ** "test_function <enc> <arg>" |
| 2292 | ** |
| 2293 | ** Where <enc> is one of UTF-8, UTF-16LE or UTF16BE, and <arg> is the |
| 2294 | ** single argument passed to the SQL function. The value returned by |
| 2295 | ** the TCL script is used as the return value of the SQL function. It |
| 2296 | ** is passed to SQLite using UTF-16BE for a UTF-8 test_function(), UTF-8 |
| 2297 | ** for a UTF-16LE test_function(), and UTF-16LE for an implementation that |
| 2298 | ** prefers UTF-16BE. |
| 2299 | */ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 2300 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 2301 | static void test_function_utf8( |
| 2302 | sqlite3_context *pCtx, |
| 2303 | int nArg, |
| 2304 | sqlite3_value **argv |
| 2305 | ){ |
| 2306 | Tcl_Interp *interp; |
| 2307 | Tcl_Obj *pX; |
| 2308 | sqlite3_value *pVal; |
| 2309 | interp = (Tcl_Interp *)sqlite3_user_data(pCtx); |
| 2310 | pX = Tcl_NewStringObj("test_function", -1); |
| 2311 | Tcl_IncrRefCount(pX); |
| 2312 | Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-8", -1)); |
| 2313 | Tcl_ListObjAppendElement(interp, pX, |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 2314 | Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1)); |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 2315 | Tcl_EvalObjEx(interp, pX, 0); |
| 2316 | Tcl_DecrRefCount(pX); |
| 2317 | sqlite3_result_text(pCtx, Tcl_GetStringResult(interp), -1, SQLITE_TRANSIENT); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 2318 | pVal = sqlite3ValueNew(0); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 2319 | sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 2320 | SQLITE_UTF8, SQLITE_STATIC); |
| 2321 | sqlite3_result_text16be(pCtx, sqlite3_value_text16be(pVal), |
| 2322 | -1, SQLITE_TRANSIENT); |
| 2323 | sqlite3ValueFree(pVal); |
| 2324 | } |
| 2325 | static void test_function_utf16le( |
| 2326 | sqlite3_context *pCtx, |
| 2327 | int nArg, |
| 2328 | sqlite3_value **argv |
| 2329 | ){ |
| 2330 | Tcl_Interp *interp; |
| 2331 | Tcl_Obj *pX; |
| 2332 | sqlite3_value *pVal; |
| 2333 | interp = (Tcl_Interp *)sqlite3_user_data(pCtx); |
| 2334 | pX = Tcl_NewStringObj("test_function", -1); |
| 2335 | Tcl_IncrRefCount(pX); |
| 2336 | Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16LE", -1)); |
| 2337 | Tcl_ListObjAppendElement(interp, pX, |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 2338 | Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1)); |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 2339 | Tcl_EvalObjEx(interp, pX, 0); |
| 2340 | Tcl_DecrRefCount(pX); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 2341 | pVal = sqlite3ValueNew(0); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 2342 | sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 2343 | SQLITE_UTF8, SQLITE_STATIC); |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 2344 | sqlite3_result_text(pCtx,(char*)sqlite3_value_text(pVal),-1,SQLITE_TRANSIENT); |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 2345 | sqlite3ValueFree(pVal); |
| 2346 | } |
| 2347 | static void test_function_utf16be( |
| 2348 | sqlite3_context *pCtx, |
| 2349 | int nArg, |
| 2350 | sqlite3_value **argv |
| 2351 | ){ |
| 2352 | Tcl_Interp *interp; |
| 2353 | Tcl_Obj *pX; |
| 2354 | sqlite3_value *pVal; |
| 2355 | interp = (Tcl_Interp *)sqlite3_user_data(pCtx); |
| 2356 | pX = Tcl_NewStringObj("test_function", -1); |
| 2357 | Tcl_IncrRefCount(pX); |
| 2358 | Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16BE", -1)); |
| 2359 | Tcl_ListObjAppendElement(interp, pX, |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 2360 | Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1)); |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 2361 | Tcl_EvalObjEx(interp, pX, 0); |
| 2362 | Tcl_DecrRefCount(pX); |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 2363 | pVal = sqlite3ValueNew(0); |
drh | b21c8cd | 2007-08-21 19:33:56 +0000 | [diff] [blame] | 2364 | sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 2365 | SQLITE_UTF8, SQLITE_STATIC); |
| 2366 | sqlite3_result_text16le(pCtx, sqlite3_value_text16le(pVal), |
| 2367 | -1, SQLITE_TRANSIENT); |
| 2368 | sqlite3ValueFree(pVal); |
| 2369 | } |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 2370 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 2371 | static int test_function( |
| 2372 | void * clientData, |
| 2373 | Tcl_Interp *interp, |
| 2374 | int objc, |
| 2375 | Tcl_Obj *CONST objv[] |
| 2376 | ){ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 2377 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 2378 | sqlite3 *db; |
| 2379 | int val; |
| 2380 | |
| 2381 | if( objc!=5 ) goto bad_args; |
| 2382 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2383 | |
| 2384 | if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR; |
| 2385 | if( val ){ |
| 2386 | sqlite3_create_function(db, "test_function", 1, SQLITE_UTF8, |
| 2387 | interp, test_function_utf8, 0, 0); |
| 2388 | } |
| 2389 | if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR; |
| 2390 | if( val ){ |
| 2391 | sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16LE, |
| 2392 | interp, test_function_utf16le, 0, 0); |
| 2393 | } |
| 2394 | if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR; |
| 2395 | if( val ){ |
| 2396 | sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16BE, |
| 2397 | interp, test_function_utf16be, 0, 0); |
| 2398 | } |
| 2399 | |
| 2400 | return TCL_OK; |
| 2401 | bad_args: |
| 2402 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2403 | Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0); |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 2404 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | c8e9a2d | 2004-06-25 12:08:46 +0000 | [diff] [blame] | 2405 | return TCL_ERROR; |
| 2406 | } |
| 2407 | |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2408 | /* |
| 2409 | ** Usage: test_errstr <err code> |
| 2410 | ** |
| 2411 | ** Test that the english language string equivalents for sqlite error codes |
| 2412 | ** are sane. The parameter is an integer representing an sqlite error code. |
| 2413 | ** The result is a list of two elements, the string representation of the |
| 2414 | ** error code and the english language explanation. |
| 2415 | */ |
| 2416 | static int test_errstr( |
| 2417 | void * clientData, |
| 2418 | Tcl_Interp *interp, |
| 2419 | int objc, |
| 2420 | Tcl_Obj *CONST objv[] |
| 2421 | ){ |
| 2422 | char *zCode; |
| 2423 | int i; |
| 2424 | if( objc!=1 ){ |
| 2425 | Tcl_WrongNumArgs(interp, 1, objv, "<error code>"); |
| 2426 | } |
| 2427 | |
| 2428 | zCode = Tcl_GetString(objv[1]); |
| 2429 | for(i=0; i<200; i++){ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 2430 | if( 0==strcmp(t1ErrorName(i), zCode) ) break; |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 2431 | } |
| 2432 | Tcl_SetResult(interp, (char *)sqlite3ErrStr(i), 0); |
| 2433 | return TCL_OK; |
| 2434 | } |
| 2435 | |
drh | 5045789 | 2003-09-06 01:10:47 +0000 | [diff] [blame] | 2436 | /* |
drh | 99ee360 | 2003-02-16 19:13:36 +0000 | [diff] [blame] | 2437 | ** Usage: breakpoint |
| 2438 | ** |
| 2439 | ** This routine exists for one purpose - to provide a place to put a |
| 2440 | ** breakpoint with GDB that can be triggered using TCL code. The use |
| 2441 | ** for this is when a particular test fails on (say) the 1485th iteration. |
| 2442 | ** In the TCL test script, we can add code like this: |
| 2443 | ** |
| 2444 | ** if {$i==1485} breakpoint |
| 2445 | ** |
| 2446 | ** Then run testfixture in the debugger and wait for the breakpoint to |
| 2447 | ** fire. Then additional breakpoints can be set to trace down the bug. |
| 2448 | */ |
| 2449 | static int test_breakpoint( |
| 2450 | void *NotUsed, |
| 2451 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 2452 | int argc, /* Number of arguments */ |
| 2453 | char **argv /* Text of each argument */ |
| 2454 | ){ |
| 2455 | return TCL_OK; /* Do nothing */ |
| 2456 | } |
| 2457 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2458 | /* |
drh | b026e05 | 2007-05-02 01:34:31 +0000 | [diff] [blame] | 2459 | ** Usage: sqlite3_bind_zeroblob STMT IDX N |
| 2460 | ** |
| 2461 | ** Test the sqlite3_bind_zeroblob interface. STMT is a prepared statement. |
| 2462 | ** IDX is the index of a wildcard in the prepared statement. This command |
| 2463 | ** binds a N-byte zero-filled BLOB to the wildcard. |
| 2464 | */ |
| 2465 | static int test_bind_zeroblob( |
| 2466 | void * clientData, |
| 2467 | Tcl_Interp *interp, |
| 2468 | int objc, |
| 2469 | Tcl_Obj *CONST objv[] |
| 2470 | ){ |
| 2471 | sqlite3_stmt *pStmt; |
| 2472 | int idx; |
| 2473 | int n; |
| 2474 | int rc; |
| 2475 | |
| 2476 | if( objc!=4 ){ |
| 2477 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2478 | Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); |
| 2479 | return TCL_ERROR; |
| 2480 | } |
| 2481 | |
| 2482 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2483 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 2484 | if( Tcl_GetIntFromObj(interp, objv[3], &n) ) return TCL_ERROR; |
| 2485 | |
| 2486 | rc = sqlite3_bind_zeroblob(pStmt, idx, n); |
| 2487 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
| 2488 | if( rc!=SQLITE_OK ){ |
| 2489 | return TCL_ERROR; |
| 2490 | } |
| 2491 | |
| 2492 | return TCL_OK; |
| 2493 | } |
| 2494 | |
| 2495 | /* |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2496 | ** Usage: sqlite3_bind_int STMT N VALUE |
| 2497 | ** |
| 2498 | ** Test the sqlite3_bind_int interface. STMT is a prepared statement. |
| 2499 | ** N is the index of a wildcard in the prepared statement. This command |
| 2500 | ** binds a 32-bit integer VALUE to that wildcard. |
| 2501 | */ |
| 2502 | static int test_bind_int( |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2503 | void * clientData, |
| 2504 | Tcl_Interp *interp, |
| 2505 | int objc, |
| 2506 | Tcl_Obj *CONST objv[] |
| 2507 | ){ |
| 2508 | sqlite3_stmt *pStmt; |
| 2509 | int idx; |
| 2510 | int value; |
| 2511 | int rc; |
| 2512 | |
| 2513 | if( objc!=4 ){ |
| 2514 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2515 | Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2516 | return TCL_ERROR; |
| 2517 | } |
| 2518 | |
| 2519 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2520 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 2521 | if( Tcl_GetIntFromObj(interp, objv[3], &value) ) return TCL_ERROR; |
| 2522 | |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 2523 | rc = sqlite3_bind_int(pStmt, idx, value); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2524 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2525 | if( rc!=SQLITE_OK ){ |
| 2526 | return TCL_ERROR; |
| 2527 | } |
| 2528 | |
| 2529 | return TCL_OK; |
| 2530 | } |
| 2531 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2532 | |
| 2533 | /* |
| 2534 | ** Usage: sqlite3_bind_int64 STMT N VALUE |
| 2535 | ** |
| 2536 | ** Test the sqlite3_bind_int64 interface. STMT is a prepared statement. |
| 2537 | ** N is the index of a wildcard in the prepared statement. This command |
| 2538 | ** binds a 64-bit integer VALUE to that wildcard. |
| 2539 | */ |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2540 | static int test_bind_int64( |
| 2541 | void * clientData, |
| 2542 | Tcl_Interp *interp, |
| 2543 | int objc, |
| 2544 | Tcl_Obj *CONST objv[] |
| 2545 | ){ |
| 2546 | sqlite3_stmt *pStmt; |
| 2547 | int idx; |
| 2548 | i64 value; |
| 2549 | int rc; |
| 2550 | |
| 2551 | if( objc!=4 ){ |
| 2552 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2553 | Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2554 | return TCL_ERROR; |
| 2555 | } |
| 2556 | |
| 2557 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2558 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 2559 | if( Tcl_GetWideIntFromObj(interp, objv[3], &value) ) return TCL_ERROR; |
| 2560 | |
| 2561 | rc = sqlite3_bind_int64(pStmt, idx, value); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2562 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2563 | if( rc!=SQLITE_OK ){ |
| 2564 | return TCL_ERROR; |
| 2565 | } |
| 2566 | |
| 2567 | return TCL_OK; |
| 2568 | } |
| 2569 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2570 | |
| 2571 | /* |
| 2572 | ** Usage: sqlite3_bind_double STMT N VALUE |
| 2573 | ** |
| 2574 | ** Test the sqlite3_bind_double interface. STMT is a prepared statement. |
| 2575 | ** N is the index of a wildcard in the prepared statement. This command |
| 2576 | ** binds a 64-bit integer VALUE to that wildcard. |
| 2577 | */ |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2578 | static int test_bind_double( |
| 2579 | void * clientData, |
| 2580 | Tcl_Interp *interp, |
| 2581 | int objc, |
| 2582 | Tcl_Obj *CONST objv[] |
| 2583 | ){ |
| 2584 | sqlite3_stmt *pStmt; |
| 2585 | int idx; |
| 2586 | double value; |
| 2587 | int rc; |
| 2588 | |
| 2589 | if( objc!=4 ){ |
| 2590 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2591 | Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2592 | return TCL_ERROR; |
| 2593 | } |
| 2594 | |
| 2595 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2596 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 2597 | if( Tcl_GetDoubleFromObj(interp, objv[3], &value) ) return TCL_ERROR; |
| 2598 | |
| 2599 | rc = sqlite3_bind_double(pStmt, idx, value); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2600 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2601 | if( rc!=SQLITE_OK ){ |
| 2602 | return TCL_ERROR; |
| 2603 | } |
| 2604 | |
| 2605 | return TCL_OK; |
| 2606 | } |
| 2607 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2608 | /* |
| 2609 | ** Usage: sqlite3_bind_null STMT N |
| 2610 | ** |
| 2611 | ** Test the sqlite3_bind_null interface. STMT is a prepared statement. |
| 2612 | ** N is the index of a wildcard in the prepared statement. This command |
| 2613 | ** binds a NULL to the wildcard. |
| 2614 | */ |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2615 | static int test_bind_null( |
| 2616 | void * clientData, |
| 2617 | Tcl_Interp *interp, |
| 2618 | int objc, |
| 2619 | Tcl_Obj *CONST objv[] |
| 2620 | ){ |
| 2621 | sqlite3_stmt *pStmt; |
| 2622 | int idx; |
| 2623 | int rc; |
| 2624 | |
| 2625 | if( objc!=3 ){ |
| 2626 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2627 | Tcl_GetStringFromObj(objv[0], 0), " STMT N", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2628 | return TCL_ERROR; |
| 2629 | } |
| 2630 | |
| 2631 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2632 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 2633 | |
| 2634 | rc = sqlite3_bind_null(pStmt, idx); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2635 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2636 | if( rc!=SQLITE_OK ){ |
| 2637 | return TCL_ERROR; |
| 2638 | } |
| 2639 | |
| 2640 | return TCL_OK; |
| 2641 | } |
| 2642 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2643 | /* |
| 2644 | ** Usage: sqlite3_bind_text STMT N STRING BYTES |
| 2645 | ** |
| 2646 | ** Test the sqlite3_bind_text interface. STMT is a prepared statement. |
| 2647 | ** N is the index of a wildcard in the prepared statement. This command |
| 2648 | ** binds a UTF-8 string STRING to the wildcard. The string is BYTES bytes |
| 2649 | ** long. |
| 2650 | */ |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2651 | static int test_bind_text( |
| 2652 | void * clientData, |
| 2653 | Tcl_Interp *interp, |
| 2654 | int objc, |
| 2655 | Tcl_Obj *CONST objv[] |
| 2656 | ){ |
| 2657 | sqlite3_stmt *pStmt; |
| 2658 | int idx; |
| 2659 | int bytes; |
| 2660 | char *value; |
| 2661 | int rc; |
| 2662 | |
| 2663 | if( objc!=5 ){ |
| 2664 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2665 | Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE BYTES", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2666 | return TCL_ERROR; |
| 2667 | } |
| 2668 | |
| 2669 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2670 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 2671 | value = Tcl_GetString(objv[3]); |
| 2672 | if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR; |
| 2673 | |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 2674 | rc = sqlite3_bind_text(pStmt, idx, value, bytes, SQLITE_TRANSIENT); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2675 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2676 | if( rc!=SQLITE_OK ){ |
drh | 473d179 | 2005-06-06 17:54:55 +0000 | [diff] [blame] | 2677 | Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2678 | return TCL_ERROR; |
| 2679 | } |
| 2680 | |
| 2681 | return TCL_OK; |
| 2682 | } |
| 2683 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2684 | /* |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 2685 | ** Usage: sqlite3_bind_text16 ?-static? STMT N STRING BYTES |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2686 | ** |
| 2687 | ** Test the sqlite3_bind_text16 interface. STMT is a prepared statement. |
| 2688 | ** N is the index of a wildcard in the prepared statement. This command |
| 2689 | ** binds a UTF-16 string STRING to the wildcard. The string is BYTES bytes |
| 2690 | ** long. |
| 2691 | */ |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2692 | static int test_bind_text16( |
| 2693 | void * clientData, |
| 2694 | Tcl_Interp *interp, |
| 2695 | int objc, |
| 2696 | Tcl_Obj *CONST objv[] |
| 2697 | ){ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 2698 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2699 | sqlite3_stmt *pStmt; |
| 2700 | int idx; |
| 2701 | int bytes; |
| 2702 | char *value; |
| 2703 | int rc; |
| 2704 | |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 2705 | void (*xDel)() = (objc==6?SQLITE_STATIC:SQLITE_TRANSIENT); |
| 2706 | Tcl_Obj *oStmt = objv[objc-4]; |
| 2707 | Tcl_Obj *oN = objv[objc-3]; |
| 2708 | Tcl_Obj *oString = objv[objc-2]; |
| 2709 | Tcl_Obj *oBytes = objv[objc-1]; |
| 2710 | |
| 2711 | if( objc!=5 && objc!=6){ |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2712 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2713 | Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE BYTES", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2714 | return TCL_ERROR; |
| 2715 | } |
| 2716 | |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 2717 | if( getStmtPointer(interp, Tcl_GetString(oStmt), &pStmt) ) return TCL_ERROR; |
| 2718 | if( Tcl_GetIntFromObj(interp, oN, &idx) ) return TCL_ERROR; |
| 2719 | value = (char*)Tcl_GetByteArrayFromObj(oString, 0); |
| 2720 | if( Tcl_GetIntFromObj(interp, oBytes, &bytes) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2721 | |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 2722 | rc = sqlite3_bind_text16(pStmt, idx, (void *)value, bytes, xDel); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2723 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2724 | if( rc!=SQLITE_OK ){ |
| 2725 | return TCL_ERROR; |
| 2726 | } |
| 2727 | |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 2728 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2729 | return TCL_OK; |
| 2730 | } |
| 2731 | |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2732 | /* |
danielk1977 | 5b159dc | 2007-05-17 16:34:43 +0000 | [diff] [blame] | 2733 | ** Usage: sqlite3_bind_blob ?-static? STMT N DATA BYTES |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2734 | ** |
| 2735 | ** Test the sqlite3_bind_blob interface. STMT is a prepared statement. |
| 2736 | ** N is the index of a wildcard in the prepared statement. This command |
| 2737 | ** binds a BLOB to the wildcard. The BLOB is BYTES bytes in size. |
| 2738 | */ |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2739 | static int test_bind_blob( |
| 2740 | void * clientData, |
| 2741 | Tcl_Interp *interp, |
| 2742 | int objc, |
| 2743 | Tcl_Obj *CONST objv[] |
| 2744 | ){ |
| 2745 | sqlite3_stmt *pStmt; |
| 2746 | int idx; |
| 2747 | int bytes; |
| 2748 | char *value; |
| 2749 | int rc; |
danielk1977 | 5b159dc | 2007-05-17 16:34:43 +0000 | [diff] [blame] | 2750 | sqlite3_destructor_type xDestructor = SQLITE_TRANSIENT; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2751 | |
danielk1977 | 5b159dc | 2007-05-17 16:34:43 +0000 | [diff] [blame] | 2752 | if( objc!=5 && objc!=6 ){ |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2753 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 2754 | Tcl_GetStringFromObj(objv[0], 0), " STMT N DATA BYTES", 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2755 | return TCL_ERROR; |
| 2756 | } |
| 2757 | |
danielk1977 | 5b159dc | 2007-05-17 16:34:43 +0000 | [diff] [blame] | 2758 | if( objc==6 ){ |
| 2759 | xDestructor = SQLITE_STATIC; |
| 2760 | objv++; |
| 2761 | } |
| 2762 | |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2763 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2764 | if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR; |
| 2765 | value = Tcl_GetString(objv[3]); |
danielk1977 | 49e4643 | 2004-05-27 13:55:27 +0000 | [diff] [blame] | 2766 | if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2767 | |
danielk1977 | 5b159dc | 2007-05-17 16:34:43 +0000 | [diff] [blame] | 2768 | rc = sqlite3_bind_blob(pStmt, idx, value, bytes, xDestructor); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 2769 | if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 2770 | if( rc!=SQLITE_OK ){ |
| 2771 | return TCL_ERROR; |
| 2772 | } |
| 2773 | |
| 2774 | return TCL_OK; |
| 2775 | } |
| 2776 | |
drh | 99ee360 | 2003-02-16 19:13:36 +0000 | [diff] [blame] | 2777 | /* |
drh | 75f6a03 | 2004-07-15 14:15:00 +0000 | [diff] [blame] | 2778 | ** Usage: sqlite3_bind_parameter_count STMT |
| 2779 | ** |
| 2780 | ** Return the number of wildcards in the given statement. |
| 2781 | */ |
| 2782 | static int test_bind_parameter_count( |
| 2783 | void * clientData, |
| 2784 | Tcl_Interp *interp, |
| 2785 | int objc, |
| 2786 | Tcl_Obj *CONST objv[] |
| 2787 | ){ |
| 2788 | sqlite3_stmt *pStmt; |
| 2789 | |
| 2790 | if( objc!=2 ){ |
| 2791 | Tcl_WrongNumArgs(interp, 1, objv, "STMT"); |
| 2792 | return TCL_ERROR; |
| 2793 | } |
| 2794 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2795 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_bind_parameter_count(pStmt))); |
| 2796 | return TCL_OK; |
| 2797 | } |
| 2798 | |
| 2799 | /* |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 2800 | ** Usage: sqlite3_bind_parameter_name STMT N |
| 2801 | ** |
| 2802 | ** Return the name of the Nth wildcard. The first wildcard is 1. |
| 2803 | ** An empty string is returned if N is out of range or if the wildcard |
| 2804 | ** is nameless. |
| 2805 | */ |
| 2806 | static int test_bind_parameter_name( |
| 2807 | void * clientData, |
| 2808 | Tcl_Interp *interp, |
| 2809 | int objc, |
| 2810 | Tcl_Obj *CONST objv[] |
| 2811 | ){ |
| 2812 | sqlite3_stmt *pStmt; |
| 2813 | int i; |
| 2814 | |
| 2815 | if( objc!=3 ){ |
| 2816 | Tcl_WrongNumArgs(interp, 1, objv, "STMT N"); |
| 2817 | return TCL_ERROR; |
| 2818 | } |
| 2819 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2820 | if( Tcl_GetIntFromObj(interp, objv[2], &i) ) return TCL_ERROR; |
| 2821 | Tcl_SetObjResult(interp, |
| 2822 | Tcl_NewStringObj(sqlite3_bind_parameter_name(pStmt,i),-1) |
| 2823 | ); |
| 2824 | return TCL_OK; |
| 2825 | } |
| 2826 | |
| 2827 | /* |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 2828 | ** Usage: sqlite3_bind_parameter_index STMT NAME |
| 2829 | ** |
| 2830 | ** Return the index of the wildcard called NAME. Return 0 if there is |
| 2831 | ** no such wildcard. |
| 2832 | */ |
| 2833 | static int test_bind_parameter_index( |
| 2834 | void * clientData, |
| 2835 | Tcl_Interp *interp, |
| 2836 | int objc, |
| 2837 | Tcl_Obj *CONST objv[] |
| 2838 | ){ |
| 2839 | sqlite3_stmt *pStmt; |
| 2840 | |
| 2841 | if( objc!=3 ){ |
| 2842 | Tcl_WrongNumArgs(interp, 1, objv, "STMT NAME"); |
| 2843 | return TCL_ERROR; |
| 2844 | } |
| 2845 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2846 | Tcl_SetObjResult(interp, |
| 2847 | Tcl_NewIntObj( |
| 2848 | sqlite3_bind_parameter_index(pStmt,Tcl_GetString(objv[2])) |
| 2849 | ) |
| 2850 | ); |
| 2851 | return TCL_OK; |
| 2852 | } |
| 2853 | |
| 2854 | /* |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 2855 | ** Usage: sqlite3_clear_bindings STMT |
| 2856 | ** |
| 2857 | */ |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 2858 | static int test_clear_bindings( |
| 2859 | void * clientData, |
| 2860 | Tcl_Interp *interp, |
| 2861 | int objc, |
| 2862 | Tcl_Obj *CONST objv[] |
| 2863 | ){ |
| 2864 | sqlite3_stmt *pStmt; |
| 2865 | |
| 2866 | if( objc!=2 ){ |
| 2867 | Tcl_WrongNumArgs(interp, 1, objv, "STMT"); |
| 2868 | return TCL_ERROR; |
| 2869 | } |
| 2870 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 2871 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_clear_bindings(pStmt))); |
| 2872 | return TCL_OK; |
| 2873 | } |
drh | f9cb7f5 | 2006-06-27 20:06:44 +0000 | [diff] [blame] | 2874 | |
| 2875 | /* |
| 2876 | ** Usage: sqlite3_sleep MILLISECONDS |
| 2877 | */ |
| 2878 | static int test_sleep( |
| 2879 | void * clientData, |
| 2880 | Tcl_Interp *interp, |
| 2881 | int objc, |
| 2882 | Tcl_Obj *CONST objv[] |
| 2883 | ){ |
| 2884 | int ms; |
| 2885 | |
| 2886 | if( objc!=2 ){ |
| 2887 | Tcl_WrongNumArgs(interp, 1, objv, "MILLISECONDS"); |
| 2888 | return TCL_ERROR; |
| 2889 | } |
| 2890 | if( Tcl_GetIntFromObj(interp, objv[1], &ms) ){ |
| 2891 | return TCL_ERROR; |
| 2892 | } |
| 2893 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_sleep(ms))); |
| 2894 | return TCL_OK; |
| 2895 | } |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 2896 | |
| 2897 | /* |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 2898 | ** Usage: sqlite3_errcode DB |
| 2899 | ** |
| 2900 | ** Return the string representation of the most recent sqlite3_* API |
| 2901 | ** error code. e.g. "SQLITE_ERROR". |
| 2902 | */ |
| 2903 | static int test_errcode( |
| 2904 | void * clientData, |
| 2905 | Tcl_Interp *interp, |
| 2906 | int objc, |
| 2907 | Tcl_Obj *CONST objv[] |
| 2908 | ){ |
| 2909 | sqlite3 *db; |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 2910 | int rc; |
| 2911 | char zBuf[30]; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 2912 | |
| 2913 | if( objc!=2 ){ |
| 2914 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2915 | Tcl_GetString(objv[0]), " DB", 0); |
| 2916 | return TCL_ERROR; |
| 2917 | } |
| 2918 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 2919 | rc = sqlite3_errcode(db); |
| 2920 | if( (rc&0xff)==rc ){ |
| 2921 | zBuf[0] = 0; |
| 2922 | }else{ |
| 2923 | sprintf(zBuf,"+%d", rc>>8); |
| 2924 | } |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 2925 | Tcl_AppendResult(interp, (char *)t1ErrorName(rc), zBuf, 0); |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 2926 | return TCL_OK; |
| 2927 | } |
| 2928 | |
| 2929 | /* |
| 2930 | ** Usage: test_errmsg DB |
| 2931 | ** |
| 2932 | ** Returns the UTF-8 representation of the error message string for the |
| 2933 | ** most recent sqlite3_* API call. |
| 2934 | */ |
| 2935 | static int test_errmsg( |
| 2936 | void * clientData, |
| 2937 | Tcl_Interp *interp, |
| 2938 | int objc, |
| 2939 | Tcl_Obj *CONST objv[] |
| 2940 | ){ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 2941 | sqlite3 *db; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 2942 | const char *zErr; |
| 2943 | |
| 2944 | if( objc!=2 ){ |
| 2945 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2946 | Tcl_GetString(objv[0]), " DB", 0); |
| 2947 | return TCL_ERROR; |
| 2948 | } |
| 2949 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2950 | |
| 2951 | zErr = sqlite3_errmsg(db); |
| 2952 | Tcl_SetObjResult(interp, Tcl_NewStringObj(zErr, -1)); |
| 2953 | return TCL_OK; |
| 2954 | } |
| 2955 | |
| 2956 | /* |
| 2957 | ** Usage: test_errmsg16 DB |
| 2958 | ** |
| 2959 | ** Returns the UTF-16 representation of the error message string for the |
| 2960 | ** most recent sqlite3_* API call. This is a byte array object at the TCL |
| 2961 | ** level, and it includes the 0x00 0x00 terminator bytes at the end of the |
| 2962 | ** UTF-16 string. |
| 2963 | */ |
| 2964 | static int test_errmsg16( |
| 2965 | void * clientData, |
| 2966 | Tcl_Interp *interp, |
| 2967 | int objc, |
| 2968 | Tcl_Obj *CONST objv[] |
| 2969 | ){ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 2970 | #ifndef SQLITE_OMIT_UTF16 |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 2971 | sqlite3 *db; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 2972 | const void *zErr; |
danielk1977 | 950f054 | 2006-01-18 05:51:57 +0000 | [diff] [blame] | 2973 | int bytes = 0; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 2974 | |
| 2975 | if( objc!=2 ){ |
| 2976 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 2977 | Tcl_GetString(objv[0]), " DB", 0); |
| 2978 | return TCL_ERROR; |
| 2979 | } |
| 2980 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 2981 | |
| 2982 | zErr = sqlite3_errmsg16(db); |
danielk1977 | 950f054 | 2006-01-18 05:51:57 +0000 | [diff] [blame] | 2983 | if( zErr ){ |
drh | ee85813 | 2007-05-08 20:37:38 +0000 | [diff] [blame] | 2984 | bytes = sqlite3Utf16ByteLen(zErr, -1); |
danielk1977 | 950f054 | 2006-01-18 05:51:57 +0000 | [diff] [blame] | 2985 | } |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 2986 | Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(zErr, bytes)); |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 2987 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 2988 | return TCL_OK; |
| 2989 | } |
| 2990 | |
| 2991 | /* |
| 2992 | ** Usage: sqlite3_prepare DB sql bytes tailvar |
| 2993 | ** |
| 2994 | ** Compile up to <bytes> bytes of the supplied SQL string <sql> using |
| 2995 | ** database handle <DB>. The parameter <tailval> is the name of a global |
| 2996 | ** variable that is set to the unused portion of <sql> (if any). A |
| 2997 | ** STMT handle is returned. |
| 2998 | */ |
| 2999 | static int test_prepare( |
| 3000 | void * clientData, |
| 3001 | Tcl_Interp *interp, |
| 3002 | int objc, |
| 3003 | Tcl_Obj *CONST objv[] |
| 3004 | ){ |
| 3005 | sqlite3 *db; |
| 3006 | const char *zSql; |
| 3007 | int bytes; |
| 3008 | const char *zTail = 0; |
| 3009 | sqlite3_stmt *pStmt = 0; |
| 3010 | char zBuf[50]; |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3011 | int rc; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3012 | |
| 3013 | if( objc!=5 ){ |
| 3014 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3015 | Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0); |
| 3016 | return TCL_ERROR; |
| 3017 | } |
| 3018 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 3019 | zSql = Tcl_GetString(objv[2]); |
| 3020 | if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; |
| 3021 | |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3022 | rc = sqlite3_prepare(db, zSql, bytes, &pStmt, &zTail); |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3023 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3024 | if( zTail ){ |
| 3025 | if( bytes>=0 ){ |
| 3026 | bytes = bytes - (zTail-zSql); |
| 3027 | } |
| 3028 | Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0); |
| 3029 | } |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3030 | if( rc!=SQLITE_OK ){ |
| 3031 | assert( pStmt==0 ); |
| 3032 | sprintf(zBuf, "(%d) ", rc); |
| 3033 | Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0); |
| 3034 | return TCL_ERROR; |
| 3035 | } |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3036 | |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3037 | if( pStmt ){ |
drh | 64b1bea | 2006-01-15 02:30:57 +0000 | [diff] [blame] | 3038 | if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3039 | Tcl_AppendResult(interp, zBuf, 0); |
| 3040 | } |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3041 | return TCL_OK; |
| 3042 | } |
| 3043 | |
| 3044 | /* |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 3045 | ** Usage: sqlite3_prepare_v2 DB sql bytes tailvar |
| 3046 | ** |
| 3047 | ** Compile up to <bytes> bytes of the supplied SQL string <sql> using |
| 3048 | ** database handle <DB>. The parameter <tailval> is the name of a global |
| 3049 | ** variable that is set to the unused portion of <sql> (if any). A |
| 3050 | ** STMT handle is returned. |
| 3051 | */ |
| 3052 | static int test_prepare_v2( |
| 3053 | void * clientData, |
| 3054 | Tcl_Interp *interp, |
| 3055 | int objc, |
| 3056 | Tcl_Obj *CONST objv[] |
| 3057 | ){ |
| 3058 | sqlite3 *db; |
| 3059 | const char *zSql; |
| 3060 | int bytes; |
| 3061 | const char *zTail = 0; |
| 3062 | sqlite3_stmt *pStmt = 0; |
| 3063 | char zBuf[50]; |
| 3064 | int rc; |
| 3065 | |
| 3066 | if( objc!=5 ){ |
| 3067 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3068 | Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0); |
| 3069 | return TCL_ERROR; |
| 3070 | } |
| 3071 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 3072 | zSql = Tcl_GetString(objv[2]); |
| 3073 | if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; |
| 3074 | |
| 3075 | rc = sqlite3_prepare_v2(db, zSql, bytes, &pStmt, &zTail); |
danielk1977 | 7e29e95 | 2007-04-19 11:09:01 +0000 | [diff] [blame] | 3076 | assert(rc==SQLITE_OK || pStmt==0); |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 3077 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
| 3078 | if( zTail ){ |
| 3079 | if( bytes>=0 ){ |
| 3080 | bytes = bytes - (zTail-zSql); |
| 3081 | } |
| 3082 | Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0); |
| 3083 | } |
| 3084 | if( rc!=SQLITE_OK ){ |
| 3085 | assert( pStmt==0 ); |
| 3086 | sprintf(zBuf, "(%d) ", rc); |
| 3087 | Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0); |
| 3088 | return TCL_ERROR; |
| 3089 | } |
| 3090 | |
| 3091 | if( pStmt ){ |
| 3092 | if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; |
| 3093 | Tcl_AppendResult(interp, zBuf, 0); |
| 3094 | } |
| 3095 | return TCL_OK; |
| 3096 | } |
| 3097 | |
| 3098 | /* |
| 3099 | ** Usage: sqlite3_prepare16 DB sql bytes tailvar |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3100 | ** |
| 3101 | ** Compile up to <bytes> bytes of the supplied SQL string <sql> using |
| 3102 | ** database handle <DB>. The parameter <tailval> is the name of a global |
| 3103 | ** variable that is set to the unused portion of <sql> (if any). A |
| 3104 | ** STMT handle is returned. |
| 3105 | */ |
| 3106 | static int test_prepare16( |
| 3107 | void * clientData, |
| 3108 | Tcl_Interp *interp, |
| 3109 | int objc, |
| 3110 | Tcl_Obj *CONST objv[] |
| 3111 | ){ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 3112 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3113 | sqlite3 *db; |
| 3114 | const void *zSql; |
| 3115 | const void *zTail = 0; |
| 3116 | Tcl_Obj *pTail = 0; |
| 3117 | sqlite3_stmt *pStmt = 0; |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3118 | char zBuf[50]; |
| 3119 | int rc; |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3120 | int bytes; /* The integer specified as arg 3 */ |
| 3121 | int objlen; /* The byte-array length of arg 2 */ |
| 3122 | |
| 3123 | if( objc!=5 ){ |
| 3124 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3125 | Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0); |
| 3126 | return TCL_ERROR; |
| 3127 | } |
| 3128 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 3129 | zSql = Tcl_GetByteArrayFromObj(objv[2], &objlen); |
| 3130 | if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; |
| 3131 | |
drh | c60d044 | 2004-09-30 13:43:13 +0000 | [diff] [blame] | 3132 | rc = sqlite3_prepare16(db, zSql, bytes, &pStmt, &zTail); |
| 3133 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
| 3134 | if( rc ){ |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3135 | return TCL_ERROR; |
| 3136 | } |
| 3137 | |
| 3138 | if( zTail ){ |
| 3139 | objlen = objlen - ((u8 *)zTail-(u8 *)zSql); |
| 3140 | }else{ |
| 3141 | objlen = 0; |
| 3142 | } |
| 3143 | pTail = Tcl_NewByteArrayObj((u8 *)zTail, objlen); |
| 3144 | Tcl_IncrRefCount(pTail); |
| 3145 | Tcl_ObjSetVar2(interp, objv[4], 0, pTail, 0); |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3146 | Tcl_DecrRefCount(pTail); |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3147 | |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3148 | if( pStmt ){ |
drh | 64b1bea | 2006-01-15 02:30:57 +0000 | [diff] [blame] | 3149 | if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3150 | } |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3151 | Tcl_AppendResult(interp, zBuf, 0); |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 3152 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3153 | return TCL_OK; |
| 3154 | } |
| 3155 | |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3156 | /* |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 3157 | ** Usage: sqlite3_prepare16_v2 DB sql bytes tailvar |
| 3158 | ** |
| 3159 | ** Compile up to <bytes> bytes of the supplied SQL string <sql> using |
| 3160 | ** database handle <DB>. The parameter <tailval> is the name of a global |
| 3161 | ** variable that is set to the unused portion of <sql> (if any). A |
| 3162 | ** STMT handle is returned. |
| 3163 | */ |
| 3164 | static int test_prepare16_v2( |
| 3165 | void * clientData, |
| 3166 | Tcl_Interp *interp, |
| 3167 | int objc, |
| 3168 | Tcl_Obj *CONST objv[] |
| 3169 | ){ |
| 3170 | #ifndef SQLITE_OMIT_UTF16 |
| 3171 | sqlite3 *db; |
| 3172 | const void *zSql; |
| 3173 | const void *zTail = 0; |
| 3174 | Tcl_Obj *pTail = 0; |
| 3175 | sqlite3_stmt *pStmt = 0; |
| 3176 | char zBuf[50]; |
| 3177 | int rc; |
| 3178 | int bytes; /* The integer specified as arg 3 */ |
| 3179 | int objlen; /* The byte-array length of arg 2 */ |
| 3180 | |
| 3181 | if( objc!=5 ){ |
| 3182 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3183 | Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0); |
| 3184 | return TCL_ERROR; |
| 3185 | } |
| 3186 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 3187 | zSql = Tcl_GetByteArrayFromObj(objv[2], &objlen); |
| 3188 | if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; |
| 3189 | |
| 3190 | rc = sqlite3_prepare16_v2(db, zSql, bytes, &pStmt, &zTail); |
| 3191 | if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; |
| 3192 | if( rc ){ |
| 3193 | return TCL_ERROR; |
| 3194 | } |
| 3195 | |
| 3196 | if( zTail ){ |
| 3197 | objlen = objlen - ((u8 *)zTail-(u8 *)zSql); |
| 3198 | }else{ |
| 3199 | objlen = 0; |
| 3200 | } |
| 3201 | pTail = Tcl_NewByteArrayObj((u8 *)zTail, objlen); |
| 3202 | Tcl_IncrRefCount(pTail); |
| 3203 | Tcl_ObjSetVar2(interp, objv[4], 0, pTail, 0); |
| 3204 | Tcl_DecrRefCount(pTail); |
| 3205 | |
| 3206 | if( pStmt ){ |
| 3207 | if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR; |
| 3208 | } |
| 3209 | Tcl_AppendResult(interp, zBuf, 0); |
| 3210 | #endif /* SQLITE_OMIT_UTF16 */ |
| 3211 | return TCL_OK; |
| 3212 | } |
| 3213 | |
| 3214 | /* |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3215 | ** Usage: sqlite3_open filename ?options-list? |
| 3216 | */ |
| 3217 | static int test_open( |
| 3218 | void * clientData, |
| 3219 | Tcl_Interp *interp, |
| 3220 | int objc, |
| 3221 | Tcl_Obj *CONST objv[] |
| 3222 | ){ |
| 3223 | const char *zFilename; |
| 3224 | sqlite3 *db; |
| 3225 | int rc; |
| 3226 | char zBuf[100]; |
| 3227 | |
| 3228 | if( objc!=3 && objc!=2 ){ |
| 3229 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3230 | Tcl_GetString(objv[0]), " filename options-list", 0); |
| 3231 | return TCL_ERROR; |
| 3232 | } |
| 3233 | |
| 3234 | zFilename = Tcl_GetString(objv[1]); |
danielk1977 | 4f057f9 | 2004-06-08 00:02:33 +0000 | [diff] [blame] | 3235 | rc = sqlite3_open(zFilename, &db); |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3236 | |
drh | 64b1bea | 2006-01-15 02:30:57 +0000 | [diff] [blame] | 3237 | if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR; |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3238 | Tcl_AppendResult(interp, zBuf, 0); |
| 3239 | return TCL_OK; |
| 3240 | } |
| 3241 | |
| 3242 | /* |
| 3243 | ** Usage: sqlite3_open16 filename options |
| 3244 | */ |
| 3245 | static int test_open16( |
| 3246 | void * clientData, |
| 3247 | Tcl_Interp *interp, |
| 3248 | int objc, |
| 3249 | Tcl_Obj *CONST objv[] |
| 3250 | ){ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 3251 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3252 | const void *zFilename; |
| 3253 | sqlite3 *db; |
| 3254 | int rc; |
| 3255 | char zBuf[100]; |
| 3256 | |
| 3257 | if( objc!=3 ){ |
| 3258 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3259 | Tcl_GetString(objv[0]), " filename options-list", 0); |
| 3260 | return TCL_ERROR; |
| 3261 | } |
| 3262 | |
| 3263 | zFilename = Tcl_GetByteArrayFromObj(objv[1], 0); |
danielk1977 | 4f057f9 | 2004-06-08 00:02:33 +0000 | [diff] [blame] | 3264 | rc = sqlite3_open16(zFilename, &db); |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3265 | |
drh | 64b1bea | 2006-01-15 02:30:57 +0000 | [diff] [blame] | 3266 | if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR; |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3267 | Tcl_AppendResult(interp, zBuf, 0); |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 3268 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | 4ad1713 | 2004-05-21 01:47:26 +0000 | [diff] [blame] | 3269 | return TCL_OK; |
| 3270 | } |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 3271 | |
| 3272 | /* |
danielk1977 | bc6ada4 | 2004-06-30 08:20:16 +0000 | [diff] [blame] | 3273 | ** Usage: sqlite3_complete16 <UTF-16 string> |
| 3274 | ** |
| 3275 | ** Return 1 if the supplied argument is a complete SQL statement, or zero |
| 3276 | ** otherwise. |
| 3277 | */ |
| 3278 | static int test_complete16( |
| 3279 | void * clientData, |
| 3280 | Tcl_Interp *interp, |
| 3281 | int objc, |
| 3282 | Tcl_Obj *CONST objv[] |
| 3283 | ){ |
drh | ccae602 | 2005-02-26 17:31:26 +0000 | [diff] [blame] | 3284 | #if !defined(SQLITE_OMIT_COMPLETE) && !defined(SQLITE_OMIT_UTF16) |
danielk1977 | bc6ada4 | 2004-06-30 08:20:16 +0000 | [diff] [blame] | 3285 | char *zBuf; |
| 3286 | |
| 3287 | if( objc!=2 ){ |
| 3288 | Tcl_WrongNumArgs(interp, 1, objv, "<utf-16 sql>"); |
| 3289 | return TCL_ERROR; |
| 3290 | } |
| 3291 | |
drh | 03d847e | 2005-12-09 20:21:58 +0000 | [diff] [blame] | 3292 | zBuf = (char*)Tcl_GetByteArrayFromObj(objv[1], 0); |
danielk1977 | bc6ada4 | 2004-06-30 08:20:16 +0000 | [diff] [blame] | 3293 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_complete16(zBuf))); |
drh | ccae602 | 2005-02-26 17:31:26 +0000 | [diff] [blame] | 3294 | #endif /* SQLITE_OMIT_COMPLETE && SQLITE_OMIT_UTF16 */ |
danielk1977 | bc6ada4 | 2004-06-30 08:20:16 +0000 | [diff] [blame] | 3295 | return TCL_OK; |
| 3296 | } |
| 3297 | |
| 3298 | /* |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 3299 | ** Usage: sqlite3_step STMT |
| 3300 | ** |
| 3301 | ** Advance the statement to the next row. |
| 3302 | */ |
danielk1977 | 17240fd | 2004-05-26 00:07:25 +0000 | [diff] [blame] | 3303 | static int test_step( |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 3304 | void * clientData, |
| 3305 | Tcl_Interp *interp, |
| 3306 | int objc, |
| 3307 | Tcl_Obj *CONST objv[] |
| 3308 | ){ |
| 3309 | sqlite3_stmt *pStmt; |
| 3310 | int rc; |
| 3311 | |
danielk1977 | e1cd987 | 2004-05-22 10:33:04 +0000 | [diff] [blame] | 3312 | if( objc!=2 ){ |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 3313 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3314 | Tcl_GetString(objv[0]), " STMT", 0); |
| 3315 | return TCL_ERROR; |
| 3316 | } |
| 3317 | |
| 3318 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
danielk1977 | 17240fd | 2004-05-26 00:07:25 +0000 | [diff] [blame] | 3319 | rc = sqlite3_step(pStmt); |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 3320 | |
danielk1977 | fbcd585 | 2004-06-15 02:44:18 +0000 | [diff] [blame] | 3321 | /* if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; */ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 3322 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0); |
danielk1977 | e1cd987 | 2004-05-22 10:33:04 +0000 | [diff] [blame] | 3323 | return TCL_OK; |
| 3324 | } |
| 3325 | |
| 3326 | /* |
danielk1977 | 17240fd | 2004-05-26 00:07:25 +0000 | [diff] [blame] | 3327 | ** Usage: sqlite3_column_count STMT |
| 3328 | ** |
| 3329 | ** Return the number of columns returned by the sql statement STMT. |
| 3330 | */ |
| 3331 | static int test_column_count( |
| 3332 | void * clientData, |
| 3333 | Tcl_Interp *interp, |
| 3334 | int objc, |
| 3335 | Tcl_Obj *CONST objv[] |
| 3336 | ){ |
| 3337 | sqlite3_stmt *pStmt; |
| 3338 | |
| 3339 | if( objc!=2 ){ |
| 3340 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3341 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 3342 | return TCL_ERROR; |
| 3343 | } |
| 3344 | |
| 3345 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3346 | |
| 3347 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_column_count(pStmt))); |
| 3348 | return TCL_OK; |
| 3349 | } |
| 3350 | |
| 3351 | /* |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 3352 | ** Usage: sqlite3_column_type STMT column |
| 3353 | ** |
| 3354 | ** Return the type of the data in column 'column' of the current row. |
| 3355 | */ |
| 3356 | static int test_column_type( |
| 3357 | void * clientData, |
| 3358 | Tcl_Interp *interp, |
| 3359 | int objc, |
| 3360 | Tcl_Obj *CONST objv[] |
| 3361 | ){ |
| 3362 | sqlite3_stmt *pStmt; |
| 3363 | int col; |
| 3364 | int tp; |
| 3365 | |
| 3366 | if( objc!=3 ){ |
| 3367 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3368 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 3369 | return TCL_ERROR; |
| 3370 | } |
| 3371 | |
| 3372 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3373 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
| 3374 | |
| 3375 | tp = sqlite3_column_type(pStmt, col); |
| 3376 | switch( tp ){ |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 3377 | case SQLITE_INTEGER: |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 3378 | Tcl_SetResult(interp, "INTEGER", TCL_STATIC); |
| 3379 | break; |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 3380 | case SQLITE_NULL: |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 3381 | Tcl_SetResult(interp, "NULL", TCL_STATIC); |
| 3382 | break; |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 3383 | case SQLITE_FLOAT: |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 3384 | Tcl_SetResult(interp, "FLOAT", TCL_STATIC); |
| 3385 | break; |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 3386 | case SQLITE_TEXT: |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 3387 | Tcl_SetResult(interp, "TEXT", TCL_STATIC); |
| 3388 | break; |
drh | 9c05483 | 2004-05-31 18:51:57 +0000 | [diff] [blame] | 3389 | case SQLITE_BLOB: |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 3390 | Tcl_SetResult(interp, "BLOB", TCL_STATIC); |
| 3391 | break; |
| 3392 | default: |
| 3393 | assert(0); |
| 3394 | } |
| 3395 | |
| 3396 | return TCL_OK; |
| 3397 | } |
| 3398 | |
| 3399 | /* |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3400 | ** Usage: sqlite3_column_int64 STMT column |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 3401 | ** |
| 3402 | ** Return the data in column 'column' of the current row cast as an |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3403 | ** wide (64-bit) integer. |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 3404 | */ |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3405 | static int test_column_int64( |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 3406 | void * clientData, |
| 3407 | Tcl_Interp *interp, |
| 3408 | int objc, |
| 3409 | Tcl_Obj *CONST objv[] |
| 3410 | ){ |
| 3411 | sqlite3_stmt *pStmt; |
| 3412 | int col; |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3413 | i64 iVal; |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 3414 | |
| 3415 | if( objc!=3 ){ |
| 3416 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3417 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 3418 | return TCL_ERROR; |
| 3419 | } |
| 3420 | |
| 3421 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3422 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
| 3423 | |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3424 | iVal = sqlite3_column_int64(pStmt, col); |
| 3425 | Tcl_SetObjResult(interp, Tcl_NewWideIntObj(iVal)); |
| 3426 | return TCL_OK; |
| 3427 | } |
| 3428 | |
| 3429 | /* |
danielk1977 | ea61b2c | 2004-05-27 01:49:51 +0000 | [diff] [blame] | 3430 | ** Usage: sqlite3_column_blob STMT column |
| 3431 | */ |
| 3432 | static int test_column_blob( |
| 3433 | void * clientData, |
| 3434 | Tcl_Interp *interp, |
| 3435 | int objc, |
| 3436 | Tcl_Obj *CONST objv[] |
| 3437 | ){ |
| 3438 | sqlite3_stmt *pStmt; |
| 3439 | int col; |
| 3440 | |
| 3441 | int len; |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 3442 | const void *pBlob; |
danielk1977 | ea61b2c | 2004-05-27 01:49:51 +0000 | [diff] [blame] | 3443 | |
| 3444 | if( objc!=3 ){ |
| 3445 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3446 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 3447 | return TCL_ERROR; |
| 3448 | } |
| 3449 | |
| 3450 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3451 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
| 3452 | |
danielk1977 | ea61b2c | 2004-05-27 01:49:51 +0000 | [diff] [blame] | 3453 | len = sqlite3_column_bytes(pStmt, col); |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 3454 | pBlob = sqlite3_column_blob(pStmt, col); |
danielk1977 | ea61b2c | 2004-05-27 01:49:51 +0000 | [diff] [blame] | 3455 | Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pBlob, len)); |
| 3456 | return TCL_OK; |
| 3457 | } |
| 3458 | |
| 3459 | /* |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3460 | ** Usage: sqlite3_column_double STMT column |
| 3461 | ** |
| 3462 | ** Return the data in column 'column' of the current row cast as a double. |
| 3463 | */ |
| 3464 | static int test_column_double( |
| 3465 | void * clientData, |
| 3466 | Tcl_Interp *interp, |
| 3467 | int objc, |
| 3468 | Tcl_Obj *CONST objv[] |
| 3469 | ){ |
| 3470 | sqlite3_stmt *pStmt; |
| 3471 | int col; |
| 3472 | double rVal; |
| 3473 | |
| 3474 | if( objc!=3 ){ |
| 3475 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3476 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 3477 | return TCL_ERROR; |
| 3478 | } |
| 3479 | |
| 3480 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3481 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
| 3482 | |
| 3483 | rVal = sqlite3_column_double(pStmt, col); |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 3484 | Tcl_SetObjResult(interp, Tcl_NewDoubleObj(rVal)); |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 3485 | return TCL_OK; |
| 3486 | } |
| 3487 | |
| 3488 | /* |
danielk1977 | 17240fd | 2004-05-26 00:07:25 +0000 | [diff] [blame] | 3489 | ** Usage: sqlite3_data_count STMT |
| 3490 | ** |
| 3491 | ** Return the number of columns returned by the sql statement STMT. |
| 3492 | */ |
| 3493 | static int test_data_count( |
| 3494 | void * clientData, |
| 3495 | Tcl_Interp *interp, |
| 3496 | int objc, |
| 3497 | Tcl_Obj *CONST objv[] |
| 3498 | ){ |
| 3499 | sqlite3_stmt *pStmt; |
| 3500 | |
| 3501 | if( objc!=2 ){ |
| 3502 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3503 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 3504 | return TCL_ERROR; |
| 3505 | } |
| 3506 | |
| 3507 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3508 | |
| 3509 | Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_data_count(pStmt))); |
| 3510 | return TCL_OK; |
| 3511 | } |
| 3512 | |
| 3513 | /* |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3514 | ** Usage: sqlite3_column_text STMT column |
| 3515 | ** |
| 3516 | ** Usage: sqlite3_column_decltype STMT column |
| 3517 | ** |
| 3518 | ** Usage: sqlite3_column_name STMT column |
| 3519 | */ |
| 3520 | static int test_stmt_utf8( |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3521 | void * clientData, /* Pointer to SQLite API function to be invoke */ |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3522 | Tcl_Interp *interp, |
| 3523 | int objc, |
| 3524 | Tcl_Obj *CONST objv[] |
| 3525 | ){ |
| 3526 | sqlite3_stmt *pStmt; |
| 3527 | int col; |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 3528 | const char *(*xFunc)(sqlite3_stmt*, int) = clientData; |
danielk1977 | f93bbbe | 2004-05-27 10:30:52 +0000 | [diff] [blame] | 3529 | const char *zRet; |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3530 | |
| 3531 | if( objc!=3 ){ |
| 3532 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3533 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 3534 | return TCL_ERROR; |
| 3535 | } |
| 3536 | |
| 3537 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3538 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
danielk1977 | f93bbbe | 2004-05-27 10:30:52 +0000 | [diff] [blame] | 3539 | zRet = xFunc(pStmt, col); |
| 3540 | if( zRet ){ |
| 3541 | Tcl_SetResult(interp, (char *)zRet, 0); |
| 3542 | } |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3543 | return TCL_OK; |
| 3544 | } |
| 3545 | |
danielk1977 | 6b456a2 | 2005-03-21 04:04:02 +0000 | [diff] [blame] | 3546 | static int test_global_recover( |
| 3547 | void * clientData, |
| 3548 | Tcl_Interp *interp, |
| 3549 | int objc, |
| 3550 | Tcl_Obj *CONST objv[] |
| 3551 | ){ |
| 3552 | #ifndef SQLITE_OMIT_GLOBALRECOVER |
| 3553 | int rc; |
| 3554 | if( objc!=1 ){ |
| 3555 | Tcl_WrongNumArgs(interp, 1, objv, ""); |
| 3556 | return TCL_ERROR; |
| 3557 | } |
| 3558 | rc = sqlite3_global_recover(); |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 3559 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 6b456a2 | 2005-03-21 04:04:02 +0000 | [diff] [blame] | 3560 | #endif |
| 3561 | return TCL_OK; |
| 3562 | } |
| 3563 | |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3564 | /* |
| 3565 | ** Usage: sqlite3_column_text STMT column |
| 3566 | ** |
| 3567 | ** Usage: sqlite3_column_decltype STMT column |
| 3568 | ** |
| 3569 | ** Usage: sqlite3_column_name STMT column |
| 3570 | */ |
| 3571 | static int test_stmt_utf16( |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3572 | void * clientData, /* Pointer to SQLite API function to be invoked */ |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3573 | Tcl_Interp *interp, |
| 3574 | int objc, |
| 3575 | Tcl_Obj *CONST objv[] |
| 3576 | ){ |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 3577 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3578 | sqlite3_stmt *pStmt; |
| 3579 | int col; |
| 3580 | Tcl_Obj *pRet; |
| 3581 | const void *zName16; |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 3582 | const void *(*xFunc)(sqlite3_stmt*, int) = clientData; |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3583 | |
| 3584 | if( objc!=3 ){ |
| 3585 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3586 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 3587 | return TCL_ERROR; |
| 3588 | } |
| 3589 | |
| 3590 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3591 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
| 3592 | |
| 3593 | zName16 = xFunc(pStmt, col); |
danielk1977 | f93bbbe | 2004-05-27 10:30:52 +0000 | [diff] [blame] | 3594 | if( zName16 ){ |
drh | ee85813 | 2007-05-08 20:37:38 +0000 | [diff] [blame] | 3595 | pRet = Tcl_NewByteArrayObj(zName16, sqlite3Utf16ByteLen(zName16, -1)+2); |
danielk1977 | f93bbbe | 2004-05-27 10:30:52 +0000 | [diff] [blame] | 3596 | Tcl_SetObjResult(interp, pRet); |
| 3597 | } |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 3598 | #endif /* SQLITE_OMIT_UTF16 */ |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3599 | |
| 3600 | return TCL_OK; |
| 3601 | } |
| 3602 | |
| 3603 | /* |
| 3604 | ** Usage: sqlite3_column_int STMT column |
| 3605 | ** |
| 3606 | ** Usage: sqlite3_column_bytes STMT column |
| 3607 | ** |
| 3608 | ** Usage: sqlite3_column_bytes16 STMT column |
| 3609 | ** |
| 3610 | */ |
| 3611 | static int test_stmt_int( |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 3612 | void * clientData, /* Pointer to SQLite API function to be invoked */ |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3613 | Tcl_Interp *interp, |
| 3614 | int objc, |
| 3615 | Tcl_Obj *CONST objv[] |
| 3616 | ){ |
| 3617 | sqlite3_stmt *pStmt; |
| 3618 | int col; |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 3619 | int (*xFunc)(sqlite3_stmt*, int) = clientData; |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3620 | |
| 3621 | if( objc!=3 ){ |
| 3622 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3623 | Tcl_GetString(objv[0]), " STMT column", 0); |
| 3624 | return TCL_ERROR; |
| 3625 | } |
| 3626 | |
| 3627 | if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; |
| 3628 | if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; |
| 3629 | |
| 3630 | Tcl_SetObjResult(interp, Tcl_NewIntObj(xFunc(pStmt, col))); |
| 3631 | return TCL_OK; |
| 3632 | } |
| 3633 | |
danielk1977 | 44ee5bf | 2005-05-27 09:41:12 +0000 | [diff] [blame] | 3634 | #ifndef SQLITE_OMIT_DISKIO |
danielk1977 | b4b4741 | 2007-08-17 15:53:36 +0000 | [diff] [blame] | 3635 | #if 0 |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3636 | /* |
| 3637 | ** Usage: sqlite3OsOpenReadWrite <filename> |
| 3638 | */ |
| 3639 | static int test_sqlite3OsOpenReadWrite( |
| 3640 | void * clientData, |
| 3641 | Tcl_Interp *interp, |
| 3642 | int objc, |
| 3643 | Tcl_Obj *CONST objv[] |
| 3644 | ){ |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 3645 | sqlite3_file *pFile; |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3646 | int rc; |
| 3647 | int dummy; |
| 3648 | char zBuf[100]; |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 3649 | |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3650 | if( objc!=2 ){ |
| 3651 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3652 | Tcl_GetString(objv[0]), " filename", 0); |
| 3653 | return TCL_ERROR; |
| 3654 | } |
| 3655 | |
drh | 66560ad | 2006-01-06 14:32:19 +0000 | [diff] [blame] | 3656 | rc = sqlite3OsOpenReadWrite(Tcl_GetString(objv[1]), &pFile, &dummy); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3657 | if( rc!=SQLITE_OK ){ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 3658 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3659 | return TCL_ERROR; |
| 3660 | } |
drh | 64b1bea | 2006-01-15 02:30:57 +0000 | [diff] [blame] | 3661 | sqlite3TestMakePointerStr(interp, zBuf, pFile); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3662 | Tcl_SetResult(interp, zBuf, 0); |
| 3663 | return TCL_ERROR; |
| 3664 | } |
| 3665 | |
| 3666 | /* |
| 3667 | ** Usage: sqlite3OsClose <file handle> |
| 3668 | */ |
| 3669 | static int test_sqlite3OsClose( |
| 3670 | void * clientData, |
| 3671 | Tcl_Interp *interp, |
| 3672 | int objc, |
| 3673 | Tcl_Obj *CONST objv[] |
| 3674 | ){ |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 3675 | sqlite3_file *pFile; |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3676 | int rc; |
| 3677 | |
| 3678 | if( objc!=2 ){ |
| 3679 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3680 | Tcl_GetString(objv[0]), " filehandle", 0); |
| 3681 | return TCL_ERROR; |
| 3682 | } |
| 3683 | |
| 3684 | if( getFilePointer(interp, Tcl_GetString(objv[1]), &pFile) ){ |
| 3685 | return TCL_ERROR; |
| 3686 | } |
drh | 054889e | 2005-11-30 03:20:31 +0000 | [diff] [blame] | 3687 | rc = sqlite3OsClose(&pFile); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3688 | if( rc!=SQLITE_OK ){ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 3689 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3690 | return TCL_ERROR; |
| 3691 | } |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3692 | return TCL_OK; |
| 3693 | } |
| 3694 | |
| 3695 | /* |
| 3696 | ** Usage: sqlite3OsLock <file handle> <locktype> |
| 3697 | */ |
| 3698 | static int test_sqlite3OsLock( |
| 3699 | void * clientData, |
| 3700 | Tcl_Interp *interp, |
| 3701 | int objc, |
| 3702 | Tcl_Obj *CONST objv[] |
| 3703 | ){ |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 3704 | sqlite3_file * pFile; |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3705 | int rc; |
| 3706 | |
| 3707 | if( objc!=3 ){ |
| 3708 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3709 | Tcl_GetString(objv[0]), |
| 3710 | " filehandle (SHARED|RESERVED|PENDING|EXCLUSIVE)", 0); |
| 3711 | return TCL_ERROR; |
| 3712 | } |
| 3713 | |
| 3714 | if( getFilePointer(interp, Tcl_GetString(objv[1]), &pFile) ){ |
| 3715 | return TCL_ERROR; |
| 3716 | } |
| 3717 | |
| 3718 | if( 0==strcmp("SHARED", Tcl_GetString(objv[2])) ){ |
drh | 054889e | 2005-11-30 03:20:31 +0000 | [diff] [blame] | 3719 | rc = sqlite3OsLock(pFile, SHARED_LOCK); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3720 | } |
| 3721 | else if( 0==strcmp("RESERVED", Tcl_GetString(objv[2])) ){ |
drh | 054889e | 2005-11-30 03:20:31 +0000 | [diff] [blame] | 3722 | rc = sqlite3OsLock(pFile, RESERVED_LOCK); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3723 | } |
| 3724 | else if( 0==strcmp("PENDING", Tcl_GetString(objv[2])) ){ |
drh | 054889e | 2005-11-30 03:20:31 +0000 | [diff] [blame] | 3725 | rc = sqlite3OsLock(pFile, PENDING_LOCK); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3726 | } |
| 3727 | else if( 0==strcmp("EXCLUSIVE", Tcl_GetString(objv[2])) ){ |
drh | 054889e | 2005-11-30 03:20:31 +0000 | [diff] [blame] | 3728 | rc = sqlite3OsLock(pFile, EXCLUSIVE_LOCK); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3729 | }else{ |
| 3730 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3731 | Tcl_GetString(objv[0]), |
| 3732 | " filehandle (SHARED|RESERVED|PENDING|EXCLUSIVE)", 0); |
| 3733 | return TCL_ERROR; |
| 3734 | } |
| 3735 | |
| 3736 | if( rc!=SQLITE_OK ){ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 3737 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3738 | return TCL_ERROR; |
| 3739 | } |
| 3740 | return TCL_OK; |
| 3741 | } |
| 3742 | |
| 3743 | /* |
| 3744 | ** Usage: sqlite3OsUnlock <file handle> |
| 3745 | */ |
| 3746 | static int test_sqlite3OsUnlock( |
| 3747 | void * clientData, |
| 3748 | Tcl_Interp *interp, |
| 3749 | int objc, |
| 3750 | Tcl_Obj *CONST objv[] |
| 3751 | ){ |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 3752 | sqlite3_file * pFile; |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3753 | int rc; |
| 3754 | |
| 3755 | if( objc!=2 ){ |
| 3756 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 3757 | Tcl_GetString(objv[0]), " filehandle", 0); |
| 3758 | return TCL_ERROR; |
| 3759 | } |
| 3760 | |
| 3761 | if( getFilePointer(interp, Tcl_GetString(objv[1]), &pFile) ){ |
| 3762 | return TCL_ERROR; |
| 3763 | } |
drh | 054889e | 2005-11-30 03:20:31 +0000 | [diff] [blame] | 3764 | rc = sqlite3OsUnlock(pFile, NO_LOCK); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3765 | if( rc!=SQLITE_OK ){ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 3766 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 3767 | return TCL_ERROR; |
| 3768 | } |
| 3769 | return TCL_OK; |
| 3770 | } |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 3771 | |
drh | ab3f9fe | 2004-08-14 17:10:10 +0000 | [diff] [blame] | 3772 | /* |
| 3773 | ** Usage: sqlite3OsTempFileName |
| 3774 | */ |
| 3775 | static int test_sqlite3OsTempFileName( |
| 3776 | void * clientData, |
| 3777 | Tcl_Interp *interp, |
| 3778 | int objc, |
| 3779 | Tcl_Obj *CONST objv[] |
| 3780 | ){ |
| 3781 | char zFile[SQLITE_TEMPNAME_SIZE]; |
| 3782 | int rc; |
| 3783 | |
drh | 66560ad | 2006-01-06 14:32:19 +0000 | [diff] [blame] | 3784 | rc = sqlite3OsTempFileName(zFile); |
drh | ab3f9fe | 2004-08-14 17:10:10 +0000 | [diff] [blame] | 3785 | if( rc!=SQLITE_OK ){ |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 3786 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
drh | ab3f9fe | 2004-08-14 17:10:10 +0000 | [diff] [blame] | 3787 | return TCL_ERROR; |
| 3788 | } |
| 3789 | Tcl_AppendResult(interp, zFile, 0); |
| 3790 | return TCL_OK; |
| 3791 | } |
danielk1977 | 44ee5bf | 2005-05-27 09:41:12 +0000 | [diff] [blame] | 3792 | #endif |
danielk1977 | b4b4741 | 2007-08-17 15:53:36 +0000 | [diff] [blame] | 3793 | #endif |
danielk1977 | d812336 | 2004-06-12 09:25:12 +0000 | [diff] [blame] | 3794 | |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 3795 | /* |
drh | cacb208 | 2005-01-11 15:28:33 +0000 | [diff] [blame] | 3796 | ** Usage: sqlite_set_magic DB MAGIC-NUMBER |
| 3797 | ** |
| 3798 | ** Set the db->magic value. This is used to test error recovery logic. |
| 3799 | */ |
| 3800 | static int sqlite_set_magic( |
| 3801 | void * clientData, |
| 3802 | Tcl_Interp *interp, |
| 3803 | int argc, |
| 3804 | char **argv |
| 3805 | ){ |
| 3806 | sqlite3 *db; |
| 3807 | if( argc!=3 ){ |
| 3808 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 3809 | " DB MAGIC", 0); |
| 3810 | return TCL_ERROR; |
| 3811 | } |
| 3812 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 3813 | if( strcmp(argv[2], "SQLITE_MAGIC_OPEN")==0 ){ |
| 3814 | db->magic = SQLITE_MAGIC_OPEN; |
| 3815 | }else if( strcmp(argv[2], "SQLITE_MAGIC_CLOSED")==0 ){ |
| 3816 | db->magic = SQLITE_MAGIC_CLOSED; |
| 3817 | }else if( strcmp(argv[2], "SQLITE_MAGIC_BUSY")==0 ){ |
| 3818 | db->magic = SQLITE_MAGIC_BUSY; |
| 3819 | }else if( strcmp(argv[2], "SQLITE_MAGIC_ERROR")==0 ){ |
| 3820 | db->magic = SQLITE_MAGIC_ERROR; |
| 3821 | }else if( Tcl_GetInt(interp, argv[2], &db->magic) ){ |
| 3822 | return TCL_ERROR; |
| 3823 | } |
| 3824 | return TCL_OK; |
| 3825 | } |
| 3826 | |
| 3827 | /* |
drh | c5cdca6 | 2005-01-11 16:54:14 +0000 | [diff] [blame] | 3828 | ** Usage: sqlite3_interrupt DB |
| 3829 | ** |
| 3830 | ** Trigger an interrupt on DB |
| 3831 | */ |
| 3832 | static int test_interrupt( |
| 3833 | void * clientData, |
| 3834 | Tcl_Interp *interp, |
| 3835 | int argc, |
| 3836 | char **argv |
| 3837 | ){ |
| 3838 | sqlite3 *db; |
| 3839 | if( argc!=2 ){ |
| 3840 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB", 0); |
| 3841 | return TCL_ERROR; |
| 3842 | } |
| 3843 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 3844 | sqlite3_interrupt(db); |
| 3845 | return TCL_OK; |
| 3846 | } |
| 3847 | |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 3848 | static u8 *sqlite3_stack_baseline = 0; |
| 3849 | |
drh | c5cdca6 | 2005-01-11 16:54:14 +0000 | [diff] [blame] | 3850 | /* |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 3851 | ** Fill the stack with a known bitpattern. |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 3852 | */ |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 3853 | static void prepStack(void){ |
| 3854 | int i; |
| 3855 | u32 bigBuf[65536]; |
| 3856 | for(i=0; i<sizeof(bigBuf); i++) bigBuf[i] = 0xdeadbeef; |
| 3857 | sqlite3_stack_baseline = (u8*)&bigBuf[65536]; |
| 3858 | } |
| 3859 | |
| 3860 | /* |
| 3861 | ** Get the current stack depth. Used for debugging only. |
| 3862 | */ |
| 3863 | u64 sqlite3StackDepth(void){ |
| 3864 | u8 x; |
| 3865 | return (u64)(sqlite3_stack_baseline - &x); |
| 3866 | } |
| 3867 | |
| 3868 | /* |
| 3869 | ** Usage: sqlite3_stack_used DB SQL |
| 3870 | ** |
| 3871 | ** Try to measure the amount of stack space used by a call to sqlite3_exec |
| 3872 | */ |
| 3873 | static int test_stack_used( |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 3874 | void * clientData, |
| 3875 | Tcl_Interp *interp, |
| 3876 | int argc, |
| 3877 | char **argv |
| 3878 | ){ |
| 3879 | sqlite3 *db; |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 3880 | int i; |
| 3881 | if( argc!=3 ){ |
| 3882 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 3883 | " DB SQL", 0); |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 3884 | return TCL_ERROR; |
| 3885 | } |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 3886 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 3887 | prepStack(); |
drh | 3752785 | 2006-03-16 16:19:56 +0000 | [diff] [blame] | 3888 | (void)sqlite3_exec(db, argv[2], 0, 0, 0); |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 3889 | for(i=65535; i>=0 && ((u32*)sqlite3_stack_baseline)[-i]==0xdeadbeef; i--){} |
| 3890 | Tcl_SetObjResult(interp, Tcl_NewIntObj(i*4)); |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 3891 | return TCL_OK; |
| 3892 | } |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 3893 | |
| 3894 | /* |
danielk1977 | 9636c4e | 2005-01-25 04:27:54 +0000 | [diff] [blame] | 3895 | ** Usage: sqlite_delete_function DB function-name |
| 3896 | ** |
| 3897 | ** Delete the user function 'function-name' from database handle DB. It |
| 3898 | ** is assumed that the user function was created as UTF8, any number of |
| 3899 | ** arguments (the way the TCL interface does it). |
| 3900 | */ |
| 3901 | static int delete_function( |
| 3902 | void * clientData, |
| 3903 | Tcl_Interp *interp, |
| 3904 | int argc, |
| 3905 | char **argv |
| 3906 | ){ |
| 3907 | int rc; |
| 3908 | sqlite3 *db; |
| 3909 | if( argc!=3 ){ |
| 3910 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 3911 | " DB function-name", 0); |
| 3912 | return TCL_ERROR; |
| 3913 | } |
| 3914 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 3915 | 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] | 3916 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 9636c4e | 2005-01-25 04:27:54 +0000 | [diff] [blame] | 3917 | return TCL_OK; |
| 3918 | } |
| 3919 | |
| 3920 | /* |
| 3921 | ** Usage: sqlite_delete_collation DB collation-name |
| 3922 | ** |
| 3923 | ** Delete the collation sequence 'collation-name' from database handle |
| 3924 | ** DB. It is assumed that the collation sequence was created as UTF8 (the |
| 3925 | ** way the TCL interface does it). |
| 3926 | */ |
| 3927 | static int delete_collation( |
| 3928 | void * clientData, |
| 3929 | Tcl_Interp *interp, |
| 3930 | int argc, |
| 3931 | char **argv |
| 3932 | ){ |
| 3933 | int rc; |
| 3934 | sqlite3 *db; |
| 3935 | if( argc!=3 ){ |
| 3936 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 3937 | " DB function-name", 0); |
| 3938 | return TCL_ERROR; |
| 3939 | } |
| 3940 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 3941 | rc = sqlite3_create_collation(db, argv[2], SQLITE_UTF8, 0, 0); |
drh | 4f0c587 | 2007-03-26 22:05:01 +0000 | [diff] [blame] | 3942 | Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC); |
danielk1977 | 9636c4e | 2005-01-25 04:27:54 +0000 | [diff] [blame] | 3943 | return TCL_OK; |
| 3944 | } |
| 3945 | |
| 3946 | /* |
drh | 3e1d8e6 | 2005-05-26 16:23:34 +0000 | [diff] [blame] | 3947 | ** Usage: sqlite3_get_autocommit DB |
| 3948 | ** |
| 3949 | ** Return true if the database DB is currently in auto-commit mode. |
| 3950 | ** Return false if not. |
| 3951 | */ |
| 3952 | static int get_autocommit( |
| 3953 | void * clientData, |
| 3954 | Tcl_Interp *interp, |
| 3955 | int argc, |
| 3956 | char **argv |
| 3957 | ){ |
| 3958 | char zBuf[30]; |
| 3959 | sqlite3 *db; |
| 3960 | if( argc!=2 ){ |
| 3961 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 3962 | " DB", 0); |
| 3963 | return TCL_ERROR; |
| 3964 | } |
| 3965 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 3966 | sprintf(zBuf, "%d", sqlite3_get_autocommit(db)); |
| 3967 | Tcl_AppendResult(interp, zBuf, 0); |
| 3968 | return TCL_OK; |
| 3969 | } |
| 3970 | |
| 3971 | /* |
drh | 3086765 | 2006-07-06 10:59:57 +0000 | [diff] [blame] | 3972 | ** Usage: sqlite3_busy_timeout DB MS |
| 3973 | ** |
| 3974 | ** Set the busy timeout. This is more easily done using the timeout |
| 3975 | ** method of the TCL interface. But we need a way to test the case |
| 3976 | ** where it returns SQLITE_MISUSE. |
| 3977 | */ |
| 3978 | static int test_busy_timeout( |
| 3979 | void * clientData, |
| 3980 | Tcl_Interp *interp, |
| 3981 | int argc, |
| 3982 | char **argv |
| 3983 | ){ |
| 3984 | int rc, ms; |
| 3985 | sqlite3 *db; |
| 3986 | if( argc!=3 ){ |
| 3987 | Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 3988 | " DB", 0); |
| 3989 | return TCL_ERROR; |
| 3990 | } |
| 3991 | if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; |
| 3992 | if( Tcl_GetInt(interp, argv[2], &ms) ) return TCL_ERROR; |
| 3993 | rc = sqlite3_busy_timeout(db, ms); |
| 3994 | Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0); |
| 3995 | return TCL_OK; |
| 3996 | } |
| 3997 | |
| 3998 | /* |
drh | 92febd9 | 2004-08-20 18:34:20 +0000 | [diff] [blame] | 3999 | ** Usage: tcl_variable_type VARIABLENAME |
| 4000 | ** |
| 4001 | ** Return the name of the internal representation for the |
| 4002 | ** value of the given variable. |
| 4003 | */ |
| 4004 | static int tcl_variable_type( |
| 4005 | void * clientData, |
| 4006 | Tcl_Interp *interp, |
| 4007 | int objc, |
| 4008 | Tcl_Obj *CONST objv[] |
| 4009 | ){ |
| 4010 | Tcl_Obj *pVar; |
| 4011 | if( objc!=2 ){ |
| 4012 | Tcl_WrongNumArgs(interp, 1, objv, "VARIABLE"); |
| 4013 | return TCL_ERROR; |
| 4014 | } |
| 4015 | pVar = Tcl_GetVar2Ex(interp, Tcl_GetString(objv[1]), 0, TCL_LEAVE_ERR_MSG); |
| 4016 | if( pVar==0 ) return TCL_ERROR; |
| 4017 | if( pVar->typePtr ){ |
| 4018 | Tcl_SetObjResult(interp, Tcl_NewStringObj(pVar->typePtr->name, -1)); |
| 4019 | } |
| 4020 | return TCL_OK; |
| 4021 | } |
| 4022 | |
| 4023 | /* |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 4024 | ** Usage: sqlite3_release_memory ?N? |
| 4025 | ** |
| 4026 | ** Attempt to release memory currently held but not actually required. |
| 4027 | ** The integer N is the number of bytes we are trying to release. The |
| 4028 | ** return value is the amount of memory actually released. |
| 4029 | */ |
| 4030 | static int test_release_memory( |
| 4031 | void * clientData, |
| 4032 | Tcl_Interp *interp, |
| 4033 | int objc, |
| 4034 | Tcl_Obj *CONST objv[] |
| 4035 | ){ |
drh | 6f7adc8 | 2006-01-11 21:41:20 +0000 | [diff] [blame] | 4036 | #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO) |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 4037 | int N; |
| 4038 | int amt; |
| 4039 | if( objc!=1 && objc!=2 ){ |
| 4040 | Tcl_WrongNumArgs(interp, 1, objv, "?N?"); |
| 4041 | return TCL_ERROR; |
| 4042 | } |
| 4043 | if( objc==2 ){ |
| 4044 | if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR; |
| 4045 | }else{ |
| 4046 | N = -1; |
| 4047 | } |
| 4048 | amt = sqlite3_release_memory(N); |
| 4049 | Tcl_SetObjResult(interp, Tcl_NewIntObj(amt)); |
| 4050 | #endif |
| 4051 | return TCL_OK; |
| 4052 | } |
| 4053 | |
| 4054 | /* |
| 4055 | ** Usage: sqlite3_soft_heap_limit ?N? |
| 4056 | ** |
| 4057 | ** Query or set the soft heap limit for the current thread. The |
| 4058 | ** limit is only changed if the N is present. The previous limit |
| 4059 | ** is returned. |
| 4060 | */ |
| 4061 | static int test_soft_heap_limit( |
| 4062 | void * clientData, |
| 4063 | Tcl_Interp *interp, |
| 4064 | int objc, |
| 4065 | Tcl_Obj *CONST objv[] |
| 4066 | ){ |
drh | 86f8c19 | 2007-08-22 00:39:19 +0000 | [diff] [blame] | 4067 | static int softHeapLimit = 0; |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 4068 | int amt; |
| 4069 | if( objc!=1 && objc!=2 ){ |
| 4070 | Tcl_WrongNumArgs(interp, 1, objv, "?N?"); |
| 4071 | return TCL_ERROR; |
| 4072 | } |
drh | 86f8c19 | 2007-08-22 00:39:19 +0000 | [diff] [blame] | 4073 | amt = softHeapLimit; |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 4074 | if( objc==2 ){ |
| 4075 | int N; |
| 4076 | if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR; |
| 4077 | sqlite3_soft_heap_limit(N); |
drh | 86f8c19 | 2007-08-22 00:39:19 +0000 | [diff] [blame] | 4078 | softHeapLimit = N; |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 4079 | } |
| 4080 | Tcl_SetObjResult(interp, Tcl_NewIntObj(amt)); |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 4081 | return TCL_OK; |
| 4082 | } |
| 4083 | |
| 4084 | /* |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 4085 | ** Usage: sqlite3_clear_tsd_memdebug |
| 4086 | ** |
| 4087 | ** Clear all of the MEMDEBUG information out of thread-specific data. |
| 4088 | ** This will allow it to be deallocated. |
| 4089 | */ |
| 4090 | static int test_clear_tsd_memdebug( |
| 4091 | void * clientData, |
| 4092 | Tcl_Interp *interp, |
| 4093 | int objc, |
| 4094 | Tcl_Obj *CONST objv[] |
| 4095 | ){ |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 4096 | return TCL_OK; |
| 4097 | } |
| 4098 | |
| 4099 | /* |
| 4100 | ** Usage: sqlite3_tsd_release |
| 4101 | ** |
| 4102 | ** Call sqlite3ReleaseThreadData. |
| 4103 | */ |
| 4104 | static int test_tsd_release( |
| 4105 | void * clientData, |
| 4106 | Tcl_Interp *interp, |
| 4107 | int objc, |
| 4108 | Tcl_Obj *CONST objv[] |
| 4109 | ){ |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 4110 | return TCL_OK; |
| 4111 | } |
| 4112 | |
| 4113 | /* |
| 4114 | ** Usage: sqlite3_thread_cleanup |
| 4115 | ** |
| 4116 | ** Call the sqlite3_thread_cleanup API. |
| 4117 | */ |
| 4118 | static int test_thread_cleanup( |
| 4119 | void * clientData, |
| 4120 | Tcl_Interp *interp, |
| 4121 | int objc, |
| 4122 | Tcl_Obj *CONST objv[] |
| 4123 | ){ |
| 4124 | sqlite3_thread_cleanup(); |
| 4125 | return TCL_OK; |
| 4126 | } |
| 4127 | |
| 4128 | |
| 4129 | /* |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 4130 | ** Usage: sqlite3_pager_refcounts DB |
| 4131 | ** |
drh | f534544 | 2007-04-09 12:45:02 +0000 | [diff] [blame] | 4132 | ** Return a list of numbers which are the PagerRefcount for all |
| 4133 | ** pagers on each database connection. |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 4134 | */ |
| 4135 | static int test_pager_refcounts( |
| 4136 | void * clientData, |
| 4137 | Tcl_Interp *interp, |
| 4138 | int objc, |
| 4139 | Tcl_Obj *CONST objv[] |
| 4140 | ){ |
| 4141 | sqlite3 *db; |
| 4142 | int i; |
| 4143 | int v, *a; |
| 4144 | Tcl_Obj *pResult; |
| 4145 | |
| 4146 | if( objc!=2 ){ |
| 4147 | Tcl_AppendResult(interp, "wrong # args: should be \"", |
drh | f534544 | 2007-04-09 12:45:02 +0000 | [diff] [blame] | 4148 | Tcl_GetStringFromObj(objv[0], 0), " DB", 0); |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 4149 | return TCL_ERROR; |
| 4150 | } |
| 4151 | if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; |
| 4152 | pResult = Tcl_NewObj(); |
| 4153 | for(i=0; i<db->nDb; i++){ |
| 4154 | if( db->aDb[i].pBt==0 ){ |
| 4155 | v = -1; |
| 4156 | }else{ |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 4157 | sqlite3_mutex_enter(db->mutex); |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 4158 | a = sqlite3PagerStats(sqlite3BtreePager(db->aDb[i].pBt)); |
| 4159 | v = a[0]; |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 4160 | sqlite3_mutex_leave(db->mutex); |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 4161 | } |
| 4162 | Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(v)); |
| 4163 | } |
| 4164 | Tcl_SetObjResult(interp, pResult); |
| 4165 | return TCL_OK; |
| 4166 | } |
| 4167 | |
| 4168 | |
| 4169 | /* |
drh | 80788d8 | 2006-09-02 14:50:23 +0000 | [diff] [blame] | 4170 | ** tclcmd: working_64bit_int |
| 4171 | ** |
| 4172 | ** Some TCL builds (ex: cygwin) do not support 64-bit integers. This |
| 4173 | ** leads to a number of test failures. The present command checks the |
| 4174 | ** TCL build to see whether or not it supports 64-bit integers. It |
| 4175 | ** returns TRUE if it does and FALSE if not. |
| 4176 | ** |
| 4177 | ** This command is used to warn users that their TCL build is defective |
| 4178 | ** and that the errors they are seeing in the test scripts might be |
| 4179 | ** a result of their defective TCL rather than problems in SQLite. |
| 4180 | */ |
| 4181 | static int working_64bit_int( |
| 4182 | ClientData clientData, /* Pointer to sqlite3_enable_XXX function */ |
| 4183 | Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ |
| 4184 | int objc, /* Number of arguments */ |
| 4185 | Tcl_Obj *CONST objv[] /* Command arguments */ |
| 4186 | ){ |
| 4187 | Tcl_Obj *pTestObj; |
| 4188 | int working = 0; |
| 4189 | |
| 4190 | pTestObj = Tcl_NewWideIntObj(1000000*(i64)1234567890); |
| 4191 | working = strcmp(Tcl_GetString(pTestObj), "1234567890000000")==0; |
| 4192 | Tcl_DecrRefCount(pTestObj); |
| 4193 | Tcl_SetObjResult(interp, Tcl_NewBooleanObj(working)); |
| 4194 | return TCL_OK; |
| 4195 | } |
| 4196 | |
| 4197 | |
| 4198 | /* |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 4199 | ** Register commands with the TCL interpreter. |
| 4200 | */ |
| 4201 | int Sqlitetest1_Init(Tcl_Interp *interp){ |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 4202 | extern int sqlite3_search_count; |
| 4203 | extern int sqlite3_interrupt_count; |
| 4204 | extern int sqlite3_open_file_count; |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame] | 4205 | extern int sqlite3_sort_count; |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 4206 | extern int sqlite3_current_time; |
drh | ae7e151 | 2007-05-02 16:51:59 +0000 | [diff] [blame] | 4207 | extern int sqlite3_max_blobsize; |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 4208 | extern int sqlite3BtreeSharedCacheReport(void*, |
| 4209 | Tcl_Interp*,int,Tcl_Obj*CONST*); |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 4210 | static struct { |
| 4211 | char *zName; |
| 4212 | Tcl_CmdProc *xProc; |
| 4213 | } aCmd[] = { |
drh | 2764170 | 2007-08-22 02:56:42 +0000 | [diff] [blame] | 4214 | { "db_enter", (Tcl_CmdProc*)db_enter }, |
| 4215 | { "db_leave", (Tcl_CmdProc*)db_leave }, |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 4216 | { "sqlite3_mprintf_int", (Tcl_CmdProc*)sqlite3_mprintf_int }, |
drh | e970767 | 2004-06-25 01:10:48 +0000 | [diff] [blame] | 4217 | { "sqlite3_mprintf_int64", (Tcl_CmdProc*)sqlite3_mprintf_int64 }, |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 4218 | { "sqlite3_mprintf_str", (Tcl_CmdProc*)sqlite3_mprintf_str }, |
drh | b3738b6 | 2007-03-31 15:02:49 +0000 | [diff] [blame] | 4219 | { "sqlite3_snprintf_str", (Tcl_CmdProc*)sqlite3_snprintf_str }, |
drh | e29b1a0 | 2004-07-17 21:56:09 +0000 | [diff] [blame] | 4220 | { "sqlite3_mprintf_stronly", (Tcl_CmdProc*)sqlite3_mprintf_stronly}, |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 4221 | { "sqlite3_mprintf_double", (Tcl_CmdProc*)sqlite3_mprintf_double }, |
| 4222 | { "sqlite3_mprintf_scaled", (Tcl_CmdProc*)sqlite3_mprintf_scaled }, |
drh | 6378285 | 2005-08-30 19:30:59 +0000 | [diff] [blame] | 4223 | { "sqlite3_mprintf_hexdouble", (Tcl_CmdProc*)sqlite3_mprintf_hexdouble}, |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 4224 | { "sqlite3_mprintf_z_test", (Tcl_CmdProc*)test_mprintf_z }, |
drh | 05a8298 | 2006-03-19 13:00:25 +0000 | [diff] [blame] | 4225 | { "sqlite3_mprintf_n_test", (Tcl_CmdProc*)test_mprintf_n }, |
drh | 6885390 | 2007-05-07 11:24:30 +0000 | [diff] [blame] | 4226 | { "sqlite3_snprintf_int", (Tcl_CmdProc*)test_snprintf_int }, |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 4227 | { "sqlite3_last_insert_rowid", (Tcl_CmdProc*)test_last_rowid }, |
| 4228 | { "sqlite3_exec_printf", (Tcl_CmdProc*)test_exec_printf }, |
drh | b62c335 | 2006-11-23 09:39:16 +0000 | [diff] [blame] | 4229 | { "sqlite3_exec", (Tcl_CmdProc*)test_exec }, |
| 4230 | { "sqlite3_exec_nr", (Tcl_CmdProc*)test_exec_nr }, |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 4231 | { "sqlite3_get_table_printf", (Tcl_CmdProc*)test_get_table_printf }, |
| 4232 | { "sqlite3_close", (Tcl_CmdProc*)sqlite_test_close }, |
| 4233 | { "sqlite3_create_function", (Tcl_CmdProc*)test_create_function }, |
| 4234 | { "sqlite3_create_aggregate", (Tcl_CmdProc*)test_create_aggregate }, |
| 4235 | { "sqlite_register_test_function", (Tcl_CmdProc*)test_register_func }, |
| 4236 | { "sqlite_abort", (Tcl_CmdProc*)sqlite_abort }, |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 4237 | { "sqlite_bind", (Tcl_CmdProc*)test_bind }, |
| 4238 | { "breakpoint", (Tcl_CmdProc*)test_breakpoint }, |
| 4239 | { "sqlite3_key", (Tcl_CmdProc*)test_key }, |
| 4240 | { "sqlite3_rekey", (Tcl_CmdProc*)test_rekey }, |
drh | cacb208 | 2005-01-11 15:28:33 +0000 | [diff] [blame] | 4241 | { "sqlite_set_magic", (Tcl_CmdProc*)sqlite_set_magic }, |
drh | c5cdca6 | 2005-01-11 16:54:14 +0000 | [diff] [blame] | 4242 | { "sqlite3_interrupt", (Tcl_CmdProc*)test_interrupt }, |
drh | 3e1d8e6 | 2005-05-26 16:23:34 +0000 | [diff] [blame] | 4243 | { "sqlite_delete_function", (Tcl_CmdProc*)delete_function }, |
| 4244 | { "sqlite_delete_collation", (Tcl_CmdProc*)delete_collation }, |
| 4245 | { "sqlite3_get_autocommit", (Tcl_CmdProc*)get_autocommit }, |
drh | 79158e1 | 2005-09-06 21:40:45 +0000 | [diff] [blame] | 4246 | { "sqlite3_stack_used", (Tcl_CmdProc*)test_stack_used }, |
drh | 3086765 | 2006-07-06 10:59:57 +0000 | [diff] [blame] | 4247 | { "sqlite3_busy_timeout", (Tcl_CmdProc*)test_busy_timeout }, |
drh | 3c23a88 | 2007-01-09 14:01:13 +0000 | [diff] [blame] | 4248 | { "printf", (Tcl_CmdProc*)test_printf }, |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 4249 | { "sqlite3_io_trace", (Tcl_CmdProc*)test_io_trace }, |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 4250 | }; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 4251 | static struct { |
| 4252 | char *zName; |
| 4253 | Tcl_ObjCmdProc *xProc; |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4254 | void *clientData; |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 4255 | } aObjCmd[] = { |
drh | dddca28 | 2006-01-03 00:33:50 +0000 | [diff] [blame] | 4256 | { "sqlite3_connection_pointer", get_sqlite_pointer, 0 }, |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 4257 | { "sqlite3_bind_int", test_bind_int, 0 }, |
drh | b026e05 | 2007-05-02 01:34:31 +0000 | [diff] [blame] | 4258 | { "sqlite3_bind_zeroblob", test_bind_zeroblob, 0 }, |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 4259 | { "sqlite3_bind_int64", test_bind_int64, 0 }, |
| 4260 | { "sqlite3_bind_double", test_bind_double, 0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4261 | { "sqlite3_bind_null", test_bind_null ,0 }, |
| 4262 | { "sqlite3_bind_text", test_bind_text ,0 }, |
| 4263 | { "sqlite3_bind_text16", test_bind_text16 ,0 }, |
| 4264 | { "sqlite3_bind_blob", test_bind_blob ,0 }, |
drh | 75f6a03 | 2004-07-15 14:15:00 +0000 | [diff] [blame] | 4265 | { "sqlite3_bind_parameter_count", test_bind_parameter_count, 0}, |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 4266 | { "sqlite3_bind_parameter_name", test_bind_parameter_name, 0}, |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 4267 | { "sqlite3_bind_parameter_index", test_bind_parameter_index, 0}, |
danielk1977 | 600dd0b | 2005-01-20 01:14:23 +0000 | [diff] [blame] | 4268 | { "sqlite3_clear_bindings", test_clear_bindings, 0}, |
drh | f9cb7f5 | 2006-06-27 20:06:44 +0000 | [diff] [blame] | 4269 | { "sqlite3_sleep", test_sleep, 0}, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4270 | { "sqlite3_errcode", test_errcode ,0 }, |
| 4271 | { "sqlite3_errmsg", test_errmsg ,0 }, |
| 4272 | { "sqlite3_errmsg16", test_errmsg16 ,0 }, |
| 4273 | { "sqlite3_open", test_open ,0 }, |
| 4274 | { "sqlite3_open16", test_open16 ,0 }, |
danielk1977 | bc6ada4 | 2004-06-30 08:20:16 +0000 | [diff] [blame] | 4275 | { "sqlite3_complete16", test_complete16 ,0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4276 | |
| 4277 | { "sqlite3_prepare", test_prepare ,0 }, |
| 4278 | { "sqlite3_prepare16", test_prepare16 ,0 }, |
drh | b900aaf | 2006-11-09 00:24:53 +0000 | [diff] [blame] | 4279 | { "sqlite3_prepare_v2", test_prepare_v2 ,0 }, |
| 4280 | { "sqlite3_prepare16_v2", test_prepare16_v2 ,0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4281 | { "sqlite3_finalize", test_finalize ,0 }, |
| 4282 | { "sqlite3_reset", test_reset ,0 }, |
drh | d89bd00 | 2005-01-22 03:03:54 +0000 | [diff] [blame] | 4283 | { "sqlite3_expired", test_expired ,0 }, |
drh | f8db1bc | 2005-04-22 02:38:37 +0000 | [diff] [blame] | 4284 | { "sqlite3_transfer_bindings", test_transfer_bind ,0 }, |
danielk1977 | fbcd585 | 2004-06-15 02:44:18 +0000 | [diff] [blame] | 4285 | { "sqlite3_changes", test_changes ,0 }, |
| 4286 | { "sqlite3_step", test_step ,0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4287 | |
drh | b4bc705 | 2006-01-11 23:40:33 +0000 | [diff] [blame] | 4288 | { "sqlite3_release_memory", test_release_memory, 0}, |
| 4289 | { "sqlite3_soft_heap_limit", test_soft_heap_limit, 0}, |
| 4290 | { "sqlite3_clear_tsd_memdebug", test_clear_tsd_memdebug, 0}, |
| 4291 | { "sqlite3_tsd_release", test_tsd_release, 0}, |
| 4292 | { "sqlite3_thread_cleanup", test_thread_cleanup, 0}, |
drh | c6ba55f | 2007-04-05 17:36:18 +0000 | [diff] [blame] | 4293 | { "sqlite3_pager_refcounts", test_pager_refcounts, 0}, |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 4294 | |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 4295 | { "sqlite3_load_extension", test_load_extension, 0}, |
| 4296 | { "sqlite3_enable_load_extension", test_enable_load, 0}, |
drh | 4ac285a | 2006-09-15 07:28:50 +0000 | [diff] [blame] | 4297 | { "sqlite3_extended_result_codes", test_extended_result_codes, 0}, |
drh | c2e87a3 | 2006-06-27 15:16:14 +0000 | [diff] [blame] | 4298 | |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4299 | /* sqlite3_column_*() API */ |
| 4300 | { "sqlite3_column_count", test_column_count ,0 }, |
| 4301 | { "sqlite3_data_count", test_data_count ,0 }, |
| 4302 | { "sqlite3_column_type", test_column_type ,0 }, |
danielk1977 | ea61b2c | 2004-05-27 01:49:51 +0000 | [diff] [blame] | 4303 | { "sqlite3_column_blob", test_column_blob ,0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4304 | { "sqlite3_column_double", test_column_double ,0 }, |
| 4305 | { "sqlite3_column_int64", test_column_int64 ,0 }, |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 4306 | { "sqlite3_column_text", test_stmt_utf8, sqlite3_column_text }, |
| 4307 | { "sqlite3_column_decltype", test_stmt_utf8, sqlite3_column_decltype }, |
| 4308 | { "sqlite3_column_name", test_stmt_utf8, sqlite3_column_name }, |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 4309 | { "sqlite3_column_int", test_stmt_int, sqlite3_column_int }, |
| 4310 | { "sqlite3_column_bytes", test_stmt_int, sqlite3_column_bytes }, |
danielk1977 | 4b1ae99 | 2006-02-10 03:06:10 +0000 | [diff] [blame] | 4311 | #ifdef SQLITE_ENABLE_COLUMN_METADATA |
danielk1977 | 955de52 | 2006-02-10 02:27:42 +0000 | [diff] [blame] | 4312 | { "sqlite3_column_database_name", test_stmt_utf8, sqlite3_column_database_name}, |
| 4313 | { "sqlite3_column_table_name", test_stmt_utf8, sqlite3_column_table_name}, |
| 4314 | { "sqlite3_column_origin_name", test_stmt_utf8, sqlite3_column_origin_name}, |
danielk1977 | 4b1ae99 | 2006-02-10 03:06:10 +0000 | [diff] [blame] | 4315 | #endif |
danielk1977 | 955de52 | 2006-02-10 02:27:42 +0000 | [diff] [blame] | 4316 | |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 4317 | #ifndef SQLITE_OMIT_UTF16 |
| 4318 | { "sqlite3_column_bytes16", test_stmt_int, sqlite3_column_bytes16 }, |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 4319 | { "sqlite3_column_text16", test_stmt_utf16, sqlite3_column_text16 }, |
| 4320 | { "sqlite3_column_decltype16", test_stmt_utf16, sqlite3_column_decltype16}, |
| 4321 | { "sqlite3_column_name16", test_stmt_utf16, sqlite3_column_name16 }, |
drh | 7d9bd4e | 2006-02-16 18:16:36 +0000 | [diff] [blame] | 4322 | { "add_alignment_test_collations", add_alignment_test_collations, 0 }, |
danielk1977 | 4b1ae99 | 2006-02-10 03:06:10 +0000 | [diff] [blame] | 4323 | #ifdef SQLITE_ENABLE_COLUMN_METADATA |
danielk1977 | 955de52 | 2006-02-10 02:27:42 +0000 | [diff] [blame] | 4324 | {"sqlite3_column_database_name16", |
| 4325 | test_stmt_utf16, sqlite3_column_database_name16}, |
| 4326 | {"sqlite3_column_table_name16", test_stmt_utf16, sqlite3_column_table_name16}, |
| 4327 | {"sqlite3_column_origin_name16", test_stmt_utf16, sqlite3_column_origin_name16}, |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 4328 | #endif |
danielk1977 | 4b1ae99 | 2006-02-10 03:06:10 +0000 | [diff] [blame] | 4329 | #endif |
danielk1977 | a393c03 | 2007-05-07 14:58:53 +0000 | [diff] [blame] | 4330 | { "sqlite3_create_collation_v2", test_create_collation_v2, 0 }, |
danielk1977 | a9808b3 | 2007-05-07 09:32:45 +0000 | [diff] [blame] | 4331 | { "sqlite3_global_recover", test_global_recover, 0 }, |
| 4332 | { "working_64bit_int", working_64bit_int, 0 }, |
danielk1977 | 04f2e68 | 2004-05-27 01:04:07 +0000 | [diff] [blame] | 4333 | |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 4334 | /* Functions from os.h */ |
danielk1977 | 44ee5bf | 2005-05-27 09:41:12 +0000 | [diff] [blame] | 4335 | #ifndef SQLITE_OMIT_DISKIO |
danielk1977 | b4b4741 | 2007-08-17 15:53:36 +0000 | [diff] [blame] | 4336 | #if 0 |
danielk1977 | 9a1d0ab | 2004-06-01 14:09:28 +0000 | [diff] [blame] | 4337 | { "sqlite3OsOpenReadWrite",test_sqlite3OsOpenReadWrite, 0 }, |
| 4338 | { "sqlite3OsClose", test_sqlite3OsClose, 0 }, |
| 4339 | { "sqlite3OsLock", test_sqlite3OsLock, 0 }, |
drh | ab3f9fe | 2004-08-14 17:10:10 +0000 | [diff] [blame] | 4340 | { "sqlite3OsTempFileName", test_sqlite3OsTempFileName, 0 }, |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 4341 | |
| 4342 | /* Custom test interfaces */ |
| 4343 | { "sqlite3OsUnlock", test_sqlite3OsUnlock, 0 }, |
danielk1977 | 44ee5bf | 2005-05-27 09:41:12 +0000 | [diff] [blame] | 4344 | #endif |
danielk1977 | b4b4741 | 2007-08-17 15:53:36 +0000 | [diff] [blame] | 4345 | #endif |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 4346 | #ifndef SQLITE_OMIT_UTF16 |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 4347 | { "add_test_collate", test_collate, 0 }, |
| 4348 | { "add_test_collate_needed", test_collate_needed, 0 }, |
| 4349 | { "add_test_function", test_function, 0 }, |
drh | 5436dc2 | 2004-11-14 04:04:17 +0000 | [diff] [blame] | 4350 | #endif |
danielk1977 | 312d6b3 | 2004-06-29 13:18:23 +0000 | [diff] [blame] | 4351 | { "sqlite3_test_errstr", test_errstr, 0 }, |
drh | 92febd9 | 2004-08-20 18:34:20 +0000 | [diff] [blame] | 4352 | { "tcl_variable_type", tcl_variable_type, 0 }, |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 4353 | #ifndef SQLITE_OMIT_SHARED_CACHE |
drh | 6f7adc8 | 2006-01-11 21:41:20 +0000 | [diff] [blame] | 4354 | { "sqlite3_enable_shared_cache", test_enable_shared, 0 }, |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 4355 | { "sqlite3_shared_cache_report", sqlite3BtreeSharedCacheReport, 0}, |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 4356 | #endif |
danielk1977 | 161fb79 | 2006-01-24 10:58:21 +0000 | [diff] [blame] | 4357 | { "sqlite3_libversion_number", test_libversion_number, 0 }, |
danielk1977 | deb802c | 2006-02-09 13:43:28 +0000 | [diff] [blame] | 4358 | #ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 4359 | { "sqlite3_table_column_metadata", test_table_column_metadata, 0 }, |
| 4360 | #endif |
danielk1977 | dcbb5d3 | 2007-05-04 18:36:44 +0000 | [diff] [blame] | 4361 | #ifndef SQLITE_OMIT_INCRBLOB |
| 4362 | { "sqlite3_blob_read", test_blob_read, 0 }, |
| 4363 | { "sqlite3_blob_write", test_blob_write, 0 }, |
| 4364 | #endif |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 4365 | }; |
drh | 1398ad3 | 2005-01-19 23:24:50 +0000 | [diff] [blame] | 4366 | static int bitmask_size = sizeof(Bitmask)*8; |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 4367 | int i; |
drh | 51147ba | 2005-07-23 22:59:55 +0000 | [diff] [blame] | 4368 | extern int sqlite3_where_trace; |
drh | b851b2c | 2005-03-10 14:11:12 +0000 | [diff] [blame] | 4369 | extern int sqlite3_sync_count, sqlite3_fullsync_count; |
drh | af6df11 | 2005-06-07 02:12:30 +0000 | [diff] [blame] | 4370 | extern int sqlite3_opentemp_count; |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 4371 | extern int sqlite3_like_count; |
drh | dd73521 | 2007-02-24 13:53:05 +0000 | [diff] [blame] | 4372 | extern int sqlite3_xferopt_count; |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 4373 | extern int sqlite3_pager_readdb_count; |
| 4374 | extern int sqlite3_pager_writedb_count; |
| 4375 | extern int sqlite3_pager_writej_count; |
| 4376 | extern int sqlite3_pager_pgfree_count; |
drh | d677b3d | 2007-08-20 22:48:41 +0000 | [diff] [blame] | 4377 | #if OS_UNIX && defined(SQLITE_TEST) && SQLITE_THREADSAFE |
drh | 029b44b | 2006-01-15 00:13:15 +0000 | [diff] [blame] | 4378 | extern int threadsOverrideEachOthersLocks; |
| 4379 | #endif |
drh | c092998 | 2005-09-05 19:08:29 +0000 | [diff] [blame] | 4380 | #if OS_WIN |
| 4381 | extern int sqlite3_os_type; |
| 4382 | #endif |
drh | 8b3d990 | 2005-08-19 00:14:42 +0000 | [diff] [blame] | 4383 | #ifdef SQLITE_DEBUG |
drh | 73be501 | 2007-08-08 12:11:21 +0000 | [diff] [blame] | 4384 | extern int sqlite3_os_trace; |
drh | 8b3d990 | 2005-08-19 00:14:42 +0000 | [diff] [blame] | 4385 | extern int sqlite3_vdbe_addop_trace; |
drh | 549c8b6 | 2005-09-19 13:15:23 +0000 | [diff] [blame] | 4386 | #endif |
| 4387 | #ifdef SQLITE_TEST |
| 4388 | extern char sqlite3_query_plan[]; |
drh | 9042f39 | 2005-07-15 23:24:23 +0000 | [diff] [blame] | 4389 | static char *query_plan = sqlite3_query_plan; |
drh | 48083ce | 2005-09-19 12:37:27 +0000 | [diff] [blame] | 4390 | #endif |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 4391 | |
| 4392 | for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ |
| 4393 | Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); |
| 4394 | } |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 4395 | for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){ |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 4396 | Tcl_CreateObjCommand(interp, aObjCmd[i].zName, |
| 4397 | aObjCmd[i].xProc, aObjCmd[i].clientData, 0); |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 4398 | } |
danielk1977 | 6490beb | 2004-05-11 06:17:21 +0000 | [diff] [blame] | 4399 | Tcl_LinkVar(interp, "sqlite_search_count", |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 4400 | (char*)&sqlite3_search_count, TCL_LINK_INT); |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame] | 4401 | Tcl_LinkVar(interp, "sqlite_sort_count", |
| 4402 | (char*)&sqlite3_sort_count, TCL_LINK_INT); |
drh | ae7e151 | 2007-05-02 16:51:59 +0000 | [diff] [blame] | 4403 | Tcl_LinkVar(interp, "sqlite3_max_blobsize", |
| 4404 | (char*)&sqlite3_max_blobsize, TCL_LINK_INT); |
drh | 55ef4d9 | 2005-08-14 01:20:37 +0000 | [diff] [blame] | 4405 | Tcl_LinkVar(interp, "sqlite_like_count", |
| 4406 | (char*)&sqlite3_like_count, TCL_LINK_INT); |
danielk1977 | 6490beb | 2004-05-11 06:17:21 +0000 | [diff] [blame] | 4407 | Tcl_LinkVar(interp, "sqlite_interrupt_count", |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 4408 | (char*)&sqlite3_interrupt_count, TCL_LINK_INT); |
danielk1977 | 6490beb | 2004-05-11 06:17:21 +0000 | [diff] [blame] | 4409 | Tcl_LinkVar(interp, "sqlite_open_file_count", |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 4410 | (char*)&sqlite3_open_file_count, TCL_LINK_INT); |
danielk1977 | 6490beb | 2004-05-11 06:17:21 +0000 | [diff] [blame] | 4411 | Tcl_LinkVar(interp, "sqlite_current_time", |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 4412 | (char*)&sqlite3_current_time, TCL_LINK_INT); |
drh | dd73521 | 2007-02-24 13:53:05 +0000 | [diff] [blame] | 4413 | Tcl_LinkVar(interp, "sqlite3_xferopt_count", |
| 4414 | (char*)&sqlite3_xferopt_count, TCL_LINK_INT); |
drh | 538f570 | 2007-04-13 02:14:30 +0000 | [diff] [blame] | 4415 | Tcl_LinkVar(interp, "sqlite3_pager_readdb_count", |
| 4416 | (char*)&sqlite3_pager_readdb_count, TCL_LINK_INT); |
| 4417 | Tcl_LinkVar(interp, "sqlite3_pager_writedb_count", |
| 4418 | (char*)&sqlite3_pager_writedb_count, TCL_LINK_INT); |
| 4419 | Tcl_LinkVar(interp, "sqlite3_pager_writej_count", |
| 4420 | (char*)&sqlite3_pager_writej_count, TCL_LINK_INT); |
| 4421 | Tcl_LinkVar(interp, "sqlite3_pager_pgfree_count", |
| 4422 | (char*)&sqlite3_pager_pgfree_count, TCL_LINK_INT); |
danielk1977 | 4b2688a | 2006-06-20 11:01:07 +0000 | [diff] [blame] | 4423 | #ifndef SQLITE_OMIT_UTF16 |
drh | 7d9bd4e | 2006-02-16 18:16:36 +0000 | [diff] [blame] | 4424 | Tcl_LinkVar(interp, "unaligned_string_counter", |
| 4425 | (char*)&unaligned_string_counter, TCL_LINK_INT); |
danielk1977 | 4b2688a | 2006-06-20 11:01:07 +0000 | [diff] [blame] | 4426 | #endif |
drh | d677b3d | 2007-08-20 22:48:41 +0000 | [diff] [blame] | 4427 | #if OS_UNIX && defined(SQLITE_TEST) && SQLITE_THREADSAFE |
drh | 029b44b | 2006-01-15 00:13:15 +0000 | [diff] [blame] | 4428 | Tcl_LinkVar(interp, "threadsOverrideEachOthersLocks", |
| 4429 | (char*)&threadsOverrideEachOthersLocks, TCL_LINK_INT); |
| 4430 | #endif |
drh | 268803a | 2005-12-14 20:11:30 +0000 | [diff] [blame] | 4431 | #ifndef SQLITE_OMIT_UTF16 |
| 4432 | Tcl_LinkVar(interp, "sqlite_last_needed_collation", |
| 4433 | (char*)&pzNeededCollation, TCL_LINK_STRING|TCL_LINK_READ_ONLY); |
| 4434 | #endif |
drh | c092998 | 2005-09-05 19:08:29 +0000 | [diff] [blame] | 4435 | #if OS_WIN |
| 4436 | Tcl_LinkVar(interp, "sqlite_os_type", |
| 4437 | (char*)&sqlite3_os_type, TCL_LINK_INT); |
| 4438 | #endif |
drh | 549c8b6 | 2005-09-19 13:15:23 +0000 | [diff] [blame] | 4439 | #ifdef SQLITE_TEST |
| 4440 | Tcl_LinkVar(interp, "sqlite_query_plan", |
| 4441 | (char*)&query_plan, TCL_LINK_STRING|TCL_LINK_READ_ONLY); |
| 4442 | #endif |
drh | 8b3d990 | 2005-08-19 00:14:42 +0000 | [diff] [blame] | 4443 | #ifdef SQLITE_DEBUG |
| 4444 | Tcl_LinkVar(interp, "sqlite_addop_trace", |
| 4445 | (char*)&sqlite3_vdbe_addop_trace, TCL_LINK_INT); |
drh | 48083ce | 2005-09-19 12:37:27 +0000 | [diff] [blame] | 4446 | Tcl_LinkVar(interp, "sqlite_where_trace", |
| 4447 | (char*)&sqlite3_where_trace, TCL_LINK_INT); |
drh | 73be501 | 2007-08-08 12:11:21 +0000 | [diff] [blame] | 4448 | Tcl_LinkVar(interp, "sqlite_os_trace", |
| 4449 | (char*)&sqlite3_os_trace, TCL_LINK_INT); |
drh | 8b3d990 | 2005-08-19 00:14:42 +0000 | [diff] [blame] | 4450 | #endif |
danielk1977 | cbe21be | 2005-06-07 07:58:48 +0000 | [diff] [blame] | 4451 | #ifndef SQLITE_OMIT_DISKIO |
drh | af6df11 | 2005-06-07 02:12:30 +0000 | [diff] [blame] | 4452 | Tcl_LinkVar(interp, "sqlite_opentemp_count", |
| 4453 | (char*)&sqlite3_opentemp_count, TCL_LINK_INT); |
danielk1977 | cbe21be | 2005-06-07 07:58:48 +0000 | [diff] [blame] | 4454 | #endif |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 4455 | Tcl_LinkVar(interp, "sqlite_static_bind_value", |
| 4456 | (char*)&sqlite_static_bind_value, TCL_LINK_STRING); |
drh | f031381 | 2006-09-04 15:53:53 +0000 | [diff] [blame] | 4457 | Tcl_LinkVar(interp, "sqlite_static_bind_nbyte", |
| 4458 | (char*)&sqlite_static_bind_nbyte, TCL_LINK_INT); |
drh | ab3f9fe | 2004-08-14 17:10:10 +0000 | [diff] [blame] | 4459 | Tcl_LinkVar(interp, "sqlite_temp_directory", |
drh | effd02b | 2004-08-29 23:42:13 +0000 | [diff] [blame] | 4460 | (char*)&sqlite3_temp_directory, TCL_LINK_STRING); |
drh | 1398ad3 | 2005-01-19 23:24:50 +0000 | [diff] [blame] | 4461 | Tcl_LinkVar(interp, "bitmask_size", |
| 4462 | (char*)&bitmask_size, TCL_LINK_INT|TCL_LINK_READ_ONLY); |
drh | 748f763 | 2005-03-11 04:41:39 +0000 | [diff] [blame] | 4463 | #if OS_UNIX |
drh | b851b2c | 2005-03-10 14:11:12 +0000 | [diff] [blame] | 4464 | Tcl_LinkVar(interp, "sqlite_sync_count", |
| 4465 | (char*)&sqlite3_sync_count, TCL_LINK_INT); |
| 4466 | Tcl_LinkVar(interp, "sqlite_fullsync_count", |
| 4467 | (char*)&sqlite3_fullsync_count, TCL_LINK_INT); |
drh | 748f763 | 2005-03-11 04:41:39 +0000 | [diff] [blame] | 4468 | #endif /* OS_UNIX */ |
danielk1977 | b82e7ed | 2006-01-11 14:09:31 +0000 | [diff] [blame] | 4469 | |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 4470 | return TCL_OK; |
| 4471 | } |