aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analyze.c')
-rw-r--r--src/analyze.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/analyze.c b/src/analyze.c
index abbbf0fd5..3501fddc3 100644
--- a/src/analyze.c
+++ b/src/analyze.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code associated with the ANALYZE command.
**
-** @(#) $Id: analyze.c,v 1.17 2007/03/29 05:51:49 drh Exp $
+** @(#) $Id: analyze.c,v 1.18 2007/05/12 12:08:51 drh Exp $
*/
#ifndef SQLITE_OMIT_ANALYZE
#include "sqliteInt.h"
@@ -36,6 +36,7 @@ static void openStatTable(
Table *pStat;
Vdbe *v = sqlite3GetVdbe(pParse);
+ if( v==0 ) return;
pDb = &db->aDb[iDb];
if( (pStat = sqlite3FindTable(db, "sqlite_stat1", pDb->zName))==0 ){
/* The sqlite_stat1 tables does not exist. Create it.
@@ -95,7 +96,7 @@ static void analyzeOneTable(
int iDb; /* Index of database containing pTab */
v = sqlite3GetVdbe(pParse);
- if( pTab==0 || pTab->pIndex==0 ){
+ if( v==0 || pTab==0 || pTab->pIndex==0 ){
/* Do no analysis for tables that have no indices */
return;
}
@@ -222,7 +223,9 @@ static void analyzeOneTable(
*/
static void loadAnalysis(Parse *pParse, int iDb){
Vdbe *v = sqlite3GetVdbe(pParse);
- sqlite3VdbeAddOp(v, OP_LoadAnalysis, iDb, 0);
+ if( v ){
+ sqlite3VdbeAddOp(v, OP_LoadAnalysis, iDb, 0);
+ }
}
/*
@@ -314,10 +317,12 @@ void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){
if( iDb>=0 ){
zDb = db->aDb[iDb].zName;
z = sqlite3NameFromToken(pTableName);
- pTab = sqlite3LocateTable(pParse, z, zDb);
- sqliteFree(z);
- if( pTab ){
- analyzeTable(pParse, pTab);
+ if( z ){
+ pTab = sqlite3LocateTable(pParse, z, zDb);
+ sqliteFree(z);
+ if( pTab ){
+ analyzeTable(pParse, pTab);
+ }
}
}
}
@@ -371,10 +376,11 @@ static int analysisLoader(void *pData, int argc, char **argv, char **azNotUsed){
/*
** Load the content of the sqlite_stat1 table into the index hash tables.
*/
-void sqlite3AnalysisLoad(sqlite3 *db, int iDb){
+int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
analysisInfo sInfo;
HashElem *i;
char *zSql;
+ int rc;
/* Clear any prior statistics */
for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
@@ -386,7 +392,7 @@ void sqlite3AnalysisLoad(sqlite3 *db, int iDb){
sInfo.db = db;
sInfo.zDatabase = db->aDb[iDb].zName;
if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
- return;
+ return SQLITE_ERROR;
}
@@ -394,9 +400,10 @@ void sqlite3AnalysisLoad(sqlite3 *db, int iDb){
zSql = sqlite3MPrintf("SELECT idx, stat FROM %Q.sqlite_stat1",
sInfo.zDatabase);
sqlite3SafetyOff(db);
- sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
+ rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
sqlite3SafetyOn(db);
sqliteFree(zSql);
+ return rc;
}