3
I just started with python and I’m trying that:
import mysql.connector
mydb = mysql.connector.connect(
infos..
)
cursor = mydb.cursor(buffered=True)
cursor2 = mydb.cursor()
query = ("SELECT * FROM table LIMIT 5")
cursor.execute(query)
for row in cursor.fetchall():
print(row[1])
var1 = "blabla"
var2 = "blblbl"
cursor2.execute("UPDATE table SET col1 = (%s), col2= (%s) WHERE col3= (%s)", (var1, var2, row[2]))
mydb.commit()
cursor.close()
cursor2.close()
But I keep getting the bug:
mysql.connector.errors.Interfaceerror: 2013: Lost Connection to Mysql server During query
I researched and thought that using "buffered=True" would solve the problem, but it didn’t work. I also tried to create a pool, but when I run at the point of reaching the cursor2 error appears:
Referenceerror: Weakly-referenced Object no longer exists
Can’t two cursor be used for the same connection? That’s it?
I don’t know the specific lib, so I don’t know if the term "cursor" is native to SQL or some peculiarity of lib. I suggest a peek if you have a direct query function to use in updates (actually, in terms of mysql, you wouldn’t even need a cursor for select, just fetch).
– Bacco
I tried looking into this and found this clarification about cursors in python: https://stackoverflow.com/a/39438325/3383534
– ziad.ali