aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/legacy.c8
-rw-r--r--src/main.c43
-rw-r--r--src/prepare.c6
-rw-r--r--src/test_func.c25
-rw-r--r--src/vdbeapi.c5
-rw-r--r--src/vdbeblob.c6
-rw-r--r--src/vtab.c6
7 files changed, 65 insertions, 34 deletions
diff --git a/src/legacy.c b/src/legacy.c
index e83817da7..75de5dc91 100644
--- a/src/legacy.c
+++ b/src/legacy.c
@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
-** $Id: legacy.c,v 1.31 2009/01/20 16:53:40 danielk1977 Exp $
+** $Id: legacy.c,v 1.32 2009/03/19 18:51:07 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -101,7 +101,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;
@@ -109,7 +109,7 @@ int sqlite3_exec(
}
if( rc!=SQLITE_ROW ){
- rc = sqlite3_finalize(pStmt);
+ rc = sqlite3VdbeFinalize((Vdbe *)pStmt);
pStmt = 0;
if( rc!=SQLITE_SCHEMA ){
nRetry = 0;
@@ -125,7 +125,7 @@ int sqlite3_exec(
}
exec_out:
- if( pStmt ) sqlite3_finalize(pStmt);
+ if( pStmt ) sqlite3VdbeFinalize((Vdbe *)pStmt);
sqlite3DbFree(db, azCols);
rc = sqlite3ApiExit(db, rc);
diff --git a/src/main.c b/src/main.c
index 605f138ab..5eddc02e6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
-** $Id: main.c,v 1.532 2009/03/18 10:33:01 danielk1977 Exp $
+** $Id: main.c,v 1.533 2009/03/19 18:51:07 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -1245,15 +1245,15 @@ const char *sqlite3_errmsg(sqlite3 *db){
if( !sqlite3SafetyCheckSickOrOk(db) ){
return sqlite3ErrStr(SQLITE_MISUSE);
}
- if( db->mallocFailed ){
- return sqlite3ErrStr(SQLITE_NOMEM);
- }
sqlite3_mutex_enter(db->mutex);
- assert( !db->mallocFailed );
- z = (char*)sqlite3_value_text(db->pErr);
- assert( !db->mallocFailed );
- if( z==0 ){
- z = sqlite3ErrStr(db->errCode);
+ if( db->mallocFailed ){
+ z = sqlite3ErrStr(SQLITE_NOMEM);
+ }else{
+ z = (char*)sqlite3_value_text(db->pErr);
+ assert( !db->mallocFailed );
+ if( z==0 ){
+ z = sqlite3ErrStr(db->errCode);
+ }
}
sqlite3_mutex_leave(db->mutex);
return z;
@@ -1285,19 +1285,22 @@ const void *sqlite3_errmsg16(sqlite3 *db){
return (void *)misuse;
}
sqlite3_mutex_enter(db->mutex);
- assert( !db->mallocFailed );
- z = sqlite3_value_text16(db->pErr);
- if( z==0 ){
- sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),
- SQLITE_UTF8, SQLITE_STATIC);
+ if( db->mallocFailed ){
+ z = (void *)outOfMem;
+ }else{
z = sqlite3_value_text16(db->pErr);
+ if( z==0 ){
+ sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),
+ SQLITE_UTF8, SQLITE_STATIC);
+ z = sqlite3_value_text16(db->pErr);
+ }
+ /* A malloc() may have failed within the call to sqlite3_value_text16()
+ ** above. If this is the case, then the db->mallocFailed flag needs to
+ ** be cleared before returning. Do this directly, instead of via
+ ** sqlite3ApiExit(), to avoid setting the database handle error message.
+ */
+ db->mallocFailed = 0;
}
- /* A malloc() may have failed within the call to sqlite3_value_text16()
- ** above. If this is the case, then the db->mallocFailed flag needs to
- ** be cleared before returning. Do this directly, instead of via
- ** sqlite3ApiExit(), to avoid setting the database handle error message.
- */
- db->mallocFailed = 0;
sqlite3_mutex_leave(db->mutex);
return z;
}
diff --git a/src/prepare.c b/src/prepare.c
index 0b9e747dd..3367f7979 100644
--- a/src/prepare.c
+++ b/src/prepare.c
@@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema
** from disk.
**
-** $Id: prepare.c,v 1.110 2009/03/19 07:58:31 danielk1977 Exp $
+** $Id: prepare.c,v 1.111 2009/03/19 18:51:07 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -648,8 +648,8 @@ static int sqlite3Prepare(
Vdbe *pVdbe = sParse.pVdbe;
sqlite3VdbeSetSql(pVdbe, zSql, (int)(sParse.zTail-zSql), saveSqlFlag);
}
- if( rc!=SQLITE_OK || db->mallocFailed ){
- sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);
+ if( sParse.pVdbe && (rc!=SQLITE_OK || db->mallocFailed) ){
+ sqlite3VdbeFinalize(sParse.pVdbe);
assert(!(*ppStmt));
}else{
*ppStmt = (sqlite3_stmt*)sParse.pVdbe;
diff --git a/src/test_func.c b/src/test_func.c
index 20f330718..275359e38 100644
--- a/src/test_func.c
+++ b/src/test_func.c
@@ -12,7 +12,7 @@
** Code for testing all sorts of SQLite interfaces. This code
** implements new SQL functions used by the test scripts.
**
-** $Id: test_func.c,v 1.13 2008/08/28 02:26:07 drh Exp $
+** $Id: test_func.c,v 1.14 2009/03/19 18:51:07 danielk1977 Exp $
*/
#include "sqlite3.h"
#include "tcl.h"
@@ -147,6 +147,25 @@ static void test_destructor_count(
}
/*
+** The following aggregate function, test_agg_errmsg16(), takes zero
+** arguments. It returns the text value returned by the sqlite3_errmsg16()
+** API function.
+*/
+void sqlite3BeginBenignMalloc(void);
+void sqlite3EndBenignMalloc(void);
+static void test_agg_errmsg16_step(sqlite3_context *a, int b,sqlite3_value **c){
+}
+static void test_agg_errmsg16_final(sqlite3_context *ctx){
+ const void *z;
+ sqlite3 * db = sqlite3_context_db_handle(ctx);
+ sqlite3_aggregate_context(ctx, 2048);
+ sqlite3BeginBenignMalloc();
+ z = sqlite3_errmsg16(db);
+ sqlite3EndBenignMalloc();
+ sqlite3_result_text16(ctx, z, -1, SQLITE_TRANSIENT);
+}
+
+/*
** Routines for testing the sqlite3_get_auxdata() and sqlite3_set_auxdata()
** interface.
**
@@ -318,6 +337,10 @@ static int registerTestFunctions(sqlite3 *db){
sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
aFuncs[i].eTextRep, 0, aFuncs[i].xFunc, 0, 0);
}
+
+ sqlite3_create_function(db, "test_agg_errmsg16", 0, SQLITE_ANY, 0, 0,
+ test_agg_errmsg16_step, test_agg_errmsg16_final);
+
return SQLITE_OK;
}
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index f0c0e0674..9762e380c 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -13,7 +13,7 @@
** This file contains code use to implement APIs that are part of the
** VDBE.
**
-** $Id: vdbeapi.c,v 1.154 2009/03/19 07:58:31 danielk1977 Exp $
+** $Id: vdbeapi.c,v 1.155 2009/03/19 18:51:07 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@@ -204,12 +204,14 @@ int sqlite3_finalize(sqlite3_stmt *pStmt){
rc = SQLITE_OK;
}else{
Vdbe *v = (Vdbe*)pStmt;
+ sqlite3 *db = v->db;
#if SQLITE_THREADSAFE
sqlite3_mutex *mutex = v->db->mutex;
#endif
sqlite3_mutex_enter(mutex);
stmtLruRemove(v);
rc = sqlite3VdbeFinalize(v);
+ rc = sqlite3ApiExit(db, rc);
sqlite3_mutex_leave(mutex);
}
return rc;
@@ -234,6 +236,7 @@ int sqlite3_reset(sqlite3_stmt *pStmt){
stmtLruAdd(v);
sqlite3VdbeMakeReady(v, -1, 0, 0, 0);
assert( (rc & (v->db->errMask))==rc );
+ rc = sqlite3ApiExit(v->db, rc);
sqlite3_mutex_leave(v->db->mutex);
}
return rc;
diff --git a/src/vdbeblob.c b/src/vdbeblob.c
index a7caf2434..82844675b 100644
--- a/src/vdbeblob.c
+++ b/src/vdbeblob.c
@@ -12,7 +12,7 @@
**
** This file contains code used to implement incremental BLOB I/O.
**
-** $Id: vdbeblob.c,v 1.29 2009/03/05 03:48:07 shane Exp $
+** $Id: vdbeblob.c,v 1.30 2009/03/19 18:51:07 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -248,8 +248,8 @@ int sqlite3_blob_open(
blob_open_out:
zErr[sizeof(zErr)-1] = '\0';
- if( rc!=SQLITE_OK || db->mallocFailed ){
- sqlite3_finalize((sqlite3_stmt *)v);
+ if( v && (rc!=SQLITE_OK || db->mallocFailed) ){
+ sqlite3VdbeFinalize(v);
}
sqlite3Error(db, rc, (rc==SQLITE_OK?0:zErr));
rc = sqlite3ApiExit(db, rc);
diff --git a/src/vtab.c b/src/vtab.c
index 4bf678503..a5865d893 100644
--- a/src/vtab.c
+++ b/src/vtab.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to help implement virtual tables.
**
-** $Id: vtab.c,v 1.82 2009/03/16 13:19:36 danielk1977 Exp $
+** $Id: vtab.c,v 1.83 2009/03/19 18:51:07 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_VIRTUALTABLE
#include "sqliteInt.h"
@@ -571,7 +571,9 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
}
sParse.declareVtab = 0;
- sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);
+ if( sParse.pVdbe ){
+ sqlite3VdbeFinalize(sParse.pVdbe);
+ }
sqlite3DeleteTable(sParse.pNewTable);
sParse.pNewTable = 0;