diff --git a/Driver/PDODblib/Connection.php b/Driver/PDODblib/Connection.php index 32b83a1..6c0af25 100644 --- a/Driver/PDODblib/Connection.php +++ b/Driver/PDODblib/Connection.php @@ -33,7 +33,7 @@ class Connection extends \Doctrine\DBAL\Driver\PDOConnection implements DriverCo */ public function rollback() { - $this->exec('ROLLBACK TRANSACTION'); +// $this->exec('ROLLBACK TRANSACTION'); } /** diff --git a/Platforms/DblibPlatform.php b/Platforms/DblibPlatform.php index 7a9860d..8ddad4c 100644 --- a/Platforms/DblibPlatform.php +++ b/Platforms/DblibPlatform.php @@ -26,6 +26,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLServerPlatform; +use Doctrine\DBAL\Schema\Index; /** * The DblibPlatform provides the behavior, features and SQL dialect of the @@ -133,17 +134,28 @@ protected function initializeDoctrineTypeMappings() parent::initializeDoctrineTypeMappings(); // add uniqueidentifier + //$this->doctrineTypeMapping['timestamp'] = 'date'; $this->doctrineTypeMapping['uniqueidentifier'] = 'uniqueidentifier'; } + public function getTimestampTypeDeclarationSQL(array $fieldDeclaration) + { + return "TIMESTAMP"; + } + /** * @override */ public function getDateTimeFormatString() { - return 'Y-m-d H:i:s.u'; + return 'F d Y H:i:s:000A'; } + public function getTimestampFormatString() + { + return 'Y-m-d H:i:s'; + } + /** * @override * @return bool @@ -152,4 +164,26 @@ public function supportsLimitOffset() { return true; } + + public function getCreateIndexSQL(Index $index, $table) + { + if ($table instanceof Table) { + $table = $table->getQuotedName($this); + } + $name = $index->getQuotedName($this); + $columns = $index->getColumns(); + + if (count($columns) == 0) { + throw new \InvalidArgumentException("Incomplete definition. 'columns' required."); + } + + if ($index->isPrimary()) { + return $this->getCreatePrimaryKeySQL($index, $table); + } + + $query = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table; + $query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')'; + + return $query; + } } diff --git a/Schema/DblibSchemaManager.php b/Schema/DblibSchemaManager.php index 3e601d2..97d5f55 100644 --- a/Schema/DblibSchemaManager.php +++ b/Schema/DblibSchemaManager.php @@ -29,21 +29,23 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) $list = array(); foreach ($tableForeignKeys as $key => $value) { $value = \array_change_key_case($value, CASE_LOWER); - if (!isset($list[$value['constraint_name']])) { - if ($value['delete_rule'] == "NO ACTION") { - $value['delete_rule'] = null; + if(array_key_exists('constraint_name', $value)){ + if (!isset($list[$value['constraint_name']])) { + if ($value['delete_rule'] == "NO ACTION") { + $value['delete_rule'] = null; + } + + $list[$value['pkconstraint_name']] = array( + 'name' => $value['pkconstraint_name'], + 'local' => array(), + 'foreign' => array(), + 'foreignTable' => $value['fktable_name'], + 'onDelete' => $value['delete_rule'], + ); } - - $list[$value['pkconstraint_name']] = array( - 'name' => $value['pkconstraint_name'], - 'local' => array(), - 'foreign' => array(), - 'foreignTable' => $value['fktable_name'], - 'onDelete' => $value['delete_rule'], - ); + $list[$value['pkconstraint_name']]['local'][$value['deferrability']] = $value['pkcolumn_name']; + $list[$value['pkconstraint_name']]['foreign'][$value['deferrability']] = $value['fkcolumn_name']; } - $list[$value['pkconstraint_name']]['local'][$value['deferrability']] = $value['pkcolumn_name']; - $list[$value['pkconstraint_name']]['foreign'][$value['deferrability']] = $value['fkcolumn_name']; } $result = array(); diff --git a/Types/TimestampType.php b/Types/TimestampType.php new file mode 100644 index 0000000..da26496 --- /dev/null +++ b/Types/TimestampType.php @@ -0,0 +1,69 @@ +. + */ + +namespace Realestate\MssqlBundle\Types; + +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Type; + +/** + * Type that maps an SQL TIME to a PHP DateTime object. + * + * @since 2.0 + */ +class TimestampType extends Type +{ + public function getName() + { + return 'timestamp'; + } + + /** + * {@inheritdoc} + */ + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + { + return $platform->getTimestampTypeDeclarationSQL($fieldDeclaration); + } + + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + return ($value !== null) + ? $value->format($platform->getTimestampFormatString()) : null; + } + + /** + * {@inheritdoc} + */ + public function convertToPHPValue($value, AbstractPlatform $platform) + { + if ($value === null) { + return null; + } + + $val = \Realestate\MssqlBundle\Types\RealestateDateTime::createFromFormat($platform->getTimestampFormatString(), $value); + if (!$val) { + throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimestampFormatString()); + } + return $val; + } +} \ No newline at end of file