class MySQL(object): def __init__(self): self.dbpool = adbapi.ConnectionPool( 'MySQLdb', db='dummy', user='root', passwd='', host = 'localhost', cp_reconnect = True, cursorclass=MySQLdb.cursors.DictCursor, charset='utf8', use_unicode=True ) def process(self, item): query = self.dbpool.runInteraction(self.conditionalInsert, item).addErrback(self.handle_error) return item def conditionalInsert(self, tx, item): tx.execute("INSERT INTO User (user_name) VALUES (%s)",(name)) tx.execute("SELECT LAST_INSERT_ID()") lastID = getID(tx.fetchone())
The last identifier of the second row below corresponds to the insertion in the first row? or can it be from any of the runInteraction threads?
tx.execute("INSERT INTO User (user_name) VALUES (%s)",(name)) tx.execute("SELECT LAST_INSERT_ID()")
source share