我终于可以运行insert代码并将行插入到mysql/mariadb数据库中,但是当我循环下面的函数时,即使只有很少的行(比如4行),运行也需要2分钟。有人能告诉我在insert函数中我做错了什么吗? def ProcessMsg(msg_id, reg_num, sent_date, subject): # Insert into Database row_data = {} row_data['msg_id'] = msg_id row_data['reg_num'] = reg_num row_data['sent_date'] = sent_date row_data['subject'] = subject metadata = MetaData(bind=engine) msg_in = Table('msg_inbound', metadata, autoload=True) conn = engine.connect() Session = sessionmaker(bind=conn) session = Session() i = insert(msg_in) i = i.values({"msg_id": row_data['msg_id'], "reg_num": row_data['reg_num'], "sent_date": row_data['sent_date'], "subject": row_data['subject'] }) session.execute(i) session.commit() session.close()
暂无答案!
目前还没有任何答案,快来回答吧!