Skip to content

Commit

Permalink
Merge pull request #11309 from creative-commoners/pulls/5.2/clear-table
Browse files Browse the repository at this point in the history
FIX Truncate table to clear table
  • Loading branch information
GuySartorelli authored Jul 21, 2024
2 parents b6e347e + 539d464 commit 4693e3f
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions src/ORM/Connect/MySQLDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,6 @@ public function random()
*/
public function clearTable($table)
{
$this->query("DELETE FROM \"$table\"");

// Check if resetting the auto-increment is needed
$autoIncrement = $this->preparedQuery(
'SELECT "AUTO_INCREMENT" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?',
[ $this->getSelectedDatabase(), $table]
)->value();

if ($autoIncrement > 1) {
$this->query("ALTER TABLE \"$table\" AUTO_INCREMENT = 1");
}
$this->query("TRUNCATE TABLE \"$table\"");
}
}

0 comments on commit 4693e3f

Please sign in to comment.