Currently, if SQLite cannot find a table or index referred to by a query, it reloads the database schema from disk to see if the table or index has been added since the schema was cached in memory. Extend this behaviour to columns (which may have been added using ALTER TABLE) and fix some obscure cases related to tables and indexes (INDEXED BY, DROP TABLE etc.).
FossilOrigin-Name: 4932f22848b3d15a2b6dc5fa2cd69ce19182e2a4
diff --git a/src/build.c b/src/build.c
index 4c00e39..ce3e614 100644
--- a/src/build.c
+++ b/src/build.c
@@ -2614,6 +2614,7 @@
if( j>=pTab->nCol ){
sqlite3ErrorMsg(pParse, "table %s has no column named %s",
pTab->zName, zColName);
+ pParse->checkSchema = 1;
goto exit_create_index;
}
pIndex->aiColumn[i] = j;
diff --git a/src/insert.c b/src/insert.c
index 05964f8..f6ad5ab 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -727,7 +727,7 @@
}else{
sqlite3ErrorMsg(pParse, "table %S has no column named %s",
pTabList, 0, pColumn->a[i].zName);
- pParse->nErr++;
+ pParse->checkSchema = 1;
goto insert_cleanup;
}
}
diff --git a/src/resolve.c b/src/resolve.c
index 4e94827..74d6aae 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -357,6 +357,7 @@
}else{
sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol);
}
+ pParse->checkSchema = 1;
pTopNC->nErr++;
}
diff --git a/src/select.c b/src/select.c
index 9a01603..b03e506 100644
--- a/src/select.c
+++ b/src/select.c
@@ -3020,6 +3020,7 @@
);
if( !pIdx ){
sqlite3ErrorMsg(pParse, "no such index: %s", zIndex, 0);
+ pParse->checkSchema = 1;
return SQLITE_ERROR;
}
pFrom->pIndex = pIdx;
diff --git a/src/trigger.c b/src/trigger.c
index 66464bd..27fc708 100644
--- a/src/trigger.c
+++ b/src/trigger.c
@@ -496,6 +496,7 @@
if( !noErr ){
sqlite3ErrorMsg(pParse, "no such trigger: %S", pName, 0);
}
+ pParse->checkSchema = 1;
goto drop_trigger_cleanup;
}
sqlite3DropTriggerPtr(pParse, pTrigger);
diff --git a/src/update.c b/src/update.c
index 3c82c27..fe8344c 100644
--- a/src/update.c
+++ b/src/update.c
@@ -212,6 +212,7 @@
pRowidExpr = pChanges->a[i].pExpr;
}else{
sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
+ pParse->checkSchema = 1;
goto update_cleanup;
}
}