From fe5d2f8f2394cbcbe7fc8fb6a25c1204a13b5991 Mon Sep 17 00:00:00 2001 From: shafran Date: Mon, 22 Jun 2026 22:59:50 +0300 Subject: [PATCH 1/8] Added sql code --- task.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/task.sql b/task.sql index 8adf22b..a28d7e8 100644 --- a/task.sql +++ b/task.sql @@ -3,9 +3,11 @@ USE ShopDB; -- Some data should be created outside the transaction (here) +insert into Orders (CustomerID, Date) values (1, '2024-06-01'); -- Start the transaction START TRANSACTION; -- And some data should be created inside the transaction +update Products set WarehouseAmount = WarehouseAmount - 1 where ID = 1; COMMIT; \ No newline at end of file From acb2d8a76585ed70ec85a4fee71d59e2d8bcc550 Mon Sep 17 00:00:00 2001 From: shafran Date: Mon, 22 Jun 2026 23:02:27 +0300 Subject: [PATCH 2/8] fix sql --- task.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/task.sql b/task.sql index a28d7e8..28849ff 100644 --- a/task.sql +++ b/task.sql @@ -8,6 +8,8 @@ insert into Orders (CustomerID, Date) values (1, '2024-06-01'); START TRANSACTION; -- And some data should be created inside the transaction + +insert into OrderItems (OrderID, ProductID, Quantity) values (1, 1, 1); update Products set WarehouseAmount = WarehouseAmount - 1 where ID = 1; COMMIT; \ No newline at end of file From 93bbd1d61e75b4a57c5b9b9dd94bf01593b53502 Mon Sep 17 00:00:00 2001 From: shafran Date: Mon, 22 Jun 2026 23:04:53 +0300 Subject: [PATCH 3/8] fix sql --- task.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task.sql b/task.sql index 28849ff..afc9098 100644 --- a/task.sql +++ b/task.sql @@ -9,7 +9,7 @@ START TRANSACTION; -- And some data should be created inside the transaction -insert into OrderItems (OrderID, ProductID, Quantity) values (1, 1, 1); +insert into OrderItems (OrderID, ProductID, Count) values (1, 1, 1); update Products set WarehouseAmount = WarehouseAmount - 1 where ID = 1; COMMIT; \ No newline at end of file From 8a0005024cdd87f9458c263e960c0b5bba72b8d0 Mon Sep 17 00:00:00 2001 From: shafran Date: Mon, 22 Jun 2026 23:11:05 +0300 Subject: [PATCH 4/8] captured OrderID --- task.sql | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/task.sql b/task.sql index afc9098..d1d6a46 100644 --- a/task.sql +++ b/task.sql @@ -4,12 +4,13 @@ USE ShopDB; -- Some data should be created outside the transaction (here) insert into Orders (CustomerID, Date) values (1, '2024-06-01'); --- Start the transaction -START TRANSACTION; +SET @orderId = LAST_INSERT_ID(); +-- Start the transaction +START TRANSACTION; --- And some data should be created inside the transaction +-- And some data should be created inside the transaction -insert into OrderItems (OrderID, ProductID, Count) values (1, 1, 1); +insert into OrderItems (OrderID, ProductID, Count) values (@orderId, 1, 1); update Products set WarehouseAmount = WarehouseAmount - 1 where ID = 1; COMMIT; \ No newline at end of file From 828164957c6dd078402d8d2e6abe8dacc926f7cd Mon Sep 17 00:00:00 2001 From: shafran Date: Mon, 22 Jun 2026 23:13:02 +0300 Subject: [PATCH 5/8] fix --- task.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/task.sql b/task.sql index d1d6a46..56fef5a 100644 --- a/task.sql +++ b/task.sql @@ -3,12 +3,13 @@ USE ShopDB; -- Some data should be created outside the transaction (here) -insert into Orders (CustomerID, Date) values (1, '2024-06-01'); + SET @orderId = LAST_INSERT_ID(); -- Start the transaction START TRANSACTION; -- And some data should be created inside the transaction +insert into Orders (CustomerID, Date) values (1, '2024-06-01'); insert into OrderItems (OrderID, ProductID, Count) values (@orderId, 1, 1); update Products set WarehouseAmount = WarehouseAmount - 1 where ID = 1; From 7a86e288d16439c0521abd72f76fc934720a51e9 Mon Sep 17 00:00:00 2001 From: shafran Date: Tue, 23 Jun 2026 07:27:56 +0300 Subject: [PATCH 6/8] fix task.sql --- task.sql | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/task.sql b/task.sql index 56fef5a..35f7518 100644 --- a/task.sql +++ b/task.sql @@ -3,14 +3,12 @@ USE ShopDB; -- Some data should be created outside the transaction (here) - +insert into Orders (CustomerID, Date) values (1, '2023-01-01'); SET @orderId = LAST_INSERT_ID(); -- Start the transaction START TRANSACTION; -- And some data should be created inside the transaction -insert into Orders (CustomerID, Date) values (1, '2024-06-01'); - insert into OrderItems (OrderID, ProductID, Count) values (@orderId, 1, 1); update Products set WarehouseAmount = WarehouseAmount - 1 where ID = 1; From 8ec8ea4241b1d1710c23dc2ed98b2eb0c88c917b Mon Sep 17 00:00:00 2001 From: shafran Date: Tue, 23 Jun 2026 07:29:16 +0300 Subject: [PATCH 7/8] fix --- task.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/task.sql b/task.sql index 35f7518..3df3054 100644 --- a/task.sql +++ b/task.sql @@ -3,12 +3,12 @@ USE ShopDB; -- Some data should be created outside the transaction (here) -insert into Orders (CustomerID, Date) values (1, '2023-01-01'); -SET @orderId = LAST_INSERT_ID(); -- Start the transaction START TRANSACTION; -- And some data should be created inside the transaction +insert into Orders (CustomerID, Date) values (1, '2023-01-01'); +SET @orderId = LAST_INSERT_ID(); insert into OrderItems (OrderID, ProductID, Count) values (@orderId, 1, 1); update Products set WarehouseAmount = WarehouseAmount - 1 where ID = 1; From beb22b41c08a78bf1c1601bcea1ca032b54c5c74 Mon Sep 17 00:00:00 2001 From: shafran Date: Tue, 23 Jun 2026 07:32:10 +0300 Subject: [PATCH 8/8] fix --- task.sql | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/task.sql b/task.sql index 3df3054..0094ad8 100644 --- a/task.sql +++ b/task.sql @@ -1,15 +1,16 @@ -- Use our database -USE ShopDB; +USE ShopDB; -- Some data should be created outside the transaction (here) +INSERT INTO Orders (CustomerID, Date) VALUES (1, '2023-01-01'); + +SET @orderId = LAST_INSERT_ID(); -- Start the transaction START TRANSACTION; -- And some data should be created inside the transaction -insert into Orders (CustomerID, Date) values (1, '2023-01-01'); -SET @orderId = LAST_INSERT_ID(); -insert into OrderItems (OrderID, ProductID, Count) values (@orderId, 1, 1); -update Products set WarehouseAmount = WarehouseAmount - 1 where ID = 1; +INSERT INTO OrderItems (OrderID, ProductID, Count) VALUES (@orderId, 1, 1); +UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 WHERE ID = 1; -COMMIT; \ No newline at end of file +COMMIT;