drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | ** 2003 April 6 |
| 3 | ** |
| 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
| 6 | ** |
| 7 | ** May you do good and not evil. |
| 8 | ** May you find forgiveness for yourself and forgive others. |
| 9 | ** May you share freely, never taking more than you give. |
| 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** This file contains code used to implement the PRAGMA command. |
| 13 | ** |
drh | e22a334 | 2003-04-22 20:30:37 +0000 | [diff] [blame^] | 14 | ** $Id: pragma.c,v 1.4 2003/04/22 20:30:39 drh Exp $ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 15 | */ |
| 16 | #include "sqliteInt.h" |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 17 | #include <ctype.h> |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | ** Interpret the given string as a boolean value. |
| 21 | */ |
| 22 | static int getBoolean(char *z){ |
| 23 | static char *azTrue[] = { "yes", "on", "true" }; |
| 24 | int i; |
| 25 | if( z[0]==0 ) return 0; |
| 26 | if( isdigit(z[0]) || (z[0]=='-' && isdigit(z[1])) ){ |
| 27 | return atoi(z); |
| 28 | } |
| 29 | for(i=0; i<sizeof(azTrue)/sizeof(azTrue[0]); i++){ |
| 30 | if( sqliteStrICmp(z,azTrue[i])==0 ) return 1; |
| 31 | } |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | /* |
| 36 | ** Interpret the given string as a safety level. Return 0 for OFF, |
| 37 | ** 1 for ON or NORMAL and 2 for FULL. |
| 38 | ** |
| 39 | ** Note that the values returned are one less that the values that |
| 40 | ** should be passed into sqliteBtreeSetSafetyLevel(). The is done |
| 41 | ** to support legacy SQL code. The safety level used to be boolean |
| 42 | ** and older scripts may have used numbers 0 for OFF and 1 for ON. |
| 43 | */ |
| 44 | static int getSafetyLevel(char *z){ |
| 45 | static const struct { |
| 46 | const char *zWord; |
| 47 | int val; |
| 48 | } aKey[] = { |
| 49 | { "no", 0 }, |
| 50 | { "off", 0 }, |
| 51 | { "false", 0 }, |
| 52 | { "yes", 1 }, |
| 53 | { "on", 1 }, |
| 54 | { "true", 1 }, |
| 55 | { "full", 2 }, |
| 56 | }; |
| 57 | int i; |
| 58 | if( z[0]==0 ) return 1; |
| 59 | if( isdigit(z[0]) || (z[0]=='-' && isdigit(z[1])) ){ |
| 60 | return atoi(z); |
| 61 | } |
| 62 | for(i=0; i<sizeof(aKey)/sizeof(aKey[0]); i++){ |
| 63 | if( sqliteStrICmp(z,aKey[i].zWord)==0 ) return aKey[i].val; |
| 64 | } |
| 65 | return 1; |
| 66 | } |
| 67 | |
| 68 | /* |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 69 | ** Interpret the given string as a temp db location. Return 1 for file |
| 70 | ** backed temporary databases, 2 for the Red-Black tree in memory database |
| 71 | ** and 0 to use the compile-time default. |
| 72 | */ |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 73 | static int getTempStore(char *z){ |
| 74 | if (sqliteStrICmp(z, "file") == 0) { |
| 75 | return 1; |
| 76 | }else if(sqliteStrICmp(z, "memory") == 0) { |
| 77 | return 2; |
| 78 | }else{ |
| 79 | return 0; |
| 80 | } |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /* |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 84 | ** Process a pragma statement. |
| 85 | ** |
| 86 | ** Pragmas are of this form: |
| 87 | ** |
| 88 | ** PRAGMA id = value |
| 89 | ** |
| 90 | ** The identifier might also be a string. The value is a string, and |
| 91 | ** identifier, or a number. If minusFlag is true, then the value is |
| 92 | ** a number that was preceded by a minus sign. |
| 93 | */ |
| 94 | void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){ |
| 95 | char *zLeft = 0; |
| 96 | char *zRight = 0; |
| 97 | sqlite *db = pParse->db; |
| 98 | Vdbe *v = sqliteGetVdbe(pParse); |
| 99 | if( v==0 ) return; |
| 100 | |
| 101 | zLeft = sqliteStrNDup(pLeft->z, pLeft->n); |
| 102 | sqliteDequote(zLeft); |
| 103 | if( minusFlag ){ |
| 104 | zRight = 0; |
| 105 | sqliteSetNString(&zRight, "-", 1, pRight->z, pRight->n, 0); |
| 106 | }else{ |
| 107 | zRight = sqliteStrNDup(pRight->z, pRight->n); |
| 108 | sqliteDequote(zRight); |
| 109 | } |
drh | e22a334 | 2003-04-22 20:30:37 +0000 | [diff] [blame^] | 110 | if( sqliteAuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, 0) ){ |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 111 | sqliteFree(zLeft); |
| 112 | sqliteFree(zRight); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | ** PRAGMA default_cache_size |
| 118 | ** PRAGMA default_cache_size=N |
| 119 | ** |
| 120 | ** The first form reports the current persistent setting for the |
| 121 | ** page cache size. The value returned is the maximum number of |
| 122 | ** pages in the page cache. The second form sets both the current |
| 123 | ** page cache size value and the persistent page cache size value |
| 124 | ** stored in the database file. |
| 125 | ** |
| 126 | ** The default cache size is stored in meta-value 2 of page 1 of the |
| 127 | ** database file. The cache size is actually the absolute value of |
| 128 | ** this memory location. The sign of meta-value 2 determines the |
| 129 | ** synchronous setting. A negative value means synchronous is off |
| 130 | ** and a positive value means synchronous is on. |
| 131 | */ |
| 132 | if( sqliteStrICmp(zLeft,"default_cache_size")==0 ){ |
| 133 | static VdbeOp getCacheSize[] = { |
| 134 | { OP_ReadCookie, 0, 2, 0}, |
| 135 | { OP_AbsValue, 0, 0, 0}, |
| 136 | { OP_Dup, 0, 0, 0}, |
| 137 | { OP_Integer, 0, 0, 0}, |
| 138 | { OP_Ne, 0, 6, 0}, |
| 139 | { OP_Integer, MAX_PAGES,0, 0}, |
| 140 | { OP_ColumnName, 0, 0, "cache_size"}, |
| 141 | { OP_Callback, 1, 0, 0}, |
| 142 | }; |
| 143 | if( pRight->z==pLeft->z ){ |
| 144 | sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize); |
| 145 | }else{ |
| 146 | int addr; |
| 147 | int size = atoi(zRight); |
| 148 | if( size<0 ) size = -size; |
| 149 | sqliteBeginWriteOperation(pParse, 0, 0); |
| 150 | sqliteVdbeAddOp(v, OP_Integer, size, 0); |
| 151 | sqliteVdbeAddOp(v, OP_ReadCookie, 0, 2); |
| 152 | addr = sqliteVdbeAddOp(v, OP_Integer, 0, 0); |
| 153 | sqliteVdbeAddOp(v, OP_Ge, 0, addr+3); |
| 154 | sqliteVdbeAddOp(v, OP_Negative, 0, 0); |
| 155 | sqliteVdbeAddOp(v, OP_SetCookie, 0, 2); |
| 156 | sqliteEndWriteOperation(pParse); |
| 157 | db->cache_size = db->cache_size<0 ? -size : size; |
| 158 | sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size); |
| 159 | } |
| 160 | }else |
| 161 | |
| 162 | /* |
| 163 | ** PRAGMA cache_size |
| 164 | ** PRAGMA cache_size=N |
| 165 | ** |
| 166 | ** The first form reports the current local setting for the |
| 167 | ** page cache size. The local setting can be different from |
| 168 | ** the persistent cache size value that is stored in the database |
| 169 | ** file itself. The value returned is the maximum number of |
| 170 | ** pages in the page cache. The second form sets the local |
| 171 | ** page cache size value. It does not change the persistent |
| 172 | ** cache size stored on the disk so the cache size will revert |
| 173 | ** to its default value when the database is closed and reopened. |
| 174 | ** N should be a positive integer. |
| 175 | */ |
| 176 | if( sqliteStrICmp(zLeft,"cache_size")==0 ){ |
| 177 | static VdbeOp getCacheSize[] = { |
| 178 | { OP_ColumnName, 0, 0, "cache_size"}, |
| 179 | { OP_Callback, 1, 0, 0}, |
| 180 | }; |
| 181 | if( pRight->z==pLeft->z ){ |
| 182 | int size = db->cache_size;; |
| 183 | if( size<0 ) size = -size; |
| 184 | sqliteVdbeAddOp(v, OP_Integer, size, 0); |
| 185 | sqliteVdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize); |
| 186 | }else{ |
| 187 | int size = atoi(zRight); |
| 188 | if( size<0 ) size = -size; |
| 189 | if( db->cache_size<0 ) size = -size; |
| 190 | db->cache_size = size; |
| 191 | sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size); |
| 192 | } |
| 193 | }else |
| 194 | |
| 195 | /* |
| 196 | ** PRAGMA default_synchronous |
| 197 | ** PRAGMA default_synchronous=ON|OFF|NORMAL|FULL |
| 198 | ** |
| 199 | ** The first form returns the persistent value of the "synchronous" setting |
| 200 | ** that is stored in the database. This is the synchronous setting that |
| 201 | ** is used whenever the database is opened unless overridden by a separate |
| 202 | ** "synchronous" pragma. The second form changes the persistent and the |
| 203 | ** local synchronous setting to the value given. |
| 204 | ** |
| 205 | ** If synchronous is OFF, SQLite does not attempt any fsync() systems calls |
| 206 | ** to make sure data is committed to disk. Write operations are very fast, |
| 207 | ** but a power failure can leave the database in an inconsistent state. |
| 208 | ** If synchronous is ON or NORMAL, SQLite will do an fsync() system call to |
| 209 | ** make sure data is being written to disk. The risk of corruption due to |
| 210 | ** a power loss in this mode is negligible but non-zero. If synchronous |
| 211 | ** is FULL, extra fsync()s occur to reduce the risk of corruption to near |
| 212 | ** zero, but with a write performance penalty. The default mode is NORMAL. |
| 213 | */ |
| 214 | if( sqliteStrICmp(zLeft,"default_synchronous")==0 ){ |
| 215 | static VdbeOp getSync[] = { |
| 216 | { OP_ColumnName, 0, 0, "synchronous"}, |
| 217 | { OP_ReadCookie, 0, 3, 0}, |
| 218 | { OP_Dup, 0, 0, 0}, |
| 219 | { OP_If, 0, 0, 0}, /* 3 */ |
| 220 | { OP_ReadCookie, 0, 2, 0}, |
| 221 | { OP_Integer, 0, 0, 0}, |
| 222 | { OP_Lt, 0, 5, 0}, |
| 223 | { OP_AddImm, 1, 0, 0}, |
| 224 | { OP_Callback, 1, 0, 0}, |
| 225 | { OP_Halt, 0, 0, 0}, |
| 226 | { OP_AddImm, -1, 0, 0}, /* 10 */ |
| 227 | { OP_Callback, 1, 0, 0} |
| 228 | }; |
| 229 | if( pRight->z==pLeft->z ){ |
| 230 | int addr = sqliteVdbeAddOpList(v, ArraySize(getSync), getSync); |
| 231 | sqliteVdbeChangeP2(v, addr+3, addr+10); |
| 232 | }else{ |
| 233 | int addr; |
| 234 | int size = db->cache_size; |
| 235 | if( size<0 ) size = -size; |
| 236 | sqliteBeginWriteOperation(pParse, 0, 0); |
| 237 | sqliteVdbeAddOp(v, OP_ReadCookie, 0, 2); |
| 238 | sqliteVdbeAddOp(v, OP_Dup, 0, 0); |
| 239 | addr = sqliteVdbeAddOp(v, OP_Integer, 0, 0); |
| 240 | sqliteVdbeAddOp(v, OP_Ne, 0, addr+3); |
| 241 | sqliteVdbeAddOp(v, OP_AddImm, MAX_PAGES, 0); |
| 242 | sqliteVdbeAddOp(v, OP_AbsValue, 0, 0); |
| 243 | db->safety_level = getSafetyLevel(zRight)+1; |
| 244 | if( db->safety_level==1 ){ |
| 245 | sqliteVdbeAddOp(v, OP_Negative, 0, 0); |
| 246 | size = -size; |
| 247 | } |
| 248 | sqliteVdbeAddOp(v, OP_SetCookie, 0, 2); |
| 249 | sqliteVdbeAddOp(v, OP_Integer, db->safety_level, 0); |
| 250 | sqliteVdbeAddOp(v, OP_SetCookie, 0, 3); |
| 251 | sqliteEndWriteOperation(pParse); |
| 252 | db->cache_size = size; |
| 253 | sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size); |
| 254 | sqliteBtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level); |
| 255 | } |
| 256 | }else |
| 257 | |
| 258 | /* |
| 259 | ** PRAGMA synchronous |
| 260 | ** PRAGMA synchronous=OFF|ON|NORMAL|FULL |
| 261 | ** |
| 262 | ** Return or set the local value of the synchronous flag. Changing |
| 263 | ** the local value does not make changes to the disk file and the |
| 264 | ** default value will be restored the next time the database is |
| 265 | ** opened. |
| 266 | */ |
| 267 | if( sqliteStrICmp(zLeft,"synchronous")==0 ){ |
| 268 | static VdbeOp getSync[] = { |
| 269 | { OP_ColumnName, 0, 0, "synchronous"}, |
| 270 | { OP_Callback, 1, 0, 0}, |
| 271 | }; |
| 272 | if( pRight->z==pLeft->z ){ |
| 273 | sqliteVdbeAddOp(v, OP_Integer, db->safety_level-1, 0); |
| 274 | sqliteVdbeAddOpList(v, ArraySize(getSync), getSync); |
| 275 | }else{ |
| 276 | int size = db->cache_size; |
| 277 | if( size<0 ) size = -size; |
| 278 | db->safety_level = getSafetyLevel(zRight)+1; |
| 279 | if( db->safety_level==1 ) size = -size; |
| 280 | db->cache_size = size; |
| 281 | sqliteBtreeSetCacheSize(db->aDb[0].pBt, db->cache_size); |
| 282 | sqliteBtreeSetSafetyLevel(db->aDb[0].pBt, db->safety_level); |
| 283 | } |
| 284 | }else |
| 285 | |
| 286 | if( sqliteStrICmp(zLeft, "trigger_overhead_test")==0 ){ |
| 287 | if( getBoolean(zRight) ){ |
| 288 | always_code_trigger_setup = 1; |
| 289 | }else{ |
| 290 | always_code_trigger_setup = 0; |
| 291 | } |
| 292 | }else |
| 293 | |
| 294 | if( sqliteStrICmp(zLeft, "vdbe_trace")==0 ){ |
| 295 | if( getBoolean(zRight) ){ |
| 296 | db->flags |= SQLITE_VdbeTrace; |
| 297 | }else{ |
| 298 | db->flags &= ~SQLITE_VdbeTrace; |
| 299 | } |
| 300 | }else |
| 301 | |
| 302 | if( sqliteStrICmp(zLeft, "full_column_names")==0 ){ |
| 303 | if( getBoolean(zRight) ){ |
| 304 | db->flags |= SQLITE_FullColNames; |
| 305 | }else{ |
| 306 | db->flags &= ~SQLITE_FullColNames; |
| 307 | } |
| 308 | }else |
| 309 | |
| 310 | if( sqliteStrICmp(zLeft, "show_datatypes")==0 ){ |
| 311 | if( getBoolean(zRight) ){ |
| 312 | db->flags |= SQLITE_ReportTypes; |
| 313 | }else{ |
| 314 | db->flags &= ~SQLITE_ReportTypes; |
| 315 | } |
| 316 | }else |
| 317 | |
| 318 | if( sqliteStrICmp(zLeft, "result_set_details")==0 ){ |
| 319 | if( getBoolean(zRight) ){ |
| 320 | db->flags |= SQLITE_ResultDetails; |
| 321 | }else{ |
| 322 | db->flags &= ~SQLITE_ResultDetails; |
| 323 | } |
| 324 | }else |
| 325 | |
| 326 | if( sqliteStrICmp(zLeft, "count_changes")==0 ){ |
| 327 | if( getBoolean(zRight) ){ |
| 328 | db->flags |= SQLITE_CountRows; |
| 329 | }else{ |
| 330 | db->flags &= ~SQLITE_CountRows; |
| 331 | } |
| 332 | }else |
| 333 | |
| 334 | if( sqliteStrICmp(zLeft, "empty_result_callbacks")==0 ){ |
| 335 | if( getBoolean(zRight) ){ |
| 336 | db->flags |= SQLITE_NullCallback; |
| 337 | }else{ |
| 338 | db->flags &= ~SQLITE_NullCallback; |
| 339 | } |
| 340 | }else |
| 341 | |
| 342 | if( sqliteStrICmp(zLeft, "table_info")==0 ){ |
| 343 | Table *pTab; |
| 344 | pTab = sqliteFindTable(db, zRight, 0); |
| 345 | if( pTab ){ |
| 346 | static VdbeOp tableInfoPreface[] = { |
| 347 | { OP_ColumnName, 0, 0, "cid"}, |
| 348 | { OP_ColumnName, 1, 0, "name"}, |
| 349 | { OP_ColumnName, 2, 0, "type"}, |
| 350 | { OP_ColumnName, 3, 0, "notnull"}, |
| 351 | { OP_ColumnName, 4, 0, "dflt_value"}, |
| 352 | }; |
| 353 | int i; |
| 354 | sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface); |
| 355 | sqliteViewGetColumnNames(pParse, pTab); |
| 356 | for(i=0; i<pTab->nCol; i++){ |
| 357 | sqliteVdbeAddOp(v, OP_Integer, i, 0); |
| 358 | sqliteVdbeAddOp(v, OP_String, 0, 0); |
| 359 | sqliteVdbeChangeP3(v, -1, pTab->aCol[i].zName, P3_STATIC); |
| 360 | sqliteVdbeAddOp(v, OP_String, 0, 0); |
| 361 | sqliteVdbeChangeP3(v, -1, |
| 362 | pTab->aCol[i].zType ? pTab->aCol[i].zType : "numeric", P3_STATIC); |
| 363 | sqliteVdbeAddOp(v, OP_Integer, pTab->aCol[i].notNull, 0); |
| 364 | sqliteVdbeAddOp(v, OP_String, 0, 0); |
| 365 | sqliteVdbeChangeP3(v, -1, pTab->aCol[i].zDflt, P3_STATIC); |
| 366 | sqliteVdbeAddOp(v, OP_Callback, 5, 0); |
| 367 | } |
| 368 | } |
| 369 | }else |
| 370 | |
| 371 | if( sqliteStrICmp(zLeft, "index_info")==0 ){ |
| 372 | Index *pIdx; |
| 373 | Table *pTab; |
| 374 | pIdx = sqliteFindIndex(db, zRight, 0); |
| 375 | if( pIdx ){ |
| 376 | static VdbeOp tableInfoPreface[] = { |
| 377 | { OP_ColumnName, 0, 0, "seqno"}, |
| 378 | { OP_ColumnName, 1, 0, "cid"}, |
| 379 | { OP_ColumnName, 2, 0, "name"}, |
| 380 | }; |
| 381 | int i; |
| 382 | pTab = pIdx->pTable; |
| 383 | sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface); |
| 384 | for(i=0; i<pIdx->nColumn; i++){ |
| 385 | int cnum = pIdx->aiColumn[i]; |
| 386 | sqliteVdbeAddOp(v, OP_Integer, i, 0); |
| 387 | sqliteVdbeAddOp(v, OP_Integer, cnum, 0); |
| 388 | sqliteVdbeAddOp(v, OP_String, 0, 0); |
| 389 | assert( pTab->nCol>cnum ); |
| 390 | sqliteVdbeChangeP3(v, -1, pTab->aCol[cnum].zName, P3_STATIC); |
| 391 | sqliteVdbeAddOp(v, OP_Callback, 3, 0); |
| 392 | } |
| 393 | } |
| 394 | }else |
| 395 | |
| 396 | if( sqliteStrICmp(zLeft, "index_list")==0 ){ |
| 397 | Index *pIdx; |
| 398 | Table *pTab; |
| 399 | pTab = sqliteFindTable(db, zRight, 0); |
| 400 | if( pTab ){ |
| 401 | v = sqliteGetVdbe(pParse); |
| 402 | pIdx = pTab->pIndex; |
| 403 | } |
| 404 | if( pTab && pIdx ){ |
| 405 | int i = 0; |
| 406 | static VdbeOp indexListPreface[] = { |
| 407 | { OP_ColumnName, 0, 0, "seq"}, |
| 408 | { OP_ColumnName, 1, 0, "name"}, |
| 409 | { OP_ColumnName, 2, 0, "unique"}, |
| 410 | }; |
| 411 | |
| 412 | sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface); |
| 413 | while(pIdx){ |
| 414 | sqliteVdbeAddOp(v, OP_Integer, i, 0); |
| 415 | sqliteVdbeAddOp(v, OP_String, 0, 0); |
| 416 | sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC); |
| 417 | sqliteVdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0); |
| 418 | sqliteVdbeAddOp(v, OP_Callback, 3, 0); |
| 419 | ++i; |
| 420 | pIdx = pIdx->pNext; |
| 421 | } |
| 422 | } |
| 423 | }else |
| 424 | |
| 425 | if( sqliteStrICmp(zLeft, "database_list")==0 ){ |
| 426 | int i; |
| 427 | static VdbeOp indexListPreface[] = { |
| 428 | { OP_ColumnName, 0, 0, "seq"}, |
| 429 | { OP_ColumnName, 1, 0, "name"}, |
| 430 | }; |
| 431 | |
| 432 | sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface); |
| 433 | for(i=0; i<db->nDb; i++){ |
| 434 | if( db->aDb[i].pBt==0 ) continue; |
| 435 | assert( db->aDb[i].zName!=0 ); |
| 436 | sqliteVdbeAddOp(v, OP_Integer, i, 0); |
| 437 | sqliteVdbeAddOp(v, OP_String, 0, 0); |
| 438 | sqliteVdbeChangeP3(v, -1, db->aDb[i].zName, P3_STATIC); |
| 439 | sqliteVdbeAddOp(v, OP_Callback, 2, 0); |
| 440 | } |
| 441 | }else |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 442 | /* |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 443 | ** PRAGMA temp_store |
| 444 | ** PRAGMA temp_store = "default"|"memory"|"file" |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 445 | ** |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 446 | ** Return or set the local value of the temp_store flag. Changing |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 447 | ** the local value does not make changes to the disk file and the default |
| 448 | ** value will be restored the next time the database is opened. |
| 449 | ** |
| 450 | ** Note that it is possible for the library compile-time options to |
| 451 | ** override this setting |
| 452 | */ |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 453 | if( sqliteStrICmp(zLeft, "temp_store")==0 ){ |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 454 | static VdbeOp getTmpDbLoc[] = { |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 455 | { OP_ColumnName, 0, 0, "temp_store"}, |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 456 | { OP_Callback, 1, 0, 0}, |
| 457 | }; |
| 458 | if( pRight->z==pLeft->z ){ |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 459 | sqliteVdbeAddOp(v, OP_Integer, db->temp_store, 0); |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 460 | sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc); |
| 461 | }else{ |
| 462 | if (&db->aDb[1].pBt != 0) { |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 463 | sqliteErrorMsg(pParse, "The temporary database already exists - " |
| 464 | "its location cannot now be changed"); |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 465 | } else { |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 466 | db->temp_store = getTempStore(zRight); |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | }else |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 470 | |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 471 | /* |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 472 | ** PRAGMA default_temp_store |
| 473 | ** PRAGMA default_temp_store = "default"|"memory"|"file" |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 474 | ** |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 475 | ** Return or set the value of the persistent temp_store flag (as |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 476 | ** well as the value currently in force). |
| 477 | ** |
| 478 | ** Note that it is possible for the library compile-time options to |
| 479 | ** override this setting |
| 480 | */ |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 481 | if( sqliteStrICmp(zLeft, "default_temp_store")==0 ){ |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 482 | static VdbeOp getTmpDbLoc[] = { |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 483 | { OP_ColumnName, 0, 0, "temp_store"}, |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 484 | { OP_ReadCookie, 0, 5, 0}, |
| 485 | { OP_Callback, 1, 0, 0}}; |
| 486 | if( pRight->z==pLeft->z ){ |
| 487 | sqliteVdbeAddOpList(v, ArraySize(getTmpDbLoc), getTmpDbLoc); |
| 488 | }else{ |
| 489 | if (&db->aDb[1].pBt != 0) { |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 490 | sqliteErrorMsg(pParse, "The temporary database already exists - " |
| 491 | "its location cannot now be changed"); |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 492 | } else { |
| 493 | sqliteBeginWriteOperation(pParse, 0, 0); |
drh | 13bff81 | 2003-04-15 01:19:47 +0000 | [diff] [blame] | 494 | db->temp_store = getTempStore(zRight); |
| 495 | sqliteVdbeAddOp(v, OP_Integer, db->temp_store, 0); |
paul | b0208cc | 2003-04-13 18:26:49 +0000 | [diff] [blame] | 496 | sqliteVdbeAddOp(v, OP_SetCookie, 0, 5); |
| 497 | sqliteEndWriteOperation(pParse); |
| 498 | } |
| 499 | } |
| 500 | }else |
drh | c11d4f9 | 2003-04-06 21:08:24 +0000 | [diff] [blame] | 501 | |
| 502 | #ifndef NDEBUG |
| 503 | if( sqliteStrICmp(zLeft, "parser_trace")==0 ){ |
| 504 | extern void sqliteParserTrace(FILE*, char *); |
| 505 | if( getBoolean(zRight) ){ |
| 506 | sqliteParserTrace(stdout, "parser: "); |
| 507 | }else{ |
| 508 | sqliteParserTrace(0, 0); |
| 509 | } |
| 510 | }else |
| 511 | #endif |
| 512 | |
| 513 | if( sqliteStrICmp(zLeft, "integrity_check")==0 ){ |
| 514 | static VdbeOp checkDb[] = { |
| 515 | { OP_SetInsert, 0, 0, "2"}, |
| 516 | { OP_Integer, 0, 0, 0}, |
| 517 | { OP_OpenRead, 0, 2, 0}, |
| 518 | { OP_Rewind, 0, 7, 0}, |
| 519 | { OP_Column, 0, 3, 0}, /* 4 */ |
| 520 | { OP_SetInsert, 0, 0, 0}, |
| 521 | { OP_Next, 0, 4, 0}, |
| 522 | { OP_IntegrityCk, 0, 0, 0}, /* 7 */ |
| 523 | { OP_ColumnName, 0, 0, "integrity_check"}, |
| 524 | { OP_Callback, 1, 0, 0}, |
| 525 | { OP_SetInsert, 1, 0, "2"}, |
| 526 | { OP_Integer, 1, 0, 0}, |
| 527 | { OP_OpenRead, 1, 2, 0}, |
| 528 | { OP_Rewind, 1, 17, 0}, |
| 529 | { OP_Column, 1, 3, 0}, /* 14 */ |
| 530 | { OP_SetInsert, 1, 0, 0}, |
| 531 | { OP_Next, 1, 14, 0}, |
| 532 | { OP_IntegrityCk, 1, 1, 0}, /* 17 */ |
| 533 | { OP_Callback, 1, 0, 0}, |
| 534 | }; |
| 535 | sqliteVdbeAddOpList(v, ArraySize(checkDb), checkDb); |
| 536 | }else |
| 537 | |
| 538 | {} |
| 539 | sqliteFree(zLeft); |
| 540 | sqliteFree(zRight); |
| 541 | } |