我无法确定生成的 id 是否是连续的,如果不是,还有其他方法可以获取它们吗?
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()