Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
YujithIsura committed Oct 7, 2024
2 parents 919a8ec + 266cb5a commit 166aee4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions api/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -5560,6 +5560,8 @@ AND p.organization_id IN (
int|string? permanent_address_insert_id = null;
int|string? mailing_address_insert_id = null;

string message = "";

transaction {

int permanent_address_id = permanent_address?.id ?: 0;
Expand Down Expand Up @@ -5587,6 +5589,7 @@ AND p.organization_id IN (
if (permanent_address_res.affectedRowCount == sql:EXECUTION_FAILED) {
first_db_transaction_fail = true;
io:println("Unable to update permanent address record");
message = "Unable to update permanent address record";
}
}

Expand All @@ -5611,6 +5614,7 @@ AND p.organization_id IN (
if !(permanent_address_insert_id is int) {
first_db_transaction_fail = true;
io:println("Unable to insert permanent address");
message = "Unable to insert permanent address";
}
}
}
Expand Down Expand Up @@ -5641,6 +5645,7 @@ AND p.organization_id IN (
if (mailing_address_res.affectedRowCount == sql:EXECUTION_FAILED) {
second_db_transaction_fail = true;
io:println("Unable to update mailing address record");
message = "Unable to update mailing address record";
}
}

Expand All @@ -5665,6 +5670,7 @@ AND p.organization_id IN (
if !(mailing_address_insert_id is int) {
second_db_transaction_fail = true;
io:println("Unable to insert mailing address");
message = "Unable to insert mailing address";
}
}

Expand Down Expand Up @@ -5706,14 +5712,15 @@ AND p.organization_id IN (
if (update_person_res.affectedRowCount == sql:EXECUTION_FAILED) {
third_db_transaction_fail = true;
io:println("Unable to update person record");
message = "Unable to update person record";
}

if (first_db_transaction_fail ||
second_db_transaction_fail ||
third_db_transaction_fail) {

rollback;
return error("Transaction rollback");
return error(message);
} else {

// Commit the transaction if three updates are successful
Expand All @@ -5734,6 +5741,8 @@ AND p.organization_id IN (

int|string? mailing_address_insert_id = null;

string message = "";

transaction {

Person|error? personRaw = db_client->queryRow(
Expand All @@ -5746,6 +5755,7 @@ AND p.organization_id IN (
if (personRaw is Person) {
first_db_transaction_fail = true;
io:println("Person already exists.");
message = "Person already exists.";
}

if (mailing_address != null && mailing_address_city != null) {
Expand All @@ -5767,6 +5777,7 @@ AND p.organization_id IN (
if !(mailing_address_insert_id is int) {
second_db_transaction_fail = true;
io:println("Unable to insert mailing address");
message = "Unable to insert mailing address";
}
}

Expand Down Expand Up @@ -5822,14 +5833,15 @@ AND p.organization_id IN (
if !(insert_person_id is int) {
third_db_transaction_fail = true;
io:println("Unable to insert person");
message = "Unable to insert person";
}

if (first_db_transaction_fail ||
second_db_transaction_fail ||
third_db_transaction_fail) {

rollback;
return error("Transaction rollback");
return error(message);
} else {

// Commit the transaction if three updates are successful
Expand Down

0 comments on commit 166aee4

Please sign in to comment.