﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
1590	mysql and postgresql backends get_last_insert_id() do extra queries	anonymous	Adrian Holovaty	"PEP-249 specifies:
{{{
    Cursor Attribute .lastrowid

        This read-only attribute provides the rowid of the last
        modified row (most databases return a rowid only when a single
        INSERT operation is performed). If the operation does not set
        a rowid or if the database does not support rowids, this
        attribute should be set to None.

        The semantics of .lastrowid are undefined in case the last
        executed statement modified more than one row, e.g. when
        using INSERT with .executemany().

        Warning Message: ""DB-API extension cursor.lastrowid used""
}}}
While this is an extension, it is supported by both MySQLdb and psycopg (including version 1). Therefore, it is only necessary in base.py to do this:
{{{
def get_last_insert_id(cursor, table_name, pk_name):
    return cursor.lastrowid
}}}
The sqlite3 backend already does this, in fact.

I've been testing the above change with MySQLdb for awhile and it works fine. I have not tried it with pyscopg1, but judging from the source code, it should work: http://initd.org/tracker/psycopg/browser/psycopg1/trunk/cursor.c (look for lastrowid defined on the cursor object)."	enhancement	closed	Core (Other)	magic-removal	minor	fixed			Unreviewed	0	0	0	0	0	0
