transactions

This commit is contained in:
Shish 2020-10-27 22:03:56 +00:00
parent a4ff796b35
commit 81fe37de50
2 changed files with 8 additions and 4 deletions

View File

@ -281,14 +281,18 @@ function create_tables(Database $db)
$db->execute("CREATE INDEX images_tags_tag_id_idx ON image_tags(tag_id)", []); $db->execute("CREATE INDEX images_tags_tag_id_idx ON image_tags(tag_id)", []);
$db->execute("INSERT INTO config(name, value) VALUES('db_version', 11)"); $db->execute("INSERT INTO config(name, value) VALUES('db_version', 11)");
$db->commit();
// mysql auto-commits when creating a table, so the transaction
// is closed; other databases need to commit
if($db->is_transaction_open()) {
$db->commit();
}
} catch (PDOException $e) { } catch (PDOException $e) {
throw new InstallerException( throw new InstallerException(
"PDO Error:", "PDO Error:",
"<p>An error occurred while trying to create the database tables necessary for Shimmie.</p> "<p>An error occurred while trying to create the database tables necessary for Shimmie.</p>
<p>Please check and ensure that the database configuration options are all correct.</p> <p>Please check and ensure that the database configuration options are all correct.</p>
<p>{$e->getMessage()}</p> <p>{$e->getMessage()}</p>
<!-- {$e->getTraceAsString()} -->
", ",
3 3
); );

View File

@ -83,7 +83,7 @@ try {
$page->display(); $page->display();
} }
if ($database->transaction===true) { if ($database->is_transaction_open()) {
$database->commit(); $database->commit();
} }
@ -92,7 +92,7 @@ try {
fastcgi_finish_request(); fastcgi_finish_request();
} }
} catch (Exception $e) { } catch (Exception $e) {
if ($database && $database->transaction===true) { if ($database && $database->is_transaction_open()) {
$database->rollback(); $database->rollback();
} }
_fatal_error($e); _fatal_error($e);