SQLite
Check-in [ac81ae493f]
Not logged in
Overview
SHA1 Hash:ac81ae493f97e415f13ef517b0ff88a901bc276f
Date: 2012-10-05 18:35:33
User: drh
Comment:Backport fixes to shared-cache mode, from the shared-cache-fix branch, to version 3.7.9
Tags And Properties
Changes
hide diffs unified diffs patch

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 ** ................................................................................................................................................................................ 2086 2111 2087 if( db->mallocFailed ){ 2112 if( db->mallocFailed ){ 2088 goto exit_drop_table; 2113 goto exit_drop_table; 2089 } 2114 } 2090 assert( pParse->nErr==0 ); 2115 assert( pParse->nErr==0 ); 2091 assert( pName->nSrc==1 ); 2116 assert( pName->nSrc==1 ); 2092 if( noErr ) db->suppressErr++; 2117 if( noErr ) db->suppressErr++; 2093 pTab = sqlite3LocateTable(pParse, isView, | 2118 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]); 2094 pName->a[0].zName, pName->a[0].zDatabase); < 2095 if( noErr ) db->suppressErr--; 2119 if( noErr ) db->suppressErr--; 2096 2120 2097 if( pTab==0 ){ 2121 if( pTab==0 ){ 2098 if( noErr ) sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase); 2122 if( noErr ) sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase); 2099 goto exit_drop_table; 2123 goto exit_drop_table; 2100 } 2124 } 2101 iDb = sqlite3SchemaToIndex(db, pTab->pSchema); 2125 iDb = sqlite3SchemaToIndex(db, pTab->pSchema); ................................................................................................................................................................................ 2529 if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && 2553 if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) && 2530 sqlite3FixSrcList(&sFix, pTblName) 2554 sqlite3FixSrcList(&sFix, pTblName) 2531 ){ 2555 ){ 2532 /* Because the parser constructs pTblName from a single identifier, 2556 /* Because the parser constructs pTblName from a single identifier, 2533 ** sqlite3FixSrcList can never fail. */ 2557 ** sqlite3FixSrcList can never fail. */ 2534 assert(0); 2558 assert(0); 2535 } 2559 } 2536 pTab = sqlite3LocateTable(pParse, 0, pTblName->a[0].zName, | 2560 pTab = sqlite3LocateTableItem(pParse, 0, &pTblName->a[0]); 2537 pTblName->a[0].zDatabase); < 2538 if( !pTab || db->mallocFailed ) goto exit_create_index; 2561 if( !pTab || db->mallocFailed ) goto exit_create_index; 2539 assert( db->aDb[iDb].pSchema==pTab->pSchema ); 2562 assert( db->aDb[iDb].pSchema==pTab->pSchema ); 2540 }else{ 2563 }else{ 2541 assert( pName==0 ); 2564 assert( pName==0 ); 2542 assert( pStart==0 ); 2565 assert( pStart==0 ); 2543 pTab = pParse->pNewTable; 2566 pTab = pParse->pNewTable; 2544 if( !pTab ) goto exit_create_index; 2567 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

893 pNew = sqlite3DbMallocRaw(db, nByte ); 893 pNew = sqlite3DbMallocRaw(db, nByte ); 894 if( pNew==0 ) return 0; 894 if( pNew==0 ) return 0; 895 pNew->nSrc = pNew->nAlloc = p->nSrc; 895 pNew->nSrc = pNew->nAlloc = p->nSrc; 896 for(i=0; i<p->nSrc; i++){ 896 for(i=0; i<p->nSrc; i++){ 897 struct SrcList_item *pNewItem = &pNew->a[i]; 897 struct SrcList_item *pNewItem = &pNew->a[i]; 898 struct SrcList_item *pOldItem = &p->a[i]; 898 struct SrcList_item *pOldItem = &p->a[i]; 899 Table *pTab; 899 Table *pTab; > 900 pNewItem->pSchema = pOldItem->pSchema; 900 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase); 901 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase); 901 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); 902 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); 902 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias); 903 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias); 903 pNewItem->jointype = pOldItem->jointype; 904 pNewItem->jointype = pOldItem->jointype; 904 pNewItem->iCursor = pOldItem->iCursor; 905 pNewItem->iCursor = pOldItem->iCursor; 905 pNewItem->addrFillSub = pOldItem->addrFillSub; 906 pNewItem->addrFillSub = pOldItem->addrFillSub; 906 pNewItem->regReturn = pOldItem->regReturn; 907 pNewItem->regReturn = pOldItem->regReturn;

Changes to src/insert.c

1211 } 1211 } 1212 1212 1213 /* Test all CHECK constraints 1213 /* Test all CHECK constraints 1214 */ 1214 */ 1215 #ifndef SQLITE_OMIT_CHECK 1215 #ifndef SQLITE_OMIT_CHECK 1216 if( pTab->pCheck && (pParse->db->flags & SQLITE_IgnoreChecks)==0 ){ 1216 if( pTab->pCheck && (pParse->db->flags & SQLITE_IgnoreChecks)==0 ){ 1217 int allOk = sqlite3VdbeMakeLabel(v); 1217 int allOk = sqlite3VdbeMakeLabel(v); > 1218 Expr *pDup = sqlite3ExprDup(pParse->db, pTab->pCheck, 0); 1218 pParse->ckBase = regData; 1219 pParse->ckBase = regData; 1219 sqlite3ExprIfTrue(pParse, pTab->pCheck, allOk, SQLITE_JUMPIFNULL); | 1220 sqlite3ExprIfTrue(pParse, pDup, allOk, SQLITE_JUMPIFNULL); 1220 onError = overrideError!=OE_Default ? overrideError : OE_Abort; 1221 onError = overrideError!=OE_Default ? overrideError : OE_Abort; 1221 if( onError==OE_Ignore ){ 1222 if( onError==OE_Ignore ){ 1222 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); 1223 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); 1223 }else{ 1224 }else{ 1224 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ 1225 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ 1225 sqlite3HaltConstraint(pParse, onError, 0, 0); 1226 sqlite3HaltConstraint(pParse, onError, 0, 0); 1226 } 1227 } > 1228 sqlite3ExprDelete(pParse->db, pDup); 1227 sqlite3VdbeResolveLabel(v, allOk); 1229 sqlite3VdbeResolveLabel(v, allOk); 1228 } 1230 } 1229 #endif /* !defined(SQLITE_OMIT_CHECK) */ 1231 #endif /* !defined(SQLITE_OMIT_CHECK) */ 1230 1232 1231 /* If we have an INTEGER PRIMARY KEY, make sure the primary key 1233 /* If we have an INTEGER PRIMARY KEY, make sure the primary key 1232 ** of the new record does not previously exist. Except, if this 1234 ** of the new record does not previously exist. Except, if this 1233 ** is an UPDATE and the primary key is not changing, that is OK. 1235 ** is an UPDATE and the primary key is not changing, that is OK. ................................................................................................................................................................................ 1683 } 1685 } 1684 1686 1685 /* At this point we have established that the statement is of the 1687 /* At this point we have established that the statement is of the 1686 ** correct syntactic form to participate in this optimization. Now 1688 ** correct syntactic form to participate in this optimization. Now 1687 ** we have to check the semantics. 1689 ** we have to check the semantics. 1688 */ 1690 */ 1689 pItem = pSelect->pSrc->a; 1691 pItem = pSelect->pSrc->a; 1690 pSrc = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase); | 1692 pSrc = sqlite3LocateTableItem(pParse, 0, pItem); 1691 if( pSrc==0 ){ 1693 if( pSrc==0 ){ 1692 return 0; /* FROM clause does not contain a real table */ 1694 return 0; /* FROM clause does not contain a real table */ 1693 } 1695 } 1694 if( pSrc==pDest ){ 1696 if( pSrc==pDest ){ 1695 return 0; /* tab1 and tab2 may not be the same table */ 1697 return 0; /* tab1 and tab2 may not be the same table */ 1696 } 1698 } 1697 #ifndef SQLITE_OMIT_VIRTUALTABLE 1699 #ifndef SQLITE_OMIT_VIRTUALTABLE

Changes to src/select.c

3235 pTab->iPKey = -1; 3235 pTab->iPKey = -1; 3236 pTab->nRowEst = 1000000; 3236 pTab->nRowEst = 1000000; 3237 pTab->tabFlags |= TF_Ephemeral; 3237 pTab->tabFlags |= TF_Ephemeral; 3238 #endif 3238 #endif 3239 }else{ 3239 }else{ 3240 /* An ordinary table or view name in the FROM clause */ 3240 /* An ordinary table or view name in the FROM clause */ 3241 assert( pFrom->pTab==0 ); 3241 assert( pFrom->pTab==0 ); 3242 pFrom->pTab = pTab = | 3242 pFrom->pTab = pTab = sqlite3LocateTableItem(pParse, 0, pFrom); 3243 sqlite3LocateTable(pParse,0,pFrom->zName,pFrom->zDatabase); < 3244 if( pTab==0 ) return WRC_Abort; 3243 if( pTab==0 ) return WRC_Abort; 3245 pTab->nRef++; 3244 pTab->nRef++; 3246 #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) 3245 #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) 3247 if( pTab->pSelect || IsVirtual(pTab) ){ 3246 if( pTab->pSelect || IsVirtual(pTab) ){ 3248 /* We reach here if the named table is a really a view */ 3247 /* We reach here if the named table is a really a view */ 3249 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; 3248 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; 3250 assert( pFrom->pSelect==0 ); 3249 assert( pFrom->pSelect==0 );

Changes to src/sqliteInt.h

1857 ** In the colUsed field, the high-order bit (bit 63) is set if the table 1857 ** In the colUsed field, the high-order bit (bit 63) is set if the table 1858 ** contains more than 63 columns and the 64-th or later column is used. 1858 ** contains more than 63 columns and the 64-th or later column is used. 1859 */ 1859 */ 1860 struct SrcList { 1860 struct SrcList { 1861 i16 nSrc; /* Number of tables or subqueries in the FROM clause */ 1861 i16 nSrc; /* Number of tables or subqueries in the FROM clause */ 1862 i16 nAlloc; /* Number of entries allocated in a[] below */ 1862 i16 nAlloc; /* Number of entries allocated in a[] below */ 1863 struct SrcList_item { 1863 struct SrcList_item { > 1864 Schema *pSchema; /* Schema to which this item is fixed */ 1864 char *zDatabase; /* Name of database holding this table */ 1865 char *zDatabase; /* Name of database holding this table */ 1865 char *zName; /* Name of the table */ 1866 char *zName; /* Name of the table */ 1866 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ 1867 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ 1867 Table *pTab; /* An SQL table corresponding to zName */ 1868 Table *pTab; /* An SQL table corresponding to zName */ 1868 Select *pSelect; /* A SELECT statement used in place of a table name */ 1869 Select *pSelect; /* A SELECT statement used in place of a table name */ 1869 int addrFillSub; /* Address of subroutine to manifest a subquery */ 1870 int addrFillSub; /* Address of subroutine to manifest a subquery */ 1870 int regReturn; /* Register holding return address of addrFillSub */ 1871 int regReturn; /* Register holding return address of addrFillSub */ ................................................................................................................................................................................ 2408 ** The following structure contains information used by the sqliteFix... 2409 ** The following structure contains information used by the sqliteFix... 2409 ** routines as they walk the parse tree to make database references 2410 ** routines as they walk the parse tree to make database references 2410 ** explicit. 2411 ** explicit. 2411 */ 2412 */ 2412 typedef struct DbFixer DbFixer; 2413 typedef struct DbFixer DbFixer; 2413 struct DbFixer { 2414 struct DbFixer { 2414 Parse *pParse; /* The parsing context. Error messages written here */ 2415 Parse *pParse; /* The parsing context. Error messages written here */ > 2416 Schema *pSchema; /* Fix items to this schema */ 2415 const char *zDb; /* Make sure all objects are contained in this database */ 2417 const char *zDb; /* Make sure all objects are contained in this database */ 2416 const char *zType; /* Type of the container - used for error messages */ 2418 const char *zType; /* Type of the container - used for error messages */ 2417 const Token *pName; /* Name of the container - used for error messages */ 2419 const Token *pName; /* Name of the container - used for error messages */ 2418 }; 2420 }; 2419 2421 2420 /* 2422 /* 2421 ** An objected used to accumulate the text of a string where we 2423 ** An objected used to accumulate the text of a string where we ................................................................................................................................................................................ 2786 int sqlite3ExprCodeAndCache(Parse*, Expr*, int); 2788 int sqlite3ExprCodeAndCache(Parse*, Expr*, int); 2787 void sqlite3ExprCodeConstants(Parse*, Expr*); 2789 void sqlite3ExprCodeConstants(Parse*, Expr*); 2788 int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int); 2790 int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int); 2789 void sqlite3ExprIfTrue(Parse*, Expr*, int, int); 2791 void sqlite3ExprIfTrue(Parse*, Expr*, int, int); 2790 void sqlite3ExprIfFalse(Parse*, Expr*, int, int); 2792 void sqlite3ExprIfFalse(Parse*, Expr*, int, int); 2791 Table *sqlite3FindTable(sqlite3*,const char*, const char*); 2793 Table *sqlite3FindTable(sqlite3*,const char*, const char*); 2792 Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*); 2794 Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*); > 2795 Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *); 2793 Index *sqlite3FindIndex(sqlite3*,const char*, const char*); 2796 Index *sqlite3FindIndex(sqlite3*,const char*, const char*); 2794 void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); 2797 void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); 2795 void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); 2798 void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); 2796 void sqlite3Vacuum(Parse*); 2799 void sqlite3Vacuum(Parse*); 2797 int sqlite3RunVacuum(char**, sqlite3*); 2800 int sqlite3RunVacuum(char**, sqlite3*); 2798 char *sqlite3NameFromToken(sqlite3*, Token*); 2801 char *sqlite3NameFromToken(sqlite3*, Token*); 2799 int sqlite3ExprCompare(Expr*, Expr*); 2802 int sqlite3ExprCompare(Expr*, Expr*);

Changes to src/vtab.c

232 ** in the list are moved to the sqlite3.pDisconnect list of the associated 232 ** in the list are moved to the sqlite3.pDisconnect list of the associated 233 ** database connection. 233 ** database connection. 234 */ 234 */ 235 void sqlite3VtabClear(sqlite3 *db, Table *p){ 235 void sqlite3VtabClear(sqlite3 *db, Table *p){ 236 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p); 236 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p); 237 if( p->azModuleArg ){ 237 if( p->azModuleArg ){ 238 int i; 238 int i; > 239 assert( p->nModuleArg<2 || p->azModuleArg[1]==0 ); 239 for(i=0; i<p->nModuleArg; i++){ 240 for(i=0; i<p->nModuleArg; i++){ 240 sqlite3DbFree(db, p->azModuleArg[i]); 241 sqlite3DbFree(db, p->azModuleArg[i]); 241 } 242 } 242 sqlite3DbFree(db, p->azModuleArg); 243 sqlite3DbFree(db, p->azModuleArg); 243 } 244 } 244 } 245 } 245 246 ................................................................................................................................................................................ 292 db = pParse->db; 293 db = pParse->db; 293 iDb = sqlite3SchemaToIndex(db, pTable->pSchema); 294 iDb = sqlite3SchemaToIndex(db, pTable->pSchema); 294 assert( iDb>=0 ); 295 assert( iDb>=0 ); 295 296 296 pTable->tabFlags |= TF_Virtual; 297 pTable->tabFlags |= TF_Virtual; 297 pTable->nModuleArg = 0; 298 pTable->nModuleArg = 0; 298 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName)); 299 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName)); 299 addModuleArgument(db, pTable, sqlite3DbStrDup(db, db->aDb[iDb].zName)); | 300 addModuleArgument(db, pTable, 0); 300 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName)); 301 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName)); 301 pParse->sNameToken.n = (int)(&pModuleName->z[pModuleName->n] - pName1->z); 302 pParse->sNameToken.n = (int)(&pModuleName->z[pModuleName->n] - pName1->z); 302 303 303 #ifndef SQLITE_OMIT_AUTHORIZATION 304 #ifndef SQLITE_OMIT_AUTHORIZATION 304 /* Creating a virtual table invokes the authorization callback twice. 305 /* Creating a virtual table invokes the authorization callback twice. 305 ** The first invocation, to obtain permission to INSERT a row into the 306 ** The first invocation, to obtain permission to INSERT a row into the 306 ** sqlite_master table, has already been made by sqlite3StartTable(). 307 ** sqlite_master table, has already been made by sqlite3StartTable(). ................................................................................................................................................................................ 449 VtabCtx sCtx; 450 VtabCtx sCtx; 450 VTable *pVTable; 451 VTable *pVTable; 451 int rc; 452 int rc; 452 const char *const*azArg = (const char *const*)pTab->azModuleArg; 453 const char *const*azArg = (const char *const*)pTab->azModuleArg; 453 int nArg = pTab->nModuleArg; 454 int nArg = pTab->nModuleArg; 454 char *zErr = 0; 455 char *zErr = 0; 455 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); 456 char *zModuleName = sqlite3MPrintf(db, "%s", pTab->zName); > 457 int iDb; 456 458 457 if( !zModuleName ){ 459 if( !zModuleName ){ 458 return SQLITE_NOMEM; 460 return SQLITE_NOMEM; 459 } 461 } 460 462 461 pVTable = sqlite3DbMallocZero(db, sizeof(VTable)); 463 pVTable = sqlite3DbMallocZero(db, sizeof(VTable)); 462 if( !pVTable ){ 464 if( !pVTable ){ 463 sqlite3DbFree(db, zModuleName); 465 sqlite3DbFree(db, zModuleName); 464 return SQLITE_NOMEM; 466 return SQLITE_NOMEM; 465 } 467 } 466 pVTable->db = db; 468 pVTable->db = db; 467 pVTable->pMod = pMod; 469 pVTable->pMod = pMod; 468 470 > 471 assert( pTab->azModuleArg[1]==0 ); > 472 iDb = sqlite3SchemaToIndex(db, pTab->pSchema); > 473 pTab->azModuleArg[1] = db->aDb[iDb].zName; > 474 469 /* Invoke the virtual table constructor */ 475 /* Invoke the virtual table constructor */ 470 assert( &db->pVtabCtx ); 476 assert( &db->pVtabCtx ); 471 assert( xConstruct ); 477 assert( xConstruct ); 472 sCtx.pTab = pTab; 478 sCtx.pTab = pTab; 473 sCtx.pVTable = pVTable; 479 sCtx.pVTable = pVTable; 474 db->pVtabCtx = &sCtx; 480 db->pVtabCtx = &sCtx; 475 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); 481 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr); 476 db->pVtabCtx = 0; 482 db->pVtabCtx = 0; 477 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; 483 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; > 484 pTab->azModuleArg[1] = 0; 478 485 479 if( SQLITE_OK!=rc ){ 486 if( SQLITE_OK!=rc ){ 480 if( zErr==0 ){ 487 if( zErr==0 ){ 481 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); 488 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName); 482 }else { 489 }else { 483 *pzErr = sqlite3MPrintf(db, "%s", zErr); 490 *pzErr = sqlite3MPrintf(db, "%s", zErr); 484 sqlite3_free(zErr); 491 sqlite3_free(zErr);

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