Skip to content

Fix/ecakubi enhance delete function #1017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions MysqliDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,8 @@ public function update($tableName, $tableData, $numRows = null)

/**
* Delete query. Call the "where" method first.
* For better error handling, we can make use of exceptions.
* This will allow the caller to handle the error in a more specific way, including providing more specific error messages.
*
* @param string $tableName The name of the database table to work with.
* @param int|array $numRows Array to define SQL limit in format Array ($offset, $count)
Expand All @@ -946,8 +948,9 @@ public function update($tableName, $tableData, $numRows = null)
public function delete($tableName, $numRows = null)
{
if ($this->isSubQuery) {
return;
throw new Exception('Delete function cannot be used within a subquery context.');
}


$table = self::$prefix . $tableName;

Expand All @@ -958,13 +961,17 @@ public function delete($tableName, $numRows = null)
}

$stmt = $this->_buildQuery($numRows);
$stmt->execute();

// Error handling
if (!$stmt->execute()) {
throw new Exception('Failed to execute delete operation: ' . $this->_stmtError);
}
$this->_stmtError = $stmt->error;
$this->_stmtErrno = $stmt->errno;
$this->count = $stmt->affected_rows;
$this->reset();

return ($stmt->affected_rows > -1); // -1 indicates that the query returned an error
return ($stmt->affected_rows >= 0); // anything greater than -1 indicates success
}

/**
Expand Down