Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions python/grass/temporal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,8 +1375,12 @@ def connect(self, dbstring: str | None = None) -> None:
self.connection.isolation_level = None
self.connection.text_factory = str
self.cursor = self.connection.cursor()
self.cursor.execute("PRAGMA synchronous = OFF")
self.cursor.execute("PRAGMA journal_mode = MEMORY")
# busy_timeout is set to 30 seconds to avoid "database is locked" errors
self.cursor.executescript(
"PRAGMA synchronous = OFF;"
"PRAGMA journal_mode = MEMORY;"
"PRAGMA busy_timeout = 30000;"
)
elif self.dbmi.__name__ == "psycopg2":
self.connection = self.dbmi.connect(dbstring)
# self.connection.set_isolation_level(dbmi.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
Expand Down Expand Up @@ -1570,13 +1574,11 @@ def execute(self, statement, args=None):
else:
self.cursor.execute(statement)
except db_errors:
if connected:
self.close()
self.msgr.error(_("Unable to execute :\n %(sql)s") % {"sql": statement})
raise

if connected:
self.close()
finally:
if connected:
self.close()

def fetchone(self):
if self.connected:
Expand All @@ -1601,27 +1603,22 @@ def execute_transaction(self, statement, mapset=None):
self.connect()
connected = True

sql_script = ""
sql_script += "BEGIN TRANSACTION;\n"
sql_script += statement
sql_script += "END TRANSACTION;"
sql_script = f"BEGIN TRANSACTION;\n{statement};\nEND TRANSACTION;"

try:
if self.dbmi.__name__ == "sqlite3":
self.cursor.executescript(statement)
self.cursor.executescript(sql_script)
else:
self.cursor.execute(statement)
self.connection.commit()
except db_errors:
if connected:
self.close()
self.msgr.error(
_("Unable to execute transaction:\n %(sql)s") % {"sql": statement}
)
raise

if connected:
self.close()
finally:
if connected:
self.close()


###############################################################################
Expand Down
Loading