Having worked with other programming/scripting languages, I am completely baffled by Python's mysql interface (I am a bit new to Python) I am unable to commit my changes. I have stripped the code to the bare minimum:
#!/usr/bin/python
import mysql.connector as mariadb
mariadb_connection = mariadb.connect(
user='testdb',
password='testdb',
database='testdb',
host='127.0.0.1',
autocommit=True
)
mariadb_connection.autocommit=True
cursor = mariadb_connection.cursor(buffered=True)
cursor.execute( "UPDATE testdb SET descr='konijn' WHERE number=14549")
mariadb_connection.commit()
mariadb_connection.close()
I would have expected that the autocommit would do the trick, but it doesn't. Also, the mariadb_connection.commit()
does nothing to commit the changes.
The database is (for as much as relevant):
number INTEGER,
type VARCHAR(255),
file VARCHAR(255),
year INTEGER,
month INTEGER,
descr VARCHAR(4096)
I am able to commit changes using the same credentials using TCL/Tk, so it should not be a permission problem.
What am I doing wrong?
number
is of type int in the database?print(cursor.execute("""SELECT * FROM testdb WHERE number=14549""").fetchall())
?select number,year,month,descr from testdb WHERE number=14549
I get14549 2009 7 tremolat
. When I do the update, the pythonscript will actually see the table as being updated. So aselect
after theupdate
will show an updated table. But when the script ends, everything is rolled-back.