OLD | NEW |
1 /* | 1 /* |
2 ** 2003 April 6 | 2 ** 2003 April 6 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 20 matching lines...) Expand all Loading... |
31 ** ATTACH DATABASE abc||def AS 'db2' | 31 ** ATTACH DATABASE abc||def AS 'db2' |
32 ** | 32 ** |
33 ** will fail because neither abc or def can be resolved. | 33 ** will fail because neither abc or def can be resolved. |
34 */ | 34 */ |
35 static int resolveAttachExpr(NameContext *pName, Expr *pExpr) | 35 static int resolveAttachExpr(NameContext *pName, Expr *pExpr) |
36 { | 36 { |
37 int rc = SQLITE_OK; | 37 int rc = SQLITE_OK; |
38 if( pExpr ){ | 38 if( pExpr ){ |
39 if( pExpr->op!=TK_ID ){ | 39 if( pExpr->op!=TK_ID ){ |
40 rc = sqlite3ResolveExprNames(pName, pExpr); | 40 rc = sqlite3ResolveExprNames(pName, pExpr); |
41 if( rc==SQLITE_OK && !sqlite3ExprIsConstant(pExpr) ){ | |
42 sqlite3ErrorMsg(pName->pParse, "invalid name: \"%s\"", pExpr->u.zToken); | |
43 return SQLITE_ERROR; | |
44 } | |
45 }else{ | 41 }else{ |
46 pExpr->op = TK_STRING; | 42 pExpr->op = TK_STRING; |
47 } | 43 } |
48 } | 44 } |
49 return rc; | 45 return rc; |
50 } | 46 } |
51 | 47 |
52 /* | 48 /* |
53 ** An SQL user-function registered to do the work of an ATTACH statement. The | 49 ** An SQL user-function registered to do the work of an ATTACH statement. The |
54 ** three arguments to the function come directly from an attach statement: | 50 ** three arguments to the function come directly from an attach statement: |
55 ** | 51 ** |
56 ** ATTACH DATABASE x AS y KEY z | 52 ** ATTACH DATABASE x AS y KEY z |
57 ** | 53 ** |
58 ** SELECT sqlite_attach(x, y, z) | 54 ** SELECT sqlite_attach(x, y, z) |
59 ** | 55 ** |
60 ** If the optional "KEY z" syntax is omitted, an SQL NULL is passed as the | 56 ** If the optional "KEY z" syntax is omitted, an SQL NULL is passed as the |
61 ** third argument. | 57 ** third argument. |
62 */ | 58 */ |
63 static void attachFunc( | 59 static void attachFunc( |
64 sqlite3_context *context, | 60 sqlite3_context *context, |
65 int NotUsed, | 61 int NotUsed, |
66 sqlite3_value **argv | 62 sqlite3_value **argv |
67 ){ | 63 ){ |
68 int i; | 64 int i; |
69 int rc = 0; | 65 int rc = 0; |
70 sqlite3 *db = sqlite3_context_db_handle(context); | 66 sqlite3 *db = sqlite3_context_db_handle(context); |
71 const char *zName; | 67 const char *zName; |
72 const char *zFile; | 68 const char *zFile; |
| 69 char *zPath = 0; |
| 70 char *zErr = 0; |
| 71 unsigned int flags; |
73 Db *aNew; | 72 Db *aNew; |
74 char *zErrDyn = 0; | 73 char *zErrDyn = 0; |
| 74 sqlite3_vfs *pVfs; |
75 | 75 |
76 UNUSED_PARAMETER(NotUsed); | 76 UNUSED_PARAMETER(NotUsed); |
77 | 77 |
78 zFile = (const char *)sqlite3_value_text(argv[0]); | 78 zFile = (const char *)sqlite3_value_text(argv[0]); |
79 zName = (const char *)sqlite3_value_text(argv[1]); | 79 zName = (const char *)sqlite3_value_text(argv[1]); |
80 if( zFile==0 ) zFile = ""; | 80 if( zFile==0 ) zFile = ""; |
81 if( zName==0 ) zName = ""; | 81 if( zName==0 ) zName = ""; |
82 | 82 |
83 /* Check for the following errors: | 83 /* Check for the following errors: |
84 ** | 84 ** |
(...skipping 13 matching lines...) Expand all Loading... |
98 } | 98 } |
99 for(i=0; i<db->nDb; i++){ | 99 for(i=0; i<db->nDb; i++){ |
100 char *z = db->aDb[i].zName; | 100 char *z = db->aDb[i].zName; |
101 assert( z && zName ); | 101 assert( z && zName ); |
102 if( sqlite3StrICmp(z, zName)==0 ){ | 102 if( sqlite3StrICmp(z, zName)==0 ){ |
103 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName); | 103 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName); |
104 goto attach_error; | 104 goto attach_error; |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 /* Allocate the new entry in the db->aDb[] array and initialise the schema | 108 /* Allocate the new entry in the db->aDb[] array and initialize the schema |
109 ** hash tables. | 109 ** hash tables. |
110 */ | 110 */ |
111 if( db->aDb==db->aDbStatic ){ | 111 if( db->aDb==db->aDbStatic ){ |
112 aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 ); | 112 aNew = sqlite3DbMallocRaw(db, sizeof(db->aDb[0])*3 ); |
113 if( aNew==0 ) return; | 113 if( aNew==0 ) return; |
114 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2); | 114 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2); |
115 }else{ | 115 }else{ |
116 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); | 116 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) ); |
117 if( aNew==0 ) return; | 117 if( aNew==0 ) return; |
118 } | 118 } |
119 db->aDb = aNew; | 119 db->aDb = aNew; |
120 aNew = &db->aDb[db->nDb]; | 120 aNew = &db->aDb[db->nDb]; |
121 memset(aNew, 0, sizeof(*aNew)); | 121 memset(aNew, 0, sizeof(*aNew)); |
122 | 122 |
123 /* Open the database file. If the btree is successfully opened, use | 123 /* Open the database file. If the btree is successfully opened, use |
124 ** it to obtain the database schema. At this point the schema may | 124 ** it to obtain the database schema. At this point the schema may |
125 ** or may not be initialised. | 125 ** or may not be initialized. |
126 */ | 126 */ |
127 rc = sqlite3BtreeOpen(zFile, db, &aNew->pBt, 0, | 127 flags = db->openFlags; |
128 db->openFlags | SQLITE_OPEN_MAIN_DB); | 128 rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr); |
| 129 if( rc!=SQLITE_OK ){ |
| 130 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; |
| 131 sqlite3_result_error(context, zErr, -1); |
| 132 sqlite3_free(zErr); |
| 133 return; |
| 134 } |
| 135 assert( pVfs ); |
| 136 flags |= SQLITE_OPEN_MAIN_DB; |
| 137 rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags); |
| 138 sqlite3_free( zPath ); |
129 db->nDb++; | 139 db->nDb++; |
130 if( rc==SQLITE_CONSTRAINT ){ | 140 if( rc==SQLITE_CONSTRAINT ){ |
131 rc = SQLITE_ERROR; | 141 rc = SQLITE_ERROR; |
132 zErrDyn = sqlite3MPrintf(db, "database is already attached"); | 142 zErrDyn = sqlite3MPrintf(db, "database is already attached"); |
133 }else if( rc==SQLITE_OK ){ | 143 }else if( rc==SQLITE_OK ){ |
134 Pager *pPager; | 144 Pager *pPager; |
135 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt); | 145 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt); |
136 if( !aNew->pSchema ){ | 146 if( !aNew->pSchema ){ |
137 rc = SQLITE_NOMEM; | 147 rc = SQLITE_NOMEM; |
138 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){ | 148 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){ |
139 zErrDyn = sqlite3MPrintf(db, | 149 zErrDyn = sqlite3MPrintf(db, |
140 "attached databases must use the same text encoding as main database"); | 150 "attached databases must use the same text encoding as main database"); |
141 rc = SQLITE_ERROR; | 151 rc = SQLITE_ERROR; |
142 } | 152 } |
143 pPager = sqlite3BtreePager(aNew->pBt); | 153 pPager = sqlite3BtreePager(aNew->pBt); |
144 sqlite3PagerLockingMode(pPager, db->dfltLockMode); | 154 sqlite3PagerLockingMode(pPager, db->dfltLockMode); |
145 sqlite3BtreeSecureDelete(aNew->pBt, | 155 sqlite3BtreeSecureDelete(aNew->pBt, |
146 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) ); | 156 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) ); |
| 157 #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 158 sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK)); |
| 159 #endif |
147 } | 160 } |
148 aNew->safety_level = 3; | 161 aNew->safety_level = 3; |
149 aNew->zName = sqlite3DbStrDup(db, zName); | 162 aNew->zName = sqlite3DbStrDup(db, zName); |
150 if( rc==SQLITE_OK && aNew->zName==0 ){ | 163 if( rc==SQLITE_OK && aNew->zName==0 ){ |
151 rc = SQLITE_NOMEM; | 164 rc = SQLITE_NOMEM; |
152 } | 165 } |
153 | 166 |
154 | 167 |
155 #ifdef SQLITE_HAS_CODEC | 168 #ifdef SQLITE_HAS_CODEC |
156 if( rc==SQLITE_OK ){ | 169 if( rc==SQLITE_OK ){ |
(...skipping 30 matching lines...) Expand all Loading... |
187 /* If the file was opened successfully, read the schema for the new database. | 200 /* If the file was opened successfully, read the schema for the new database. |
188 ** If this fails, or if opening the file failed, then close the file and | 201 ** If this fails, or if opening the file failed, then close the file and |
189 ** remove the entry from the db->aDb[] array. i.e. put everything back the way | 202 ** remove the entry from the db->aDb[] array. i.e. put everything back the way |
190 ** we found it. | 203 ** we found it. |
191 */ | 204 */ |
192 if( rc==SQLITE_OK ){ | 205 if( rc==SQLITE_OK ){ |
193 sqlite3BtreeEnterAll(db); | 206 sqlite3BtreeEnterAll(db); |
194 rc = sqlite3Init(db, &zErrDyn); | 207 rc = sqlite3Init(db, &zErrDyn); |
195 sqlite3BtreeLeaveAll(db); | 208 sqlite3BtreeLeaveAll(db); |
196 } | 209 } |
| 210 #ifdef SQLITE_USER_AUTHENTICATION |
| 211 if( rc==SQLITE_OK ){ |
| 212 u8 newAuth = 0; |
| 213 rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth); |
| 214 if( newAuth<db->auth.authLevel ){ |
| 215 rc = SQLITE_AUTH_USER; |
| 216 } |
| 217 } |
| 218 #endif |
197 if( rc ){ | 219 if( rc ){ |
198 int iDb = db->nDb - 1; | 220 int iDb = db->nDb - 1; |
199 assert( iDb>=2 ); | 221 assert( iDb>=2 ); |
200 if( db->aDb[iDb].pBt ){ | 222 if( db->aDb[iDb].pBt ){ |
201 sqlite3BtreeClose(db->aDb[iDb].pBt); | 223 sqlite3BtreeClose(db->aDb[iDb].pBt); |
202 db->aDb[iDb].pBt = 0; | 224 db->aDb[iDb].pBt = 0; |
203 db->aDb[iDb].pSchema = 0; | 225 db->aDb[iDb].pSchema = 0; |
204 } | 226 } |
205 sqlite3ResetInternalSchema(db, -1); | 227 sqlite3ResetAllSchemasOfConnection(db); |
206 db->nDb = iDb; | 228 db->nDb = iDb; |
207 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ | 229 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ |
208 db->mallocFailed = 1; | 230 db->mallocFailed = 1; |
209 sqlite3DbFree(db, zErrDyn); | 231 sqlite3DbFree(db, zErrDyn); |
210 zErrDyn = sqlite3MPrintf(db, "out of memory"); | 232 zErrDyn = sqlite3MPrintf(db, "out of memory"); |
211 }else if( zErrDyn==0 ){ | 233 }else if( zErrDyn==0 ){ |
212 zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile); | 234 zErrDyn = sqlite3MPrintf(db, "unable to open database: %s", zFile); |
213 } | 235 } |
214 goto attach_error; | 236 goto attach_error; |
215 } | 237 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 goto detach_error; | 289 goto detach_error; |
268 } | 290 } |
269 if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){ | 291 if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){ |
270 sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName); | 292 sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName); |
271 goto detach_error; | 293 goto detach_error; |
272 } | 294 } |
273 | 295 |
274 sqlite3BtreeClose(pDb->pBt); | 296 sqlite3BtreeClose(pDb->pBt); |
275 pDb->pBt = 0; | 297 pDb->pBt = 0; |
276 pDb->pSchema = 0; | 298 pDb->pSchema = 0; |
277 sqlite3ResetInternalSchema(db, -1); | 299 sqlite3ResetAllSchemasOfConnection(db); |
278 return; | 300 return; |
279 | 301 |
280 detach_error: | 302 detach_error: |
281 sqlite3_result_error(context, zErr, -1); | 303 sqlite3_result_error(context, zErr, -1); |
282 } | 304 } |
283 | 305 |
284 /* | 306 /* |
285 ** This procedure generates VDBE code for a single invocation of either the | 307 ** This procedure generates VDBE code for a single invocation of either the |
286 ** sqlite_detach() or sqlite_attach() SQL user functions. | 308 ** sqlite_detach() or sqlite_attach() SQL user functions. |
287 */ | 309 */ |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 } | 377 } |
356 | 378 |
357 /* | 379 /* |
358 ** Called by the parser to compile a DETACH statement. | 380 ** Called by the parser to compile a DETACH statement. |
359 ** | 381 ** |
360 ** DETACH pDbname | 382 ** DETACH pDbname |
361 */ | 383 */ |
362 void sqlite3Detach(Parse *pParse, Expr *pDbname){ | 384 void sqlite3Detach(Parse *pParse, Expr *pDbname){ |
363 static const FuncDef detach_func = { | 385 static const FuncDef detach_func = { |
364 1, /* nArg */ | 386 1, /* nArg */ |
365 SQLITE_UTF8, /* iPrefEnc */ | 387 SQLITE_UTF8, /* funcFlags */ |
366 0, /* flags */ | |
367 0, /* pUserData */ | 388 0, /* pUserData */ |
368 0, /* pNext */ | 389 0, /* pNext */ |
369 detachFunc, /* xFunc */ | 390 detachFunc, /* xFunc */ |
370 0, /* xStep */ | 391 0, /* xStep */ |
371 0, /* xFinalize */ | 392 0, /* xFinalize */ |
372 "sqlite_detach", /* zName */ | 393 "sqlite_detach", /* zName */ |
373 0, /* pHash */ | 394 0, /* pHash */ |
374 0 /* pDestructor */ | 395 0 /* pDestructor */ |
375 }; | 396 }; |
376 codeAttach(pParse, SQLITE_DETACH, &detach_func, pDbname, 0, 0, pDbname); | 397 codeAttach(pParse, SQLITE_DETACH, &detach_func, pDbname, 0, 0, pDbname); |
377 } | 398 } |
378 | 399 |
379 /* | 400 /* |
380 ** Called by the parser to compile an ATTACH statement. | 401 ** Called by the parser to compile an ATTACH statement. |
381 ** | 402 ** |
382 ** ATTACH p AS pDbname KEY pKey | 403 ** ATTACH p AS pDbname KEY pKey |
383 */ | 404 */ |
384 void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){ | 405 void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){ |
385 static const FuncDef attach_func = { | 406 static const FuncDef attach_func = { |
386 3, /* nArg */ | 407 3, /* nArg */ |
387 SQLITE_UTF8, /* iPrefEnc */ | 408 SQLITE_UTF8, /* funcFlags */ |
388 0, /* flags */ | |
389 0, /* pUserData */ | 409 0, /* pUserData */ |
390 0, /* pNext */ | 410 0, /* pNext */ |
391 attachFunc, /* xFunc */ | 411 attachFunc, /* xFunc */ |
392 0, /* xStep */ | 412 0, /* xStep */ |
393 0, /* xFinalize */ | 413 0, /* xFinalize */ |
394 "sqlite_attach", /* zName */ | 414 "sqlite_attach", /* zName */ |
395 0, /* pHash */ | 415 0, /* pHash */ |
396 0 /* pDestructor */ | 416 0 /* pDestructor */ |
397 }; | 417 }; |
398 codeAttach(pParse, SQLITE_ATTACH, &attach_func, p, p, pDbname, pKey); | 418 codeAttach(pParse, SQLITE_ATTACH, &attach_func, p, p, pDbname, pKey); |
399 } | 419 } |
400 #endif /* SQLITE_OMIT_ATTACH */ | 420 #endif /* SQLITE_OMIT_ATTACH */ |
401 | 421 |
402 /* | 422 /* |
403 ** Initialize a DbFixer structure. This routine must be called prior | 423 ** Initialize a DbFixer structure. This routine must be called prior |
404 ** to passing the structure to one of the sqliteFixAAAA() routines below. | 424 ** to passing the structure to one of the sqliteFixAAAA() routines below. |
405 ** | |
406 ** The return value indicates whether or not fixation is required. TRUE | |
407 ** means we do need to fix the database references, FALSE means we do not. | |
408 */ | 425 */ |
409 int sqlite3FixInit( | 426 void sqlite3FixInit( |
410 DbFixer *pFix, /* The fixer to be initialized */ | 427 DbFixer *pFix, /* The fixer to be initialized */ |
411 Parse *pParse, /* Error messages will be written here */ | 428 Parse *pParse, /* Error messages will be written here */ |
412 int iDb, /* This is the database that must be used */ | 429 int iDb, /* This is the database that must be used */ |
413 const char *zType, /* "view", "trigger", or "index" */ | 430 const char *zType, /* "view", "trigger", or "index" */ |
414 const Token *pName /* Name of the view, trigger, or index */ | 431 const Token *pName /* Name of the view, trigger, or index */ |
415 ){ | 432 ){ |
416 sqlite3 *db; | 433 sqlite3 *db; |
417 | 434 |
418 if( NEVER(iDb<0) || iDb==1 ) return 0; | |
419 db = pParse->db; | 435 db = pParse->db; |
420 assert( db->nDb>iDb ); | 436 assert( db->nDb>iDb ); |
421 pFix->pParse = pParse; | 437 pFix->pParse = pParse; |
422 pFix->zDb = db->aDb[iDb].zName; | 438 pFix->zDb = db->aDb[iDb].zName; |
| 439 pFix->pSchema = db->aDb[iDb].pSchema; |
423 pFix->zType = zType; | 440 pFix->zType = zType; |
424 pFix->pName = pName; | 441 pFix->pName = pName; |
425 return 1; | 442 pFix->bVarOnly = (iDb==1); |
426 } | 443 } |
427 | 444 |
428 /* | 445 /* |
429 ** The following set of routines walk through the parse tree and assign | 446 ** The following set of routines walk through the parse tree and assign |
430 ** a specific database to all table references where the database name | 447 ** a specific database to all table references where the database name |
431 ** was left unspecified in the original SQL statement. The pFix structure | 448 ** was left unspecified in the original SQL statement. The pFix structure |
432 ** must have been initialized by a prior call to sqlite3FixInit(). | 449 ** must have been initialized by a prior call to sqlite3FixInit(). |
433 ** | 450 ** |
434 ** These routines are used to make sure that an index, trigger, or | 451 ** These routines are used to make sure that an index, trigger, or |
435 ** view in one database does not refer to objects in a different database. | 452 ** view in one database does not refer to objects in a different database. |
436 ** (Exception: indices, triggers, and views in the TEMP database are | 453 ** (Exception: indices, triggers, and views in the TEMP database are |
437 ** allowed to refer to anything.) If a reference is explicitly made | 454 ** allowed to refer to anything.) If a reference is explicitly made |
438 ** to an object in a different database, an error message is added to | 455 ** to an object in a different database, an error message is added to |
439 ** pParse->zErrMsg and these routines return non-zero. If everything | 456 ** pParse->zErrMsg and these routines return non-zero. If everything |
440 ** checks out, these routines return 0. | 457 ** checks out, these routines return 0. |
441 */ | 458 */ |
442 int sqlite3FixSrcList( | 459 int sqlite3FixSrcList( |
443 DbFixer *pFix, /* Context of the fixation */ | 460 DbFixer *pFix, /* Context of the fixation */ |
444 SrcList *pList /* The Source list to check and modify */ | 461 SrcList *pList /* The Source list to check and modify */ |
445 ){ | 462 ){ |
446 int i; | 463 int i; |
447 const char *zDb; | 464 const char *zDb; |
448 struct SrcList_item *pItem; | 465 struct SrcList_item *pItem; |
449 | 466 |
450 if( NEVER(pList==0) ) return 0; | 467 if( NEVER(pList==0) ) return 0; |
451 zDb = pFix->zDb; | 468 zDb = pFix->zDb; |
452 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){ | 469 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){ |
453 if( pItem->zDatabase==0 ){ | 470 if( pFix->bVarOnly==0 ){ |
454 pItem->zDatabase = sqlite3DbStrDup(pFix->pParse->db, zDb); | 471 if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){ |
455 }else if( sqlite3StrICmp(pItem->zDatabase,zDb)!=0 ){ | 472 sqlite3ErrorMsg(pFix->pParse, |
456 sqlite3ErrorMsg(pFix->pParse, | 473 "%s %T cannot reference objects in database %s", |
457 "%s %T cannot reference objects in database %s", | 474 pFix->zType, pFix->pName, pItem->zDatabase); |
458 pFix->zType, pFix->pName, pItem->zDatabase); | 475 return 1; |
459 return 1; | 476 } |
| 477 sqlite3DbFree(pFix->pParse->db, pItem->zDatabase); |
| 478 pItem->zDatabase = 0; |
| 479 pItem->pSchema = pFix->pSchema; |
460 } | 480 } |
461 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) | 481 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) |
462 if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1; | 482 if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1; |
463 if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1; | 483 if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1; |
464 #endif | 484 #endif |
465 } | 485 } |
466 return 0; | 486 return 0; |
467 } | 487 } |
468 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) | 488 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) |
469 int sqlite3FixSelect( | 489 int sqlite3FixSelect( |
470 DbFixer *pFix, /* Context of the fixation */ | 490 DbFixer *pFix, /* Context of the fixation */ |
471 Select *pSelect /* The SELECT statement to be fixed to one database */ | 491 Select *pSelect /* The SELECT statement to be fixed to one database */ |
472 ){ | 492 ){ |
473 while( pSelect ){ | 493 while( pSelect ){ |
474 if( sqlite3FixExprList(pFix, pSelect->pEList) ){ | 494 if( sqlite3FixExprList(pFix, pSelect->pEList) ){ |
475 return 1; | 495 return 1; |
476 } | 496 } |
477 if( sqlite3FixSrcList(pFix, pSelect->pSrc) ){ | 497 if( sqlite3FixSrcList(pFix, pSelect->pSrc) ){ |
478 return 1; | 498 return 1; |
479 } | 499 } |
480 if( sqlite3FixExpr(pFix, pSelect->pWhere) ){ | 500 if( sqlite3FixExpr(pFix, pSelect->pWhere) ){ |
481 return 1; | 501 return 1; |
482 } | 502 } |
| 503 if( sqlite3FixExprList(pFix, pSelect->pGroupBy) ){ |
| 504 return 1; |
| 505 } |
483 if( sqlite3FixExpr(pFix, pSelect->pHaving) ){ | 506 if( sqlite3FixExpr(pFix, pSelect->pHaving) ){ |
484 return 1; | 507 return 1; |
485 } | 508 } |
| 509 if( sqlite3FixExprList(pFix, pSelect->pOrderBy) ){ |
| 510 return 1; |
| 511 } |
| 512 if( sqlite3FixExpr(pFix, pSelect->pLimit) ){ |
| 513 return 1; |
| 514 } |
| 515 if( sqlite3FixExpr(pFix, pSelect->pOffset) ){ |
| 516 return 1; |
| 517 } |
486 pSelect = pSelect->pPrior; | 518 pSelect = pSelect->pPrior; |
487 } | 519 } |
488 return 0; | 520 return 0; |
489 } | 521 } |
490 int sqlite3FixExpr( | 522 int sqlite3FixExpr( |
491 DbFixer *pFix, /* Context of the fixation */ | 523 DbFixer *pFix, /* Context of the fixation */ |
492 Expr *pExpr /* The expression to be fixed to one database */ | 524 Expr *pExpr /* The expression to be fixed to one database */ |
493 ){ | 525 ){ |
494 while( pExpr ){ | 526 while( pExpr ){ |
495 if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ) break; | 527 if( pExpr->op==TK_VARIABLE ){ |
| 528 if( pFix->pParse->db->init.busy ){ |
| 529 pExpr->op = TK_NULL; |
| 530 }else{ |
| 531 sqlite3ErrorMsg(pFix->pParse, "%s cannot use variables", pFix->zType); |
| 532 return 1; |
| 533 } |
| 534 } |
| 535 if( ExprHasProperty(pExpr, EP_TokenOnly) ) break; |
496 if( ExprHasProperty(pExpr, EP_xIsSelect) ){ | 536 if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
497 if( sqlite3FixSelect(pFix, pExpr->x.pSelect) ) return 1; | 537 if( sqlite3FixSelect(pFix, pExpr->x.pSelect) ) return 1; |
498 }else{ | 538 }else{ |
499 if( sqlite3FixExprList(pFix, pExpr->x.pList) ) return 1; | 539 if( sqlite3FixExprList(pFix, pExpr->x.pList) ) return 1; |
500 } | 540 } |
501 if( sqlite3FixExpr(pFix, pExpr->pRight) ){ | 541 if( sqlite3FixExpr(pFix, pExpr->pRight) ){ |
502 return 1; | 542 return 1; |
503 } | 543 } |
504 pExpr = pExpr->pLeft; | 544 pExpr = pExpr->pLeft; |
505 } | 545 } |
(...skipping 28 matching lines...) Expand all Loading... |
534 return 1; | 574 return 1; |
535 } | 575 } |
536 if( sqlite3FixExprList(pFix, pStep->pExprList) ){ | 576 if( sqlite3FixExprList(pFix, pStep->pExprList) ){ |
537 return 1; | 577 return 1; |
538 } | 578 } |
539 pStep = pStep->pNext; | 579 pStep = pStep->pNext; |
540 } | 580 } |
541 return 0; | 581 return 0; |
542 } | 582 } |
543 #endif | 583 #endif |
OLD | NEW |