Overview
| SHA1 Hash: | 325364a984e9a5c0825810bf50f57e026ff3b8dd |
|---|---|
| Date: | 2012-10-26 13:34:05 |
| User: | drh |
| Comment: | Backport the shared-cache-fix branch. |
Tags And Properties
- branch=branch-3.7.14 inherited from [9fab9edd0d]
- sym-branch-3.7.14 inherited from [9fab9edd0d]
Changes
Changes to src/alter.c
410 int savedDbFlags; /* Saved value of db->flags */ 410 int savedDbFlags; /* Saved value of db->flags */ 411 411 412 savedDbFlags = db->flags; 412 savedDbFlags = db->flags; 413 if( NEVER(db->mallocFailed) ) goto exit_rename_table; 413 if( NEVER(db->mallocFailed) ) goto exit_rename_table; 414 assert( pSrc->nSrc==1 ); 414 assert( pSrc->nSrc==1 ); 415 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) ); 415 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) ); 416 416 417 pTab = sqlite3LocateTable(pParse, 0, pSrc->a[0].zName, pSrc->a[0].zDatabase); | 417 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]); 418 if( !pTab ) goto exit_rename_table; 418 if( !pTab ) goto exit_rename_table; 419 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); 419 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); 420 zDb = db->aDb[iDb].zName; 420 zDb = db->aDb[iDb].zName; 421 db->flags |= SQLITE_PreferBuiltin; 421 db->flags |= SQLITE_PreferBuiltin; 422 422 423 /* Get a NULL terminated version of the new table name. */ 423 /* Get a NULL terminated version of the new table name. */ 424 zName = sqlite3NameFromToken(db, pName); 424 zName = sqlite3NameFromToken(db, pName); ................................................................................................................................................................................ 753 int nAlloc; 753 int nAlloc; 754 sqlite3 *db = pParse->db; 754 sqlite3 *db = pParse->db; 755 755 756 /* Look up the table being altered. */ 756 /* Look up the table being altered. */ 757 assert( pParse->pNewTable==0 ); 757 assert( pParse->pNewTable==0 ); 758 assert( sqlite3BtreeHoldsAllMutexes(db) ); 758 assert( sqlite3BtreeHoldsAllMutexes(db) ); 759 if( db->mallocFailed ) goto exit_begin_add_column; 759 if( db->mallocFailed ) goto exit_begin_add_column; 760 pTab = sqlite3LocateTable(pParse, 0, pSrc->a[0].zName, pSrc->a[0].zDatabase); | 760 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]); 761 if( !pTab ) goto exit_begin_add_column; 761 if( !pTab ) goto exit_begin_add_column; 762 762 763 #ifndef SQLITE_OMIT_VIRTUALTABLE 763 #ifndef SQLITE_OMIT_VIRTUALTABLE 764 if( IsVirtual(pTab) ){ 764 if( IsVirtual(pTab) ){ 765 sqlite3ErrorMsg(pParse, "virtual tables may not be altered"); 765 sqlite3ErrorMsg(pParse, "virtual tables may not be altered"); 766 goto exit_begin_add_column; 766 goto exit_begin_add_column; 767 } 767 }
Changes to src/attach.c
430 sqlite3 *db; 430 sqlite3 *db; 431 431 432 if( NEVER(iDb<0) || iDb==1 ) return 0; 432 if( NEVER(iDb<0) || iDb==1 ) return 0; 433 db = pParse->db; 433 db = pParse->db; 434 assert( db->nDb>iDb ); 434 assert( db->nDb>iDb ); 435 pFix->pParse = pParse; 435 pFix->pParse = pParse; 436 pFix->zDb = db->aDb[iDb].zName; 436 pFix->zDb = db->aDb[iDb].zName; > 437 pFix->pSchema = db->aDb[iDb].pSchema; 437 pFix->zType = zType; 438 pFix->zType = zType; 438 pFix->pName = pName; 439 pFix->pName = pName; 439 return 1; 440 return 1; 440 } 441 } 441 442 442 /* 443 /* 443 ** The following set of routines walk through the parse tree and assign 444 ** The following set of routines walk through the parse tree and assign ................................................................................................................................................................................ 460 int i; 461 int i; 461 const char *zDb; 462 const char *zDb; 462 struct SrcList_item *pItem; 463 struct SrcList_item *pItem; 463 464 464 if( NEVER(pList==0) ) return 0; 465 if( NEVER(pList==0) ) return 0; 465 zDb = pFix->zDb; 466 zDb = pFix->zDb; 466 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){ 467 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){ 467 if( pItem->zDatabase==0 ){ < 468 pItem->zDatabase = sqlite3DbStrDup(pFix->pParse->db, zDb); < 469 }else if( sqlite3StrICmp(pItem->zDatabase,zDb)!=0 ){ | 468 if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){ 470 sqlite3ErrorMsg(pFix->pParse, 469 sqlite3ErrorMsg(pFix->pParse, 471 "%s %T cannot reference objects in database %s", 470 "%s %T cannot reference objects in database %s", 472 pFix->zType, pFix->pName, pItem->zDatabase); 471 pFix->zType, pFix->pName, pItem->zDatabase); 473 return 1; 472 return 1; 474 } 473 } > 474 sqlite3_free(pItem->zDatabase); > 475 pItem->zDatabase = 0; > 476 pItem->pSchema = pFix->pSchema; 475 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) 477 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) 476 if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1; 478 if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1; 477 if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1; 479 if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1; 478 #endif 480 #endif 479 } 481 } 480 return 0; 482 return 0; 481 } 483 }
Changes to src/build.c
314 }else{ 314 }else{ 315 sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName); 315 sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName); 316 } 316 } 317 pParse->checkSchema = 1; 317 pParse->checkSchema = 1; 318 } 318 } 319 return p; 319 return p; 320 } 320 } > 321 > 322 /* > 323 ** Locate the table identified by *p. > 324 ** > 325 ** This is a wrapper around sqlite3LocateTable(). The difference between > 326 ** sqlite3LocateTable() and this function is that this function restricts > 327 ** the search to schema (p->pSchema) if it is not NULL. p->pSchema may be > 328 ** non-NULL if it is part of a view or trigger program definition. See > 329 ** sqlite3FixSrcList() for details. > 330 */ > 331 Table *sqlite3LocateTableItem( > 332 Parse *pParse, > 333 int isView, > 334 struct SrcList_item *p > 335 ){ > 336 const char *zDb; > 337 assert( p->pSchema==0 || p->zDatabase==0 ); > 338 if( p->pSchema ){ > 339 int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema); > 340 zDb = pParse->db->aDb[iDb].zName; > 341 }else{ > 342 zDb = p->zDatabase; > 343 } > 344 return sqlite3LocateTable(pParse, isView, p->zName, zDb); > 345 } 321 346 322 /* 347 /* 323 ** Locate the in-memory structure that describes 348 ** Locate the in-memory structure that describes 324 ** a particular index given the name of that index 349 ** a particular index given the name of that index 325 ** and the name of the database that contains the index. 350 ** and the name of the database that contains the index. 326 ** Return NULL if not found. 351 ** Return NULL if not found. 327 ** 352 ** ................................................................................................................................................................................ 2110 2135 2111 if( db->mallocFailed ){ 2136 if( db->mallocFailed ){ 2112 goto exit_drop_table; 2137 goto exit_drop_table; 2113 } 2138 } 2114 assert( pParse->nErr==0 ); 2139 assert( pParse->nErr==0 ); 2115 assert( pName->nSrc==1 ); 2140 assert( pName->nSrc==1 ); 2116 if( noErr ) db->suppressErr++; 2141 if( noErr ) db->suppressErr++; 2117 pTab = sqlite3LocateTable(pParse, isView, | 2142 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]); 2118 pName->a[0].zName, pName->a[0].zDatabase); < 2119 if( noErr ) db->suppressErr--; 2143 if( noErr ) db->suppressErr--; 2120 2144 2121 if( pTab==0 ){ 2145 if( pTab==0 ){ 2122 if( noErr ) sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase); 2146 if( noErr ) sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase); 2123 goto exit_drop_table; 2147 goto exit_drop_table; 2124 } 2148 } 2125 iDb = sqlite3SchemaToIndex(db, pTab->pSchema); 2149 iDb = sqlite3SchemaToIndex(db, pTab->pSchema); ................................................................................................................................................................................ 2551 if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && 2575 if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && 2552 sqlite3FixSrcList(&sFix, pTblName) 2576 sqlite3FixSrcList(&sFix, pTblName) 2553 ){ 2577 ){ 2554 /* Because the parser constructs pTblName from a single identifier, 2578 /* Because the parser constructs pTblName from a single identifier, 2555 ** sqlite3FixSrcList can never fail. */ 2579 ** sqlite3FixSrcList can never fail. */ 2556 assert(0); 2580 assert(0); 2557 } 2581 } 2558 pTab = sqlite3LocateTable(pParse, 0, pTblName->a[0].zName, | 2582 pTab = sqlite3LocateTableItem(pParse, 0, &pTblName->a[0]); 2559 pTblName->a[0].zDatabase); < 2560 if( !pTab || db->mallocFailed ) goto exit_create_index; 2583 if( !pTab || db->mallocFailed ) goto exit_create_index; 2561 assert( db->aDb[iDb].pSchema==pTab->pSchema ); 2584 assert( db->aDb[iDb].pSchema==pTab->pSchema ); 2562 }else{ 2585 }else{ 2563 assert( pName==0 ); 2586 assert( pName==0 ); 2564 assert( pStart==0 ); 2587 assert( pStart==0 ); 2565 pTab = pParse->pNewTable; 2588 pTab = pParse->pNewTable; 2566 if( !pTab ) goto exit_create_index; 2589 if( !pTab ) goto exit_create_index;
Changes to src/delete.c
28 ** pSrc->a[0].pIndex Pointer to the INDEXED BY index, if there is one 28 ** pSrc->a[0].pIndex Pointer to the INDEXED BY index, if there is one 29 ** 29 ** 30 */ 30 */ 31 Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){ 31 Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){ 32 struct SrcList_item *pItem = pSrc->a; 32 struct SrcList_item *pItem = pSrc->a; 33 Table *pTab; 33 Table *pTab; 34 assert( pItem && pSrc->nSrc==1 ); 34 assert( pItem && pSrc->nSrc==1 ); 35 pTab = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase); | 35 pTab = sqlite3LocateTableItem(pParse, 0, pItem); 36 sqlite3DeleteTable(pParse->db, pItem->pTab); 36 sqlite3DeleteTable(pParse->db, pItem->pTab); 37 pItem->pTab = pTab; 37 pItem->pTab = pTab; 38 if( pTab ){ 38 if( pTab ){ 39 pTab->nRef++; 39 pTab->nRef++; 40 } 40 } 41 if( sqlite3IndexedByLookup(pParse, pItem) ){ 41 if( sqlite3IndexedByLookup(pParse, pItem) ){ 42 pTab = 0; 42 pTab = 0;
Changes to src/expr.c
926 pNew = sqlite3DbMallocRaw(db, nByte ); 926 pNew = sqlite3DbMallocRaw(db, nByte ); 927 if( pNew==0 ) return 0; 927 if( pNew==0 ) return 0; 928 pNew->nSrc = pNew->nAlloc = p->nSrc; 928 pNew->nSrc = pNew->nAlloc = p->nSrc; 929 for(i=0; i<p->nSrc; i++){ 929 for(i=0; i<p->nSrc; i++){ 930 struct SrcList_item *pNewItem = &pNew->a[i]; 930 struct SrcList_item *pNewItem = &pNew->a[i]; 931 struct SrcList_item *pOldItem = &p->a[i]; 931 struct SrcList_item *pOldItem = &p->a[i]; 932 Table *pTab; 932 Table *pTab; > 933 pNewItem->pSchema = pOldItem->pSchema; 933 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase); 934 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase); 934 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); 935 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); 935 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias); 936 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias); 936 pNewItem->jointype = pOldItem->jointype; 937 pNewItem->jointype = pOldItem->jointype; 937 pNewItem->iCursor = pOldItem->iCursor; 938 pNewItem->iCursor = pOldItem->iCursor; 938 pNewItem->addrFillSub = pOldItem->addrFillSub; 939 pNewItem->addrFillSub = pOldItem->addrFillSub; 939 pNewItem->regReturn = pOldItem->regReturn; 940 pNewItem->regReturn = pOldItem->regReturn;
Changes to src/insert.c
1218 #ifndef SQLITE_OMIT_CHECK 1218 #ifndef SQLITE_OMIT_CHECK 1219 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){ 1219 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){ 1220 ExprList *pCheck = pTab->pCheck; 1220 ExprList *pCheck = pTab->pCheck; 1221 pParse->ckBase = regData; 1221 pParse->ckBase = regData; 1222 onError = overrideError!=OE_Default ? overrideError : OE_Abort; 1222 onError = overrideError!=OE_Default ? overrideError : OE_Abort; 1223 for(i=0; i<pCheck->nExpr; i++){ 1223 for(i=0; i<pCheck->nExpr; i++){ 1224 int allOk = sqlite3VdbeMakeLabel(v); 1224 int allOk = sqlite3VdbeMakeLabel(v); > 1225 Expr *pDup = sqlite3ExprDup(db, pCheck->a[i].pExpr, 0); > 1226 if( pDup==0 ) break; 1225 sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL); | 1227 sqlite3ExprIfTrue(pParse, pDup, allOk, SQLITE_JUMPIFNULL); 1226 if( onError==OE_Ignore ){ 1228 if( onError==OE_Ignore ){ 1227 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); 1229 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); 1228 }else{ 1230 }else{ 1229 char *zConsName = pCheck->a[i].zName; 1231 char *zConsName = pCheck->a[i].zName; 1230 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ 1232 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ 1231 if( zConsName ){ 1233 if( zConsName ){ 1232 zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); 1234 zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); 1233 }else{ 1235 }else{ 1234 zConsName = 0; 1236 zConsName = 0; 1235 } 1237 } 1236 sqlite3HaltConstraint(pParse, onError, zConsName, P4_DYNAMIC); 1238 sqlite3HaltConstraint(pParse, onError, zConsName, P4_DYNAMIC); 1237 } 1239 } 1238 sqlite3VdbeResolveLabel(v, allOk); 1240 sqlite3VdbeResolveLabel(v, allOk); > 1241 sqlite3ExprDelete(db, pDup); 1239 } 1242 } 1240 } 1243 } 1241 #endif /* !defined(SQLITE_OMIT_CHECK) */ 1244 #endif /* !defined(SQLITE_OMIT_CHECK) */ 1242 1245 1243 /* If we have an INTEGER PRIMARY KEY, make sure the primary key 1246 /* If we have an INTEGER PRIMARY KEY, make sure the primary key 1244 ** of the new record does not previously exist. Except, if this 1247 ** of the new record does not previously exist. Except, if this 1245 ** is an UPDATE and the primary key is not changing, that is OK. 1248 ** is an UPDATE and the primary key is not changing, that is OK. ................................................................................................................................................................................ 1687 } 1690 } 1688 1691 1689 /* At this point we have established that the statement is of the 1692 /* At this point we have established that the statement is of the 1690 ** correct syntactic form to participate in this optimization. Now 1693 ** correct syntactic form to participate in this optimization. Now 1691 ** we have to check the semantics. 1694 ** we have to check the semantics. 1692 */ 1695 */ 1693 pItem = pSelect->pSrc->a; 1696 pItem = pSelect->pSrc->a; 1694 pSrc = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase); | 1697 pSrc = sqlite3LocateTableItem(pParse, 0, pItem); 1695 if( pSrc==0 ){ 1698 if( pSrc==0 ){ 1696 return 0; /* FROM clause does not contain a real table */ 1699 return 0; /* FROM clause does not contain a real table */ 1697 } 1700 } 1698 if( pSrc==pDest ){ 1701 if( pSrc==pDest ){ 1699 return 0; /* tab1 and tab2 may not be the same table */ 1702 return 0; /* tab1 and tab2 may not be the same table */ 1700 } 1703 } 1701 #ifndef SQLITE_OMIT_VIRTUALTABLE 1704 #ifndef SQLITE_OMIT_VIRTUALTABLE
Changes to src/select.c
3264 pTab->iPKey = -1; 3264 pTab->iPKey = -1; 3265 pTab->nRowEst = 1000000; 3265 pTab->nRowEst = 1000000; 3266 pTab->tabFlags |= TF_Ephemeral; 3266 pTab->tabFlags |= TF_Ephemeral; 3267 #endif 3267 #endif 3268 }else{ 3268 }else{ 3269 /* An ordinary table or view name in the FROM clause */ 3269 /* An ordinary table or view name in the FROM clause */ 3270 assert( pFrom->pTab==0 ); 3270 assert( pFrom->pTab==0 ); 3271 pFrom->pTab = pTab = | 3271 pFrom->pTab = pTab = sqlite3LocateTableItem(pParse, 0, pFrom); 3272 sqlite3LocateTable(pParse,0,pFrom->zName,pFrom->zDatabase); < 3273 if( pTab==0 ) return WRC_Abort; 3272 if( pTab==0 ) return WRC_Abort; 3274 pTab->nRef++; 3273 pTab->nRef++; 3275 #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) 3274 #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) 3276 if( pTab->pSelect || IsVirtual(pTab) ){ 3275 if( pTab->pSelect || IsVirtual(pTab) ){ 3277 /* We reach here if the named table is a really a view */ 3276 /* We reach here if the named table is a really a view */ 3278 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; 3277 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; 3279 assert( pFrom->pSelect==0 ); 3278 assert( pFrom->pSelect==0 );
Changes to src/sqliteInt.h
1851 ** In the colUsed field, the high-order bit (bit 63) is set if the table 1851 ** In the colUsed field, the high-order bit (bit 63) is set if the table 1852 ** contains more than 63 columns and the 64-th or later column is used. 1852 ** contains more than 63 columns and the 64-th or later column is used. 1853 */ 1853 */ 1854 struct SrcList { 1854 struct SrcList { 1855 i16 nSrc; /* Number of tables or subqueries in the FROM clause */ 1855 i16 nSrc; /* Number of tables or subqueries in the FROM clause */ 1856 i16 nAlloc; /* Number of entries allocated in a[] below */ 1856 i16 nAlloc; /* Number of entries allocated in a[] below */ 1857 struct SrcList_item { 1857 struct SrcList_item { > 1858 Schema *pSchema; /* Schema to which this item is fixed */ 1858 char *zDatabase; /* Name of database holding this table */ 1859 char *zDatabase; /* Name of database holding this table */ 1859 char *zName; /* Name of the table */ 1860 char *zName; /* Name of the table */ 1860 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ 1861 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ 1861 Table *pTab; /* An SQL table corresponding to zName */ 1862 Table *pTab; /* An SQL table corresponding to zName */ 1862 Select *pSelect; /* A SELECT statement used in place of a table name */ 1863 Select *pSelect; /* A SELECT statement used in place of a table name */ 1863 int addrFillSub; /* Address of subroutine to manifest a subquery */ 1864 int addrFillSub; /* Address of subroutine to manifest a subquery */ 1864 int regReturn; /* Register holding return address of addrFillSub */ 1865 int regReturn; /* Register holding return address of addrFillSub */ ................................................................................................................................................................................ 2416 ** The following structure contains information used by the sqliteFix... 2417 ** The following structure contains information used by the sqliteFix... 2417 ** routines as they walk the parse tree to make database references 2418 ** routines as they walk the parse tree to make database references 2418 ** explicit. 2419 ** explicit. 2419 */ 2420 */ 2420 typedef struct DbFixer DbFixer; 2421 typedef struct DbFixer DbFixer; 2421 struct DbFixer { 2422 struct DbFixer { 2422 Parse *pParse; /* The parsing context. Error messages written here */ 2423 Parse *pParse; /* The parsing context. Error messages written here */ > 2424 Schema *pSchema; /* Fix items to this schema */ 2423 const char *zDb; /* Make sure all objects are contained in this database */ 2425 const char *zDb; /* Make sure all objects are contained in this database */ 2424 const char *zType; /* Type of the container - used for error messages */ 2426 const char *zType; /* Type of the container - used for error messages */ 2425 const Token *pName; /* Name of the container - used for error messages */ 2427 const Token *pName; /* Name of the container - used for error messages */ 2426 }; 2428 }; 2427 2429 2428 /* 2430 /* 2429 ** An objected used to accumulate the text of a string where we 2431 ** An objected used to accumulate the text of a string where we ................................................................................................................................................................................ 2826 int sqlite3ExprCodeAndCache(Parse*, Expr*, int); 2828 int sqlite3ExprCodeAndCache(Parse*, Expr*, int); 2827 void sqlite3ExprCodeConstants(Parse*, Expr*); 2829 void sqlite3ExprCodeConstants(Parse*, Expr*); 2828 int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int); 2830 int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int); 2829 void sqlite3ExprIfTrue(Parse*, Expr*, int, int); 2831 void sqlite3ExprIfTrue(Parse*, Expr*, int, int); 2830 void sqlite3ExprIfFalse(Parse*, Expr*, int, int); 2832 void sqlite3ExprIfFalse(Parse*, Expr*, int, int); 2831 Table *sqlite3FindTable(sqlite3*,const char*, const char*); 2833 Table *sqlite3FindTable(sqlite3*,const char*, const char*); 2832 Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*); 2834 Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*); > 2835 Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *); 2833 Index *sqlite3FindIndex(sqlite3*,const char*, const char*); 2836 Index *sqlite3FindIndex(sqlite3*,const char*, const char*); 2834 void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); 2837 void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); 2835 void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); 2838 void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); 2836 void sqlite3Vacuum(Parse*); 2839 void sqlite3Vacuum(Parse*); 2837 int sqlite3RunVacuum(char**, sqlite3*); 2840 int sqlite3RunVacuum(char**, sqlite3*); 2838 char *sqlite3NameFromToken(sqlite3*, Token*); 2841 char *sqlite3NameFromToken(sqlite3*, Token*); 2839 int sqlite3ExprCompare(Expr*, Expr*); 2842 int sqlite3ExprCompare(Expr*, Expr*);
Changes to src/vtab.c
259 ** in the list are moved to the sqlite3.pDisconnect list of the associated 259 ** in the list are moved to the sqlite3.pDisconnect list of the associated 260 ** database connection. 260 ** database connection. 261 */ 261 */ 262 void sqlite3VtabClear(sqlite3 *db, Table *p){ 262 void sqlite3VtabClear(sqlite3 *db, Table *p){ 263 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p); 263 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p); 264 if( p->azModuleArg ){ 264 if( p->azModuleArg ){ 265 int i; 265 int i; > 266 assert( p->nModuleArg<2 || p->azModuleArg[1]==0 ); 266 for(i=0; i<p->nModuleArg; i++){ 267 for(i=0; i<p->nModuleArg; i++){ 267 sqlite3DbFree(db, p->azModuleArg[i]); 268 sqlite3DbFree(db, p->azModuleArg[i]); 268 } 269 } 269 sqlite3DbFree(db, p->azModuleArg); 270 sqlite3DbFree(db, p->azModuleArg); 270 } 271 } 271 } 272 } 272 273 ................................................................................................................................................................................ 320 db = pParse->db; 321 db = pParse->db; 321 iDb = sqlite3SchemaToIndex(db, pTable->pSchema); 322 iDb = sqlite3SchemaToIndex(db, pTable->pSchema); 322 assert( iDb>=0 ); 323 assert( iDb>=0 ); 323 324 324 pTable->tabFlags |= TF_Virtual; 325 pTable->tabFlags |= TF_Virtual; 325 pTable->nModuleArg = 0; 326 pTable->nModuleArg = 0; 326 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName)); 327 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName)); 327 addModuleArgument(db, pTable, sqlite3DbStrDup(db, db->aDb[iDb].zName)); | 328 addModuleArgument(db, pTable, 0); 328 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName)); 329 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName)); 329 pParse->sNameToken.n = (int)(&pModuleName->z[pModuleName->n] - pName1->z); 330 pParse->sNameToken.n = (int)(&pModuleName->z[pModuleName->n] - pName1->z); 330 331 331 #ifndef SQLITE_OMIT_AUTHORIZATION 332 #ifndef SQLITE_OMIT_AUTHORIZATION 332 /* Creating a virtual table invokes the authorization callback twice. 333 /* Creating a virtual table invokes the authorization callback twice. 333 ** The first invocation, to obtain permission to INSERT a row into the 334 ** The first invocation, to obtain permission to INSERT a row into the 334 ** sqlite_master table, has already been made by sqlite3StartTable(). 335 ** sqlite_master table, has already been made by sqlite3StartTable(). ................................................................................................................................................................................ 477 VtabCtx sCtx, *pPriorCtx; 478 VtabCtx sCtx, *pPriorCtx; 478 VTable *pVTable; 479 VTable *pVTable; 479 int rc; 480 int rc; 480 const char *const*azArg = (const char *const*)pTab->azModuleArg; 481 const char *const*azArg = (const char *const*)pTab->azModuleArg; 481 int nArg = pTab->nModuleArg; 482 int nArg = pTab->nModuleArg; 482 char *zErr = 0; 483 char *zErr = 0; 483 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); 484 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); > 485 int iDb; 484 486 485 if( !zModuleName ){ 487 if( !zModuleName ){ 486 return SQLITE_NOMEM; 488 return SQLITE_NOMEM; 487 } 489 } 488 490 489 pVTable = sqlite3DbMallocZero(db, sizeof(VTable)); 491 pVTable = sqlite3DbMallocZero(db, sizeof(VTable)); 490 if( !pVTable ){ 492 if( !pVTable ){ 491 sqlite3DbFree(db, zModuleName); 493 sqlite3DbFree(db, zModuleName); 492 return SQLITE_NOMEM; 494 return SQLITE_NOMEM; 493 } 495 } 494 pVTable->db = db; 496 pVTable->db = db; 495 pVTable->pMod = pMod; 497 pVTable->pMod = pMod; 496 498 > 499 assert( pTab->azModuleArg[1]==0 ); > 500 iDb = sqlite3SchemaToIndex(db, pTab->pSchema); > 501 pTab->azModuleArg[1] = db->aDb[iDb].zName; > 502 497 /* Invoke the virtual table constructor */ 503 /* Invoke the virtual table constructor */ 498 assert( &db->pVtabCtx ); 504 assert( &db->pVtabCtx ); 499 assert( xConstruct ); 505 assert( xConstruct ); 500 sCtx.pTab = pTab; 506 sCtx.pTab = pTab; 501 sCtx.pVTable = pVTable; 507 sCtx.pVTable = pVTable; 502 pPriorCtx = db->pVtabCtx; 508 pPriorCtx = db->pVtabCtx; 503 db->pVtabCtx = &sCtx; 509 db->pVtabCtx = &sCtx; 504 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); 510 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); 505 db->pVtabCtx = pPriorCtx; 511 db->pVtabCtx = pPriorCtx; 506 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; 512 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; > 513 pTab->azModuleArg[1] = 0; 507 514 508 if( SQLITE_OK!=rc ){ 515 if( SQLITE_OK!=rc ){ 509 if( zErr==0 ){ 516 if( zErr==0 ){ 510 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); 517 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); 511 }else { 518 }else { 512 *pzErr = sqlite3MPrintf(db, "%s", zErr); 519 *pzErr = sqlite3MPrintf(db, "%s", zErr); 513 sqlite3_free(zErr); 520 sqlite3_free(zErr);
Added test/shared9.test
> 1 # 2012 October 5 > 2 # > 3 # The author disclaims copyright to this source code. In place of > 4 # a legal notice, here is a blessing: > 5 # > 6 # May you do good and not evil. > 7 # May you find forgiveness for yourself and forgive others. > 8 # May you share freely, never taking more than you give. > 9 # > 10 #*********************************************************************** > 11 # > 12 # The tests in this file are intended to show if two connections attach > 13 # to the same shared cache using different database names, views and > 14 # virtual tables may still be accessed. > 15 # > 16 > 17 set testdir [file dirname $argv0] > 18 source $testdir/tester.tcl > 19 set testprefix shared9 > 20 > 21 ifcapable !view||!trigger { > 22 finish_test > 23 return > 24 } > 25 > 26 db close > 27 set enable_shared_cache [sqlite3_enable_shared_cache 1] > 28 > 29 sqlite3 db1 test.db > 30 sqlite3 db2 test.db > 31 forcedelete test.db2 > 32 > 33 do_test 1.1 { > 34 db1 eval { > 35 ATTACH 'test.db2' AS 'fred'; > 36 CREATE TABLE fred.t1(a, b, c); > 37 CREATE VIEW fred.v1 AS SELECT * FROM t1; > 38 > 39 CREATE TABLE fred.t2(a, b); > 40 CREATE TABLE fred.t3(a, b); > 41 CREATE TRIGGER fred.trig AFTER INSERT ON t2 BEGIN > 42 DELETE FROM t3; > 43 INSERT INTO t3 SELECT * FROM t2; > 44 END; > 45 INSERT INTO t2 VALUES(1, 2); > 46 SELECT * FROM t3; > 47 } > 48 } {1 2} > 49 > 50 do_test 1.2 { db2 eval "ATTACH 'test.db2' AS 'jones'" } {} > 51 do_test 1.3 { db2 eval "SELECT * FROM v1" } {} > 52 do_test 1.4 { db2 eval "INSERT INTO t2 VALUES(3, 4)" } {} > 53 > 54 ifcapable fts3 { > 55 do_test 1.5 { > 56 db1 eval { > 57 CREATE VIRTUAL TABLE fred.t4 USING fts4; > 58 INSERT INTO t4 VALUES('hello world'); > 59 } > 60 } {} > 61 > 62 do_test 1.6 { > 63 db2 eval { > 64 INSERT INTO t4 VALUES('shared cache'); > 65 SELECT * FROM t4 WHERE t4 MATCH 'hello'; > 66 } > 67 } {{hello world}} > 68 > 69 do_test 1.7 { > 70 db1 eval { > 71 SELECT * FROM t4 WHERE t4 MATCH 'c*'; > 72 } > 73 } {{shared cache}} > 74 } > 75 > 76 db1 close > 77 db2 close > 78 > 79 #------------------------------------------------------------------------- > 80 # The following tests attempt to find a similar problem with collation > 81 # sequence names - pointers to database handle specific allocations leaking > 82 # into schema objects and being used after the original handle has been > 83 # closed. > 84 # > 85 forcedelete test.db test.db2 > 86 sqlite3 db1 test.db > 87 sqlite3 db2 test.db > 88 foreach x {collate1 collate2 collate3} { > 89 proc $x {a b} { string compare $a $b } > 90 db1 collate $x $x > 91 db2 collate $x $x > 92 } > 93 do_test 2.1 { > 94 db1 eval { > 95 CREATE TABLE t1(a, b, c COLLATE collate1); > 96 CREATE INDEX i1 ON t1(a COLLATE collate2, c, b); > 97 } > 98 } {} > 99 do_test 2.2 { > 100 db1 close > 101 db2 eval "INSERT INTO t1 VALUES('abc', 'def', 'ghi')" > 102 } {} > 103 db2 close > 104 > 105 #------------------------------------------------------------------------- > 106 # At one point, the following would cause a collation sequence belonging > 107 # to connection [db1] to be invoked by a call to [db2 eval]. Which is a > 108 # problem if [db1] has already been closed. > 109 # > 110 forcedelete test.db test.db2 > 111 sqlite3 db1 test.db > 112 sqlite3 db2 test.db > 113 > 114 proc mycollate_db1 {a b} {set ::invoked_mycollate_db1 1 ; string compare $a $b} > 115 proc mycollate_db2 {a b} {string compare $a $b} > 116 > 117 db1 collate mycollate mycollate_db1 > 118 db2 collate mycollate mycollate_db2 > 119 > 120 do_test 2.3 { > 121 set ::invoked_mycollate_db1 0 > 122 db1 eval { > 123 CREATE TABLE t1(a COLLATE mycollate, CHECK (a IN ('one', 'two', 'three'))); > 124 INSERT INTO t1 VALUES('one'); > 125 } > 126 db1 close > 127 set ::invoked_mycollate_db1 > 128 } {1} > 129 do_test 2.4 { > 130 set ::invoked_mycollate_db1 0 > 131 db2 eval { > 132 INSERT INTO t1 VALUES('two'); > 133 } > 134 db2 close > 135 set ::invoked_mycollate_db1 > 136 } {0} > 137 > 138 sqlite3_enable_shared_cache $::enable_shared_cache > 139 finish_test > 140
Changes to test/trigger1.test
206 do_test trigger1-1.12 { 206 do_test trigger1-1.12 { 207 catchsql { 207 catchsql { 208 create table t1(a,b); 208 create table t1(a,b); 209 create trigger t1t instead of update on t1 for each row begin 209 create trigger t1t instead of update on t1 for each row begin 210 delete from t1 WHERE a=old.a+2; 210 delete from t1 WHERE a=old.a+2; 211 end; 211 end; 212 } 212 } 213 } {1 {cannot create INSTEAD OF trigger on table: main.t1}} | 213 } {1 {cannot create INSTEAD OF trigger on table: t1}} 214 214 215 ifcapable view { 215 ifcapable view { 216 # Ensure that we cannot create BEFORE triggers on views 216 # Ensure that we cannot create BEFORE triggers on views 217 do_test trigger1-1.13 { 217 do_test trigger1-1.13 { 218 catchsql { 218 catchsql { 219 create view v1 as select * from t1; 219 create view v1 as select * from t1; 220 create trigger v1t before update on v1 for each row begin 220 create trigger v1t before update on v1 for each row begin 221 delete from t1 WHERE a=old.a+2; 221 delete from t1 WHERE a=old.a+2; 222 end; 222 end; 223 } 223 } 224 } {1 {cannot create BEFORE trigger on view: main.v1}} | 224 } {1 {cannot create BEFORE trigger on view: v1}} 225 # Ensure that we cannot create AFTER triggers on views 225 # Ensure that we cannot create AFTER triggers on views 226 do_test trigger1-1.14 { 226 do_test trigger1-1.14 { 227 catchsql { 227 catchsql { 228 drop view v1; 228 drop view v1; 229 create view v1 as select * from t1; 229 create view v1 as select * from t1; 230 create trigger v1t AFTER update on v1 for each row begin 230 create trigger v1t AFTER update on v1 for each row begin 231 delete from t1 WHERE a=old.a+2; 231 delete from t1 WHERE a=old.a+2; 232 end; 232 end; 233 } 233 } 234 } {1 {cannot create AFTER trigger on view: main.v1}} | 234 } {1 {cannot create AFTER trigger on view: v1}} 235 } ;# ifcapable view 235 } ;# ifcapable view 236 236 237 # Check for memory leaks in the trigger parser 237 # Check for memory leaks in the trigger parser 238 # 238 # 239 do_test trigger1-2.1 { 239 do_test trigger1-2.1 { 240 catchsql { 240 catchsql { 241 CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN 241 CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN