You right... i had even been following a similar thread and didn't realize that it was my problem too.. thanks a ton!
--preston

----- Original Message ----- From: "Robert Simpson" <[EMAIL PROTECTED]>
To: <sqlite-users@sqlite.org>
Sent: Friday, October 14, 2005 2:55 PM
Subject: Re: [sqlite] drop statement returns SQLITE_ERROR


----- Original Message ----- From: "Preston" <[EMAIL PROTECTED]>
To: <sqlite-users@sqlite.org>
Sent: Friday, October 14, 2005 1:21 PM
Subject: Re: [sqlite] drop statement returns SQLITE_ERROR


Here is the full source to a stripped down version of the app i am truing to
debug. It exhibits the problem. to recreat this problem simply create a
target.bin and add a table t1, then create a database update.bin with the
table
adhoc_sql(adhocsqlid int, sqltext text) and insert the values (1, 'drop
table t1;')

I'm sure it is something in my code... i'm just not sure what. I really do
appreciate the time that anybody puts into this.. i know it isn't a quick
question.
Thanks again
--Preston

-------------------------
#include "sqlite/sqlite3.h"
#include <stdio.h>
#include <string.h>

bool RunAdHoc(sqlite3** ppDb, char* SqlStatementList)
{
int rc;
sqlite3_stmt *pListStmt;
sqlite3_stmt *pUpdateStmt;
sqlite3* pDb = *ppDb;
bool ok = true;

sqlite3_prepare(pDb, SqlStatementList, -1, &pListStmt, 0);
rc = sqlite3_step(pListStmt);
while( rc == SQLITE_ROW && ok)
{
 sqlite3_prepare(pDb, (const char*)sqlite3_column_text(pListStmt, 0), -1,
&pUpdateStmt, 0);
 rc = sqlite3_step(pUpdateStmt);
 ok = rc == SQLITE_OK || rc == SQLITE_ROW || rc == SQLITE_DONE;
 sqlite3_finalize(pUpdateStmt);

You have a prepared statement stepping in a loop (locking the database for read-only access), and inside that loop you execute a statement that changes the database schema, thereby invalidating the outer prepared statement. You need to read in all the statements first into an array, finalize, then loop through the array and execute all the statements. Either that, or you need to open a new connection to execute the inner statements on.

Robert



Reply via email to