On Mon, 2007-03-26 at 17:08 +0200, Vivien Malerba wrote:
> On 3/26/07, Martin Jenkins <[EMAIL PROTECTED]> wrote:
> > Vivien Malerba wrote:
> > > Hi!
> > >
> > > I've got an error reporting problem when trying to insert a row which
> > > breaks a UNIQUE constraint in a table in a C program, I get the
> > > following error with sqlite3_errmsg():
> > > "SQL logic error or missing database"
> > >
> > > If I fire the sqlite3 program and run the same SQL query, I get the
> > > following error:
> > > "SQL error: column name is not unique"
> > > which is much more obvious to understand.
> > >
> > > Any idea how I could get that error message calling sqlite3_errmsg()?
> >
> > The pysqlite wrapper has a bug which reports the same error message if
> > you try to nest transactions. I fixed the wrapper (locally) by adding an
> > sqlite_reset(). I think there's a new API (sqlite_prepare_v2()?) which
> > has the same effect. If you can't search (say) gmane then post a tiny
> > code snippet and someone who uses the C API more than I do will spot the
> > problem straight away.
> 
> Here is a sample test case, just uncompress, run "make" and "./test".
> Here is what I get using SQLite 3.3.13 (On Linux):
> SQL error (step): SQL logic error or missing database
> SQL error (step): column name is not unique
> 
> It shows that calling sqlite3_reset() seems to be required (contrary
> to what the doc says), or maybe I got something wrong...

Even using the prepare_v2() interface, the database handle error-code
and error-message (the stuff returned by sqlite3_errcode() and 
sqlite3_errmsg() respectively) are not populated by sqlite3_step(). 
After sqlite3_step() reports an error you need to call either
sqlite3_reset() or sqlite3_finalize() to copy the error-code and
message from the statement to the database handle.

The change the prepare_v2() API makes is that in your example 
sqlite3_step() returns SQLITE_CONSTRAINT when it hits the constraint.
Using sqlite3_prepare() it would have returned the generic SQLITE_ERROR.

Dan.



-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to