Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

python sql last insertend

>>> import MySQLdb
>>> connection = MySQLdb.connect(user='root')
>>> cursor = connection.cursor()
>>> cursor.execute('INSERT INTO sometable VALUES (...)')
1L
>>> connection.insert_id()
3L
>>> cursor.lastrowid
3L
>>> cursor.execute('SELECT last_insert_id()')
1L
>>> cursor.fetchone()
(3L,)
>>> cursor.execute('select @@identity')
1L
>>> cursor.fetchone()
(3L,)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #sql #insertend
ADD COMMENT
Topic
Name
2+2 =