Commit 537de7ea authored by Benjamin Eberlei's avatar Benjamin Eberlei

Fix MsSQL Platform and Tests

parent 70438ca2
......@@ -277,6 +277,8 @@ class MsSqlPlatform extends AbstractPlatform
public function getAlterTableSQL(TableDiff $diff)
{
$queryParts = array();
$sql = array();
if ($diff->newName !== false) {
$queryParts[] = 'RENAME TO ' . $diff->newName;
}
......@@ -292,17 +294,16 @@ class MsSqlPlatform extends AbstractPlatform
foreach ($diff->changedColumns AS $columnDiff) {
/* @var $columnDiff Doctrine\DBAL\Schema\ColumnDiff */
$column = $columnDiff->column;
$queryParts[] = 'CHANGE ' . ($columnDiff->oldColumnName) . ' '
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
$queryParts[] = 'ALTER COLUMN ' .
$this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
}
foreach ($diff->renamedColumns AS $oldColumnName => $column) {
$queryParts[] = 'CHANGE ' . $oldColumnName . ' '
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
$sql[] = "sp_RENAME '". $diff->name. ".". $oldColumnName . "' , '".$column->getQuotedName($this)."', 'COLUMN'";
$queryParts[] = 'ALTER COLUMN ' .
$this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
}
$sql = array();
foreach ($queryParts as $query) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query;
}
......@@ -342,7 +343,7 @@ class MsSqlPlatform extends AbstractPlatform
*/
public function getListTableColumnsSQL($table, $database = null)
{
return 'exec sp_columns @table_name = ' . $table;
return "exec sp_columns @table_name = '" . $table . "'";
}
/**
......
......@@ -23,6 +23,7 @@ namespace Doctrine\DBAL\Portability;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Cache\QueryCacheProfile;
class Connection extends \Doctrine\DBAL\Connection
{
......@@ -86,9 +87,9 @@ class Connection extends \Doctrine\DBAL\Connection
return $this->case;
}
public function executeQuery($query, array $params = array(), $types = array(), $useCacheLifetime = false, $cacheResultKey = null)
public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null)
{
return new Statement(parent::executeQuery($query, $params, $types, $useCacheLifetime, $cacheResultKey), $this);
return new Statement(parent::executeQuery($query, $params, $types, $qcp), $this);
}
/**
......
......@@ -6,6 +6,14 @@ require_once __DIR__ . '/../../../TestInit.php';
class OCI8StatementTest extends \Doctrine\Tests\DbalTestCase
{
public function setUp()
{
if (!extension_loaded('oci8')) {
$this->markTestSkipped('oci8 is not installed.');
}
parent::setUp();
}
protected function getMockOCI8Statement()
{
......
......@@ -103,7 +103,8 @@ class ModifyLimitQueryTest extends \Doctrine\Tests\DbalFunctionalTestCase
$p = $this->_conn->getDatabasePlatform();
$data = array();
foreach ($this->_conn->fetchAll($p->modifyLimitQuery($sql, $limit, $offset)) AS $row) {
$data[] = current($row);
$row = array_change_key_case($row, CASE_LOWER);
$data[] = $row['test_int'];
}
$this->assertEquals($expectedResults, $data);
}
......
......@@ -34,7 +34,7 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase
'ALTER TABLE mytable RENAME TO userlist',
'ALTER TABLE mytable ADD quota INT DEFAULT NULL',
'ALTER TABLE mytable DROP COLUMN foo',
'ALTER TABLE mytable CHANGE bar baz NVARCHAR(255) DEFAULT \'def\' NOT NULL',
'ALTER TABLE mytable ALTER COLUMN baz NVARCHAR(255) DEFAULT \'def\' NOT NULL',
);
}
......@@ -156,7 +156,7 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase
public function testModifyLimitQueryWithOffset()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10, 5);
$this->assertEquals('WITH outer_tbl AS (SELECT ROW_NUMBER() OVER (ORDER BY username DESC) AS "doctrine_rownum", * FROM (SELECT * FROM user) AS inner_tbl) SELECT * FROM outer_tbl WHERE "doctrine_rownum" BETWEEN 6 AND 15', $sql);
$this->assertEquals('SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY username DESC) AS "doctrine_rownum", * FROM user) AS doctrine_tbl WHERE "doctrine_rownum" BETWEEN 6 AND 15', $sql);
}
public function testModifyLimitQueryWithAscOrderBy()
......
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