Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Classe « connection »

Méthode MySQLdb.connection.insert_id

Signature de la méthode insert_id

Description

insert_id.__doc__

Returns the ID generated for an AUTO_INCREMENT column by the previous
query. Use this function after you have performed an INSERT query into a
table that contains an AUTO_INCREMENT field.

Note that this returns 0 if the previous query does not
generate an AUTO_INCREMENT value. If you need to save the value for
later, be sure to call this immediately after the query
that generates the value.

The ID is updated after INSERT and UPDATE statements that generate
an AUTO_INCREMENT value or that set a column value to
LAST_INSERT_ID(expr). See section 6.3.5.2 Miscellaneous Functions
in the MySQL documentation.

Also note that the value of the SQL LAST_INSERT_ID() function always
contains the most recently generated AUTO_INCREMENT value, and is not
reset between queries because the value of that function is maintained
in the server.