> -----Original Message-----
> From: Ran [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, May 23, 2006 10:08 AM
> To: sqlite-users@sqlite.org
> Subject: Re: [sqlite] "SQL logic error or missing database"
> 
> Oh! Did you run it with a parameter so:
> 
> ./bug 1
> 

No I missed that little gem.  After I passed in a parameter, it failed.

However, the failure is due to a SQLITE_SCHEMA error.  (I am using 3.3.5)

I modified the code slightly to catch the schema error:

  rc = sqlite3_prepare(db1,                // Database handle
                       "select * from bla",
                       -1,                 // Length of the statement
                       &pStmt3,            // OUT: Statement handle
                       0);                 // OUT: Pointer to unused portion

                                           // of the statement
  if (rc != SQLITE_OK) {
    printf("Failed to prepare statement: %s\n", sqlite3_errmsg(db1));
  }

  rc = sqlite3_step(pStmt3);
  if (rc) rc = sqlite3_reset(pStmt3);
  if (rc == SQLITE_SCHEMA) {
    rc = sqlite3_finalize(pStmt3);
    // Todo: re-prepare the statement according to the FAQ at
    // http://www.sqlite.org/faq.html#q17
  }


After sqlite3_step() fails, you should call sqlite3_reset() on the
statement.  This is what will give you the SQLITE_SCHEMA error, indicating
you need to re-prepare your statement.

Robert


Reply via email to