Tôi không thể chắc chắn liệu các id được tạo có liên tục hay không, nếu không, có cách nào khác để nhận chúng không?là nó có thể lấy tất cả các lastrowids sau khi thực hiện chèn trong mysqldb?
class BaseDao(object):
def __init__(self,pooldb):
self.pooldb = pooldb
def insertmany(self,sql,args):
conn,cur = None,None
try:
conn = pooldb.dedicated_connection()
cur = conn.cursor()
num=cur.executemany(sql,args)
if num <= 0:
raise Exception("insert failure with num equals zero")
lastrowid = int(cur.lastrowid)
return [range(lastrowid - num + 1,lastrowid+1)]
except:
conn.rollback()
traceback.print_exc()
raise Exception("error happened when insert sql=%s args=%s " % (sql,str(args)))
finally:
if cur:
cur.close()
if conn:
conn.close()
tốt, tôi sẽ không hy vọng làm điều gì tốt đẹp giải quyết nó trừ khi thực hiện theo trình tự, giống như những gì bạn nói – bigwesthorse