Work on native gui: views and database model

This commit is contained in:
2026-09-09 12:20:57 +02:00
parent 66f017567e
commit b21a6beffd
35 changed files with 5649 additions and 3266 deletions
+27
View File
@@ -20,6 +20,7 @@ class Database():
except MySQLdb.Error as e:
self.error = e
return False
self.conn.autocommit(False)
self.cur = self.conn.cursor()
self.dcur = self.conn.cursor(MySQLdb.cursors.DictCursor)
return True
@@ -54,3 +55,29 @@ class Database():
text = self.error.args[1]
self.error = None
return(code, text)
def execute_write(self, sql, values=(), expected_rows=None):
"""
Execute an INSERT, UPDATE, or DELETE statement.
expected_rows:
None = do not check the number of affected rows
1 = expect exactly one affected row
0 = expect no affected rows
"""
try:
self.cur.execute(sql, values)
except MySQLdb.Error as e:
self.rollback()
self.error = e
return False
if (expected_rows is not None and self.cur.rowcount != expected_rows):
self.rollback()
self.error = RuntimeError(
"Expected {} affected rows, got {}".format(
expected_rows,
self.cur.rowcount
)
)
return False
self.error = None
return True