Commit 91de30d5 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Fix a bunch of MSSQL issues to get the testsuite running again

parent 52e6fd7f
......@@ -37,6 +37,33 @@ use Doctrine\DBAL\Schema\Index,
*/
class MsSqlPlatform extends AbstractPlatform
{
/**
* {@inheritDoc}
*/
public function getDateDiffExpression($date1, $date2)
{
return 'DATEDIFF(day, ' . $date2 . ',' . $date1 . ')';
}
public function getDateAddDaysExpression($date, $days)
{
return 'DATEADD(day, ' . $days . ', ' . $date . ')';
}
public function getDateSubDaysExpression($date, $days)
{
return 'DATEADD(day, -1 * ' . $days . ', ' . $date . ')';
}
public function getDateAddMonthExpression($date, $months)
{
return 'DATEADD(month, ' . $months . ', ' . $date . ')';
}
public function getDateSubMonthExpression($date, $months)
{
return 'DATEADD(month, -1 * ' . $months . ', ' . $date . ')';
}
/**
* Whether the platform prefers identity columns for ID generation.
......@@ -794,4 +821,9 @@ class MsSqlPlatform extends AbstractPlatform
{
return "[" . str_replace("]", "][", $str) . "]";
}
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE TABLE '.$tableName;
}
}
......@@ -169,4 +169,28 @@ class MsSqlSchemaManager extends AbstractSchemaManager
return new View($view['name'], null);
}
/**
* List the indexes for a given table returning an array of Index instances.
*
* Keys of the portable indexes list are all lower-cased.
*
* @param string $table The name of the table
* @return Index[] $tableIndexes
*/
public function listTableIndexes($table)
{
$sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase());
try {
$tableIndexes = $this->_conn->fetchAll($sql);
} catch(\PDOException $e) {
if ($e->getCode() == "IMSSP") {
return array();
} else {
throw $e;
}
}
return $this->_getPortableTableIndexesList($tableIndexes, $table);
}
}
\ No newline at end of file
......@@ -70,29 +70,25 @@ class TestUtil
} else {
$sm = $realConn->getSchemaManager();
$tableNames = $sm->listTableNames();
foreach ($tableNames AS $tableName) {
$sm->dropTable($tableName);
}
}
/* @var $schema Schema */
$schema = $sm->createSchema();
$stmts = $schema->toDropSql($realConn->getDatabasePlatform());
$eventManager = null;
if (isset($GLOBALS['db_event_subscribers'])) {
$eventManager = new \Doctrine\Common\EventManager();
foreach (explode(",", $GLOBALS['db_event_subscribers']) AS $subscriberClass) {
$subscriberInstance = new $subscriberClass();
$eventManager->addEventSubscriber($subscriberInstance);
foreach ($stmts AS $stmt) {
$realConn->exec($stmt);
}
}
$conn = \Doctrine\DBAL\DriverManager::getConnection($realDbParams, null, $eventManager);
$conn = \Doctrine\DBAL\DriverManager::getConnection($realDbParams, null, null);
} else {
$params = array(
'driver' => 'pdo_sqlite',
'memory' => true
);
if (isset($GLOBALS['db_path'])) {
$params['path'] = $GLOBALS['db_path'];
unlink($GLOBALS['db_path']);
}
$conn = \Doctrine\DBAL\DriverManager::getConnection($params);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment