SQLite
Check-in [2b370dea70]
Not logged in
Overview
SHA1 Hash:2b370dea704b59262c604af0efcef5660b194454
Date: 2012-10-04 19:33:00
User: dan
Comment:Shared-cache mode fixes for views and virtual tables.
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 ** ................................................................................................................................................................................ 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

1739 } 1739 } 1740 1740 1741 /* At this point we have established that the statement is of the 1741 /* At this point we have established that the statement is of the 1742 ** correct syntactic form to participate in this optimization. Now 1742 ** correct syntactic form to participate in this optimization. Now 1743 ** we have to check the semantics. 1743 ** we have to check the semantics. 1744 */ 1744 */ 1745 pItem = pSelect->pSrc->a; 1745 pItem = pSelect->pSrc->a; 1746 pSrc = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase); | 1746 pSrc = sqlite3LocateTableItem(pParse, 0, pItem); 1747 if( pSrc==0 ){ 1747 if( pSrc==0 ){ 1748 return 0; /* FROM clause does not contain a real table */ 1748 return 0; /* FROM clause does not contain a real table */ 1749 } 1749 } 1750 if( pSrc==pDest ){ 1750 if( pSrc==pDest ){ 1751 return 0; /* tab1 and tab2 may not be the same table */ 1751 return 0; /* tab1 and tab2 may not be the same table */ 1752 } 1752 } 1753 #ifndef SQLITE_OMIT_VIRTUALTABLE 1753 #ifndef SQLITE_OMIT_VIRTUALTABLE

Changes to src/select.c

3328 pTab->iPKey = -1; 3328 pTab->iPKey = -1; 3329 pTab->nRowEst = 1000000; 3329 pTab->nRowEst = 1000000; 3330 pTab->tabFlags |= TF_Ephemeral; 3330 pTab->tabFlags |= TF_Ephemeral; 3331 #endif 3331 #endif 3332 }else{ 3332 }else{ 3333 /* An ordinary table or view name in the FROM clause */ 3333 /* An ordinary table or view name in the FROM clause */ 3334 assert( pFrom->pTab==0 ); 3334 assert( pFrom->pTab==0 ); 3335 pFrom->pTab = pTab = | 3335 pFrom->pTab = pTab = sqlite3LocateTableItem(pParse, 0, pFrom); 3336 sqlite3LocateTable(pParse,0,pFrom->zName,pFrom->zDatabase); < 3337 if( pTab==0 ) return WRC_Abort; 3336 if( pTab==0 ) return WRC_Abort; 3338 pTab->nRef++; 3337 pTab->nRef++; 3339 #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) 3338 #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) 3340 if( pTab->pSelect || IsVirtual(pTab) ){ 3339 if( pTab->pSelect || IsVirtual(pTab) ){ 3341 /* We reach here if the named table is a really a view */ 3340 /* We reach here if the named table is a really a view */ 3342 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; 3341 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; 3343 assert( pFrom->pSelect==0 ); 3342 assert( pFrom->pSelect==0 );

Changes to src/sqliteInt.h

1865 ** In the colUsed field, the high-order bit (bit 63) is set if the table 1865 ** In the colUsed field, the high-order bit (bit 63) is set if the table 1866 ** contains more than 63 columns and the 64-th or later column is used. 1866 ** contains more than 63 columns and the 64-th or later column is used. 1867 */ 1867 */ 1868 struct SrcList { 1868 struct SrcList { 1869 i16 nSrc; /* Number of tables or subqueries in the FROM clause */ 1869 i16 nSrc; /* Number of tables or subqueries in the FROM clause */ 1870 i16 nAlloc; /* Number of entries allocated in a[] below */ 1870 i16 nAlloc; /* Number of entries allocated in a[] below */ 1871 struct SrcList_item { 1871 struct SrcList_item { > 1872 Schema *pSchema; /* Schema to which this item is fixed */ 1872 char *zDatabase; /* Name of database holding this table */ 1873 char *zDatabase; /* Name of database holding this table */ 1873 char *zName; /* Name of the table */ 1874 char *zName; /* Name of the table */ 1874 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ 1875 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ 1875 Table *pTab; /* An SQL table corresponding to zName */ 1876 Table *pTab; /* An SQL table corresponding to zName */ 1876 Select *pSelect; /* A SELECT statement used in place of a table name */ 1877 Select *pSelect; /* A SELECT statement used in place of a table name */ 1877 int addrFillSub; /* Address of subroutine to manifest a subquery */ 1878 int addrFillSub; /* Address of subroutine to manifest a subquery */ 1878 int regReturn; /* Register holding return address of addrFillSub */ 1879 int regReturn; /* Register holding return address of addrFillSub */ ................................................................................................................................................................................ 2433 ** The following structure contains information used by the sqliteFix... 2434 ** The following structure contains information used by the sqliteFix... 2434 ** routines as they walk the parse tree to make database references 2435 ** routines as they walk the parse tree to make database references 2435 ** explicit. 2436 ** explicit. 2436 */ 2437 */ 2437 typedef struct DbFixer DbFixer; 2438 typedef struct DbFixer DbFixer; 2438 struct DbFixer { 2439 struct DbFixer { 2439 Parse *pParse; /* The parsing context. Error messages written here */ 2440 Parse *pParse; /* The parsing context. Error messages written here */ > 2441 Schema *pSchema; /* Fix items to this schema */ 2440 const char *zDb; /* Make sure all objects are contained in this database */ 2442 const char *zDb; /* Make sure all objects are contained in this database */ 2441 const char *zType; /* Type of the container - used for error messages */ 2443 const char *zType; /* Type of the container - used for error messages */ 2442 const Token *pName; /* Name of the container - used for error messages */ 2444 const Token *pName; /* Name of the container - used for error messages */ 2443 }; 2445 }; 2444 2446 2445 /* 2447 /* 2446 ** An objected used to accumulate the text of a string where we 2448 ** An objected used to accumulate the text of a string where we ................................................................................................................................................................................ 2843 int sqlite3ExprCodeAndCache(Parse*, Expr*, int); 2845 int sqlite3ExprCodeAndCache(Parse*, Expr*, int); 2844 void sqlite3ExprCodeConstants(Parse*, Expr*); 2846 void sqlite3ExprCodeConstants(Parse*, Expr*); 2845 int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int); 2847 int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int); 2846 void sqlite3ExprIfTrue(Parse*, Expr*, int, int); 2848 void sqlite3ExprIfTrue(Parse*, Expr*, int, int); 2847 void sqlite3ExprIfFalse(Parse*, Expr*, int, int); 2849 void sqlite3ExprIfFalse(Parse*, Expr*, int, int); 2848 Table *sqlite3FindTable(sqlite3*,const char*, const char*); 2850 Table *sqlite3FindTable(sqlite3*,const char*, const char*); 2849 Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*); 2851 Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*); > 2852 Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *); 2850 Index *sqlite3FindIndex(sqlite3*,const char*, const char*); 2853 Index *sqlite3FindIndex(sqlite3*,const char*, const char*); 2851 void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); 2854 void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); 2852 void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); 2855 void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); 2853 void sqlite3Vacuum(Parse*); 2856 void sqlite3Vacuum(Parse*); 2854 int sqlite3RunVacuum(char**, sqlite3*); 2857 int sqlite3RunVacuum(char**, sqlite3*); 2855 char *sqlite3NameFromToken(sqlite3*, Token*); 2858 char *sqlite3NameFromToken(sqlite3*, Token*); 2856 int sqlite3ExprCompare(Expr*, Expr*); 2859 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 db close > 21 set enable_shared_cache [sqlite3_enable_shared_cache 1] > 22 > 23 # Test organization: > 24 # > 25 # 1.* - Views. > 26 # 2.* - Virtual tables. > 27 # > 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.2 { db2 eval "SELECT * FROM v1" } {} > 52 do_test 1.3 { db2 eval "INSERT INTO t2 VALUES(3, 4)" } {} > 53 > 54 do_test 2.1 { > 55 db1 eval { > 56 CREATE VIRTUAL TABLE fred.t4 USING fts4; > 57 INSERT INTO t4 VALUES('hello world'); > 58 } > 59 } {} > 60 > 61 do_test 2.2 { > 62 db2 eval { > 63 INSERT INTO t4 VALUES('shared cache'); > 64 SELECT * FROM t4 WHERE t4 MATCH 'hello'; > 65 } > 66 } {{hello world}} > 67 > 68 do_test 2.3 { > 69 db1 eval { > 70 SELECT * FROM t4 WHERE t4 MATCH 'c*'; > 71 } > 72 } {{shared cache}} > 73 > 74 db1 close > 75 db2 close > 76 sqlite3_enable_shared_cache $::enable_shared_cache > 77 finish_test > 78

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