drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 1 | /* |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 2 | ** 2001 September 15 |
drh | 7589723 | 2000-05-29 14:26:00 +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 | 7589723 | 2000-05-29 14:26:00 +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 | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** A TCL Interface to SQLite |
| 13 | ** |
drh | e22a334 | 2003-04-22 20:30:37 +0000 | [diff] [blame^] | 14 | ** $Id: tclsqlite.c,v 1.47 2003/04/22 20:30:39 drh Exp $ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 15 | */ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 16 | #ifndef NO_TCL /* Omit this whole file if TCL is unavailable */ |
| 17 | |
drh | 06b2718 | 2002-06-26 20:06:05 +0000 | [diff] [blame] | 18 | #include "sqliteInt.h" |
drh | 17a6893 | 2001-01-31 13:28:08 +0000 | [diff] [blame] | 19 | #include "tcl.h" |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
drh | ce92706 | 2001-11-09 13:41:09 +0000 | [diff] [blame] | 22 | #include <assert.h> |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 23 | |
| 24 | /* |
drh | 98808ba | 2001-10-18 12:34:46 +0000 | [diff] [blame] | 25 | ** If TCL uses UTF-8 and SQLite is configured to use iso8859, then we |
| 26 | ** have to do a translation when going between the two. Set the |
| 27 | ** UTF_TRANSLATION_NEEDED macro to indicate that we need to do |
| 28 | ** this translation. |
| 29 | */ |
| 30 | #if defined(TCL_UTF_MAX) && !defined(SQLITE_UTF8) |
| 31 | # define UTF_TRANSLATION_NEEDED 1 |
| 32 | #endif |
| 33 | |
| 34 | /* |
drh | cabb081 | 2002-09-14 13:47:32 +0000 | [diff] [blame] | 35 | ** New SQL functions can be created as TCL scripts. Each such function |
| 36 | ** is described by an instance of the following structure. |
| 37 | */ |
| 38 | typedef struct SqlFunc SqlFunc; |
| 39 | struct SqlFunc { |
| 40 | Tcl_Interp *interp; /* The TCL interpret to execute the function */ |
| 41 | char *zScript; /* The script to be run */ |
| 42 | SqlFunc *pNext; /* Next function on the list of them all */ |
| 43 | }; |
| 44 | |
| 45 | /* |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 46 | ** There is one instance of this structure for each SQLite database |
| 47 | ** that has been opened by the SQLite TCL interface. |
| 48 | */ |
| 49 | typedef struct SqliteDb SqliteDb; |
| 50 | struct SqliteDb { |
| 51 | sqlite *db; /* The "real" database structure */ |
| 52 | Tcl_Interp *interp; /* The interpreter used for this database */ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 53 | char *zBusy; /* The busy callback routine */ |
drh | 0d1a643 | 2003-04-03 15:46:04 +0000 | [diff] [blame] | 54 | char *zBegin; /* The begin-transaction callback routine */ |
| 55 | char *zCommit; /* The commit-transaction callback routine */ |
drh | e22a334 | 2003-04-22 20:30:37 +0000 | [diff] [blame^] | 56 | char *zAuth; /* The authorization callback routine */ |
drh | cabb081 | 2002-09-14 13:47:32 +0000 | [diff] [blame] | 57 | SqlFunc *pFunc; /* List of SQL functions */ |
drh | dcd997e | 2003-01-31 17:21:49 +0000 | [diff] [blame] | 58 | int rc; /* Return code of most recent sqlite_exec() */ |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | /* |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 62 | ** An instance of this structure passes information thru the sqlite |
| 63 | ** logic from the original TCL command into the callback routine. |
| 64 | */ |
| 65 | typedef struct CallbackData CallbackData; |
| 66 | struct CallbackData { |
| 67 | Tcl_Interp *interp; /* The TCL interpreter */ |
| 68 | char *zArray; /* The array into which data is written */ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 69 | Tcl_Obj *pCode; /* The code to execute for each row */ |
drh | ce92706 | 2001-11-09 13:41:09 +0000 | [diff] [blame] | 70 | int once; /* Set for first callback only */ |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 71 | int tcl_rc; /* Return code from TCL script */ |
drh | 98808ba | 2001-10-18 12:34:46 +0000 | [diff] [blame] | 72 | int nColName; /* Number of entries in the azColName[] array */ |
| 73 | char **azColName; /* Column names translated to UTF-8 */ |
drh | 98808ba | 2001-10-18 12:34:46 +0000 | [diff] [blame] | 74 | }; |
drh | 297ecf1 | 2001-04-05 15:57:13 +0000 | [diff] [blame] | 75 | |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 76 | #ifdef UTF_TRANSLATION_NEEDED |
drh | 297ecf1 | 2001-04-05 15:57:13 +0000 | [diff] [blame] | 77 | /* |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 78 | ** Called for each row of the result. |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 79 | ** |
| 80 | ** This version is used when TCL expects UTF-8 data but the database |
| 81 | ** uses the ISO8859 format. A translation must occur from ISO8859 into |
| 82 | ** UTF-8. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 83 | */ |
| 84 | static int DbEvalCallback( |
| 85 | void *clientData, /* An instance of CallbackData */ |
| 86 | int nCol, /* Number of columns in the result */ |
| 87 | char ** azCol, /* Data for each column */ |
| 88 | char ** azN /* Name for each column */ |
| 89 | ){ |
| 90 | CallbackData *cbData = (CallbackData*)clientData; |
| 91 | int i, rc; |
drh | 297ecf1 | 2001-04-05 15:57:13 +0000 | [diff] [blame] | 92 | Tcl_DString dCol; |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 93 | Tcl_DStringInit(&dCol); |
drh | ce92706 | 2001-11-09 13:41:09 +0000 | [diff] [blame] | 94 | if( cbData->azColName==0 ){ |
| 95 | assert( cbData->once ); |
| 96 | cbData->once = 0; |
| 97 | if( cbData->zArray[0] ){ |
| 98 | Tcl_SetVar2(cbData->interp, cbData->zArray, "*", "", 0); |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 99 | } |
drh | ce92706 | 2001-11-09 13:41:09 +0000 | [diff] [blame] | 100 | cbData->azColName = malloc( nCol*sizeof(char*) ); |
| 101 | if( cbData->azColName==0 ){ return 1; } |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 102 | cbData->nColName = nCol; |
| 103 | for(i=0; i<nCol; i++){ |
| 104 | Tcl_ExternalToUtfDString(NULL, azN[i], -1, &dCol); |
drh | ce92706 | 2001-11-09 13:41:09 +0000 | [diff] [blame] | 105 | cbData->azColName[i] = malloc( Tcl_DStringLength(&dCol) + 1 ); |
| 106 | if( cbData->azColName[i] ){ |
| 107 | strcpy(cbData->azColName[i], Tcl_DStringValue(&dCol)); |
| 108 | }else{ |
| 109 | return 1; |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 110 | } |
drh | ce92706 | 2001-11-09 13:41:09 +0000 | [diff] [blame] | 111 | if( cbData->zArray[0] ){ |
| 112 | Tcl_SetVar2(cbData->interp, cbData->zArray, "*", |
| 113 | Tcl_DStringValue(&dCol), TCL_LIST_ELEMENT|TCL_APPEND_VALUE); |
drh | 704027f | 2002-07-15 20:58:47 +0000 | [diff] [blame] | 114 | if( azN[nCol]!=0 ){ |
drh | 5080aaa | 2002-07-11 12:18:16 +0000 | [diff] [blame] | 115 | Tcl_DString dType; |
| 116 | Tcl_DStringInit(&dType); |
| 117 | Tcl_DStringAppend(&dType, "typeof:", -1); |
| 118 | Tcl_DStringAppend(&dType, Tcl_DStringValue(&dCol), -1); |
| 119 | Tcl_DStringFree(&dCol); |
| 120 | Tcl_ExternalToUtfDString(NULL, azN[i+nCol], -1, &dCol); |
| 121 | Tcl_SetVar2(cbData->interp, cbData->zArray, |
| 122 | Tcl_DStringValue(&dType), Tcl_DStringValue(&dCol), |
| 123 | TCL_LIST_ELEMENT|TCL_APPEND_VALUE); |
| 124 | Tcl_DStringFree(&dType); |
| 125 | } |
drh | ce92706 | 2001-11-09 13:41:09 +0000 | [diff] [blame] | 126 | } |
drh | fa173a7 | 2002-07-10 21:26:00 +0000 | [diff] [blame] | 127 | |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 128 | Tcl_DStringFree(&dCol); |
| 129 | } |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 130 | } |
| 131 | if( azCol!=0 ){ |
| 132 | if( cbData->zArray[0] ){ |
| 133 | for(i=0; i<nCol; i++){ |
| 134 | char *z = azCol[i]; |
| 135 | if( z==0 ) z = ""; |
| 136 | Tcl_DStringInit(&dCol); |
| 137 | Tcl_ExternalToUtfDString(NULL, z, -1, &dCol); |
| 138 | Tcl_SetVar2(cbData->interp, cbData->zArray, cbData->azColName[i], |
| 139 | Tcl_DStringValue(&dCol), 0); |
| 140 | Tcl_DStringFree(&dCol); |
| 141 | } |
| 142 | }else{ |
| 143 | for(i=0; i<nCol; i++){ |
| 144 | char *z = azCol[i]; |
| 145 | if( z==0 ) z = ""; |
| 146 | Tcl_DStringInit(&dCol); |
| 147 | Tcl_ExternalToUtfDString(NULL, z, -1, &dCol); |
| 148 | Tcl_SetVar(cbData->interp, cbData->azColName[i], |
| 149 | Tcl_DStringValue(&dCol), 0); |
| 150 | Tcl_DStringFree(&dCol); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | rc = Tcl_EvalObj(cbData->interp, cbData->pCode); |
| 155 | if( rc==TCL_CONTINUE ) rc = TCL_OK; |
| 156 | cbData->tcl_rc = rc; |
| 157 | return rc!=TCL_OK; |
| 158 | } |
| 159 | #endif /* UTF_TRANSLATION_NEEDED */ |
| 160 | |
| 161 | #ifndef UTF_TRANSLATION_NEEDED |
| 162 | /* |
| 163 | ** Called for each row of the result. |
| 164 | ** |
| 165 | ** This version is used when either of the following is true: |
| 166 | ** |
| 167 | ** (1) This version of TCL uses UTF-8 and the data in the |
| 168 | ** SQLite database is already in the UTF-8 format. |
| 169 | ** |
| 170 | ** (2) This version of TCL uses ISO8859 and the data in the |
| 171 | ** SQLite database is already in the ISO8859 format. |
| 172 | */ |
| 173 | static int DbEvalCallback( |
| 174 | void *clientData, /* An instance of CallbackData */ |
| 175 | int nCol, /* Number of columns in the result */ |
| 176 | char ** azCol, /* Data for each column */ |
| 177 | char ** azN /* Name for each column */ |
| 178 | ){ |
| 179 | CallbackData *cbData = (CallbackData*)clientData; |
| 180 | int i, rc; |
drh | 6a53534 | 2001-10-19 16:44:56 +0000 | [diff] [blame] | 181 | if( azCol==0 || (cbData->once && cbData->zArray[0]) ){ |
| 182 | Tcl_SetVar2(cbData->interp, cbData->zArray, "*", "", 0); |
| 183 | for(i=0; i<nCol; i++){ |
| 184 | Tcl_SetVar2(cbData->interp, cbData->zArray, "*", azN[i], |
| 185 | TCL_LIST_ELEMENT|TCL_APPEND_VALUE); |
drh | 5080aaa | 2002-07-11 12:18:16 +0000 | [diff] [blame] | 186 | if( azN[nCol] ){ |
| 187 | char *z = sqlite_mprintf("typeof:%s", azN[i]); |
| 188 | Tcl_SetVar2(cbData->interp, cbData->zArray, z, azN[i+nCol], |
| 189 | TCL_LIST_ELEMENT|TCL_APPEND_VALUE); |
| 190 | sqlite_freemem(z); |
| 191 | } |
drh | 6a53534 | 2001-10-19 16:44:56 +0000 | [diff] [blame] | 192 | } |
| 193 | cbData->once = 0; |
| 194 | } |
| 195 | if( azCol!=0 ){ |
| 196 | if( cbData->zArray[0] ){ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 197 | for(i=0; i<nCol; i++){ |
drh | 6a53534 | 2001-10-19 16:44:56 +0000 | [diff] [blame] | 198 | char *z = azCol[i]; |
| 199 | if( z==0 ) z = ""; |
drh | 6a53534 | 2001-10-19 16:44:56 +0000 | [diff] [blame] | 200 | Tcl_SetVar2(cbData->interp, cbData->zArray, azN[i], z, 0); |
drh | 6a53534 | 2001-10-19 16:44:56 +0000 | [diff] [blame] | 201 | } |
| 202 | }else{ |
| 203 | for(i=0; i<nCol; i++){ |
| 204 | char *z = azCol[i]; |
| 205 | if( z==0 ) z = ""; |
drh | 6a53534 | 2001-10-19 16:44:56 +0000 | [diff] [blame] | 206 | Tcl_SetVar(cbData->interp, azN[i], z, 0); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 207 | } |
| 208 | } |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 209 | } |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 210 | rc = Tcl_EvalObj(cbData->interp, cbData->pCode); |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 211 | if( rc==TCL_CONTINUE ) rc = TCL_OK; |
| 212 | cbData->tcl_rc = rc; |
| 213 | return rc!=TCL_OK; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 214 | } |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 215 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 216 | |
| 217 | /* |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 218 | ** This is an alternative callback for database queries. Instead |
| 219 | ** of invoking a TCL script to handle the result, this callback just |
| 220 | ** appends each column of the result to a list. After the query |
| 221 | ** is complete, the list is returned. |
| 222 | */ |
| 223 | static int DbEvalCallback2( |
| 224 | void *clientData, /* An instance of CallbackData */ |
| 225 | int nCol, /* Number of columns in the result */ |
| 226 | char ** azCol, /* Data for each column */ |
| 227 | char ** azN /* Name for each column */ |
| 228 | ){ |
| 229 | Tcl_Obj *pList = (Tcl_Obj*)clientData; |
| 230 | int i; |
drh | 6a53534 | 2001-10-19 16:44:56 +0000 | [diff] [blame] | 231 | if( azCol==0 ) return 0; |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 232 | for(i=0; i<nCol; i++){ |
| 233 | Tcl_Obj *pElem; |
| 234 | if( azCol[i] && *azCol[i] ){ |
drh | 297ecf1 | 2001-04-05 15:57:13 +0000 | [diff] [blame] | 235 | #ifdef UTF_TRANSLATION_NEEDED |
| 236 | Tcl_DString dCol; |
| 237 | Tcl_DStringInit(&dCol); |
| 238 | Tcl_ExternalToUtfDString(NULL, azCol[i], -1, &dCol); |
| 239 | pElem = Tcl_NewStringObj(Tcl_DStringValue(&dCol), -1); |
| 240 | Tcl_DStringFree(&dCol); |
| 241 | #else |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 242 | pElem = Tcl_NewStringObj(azCol[i], -1); |
drh | 297ecf1 | 2001-04-05 15:57:13 +0000 | [diff] [blame] | 243 | #endif |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 244 | }else{ |
| 245 | pElem = Tcl_NewObj(); |
| 246 | } |
| 247 | Tcl_ListObjAppendElement(0, pList, pElem); |
| 248 | } |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | /* |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 253 | ** Called when the command is deleted. |
| 254 | */ |
| 255 | static void DbDeleteCmd(void *db){ |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 256 | SqliteDb *pDb = (SqliteDb*)db; |
| 257 | sqlite_close(pDb->db); |
drh | cabb081 | 2002-09-14 13:47:32 +0000 | [diff] [blame] | 258 | while( pDb->pFunc ){ |
| 259 | SqlFunc *pFunc = pDb->pFunc; |
| 260 | pDb->pFunc = pFunc->pNext; |
| 261 | Tcl_Free((char*)pFunc); |
| 262 | } |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 263 | if( pDb->zBusy ){ |
| 264 | Tcl_Free(pDb->zBusy); |
| 265 | } |
drh | 0d1a643 | 2003-04-03 15:46:04 +0000 | [diff] [blame] | 266 | if( pDb->zBegin ){ |
| 267 | Tcl_Free(pDb->zBegin); |
| 268 | } |
| 269 | if( pDb->zCommit ){ |
| 270 | Tcl_Free(pDb->zCommit); |
| 271 | } |
drh | e22a334 | 2003-04-22 20:30:37 +0000 | [diff] [blame^] | 272 | if( pDb->zAuth ){ |
| 273 | Tcl_Free(pDb->zAuth); |
| 274 | } |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 275 | Tcl_Free((char*)pDb); |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | ** This routine is called when a database file is locked while trying |
| 280 | ** to execute SQL. |
| 281 | */ |
| 282 | static int DbBusyHandler(void *cd, const char *zTable, int nTries){ |
| 283 | SqliteDb *pDb = (SqliteDb*)cd; |
| 284 | int rc; |
| 285 | char zVal[30]; |
| 286 | char *zCmd; |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 287 | Tcl_DString cmd; |
| 288 | |
| 289 | Tcl_DStringInit(&cmd); |
| 290 | Tcl_DStringAppend(&cmd, pDb->zBusy, -1); |
| 291 | Tcl_DStringAppendElement(&cmd, zTable); |
| 292 | sprintf(zVal, " %d", nTries); |
| 293 | Tcl_DStringAppend(&cmd, zVal, -1); |
| 294 | zCmd = Tcl_DStringValue(&cmd); |
| 295 | rc = Tcl_Eval(pDb->interp, zCmd); |
| 296 | Tcl_DStringFree(&cmd); |
| 297 | if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->interp)) ){ |
| 298 | return 0; |
| 299 | } |
| 300 | return 1; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | /* |
drh | 0d1a643 | 2003-04-03 15:46:04 +0000 | [diff] [blame] | 304 | ** This routine is called when a new transaction is started. The |
| 305 | ** TCL script in pDb->zBegin is executed. If it returns non-zero or |
| 306 | ** if it throws an exception, the transaction is aborted. |
| 307 | */ |
| 308 | static int DbBeginHandler(void *cd){ |
| 309 | SqliteDb *pDb = (SqliteDb*)cd; |
| 310 | int rc; |
| 311 | |
| 312 | rc = Tcl_Eval(pDb->interp, pDb->zBegin); |
| 313 | if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->interp)) ){ |
| 314 | return 1; |
| 315 | } |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | ** This routine is called when a transaction is committed. The |
| 321 | ** TCL script in pDb->zCommit is executed. If it returns non-zero or |
| 322 | ** if it throws an exception, the transaction is rolled back instead |
| 323 | ** of being committed. |
| 324 | */ |
| 325 | static int DbCommitHandler(void *cd){ |
| 326 | SqliteDb *pDb = (SqliteDb*)cd; |
| 327 | int rc; |
| 328 | |
| 329 | rc = Tcl_Eval(pDb->interp, pDb->zCommit); |
| 330 | if( rc!=TCL_OK || atoi(Tcl_GetStringResult(pDb->interp)) ){ |
| 331 | return 1; |
| 332 | } |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | /* |
drh | cabb081 | 2002-09-14 13:47:32 +0000 | [diff] [blame] | 337 | ** This routine is called to evaluate an SQL function implemented |
| 338 | ** using TCL script. |
| 339 | */ |
| 340 | static void tclSqlFunc(sqlite_func *context, int argc, const char **argv){ |
| 341 | SqlFunc *p = sqlite_user_data(context); |
| 342 | Tcl_DString cmd; |
| 343 | int i; |
| 344 | int rc; |
| 345 | |
| 346 | Tcl_DStringInit(&cmd); |
| 347 | Tcl_DStringAppend(&cmd, p->zScript, -1); |
| 348 | for(i=0; i<argc; i++){ |
| 349 | Tcl_DStringAppendElement(&cmd, argv[i] ? argv[i] : ""); |
| 350 | } |
| 351 | rc = Tcl_Eval(p->interp, Tcl_DStringValue(&cmd)); |
| 352 | if( rc ){ |
| 353 | sqlite_set_result_error(context, Tcl_GetStringResult(p->interp), -1); |
| 354 | }else{ |
| 355 | sqlite_set_result_string(context, Tcl_GetStringResult(p->interp), -1); |
| 356 | } |
| 357 | } |
drh | e22a334 | 2003-04-22 20:30:37 +0000 | [diff] [blame^] | 358 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 359 | /* |
| 360 | ** This is the authentication function. It appends the authentication |
| 361 | ** type code and the two arguments to zCmd[] then invokes the result |
| 362 | ** on the interpreter. The reply is examined to determine if the |
| 363 | ** authentication fails or succeeds. |
| 364 | */ |
| 365 | static int auth_callback( |
| 366 | void *pArg, |
| 367 | int code, |
| 368 | const char *zArg1, |
| 369 | const char *zArg2, |
| 370 | const char *zArg3, |
| 371 | const char *zArg4 |
| 372 | ){ |
| 373 | char *zCode; |
| 374 | Tcl_DString str; |
| 375 | int rc; |
| 376 | const char *zReply; |
| 377 | SqliteDb *pDb = (SqliteDb*)pArg; |
| 378 | |
| 379 | switch( code ){ |
| 380 | case SQLITE_COPY : zCode="SQLITE_COPY"; break; |
| 381 | case SQLITE_CREATE_INDEX : zCode="SQLITE_CREATE_INDEX"; break; |
| 382 | case SQLITE_CREATE_TABLE : zCode="SQLITE_CREATE_TABLE"; break; |
| 383 | case SQLITE_CREATE_TEMP_INDEX : zCode="SQLITE_CREATE_TEMP_INDEX"; break; |
| 384 | case SQLITE_CREATE_TEMP_TABLE : zCode="SQLITE_CREATE_TEMP_TABLE"; break; |
| 385 | case SQLITE_CREATE_TEMP_TRIGGER: zCode="SQLITE_CREATE_TEMP_TRIGGER"; break; |
| 386 | case SQLITE_CREATE_TEMP_VIEW : zCode="SQLITE_CREATE_TEMP_VIEW"; break; |
| 387 | case SQLITE_CREATE_TRIGGER : zCode="SQLITE_CREATE_TRIGGER"; break; |
| 388 | case SQLITE_CREATE_VIEW : zCode="SQLITE_CREATE_VIEW"; break; |
| 389 | case SQLITE_DELETE : zCode="SQLITE_DELETE"; break; |
| 390 | case SQLITE_DROP_INDEX : zCode="SQLITE_DROP_INDEX"; break; |
| 391 | case SQLITE_DROP_TABLE : zCode="SQLITE_DROP_TABLE"; break; |
| 392 | case SQLITE_DROP_TEMP_INDEX : zCode="SQLITE_DROP_TEMP_INDEX"; break; |
| 393 | case SQLITE_DROP_TEMP_TABLE : zCode="SQLITE_DROP_TEMP_TABLE"; break; |
| 394 | case SQLITE_DROP_TEMP_TRIGGER : zCode="SQLITE_DROP_TEMP_TRIGGER"; break; |
| 395 | case SQLITE_DROP_TEMP_VIEW : zCode="SQLITE_DROP_TEMP_VIEW"; break; |
| 396 | case SQLITE_DROP_TRIGGER : zCode="SQLITE_DROP_TRIGGER"; break; |
| 397 | case SQLITE_DROP_VIEW : zCode="SQLITE_DROP_VIEW"; break; |
| 398 | case SQLITE_INSERT : zCode="SQLITE_INSERT"; break; |
| 399 | case SQLITE_PRAGMA : zCode="SQLITE_PRAGMA"; break; |
| 400 | case SQLITE_READ : zCode="SQLITE_READ"; break; |
| 401 | case SQLITE_SELECT : zCode="SQLITE_SELECT"; break; |
| 402 | case SQLITE_TRANSACTION : zCode="SQLITE_TRANSACTION"; break; |
| 403 | case SQLITE_UPDATE : zCode="SQLITE_UPDATE"; break; |
| 404 | default : zCode="????"; break; |
| 405 | } |
| 406 | Tcl_DStringInit(&str); |
| 407 | Tcl_DStringAppend(&str, pDb->zAuth, -1); |
| 408 | Tcl_DStringAppendElement(&str, zCode); |
| 409 | Tcl_DStringAppendElement(&str, zArg1 ? zArg1 : ""); |
| 410 | Tcl_DStringAppendElement(&str, zArg2 ? zArg2 : ""); |
| 411 | Tcl_DStringAppendElement(&str, zArg3 ? zArg3 : ""); |
| 412 | Tcl_DStringAppendElement(&str, zArg4 ? zArg4 : ""); |
| 413 | rc = Tcl_GlobalEval(pDb->interp, Tcl_DStringValue(&str)); |
| 414 | Tcl_DStringFree(&str); |
| 415 | zReply = Tcl_GetStringResult(pDb->interp); |
| 416 | if( strcmp(zReply,"SQLITE_OK")==0 ){ |
| 417 | rc = SQLITE_OK; |
| 418 | }else if( strcmp(zReply,"SQLITE_DENY")==0 ){ |
| 419 | rc = SQLITE_DENY; |
| 420 | }else if( strcmp(zReply,"SQLITE_IGNORE")==0 ){ |
| 421 | rc = SQLITE_IGNORE; |
| 422 | }else{ |
| 423 | rc = 999; |
| 424 | } |
| 425 | return rc; |
| 426 | } |
| 427 | #endif /* SQLITE_OMIT_AUTHORIZATION */ |
drh | cabb081 | 2002-09-14 13:47:32 +0000 | [diff] [blame] | 428 | |
| 429 | /* |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 430 | ** The "sqlite" command below creates a new Tcl command for each |
| 431 | ** connection it opens to an SQLite database. This routine is invoked |
| 432 | ** whenever one of those connection-specific commands is executed |
| 433 | ** in Tcl. For example, if you run Tcl code like this: |
| 434 | ** |
| 435 | ** sqlite db1 "my_database" |
| 436 | ** db1 close |
| 437 | ** |
| 438 | ** The first command opens a connection to the "my_database" database |
| 439 | ** and calls that connection "db1". The second command causes this |
| 440 | ** subroutine to be invoked. |
| 441 | */ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 442 | static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 443 | SqliteDb *pDb = (SqliteDb*)cd; |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 444 | int choice; |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 445 | static const char *DB_strs[] = { |
drh | e22a334 | 2003-04-22 20:30:37 +0000 | [diff] [blame^] | 446 | "authorizer", "begin_hook", "busy", |
| 447 | "changes", "close", "commit_hook", |
| 448 | "complete", "errorcode", "eval", |
| 449 | "function", "last_insert_rowid", "timeout", |
| 450 | 0 |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 451 | }; |
drh | 411995d | 2002-06-25 19:31:18 +0000 | [diff] [blame] | 452 | enum DB_enum { |
drh | e22a334 | 2003-04-22 20:30:37 +0000 | [diff] [blame^] | 453 | DB_AUTHORIZER, DB_BEGIN_HOOK, DB_BUSY, |
| 454 | DB_CHANGES, DB_CLOSE, DB_COMMIT_HOOK, |
| 455 | DB_COMPLETE, DB_ERRORCODE, DB_EVAL, |
| 456 | DB_FUNCTION, DB_LAST_INSERT_ROWID,DB_TIMEOUT, |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 457 | }; |
| 458 | |
| 459 | if( objc<2 ){ |
| 460 | Tcl_WrongNumArgs(interp, 1, objv, "SUBCOMMAND ..."); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 461 | return TCL_ERROR; |
| 462 | } |
drh | 411995d | 2002-06-25 19:31:18 +0000 | [diff] [blame] | 463 | if( Tcl_GetIndexFromObj(interp, objv[1], DB_strs, "option", 0, &choice) ){ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 464 | return TCL_ERROR; |
| 465 | } |
| 466 | |
drh | 411995d | 2002-06-25 19:31:18 +0000 | [diff] [blame] | 467 | switch( (enum DB_enum)choice ){ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 468 | |
drh | e22a334 | 2003-04-22 20:30:37 +0000 | [diff] [blame^] | 469 | /* $db authorizer ?CALLBACK? |
| 470 | ** |
| 471 | ** Invoke the given callback to authorize each SQL operation as it is |
| 472 | ** compiled. 5 arguments are appended to the callback before it is |
| 473 | ** invoked: |
| 474 | ** |
| 475 | ** (1) The authorization type (ex: SQLITE_CREATE_TABLE, SQLITE_INSERT, ...) |
| 476 | ** (2) First descriptive name (depends on authorization type) |
| 477 | ** (3) Second descriptive name |
| 478 | ** (4) Name of the database (ex: "main", "temp") |
| 479 | ** (5) Name of trigger that is doing the access |
| 480 | ** |
| 481 | ** The callback should return on of the following strings: SQLITE_OK, |
| 482 | ** SQLITE_IGNORE, or SQLITE_DENY. Any other return value is an error. |
| 483 | ** |
| 484 | ** If this method is invoked with no arguments, the current authorization |
| 485 | ** callback string is returned. |
| 486 | */ |
| 487 | case DB_AUTHORIZER: { |
| 488 | if( objc>3 ){ |
| 489 | Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?"); |
| 490 | }else if( objc==2 ){ |
| 491 | if( pDb->zBegin ){ |
| 492 | Tcl_AppendResult(interp, pDb->zAuth, 0); |
| 493 | } |
| 494 | }else{ |
| 495 | char *zAuth; |
| 496 | int len; |
| 497 | if( pDb->zAuth ){ |
| 498 | Tcl_Free(pDb->zAuth); |
| 499 | } |
| 500 | zAuth = Tcl_GetStringFromObj(objv[2], &len); |
| 501 | if( zAuth && len>0 ){ |
| 502 | pDb->zAuth = Tcl_Alloc( len + 1 ); |
| 503 | strcpy(pDb->zAuth, zAuth); |
| 504 | }else{ |
| 505 | pDb->zAuth = 0; |
| 506 | } |
| 507 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 508 | if( pDb->zAuth ){ |
| 509 | pDb->interp = interp; |
| 510 | sqlite_set_authorizer(pDb->db, auth_callback, pDb); |
| 511 | }else{ |
| 512 | sqlite_set_authorizer(pDb->db, 0, 0); |
| 513 | } |
| 514 | #endif |
| 515 | } |
| 516 | break; |
| 517 | } |
| 518 | |
| 519 | |
drh | 0d1a643 | 2003-04-03 15:46:04 +0000 | [diff] [blame] | 520 | /* $db begin_callback ?CALLBACK? |
| 521 | ** |
| 522 | ** Invoke the given callback at the beginning of every SQL transaction. |
| 523 | ** If the callback throws an exception or returns non-zero, then the |
| 524 | ** transaction is aborted. If CALLBACK is an empty string, the callback |
| 525 | ** is disabled. |
| 526 | */ |
| 527 | case DB_BEGIN_HOOK: { |
| 528 | if( objc>3 ){ |
| 529 | Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?"); |
| 530 | }else if( objc==2 ){ |
| 531 | if( pDb->zBegin ){ |
| 532 | Tcl_AppendResult(interp, pDb->zBegin, 0); |
| 533 | } |
| 534 | }else{ |
| 535 | char *zBegin; |
| 536 | int len; |
| 537 | if( pDb->zBegin ){ |
| 538 | Tcl_Free(pDb->zBegin); |
| 539 | } |
| 540 | zBegin = Tcl_GetStringFromObj(objv[2], &len); |
| 541 | if( zBegin && len>0 ){ |
| 542 | pDb->zBegin = Tcl_Alloc( len + 1 ); |
| 543 | strcpy(pDb->zBegin, zBegin); |
| 544 | }else{ |
| 545 | pDb->zBegin = 0; |
| 546 | } |
| 547 | if( pDb->zBegin ){ |
| 548 | pDb->interp = interp; |
| 549 | sqlite_begin_hook(pDb->db, DbBeginHandler, pDb); |
| 550 | }else{ |
| 551 | sqlite_begin_hook(pDb->db, 0, 0); |
| 552 | } |
| 553 | } |
| 554 | break; |
| 555 | } |
| 556 | |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 557 | /* $db busy ?CALLBACK? |
| 558 | ** |
| 559 | ** Invoke the given callback if an SQL statement attempts to open |
| 560 | ** a locked database file. |
| 561 | */ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 562 | case DB_BUSY: { |
| 563 | if( objc>3 ){ |
| 564 | Tcl_WrongNumArgs(interp, 2, objv, "CALLBACK"); |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 565 | return TCL_ERROR; |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 566 | }else if( objc==2 ){ |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 567 | if( pDb->zBusy ){ |
| 568 | Tcl_AppendResult(interp, pDb->zBusy, 0); |
| 569 | } |
| 570 | }else{ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 571 | char *zBusy; |
| 572 | int len; |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 573 | if( pDb->zBusy ){ |
| 574 | Tcl_Free(pDb->zBusy); |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 575 | } |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 576 | zBusy = Tcl_GetStringFromObj(objv[2], &len); |
| 577 | if( zBusy && len>0 ){ |
| 578 | pDb->zBusy = Tcl_Alloc( len + 1 ); |
| 579 | strcpy(pDb->zBusy, zBusy); |
| 580 | }else{ |
| 581 | pDb->zBusy = 0; |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 582 | } |
| 583 | if( pDb->zBusy ){ |
| 584 | pDb->interp = interp; |
| 585 | sqlite_busy_handler(pDb->db, DbBusyHandler, pDb); |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 586 | }else{ |
| 587 | sqlite_busy_handler(pDb->db, 0, 0); |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 588 | } |
| 589 | } |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 590 | break; |
| 591 | } |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 592 | |
drh | c8d30ac | 2002-04-12 10:08:59 +0000 | [diff] [blame] | 593 | /* |
| 594 | ** $db changes |
| 595 | ** |
| 596 | ** Return the number of rows that were modified, inserted, or deleted by |
| 597 | ** the most recent "eval". |
| 598 | */ |
| 599 | case DB_CHANGES: { |
| 600 | Tcl_Obj *pResult; |
| 601 | int nChange; |
| 602 | if( objc!=2 ){ |
| 603 | Tcl_WrongNumArgs(interp, 2, objv, ""); |
| 604 | return TCL_ERROR; |
| 605 | } |
| 606 | nChange = sqlite_changes(pDb->db); |
| 607 | pResult = Tcl_GetObjResult(interp); |
| 608 | Tcl_SetIntObj(pResult, nChange); |
| 609 | break; |
| 610 | } |
| 611 | |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 612 | /* $db close |
| 613 | ** |
| 614 | ** Shutdown the database |
| 615 | */ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 616 | case DB_CLOSE: { |
| 617 | Tcl_DeleteCommand(interp, Tcl_GetStringFromObj(objv[0], 0)); |
| 618 | break; |
| 619 | } |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 620 | |
drh | 0d1a643 | 2003-04-03 15:46:04 +0000 | [diff] [blame] | 621 | /* $db commit_hook ?CALLBACK? |
| 622 | ** |
| 623 | ** Invoke the given callback just before committing every SQL transaction. |
| 624 | ** If the callback throws an exception or returns non-zero, then the |
| 625 | ** transaction is aborted. If CALLBACK is an empty string, the callback |
| 626 | ** is disabled. |
| 627 | */ |
| 628 | case DB_COMMIT_HOOK: { |
| 629 | if( objc>3 ){ |
| 630 | Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?"); |
| 631 | }else if( objc==2 ){ |
| 632 | if( pDb->zCommit ){ |
| 633 | Tcl_AppendResult(interp, pDb->zCommit, 0); |
| 634 | } |
| 635 | }else{ |
| 636 | char *zCommit; |
| 637 | int len; |
| 638 | if( pDb->zCommit ){ |
| 639 | Tcl_Free(pDb->zCommit); |
| 640 | } |
| 641 | zCommit = Tcl_GetStringFromObj(objv[2], &len); |
| 642 | if( zCommit && len>0 ){ |
| 643 | pDb->zCommit = Tcl_Alloc( len + 1 ); |
| 644 | strcpy(pDb->zCommit, zCommit); |
| 645 | }else{ |
| 646 | pDb->zCommit = 0; |
| 647 | } |
| 648 | if( pDb->zCommit ){ |
| 649 | pDb->interp = interp; |
| 650 | sqlite_commit_hook(pDb->db, DbCommitHandler, pDb); |
| 651 | }else{ |
| 652 | sqlite_commit_hook(pDb->db, 0, 0); |
| 653 | } |
| 654 | } |
| 655 | break; |
| 656 | } |
| 657 | |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 658 | /* $db complete SQL |
| 659 | ** |
| 660 | ** Return TRUE if SQL is a complete SQL statement. Return FALSE if |
| 661 | ** additional lines of input are needed. This is similar to the |
| 662 | ** built-in "info complete" command of Tcl. |
| 663 | */ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 664 | case DB_COMPLETE: { |
| 665 | Tcl_Obj *pResult; |
| 666 | int isComplete; |
| 667 | if( objc!=3 ){ |
| 668 | Tcl_WrongNumArgs(interp, 2, objv, "SQL"); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 669 | return TCL_ERROR; |
| 670 | } |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 671 | isComplete = sqlite_complete( Tcl_GetStringFromObj(objv[2], 0) ); |
| 672 | pResult = Tcl_GetObjResult(interp); |
| 673 | Tcl_SetBooleanObj(pResult, isComplete); |
| 674 | break; |
| 675 | } |
drh | dcd997e | 2003-01-31 17:21:49 +0000 | [diff] [blame] | 676 | |
| 677 | /* |
| 678 | ** $db errorcode |
| 679 | ** |
| 680 | ** Return the numeric error code that was returned by the most recent |
| 681 | ** call to sqlite_exec(). |
| 682 | */ |
| 683 | case DB_ERRORCODE: { |
| 684 | Tcl_SetObjResult(interp, Tcl_NewIntObj(pDb->rc)); |
| 685 | break; |
| 686 | } |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 687 | |
| 688 | /* |
| 689 | ** $db eval $sql ?array { ...code... }? |
| 690 | ** |
| 691 | ** The SQL statement in $sql is evaluated. For each row, the values are |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 692 | ** placed in elements of the array named "array" and ...code... is executed. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 693 | ** If "array" and "code" are omitted, then no callback is every invoked. |
| 694 | ** If "array" is an empty string, then the values are placed in variables |
| 695 | ** that have the same name as the fields extracted by the query. |
| 696 | */ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 697 | case DB_EVAL: { |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 698 | CallbackData cbData; |
| 699 | char *zErrMsg; |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 700 | char *zSql; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 701 | int rc; |
drh | 297ecf1 | 2001-04-05 15:57:13 +0000 | [diff] [blame] | 702 | #ifdef UTF_TRANSLATION_NEEDED |
| 703 | Tcl_DString dSql; |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 704 | int i; |
drh | 297ecf1 | 2001-04-05 15:57:13 +0000 | [diff] [blame] | 705 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 706 | |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 707 | if( objc!=5 && objc!=3 ){ |
| 708 | Tcl_WrongNumArgs(interp, 2, objv, "SQL ?ARRAY-NAME CODE?"); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 709 | return TCL_ERROR; |
| 710 | } |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 711 | pDb->interp = interp; |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 712 | zSql = Tcl_GetStringFromObj(objv[2], 0); |
drh | 297ecf1 | 2001-04-05 15:57:13 +0000 | [diff] [blame] | 713 | #ifdef UTF_TRANSLATION_NEEDED |
| 714 | Tcl_DStringInit(&dSql); |
| 715 | Tcl_UtfToExternalDString(NULL, zSql, -1, &dSql); |
| 716 | zSql = Tcl_DStringValue(&dSql); |
| 717 | #endif |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 718 | Tcl_IncrRefCount(objv[2]); |
| 719 | if( objc==5 ){ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 720 | cbData.interp = interp; |
drh | dcc581c | 2000-05-30 13:44:19 +0000 | [diff] [blame] | 721 | cbData.once = 1; |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 722 | cbData.zArray = Tcl_GetStringFromObj(objv[3], 0); |
| 723 | cbData.pCode = objv[4]; |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 724 | cbData.tcl_rc = TCL_OK; |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 725 | cbData.nColName = 0; |
| 726 | cbData.azColName = 0; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 727 | zErrMsg = 0; |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 728 | Tcl_IncrRefCount(objv[3]); |
| 729 | Tcl_IncrRefCount(objv[4]); |
| 730 | rc = sqlite_exec(pDb->db, zSql, DbEvalCallback, &cbData, &zErrMsg); |
| 731 | Tcl_DecrRefCount(objv[4]); |
| 732 | Tcl_DecrRefCount(objv[3]); |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 733 | if( cbData.tcl_rc==TCL_BREAK ){ cbData.tcl_rc = TCL_OK; } |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 734 | }else{ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 735 | Tcl_Obj *pList = Tcl_NewObj(); |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 736 | cbData.tcl_rc = TCL_OK; |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 737 | rc = sqlite_exec(pDb->db, zSql, DbEvalCallback2, pList, &zErrMsg); |
| 738 | Tcl_SetObjResult(interp, pList); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 739 | } |
drh | dcd997e | 2003-01-31 17:21:49 +0000 | [diff] [blame] | 740 | pDb->rc = rc; |
drh | b798fa6 | 2002-09-03 19:43:23 +0000 | [diff] [blame] | 741 | if( rc==SQLITE_ABORT ){ |
| 742 | if( zErrMsg ) free(zErrMsg); |
| 743 | rc = cbData.tcl_rc; |
| 744 | }else if( zErrMsg ){ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 745 | Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE); |
| 746 | free(zErrMsg); |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 747 | rc = TCL_ERROR; |
drh | b798fa6 | 2002-09-03 19:43:23 +0000 | [diff] [blame] | 748 | }else if( rc!=SQLITE_OK ){ |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 749 | Tcl_AppendResult(interp, sqlite_error_string(rc), 0); |
| 750 | rc = TCL_ERROR; |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 751 | }else{ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 752 | } |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 753 | Tcl_DecrRefCount(objv[2]); |
drh | 297ecf1 | 2001-04-05 15:57:13 +0000 | [diff] [blame] | 754 | #ifdef UTF_TRANSLATION_NEEDED |
| 755 | Tcl_DStringFree(&dSql); |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 756 | if( objc==5 && cbData.azColName ){ |
| 757 | for(i=0; i<cbData.nColName; i++){ |
| 758 | if( cbData.azColName[i] ) free(cbData.azColName[i]); |
| 759 | } |
| 760 | free(cbData.azColName); |
drh | ce92706 | 2001-11-09 13:41:09 +0000 | [diff] [blame] | 761 | cbData.azColName = 0; |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 762 | } |
drh | 297ecf1 | 2001-04-05 15:57:13 +0000 | [diff] [blame] | 763 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 764 | return rc; |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 765 | } |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 766 | |
| 767 | /* |
drh | cabb081 | 2002-09-14 13:47:32 +0000 | [diff] [blame] | 768 | ** $db function NAME SCRIPT |
| 769 | ** |
| 770 | ** Create a new SQL function called NAME. Whenever that function is |
| 771 | ** called, invoke SCRIPT to evaluate the function. |
| 772 | */ |
| 773 | case DB_FUNCTION: { |
| 774 | SqlFunc *pFunc; |
| 775 | char *zName; |
| 776 | char *zScript; |
| 777 | int nScript; |
| 778 | if( objc!=4 ){ |
| 779 | Tcl_WrongNumArgs(interp, 2, objv, "NAME SCRIPT"); |
| 780 | return TCL_ERROR; |
| 781 | } |
| 782 | zName = Tcl_GetStringFromObj(objv[2], 0); |
| 783 | zScript = Tcl_GetStringFromObj(objv[3], &nScript); |
| 784 | pFunc = (SqlFunc*)Tcl_Alloc( sizeof(*pFunc) + nScript + 1 ); |
| 785 | if( pFunc==0 ) return TCL_ERROR; |
| 786 | pFunc->interp = interp; |
| 787 | pFunc->pNext = pDb->pFunc; |
| 788 | pFunc->zScript = (char*)&pFunc[1]; |
| 789 | strcpy(pFunc->zScript, zScript); |
| 790 | sqlite_create_function(pDb->db, zName, -1, tclSqlFunc, pFunc); |
| 791 | sqlite_function_type(pDb->db, zName, SQLITE_NUMERIC); |
| 792 | break; |
| 793 | } |
| 794 | |
| 795 | /* |
drh | af9ff33 | 2002-01-16 21:00:27 +0000 | [diff] [blame] | 796 | ** $db last_insert_rowid |
| 797 | ** |
| 798 | ** Return an integer which is the ROWID for the most recent insert. |
| 799 | */ |
| 800 | case DB_LAST_INSERT_ROWID: { |
| 801 | Tcl_Obj *pResult; |
| 802 | int rowid; |
| 803 | if( objc!=2 ){ |
| 804 | Tcl_WrongNumArgs(interp, 2, objv, ""); |
| 805 | return TCL_ERROR; |
| 806 | } |
| 807 | rowid = sqlite_last_insert_rowid(pDb->db); |
| 808 | pResult = Tcl_GetObjResult(interp); |
| 809 | Tcl_SetIntObj(pResult, rowid); |
| 810 | break; |
| 811 | } |
| 812 | |
| 813 | /* |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 814 | ** $db timeout MILLESECONDS |
| 815 | ** |
| 816 | ** Delay for the number of milliseconds specified when a file is locked. |
| 817 | */ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 818 | case DB_TIMEOUT: { |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 819 | int ms; |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 820 | if( objc!=3 ){ |
| 821 | Tcl_WrongNumArgs(interp, 2, objv, "MILLISECONDS"); |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 822 | return TCL_ERROR; |
| 823 | } |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 824 | if( Tcl_GetIntFromObj(interp, objv[2], &ms) ) return TCL_ERROR; |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 825 | sqlite_busy_timeout(pDb->db, ms); |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 826 | break; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 827 | } |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 828 | } /* End of the SWITCH statement */ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 829 | return TCL_OK; |
| 830 | } |
| 831 | |
| 832 | /* |
| 833 | ** sqlite DBNAME FILENAME ?MODE? |
| 834 | ** |
| 835 | ** This is the main Tcl command. When the "sqlite" Tcl command is |
| 836 | ** invoked, this routine runs to process that command. |
| 837 | ** |
| 838 | ** The first argument, DBNAME, is an arbitrary name for a new |
| 839 | ** database connection. This command creates a new command named |
| 840 | ** DBNAME that is used to control that connection. The database |
| 841 | ** connection is deleted when the DBNAME command is deleted. |
| 842 | ** |
| 843 | ** The second argument is the name of the directory that contains |
| 844 | ** the sqlite database that is to be accessed. |
drh | fbc3eab | 2001-04-06 16:13:42 +0000 | [diff] [blame] | 845 | ** |
| 846 | ** For testing purposes, we also support the following: |
| 847 | ** |
| 848 | ** sqlite -encoding |
| 849 | ** |
| 850 | ** Return the encoding used by LIKE and GLOB operators. Choices |
| 851 | ** are UTF-8 and iso8859. |
| 852 | ** |
drh | 647cb0e | 2002-11-04 19:32:25 +0000 | [diff] [blame] | 853 | ** sqlite -version |
| 854 | ** |
| 855 | ** Return the version number of the SQLite library. |
| 856 | ** |
drh | fbc3eab | 2001-04-06 16:13:42 +0000 | [diff] [blame] | 857 | ** sqlite -tcl-uses-utf |
| 858 | ** |
| 859 | ** Return "1" if compiled with a Tcl uses UTF-8. Return "0" if |
| 860 | ** not. Used by tests to make sure the library was compiled |
| 861 | ** correctly. |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 862 | */ |
| 863 | static int DbMain(void *cd, Tcl_Interp *interp, int argc, char **argv){ |
| 864 | int mode; |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 865 | SqliteDb *p; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 866 | char *zErrMsg; |
drh | 06b2718 | 2002-06-26 20:06:05 +0000 | [diff] [blame] | 867 | char zBuf[80]; |
drh | fbc3eab | 2001-04-06 16:13:42 +0000 | [diff] [blame] | 868 | if( argc==2 ){ |
| 869 | if( strcmp(argv[1],"-encoding")==0 ){ |
| 870 | Tcl_AppendResult(interp,sqlite_encoding,0); |
| 871 | return TCL_OK; |
| 872 | } |
drh | 647cb0e | 2002-11-04 19:32:25 +0000 | [diff] [blame] | 873 | if( strcmp(argv[1],"-version")==0 ){ |
| 874 | Tcl_AppendResult(interp,sqlite_version,0); |
| 875 | return TCL_OK; |
| 876 | } |
drh | fbc3eab | 2001-04-06 16:13:42 +0000 | [diff] [blame] | 877 | if( strcmp(argv[1],"-tcl-uses-utf")==0 ){ |
| 878 | #ifdef TCL_UTF_MAX |
| 879 | Tcl_AppendResult(interp,"1",0); |
| 880 | #else |
| 881 | Tcl_AppendResult(interp,"0",0); |
| 882 | #endif |
| 883 | return TCL_OK; |
| 884 | } |
| 885 | } |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 886 | if( argc!=3 && argc!=4 ){ |
| 887 | Tcl_AppendResult(interp,"wrong # args: should be \"", argv[0], |
| 888 | " HANDLE FILENAME ?MODE?\"", 0); |
| 889 | return TCL_ERROR; |
| 890 | } |
| 891 | if( argc==3 ){ |
drh | 58b9576 | 2000-06-02 01:17:37 +0000 | [diff] [blame] | 892 | mode = 0666; |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 893 | }else if( Tcl_GetInt(interp, argv[3], &mode)!=TCL_OK ){ |
| 894 | return TCL_ERROR; |
| 895 | } |
| 896 | zErrMsg = 0; |
drh | 4cdc9e8 | 2000-08-04 14:56:24 +0000 | [diff] [blame] | 897 | p = (SqliteDb*)Tcl_Alloc( sizeof(*p) ); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 898 | if( p==0 ){ |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 899 | Tcl_SetResult(interp, "malloc failed", TCL_STATIC); |
| 900 | return TCL_ERROR; |
| 901 | } |
| 902 | memset(p, 0, sizeof(*p)); |
| 903 | p->db = sqlite_open(argv[2], mode, &zErrMsg); |
| 904 | if( p->db==0 ){ |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 905 | Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE); |
drh | bec3f40 | 2000-08-04 13:49:02 +0000 | [diff] [blame] | 906 | Tcl_Free((char*)p); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 907 | free(zErrMsg); |
| 908 | return TCL_ERROR; |
| 909 | } |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 910 | Tcl_CreateObjCommand(interp, argv[1], DbObjCmd, (char*)p, DbDeleteCmd); |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 911 | |
drh | 06b2718 | 2002-06-26 20:06:05 +0000 | [diff] [blame] | 912 | /* The return value is the value of the sqlite* pointer |
| 913 | */ |
| 914 | sprintf(zBuf, "%p", p->db); |
drh | 5e5377f | 2002-07-07 17:12:36 +0000 | [diff] [blame] | 915 | if( strncmp(zBuf,"0x",2) ){ |
| 916 | sprintf(zBuf, "0x%p", p->db); |
| 917 | } |
drh | 06b2718 | 2002-06-26 20:06:05 +0000 | [diff] [blame] | 918 | Tcl_AppendResult(interp, zBuf, 0); |
| 919 | |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 920 | /* If compiled with SQLITE_TEST turned on, then register the "md5sum" |
drh | 06b2718 | 2002-06-26 20:06:05 +0000 | [diff] [blame] | 921 | ** SQL function. |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 922 | */ |
drh | 28b4e48 | 2002-03-11 02:06:13 +0000 | [diff] [blame] | 923 | #ifdef SQLITE_TEST |
| 924 | { |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 925 | extern void Md5_Register(sqlite*); |
| 926 | Md5_Register(p->db); |
drh | 06b2718 | 2002-06-26 20:06:05 +0000 | [diff] [blame] | 927 | } |
drh | 28b4e48 | 2002-03-11 02:06:13 +0000 | [diff] [blame] | 928 | #endif |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 929 | return TCL_OK; |
| 930 | } |
| 931 | |
| 932 | /* |
drh | 90ca975 | 2001-09-28 17:47:14 +0000 | [diff] [blame] | 933 | ** Provide a dummy Tcl_InitStubs if we are using this as a static |
| 934 | ** library. |
| 935 | */ |
| 936 | #ifndef USE_TCL_STUBS |
| 937 | # undef Tcl_InitStubs |
| 938 | # define Tcl_InitStubs(a,b,c) |
| 939 | #endif |
| 940 | |
| 941 | /* |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 942 | ** Initialize this module. |
| 943 | ** |
| 944 | ** This Tcl module contains only a single new Tcl command named "sqlite". |
| 945 | ** (Hence there is no namespace. There is no point in using a namespace |
| 946 | ** if the extension only supplies one new name!) The "sqlite" command is |
| 947 | ** used to open a new SQLite database. See the DbMain() routine above |
| 948 | ** for additional information. |
| 949 | */ |
| 950 | int Sqlite_Init(Tcl_Interp *interp){ |
drh | 90ca975 | 2001-09-28 17:47:14 +0000 | [diff] [blame] | 951 | Tcl_InitStubs(interp, "8.0", 0); |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 952 | Tcl_CreateCommand(interp, "sqlite", (Tcl_CmdProc*)DbMain, 0, 0); |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 953 | Tcl_PkgProvide(interp, "sqlite", "2.0"); |
drh | 90ca975 | 2001-09-28 17:47:14 +0000 | [diff] [blame] | 954 | return TCL_OK; |
| 955 | } |
| 956 | int Tclsqlite_Init(Tcl_Interp *interp){ |
| 957 | Tcl_InitStubs(interp, "8.0", 0); |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 958 | Tcl_CreateCommand(interp, "sqlite", (Tcl_CmdProc*)DbMain, 0, 0); |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 959 | Tcl_PkgProvide(interp, "sqlite", "2.0"); |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 960 | return TCL_OK; |
| 961 | } |
| 962 | int Sqlite_SafeInit(Tcl_Interp *interp){ |
| 963 | return TCL_OK; |
| 964 | } |
drh | 90ca975 | 2001-09-28 17:47:14 +0000 | [diff] [blame] | 965 | int Tclsqlite_SafeInit(Tcl_Interp *interp){ |
| 966 | return TCL_OK; |
| 967 | } |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 968 | |
drh | 3cebbde | 2000-10-19 14:59:27 +0000 | [diff] [blame] | 969 | #if 0 |
drh | 7589723 | 2000-05-29 14:26:00 +0000 | [diff] [blame] | 970 | /* |
| 971 | ** If compiled using mktclapp, this routine runs to initialize |
| 972 | ** everything. |
| 973 | */ |
| 974 | int Et_AppInit(Tcl_Interp *interp){ |
| 975 | return Sqlite_Init(interp); |
| 976 | } |
drh | 3cebbde | 2000-10-19 14:59:27 +0000 | [diff] [blame] | 977 | #endif |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 978 | |
| 979 | /* |
| 980 | ** If the macro TCLSH is defined and is one, then put in code for the |
| 981 | ** "main" routine that will initialize Tcl. |
| 982 | */ |
| 983 | #if defined(TCLSH) && TCLSH==1 |
| 984 | static char zMainloop[] = |
| 985 | "set line {}\n" |
| 986 | "while {![eof stdin]} {\n" |
| 987 | "if {$line!=\"\"} {\n" |
| 988 | "puts -nonewline \"> \"\n" |
| 989 | "} else {\n" |
| 990 | "puts -nonewline \"% \"\n" |
| 991 | "}\n" |
| 992 | "flush stdout\n" |
| 993 | "append line [gets stdin]\n" |
| 994 | "if {[info complete $line]} {\n" |
| 995 | "if {[catch {uplevel #0 $line} result]} {\n" |
| 996 | "puts stderr \"Error: $result\"\n" |
| 997 | "} elseif {$result!=\"\"} {\n" |
| 998 | "puts $result\n" |
| 999 | "}\n" |
| 1000 | "set line {}\n" |
| 1001 | "} else {\n" |
| 1002 | "append line \\n\n" |
| 1003 | "}\n" |
| 1004 | "}\n" |
| 1005 | ; |
| 1006 | |
| 1007 | #define TCLSH_MAIN main /* Needed to fake out mktclapp */ |
| 1008 | int TCLSH_MAIN(int argc, char **argv){ |
| 1009 | Tcl_Interp *interp; |
drh | 297ecf1 | 2001-04-05 15:57:13 +0000 | [diff] [blame] | 1010 | Tcl_FindExecutable(argv[0]); |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 1011 | interp = Tcl_CreateInterp(); |
| 1012 | Sqlite_Init(interp); |
drh | d9b0257 | 2001-04-15 00:37:09 +0000 | [diff] [blame] | 1013 | #ifdef SQLITE_TEST |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1014 | { |
| 1015 | extern int Sqlitetest1_Init(Tcl_Interp*); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 1016 | extern int Sqlitetest2_Init(Tcl_Interp*); |
| 1017 | extern int Sqlitetest3_Init(Tcl_Interp*); |
drh | efc251d | 2001-07-01 22:12:01 +0000 | [diff] [blame] | 1018 | extern int Md5_Init(Tcl_Interp*); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1019 | Sqlitetest1_Init(interp); |
drh | 5c4d970 | 2001-08-20 00:33:58 +0000 | [diff] [blame] | 1020 | Sqlitetest2_Init(interp); |
| 1021 | Sqlitetest3_Init(interp); |
drh | efc251d | 2001-07-01 22:12:01 +0000 | [diff] [blame] | 1022 | Md5_Init(interp); |
drh | d1bf351 | 2001-04-07 15:24:33 +0000 | [diff] [blame] | 1023 | } |
| 1024 | #endif |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 1025 | if( argc>=2 ){ |
| 1026 | int i; |
| 1027 | Tcl_SetVar(interp,"argv0",argv[1],TCL_GLOBAL_ONLY); |
| 1028 | Tcl_SetVar(interp,"argv", "", TCL_GLOBAL_ONLY); |
| 1029 | for(i=2; i<argc; i++){ |
| 1030 | Tcl_SetVar(interp, "argv", argv[i], |
| 1031 | TCL_GLOBAL_ONLY | TCL_LIST_ELEMENT | TCL_APPEND_VALUE); |
| 1032 | } |
| 1033 | if( Tcl_EvalFile(interp, argv[1])!=TCL_OK ){ |
drh | 0de8c11 | 2002-07-06 16:32:14 +0000 | [diff] [blame] | 1034 | const char *zInfo = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY); |
drh | c61053b | 2000-06-04 12:58:36 +0000 | [diff] [blame] | 1035 | if( zInfo==0 ) zInfo = interp->result; |
| 1036 | fprintf(stderr,"%s: %s\n", *argv, zInfo); |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 1037 | return 1; |
| 1038 | } |
| 1039 | }else{ |
| 1040 | Tcl_GlobalEval(interp, zMainloop); |
| 1041 | } |
| 1042 | return 0; |
| 1043 | } |
| 1044 | #endif /* TCLSH */ |
drh | 6d31316 | 2000-09-21 13:01:35 +0000 | [diff] [blame] | 1045 | |
| 1046 | #endif /* !defined(NO_TCL) */ |