> -----Original Message-----
> From: Ran [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, May 23, 2006 6:38 AM
> To: sqlite-users
> Subject: [sqlite] "SQL logic error or missing database"
>
[snip]
> Here is the script:
[snip]
> rc = sqlite3_prepare(db1, // Database handle
> "create table bla(a int,b int)",
> -1, // Length of the statement
> &pStmt1, // OUT: Statement handle
> 0); // OUT: Pointer to
> unused portion
> // of the statement
>
> rc = sqlite3_step(pStmt1);
[snip]
> rc = sqlite3_prepare(db2, // Database handle
> "create table foo(c int,d int)",
> -1, // Length of the
> statement
> &pStmt2, // OUT: Statement handle
> 0); // OUT: Pointer to unused
> portion
> // of the statement
>
> rc = sqlite3_step(pStmt2);
[snip]
> // delete from table bla using the first connection.
> sqlite3_exec(db1, "begin", 0, 0, 0);
> rc = sqlite3_prepare(db1, // Database handle
> "delete from bla",
> -1, // Length of the statement
> &pStmt3, // OUT: Statement handle
> 0); // OUT: Pointer to
> unused portion
> // of the statement
>
> rc = sqlite3_step(pStmt3);
[snip]
I strongly suspect the bug is related to you not checking the return code
from sqlite3_prepare(). I believe during the course of execution one of
those prepares is returning a SQLITE_SCHEMA error, at which point you need
to retry the statement. Something like this works:
// Try 3 times to prepare the statement
int n = 0;
while (n < 3) {
rc = sqlite3_prepare(db1,
"delete from bla",
-1,
&pStmt3,
0);
if (rc != SQLITE_SCHEMA) break;
n ++;
}
if (rc) {
// blah blah
exit(1);
}
//
Robert