Skip to content
Permalink
Browse files

Fix up double truncation causing SQLServer to do silly things.

  • Loading branch information...
markstory committed Sep 9, 2014
1 parent e3fcc62 commit 92f219264f2ed627a87d2461e8380635a8163343
@@ -430,17 +430,18 @@ public function createTableSql(Table $table, $columns, $constraints, $indexes) {
public function truncateTableSql(Table $table) {
$name = $this->_driver->quoteIdentifier($table->name());
$queries = [
sprintf('DELETE FROM TABLE %s', $name)
sprintf('DELETE FROM %s', $name)
];
// Restart identity sequences
$pk = $table->primaryKey();
foreach ($pk as $column) {
$column = $table->column($column);
if (!empty($column['autoIncrement'])) {
if (count($pk) === 1) {
$column = $table->column($pk[0]);
if (in_array($column['type'], ['integer', 'biginteger'])) {
$queries[] = sprintf(
'DBCC CHECKIDENT(%s, RESEED, 0)',
$this->_driver->quoteIdentifier($column)
$name
);
break;
}
}
return $queries;
@@ -230,8 +230,7 @@ public function load($test) {
foreach ($fixtures as $fixture) {
if (!in_array($db->configName(), (array)$fixture->created)) {
$this->_setupTable($fixture, $db, $tables, $test->dropTables);
}
if (!$test->dropTables) {
} else {
$fixture->truncate($db);
}
}
@@ -325,7 +324,8 @@ public function loadSingle($name, $db = null, $dropTables = true) {
}
if (!in_array($db->configName(), (array)$fixture->created)) {
$this->_setupTable($fixture, $db, $dropTables);
$sources = $db->schemaCollection()->listTables();
$this->_setupTable($fixture, $db, $sources, $dropTables);
}
if (!$dropTables) {
$fixture->truncate($db);
@@ -269,9 +269,8 @@ public function testListTables() {
$schema = new SchemaCollection($connection);
$result = $schema->listTables();
$this->assertInternalType('array', $result);
$this->assertCount(2, $result);
$this->assertEquals('schema_articles', $result[0]);
$this->assertEquals('schema_authors', $result[1]);
$this->assertContains('schema_articles', $result);
$this->assertContains('schema_authors', $result);
}
/**
@@ -711,7 +710,7 @@ public function testTruncateSql() {
]);
$result = $table->truncateSql($connection);
$this->assertCount(2, $result);
$this->assertEquals('TRUNCATE TABLE [schema_articles]', $result[0]);
$this->assertEquals('DELETE FROM [schema_articles]', $result[0]);
$this->assertEquals('DBCC CHECKIDENT([schema_articles], RESEED, 0)', $result[1]);
}

0 comments on commit 92f2192

Please sign in to comment.
You can’t perform that action at this time.