[APSW] SELECT COUNT(*) not succesfull?
Gerhard Häring
gh at ghaering.de
Thu Oct 23 09:18:18 EDT 2008
Gilles Ganault wrote:
> On Thu, 23 Oct 2008 00:24:01 -0200, "Gabriel Genellina"
> <gagsl-py2 at yahoo.com.ar> wrote:
>> In case you didn't notice, B.D. already provided the answer you're after -
>> reread his 3rd paragraph from the end.
>
> Yes, but it doesn't work with this wrapper (APSW version 3.5.9-r1):
>
>>> The recommended way is to pass the arguments to cursor.execute, ie:
>
> I'm getting an error when doing it this way:
>
> =======
> isbn = "123"
> sql = "SELECT COUNT(*) FROM books WHERE isbn='%s'"
>
> #Incorrect number of bindings supplied. The current statement uses 0
> and there are 1 supplied. Current offset is 0
> cursor.execute(sql, (isbn,))
> =======
>
> I don't know enough about Python and this wrapper to tell why it
> triggers an error.
>
>>> you want:
>>> row = cursor.fetchone()
>>> count = row[0]
>>> if not count:
>
> This wrapper doesn't seem to support fetchone():
>
> =====
> #AttributeError: 'apsw.Cursor' object has no attribute 'fetchone'
> row = cursor.fetchone() [...]
Directly calling next() should probably do the trick with APSW. Its
cursors support the iterator interface and iterators are implemented by
providing __iter__() and next() methods.
-- Gerhard
More information about the Python-list
mailing list