Skip to content

Commit

Permalink
fix(Database): balance sufficiency checks not working
Browse files Browse the repository at this point in the history
Closes #114
  • Loading branch information
cooldogedev committed Nov 7, 2023
1 parent 5a64e99 commit be7c8be
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function onRun(mysqli $connection): void
}

// subtract the money from the source account
$sourceUpdateQuery = $connection->prepare("UPDATE " . $this->table . " SET amount = amount - ?, decimals = ? WHERE xuid = ? OR username = ? AND amount >= ? AND decimals >= ?");
$sourceUpdateQuery = $connection->prepare("UPDATE " . $this->table . " SET amount = amount - ?, decimals = ? WHERE (xuid = ? OR username = ?) AND amount >= ? AND decimals >= ?");
$sourceUpdateQuery->bind_param("iissii", $this->amount, $this->decimals, $this->xuid, $this->username, $this->amount, $this->decimals);
$sourceUpdateQuery->execute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function onRun(mysqli $connection): void

$updateQuery = match ($this->mode) {
UpdateMode::ADD => "UPDATE " . $this->table . " SET amount = amount + ?, decimals = decimals + ? WHERE xuid = ? OR username = ?",
UpdateMode::SUBTRACT => "UPDATE " . $this->table . " SET amount = amount - ?, decimals = decimals - ? WHERE xuid = ? OR username = ? AND amount >= ? AND decimals >= ?",
UpdateMode::SUBTRACT => "UPDATE " . $this->table . " SET amount = amount - ?, decimals = decimals - ? WHERE (xuid = ? OR username = ?) AND amount >= ? AND decimals >= ?",
UpdateMode::SET => "UPDATE " . $this->table . " SET amount = ?, decimals = ? WHERE xuid = ? OR username = ?",

default => throw new InvalidArgumentException("Invalid mode " . $this->mode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function onRun(SQLite3 $connection): void
}

// subtract the money from the source account
$sourceUpdateQuery = $connection->prepare("UPDATE " . $this->table . " SET amount = amount - ?, decimals = decimals - ? WHERE xuid = ? OR username = ? AND amount >= ? AND decimals >= ?");
$sourceUpdateQuery = $connection->prepare("UPDATE " . $this->table . " SET amount = amount - ?, decimals = decimals - ? WHERE (xuid = ? OR username = ?) AND amount >= ? AND decimals >= ?");
$sourceUpdateQuery->bindValue(1, $this->amount, SQLITE3_INTEGER);
$sourceUpdateQuery->bindValue(2, $this->decimals, SQLITE3_INTEGER);
$sourceUpdateQuery->bindValue(3, $this->xuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function onRun(SQLite3 $connection): void

$updateQuery = match ($this->mode) {
UpdateMode::ADD => "UPDATE " . $this->table . " SET amount = amount + ?, decimals = decimals + ? WHERE xuid = ? OR username = ?",
UpdateMode::SUBTRACT => "UPDATE " . $this->table . " SET amount = amount - ?, decimals = decimals - ? WHERE xuid = ? OR username = ? AND amount >= ? AND decimals >= ?",
UpdateMode::SUBTRACT => "UPDATE " . $this->table . " SET amount = amount - ?, decimals = decimals - ? WHERE (xuid = ? OR username = ?) AND amount >= ? AND decimals >= ?",
UpdateMode::SET => "UPDATE " . $this->table . " SET amount = ?, decimals = ? WHERE xuid = ? OR username = ?",

default => throw new InvalidArgumentException("Invalid mode " . $this->mode)
Expand Down

0 comments on commit be7c8be

Please sign in to comment.