Re: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError?

2009-06-19 Thread Gerhard Häring
John Machin wrote:
> Hi Gerhard,
> [...]
> In http://www.sqlite.org/c3ref/prepare.html it says """When an error
> occurs, sqlite3_step() will return one of the detailed error codes or
> extended error codes. The legacy behavior was that sqlite3_step()
> would only return a generic SQLITE_ERROR result code and you would
> have to make a second call to sqlite3_reset() in order to find the
> underlying cause of the problem. With the "v2" prepare interfaces, the
> underlying reason for the error is returned immediately."""
> 
> Are you using sqlite3_prepare() or sqlite3_prepare_v2()?
> sqlite3_errcode() or sqlite3_extended_errcode()?

Because of compatibility with older SQLite versions, I'm using the old
API only.

I'll change this one day and then I'll be able to throw a lot of
compatibility code out of the window, too.

But I certainly won't go #ifdef hell and implement both.

-- Gerhard

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError?

2009-06-19 Thread John Machin
On Jun 19, 8:20 pm, Gerhard Häring  wrote:
> Gabriel Rossetti wrote:
> > Hello everyone,
>
> > I get an OperationalError with sqlite3 if I put the wrong column name,
> > but shouldn't that be a ProgrammingError instead? I read PEP 249 and it
> > says :
>
> > "        OperationalError
> >                    Exception raised for errors that are related to the
> >            database's operation and not necessarily under the control
> >            of the programmer, e.g. an unexpected disconnect occurs,
> >            the data source name is not found, a transaction could not
> >            be processed, a memory allocation error occurred during
> >            processing, etc.  It must be a subclass of DatabaseError.
> >                  ProgrammingError
> >                    Exception raised for programming errors, e.g. table not
> >            found or already exists, syntax error in the SQL
> >            statement, wrong number of parameters specified, etc.  It
> >            must be a subclass of DatabaseError.
> > "
>
> > and to me it sounds more like a programming error than an operational
> > error.
>
> I agree. But I can't help you there.
>
> See _pysqlite_seterror() 
> athttp://oss.itsystementwicklung.de/trac/pysqlite/browser/src/util.c
>
> What I do is map SQLite error codes to DB-API exceptions. And SQLite
> reports your error as generic SQLITE_ERROR, which is mapped to
> OperationalError.

Hi Gerhard,

In http://www.sqlite.org/c3ref/prepare.html it says """When an error
occurs, sqlite3_step() will return one of the detailed error codes or
extended error codes. The legacy behavior was that sqlite3_step()
would only return a generic SQLITE_ERROR result code and you would
have to make a second call to sqlite3_reset() in order to find the
underlying cause of the problem. With the "v2" prepare interfaces, the
underlying reason for the error is returned immediately."""

Are you using sqlite3_prepare() or sqlite3_prepare_v2()?
sqlite3_errcode() or sqlite3_extended_errcode()?

Cheers,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError?

2009-06-19 Thread Gerhard Häring
Gabriel Rossetti wrote:
> Hello everyone,
> 
> I get an OperationalError with sqlite3 if I put the wrong column name,
> but shouldn't that be a ProgrammingError instead? I read PEP 249 and it
> says :
> 
> "OperationalError
>Exception raised for errors that are related to the
>database's operation and not necessarily under the control
>of the programmer, e.g. an unexpected disconnect occurs,
>the data source name is not found, a transaction could not
>be processed, a memory allocation error occurred during
>processing, etc.  It must be a subclass of DatabaseError.
>  ProgrammingError
>Exception raised for programming errors, e.g. table not
>found or already exists, syntax error in the SQL
>statement, wrong number of parameters specified, etc.  It
>must be a subclass of DatabaseError.
> "
> 
> and to me it sounds more like a programming error than an operational
> error.

I agree. But I can't help you there.

See _pysqlite_seterror() at
http://oss.itsystementwicklung.de/trac/pysqlite/browser/src/util.c

What I do is map SQLite error codes to DB-API exceptions. And SQLite
reports your error as generic SQLITE_ERROR, which is mapped to
OperationalError.

-- Gerhard

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError?

2009-06-17 Thread John Machin

On 17/06/2009 5:15 PM, Gabriel Rossetti wrote:

John Machin wrote:

On Jun 17, 1:41 am, Gabriel Rossetti 
wrote:
 

Hello everyone,

I get an OperationalError with sqlite3 if I put the wrong column name,
but shouldn't that be a ProgrammingError instead? I read PEP 249 and it
says :



[snip]
 

and to me it sounds more like a programming error than an operational
error.



How about showing us the code you used and the exact error message and
traceback?


  

Well, the code isn't really relevant to the problem, but here is is :

import sqlite3

conn = sqlite3.connect("/tmp/test.db")
conn.execute("SELECT name, value FROM local_param")

for row in conn:
   print row

And I get :

Traceback (most recent call last):
 File "", line 1, in 
sqlite3.OperationalError: no such table: local_param


Which I think should be a ProgrammingError

If I fix the table name I but use a wrong column name I also get an 
OperationalError


OK OK alright already ... I agree with you ... report a bug.

Cheers,
John
--
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError?

2009-06-17 Thread Gabriel Rossetti

John Machin wrote:

On Jun 17, 1:41 am, Gabriel Rossetti 
wrote:
  

Hello everyone,

I get an OperationalError with sqlite3 if I put the wrong column name,
but shouldn't that be a ProgrammingError instead? I read PEP 249 and it
says :



[snip]
  

and to me it sounds more like a programming error than an operational
error.



How about showing us the code you used and the exact error message and
traceback?


  

Well, the code isn't really relevant to the problem, but here is is :

import sqlite3

conn = sqlite3.connect("/tmp/test.db")
conn.execute("SELECT name, value FROM local_param")

for row in conn:
   print row

And I get :

Traceback (most recent call last):
 File "", line 1, in 
sqlite3.OperationalError: no such table: local_param


Which I think should be a ProgrammingError

If I fix the table name I but use a wrong column name I also get an 
OperationalError



import sqlite3

conn = sqlite3.connect("/tmp/test.db")
conn.execute("SELECT name, valu FROM local_parameters")

for row in conn:
   print row

Traceback (most recent call last):
 File "", line 1, in 
sqlite3.OperationalError: no such column: valu

Which should also be a ProgrammingError as I see it and as my 
interpretation of the documention.


Gabriel

--
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError?

2009-06-16 Thread Jon Clements
On Jun 16, 4:41 pm, Gabriel Rossetti 
wrote:
> Hello everyone,
>
> I get an OperationalError with sqlite3 if I put the wrong column name,
> but shouldn't that be a ProgrammingError instead? I read PEP 249 and it
> says :
>
> "        OperationalError
>
>             Exception raised for errors that are related to the
>             database's operation and not necessarily under the control
>             of the programmer, e.g. an unexpected disconnect occurs,
>             the data source name is not found, a transaction could not
>             be processed, a memory allocation error occurred during
>             processing, etc.  It must be a subclass of DatabaseError.
>
>         ProgrammingError
>
>             Exception raised for programming errors, e.g. table not
>             found or already exists, syntax error in the SQL
>             statement, wrong number of parameters specified, etc.  It
>             must be a subclass of DatabaseError.
> "
>
> and to me it sounds more like a programming error than an operational
> error.
>
> Thank you,
> Gabriel

I would agree. With v2.5.2 of Python, I'm getting OperationalError
from sqlite3 and ProgrammingError from the psycopg2 (for postgres)
library. (Trying to create a table that already exists, trying to
'create tabel' and trying to select from non-existant tables)

I don't have time to go through code but looking at
http://www.sqlite.org/c3ref/c_abort.html, it would appear that there's
enough error results to distinguish between Operational and
Programming exceptions. Perhaps result != SQLITE_OK raises
OperationalError, or I'm looking at the wrong C spec for the version
in various Python versions etc... Or perhaps there's some chosen
rationale... or, perhaps, for an embedded engine, no one cares how it
failed, it just did...


Jon







-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError?

2009-06-16 Thread John Machin
On Jun 17, 1:41 am, Gabriel Rossetti 
wrote:
> Hello everyone,
>
> I get an OperationalError with sqlite3 if I put the wrong column name,
> but shouldn't that be a ProgrammingError instead? I read PEP 249 and it
> says :
>
[snip]
> and to me it sounds more like a programming error than an operational
> error.

How about showing us the code you used and the exact error message and
traceback?


-- 
http://mail.python.org/mailman/listinfo/python-list


sqlite3, OperationalError: no such column, shouldn't that ne a ProgrammingError?

2009-06-16 Thread Gabriel Rossetti

Hello everyone,

I get an OperationalError with sqlite3 if I put the wrong column name, 
but shouldn't that be a ProgrammingError instead? I read PEP 249 and it 
says :


"OperationalError

   Exception raised for errors that are related to the

   database's operation and not necessarily under the control
   of the programmer, e.g. an unexpected disconnect occurs,
   the data source name is not found, a transaction could not
   be processed, a memory allocation error occurred during
   processing, etc.  It must be a subclass of DatabaseError.
  
   ProgrammingError

   Exception raised for programming errors, e.g. table not

   found or already exists, syntax error in the SQL
   statement, wrong number of parameters specified, etc.  It
   must be a subclass of DatabaseError.
"

and to me it sounds more like a programming error than an operational 
error.


Thank you,
Gabriel
--
http://mail.python.org/mailman/listinfo/python-list