我一直收到错误“AttributeError:'Cursor'object has no attribute'fetchAll'”。我的rowCount
是451,所有查询都正常。在
我已经研究过这个问题,大多数错误都涉及到对cursor.execute()
的返回值调用fetchAll()
,但这不是我要做的。在
#initialize cursors
presswiseCursor = presswiseConnection.cursor()
localCursor = localConnection.cursor()
#products
#initialize table
localCursor.execute("DROP TABLE IF EXISTS products;")
localCursor.execute("CREATE TABLE products (id INT NOT NULL, description VARCHAR(255));")
#get data from presswise
rowCount = presswiseCursor.execute("SELECT DISTINCT id, description FROM list_product;")
print(rowCount)
rows = presswiseCursor.fetchAll()
#add data to local
for row in rows:
localCursor.execute(f'INSERT INTO products (id, description) VALUES({row[0]}{row[1]})')
我希望遍历查询的结果,并在以前使用过这种精确的技术。我的代码怎么了?在
您是否尝试过不将
cursor.execute()
归因于一个变量,然后调用cursor.fetchAll()
?在然后在
fetchAll()
之后执行len(rows)
来获得行数另请注意,为什么在sql语句中使用三重引号?在
在python3中使用fetchall()而不是fetchall()。 谢谢您。在
相关问题 更多 >
编程相关推荐