Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix SQL Platform/Schema Manager problems.

  • Loading branch information...
commit c878bd033649cda0bcbccd9b5fad8b5d66885931 1 parent b6a4eca
@beberlei beberlei authored
View
2  UPGRADE
@@ -22,7 +22,7 @@ to SQLServerSchemaManager.
## Cleanup SQLServer Platform version mess
DBAL 2.1 and before were actually only compatible to SQL Server 2008, not earlier versions.
-Still other parts of the platform did use old features instead of newly introced datatypes
+Still other parts of the platform did use old features instead of newly introduced datatypes
in SQL Server 2005. Starting with DBAL 2.2 you can pick the Doctrine abstraction exactly
matching your SQL Server version.
View
2  lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php
@@ -63,7 +63,7 @@ private function _constructPdoDsn(array $params)
public function getDatabasePlatform()
{
- return new \Doctrine\DBAL\Platforms\SQLServer2005Platform();
+ return new \Doctrine\DBAL\Platforms\SQLServer2008Platform();
}
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
View
31 lib/Doctrine/DBAL/Platforms/SQLServer2005Platform.php
@@ -35,31 +35,6 @@
*/
class SQLServer2005Platform extends SQLServerPlatform
{
- public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
- {
- // 3 - microseconds precision length
- // http://msdn.microsoft.com/en-us/library/ms187819.aspx
- return 'DATETIME';
- }
-
- /**
- * @override
- */
- public function getDateTimeFormatString()
- {
- return 'Y-m-d H:i:s.000';
- }
-
- /**
- */
- protected function initializeDoctrineTypeMappings()
- {
- parent::initializeDoctrineTypeMappings();
- $this->doctrineTypeMapping = array(
-
- );
- }
-
/**
* @override
*/
@@ -67,5 +42,11 @@ public function supportsLimitOffset()
{
return true;
}
+
+ /** @override */
+ public function getClobTypeDeclarationSQL(array $field)
+ {
+ return 'VARCHAR(MAX)';
+ }
}
View
30 lib/Doctrine/DBAL/Platforms/SQLServer2008Platform.php
@@ -52,6 +52,30 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{
return 'TIME(0)';
}
+
+ /**
+ * @override
+ */
+ public function getDateTimeFormatString()
+ {
+ return 'Y-m-d H:i:s.u';
+ }
+
+ /**
+ * @override
+ */
+ public function getDateFormatString()
+ {
+ return 'Y-m-d';
+ }
+
+ /**
+ * @override
+ */
+ public function getTimeFormatString()
+ {
+ return 'H:i:s';
+ }
/**
* Adding Datetime2 Type
@@ -59,8 +83,8 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
protected function initializeDoctrineTypeMappings()
{
parent::initializeDoctrineTypeMappings();
- $this->doctrineTypeMapping = array(
- 'datetime2' => 'datetime',
- );
+ $this->doctrineTypeMapping['datetime2'] = 'datetime';
+ $this->doctrineTypeMapping['date'] = 'date';
+ $this->doctrineTypeMapping['time'] = 'time';
@stof
stof added a note

broken indentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
}
View
20 lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
@@ -710,7 +710,23 @@ public function getTemporaryTableName($tableName)
*/
public function getDateTimeFormatString()
{
- return 'Y-m-d H:i:s.u';
+ return 'Y-m-d H:i:s.000';
+ }
+
+ /**
+ * @override
+ */
@stof
stof added a note

broken indentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ public function getDateFormatString()
+ {
+ return 'Y-m-d H:i:s.000';
+ }
+
+ /**
+ * @override
+ */
@stof
stof added a note

same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ public function getTimeFormatString()
+ {
+ return 'Y-m-d H:i:s.000';
}
/**
@@ -750,11 +766,9 @@ protected function initializeDoctrineTypeMappings()
'real' => 'float',
'double' => 'float',
'double precision' => 'float',
- 'date' => 'date',
'datetimeoffset' => 'datetimetz',
'smalldatetime' => 'datetime',
'datetime' => 'datetime',
- 'time' => 'time',
'char' => 'string',
'varchar' => 'string',
'text' => 'text',
View
2  lib/Doctrine/DBAL/SQLServerSchemaManager.php → lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
@@ -56,7 +56,7 @@ protected function _getPortableTableColumnDefinition($tableColumn)
$default = $tableColumn['COLUMN_DEF'];
while ($default != ($default2 = preg_replace("/^\((.*)\)$/", '$1', $default))) {
- $default = $default2;
+ $default = trim($default2, "'");
}
$length = (int) $tableColumn['LENGTH'];
View
5 tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php
@@ -6,5 +6,8 @@
class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
-
+ protected function getPlatformName()
+ {
+ return "mssql";
+ }
}
View
18 tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
@@ -16,18 +16,24 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
*/
protected $_sm;
+
+ protected function getPlatformName()
+ {
+ $class = get_class($this);
+ $e = explode('\\', $class);
+ $testClass = end($e);
+ $dbms = strtolower(str_replace('SchemaManagerTest', null, $testClass));
+ return $dbms;
@stof
stof added a note

same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
protected function setUp()
{
parent::setUp();
-
- $class = get_class($this);
- $e = explode('\\', $class);
- $testClass = end($e);
- $dbms = strtolower(str_replace('SchemaManagerTest', null, $testClass));
+
+ $dbms = $this->getPlatformName();
@stof
stof added a note

and here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
if ($this->_conn->getDatabasePlatform()->getName() !== $dbms) {
- $this->markTestSkipped('The ' . $testClass .' requires the use of ' . $dbms);
+ $this->markTestSkipped(get_class($this) . ' requires the use of ' . $dbms);
}
$this->_sm = $this->_conn->getSchemaManager();

1 comment on commit c878bd0

Please sign in to comment.
Something went wrong with that request. Please try again.