Commit ce5b0569 authored by beberlei's avatar beberlei

Merge remote branch 'juokaz/sqlsrv-driver' into DBAL-8

parents 3caada2b e2dd9536
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......@@ -19,17 +21,17 @@
namespace Doctrine\DBAL\Driver\PDOMsSql;
use PDO, Doctrine\DBAL\Driver\Connection as DriverConnection;
/**
* MsSql Connection implementation.
*
* @since 2.0
*/
class Connection extends PDO implements DriverConnection
class Connection extends \PDO implements \Doctrine\DBAL\Driver\Connection
{
/**
* {@inheritdoc}
* Performs the rollback.
*
* @override
*/
public function rollback()
{
......@@ -37,7 +39,9 @@ class Connection extends PDO implements DriverConnection
}
/**
* {@inheritdoc}
* Performs the commit.
*
* @override
*/
public function commit()
{
......@@ -45,21 +49,12 @@ class Connection extends PDO implements DriverConnection
}
/**
* {@inheritdoc}
* Begins a database transaction.
*
* @override
*/
public function beginTransaction()
{
$this->exec('BEGIN TRANSACTION');
}
/**
* {@inheritdoc}
*/
public function lastInsertId($name = null)
{
$stmt = $this->query('SELECT SCOPE_IDENTITY()');
$id = $stmt->fetchColumn();
$stmt->closeCursor();
return $id;
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
/**
* The PDO-based Sqlsrv driver.
*
* @since 2.0
*/
class Driver implements \Doctrine\DBAL\Driver
{
public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{
if (isset($params['dbname'])) {
$driverOptions['Database'] = $params['dbname'];
}
return new \Doctrine\DBAL\Driver\PDOConnection(
$this->_constructPdoDsn($params),
$username,
$password,
$driverOptions
);
}
/**
* Constructs the Sqlsrv PDO DSN.
*
* @return string The DSN.
*/
private function _constructPdoDsn(array $params)
{
// TODO: This might need to be revisted once we have access to a sql server
$dsn = 'sqlsrv:(';
if (isset($params['host'])) {
$dsn .= $params['host'];
}
$dsn .= ')';
if (stripos($dsn, '\sqlexpress') !== false)
{
$dsn = str_ireplace('\sqlexpress', '', $dsn);
$dsn .= '\sqlexpress';
}
$dsn = str_ireplace('localhost', 'local', $dsn);
if (isset($params['port']) && !empty($params['port'])) {
$dsn .= ',' . $params['port'];
}
return $dsn;
}
public function getDatabasePlatform()
{
return new \Doctrine\DBAL\Platforms\SqlsrvPlatform();
}
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
return new \Doctrine\DBAL\Schema\SqlsrvSchemaManager($conn);
}
public function getName()
{
return 'pdo_sqlsrv';
}
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
return $params['dbname'];
}
}
\ No newline at end of file
......@@ -44,6 +44,7 @@ final class DriverManager
'oci8' => 'Doctrine\DBAL\Driver\OCI8\Driver',
'ibm_db2' => 'Doctrine\DBAL\Driver\IBMDB2\DB2Driver',
'pdo_ibm' => 'Doctrine\DBAL\Driver\PDOIbm\Driver',
'pdo_sqlsrv' => 'Doctrine\DBAL\Driver\PDOSqlsrv\Driver',
);
/** Private constructor. This class cannot be instantiated. */
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......@@ -42,6 +40,7 @@ use Doctrine\DBAL\DBALException,
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @todo Remove any unnecessary methods.
*/
abstract class AbstractPlatform
......@@ -76,11 +75,63 @@ abstract class AbstractPlatform
*/
const TRIM_BOTH = 3;
/**
* @var array
*/
protected $doctrineTypeMapping = null;
/**
* Constructor.
*/
public function __construct() {}
/**
* Register a doctrine type to be used in conjunction with a column type of this platform.
*
* @param string $dbType
* @param string $doctrineType
*/
public function registerDoctrineTypeMapping($dbType, $doctrineType)
{
if ($this->doctrineTypeMapping === null) {
$this->initializeDoctrineTypeMappings();
}
if (!Types\Type::hasType($doctrineType)) {
throw DBALException::typeNotFound($doctrineType);
}
$dbType = strtolower($dbType);
$this->doctrineTypeMapping[$dbType] = $doctrineType;
}
/**
* Get the Doctrine type that is mapped for the given database column type.
*
* @param string $dbType
* @return string
*/
public function getDoctrineTypeMapping($dbType)
{
if ($this->doctrineTypeMapping === null) {
$this->initializeDoctrineTypeMappings();
}
$dbType = strtolower($dbType);
if (isset($this->doctrineTypeMapping[$dbType])) {
return $this->doctrineTypeMapping[$dbType];
} else {
throw new \Doctrine\DBAL\DBALException("Unknown database type ".$dbType." requested, " . get_class($this) . " may not support it.");
}
}
/**
* Lazy load Doctrine Type Mappings
*
* @return void
*/
abstract protected function initializeDoctrineTypeMappings();
/**
* Gets the character used for identifier quoting.
*
......@@ -1901,4 +1952,14 @@ abstract class AbstractPlatform
{
return 'TRUNCATE '.$tableName;
}
/**
* This is for test reasons, many vendors have special requirements for dummy statements.
*
* @return string
*/
public function getDummySelectSQL()
{
return 'SELECT 1';
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......@@ -27,6 +25,24 @@ use Doctrine\DBAL\Schema\TableDiff;
class DB2Platform extends AbstractPlatform
{
public function initializeDoctrineTypeMappings()
{
$this->doctrineTypeMapping = array(
'smallint' => 'smallint',
'bigint' => 'bigint',
'integer' => 'integer',
'time' => 'time',
'date' => 'date',
'varchar' => 'string',
'character' => 'string',
'clob' => 'text',
'decimal' => 'decimal',
'double' => 'decimal',
'real' => 'decimal',
'timestamp' => 'datetime',
);
}
/**
* Gets the SQL snippet used to declare a VARCHAR column type.
*
......@@ -518,4 +534,9 @@ class DB2Platform extends AbstractPlatform
{
return ' WITH RR USE AND KEEP UPDATE LOCKS';
}
public function getDummySelectSQL()
{
return 'SELECT 1 FROM sysibm.sysdummy1';
}
}
\ No newline at end of file
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......@@ -588,4 +586,33 @@ class MySqlPlatform extends AbstractPlatform
{
return 'LOCK IN SHARE MODE';
}
protected function initializeDoctrineTypeMappings()
{
$this->doctrineTypeMapping = array(
'tinyint' => 'boolean',
'smallint' => 'smallint',
'mediumint' => 'integer',
'int' => 'integer',
'integer' => 'integer',
'bigint' => 'bigint',
'tinytext' => 'text',
'mediumtext' => 'text',
'longtext' => 'text',
'text' => 'text',
'varchar' => 'string',
'string' => 'string',
'char' => 'string',
'date' => 'date',
'datetime' => 'datetime',
'timestamp' => 'datetime',
'time' => 'time',
'float' => 'decimal',
'double' => 'decimal',
'real' => 'decimal',
'decimal' => 'decimal',
'numeric' => 'decimal',
'year' => 'date',
);
}
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......@@ -650,4 +648,37 @@ LEFT JOIN all_cons_columns r_cols
{
return 'TRUNCATE TABLE '.$tableName;
}
/**
* This is for test reasons, many vendors have special requirements for dummy statements.
*
* @return string
*/
public function getDummySelectSQL()
{
return 'SELECT 1 FROM DUAL';
}
protected function initializeDoctrineTypeMappings()
{
$this->doctrineTypeMapping = array(
'integer' => 'integer',
'number' => 'integer',
'pls_integer' => 'boolean',
'binary_integer' => 'boolean',
'varchar' => 'string',
'varchar2' => 'string',
'nvarchar2' => 'string',
'char' => 'string',
'nchar' => 'string',
'date' => 'datetime',
'timestamp' => 'datetime',
'float' => 'decimal',
'long' => 'string',
'clob' => 'text',
'nclob' => 'text',
'rowid' => 'string',
'urowid' => 'string'
);
}
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......@@ -642,4 +640,45 @@ class PostgreSqlPlatform extends AbstractPlatform
{
return 'FOR SHARE';
}
protected function initializeDoctrineTypeMappings()
{
$this->doctrineTypeMapping = array(
'smallint' => 'smallint',
'int2' => 'smallint',
'serial' => 'integer',
'serial4' => 'integer',
'int' => 'integer',
'int4' => 'integer',
'integer' => 'integer',
'bigserial' => 'bigint',
'serial8' => 'bigint',
'bigint' => 'bigint',
'int8' => 'bigint',
'bool' => 'boolean',
'boolean' => 'boolean',
'text' => 'text',
'varchar' => 'string',
'interval' => 'string',
'_varchar' => 'string',
'char' => 'string',
'bpchar' => 'string',
'date' => 'date',
'datetime' => 'datetime',
'timestamp' => 'datetime',
'timestamptz' => 'datetime',
'time' => 'time',
'timetz' => 'time',
'float' => 'decimal',
'float4' => 'decimal',
'float8' => 'decimal',
'double' => 'decimal',
'double precision' => 'decimal',
'real' => 'decimal',
'decimal' => 'decimal',
'money' => 'decimal',
'numeric' => 'decimal',
'year' => 'date',
);
}
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......@@ -433,4 +431,39 @@ class SqlitePlatform extends AbstractPlatform
{
return '';
}
protected function initializeDoctrineTypeMappings()
{
$this->doctrineTypeMapping = array(
'boolean' => 'boolean',
'tinyint' => 'boolean',
'smallint' => 'smallint',
'mediumint' => 'integer',
'int' => 'integer',
'integer' => 'integer',
'serial' => 'integer',
'bigint' => 'bigint',
'bigserial' => 'bigint',
'clob' => 'text',
'tinytext' => 'text',
'mediumtext' => 'text',
'longtext' => 'text',
'text' => 'text',
'varchar' => 'string',
'varchar2' => 'string',
'nvarchar' => 'string',
'image' => 'string',
'ntext' => 'string',
'char' => 'string',
'date' => 'date',
'datetime' => 'datetime',
'timestamp' => 'datetime',
'time' => 'time',
'float' => 'decimal',
'double' => 'decimal',
'real' => 'decimal',
'decimal' => 'decimal',
'numeric' => 'decimal',
);
}
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\DBAL\Platforms;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\DBALException;
/**
* The SqlsrvPlatform provides the behavior, features and SQL dialect of the
* Microsoft SQL database platform.
*
* @since 2.0
* @author Juozas Kaziukenas <juozas@juokaz.com>
*/
class SqlsrvPlatform extends MsSqlPlatform
{
/**
* Get the platform name for this instance
*
* @return string
*/
public function getName()
{
return 'sqlsrv';
}
}
......@@ -66,41 +66,27 @@ class DB2SchemaManager extends AbstractSchemaManager
$unsigned = false;
$scale = false;
$precision = false;
$type = $this->_platform->getDoctrineTypeMapping($tableColumn['typename']);
switch (strtolower($tableColumn['typename'])) {
case 'smallint':
case 'bigint':
case 'integer':
case 'time':
case 'date':
$type = strtolower($tableColumn['typename']);
break;
case 'varchar':
$type = 'string';
$length = $tableColumn['length'];
$fixed = false;
break;
case 'character':
$type = 'string';
$length = $tableColumn['length'];
$fixed = true;
break;
case 'clob':
$type = 'text';
$length = $tableColumn['length'];
break;
case 'decimal':
case 'double':
case 'real':
$type = 'decimal';
$scale = $tableColumn['scale'];
$precision = $tableColumn['length'];
break;
case 'timestamp':
$type = 'datetime';
break;
default:
throw new \Doctrine\DBAL\DBALException("Unknown Type: ".$tableColumn['typename']);
}
$options = array(
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......@@ -89,9 +87,6 @@ class MySqlSchemaManager extends AbstractSchemaManager
{
$dbType = strtolower($tableColumn['Type']);
$dbType = strtok($dbType, '(), ');
if ($dbType == 'national') {
$dbType = strtok('(), ');
}
if (isset($tableColumn['length'])) {
$length = $tableColumn['length'];
$decimal = '';
......@@ -109,70 +104,10 @@ class MySqlSchemaManager extends AbstractSchemaManager
$scale = null;
$precision = null;
// Map db type to Doctrine mapping type
$type = $this->_platform->getDoctrineTypeMapping($dbType);
switch ($dbType) {
case 'tinyint':
$type = 'boolean';
$length = null;
break;
case 'smallint':
$type = 'smallint';
$length = null;
break;
case 'mediumint':
$type = 'integer';
$length = null;
break;
case 'int':
case 'integer':
$type = 'integer';
$length = null;
break;
case 'bigint':
$type = 'bigint';
$length = null;
break;
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
$type = 'text';
$fixed = false;
break;
case 'varchar':
$fixed = false;
case 'string':
case 'char':
$type = 'string';
if ($length == '1') {
$type = 'boolean';
if (preg_match('/^(is|has)/', $tableColumn['name'])) {
$type = array_reverse($type);
}
} else if (strstr($dbType, 'text')) {
$type = 'text';
if ($decimal == 'binary') {
$type = 'blob';
}
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'set':
$fixed = false;
$type = 'text';
$type = 'integer'; //FIXME:???
break;
case 'date':
$type = 'date';
break;
case 'datetime':
case 'timestamp':
$type = 'datetime';
break;
case 'time':
$type = 'time';
$fixed = true;
break;
case 'float':
case 'double':
......@@ -184,36 +119,22 @@ class MySqlSchemaManager extends AbstractSchemaManager
$scale = $match[2];
$length = null;
}
$type = 'decimal';
break;
case 'tinyint':
case 'smallint':
case 'mediumint':
case 'int':
case 'integer':
case 'bigint':
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
case 'binary':
case 'varbinary':
$type = 'blob';
$length = null;
break;
case 'year':
$type = 'integer';
$type = 'date';
$length = null;
break;
case 'geometry':
case 'geometrycollection':
case 'point':
case 'multipoint':
case 'linestring':
case 'multilinestring':
case 'polygon':
case 'multipolygon':
$type = 'blob';
$length = null;
break;
default:
$type = 'string';
$length = null;
}
$length = ((int) $length == 0) ? null : (int) $length;
......
......@@ -111,68 +111,57 @@ class OracleSchemaManager extends AbstractSchemaManager
$precision = null;
$scale = null;
$type = $this->_platform->getDoctrineTypeMapping($dbType);
switch ($dbType) {
case 'integer':
case 'number':
// @todo this sucks for the mapping stuff, is this deterministic maybe?
if($tableColumn['data_scale'] > 0) {
$type = 'decimal';
$precision = $tableColumn['data_precision'];
$scale = $tableColumn['data_scale'];
} else {
$type = 'integer';
if ($precision == 0 && $scale == 1) {
$type = 'boolean';
} else {
$type = 'decimal';
}
}
$length = null;
break;
case 'pls_integer':
case 'binary_integer':
$type = 'boolean';
$length = null;
break;
case 'varchar':
case 'varchar2':
case 'nvarchar2':
$fixed = false;
break;
case 'char':
case 'nchar':
if ($length == '1' && preg_match('/^(is|has)/', $tableColumn['column_name'])) {
$type = 'boolean';
} else {
$type = 'string';
}
if ($fixed !== false) {
$fixed = true;
}
$fixed = true;
break;
case 'date':
case 'timestamp':
$type = 'datetime';
$length = null;
break;
case 'float':
$precision = $tableColumn['data_precision'];
$scale = $tableColumn['data_scale'];
$type = 'decimal';
$length = null;
break;
case 'long':
$type = 'string';
case 'clob':
case 'nclob':
$length = null;
$type = 'text';
break;
case 'blob':
case 'raw':
case 'long raw':
case 'bfile':
$type = 'blob';
$length = null;
break;
case 'rowid':
case 'urowid':
default:
$type = 'string';
$length = null;
}
......
......@@ -199,11 +199,11 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$dbType = strtolower($tableColumn['type']);
$type = $this->_platform->getDoctrineTypeMapping($dbType);
$autoincrement = false;
switch ($dbType) {
case 'smallint':
case 'int2':
$type = 'smallint';
$length = null;
break;
case 'serial':
......@@ -213,7 +213,6 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
case 'int':
case 'int4':
case 'integer':
$type = 'integer';
$length = null;
break;
case 'bigserial':
......@@ -222,52 +221,23 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
// break missing intentionally
case 'bigint':
case 'int8':
$type = 'bigint';
$length = null;
break;
case 'bool':
case 'boolean':
$type = 'boolean';
$length = null;
break;
case 'text':
$fixed = false;
$type = 'text';
break;
case 'varchar':
case 'interval':
case '_varchar':
$fixed = false;
case 'tsvector':
case 'unknown':
break;
case 'char':
case 'bpchar':
$type = 'string';
if ($length == '1') {
if (preg_match('/^(is|has)/', $tableColumn['name'])) {
$type = 'boolean';
}
} elseif (strstr($dbType, 'text')) {
$type = 'text';
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
$type = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
case 'timetz':
case 'timestamptz':
$type = 'datetime';
$length = null;
break;
case 'time':
$type = 'time';
$length = null;
$fixed = true;
break;
case 'float':
case 'float4':
......@@ -283,34 +253,10 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$scale = $match[2];
$length = null;
}
$type = 'decimal';
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
case 'bytea':
case 'geometry':
case 'geometrycollection':
case 'point':
case 'multipoint':
case 'linestring':
case 'multilinestring':
case 'polygon':
case 'multipolygon':
$type = 'blob';
$length = null;
break;
case 'oid':
$type = 'blob';
$length = null;
break;
case 'year':
$type = 'date';
$length = null;
break;
default:
$type = 'string';
}
$options = array(
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
......@@ -131,11 +129,10 @@ class SqliteSchemaManager extends AbstractSchemaManager
}
$dbType = strtolower($tableColumn['type']);
$length = isset($tableColumn['length']) ? $tableColumn['length'] : null;
$unsigned = (boolean) isset($tableColumn['unsigned']) ? $tableColumn['unsigned'] : false;
$fixed = false;
$type = null;
$type = $this->_platform->getDoctrineTypeMapping($dbType);
$default = $tableColumn['dflt_value'];
if ($default == 'NULL') {
$default = null;
......@@ -150,72 +147,8 @@ class SqliteSchemaManager extends AbstractSchemaManager
$scale = null;
switch ($dbType) {
case 'boolean':
$type = 'boolean';
break;
case 'tinyint':
$type = 'boolean';
$length = null;
break;
case 'smallint':
$type = 'smallint';
$length = null;
break;
case 'mediumint':
case 'int':
case 'integer':
case 'serial':
$type = 'integer';
$length = null;
break;
case 'bigint':
case 'bigserial':
$type = 'bigint';
$length = null;
break;
case 'clob':
$fixed = false;
$type = 'text';
break;
case 'tinytext':
case 'mediumtext':
case 'longtext':
case 'text':
$type = 'text';
break;
case 'varchar':
case 'varchar2':
case 'nvarchar':
case 'ntext':
case 'image':
case 'nchar':
$fixed = false;
case 'char':
$type = 'string';
if ($length == '1') {
$type = 'boolean';
if (preg_match('/^(is|has)/', $tableColumn['name'])) {
$type = array_reverse($type);
}
} elseif (strstr($dbType, 'text')) {
$type = 'clob';
}
if ($fixed !== false) {
$fixed = true;
}
break;
case 'date':
$type = 'date';
$length = null;
break;
case 'datetime':
case 'timestamp':
$type = 'datetime';
$length = null;
break;
case 'time':
$type = 'time';
$length = null;
$fixed = true;
break;
case 'float':
case 'double':
......@@ -223,23 +156,8 @@ class SqliteSchemaManager extends AbstractSchemaManager
case 'decimal':
case 'numeric':
list($precision, $scale) = array_map('trim', explode(', ', $tableColumn['length']));
$type = 'decimal';
$length = null;
break;
case 'tinyblob':
case 'mediumblob':
case 'longblob':
case 'blob':
$type = 'blob';
$length = null;
break;
case 'year':
$type = 'date';
$length = null;
break;
default:
$type = 'string';
$length = null;
}
$options = array(
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
namespace Doctrine\DBAL\Schema;
/**
* xxx
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Juozas Kaziukenas <juozas@juokaz.com>
* @version $Revision$
* @since 2.0
*/
class SqlsrvSchemaManager extends MsSqlSchemaManager
{
}
\ No newline at end of file
......@@ -88,7 +88,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
try {
$this->_conn->transactional(function($conn) {
$conn->executeQuery("select 1");
$conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL());
throw new \RuntimeException("Ooops!");
});
} catch (\RuntimeException $expected) {
......@@ -99,7 +99,8 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testTransactional()
{
$this->_conn->transactional(function($conn) {
$conn->executeQuery("select 1");
/* @var $conn Connection */
$conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL());
});
}
}
\ No newline at end of file
......@@ -27,8 +27,7 @@ class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testExecuteUpdate()
{
$sql = "INSERT INTO " . $this->_conn->quoteIdentifier('write_table') . " ( " .
$this->_conn->quoteIdentifier('test_int') . " ) VALUES ( " . $this->_conn->quote(1) . ")";
$sql = "INSERT INTO write_table (test_int) VALUES ( " . $this->_conn->quote(1) . ")";
$affected = $this->_conn->executeUpdate($sql);
$this->assertEquals(1, $affected, "executeUpdate() should return the number of affected rows!");
......
......@@ -32,4 +32,6 @@ class MockPlatform extends \Doctrine\DBAL\Platforms\AbstractPlatform
{
return 'mock';
}
protected function initializeDoctrineTypeMappings() {
}
}
......@@ -16,6 +16,24 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->_platform = $this->createPlatform();
}
public function testGetUnknownDoctrineMappingType()
{
$this->setExpectedException('Doctrine\DBAL\DBALException');
$this->_platform->getDoctrineTypeMapping('foobar');
}
public function testRegisterDoctrineMappingType()
{
$this->_platform->registerDoctrineTypeMapping('foo', 'integer');
$this->assertEquals('integer', $this->_platform->getDoctrineTypeMapping('foo'));
}
public function testRegisterUnknownDoctrineMappingType()
{
$this->setExpectedException('Doctrine\DBAL\DBALException');
$this->_platform->registerDoctrineTypeMapping('foo', 'bar');
}
public function testCreateWithNoColumns()
{
$table = new \Doctrine\DBAL\Schema\Table('test');
......
......@@ -16,13 +16,13 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase
public function getGenerateTableSql()
{
return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
return 'CREATE TABLE test (id INT IDENTITY NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
}
public function getGenerateTableWithMultiColumnUniqueIndexSql()
{
return array(
'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX test_foo_bar_uniq (foo, bar))'
'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, CONSTRAINT test_foo_bar_uniq UNIQUE (foo, bar))'
);
}
......@@ -75,11 +75,11 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase
$this->_platform->getIntegerTypeDeclarationSQL(array())
);
$this->assertEquals(
'INT AUTO_INCREMENT',
'INT IDENTITY',
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
));
$this->assertEquals(
'INT AUTO_INCREMENT',
'INT IDENTITY',
$this->_platform->getIntegerTypeDeclarationSQL(
array('autoincrement' => true, 'primary' => true)
));
......
......@@ -4,7 +4,11 @@ namespace Doctrine\Tests;
class DbalFunctionalTestCase extends DbalTestCase
{
/* Shared connection when a TestCase is run alone (outside of it's functional suite) */
/**
* Shared connection when a TestCase is run alone (outside of it's functional suite)
*
* @var Doctrine\DBAL\Connection
*/
private static $_sharedConn;
/**
......@@ -14,8 +18,14 @@ class DbalFunctionalTestCase extends DbalTestCase
protected function resetSharedConn()
{
$this->sharedFixture['conn'] = null;
self::$_sharedConn = null;
if ($this->sharedFixture['conn']) {
$this->sharedFixture['conn']->close();
$this->sharedFixture['conn'] = null;
}
if (self::$_sharedConn) {
self::$_sharedConn->close();
self::$_sharedConn = null;
}
}
protected function setUp()
......@@ -29,4 +39,4 @@ class DbalFunctionalTestCase extends DbalTestCase
$this->_conn = self::$_sharedConn;
}
}
}
\ No newline at end of file
}
......@@ -82,4 +82,6 @@ class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform
{
return 'mock';
}
protected function initializeDoctrineTypeMappings() {
}
}
\ No newline at end of file
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