Skip to content

Commit

Permalink
Merge branch 'master' of github.com:doctrine/dbal
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Jun 12, 2010
2 parents e300b91 + 390717e commit 22c9f44
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 287 deletions.
65 changes: 63 additions & 2 deletions lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?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
Expand Down Expand Up @@ -42,6 +40,7 @@
* @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
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -1901,4 +1952,14 @@ public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE '.$tableName;
}

/**
* This is for test reasons, many vendors have special requirements for dummy statements.
*
* @return string
*/
public function getDummySelectSQL()
{
return 'SELECT 1';
}
}
25 changes: 23 additions & 2 deletions lib/Doctrine/DBAL/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?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
Expand All @@ -27,6 +25,24 @@

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.
*
Expand Down Expand Up @@ -518,4 +534,9 @@ public function getForUpdateSQL()
{
return ' WITH RR USE AND KEEP UPDATE LOCKS';
}

public function getDummySelectSQL()
{
return 'SELECT 1 FROM sysibm.sysdummy1';
}
}
7 changes: 5 additions & 2 deletions lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?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
Expand Down Expand Up @@ -511,4 +509,9 @@ public function appendLockHint($fromClause, $lockMode)
return $fromClause;
}
}

protected function initializeDoctrineTypeMappings()
{

}
}
31 changes: 29 additions & 2 deletions lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?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
Expand Down Expand Up @@ -588,4 +586,33 @@ public function getReadLockSQL()
{
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',
);
}
}
35 changes: 33 additions & 2 deletions lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?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
Expand Down Expand Up @@ -650,4 +648,37 @@ public function getTruncateTableSQL($tableName, $cascade = false)
{
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'
);
}
}
43 changes: 41 additions & 2 deletions lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?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
Expand Down Expand Up @@ -642,4 +640,45 @@ public function getReadLockSQL()
{
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',
);
}
}
37 changes: 35 additions & 2 deletions lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?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
Expand Down Expand Up @@ -433,4 +431,39 @@ public function getForUpdateSql()
{
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',
);
}
}
18 changes: 2 additions & 16 deletions lib/Doctrine/DBAL/Schema/DB2SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,41 +66,27 @@ protected function _getPortableTableColumnDefinition($tableColumn)
$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(
Expand Down
Loading

0 comments on commit 22c9f44

Please sign in to comment.