From 8a2010fee5a45d8da5e7824a9b208d7a64c428b7 Mon Sep 17 00:00:00 2001 From: Marco Weingart <82698121+intragart@users.noreply.github.com> Date: Thu, 5 Jan 2023 14:59:06 +0100 Subject: [PATCH] 2 add isolation level to transactions (#3) * disable autocommit, isolation level serializable * update to version 1.1 --- CHANGELOG | 8 ++++++++ version | 2 +- webapp/www/api/delete-purchase.php | 7 ++++++- webapp/www/api/insert-purchase.php | 7 ++++++- webapp/www/api/insert-user.php | 7 ++++++- webapp/www/api/update-purchase.php | 7 ++++++- webapp/www/api/update-user.php | 7 ++++++- 7 files changed, 39 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1498617..ede240c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,10 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1] - 2023-01-05 + +### Changed + +- Disabled autocommit when transactions are used +- Added isolation level serializable to all transactions + ## [1.0] - 2023-01-01 ### Added - Initial Release of the Project +[1.1]: https://github.com/intragart/Shared-Household-Expenses/compare/v1.0...v1.1 [1.0]: https://github.com/intragart/Shared-Household-Expenses/releases/tag/v1.0 diff --git a/version b/version index 472de5a..634650e 100644 --- a/version +++ b/version @@ -1 +1 @@ -v1.0 \ No newline at end of file +v1.1 \ No newline at end of file diff --git a/webapp/www/api/delete-purchase.php b/webapp/www/api/delete-purchase.php index 3945daf..ae59ab4 100644 --- a/webapp/www/api/delete-purchase.php +++ b/webapp/www/api/delete-purchase.php @@ -27,7 +27,12 @@ $db_settings = get_db_login("admin"); // connect to database and start a transaction - $db = new MySQLi($db_settings[0], $db_settings[1], $db_settings[2], $db_settings[3], $db_settings[4], $db_settings[5]); + $db = new MySQLi($db_settings[0], $db_settings[1], $db_settings[2], $db_settings[3], $db_settings[4], $db_settings[5]); + + // disable autocommit and set isolation level to serialize + $db->autocommit(false); + $db->query("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE"); + $db->begin_transaction(MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT); try { diff --git a/webapp/www/api/insert-purchase.php b/webapp/www/api/insert-purchase.php index 0ffd1c6..bd3a47a 100644 --- a/webapp/www/api/insert-purchase.php +++ b/webapp/www/api/insert-purchase.php @@ -94,7 +94,12 @@ function getRetailerID ($retailer_name) { $db_settings = get_db_login("admin"); // connect to database and start a transaction - $db = new MySQLi($db_settings[0], $db_settings[1], $db_settings[2], $db_settings[3], $db_settings[4], $db_settings[5]); + $db = new MySQLi($db_settings[0], $db_settings[1], $db_settings[2], $db_settings[3], $db_settings[4], $db_settings[5]); + + // disable autocommit and set isolation level to serialize + $db->autocommit(false); + $db->query("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE"); + $db->begin_transaction(MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT); try { diff --git a/webapp/www/api/insert-user.php b/webapp/www/api/insert-user.php index 1084228..413e8a9 100644 --- a/webapp/www/api/insert-user.php +++ b/webapp/www/api/insert-user.php @@ -43,7 +43,12 @@ $db_settings = get_db_login("admin"); // connect to database and start a transaction - $db = new MySQLi($db_settings[0], $db_settings[1], $db_settings[2], $db_settings[3], $db_settings[4], $db_settings[5]); + $db = new MySQLi($db_settings[0], $db_settings[1], $db_settings[2], $db_settings[3], $db_settings[4], $db_settings[5]); + + // disable autocommit and set isolation level to serialize + $db->autocommit(false); + $db->query("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE"); + $db->begin_transaction(MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT); try { diff --git a/webapp/www/api/update-purchase.php b/webapp/www/api/update-purchase.php index 0303ae6..76817b7 100644 --- a/webapp/www/api/update-purchase.php +++ b/webapp/www/api/update-purchase.php @@ -110,7 +110,12 @@ function getRetailerID ($retailer_name) { $db_settings = get_db_login("admin"); // connect to database and start a transaction - $db = new MySQLi($db_settings[0], $db_settings[1], $db_settings[2], $db_settings[3], $db_settings[4], $db_settings[5]); + $db = new MySQLi($db_settings[0], $db_settings[1], $db_settings[2], $db_settings[3], $db_settings[4], $db_settings[5]); + + // disable autocommit and set isolation level to serialize + $db->autocommit(false); + $db->query("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE"); + $db->begin_transaction(MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT); try { diff --git a/webapp/www/api/update-user.php b/webapp/www/api/update-user.php index 79a00bc..5ac45ea 100644 --- a/webapp/www/api/update-user.php +++ b/webapp/www/api/update-user.php @@ -46,7 +46,12 @@ $db_settings = get_db_login("admin"); // connect to database and start a transaction - $db = new MySQLi($db_settings[0], $db_settings[1], $db_settings[2], $db_settings[3], $db_settings[4], $db_settings[5]); + $db = new MySQLi($db_settings[0], $db_settings[1], $db_settings[2], $db_settings[3], $db_settings[4], $db_settings[5]); + + // disable autocommit and set isolation level to serialize + $db->autocommit(false); + $db->query("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE"); + $db->begin_transaction(MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT); try {