mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #8435 from sminnee/faster-cleartable-ss3
FIX: Use DELETE FROM instead of TRUNCATE for clearTable
This commit is contained in:
commit
8061e72bb4
@ -362,4 +362,23 @@ class MySQLDatabase extends SS_Database {
|
||||
public function random() {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ class DataObjectTest extends SapphireTest {
|
||||
'DataObjectTest_Play',
|
||||
'DataObjectTest_Ploy',
|
||||
'DataObjectTest_Bogey',
|
||||
'DataObjectTest_Sortable',
|
||||
'ManyManyListTest_Product',
|
||||
'ManyManyListTest_Category',
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user