diff options
Diffstat (limited to 'third_party/sqlite/src/legacy.c')
-rw-r--r-- | third_party/sqlite/src/legacy.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/third_party/sqlite/src/legacy.c b/third_party/sqlite/src/legacy.c index e6b75c0..7342103 100644 --- a/third_party/sqlite/src/legacy.c +++ b/third_party/sqlite/src/legacy.c @@ -14,11 +14,10 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: legacy.c,v 1.29 2008/08/02 03:50:39 drh Exp $ +** $Id: legacy.c,v 1.35 2009/08/07 16:56:00 danielk1977 Exp $ */ #include "sqliteInt.h" -#include <ctype.h> /* ** Execute SQL code. Return one of the SQLITE_ success/failure @@ -37,13 +36,12 @@ int sqlite3_exec( void *pArg, /* First argument to xCallback() */ char **pzErrMsg /* Write error messages here */ ){ - int rc = SQLITE_OK; - const char *zLeftover; - sqlite3_stmt *pStmt = 0; - char **azCols = 0; - - int nRetry = 0; - int nCallback; + int rc = SQLITE_OK; /* Return code */ + const char *zLeftover; /* Tail of unprocessed SQL */ + sqlite3_stmt *pStmt = 0; /* The current SQL statement */ + char **azCols = 0; /* Names of result columns */ + int nRetry = 0; /* Number of retry attempts */ + int callbackIsInit; /* True if callback data is initialized */ if( zSql==0 ) zSql = ""; @@ -65,7 +63,7 @@ int sqlite3_exec( continue; } - nCallback = 0; + callbackIsInit = 0; nCol = sqlite3_column_count(pStmt); while( 1 ){ @@ -74,13 +72,12 @@ int sqlite3_exec( /* Invoke the callback function if required */ if( xCallback && (SQLITE_ROW==rc || - (SQLITE_DONE==rc && !nCallback && db->flags&SQLITE_NullCallback)) ){ - if( 0==nCallback ){ + (SQLITE_DONE==rc && !callbackIsInit + && db->flags&SQLITE_NullCallback)) ){ + if( !callbackIsInit ){ + azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1); if( azCols==0 ){ - azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1); - if( azCols==0 ){ - goto exec_out; - } + goto exec_out; } for(i=0; i<nCol; i++){ azCols[i] = (char *)sqlite3_column_name(pStmt, i); @@ -88,7 +85,7 @@ int sqlite3_exec( ** strings so there is no way for sqlite3_column_name() to fail. */ assert( azCols[i]!=0 ); } - nCallback++; + callbackIsInit = 1; } if( rc==SQLITE_ROW ){ azVals = &azCols[nCol]; @@ -102,7 +99,7 @@ int sqlite3_exec( } if( xCallback(pArg, nCol, azVals, azCols) ){ rc = SQLITE_ABORT; - sqlite3_finalize(pStmt); + sqlite3VdbeFinalize((Vdbe *)pStmt); pStmt = 0; sqlite3Error(db, SQLITE_ABORT, 0); goto exec_out; @@ -110,12 +107,12 @@ int sqlite3_exec( } if( rc!=SQLITE_ROW ){ - rc = sqlite3_finalize(pStmt); + rc = sqlite3VdbeFinalize((Vdbe *)pStmt); pStmt = 0; if( rc!=SQLITE_SCHEMA ){ nRetry = 0; zSql = zLeftover; - while( isspace((unsigned char)zSql[0]) ) zSql++; + while( sqlite3Isspace(zSql[0]) ) zSql++; } break; } @@ -126,15 +123,18 @@ int sqlite3_exec( } exec_out: - if( pStmt ) sqlite3_finalize(pStmt); + if( pStmt ) sqlite3VdbeFinalize((Vdbe *)pStmt); sqlite3DbFree(db, azCols); rc = sqlite3ApiExit(db, rc); - if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){ - int nErrMsg = 1 + strlen(sqlite3_errmsg(db)); + if( rc!=SQLITE_OK && ALWAYS(rc==sqlite3_errcode(db)) && pzErrMsg ){ + int nErrMsg = 1 + sqlite3Strlen30(sqlite3_errmsg(db)); *pzErrMsg = sqlite3Malloc(nErrMsg); if( *pzErrMsg ){ memcpy(*pzErrMsg, sqlite3_errmsg(db), nErrMsg); + }else{ + rc = SQLITE_NOMEM; + sqlite3Error(db, SQLITE_NOMEM, 0); } }else if( pzErrMsg ){ *pzErrMsg = 0; |