← Back to team overview

agesys-dev team mailing list archive

Re: [Bug 718860] Re: Call to fetchone after LAST_INSERT_ID() does not clear cursor

 

Aaron,

I apologize if I don't quite understand, but if "SELECT LAST_INSERT_ID()"
returns a single row, then cursor.fetchone() should return that row, which
it does. However a subsequent insert and call to "SELECT LAST_INSERT_ID()"
should return a single row, and a cursor.fetchone() should return this row,
but it does not. It seems that cursor.fetchone() should not have to be
called twice on a query which returns a single row.

Here is a more simplified example:

>>> cursor = conn.cursor()
>>> cursor.execute("SELECT VERSION()")
>>> print cursor.fetchone()
(u'5.0.77',)
>>> cursor.execute("SELECT VERSION()")
>>> print cursor.fetchone()
None

I don't see anything in the spec that would specify this behavior.

On Mon, Feb 14, 2011 at 11:38 AM, Aaron Gallagher <_@xxxxxxxxx> wrote:

> This is not a bug. Read the DB-API spec:
> http://www.python.org/dev/peps/pep-0249/
>
>  .fetchone()
>
>            Fetch the next row of a query result set, returning a
>            single sequence, or None when no more data is
>            available.
>
> ** Changed in: oursql
>       Status: New => Invalid
>
> --
> You received this bug notification because you are a direct subscriber
> of the bug.
> https://bugs.launchpad.net/bugs/718860
>
> Title:
>  Call to fetchone after LAST_INSERT_ID() does not clear cursor
>
> Status in oursql:
>   Invalid
>
> Bug description:
>  Client: mysql  Ver 14.12 Distrib 5.0.77, for redhat-linux-gnu (i686) using
> readline 5.1
>  Server: Server version: 5.0.77 Source distribution
>  Python 2.7
>  oursql-0.9.2-py2.7-linux-i686
>
>  When calling LAST_INSERT_ID() cursor.fetchone() must be called twice,
>  or else a new call to cursor.fetchone() will return None:
>
>  >>> cursor.execute("INSERT INTO users (username) VALUES ('test')")
>  >>> cursor.execute("SELECT LAST_INSERT_ID()")
>  >>> print cursor.fetchone()
>  {'LAST_INSERT_ID()': 7L}
>  >>> cursor.execute("INSERT INTO users (username) VALUES ('test2')")
>  >>> cursor.execute("SELECT LAST_INSERT_ID()")
>  >>> print cursor.fetchone()
>  Expected:
>  {'LAST_INSERT_ID()': 8L}
>  Actual:
>  None
>
> To unsubscribe from this bug, go to:
> https://bugs.launchpad.net/oursql/+bug/718860/+subscribe
>


-- 
Isaiah Jensen
OST Communications
Phone Systems Specialist
2515 Lincoya Drive
Murfreesboro TN, 37127

-- 
You received this bug notification because you are a member of Agesys
Team, which is subscribed to oursql.
https://bugs.launchpad.net/bugs/718860

Title:
  Call to fetchone after LAST_INSERT_ID() does not clear cursor

Status in oursql:
  Invalid

Bug description:
  Client: mysql  Ver 14.12 Distrib 5.0.77, for redhat-linux-gnu (i686) using readline 5.1
  Server: Server version: 5.0.77 Source distribution
  Python 2.7
  oursql-0.9.2-py2.7-linux-i686

  When calling LAST_INSERT_ID() cursor.fetchone() must be called twice,
  or else a new call to cursor.fetchone() will return None:

  >>> cursor.execute("INSERT INTO users (username) VALUES ('test')")
  >>> cursor.execute("SELECT LAST_INSERT_ID()")
  >>> print cursor.fetchone()
  {'LAST_INSERT_ID()': 7L}
  >>> cursor.execute("INSERT INTO users (username) VALUES ('test2')")
  >>> cursor.execute("SELECT LAST_INSERT_ID()")
  >>> print cursor.fetchone()
  Expected:
  {'LAST_INSERT_ID()': 8L}
  Actual:
  None





Follow ups

References