Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: third_party/sqlite/sqlite-src-3100200/src/attach.c

Issue 1610543003: [sql] Import reference version of SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 }else if( rc==SQLITE_OK ){ 143 }else if( rc==SQLITE_OK ){
144 Pager *pPager; 144 Pager *pPager;
145 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt); 145 aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt);
146 if( !aNew->pSchema ){ 146 if( !aNew->pSchema ){
147 rc = SQLITE_NOMEM; 147 rc = SQLITE_NOMEM;
148 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){ 148 }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
149 zErrDyn = sqlite3MPrintf(db, 149 zErrDyn = sqlite3MPrintf(db,
150 "attached databases must use the same text encoding as main database"); 150 "attached databases must use the same text encoding as main database");
151 rc = SQLITE_ERROR; 151 rc = SQLITE_ERROR;
152 } 152 }
153 sqlite3BtreeEnter(aNew->pBt);
153 pPager = sqlite3BtreePager(aNew->pBt); 154 pPager = sqlite3BtreePager(aNew->pBt);
154 sqlite3PagerLockingMode(pPager, db->dfltLockMode); 155 sqlite3PagerLockingMode(pPager, db->dfltLockMode);
155 sqlite3BtreeSecureDelete(aNew->pBt, 156 sqlite3BtreeSecureDelete(aNew->pBt,
156 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) ); 157 sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
157 #ifndef SQLITE_OMIT_PAGER_PRAGMAS 158 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
158 sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK)); 159 sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK));
159 #endif 160 #endif
161 sqlite3BtreeLeave(aNew->pBt);
160 } 162 }
161 aNew->safety_level = 3; 163 aNew->safety_level = 3;
162 aNew->zName = sqlite3DbStrDup(db, zName); 164 aNew->zName = sqlite3DbStrDup(db, zName);
163 if( rc==SQLITE_OK && aNew->zName==0 ){ 165 if( rc==SQLITE_OK && aNew->zName==0 ){
164 rc = SQLITE_NOMEM; 166 rc = SQLITE_NOMEM;
165 } 167 }
166 168
167 169
168 #ifdef SQLITE_HAS_CODEC 170 #ifdef SQLITE_HAS_CODEC
169 if( rc==SQLITE_OK ){ 171 if( rc==SQLITE_OK ){
(...skipping 12 matching lines...) Expand all
182 case SQLITE_TEXT: 184 case SQLITE_TEXT:
183 case SQLITE_BLOB: 185 case SQLITE_BLOB:
184 nKey = sqlite3_value_bytes(argv[2]); 186 nKey = sqlite3_value_bytes(argv[2]);
185 zKey = (char *)sqlite3_value_blob(argv[2]); 187 zKey = (char *)sqlite3_value_blob(argv[2]);
186 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey); 188 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
187 break; 189 break;
188 190
189 case SQLITE_NULL: 191 case SQLITE_NULL:
190 /* No key specified. Use the key from the main database */ 192 /* No key specified. Use the key from the main database */
191 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey); 193 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
192 if( nKey>0 || sqlite3BtreeGetReserve(db->aDb[0].pBt)>0 ){ 194 if( nKey>0 || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){
193 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey); 195 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
194 } 196 }
195 break; 197 break;
196 } 198 }
197 } 199 }
198 #endif 200 #endif
199 201
200 /* If the file was opened successfully, read the schema for the new database. 202 /* If the file was opened successfully, read the schema for the new database.
201 ** If this fails, or if opening the file failed, then close the file and 203 ** If this fails, or if opening the file failed, then close the file and
202 ** remove the entry from the db->aDb[] array. i.e. put everything back the way 204 ** remove the entry from the db->aDb[] array. i.e. put everything back the way
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 goto detach_error; 291 goto detach_error;
290 } 292 }
291 if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){ 293 if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){
292 sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName); 294 sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);
293 goto detach_error; 295 goto detach_error;
294 } 296 }
295 297
296 sqlite3BtreeClose(pDb->pBt); 298 sqlite3BtreeClose(pDb->pBt);
297 pDb->pBt = 0; 299 pDb->pBt = 0;
298 pDb->pSchema = 0; 300 pDb->pSchema = 0;
299 sqlite3ResetAllSchemasOfConnection(db); 301 sqlite3CollapseDatabaseArray(db);
300 return; 302 return;
301 303
302 detach_error: 304 detach_error:
303 sqlite3_result_error(context, zErr, -1); 305 sqlite3_result_error(context, zErr, -1);
304 } 306 }
305 307
306 /* 308 /*
307 ** This procedure generates VDBE code for a single invocation of either the 309 ** This procedure generates VDBE code for a single invocation of either the
308 ** sqlite_detach() or sqlite_attach() SQL user functions. 310 ** sqlite_detach() or sqlite_attach() SQL user functions.
309 */ 311 */
(...skipping 13 matching lines...) Expand all
323 int regArgs; 325 int regArgs;
324 326
325 memset(&sName, 0, sizeof(NameContext)); 327 memset(&sName, 0, sizeof(NameContext));
326 sName.pParse = pParse; 328 sName.pParse = pParse;
327 329
328 if( 330 if(
329 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) || 331 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
330 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) || 332 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
331 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey)) 333 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
332 ){ 334 ){
333 pParse->nErr++;
334 goto attach_end; 335 goto attach_end;
335 } 336 }
336 337
337 #ifndef SQLITE_OMIT_AUTHORIZATION 338 #ifndef SQLITE_OMIT_AUTHORIZATION
338 if( pAuthArg ){ 339 if( pAuthArg ){
339 char *zAuthArg; 340 char *zAuthArg;
340 if( pAuthArg->op==TK_STRING ){ 341 if( pAuthArg->op==TK_STRING ){
341 zAuthArg = pAuthArg->u.zToken; 342 zAuthArg = pAuthArg->u.zToken;
342 }else{ 343 }else{
343 zAuthArg = 0; 344 zAuthArg = 0;
344 } 345 }
345 rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0); 346 rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
346 if(rc!=SQLITE_OK ){ 347 if(rc!=SQLITE_OK ){
347 goto attach_end; 348 goto attach_end;
348 } 349 }
349 } 350 }
350 #endif /* SQLITE_OMIT_AUTHORIZATION */ 351 #endif /* SQLITE_OMIT_AUTHORIZATION */
351 352
352 353
353 v = sqlite3GetVdbe(pParse); 354 v = sqlite3GetVdbe(pParse);
354 regArgs = sqlite3GetTempRange(pParse, 4); 355 regArgs = sqlite3GetTempRange(pParse, 4);
355 sqlite3ExprCode(pParse, pFilename, regArgs); 356 sqlite3ExprCode(pParse, pFilename, regArgs);
356 sqlite3ExprCode(pParse, pDbname, regArgs+1); 357 sqlite3ExprCode(pParse, pDbname, regArgs+1);
357 sqlite3ExprCode(pParse, pKey, regArgs+2); 358 sqlite3ExprCode(pParse, pKey, regArgs+2);
358 359
359 assert( v || db->mallocFailed ); 360 assert( v || db->mallocFailed );
360 if( v ){ 361 if( v ){
361 sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3); 362 sqlite3VdbeAddOp3(v, OP_Function0, 0, regArgs+3-pFunc->nArg, regArgs+3);
362 assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg ); 363 assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg );
363 sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg)); 364 sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg));
364 sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF); 365 sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);
365 366
366 /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this 367 /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
367 ** statement only). For DETACH, set it to false (expire all existing 368 ** statement only). For DETACH, set it to false (expire all existing
368 ** statements). 369 ** statements).
369 */ 370 */
370 sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH)); 371 sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH));
371 } 372 }
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 return 1; 575 return 1;
575 } 576 }
576 if( sqlite3FixExprList(pFix, pStep->pExprList) ){ 577 if( sqlite3FixExprList(pFix, pStep->pExprList) ){
577 return 1; 578 return 1;
578 } 579 }
579 pStep = pStep->pNext; 580 pStep = pStep->pNext;
580 } 581 }
581 return 0; 582 return 0;
582 } 583 }
583 #endif 584 #endif
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3100200/src/analyze.c ('k') | third_party/sqlite/sqlite-src-3100200/src/auth.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698