Merge pull request #8435 from sminnee/faster-cleartable-ss3

FIX: Use DELETE FROM instead of TRUNCATE for clearTable
This commit is contained in:
Loz Calver 2018-10-11 12:32:33 +02:00 committed by GitHub
commit 8061e72bb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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");
}
}
}

View File

@ -29,6 +29,7 @@ class DataObjectTest extends SapphireTest {
'DataObjectTest_Play',
'DataObjectTest_Ploy',
'DataObjectTest_Bogey',
'DataObjectTest_Sortable',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);