mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #8437 from sminnee/faster-cleartable-ss4
FIX: Use DELETE FROM instead of TRUNCATE for clearTable
This commit is contained in:
commit
26f2044533
@ -523,4 +523,24 @@ class MySQLDatabase extends Database
|
|||||||
{
|
{
|
||||||
return 'RAND()';
|
return 'RAND()';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear all data in a given table
|
||||||
|
*
|
||||||
|
* @param string $table Name of table
|
||||||
|
*/
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user