aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/attach.c17
-rw-r--r--src/build.c2
-rw-r--r--src/select.c8
-rw-r--r--src/sqliteInt.h1
-rw-r--r--src/update.c5
5 files changed, 21 insertions, 12 deletions
diff --git a/src/attach.c b/src/attach.c
index 6d178b6ba..2fc84e5b8 100644
--- a/src/attach.c
+++ b/src/attach.c
@@ -464,14 +464,17 @@ static int fixSelectCb(Walker *p, Select *pSelect){
if( NEVER(pList==0) ) return WRC_Continue;
for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
if( pFix->bTemp==0 ){
- if( pItem->zDatabase && iDb!=sqlite3FindDbName(db, pItem->zDatabase) ){
- sqlite3ErrorMsg(pFix->pParse,
- "%s %T cannot reference objects in database %s",
- pFix->zType, pFix->pName, pItem->zDatabase);
- return WRC_Abort;
+ if( pItem->zDatabase ){
+ if( iDb!=sqlite3FindDbName(db, pItem->zDatabase) ){
+ sqlite3ErrorMsg(pFix->pParse,
+ "%s %T cannot reference objects in database %s",
+ pFix->zType, pFix->pName, pItem->zDatabase);
+ return WRC_Abort;
+ }
+ sqlite3DbFree(db, pItem->zDatabase);
+ pItem->zDatabase = 0;
+ pItem->fg.notCte = 1;
}
- sqlite3DbFree(db, pItem->zDatabase);
- pItem->zDatabase = 0;
pItem->pSchema = pFix->pSchema;
pItem->fg.fromDDL = 1;
}
diff --git a/src/build.c b/src/build.c
index cf952ce09..25954b4d4 100644
--- a/src/build.c
+++ b/src/build.c
@@ -492,7 +492,7 @@ Table *sqlite3LocateTableItem(
SrcItem *p
){
const char *zDb;
- /* assert( p->pSchema==0 || p->zDatabase==0 ); FIX-ME */
+ assert( p->pSchema==0 || p->zDatabase==0 );
if( p->pSchema ){
int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
zDb = pParse->db->aDb[iDb].zDbSName;
diff --git a/src/select.c b/src/select.c
index aeb63d99d..1ac25c5de 100644
--- a/src/select.c
+++ b/src/select.c
@@ -5071,6 +5071,14 @@ static int resolveFromTermToCte(
** it cannot possibly be a CTE reference. */
return 0;
}
+ if( pFrom->fg.notCte ){
+ /* The FROM term is specifically excluded from matching a CTE.
+ ** (1) It is part of a trigger that used to have zDatabase but had
+ ** zDatabase removed by sqlite3FixTriggerStep().
+ ** (2) This is the first term in the FROM clause of an UPDATE.
+ */
+ return 0;
+ }
pCte = searchWith(pParse->pWith, pFrom, &pWith);
if( pCte ){
sqlite3 *db = pParse->db;
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 7eafdd2b4..1bdccddec 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -2948,6 +2948,7 @@ struct SrcItem {
unsigned isRecursive :1; /* True for recursive reference in WITH */
unsigned fromDDL :1; /* Comes from sqlite_schema */
unsigned isCte :1; /* This is a CTE */
+ unsigned notCte :1; /* This item may not match a CTE */
} fg;
int iCursor; /* The VDBE cursor number used to access this table */
Expr *pOn; /* The ON clause of a join */
diff --git a/src/update.c b/src/update.c
index a72c02a52..132232724 100644
--- a/src/update.c
+++ b/src/update.c
@@ -220,10 +220,7 @@ static void updateFromSelect(
assert( pTabList->nSrc>1 );
if( pSrc ){
- if( pSrc->a[0].zDatabase==0 ){
- int iSchema = sqlite3SchemaToIndex(db, pTab->pSchema);
- pSrc->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iSchema].zDbSName);
- }
+ pSrc->a[0].fg.notCte = 1;
pSrc->a[0].iCursor = -1;
pSrc->a[0].pTab->nTabRef--;
pSrc->a[0].pTab = 0;