pymysql cursor.execute()或cursor.rowcount为执行多个插入查询返回1

ghhkc1vu  于 2021-06-25  发布在  Mysql
关注(0)|答案(0)|浏览(302)

使用受影响的行数 cursor.execute() 执行多个插入查询时返回1。 cursor.rowcount 对于多个插入查询执行,也返回1。我已经插入了4行。但它返回1。我已经定好了 client_flag= CLIENT.MULTI_STATEMENTS|CLIENT.MULTI_RESULTS .

connection = pymysql.connect(host, username, password, database, port, client_flag= CLIENT.MULTI_STATEMENTS|CLIENT.MULTI_RESULTS)
insert_statement= "INSERT INTO demo VALUES ('$SYS/publish/messages/received',0,1515580086025);
INSERT INTO demo VALUES ('$SYS/publish/messages/sent',0,1515580086025);
INSERT INTO demo VALUES ('$SYS/publish/messages/sent',3,1515580094997);
INSERT INTO demo VALUES ('$SYS/publish/messages/sent',4,1515580105983);"
cursor = connection.cursor()
row_count = cursor.execute(insert_statement)
print (row_count) -> #always prints 1 (but actually 4 rows are inserted as per insert_statement) 

print (cursor.rowcount) -> #always prints 1 (but actually 4 rows are inserted as per insert_statement)
connection.commit()

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题