将行从数据库插入到另一个数据库

ggazkfy8  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(604)

我正在尝试使用pymysql将一行从一个数据库服务器插入到另一个不同环境中的数据库服务器

prod_conn = pymysql.connect(
        prod_common_db_endpoint,
        prod_user,
        prod_password,
        prod_common_table_name)

prod_cursor = prod_conn.cursor()

prod_ConnectFirm_table = prod_cursor.execute("select * from Common.ConnectFirm where FirmId = " + prod_source_firm + ";")
for row in prod_ConnectFirm_table:
    ConnectFirmId = int(row[1])
    ConnectFirmName = (row[2])
    FirmId = int(row[3])
    isDeleted = (row[4])
    tags = (row[5])
    createdDate = (row[6])
    createdBy = int(row[7])
    editedDate = (row[8])
    editedBy = int(row[9])

conn = pymysql.connect(target_common_db_endpoint, user, password, common_schema_name)

cursor = conn.cursor()

cursor.execute("INSERT INTO Common.ConnectFirm(ConnectFirmId, ConnectFirmName, editedDate) VALUES(" + ConnectFirmId + ", " + ConnectFirmName + ", " + editedDate + ", ")")
conn.commit()
print("error inserting")

它没有给我这个错误

Traceback (most recent call last):
  File "sql_test_3_d.py", line 109, in <module>
    for row in prod_orionConnectFirm_table:
TypeError: 'int' object is not iterable
pkbketx9

pkbketx91#

prod\u connectfirm\u表将包含执行状态,这是一个您无法覆盖的整数值

prod_ConnectFirm_table = prod_cursor.execute("select * from Common.ConnectFirm where FirmId = " + prod_source_firm + ";")

您需要从游标获取数据:

data = prod_cursor.fetchall()

“data”将以元组的形式包含查询结果,您可以对其进行解析。

相关问题