我终于可以运行我的INSERT代码,并将行插入到MySQL / MariaDB数据库中,但是当我遍历以下函数时,即使只有很少的行(如4),也需要2分钟才能完成跑。有人可以在我的插入函数中告诉我我在做什么错吗?
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()