Re: [sqlite] Error reporting problem

2007-03-27 Thread Martin Jenkins

Dan Kennedy wrote:


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.


Thanks for clearing that up Dan. I changed Vivien's test code to show 
this - rc is set to 19 and the sqlite3_errXXX functions do return the 
"wrong/right" thing before/after the sqlite3_reset. I still think the 
docs imply something else though, but it's been one of those weeks. ;)


Martin

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



Re: [sqlite] Error reporting problem

2007-03-26 Thread Dan Kennedy
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]
-



Re: [sqlite] Error reporting problem

2007-03-26 Thread Martin Jenkins

Vivien Malerba wrote:

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...


Hmm. I built this on Debian (had to tweak the Makefile very very 
slightly) and got the same results as you. From my reading of:


"""Goofy Interface Alert:  [...] The problem has been fixed with the 
"v2" interface. If you prepare all of your SQL statements using either 
sqlite3_prepare_v2() or sqlite3_prepare16_v2() instead of the legacy 
sqlite3_prepare() and sqlite3_prepare16(), then the more specific 
result-codes are returned directly by sqlite3_step(). The use of the 
"v2" interface is recommended."""


you should NOT have to call sqlite3_reset() after an error. Perhaps 
someone with experience of the C API could comment?


Martin

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



Re: [sqlite] Error reporting problem

2007-03-26 Thread Vivien Malerba

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...

Thanks,

Vivien


test_case.tgz
Description: GNU Zip compressed data
-
To unsubscribe, send email to [EMAIL PROTECTED]
-

Re: [sqlite] Error reporting problem

2007-03-26 Thread Martin Jenkins

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.


Martin

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



[sqlite] Error reporting problem

2007-03-26 Thread Vivien Malerba

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()?

Thanks,

Vivien

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