Commit 8f783fbe authored by Alexander's avatar Alexander

Merge pull request #180 from stof/fix_phpdoc

Fixed some phpdoc
parents 924a97eb da06cdb2
...@@ -22,6 +22,8 @@ namespace Doctrine\DBAL\Platforms; ...@@ -22,6 +22,8 @@ namespace Doctrine\DBAL\Platforms;
use Doctrine\DBAL\DBALException, use Doctrine\DBAL\DBALException,
Doctrine\DBAL\Connection, Doctrine\DBAL\Connection,
Doctrine\DBAL\Types, Doctrine\DBAL\Types,
Doctrine\DBAL\Schema\Constraint,
Doctrine\DBAL\Schema\Sequence,
Doctrine\DBAL\Schema\Table, Doctrine\DBAL\Schema\Table,
Doctrine\DBAL\Schema\Index, Doctrine\DBAL\Schema\Index,
Doctrine\DBAL\Schema\ForeignKeyConstraint, Doctrine\DBAL\Schema\ForeignKeyConstraint,
...@@ -48,7 +50,6 @@ use Doctrine\DBAL\DBALException, ...@@ -48,7 +50,6 @@ use Doctrine\DBAL\DBALException,
* *
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3938 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
...@@ -59,32 +60,32 @@ use Doctrine\DBAL\DBALException, ...@@ -59,32 +60,32 @@ use Doctrine\DBAL\DBALException,
abstract class AbstractPlatform abstract class AbstractPlatform
{ {
/** /**
* @var int * @var integer
*/ */
const CREATE_INDEXES = 1; const CREATE_INDEXES = 1;
/** /**
* @var int * @var integer
*/ */
const CREATE_FOREIGNKEYS = 2; const CREATE_FOREIGNKEYS = 2;
/** /**
* @var int * @var integer
*/ */
const TRIM_UNSPECIFIED = 0; const TRIM_UNSPECIFIED = 0;
/** /**
* @var int * @var integer
*/ */
const TRIM_LEADING = 1; const TRIM_LEADING = 1;
/** /**
* @var int * @var integer
*/ */
const TRIM_TRAILING = 2; const TRIM_TRAILING = 2;
/** /**
* @var int * @var integer
*/ */
const TRIM_BOTH = 3; const TRIM_BOTH = 3;
...@@ -109,7 +110,7 @@ abstract class AbstractPlatform ...@@ -109,7 +110,7 @@ abstract class AbstractPlatform
/** /**
* Holds the KeywordList instance for the current platform. * Holds the KeywordList instance for the current platform.
* *
* @var Doctrine\DBAL\Platforms\Keywords\KeywordList * @var \Doctrine\DBAL\Platforms\Keywords\KeywordList
*/ */
protected $_keywords; protected $_keywords;
...@@ -142,6 +143,7 @@ abstract class AbstractPlatform ...@@ -142,6 +143,7 @@ abstract class AbstractPlatform
* Gets the SQL snippet that declares a boolean column. * Gets the SQL snippet that declares a boolean column.
* *
* @param array $columnDef * @param array $columnDef
*
* @return string * @return string
*/ */
abstract public function getBooleanTypeDeclarationSQL(array $columnDef); abstract public function getBooleanTypeDeclarationSQL(array $columnDef);
...@@ -150,6 +152,7 @@ abstract class AbstractPlatform ...@@ -150,6 +152,7 @@ abstract class AbstractPlatform
* Gets the SQL snippet that declares a 4 byte integer column. * Gets the SQL snippet that declares a 4 byte integer column.
* *
* @param array $columnDef * @param array $columnDef
*
* @return string * @return string
*/ */
abstract public function getIntegerTypeDeclarationSQL(array $columnDef); abstract public function getIntegerTypeDeclarationSQL(array $columnDef);
...@@ -158,6 +161,7 @@ abstract class AbstractPlatform ...@@ -158,6 +161,7 @@ abstract class AbstractPlatform
* Gets the SQL snippet that declares an 8 byte integer column. * Gets the SQL snippet that declares an 8 byte integer column.
* *
* @param array $columnDef * @param array $columnDef
*
* @return string * @return string
*/ */
abstract public function getBigIntTypeDeclarationSQL(array $columnDef); abstract public function getBigIntTypeDeclarationSQL(array $columnDef);
...@@ -166,6 +170,7 @@ abstract class AbstractPlatform ...@@ -166,6 +170,7 @@ abstract class AbstractPlatform
* Gets the SQL snippet that declares a 2 byte integer column. * Gets the SQL snippet that declares a 2 byte integer column.
* *
* @param array $columnDef * @param array $columnDef
*
* @return string * @return string
*/ */
abstract public function getSmallIntTypeDeclarationSQL(array $columnDef); abstract public function getSmallIntTypeDeclarationSQL(array $columnDef);
...@@ -204,6 +209,8 @@ abstract class AbstractPlatform ...@@ -204,6 +209,8 @@ abstract class AbstractPlatform
* Gets the SQL snippet used to declare a VARCHAR column type. * Gets the SQL snippet used to declare a VARCHAR column type.
* *
* @param array $field * @param array $field
*
* @return string
*/ */
public function getVarcharTypeDeclarationSQL(array $field) public function getVarcharTypeDeclarationSQL(array $field)
{ {
...@@ -215,9 +222,9 @@ abstract class AbstractPlatform ...@@ -215,9 +222,9 @@ abstract class AbstractPlatform
if ($field['length'] > $this->getVarcharMaxLength()) { if ($field['length'] > $this->getVarcharMaxLength()) {
return $this->getClobTypeDeclarationSQL($field); return $this->getClobTypeDeclarationSQL($field);
} else {
return $this->getVarcharTypeDeclarationSQLSnippet($field['length'], $fixed);
} }
return $this->getVarcharTypeDeclarationSQLSnippet($field['length'], $fixed);
} }
/** /**
...@@ -227,6 +234,7 @@ abstract class AbstractPlatform ...@@ -227,6 +234,7 @@ abstract class AbstractPlatform
* special datatypes when the underlying databases support this datatype. * special datatypes when the underlying databases support this datatype.
* *
* @param array $field * @param array $field
*
* @return string * @return string
*/ */
public function getGuidTypeDeclarationSQL(array $field) public function getGuidTypeDeclarationSQL(array $field)
...@@ -234,6 +242,14 @@ abstract class AbstractPlatform ...@@ -234,6 +242,14 @@ abstract class AbstractPlatform
return $this->getVarcharTypeDeclarationSQL($field); return $this->getVarcharTypeDeclarationSQL($field);
} }
/**
* @param integer $length
* @param boolean $fixed
*
* @return string
*
* @throws \Doctrine\DBAL\DBALException
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{ {
throw DBALException::notSupported('VARCHARs not supported by Platform.'); throw DBALException::notSupported('VARCHARs not supported by Platform.');
...@@ -243,6 +259,8 @@ abstract class AbstractPlatform ...@@ -243,6 +259,8 @@ abstract class AbstractPlatform
* Gets the SQL snippet used to declare a CLOB column type. * Gets the SQL snippet used to declare a CLOB column type.
* *
* @param array $field * @param array $field
*
* @return string
*/ */
abstract public function getClobTypeDeclarationSQL(array $field); abstract public function getClobTypeDeclarationSQL(array $field);
...@@ -250,6 +268,8 @@ abstract class AbstractPlatform ...@@ -250,6 +268,8 @@ abstract class AbstractPlatform
* Gets the SQL Snippet used to declare a BLOB column type. * Gets the SQL Snippet used to declare a BLOB column type.
* *
* @param array $field * @param array $field
*
* @return string
*/ */
abstract public function getBlobTypeDeclarationSQL(array $field); abstract public function getBlobTypeDeclarationSQL(array $field);
...@@ -265,6 +285,8 @@ abstract class AbstractPlatform ...@@ -265,6 +285,8 @@ abstract class AbstractPlatform
* *
* @param string $dbType * @param string $dbType
* @param string $doctrineType * @param string $doctrineType
*
* @throws \Doctrine\DBAL\DBALException if the type is not found
*/ */
public function registerDoctrineTypeMapping($dbType, $doctrineType) public function registerDoctrineTypeMapping($dbType, $doctrineType)
{ {
...@@ -284,6 +306,7 @@ abstract class AbstractPlatform ...@@ -284,6 +306,7 @@ abstract class AbstractPlatform
* Get the Doctrine type that is mapped for the given database column type. * Get the Doctrine type that is mapped for the given database column type.
* *
* @param string $dbType * @param string $dbType
*
* @return string * @return string
*/ */
public function getDoctrineTypeMapping($dbType) public function getDoctrineTypeMapping($dbType)
...@@ -293,6 +316,7 @@ abstract class AbstractPlatform ...@@ -293,6 +316,7 @@ abstract class AbstractPlatform
} }
$dbType = strtolower($dbType); $dbType = strtolower($dbType);
if (!isset($this->doctrineTypeMapping[$dbType])) { if (!isset($this->doctrineTypeMapping[$dbType])) {
throw new \Doctrine\DBAL\DBALException("Unknown database type ".$dbType." requested, " . get_class($this) . " may not support it."); throw new \Doctrine\DBAL\DBALException("Unknown database type ".$dbType." requested, " . get_class($this) . " may not support it.");
} }
...@@ -304,7 +328,8 @@ abstract class AbstractPlatform ...@@ -304,7 +328,8 @@ abstract class AbstractPlatform
* Check if a database type is currently supported by this platform. * Check if a database type is currently supported by this platform.
* *
* @param string $dbType * @param string $dbType
* @return bool *
* @return boolean
*/ */
public function hasDoctrineTypeMappingFor($dbType) public function hasDoctrineTypeMappingFor($dbType)
{ {
...@@ -338,6 +363,7 @@ abstract class AbstractPlatform ...@@ -338,6 +363,7 @@ abstract class AbstractPlatform
* Is it necessary for the platform to add a parsable type comment to allow reverse engineering the given type? * Is it necessary for the platform to add a parsable type comment to allow reverse engineering the given type?
* *
* @param Type $doctrineType * @param Type $doctrineType
*
* @return boolean * @return boolean
*/ */
public function isCommentedDoctrineType(Type $doctrineType) public function isCommentedDoctrineType(Type $doctrineType)
...@@ -353,6 +379,7 @@ abstract class AbstractPlatform ...@@ -353,6 +379,7 @@ abstract class AbstractPlatform
* Mark this type as to be commented in ALTER TABLE and CREATE TABLE statements. * Mark this type as to be commented in ALTER TABLE and CREATE TABLE statements.
* *
* @param string|Type $doctrineType * @param string|Type $doctrineType
*
* @return void * @return void
*/ */
public function markDoctrineTypeCommented($doctrineType) public function markDoctrineTypeCommented($doctrineType)
...@@ -360,6 +387,7 @@ abstract class AbstractPlatform ...@@ -360,6 +387,7 @@ abstract class AbstractPlatform
if ($this->doctrineTypeComments === null) { if ($this->doctrineTypeComments === null) {
$this->initializeCommentedDoctrineTypes(); $this->initializeCommentedDoctrineTypes();
} }
$this->doctrineTypeComments[] = $doctrineType instanceof Type ? $doctrineType->getName() : $doctrineType; $this->doctrineTypeComments[] = $doctrineType instanceof Type ? $doctrineType->getName() : $doctrineType;
} }
...@@ -383,9 +411,11 @@ abstract class AbstractPlatform ...@@ -383,9 +411,11 @@ abstract class AbstractPlatform
protected function getColumnComment(Column $column) protected function getColumnComment(Column $column)
{ {
$comment = $column->getComment(); $comment = $column->getComment();
if ($this->isCommentedDoctrineType($column->getType())) { if ($this->isCommentedDoctrineType($column->getType())) {
$comment .= $this->getDoctrineTypeComment($column->getType()); $comment .= $this->getDoctrineTypeComment($column->getType());
} }
return $comment; return $comment;
} }
...@@ -473,6 +503,7 @@ abstract class AbstractPlatform ...@@ -473,6 +503,7 @@ abstract class AbstractPlatform
* Returns the average value of a column * Returns the average value of a column
* *
* @param string $column the column to use * @param string $column the column to use
*
* @return string generated sql including an AVG aggregate function * @return string generated sql including an AVG aggregate function
*/ */
public function getAvgExpression($column) public function getAvgExpression($column)
...@@ -487,6 +518,7 @@ abstract class AbstractPlatform ...@@ -487,6 +518,7 @@ abstract class AbstractPlatform
* is returned. * is returned.
* *
* @param string|integer $column the column to use * @param string|integer $column the column to use
*
* @return string generated sql including a COUNT aggregate function * @return string generated sql including a COUNT aggregate function
*/ */
public function getCountExpression($column) public function getCountExpression($column)
...@@ -546,6 +578,7 @@ abstract class AbstractPlatform ...@@ -546,6 +578,7 @@ abstract class AbstractPlatform
* Returns the length of a text field. * Returns the length of a text field.
* *
* @param string $column * @param string $column
*
* @return string * @return string
*/ */
public function getLengthExpression($column) public function getLengthExpression($column)
...@@ -557,6 +590,7 @@ abstract class AbstractPlatform ...@@ -557,6 +590,7 @@ abstract class AbstractPlatform
* Returns the squared value of a column * Returns the squared value of a column
* *
* @param string $column the column to use * @param string $column the column to use
*
* @return string generated sql including an SQRT aggregate function * @return string generated sql including an SQRT aggregate function
*/ */
public function getSqrtExpression($column) public function getSqrtExpression($column)
...@@ -569,6 +603,7 @@ abstract class AbstractPlatform ...@@ -569,6 +603,7 @@ abstract class AbstractPlatform
* *
* @param string $column * @param string $column
* @param integer $decimals * @param integer $decimals
*
* @return string * @return string
*/ */
public function getRoundExpression($column, $decimals = 0) public function getRoundExpression($column, $decimals = 0)
...@@ -582,6 +617,7 @@ abstract class AbstractPlatform ...@@ -582,6 +617,7 @@ abstract class AbstractPlatform
* *
* @param string $expression1 * @param string $expression1
* @param string $expression2 * @param string $expression2
*
* @return string * @return string
*/ */
public function getModExpression($expression1, $expression2) public function getModExpression($expression1, $expression2)
...@@ -593,8 +629,9 @@ abstract class AbstractPlatform ...@@ -593,8 +629,9 @@ abstract class AbstractPlatform
* Trim a string, leading/trailing/both and with a given char which defaults to space. * Trim a string, leading/trailing/both and with a given char which defaults to space.
* *
* @param string $str * @param string $str
* @param int $pos * @param integer $pos
* @param string $char has to be quoted already * @param string $char has to be quoted already
*
* @return string * @return string
*/ */
public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false) public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false)
...@@ -602,12 +639,18 @@ abstract class AbstractPlatform ...@@ -602,12 +639,18 @@ abstract class AbstractPlatform
$posStr = ''; $posStr = '';
$trimChar = ($char != false) ? $char . ' FROM ' : ''; $trimChar = ($char != false) ? $char . ' FROM ' : '';
if ($pos == self::TRIM_LEADING) { switch ($pos) {
case self::TRIM_LEADING:
$posStr = 'LEADING '.$trimChar; $posStr = 'LEADING '.$trimChar;
} else if($pos == self::TRIM_TRAILING) { break;
case self::TRIM_TRAILING:
$posStr = 'TRAILING '.$trimChar; $posStr = 'TRAILING '.$trimChar;
} else if($pos == self::TRIM_BOTH) { break;
case self::TRIM_BOTH:
$posStr = 'BOTH '.$trimChar; $posStr = 'BOTH '.$trimChar;
break;
} }
return 'TRIM(' . $posStr . $str . ')'; return 'TRIM(' . $posStr . $str . ')';
...@@ -618,6 +661,7 @@ abstract class AbstractPlatform ...@@ -618,6 +661,7 @@ abstract class AbstractPlatform
* returns the string $str with proceeding space characters removed * returns the string $str with proceeding space characters removed
* *
* @param string $str literal string or column name * @param string $str literal string or column name
*
* @return string * @return string
*/ */
public function getRtrimExpression($str) public function getRtrimExpression($str)
...@@ -630,6 +674,7 @@ abstract class AbstractPlatform ...@@ -630,6 +674,7 @@ abstract class AbstractPlatform
* returns the string $str with leading space characters removed * returns the string $str with leading space characters removed
* *
* @param string $str literal string or column name * @param string $str literal string or column name
*
* @return string * @return string
*/ */
public function getLtrimExpression($str) public function getLtrimExpression($str)
...@@ -643,6 +688,7 @@ abstract class AbstractPlatform ...@@ -643,6 +688,7 @@ abstract class AbstractPlatform
* uppercase according to the current character set mapping. * uppercase according to the current character set mapping.
* *
* @param string $str literal string or column name * @param string $str literal string or column name
*
* @return string * @return string
*/ */
public function getUpperExpression($str) public function getUpperExpression($str)
...@@ -656,6 +702,7 @@ abstract class AbstractPlatform ...@@ -656,6 +702,7 @@ abstract class AbstractPlatform
* lowercase according to the current character set mapping. * lowercase according to the current character set mapping.
* *
* @param string $str literal string or column name * @param string $str literal string or column name
*
* @return string * @return string
*/ */
public function getLowerExpression($str) public function getLowerExpression($str)
...@@ -669,7 +716,8 @@ abstract class AbstractPlatform ...@@ -669,7 +716,8 @@ abstract class AbstractPlatform
* @param string $str literal string * @param string $str literal string
* @param string $substr literal string to find * @param string $substr literal string to find
* @param integer $startPos position to start at, beginning of string by default * @param integer $startPos position to start at, beginning of string by default
* @return integer *
* @return string
*/ */
public function getLocateExpression($str, $substr, $startPos = false) public function getLocateExpression($str, $substr, $startPos = false)
{ {
...@@ -695,16 +743,17 @@ abstract class AbstractPlatform ...@@ -695,16 +743,17 @@ abstract class AbstractPlatform
* *
* @param string $value an sql string literal or column name/alias * @param string $value an sql string literal or column name/alias
* @param integer $from where to start the substring portion * @param integer $from where to start the substring portion
* @param integer $len the substring portion length * @param integer $length the substring portion length
*
* @return string * @return string
*/ */
public function getSubstringExpression($value, $from, $len = null) public function getSubstringExpression($value, $from, $length = null)
{ {
if ($len === null) if ($length === null) {
return 'SUBSTRING(' . $value . ' FROM ' . $from . ')'; return 'SUBSTRING(' . $value . ' FROM ' . $from . ')';
else {
return 'SUBSTRING(' . $value . ' FROM ' . $from . ' FOR ' . $len . ')';
} }
return 'SUBSTRING(' . $value . ' FROM ' . $from . ' FOR ' . $length . ')';
} }
/** /**
...@@ -714,6 +763,7 @@ abstract class AbstractPlatform ...@@ -714,6 +763,7 @@ abstract class AbstractPlatform
* must contain an expression * must contain an expression
* *
* @param string $arg1, $arg2 ... $argN strings that will be concatenated. * @param string $arg1, $arg2 ... $argN strings that will be concatenated.
*
* @return string * @return string
*/ */
public function getConcatExpression() public function getConcatExpression()
...@@ -733,6 +783,7 @@ abstract class AbstractPlatform ...@@ -733,6 +783,7 @@ abstract class AbstractPlatform
* </code> * </code>
* *
* @param string $expression * @param string $expression
*
* @return string a logical expression * @return string a logical expression
*/ */
public function getNotExpression($expression) public function getNotExpression($expression)
...@@ -750,7 +801,8 @@ abstract class AbstractPlatform ...@@ -750,7 +801,8 @@ abstract class AbstractPlatform
* These expressions will be matched against the first parameter. * These expressions will be matched against the first parameter.
* *
* @param string $column the value that should be matched against * @param string $column the value that should be matched against
* @param string|array(string) $values values that will be matched against $column * @param string|array<string> $values values that will be matched against $column
*
* @return string logical expression * @return string logical expression
*/ */
public function getInExpression($column, $values) public function getInExpression($column, $values)
...@@ -758,11 +810,14 @@ abstract class AbstractPlatform ...@@ -758,11 +810,14 @@ abstract class AbstractPlatform
if ( ! is_array($values)) { if ( ! is_array($values)) {
$values = array($values); $values = array($values);
} }
// TODO: fix this code: the method does not exist
$values = $this->getIdentifiers($values); $values = $this->getIdentifiers($values);
if (count($values) == 0) { if (count($values) == 0) {
throw new \InvalidArgumentException('Values must not be empty.'); throw new \InvalidArgumentException('Values must not be empty.');
} }
return $column . ' IN (' . implode(', ', $values) . ')'; return $column . ' IN (' . implode(', ', $values) . ')';
} }
...@@ -770,6 +825,7 @@ abstract class AbstractPlatform ...@@ -770,6 +825,7 @@ abstract class AbstractPlatform
* Returns SQL that checks if a expression is null. * Returns SQL that checks if a expression is null.
* *
* @param string $expression the expression that should be compared to null * @param string $expression the expression that should be compared to null
*
* @return string logical expression * @return string logical expression
*/ */
public function getIsNullExpression($expression) public function getIsNullExpression($expression)
...@@ -781,6 +837,7 @@ abstract class AbstractPlatform ...@@ -781,6 +837,7 @@ abstract class AbstractPlatform
* Returns SQL that checks if a expression is not null. * Returns SQL that checks if a expression is not null.
* *
* @param string $expression the expression that should be compared to null * @param string $expression the expression that should be compared to null
*
* @return string logical expression * @return string logical expression
*/ */
public function getIsNotNullExpression($expression) public function getIsNotNullExpression($expression)
...@@ -801,6 +858,7 @@ abstract class AbstractPlatform ...@@ -801,6 +858,7 @@ abstract class AbstractPlatform
* @param string $expression the value to compare to * @param string $expression the value to compare to
* @param string $value1 the lower value to compare with * @param string $value1 the lower value to compare with
* @param string $value2 the higher value to compare with * @param string $value2 the higher value to compare with
*
* @return string logical expression * @return string logical expression
*/ */
public function getBetweenExpression($expression, $value1, $value2) public function getBetweenExpression($expression, $value1, $value2)
...@@ -835,6 +893,7 @@ abstract class AbstractPlatform ...@@ -835,6 +893,7 @@ abstract class AbstractPlatform
* *
* @param string $date1 * @param string $date1
* @param string $date2 * @param string $date2
*
* @return string * @return string
*/ */
public function getDateDiffExpression($date1, $date2) public function getDateDiffExpression($date1, $date2)
...@@ -846,7 +905,8 @@ abstract class AbstractPlatform ...@@ -846,7 +905,8 @@ abstract class AbstractPlatform
* Add the number of given days to a date. * Add the number of given days to a date.
* *
* @param string $date * @param string $date
* @param int $days * @param integer $days
*
* @return string * @return string
*/ */
public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
...@@ -858,7 +918,8 @@ abstract class AbstractPlatform ...@@ -858,7 +918,8 @@ abstract class AbstractPlatform
* Substract the number of given days to a date. * Substract the number of given days to a date.
* *
* @param string $date * @param string $date
* @param int $days * @param integer $days
*
* @return string * @return string
*/ */
public function getDateSubDaysExpression($date, $days) public function getDateSubDaysExpression($date, $days)
...@@ -870,7 +931,8 @@ abstract class AbstractPlatform ...@@ -870,7 +931,8 @@ abstract class AbstractPlatform
* Add the number of given months to a date. * Add the number of given months to a date.
* *
* @param string $date * @param string $date
* @param int $months * @param integer $months
*
* @return string * @return string
*/ */
public function getDateAddMonthExpression($date, $months) public function getDateAddMonthExpression($date, $months)
...@@ -882,7 +944,8 @@ abstract class AbstractPlatform ...@@ -882,7 +944,8 @@ abstract class AbstractPlatform
* Substract the number of given months to a date. * Substract the number of given months to a date.
* *
* @param string $date * @param string $date
* @param int $months * @param integer $months
*
* @return string * @return string
*/ */
public function getDateSubMonthExpression($date, $months) public function getDateSubMonthExpression($date, $months)
...@@ -895,6 +958,7 @@ abstract class AbstractPlatform ...@@ -895,6 +958,7 @@ abstract class AbstractPlatform
* *
* @param string $value1 * @param string $value1
* @param string $value2 * @param string $value2
*
* @return string * @return string
*/ */
public function getBitAndComparisonExpression($value1, $value2) public function getBitAndComparisonExpression($value1, $value2)
...@@ -907,6 +971,7 @@ abstract class AbstractPlatform ...@@ -907,6 +971,7 @@ abstract class AbstractPlatform
* *
* @param string $value1 * @param string $value1
* @param string $value2 * @param string $value2
*
* @return string * @return string
*/ */
public function getBitOrComparisonExpression($value1, $value2) public function getBitOrComparisonExpression($value1, $value2)
...@@ -923,7 +988,8 @@ abstract class AbstractPlatform ...@@ -923,7 +988,8 @@ abstract class AbstractPlatform
* Honors that some SQL vendors such as MsSql use table hints for locking instead of the ANSI SQL FOR UPDATE specification. * Honors that some SQL vendors such as MsSql use table hints for locking instead of the ANSI SQL FOR UPDATE specification.
* *
* @param string $fromClause * @param string $fromClause
* @param int $lockMode * @param integer $lockMode
*
* @return string * @return string
*/ */
public function appendLockHint($fromClause, $lockMode) public function appendLockHint($fromClause, $lockMode)
...@@ -956,6 +1022,13 @@ abstract class AbstractPlatform ...@@ -956,6 +1022,13 @@ abstract class AbstractPlatform
return $this->getForUpdateSQL(); return $this->getForUpdateSQL();
} }
/**
* Get the SQL snippet to drop an existing database
*
* @param string $database name of the database that should be dropped
*
* @return string
*/
public function getDropDatabaseSQL($database) public function getDropDatabaseSQL($database)
{ {
return 'DROP DATABASE ' . $database; return 'DROP DATABASE ' . $database;
...@@ -965,14 +1038,16 @@ abstract class AbstractPlatform ...@@ -965,14 +1038,16 @@ abstract class AbstractPlatform
* Drop a Table * Drop a Table
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*
* @param Table|string $table * @param Table|string $table
*
* @return string * @return string
*/ */
public function getDropTableSQL($table) public function getDropTableSQL($table)
{ {
$tableArg = $table; $tableArg = $table;
if ($table instanceof \Doctrine\DBAL\Schema\Table) { if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} else if(!is_string($table)) { } else if(!is_string($table)) {
throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
...@@ -994,6 +1069,7 @@ abstract class AbstractPlatform ...@@ -994,6 +1069,7 @@ abstract class AbstractPlatform
* Get SQL to safely drop a temporary table WITHOUT implicitly committing an open transaction. * Get SQL to safely drop a temporary table WITHOUT implicitly committing an open transaction.
* *
* @param Table|string $table * @param Table|string $table
*
* @return string * @return string
*/ */
public function getDropTemporaryTableSQL($table) public function getDropTemporaryTableSQL($table)
...@@ -1006,11 +1082,12 @@ abstract class AbstractPlatform ...@@ -1006,11 +1082,12 @@ abstract class AbstractPlatform
* *
* @param Index|string $name * @param Index|string $name
* @param string|Table $table * @param string|Table $table
*
* @return string * @return string
*/ */
public function getDropIndexSQL($index, $table=null) public function getDropIndexSQL($index, $table = null)
{ {
if($index instanceof \Doctrine\DBAL\Schema\Index) { if ($index instanceof Index) {
$index = $index->getQuotedName($this); $index = $index->getQuotedName($this);
} else if(!is_string($index)) { } else if(!is_string($index)) {
throw new \InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); throw new \InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
...@@ -1024,15 +1101,16 @@ abstract class AbstractPlatform ...@@ -1024,15 +1101,16 @@ abstract class AbstractPlatform
* *
* @param \Doctrine\DBAL\Schema\Constraint $constraint * @param \Doctrine\DBAL\Schema\Constraint $constraint
* @param string|Table $table * @param string|Table $table
*
* @return string * @return string
*/ */
public function getDropConstraintSQL($constraint, $table) public function getDropConstraintSQL($constraint, $table)
{ {
if ($constraint instanceof \Doctrine\DBAL\Schema\Constraint) { if ($constraint instanceof Constraint) {
$constraint = $constraint->getQuotedName($this); $constraint = $constraint->getQuotedName($this);
} }
if ($table instanceof \Doctrine\DBAL\Schema\Table) { if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} }
...@@ -1042,15 +1120,16 @@ abstract class AbstractPlatform ...@@ -1042,15 +1120,16 @@ abstract class AbstractPlatform
/** /**
* @param ForeignKeyConstraint|string $foreignKey * @param ForeignKeyConstraint|string $foreignKey
* @param Table|string $table * @param Table|string $table
*
* @return string * @return string
*/ */
public function getDropForeignKeySQL($foreignKey, $table) public function getDropForeignKeySQL($foreignKey, $table)
{ {
if ($foreignKey instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) { if ($foreignKey instanceof ForeignKeyConstraint) {
$foreignKey = $foreignKey->getQuotedName($this); $foreignKey = $foreignKey->getQuotedName($this);
} }
if ($table instanceof \Doctrine\DBAL\Schema\Table) { if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} }
...@@ -1062,16 +1141,17 @@ abstract class AbstractPlatform ...@@ -1062,16 +1141,17 @@ abstract class AbstractPlatform
* on this platform. * on this platform.
* *
* @param string $table The name of the table. * @param string $table The name of the table.
* @param int $createFlags * @param integer $createFlags
*
* @return array The sequence of SQL statements. * @return array The sequence of SQL statements.
*/ */
public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXES) public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES)
{ {
if ( ! is_int($createFlags)) { if ( ! is_int($createFlags)) {
throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSQL() has to be integer."); throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSQL() has to be integer.");
} }
if (count($table->getColumns()) == 0) { if (count($table->getColumns()) === 0) {
throw DBALException::noColumnsSpecifiedForTable($table->getName()); throw DBALException::noColumnsSpecifiedForTable($table->getName());
} }
...@@ -1095,6 +1175,7 @@ abstract class AbstractPlatform ...@@ -1095,6 +1175,7 @@ abstract class AbstractPlatform
$columnSql = array(); $columnSql = array();
$columns = array(); $columns = array();
foreach ($table->getColumns() as $column) { foreach ($table->getColumns() as $column) {
/* @var \Doctrine\DBAL\Schema\Column $column */ /* @var \Doctrine\DBAL\Schema\Column $column */
...@@ -1116,10 +1197,12 @@ abstract class AbstractPlatform ...@@ -1116,10 +1197,12 @@ abstract class AbstractPlatform
$columnData['notnull'] = $column->getNotNull(); $columnData['notnull'] = $column->getNotNull();
$columnData['fixed'] = $column->getFixed(); $columnData['fixed'] = $column->getFixed();
$columnData['unique'] = false; // TODO: what do we do about this? $columnData['unique'] = false; // TODO: what do we do about this?
$columnData['version'] = ($column->hasPlatformOption("version"))?$column->getPlatformOption('version'):false; $columnData['version'] = $column->hasPlatformOption("version") ? $column->getPlatformOption('version') : false;
if(strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
if (strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
$columnData['length'] = 255; $columnData['length'] = 255;
} }
$columnData['unsigned'] = $column->getUnsigned(); $columnData['unsigned'] = $column->getUnsigned();
$columnData['precision'] = $column->getPrecision(); $columnData['precision'] = $column->getPrecision();
$columnData['scale'] = $column->getScale(); $columnData['scale'] = $column->getScale();
...@@ -1128,7 +1211,7 @@ abstract class AbstractPlatform ...@@ -1128,7 +1211,7 @@ abstract class AbstractPlatform
$columnData['autoincrement'] = $column->getAutoincrement(); $columnData['autoincrement'] = $column->getAutoincrement();
$columnData['comment'] = $this->getColumnComment($column); $columnData['comment'] = $this->getColumnComment($column);
if(in_array($column->getName(), $options['primary'])) { if (in_array($column->getName(), $options['primary'])) {
$columnData['primary'] = true; $columnData['primary'] = true;
} }
...@@ -1169,9 +1252,12 @@ abstract class AbstractPlatform ...@@ -1169,9 +1252,12 @@ abstract class AbstractPlatform
} }
/** /**
* Gets the SQL used to create a table.
*
* @param string $tableName * @param string $tableName
* @param array $columns * @param array $columns
* @param array $options * @param array $options
*
* @return array * @return array
*/ */
protected function _getCreateTableSQL($tableName, array $columns, array $options = array()) protected function _getCreateTableSQL($tableName, array $columns, array $options = array())
...@@ -1222,9 +1308,12 @@ abstract class AbstractPlatform ...@@ -1222,9 +1308,12 @@ abstract class AbstractPlatform
* Gets the SQL to create a sequence on this platform. * Gets the SQL to create a sequence on this platform.
* *
* @param \Doctrine\DBAL\Schema\Sequence $sequence * @param \Doctrine\DBAL\Schema\Sequence $sequence
*
* @return string
*
* @throws DBALException * @throws DBALException
*/ */
public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence) public function getCreateSequenceSQL(Sequence $sequence)
{ {
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
} }
...@@ -1233,9 +1322,10 @@ abstract class AbstractPlatform ...@@ -1233,9 +1322,10 @@ abstract class AbstractPlatform
* Gets the SQL statement to change a sequence on this platform. * Gets the SQL statement to change a sequence on this platform.
* *
* @param \Doctrine\DBAL\Schema\Sequence $sequence * @param \Doctrine\DBAL\Schema\Sequence $sequence
*
* @return string * @return string
*/ */
public function getAlterSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence) public function getAlterSequenceSQL(Sequence $sequence)
{ {
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
} }
...@@ -1245,11 +1335,12 @@ abstract class AbstractPlatform ...@@ -1245,11 +1335,12 @@ abstract class AbstractPlatform
* *
* @param \Doctrine\DBAL\Schema\Constraint $constraint * @param \Doctrine\DBAL\Schema\Constraint $constraint
* @param string|Table $table * @param string|Table $table
*
* @return string * @return string
*/ */
public function getCreateConstraintSQL(\Doctrine\DBAL\Schema\Constraint $constraint, $table) public function getCreateConstraintSQL(Constraint $constraint, $table)
{ {
if ($table instanceof \Doctrine\DBAL\Schema\Table) { if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} }
...@@ -1262,7 +1353,7 @@ abstract class AbstractPlatform ...@@ -1262,7 +1353,7 @@ abstract class AbstractPlatform
$columnList = '('. implode(', ', $columns) . ')'; $columnList = '('. implode(', ', $columns) . ')';
$referencesClause = ''; $referencesClause = '';
if ($constraint instanceof \Doctrine\DBAL\Schema\Index) { if ($constraint instanceof Index) {
if($constraint->isPrimary()) { if($constraint->isPrimary()) {
$query .= ' PRIMARY KEY'; $query .= ' PRIMARY KEY';
} elseif ($constraint->isUnique()) { } elseif ($constraint->isUnique()) {
...@@ -1272,7 +1363,7 @@ abstract class AbstractPlatform ...@@ -1272,7 +1363,7 @@ abstract class AbstractPlatform
'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().' 'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().'
); );
} }
} else if ($constraint instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) { } else if ($constraint instanceof ForeignKeyConstraint) {
$query .= ' FOREIGN KEY'; $query .= ' FOREIGN KEY';
$foreignColumns = array(); $foreignColumns = array();
...@@ -1292,6 +1383,7 @@ abstract class AbstractPlatform ...@@ -1292,6 +1383,7 @@ abstract class AbstractPlatform
* *
* @param Index $index * @param Index $index
* @param string|Table $table name of the table on which the index is to be created * @param string|Table $table name of the table on which the index is to be created
*
* @return string * @return string
*/ */
public function getCreateIndexSQL(Index $index, $table) public function getCreateIndexSQL(Index $index, $table)
...@@ -1308,11 +1400,10 @@ abstract class AbstractPlatform ...@@ -1308,11 +1400,10 @@ abstract class AbstractPlatform
if ($index->isPrimary()) { if ($index->isPrimary()) {
return $this->getCreatePrimaryKeySQL($index, $table); return $this->getCreatePrimaryKeySQL($index, $table);
} else { }
$query = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table; $query = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table;
$query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')'; $query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')';
}
return $query; return $query;
} }
...@@ -1321,15 +1412,12 @@ abstract class AbstractPlatform ...@@ -1321,15 +1412,12 @@ abstract class AbstractPlatform
* Adds additional flags for index generation * Adds additional flags for index generation
* *
* @param Index $index * @param Index $index
*
* @return string * @return string
*/ */
protected function getCreateIndexSQLFlags(Index $index) protected function getCreateIndexSQLFlags(Index $index)
{ {
$type = ''; return $index->isUnique() ? 'UNIQUE ' : '';
if ($index->isUnique()) {
$type = 'UNIQUE ';
}
return $type;
} }
/** /**
...@@ -1337,6 +1425,7 @@ abstract class AbstractPlatform ...@@ -1337,6 +1425,7 @@ abstract class AbstractPlatform
* *
* @param Index $index * @param Index $index
* @param string|Table $table * @param string|Table $table
*
* @return string * @return string
*/ */
public function getCreatePrimaryKeySQL(Index $index, $table) public function getCreatePrimaryKeySQL(Index $index, $table)
...@@ -1354,12 +1443,14 @@ abstract class AbstractPlatform ...@@ -1354,12 +1443,14 @@ abstract class AbstractPlatform
* problems than they solve. * problems than they solve.
* *
* @param string $str identifier name to be quoted * @param string $str identifier name to be quoted
*
* @return string quoted identifier string * @return string quoted identifier string
*/ */
public function quoteIdentifier($str) public function quoteIdentifier($str)
{ {
if (strpos($str, ".") !== false) { if (strpos($str, ".") !== false) {
$parts = array_map(array($this, "quoteIdentifier"), explode(".", $str)); $parts = array_map(array($this, "quoteIdentifier"), explode(".", $str));
return implode(".", $parts); return implode(".", $parts);
} }
...@@ -1370,6 +1461,7 @@ abstract class AbstractPlatform ...@@ -1370,6 +1461,7 @@ abstract class AbstractPlatform
* Quote a single identifier (no dot chain separation) * Quote a single identifier (no dot chain separation)
* *
* @param string $str * @param string $str
*
* @return string * @return string
*/ */
public function quoteSingleIdentifier($str) public function quoteSingleIdentifier($str)
...@@ -1384,11 +1476,12 @@ abstract class AbstractPlatform ...@@ -1384,11 +1476,12 @@ abstract class AbstractPlatform
* *
* @param ForeignKeyConstraint $foreignKey ForeignKey instance * @param ForeignKeyConstraint $foreignKey ForeignKey instance
* @param string|Table $table name of the table on which the foreign key is to be created * @param string|Table $table name of the table on which the foreign key is to be created
*
* @return string * @return string
*/ */
public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
{ {
if ($table instanceof \Doctrine\DBAL\Schema\Table) { if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} }
...@@ -1403,6 +1496,7 @@ abstract class AbstractPlatform ...@@ -1403,6 +1496,7 @@ abstract class AbstractPlatform
* The method returns an array of sql statements, since some platforms need several statements. * The method returns an array of sql statements, since some platforms need several statements.
* *
* @param TableDiff $diff * @param TableDiff $diff
*
* @return array * @return array
*/ */
public function getAlterTableSQL(TableDiff $diff) public function getAlterTableSQL(TableDiff $diff)
...@@ -1414,6 +1508,7 @@ abstract class AbstractPlatform ...@@ -1414,6 +1508,7 @@ abstract class AbstractPlatform
* @param Column $column * @param Column $column
* @param TableDiff $diff * @param TableDiff $diff
* @param array $columnSql * @param array $columnSql
*
* @return boolean * @return boolean
*/ */
protected function onSchemaAlterTableAddColumn(Column $column, TableDiff $diff, &$columnSql) protected function onSchemaAlterTableAddColumn(Column $column, TableDiff $diff, &$columnSql)
...@@ -1438,6 +1533,7 @@ abstract class AbstractPlatform ...@@ -1438,6 +1533,7 @@ abstract class AbstractPlatform
* @param Column $column * @param Column $column
* @param TableDiff $diff * @param TableDiff $diff
* @param array $columnSql * @param array $columnSql
*
* @return boolean * @return boolean
*/ */
protected function onSchemaAlterTableRemoveColumn(Column $column, TableDiff $diff, &$columnSql) protected function onSchemaAlterTableRemoveColumn(Column $column, TableDiff $diff, &$columnSql)
...@@ -1462,6 +1558,7 @@ abstract class AbstractPlatform ...@@ -1462,6 +1558,7 @@ abstract class AbstractPlatform
* @param ColumnDiff $columnDiff * @param ColumnDiff $columnDiff
* @param TableDiff $diff * @param TableDiff $diff
* @param array $columnSql * @param array $columnSql
*
* @return boolean * @return boolean
*/ */
protected function onSchemaAlterTableChangeColumn(ColumnDiff $columnDiff, TableDiff $diff, &$columnSql) protected function onSchemaAlterTableChangeColumn(ColumnDiff $columnDiff, TableDiff $diff, &$columnSql)
...@@ -1487,6 +1584,7 @@ abstract class AbstractPlatform ...@@ -1487,6 +1584,7 @@ abstract class AbstractPlatform
* @param Column $column * @param Column $column
* @param TableDiff $diff * @param TableDiff $diff
* @param array $columnSql * @param array $columnSql
*
* @return boolean * @return boolean
*/ */
protected function onSchemaAlterTableRenameColumn($oldColumnName, Column $column, TableDiff $diff, &$columnSql) protected function onSchemaAlterTableRenameColumn($oldColumnName, Column $column, TableDiff $diff, &$columnSql)
...@@ -1506,9 +1604,11 @@ abstract class AbstractPlatform ...@@ -1506,9 +1604,11 @@ abstract class AbstractPlatform
return $eventArgs->isDefaultPrevented(); return $eventArgs->isDefaultPrevented();
} }
/** /**
* @param TableDiff $diff * @param TableDiff $diff
* @param array $qql * @param array $sql
*
* @return boolean * @return boolean
*/ */
protected function onSchemaAlterTable(TableDiff $diff, &$sql) protected function onSchemaAlterTable(TableDiff $diff, &$sql)
...@@ -1555,11 +1655,7 @@ abstract class AbstractPlatform ...@@ -1555,11 +1655,7 @@ abstract class AbstractPlatform
protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
{ {
if ($diff->newName !== false) { $tableName = false !== $diff->newName ? $diff->newName : $diff->name;
$tableName = $diff->newName;
} else {
$tableName = $diff->name;
}
$sql = array(); $sql = array();
if ($this->supportsForeignKeyConstraints()) { if ($this->supportsForeignKeyConstraints()) {
...@@ -1585,6 +1681,7 @@ abstract class AbstractPlatform ...@@ -1585,6 +1681,7 @@ abstract class AbstractPlatform
* Common code for alter table statement generation that updates the changed Index and Foreign Key definitions. * Common code for alter table statement generation that updates the changed Index and Foreign Key definitions.
* *
* @param TableDiff $diff * @param TableDiff $diff
*
* @return array * @return array
*/ */
protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff) protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff)
...@@ -1624,10 +1721,11 @@ abstract class AbstractPlatform ...@@ -1624,10 +1721,11 @@ abstract class AbstractPlatform
public function getColumnDeclarationListSQL(array $fields) public function getColumnDeclarationListSQL(array $fields)
{ {
$queryFields = array(); $queryFields = array();
foreach ($fields as $fieldName => $field) { foreach ($fields as $fieldName => $field) {
$query = $this->getColumnDeclarationSQL($fieldName, $field); $queryFields[] = $this->getColumnDeclarationSQL($fieldName, $field);
$queryFields[] = $query;
} }
return implode(', ', $queryFields); return implode(', ', $queryFields);
} }
...@@ -1700,6 +1798,7 @@ abstract class AbstractPlatform ...@@ -1700,6 +1798,7 @@ abstract class AbstractPlatform
* Gets the SQL snippet that declares a floating point column of arbitrary precision. * Gets the SQL snippet that declares a floating point column of arbitrary precision.
* *
* @param array $columnDef * @param array $columnDef
*
* @return string * @return string
*/ */
public function getDecimalTypeDeclarationSQL(array $columnDef) public function getDecimalTypeDeclarationSQL(array $columnDef)
...@@ -1717,6 +1816,7 @@ abstract class AbstractPlatform ...@@ -1717,6 +1816,7 @@ abstract class AbstractPlatform
* declaration to be used in statements like CREATE TABLE. * declaration to be used in statements like CREATE TABLE.
* *
* @param array $field field definition array * @param array $field field definition array
*
* @return string DBMS specific SQL code portion needed to set a default value * @return string DBMS specific SQL code portion needed to set a default value
*/ */
public function getDefaultValueDeclarationSQL($field) public function getDefaultValueDeclarationSQL($field)
...@@ -1743,6 +1843,7 @@ abstract class AbstractPlatform ...@@ -1743,6 +1843,7 @@ abstract class AbstractPlatform
* declaration to be used in statements like CREATE TABLE. * declaration to be used in statements like CREATE TABLE.
* *
* @param array $definition check definition * @param array $definition check definition
*
* @return string DBMS specific SQL code portion needed to set a CHECK constraint * @return string DBMS specific SQL code portion needed to set a CHECK constraint
*/ */
public function getCheckDeclarationSQL(array $definition) public function getCheckDeclarationSQL(array $definition)
...@@ -1771,12 +1872,13 @@ abstract class AbstractPlatform ...@@ -1771,12 +1872,13 @@ abstract class AbstractPlatform
* *
* @param string $name name of the unique constraint * @param string $name name of the unique constraint
* @param Index $index index definition * @param Index $index index definition
*
* @return string DBMS specific SQL code portion needed * @return string DBMS specific SQL code portion needed
* to set a constraint * to set a constraint
*/ */
public function getUniqueConstraintDeclarationSQL($name, Index $index) public function getUniqueConstraintDeclarationSQL($name, Index $index)
{ {
if (count($index->getColumns()) == 0) { if (count($index->getColumns()) === 0) {
throw new \InvalidArgumentException("Incomplete definition. 'columns' required."); throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
} }
...@@ -1791,17 +1893,18 @@ abstract class AbstractPlatform ...@@ -1791,17 +1893,18 @@ abstract class AbstractPlatform
* *
* @param string $name name of the index * @param string $name name of the index
* @param Index $index index definition * @param Index $index index definition
*
* @return string DBMS specific SQL code portion needed to set an index * @return string DBMS specific SQL code portion needed to set an index
*/ */
public function getIndexDeclarationSQL($name, Index $index) public function getIndexDeclarationSQL($name, Index $index)
{ {
$type = ''; $type = '';
if($index->isUnique()) { if ($index->isUnique()) {
$type = 'UNIQUE '; $type = 'UNIQUE ';
} }
if (count($index->getColumns()) == 0) { if (count($index->getColumns()) === 0) {
throw new \InvalidArgumentException("Incomplete definition. 'columns' required."); throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
} }
...@@ -1817,6 +1920,7 @@ abstract class AbstractPlatform ...@@ -1817,6 +1920,7 @@ abstract class AbstractPlatform
* Only "AUTOINCREMENT" and "PRIMARY KEY" are added if appropriate. * Only "AUTOINCREMENT" and "PRIMARY KEY" are added if appropriate.
* *
* @param array $columnDef * @param array $columnDef
*
* @return string * @return string
*/ */
public function getCustomTypeDeclarationSQL(array $columnDef) public function getCustomTypeDeclarationSQL(array $columnDef)
...@@ -1830,11 +1934,13 @@ abstract class AbstractPlatform ...@@ -1830,11 +1934,13 @@ abstract class AbstractPlatform
* declaration to be used in statements like CREATE TABLE. * declaration to be used in statements like CREATE TABLE.
* *
* @param array $fields * @param array $fields
*
* @return string * @return string
*/ */
public function getIndexFieldDeclarationListSQL(array $fields) public function getIndexFieldDeclarationListSQL(array $fields)
{ {
$ret = array(); $ret = array();
foreach ($fields as $field => $definition) { foreach ($fields as $field => $definition) {
if (is_array($definition)) { if (is_array($definition)) {
$ret[] = $field; $ret[] = $field;
...@@ -1842,6 +1948,7 @@ abstract class AbstractPlatform ...@@ -1842,6 +1948,7 @@ abstract class AbstractPlatform
$ret[] = $definition; $ret[] = $definition;
} }
} }
return implode(', ', $ret); return implode(', ', $ret);
} }
...@@ -1868,6 +1975,7 @@ abstract class AbstractPlatform ...@@ -1868,6 +1975,7 @@ abstract class AbstractPlatform
* Some vendors require temporary table names to be qualified specially. * Some vendors require temporary table names to be qualified specially.
* *
* @param string $tableName * @param string $tableName
*
* @return string * @return string
*/ */
public function getTemporaryTableName($tableName) public function getTemporaryTableName($tableName)
...@@ -1889,39 +1997,7 @@ abstract class AbstractPlatform ...@@ -1889,39 +1997,7 @@ abstract class AbstractPlatform
* Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint * Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
* of a field declaration to be used in statements like CREATE TABLE. * of a field declaration to be used in statements like CREATE TABLE.
* *
* @param array $definition an associative array with the following structure: * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey
* name optional constraint name
*
* local the local field(s)
*
* foreign the foreign reference field(s)
*
* foreignTable the name of the foreign table
*
* onDelete referential delete action
*
* onUpdate referential update action
*
* deferred deferred constraint checking
*
* The onDelete and onUpdate keys accept the following values:
*
* CASCADE: Delete or update the row from the parent table and automatically delete or
* update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported.
* Between two tables, you should not define several ON UPDATE CASCADE clauses that act on the same column
* in the parent table or in the child table.
*
* SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the
* child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier
* specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported.
*
* NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary
* key value is not allowed to proceed if there is a related foreign key value in the referenced table.
*
* RESTRICT: Rejects the delete or update operation for the parent table. NO ACTION and RESTRICT are the same as
* omitting the ON DELETE or ON UPDATE clause.
*
* SET DEFAULT
* *
* @return string DBMS specific SQL code portion needed to set the FOREIGN KEY constraint * @return string DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
* of a field declaration. * of a field declaration.
...@@ -1939,6 +2015,7 @@ abstract class AbstractPlatform ...@@ -1939,6 +2015,7 @@ abstract class AbstractPlatform
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ... * as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
* *
* @param ForeignKeyConstraint $foreignKey foreign key definition * @param ForeignKeyConstraint $foreignKey foreign key definition
*
* @return string * @return string
*/ */
public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey) public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey)
...@@ -1958,7 +2035,9 @@ abstract class AbstractPlatform ...@@ -1958,7 +2035,9 @@ abstract class AbstractPlatform
* an exception * an exception
* *
* @throws \InvalidArgumentException if unknown referential action given * @throws \InvalidArgumentException if unknown referential action given
*
* @param string $action foreign key referential action * @param string $action foreign key referential action
*
* @return string * @return string
*/ */
public function getForeignKeyReferentialActionSQL($action) public function getForeignKeyReferentialActionSQL($action)
...@@ -1971,7 +2050,6 @@ abstract class AbstractPlatform ...@@ -1971,7 +2050,6 @@ abstract class AbstractPlatform
case 'RESTRICT': case 'RESTRICT':
case 'SET DEFAULT': case 'SET DEFAULT':
return $upper; return $upper;
break;
default: default:
throw new \InvalidArgumentException('Invalid foreign key action: ' . $upper); throw new \InvalidArgumentException('Invalid foreign key action: ' . $upper);
} }
...@@ -1982,6 +2060,7 @@ abstract class AbstractPlatform ...@@ -1982,6 +2060,7 @@ abstract class AbstractPlatform
* of a field declaration to be used in statements like CREATE TABLE. * of a field declaration to be used in statements like CREATE TABLE.
* *
* @param ForeignKeyConstraint $foreignKey * @param ForeignKeyConstraint $foreignKey
*
* @return string * @return string
*/ */
public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey) public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey)
...@@ -1992,13 +2071,13 @@ abstract class AbstractPlatform ...@@ -1992,13 +2071,13 @@ abstract class AbstractPlatform
} }
$sql .= 'FOREIGN KEY ('; $sql .= 'FOREIGN KEY (';
if (count($foreignKey->getLocalColumns()) == 0) { if (count($foreignKey->getLocalColumns()) === 0) {
throw new \InvalidArgumentException("Incomplete definition. 'local' required."); throw new \InvalidArgumentException("Incomplete definition. 'local' required.");
} }
if (count($foreignKey->getForeignColumns()) == 0) { if (count($foreignKey->getForeignColumns()) === 0) {
throw new \InvalidArgumentException("Incomplete definition. 'foreign' required."); throw new \InvalidArgumentException("Incomplete definition. 'foreign' required.");
} }
if (strlen($foreignKey->getForeignTableName()) == 0) { if (strlen($foreignKey->getForeignTableName()) === 0) {
throw new \InvalidArgumentException("Incomplete definition. 'foreignTable' required."); throw new \InvalidArgumentException("Incomplete definition. 'foreignTable' required.");
} }
...@@ -2027,6 +2106,7 @@ abstract class AbstractPlatform ...@@ -2027,6 +2106,7 @@ abstract class AbstractPlatform
* of a field declaration to be used in statements like CREATE TABLE. * of a field declaration to be used in statements like CREATE TABLE.
* *
* @param string $charset name of the charset * @param string $charset name of the charset
*
* @return string DBMS specific SQL code portion needed to set the CHARACTER SET * @return string DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration. * of a field declaration.
*/ */
...@@ -2040,6 +2120,7 @@ abstract class AbstractPlatform ...@@ -2040,6 +2120,7 @@ abstract class AbstractPlatform
* of a field declaration to be used in statements like CREATE TABLE. * of a field declaration to be used in statements like CREATE TABLE.
* *
* @param string $collation name of the collation * @param string $collation name of the collation
*
* @return string DBMS specific SQL code portion needed to set the COLLATION * @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration. * of a field declaration.
*/ */
...@@ -2076,6 +2157,7 @@ abstract class AbstractPlatform ...@@ -2076,6 +2157,7 @@ abstract class AbstractPlatform
* The default conversion in this implementation converts to integers (false => 0, true => 1). * The default conversion in this implementation converts to integers (false => 0, true => 1).
* *
* @param mixed $item * @param mixed $item
*
* @return mixed * @return mixed
*/ */
public function convertBooleans($item) public function convertBooleans($item)
...@@ -2089,6 +2171,7 @@ abstract class AbstractPlatform ...@@ -2089,6 +2171,7 @@ abstract class AbstractPlatform
} else if (is_bool($item)) { } else if (is_bool($item)) {
$item = (int) $item; $item = (int) $item;
} }
return $item; return $item;
} }
...@@ -2126,6 +2209,8 @@ abstract class AbstractPlatform ...@@ -2126,6 +2209,8 @@ abstract class AbstractPlatform
* Get sql for transaction isolation level Connection constant * Get sql for transaction isolation level Connection constant
* *
* @param integer $level * @param integer $level
*
* @return string
*/ */
protected function _getTransactionIsolationLevelSQL($level) protected function _getTransactionIsolationLevelSQL($level)
{ {
...@@ -2177,6 +2262,7 @@ abstract class AbstractPlatform ...@@ -2177,6 +2262,7 @@ abstract class AbstractPlatform
* Get the SQL to list all views of a database or user. * Get the SQL to list all views of a database or user.
* *
* @param string $database * @param string $database
*
* @return string * @return string
*/ */
public function getListViewsSQL($database) public function getListViewsSQL($database)
...@@ -2196,6 +2282,8 @@ abstract class AbstractPlatform ...@@ -2196,6 +2282,8 @@ abstract class AbstractPlatform
* *
* @param string $table * @param string $table
* @param string $currentDatabase * @param string $currentDatabase
*
* @return string
*/ */
public function getListTableIndexesSQL($table, $currentDatabase = null) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
...@@ -2217,6 +2305,13 @@ abstract class AbstractPlatform ...@@ -2217,6 +2305,13 @@ abstract class AbstractPlatform
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
} }
/**
* Get the SQL snippet to drop an existing sequence
*
* @param \Doctrine\DBAL\Schema\Sequence $sequence
*
* @return string
*/
public function getDropSequenceSQL($sequence) public function getDropSequenceSQL($sequence)
{ {
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
...@@ -2227,6 +2322,13 @@ abstract class AbstractPlatform ...@@ -2227,6 +2322,13 @@ abstract class AbstractPlatform
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
} }
/**
* create a new database
*
* @param string $database name of the database that should be created
*
* @return string
*/
public function getCreateDatabaseSQL($database) public function getCreateDatabaseSQL($database)
{ {
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
...@@ -2236,6 +2338,8 @@ abstract class AbstractPlatform ...@@ -2236,6 +2338,8 @@ abstract class AbstractPlatform
* Get sql to set the transaction isolation level * Get sql to set the transaction isolation level
* *
* @param integer $level * @param integer $level
*
* @return string
*/ */
public function getSetTransactionIsolationSQL($level) public function getSetTransactionIsolationSQL($level)
{ {
...@@ -2247,6 +2351,7 @@ abstract class AbstractPlatform ...@@ -2247,6 +2351,7 @@ abstract class AbstractPlatform
* statements like CREATE TABLE * statements like CREATE TABLE
* *
* @param array $fieldDeclaration * @param array $fieldDeclaration
*
* @return string * @return string
*/ */
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
...@@ -2258,6 +2363,8 @@ abstract class AbstractPlatform ...@@ -2258,6 +2363,8 @@ abstract class AbstractPlatform
* Obtain DBMS specific SQL to be used to create datetime with timezone offset fields. * Obtain DBMS specific SQL to be used to create datetime with timezone offset fields.
* *
* @param array $fieldDeclaration * @param array $fieldDeclaration
*
* @return string
*/ */
public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -2270,6 +2377,7 @@ abstract class AbstractPlatform ...@@ -2270,6 +2377,7 @@ abstract class AbstractPlatform
* like CREATE TABLE. * like CREATE TABLE.
* *
* @param array $fieldDeclaration * @param array $fieldDeclaration
*
* @return string * @return string
*/ */
public function getDateTypeDeclarationSQL(array $fieldDeclaration) public function getDateTypeDeclarationSQL(array $fieldDeclaration)
...@@ -2282,6 +2390,7 @@ abstract class AbstractPlatform ...@@ -2282,6 +2390,7 @@ abstract class AbstractPlatform
* like CREATE TABLE. * like CREATE TABLE.
* *
* @param array $fieldDeclaration * @param array $fieldDeclaration
*
* @return string * @return string
*/ */
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
...@@ -2298,6 +2407,7 @@ abstract class AbstractPlatform ...@@ -2298,6 +2407,7 @@ abstract class AbstractPlatform
* Gets the default transaction isolation level of the platform. * Gets the default transaction isolation level of the platform.
* *
* @return integer The default isolation level. * @return integer The default isolation level.
*
* @see Doctrine\DBAL\Connection\TRANSACTION_* constants. * @see Doctrine\DBAL\Connection\TRANSACTION_* constants.
*/ */
public function getDefaultTransactionIsolationLevel() public function getDefaultTransactionIsolationLevel()
...@@ -2339,6 +2449,11 @@ abstract class AbstractPlatform ...@@ -2339,6 +2449,11 @@ abstract class AbstractPlatform
return true; return true;
} }
/**
* Whether the platform supports altering tables.
*
* @return boolean
*/
public function supportsAlterTable() public function supportsAlterTable()
{ {
return true; return true;
...@@ -2397,7 +2512,7 @@ abstract class AbstractPlatform ...@@ -2397,7 +2512,7 @@ abstract class AbstractPlatform
/** /**
* Does this platform supports onUpdate in foreign key constraints? * Does this platform supports onUpdate in foreign key constraints?
* *
* @return bool * @return boolean
*/ */
public function supportsForeignKeyOnUpdate() public function supportsForeignKeyOnUpdate()
{ {
...@@ -2421,7 +2536,7 @@ abstract class AbstractPlatform ...@@ -2421,7 +2536,7 @@ abstract class AbstractPlatform
* filter a schema for the namespaced elements in {@link * filter a schema for the namespaced elements in {@link
* AbstractManager#createSchema}. * AbstractManager#createSchema}.
* *
* @return bool * @return boolean
*/ */
public function canEmulateSchemas() public function canEmulateSchemas()
{ {
...@@ -2431,7 +2546,7 @@ abstract class AbstractPlatform ...@@ -2431,7 +2546,7 @@ abstract class AbstractPlatform
/** /**
* Some databases don't allow to create and drop databases at all or only with certain tools. * Some databases don't allow to create and drop databases at all or only with certain tools.
* *
* @return bool * @return boolean
*/ */
public function supportsCreateDropDatabase() public function supportsCreateDropDatabase()
{ {
...@@ -2452,7 +2567,7 @@ abstract class AbstractPlatform ...@@ -2452,7 +2567,7 @@ abstract class AbstractPlatform
/** /**
* Does this platform support to add inline column comments as postfix. * Does this platform support to add inline column comments as postfix.
* *
* @return bool * @return boolean
*/ */
public function supportsInlineColumnComments() public function supportsInlineColumnComments()
{ {
...@@ -2462,7 +2577,7 @@ abstract class AbstractPlatform ...@@ -2462,7 +2577,7 @@ abstract class AbstractPlatform
/** /**
* Does this platform support the proprietary syntax "COMMENT ON asset" * Does this platform support the proprietary syntax "COMMENT ON asset"
* *
* @return bool * @return boolean
*/ */
public function supportsCommentOnStatement() public function supportsCommentOnStatement()
{ {
...@@ -2532,23 +2647,24 @@ abstract class AbstractPlatform ...@@ -2532,23 +2647,24 @@ abstract class AbstractPlatform
* Modify limit query * Modify limit query
* *
* @param string $query * @param string $query
* @param int $limit * @param integer $limit
* @param int $offset * @param integer $offset
*
* @return string * @return string
*/ */
final public function modifyLimitQuery($query, $limit, $offset = null) final public function modifyLimitQuery($query, $limit, $offset = null)
{ {
if ( $limit !== null) { if ($limit !== null) {
$limit = (int)$limit; $limit = (int)$limit;
} }
if ( $offset !== null) { if ($offset !== null) {
$offset = (int)$offset; $offset = (int)$offset;
if ($offset < 0) { if ($offset < 0) {
throw new DBALException("LIMIT argument offset=$offset is not valid"); throw new DBALException("LIMIT argument offset=$offset is not valid");
} }
if ( $offset > 0 && ! $this->supportsLimitOffset()) { if ($offset > 0 && ! $this->supportsLimitOffset()) {
throw new DBALException(sprintf("Platform %s does not support offset values in limit queries.", $this->getName())); throw new DBALException(sprintf("Platform %s does not support offset values in limit queries.", $this->getName()));
} }
} }
...@@ -2557,18 +2673,21 @@ abstract class AbstractPlatform ...@@ -2557,18 +2673,21 @@ abstract class AbstractPlatform
} }
/** /**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query * @param string $query
* @param int $limit * @param integer $limit
* @param int $offset * @param integer $offset
*
* @return string * @return string
*/ */
protected function doModifyLimitQuery($query, $limit, $offset) protected function doModifyLimitQuery($query, $limit, $offset)
{ {
if ( $limit !== null) { if ($limit !== null) {
$query .= ' LIMIT ' . $limit; $query .= ' LIMIT ' . $limit;
} }
if ( $offset !== null) { if ($offset !== null) {
$query .= ' OFFSET ' . $offset; $query .= ' OFFSET ' . $offset;
} }
...@@ -2578,7 +2697,7 @@ abstract class AbstractPlatform ...@@ -2578,7 +2697,7 @@ abstract class AbstractPlatform
/** /**
* Does the database platform support offsets in modify limit clauses? * Does the database platform support offsets in modify limit clauses?
* *
* @return bool * @return boolean
*/ */
public function supportsLimitOffset() public function supportsLimitOffset()
{ {
...@@ -2589,6 +2708,7 @@ abstract class AbstractPlatform ...@@ -2589,6 +2708,7 @@ abstract class AbstractPlatform
* Gets the character casing of a column in an SQL result set of this platform. * Gets the character casing of a column in an SQL result set of this platform.
* *
* @param string $column The column name for which to get the correct character casing. * @param string $column The column name for which to get the correct character casing.
*
* @return string The column name in the character casing used in SQL result sets. * @return string The column name in the character casing used in SQL result sets.
*/ */
public function getSQLResultCasing($column) public function getSQLResultCasing($column)
...@@ -2601,6 +2721,7 @@ abstract class AbstractPlatform ...@@ -2601,6 +2721,7 @@ abstract class AbstractPlatform
* by restrictions of the platform, like a maximum length. * by restrictions of the platform, like a maximum length.
* *
* @param string $schemaElementName * @param string $schemaElementName
*
* @return string * @return string
*/ */
public function fixSchemaElementName($schemaElementName) public function fixSchemaElementName($schemaElementName)
...@@ -2611,7 +2732,7 @@ abstract class AbstractPlatform ...@@ -2611,7 +2732,7 @@ abstract class AbstractPlatform
/** /**
* Maximum length of any given database identifier, like tables or column names. * Maximum length of any given database identifier, like tables or column names.
* *
* @return int * @return integer
*/ */
public function getMaxIdentifierLength() public function getMaxIdentifierLength()
{ {
...@@ -2623,6 +2744,7 @@ abstract class AbstractPlatform ...@@ -2623,6 +2744,7 @@ abstract class AbstractPlatform
* *
* @param string $tableName * @param string $tableName
* @param string $identifierColumnName * @param string $identifierColumnName
*
* @return string $sql * @return string $sql
*/ */
public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName) public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName)
...@@ -2637,7 +2759,8 @@ abstract class AbstractPlatform ...@@ -2637,7 +2759,8 @@ abstract class AbstractPlatform
* following the foreign keys. * following the foreign keys.
* *
* @param string $tableName * @param string $tableName
* @param bool $cascade * @param boolean $cascade
*
* @return string * @return string
*/ */
public function getTruncateTableSQL($tableName, $cascade = false) public function getTruncateTableSQL($tableName, $cascade = false)
...@@ -2659,6 +2782,7 @@ abstract class AbstractPlatform ...@@ -2659,6 +2782,7 @@ abstract class AbstractPlatform
* Generate SQL to create a new savepoint * Generate SQL to create a new savepoint
* *
* @param string $savepoint * @param string $savepoint
*
* @return string * @return string
*/ */
public function createSavePoint($savepoint) public function createSavePoint($savepoint)
...@@ -2670,6 +2794,7 @@ abstract class AbstractPlatform ...@@ -2670,6 +2794,7 @@ abstract class AbstractPlatform
* Generate SQL to release a savepoint * Generate SQL to release a savepoint
* *
* @param string $savepoint * @param string $savepoint
*
* @return string * @return string
*/ */
public function releaseSavePoint($savepoint) public function releaseSavePoint($savepoint)
...@@ -2681,6 +2806,7 @@ abstract class AbstractPlatform ...@@ -2681,6 +2806,7 @@ abstract class AbstractPlatform
* Generate SQL to rollback a savepoint * Generate SQL to rollback a savepoint
* *
* @param string $savepoint * @param string $savepoint
*
* @return string * @return string
*/ */
public function rollbackSavePoint($savepoint) public function rollbackSavePoint($savepoint)
...@@ -2694,6 +2820,7 @@ abstract class AbstractPlatform ...@@ -2694,6 +2820,7 @@ abstract class AbstractPlatform
* Throws exception if no keyword list is specified. * Throws exception if no keyword list is specified.
* *
* @throws DBALException * @throws DBALException
*
* @return \Doctrine\DBAL\Platforms\Keywords\KeywordList * @return \Doctrine\DBAL\Platforms\Keywords\KeywordList
*/ */
final public function getReservedKeywordsList() final public function getReservedKeywordsList()
......
...@@ -26,13 +26,16 @@ use Doctrine\DBAL\Schema\TableDiff; ...@@ -26,13 +26,16 @@ use Doctrine\DBAL\Schema\TableDiff;
class DB2Platform extends AbstractPlatform class DB2Platform extends AbstractPlatform
{ {
/** /**
* Gets the SQL Snippet used to declare a BLOB column type. * {@inheritDoc}
*/ */
public function getBlobTypeDeclarationSQL(array $field) public function getBlobTypeDeclarationSQL(array $field)
{ {
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
} }
/**
* {@inheritDoc}
*/
public function initializeDoctrineTypeMappings() public function initializeDoctrineTypeMappings()
{ {
$this->doctrineTypeMapping = array( $this->doctrineTypeMapping = array(
...@@ -52,9 +55,7 @@ class DB2Platform extends AbstractPlatform ...@@ -52,9 +55,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Gets the SQL snippet used to declare a VARCHAR column type. * {@inheritDoc}
*
* @param array $field
*/ */
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{ {
...@@ -63,9 +64,7 @@ class DB2Platform extends AbstractPlatform ...@@ -63,9 +64,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Gets the SQL snippet used to declare a CLOB column type. * {@inheritDoc}
*
* @param array $field
*/ */
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
...@@ -74,21 +73,15 @@ class DB2Platform extends AbstractPlatform ...@@ -74,21 +73,15 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Gets the name of the platform. * {@inheritDoc}
*
* @return string
*/ */
public function getName() public function getName()
{ {
return 'db2'; return 'db2';
} }
/** /**
* Gets the SQL snippet that declares a boolean column. * {@inheritDoc}
*
* @param array $columnDef
* @return string
*/ */
public function getBooleanTypeDeclarationSQL(array $columnDef) public function getBooleanTypeDeclarationSQL(array $columnDef)
{ {
...@@ -96,10 +89,7 @@ class DB2Platform extends AbstractPlatform ...@@ -96,10 +89,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Gets the SQL snippet that declares a 4 byte integer column. * {@inheritDoc}
*
* @param array $columnDef
* @return string
*/ */
public function getIntegerTypeDeclarationSQL(array $columnDef) public function getIntegerTypeDeclarationSQL(array $columnDef)
{ {
...@@ -107,10 +97,7 @@ class DB2Platform extends AbstractPlatform ...@@ -107,10 +97,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Gets the SQL snippet that declares an 8 byte integer column. * {@inheritDoc}
*
* @param array $columnDef
* @return string
*/ */
public function getBigIntTypeDeclarationSQL(array $columnDef) public function getBigIntTypeDeclarationSQL(array $columnDef)
{ {
...@@ -118,10 +105,7 @@ class DB2Platform extends AbstractPlatform ...@@ -118,10 +105,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Gets the SQL snippet that declares a 2 byte integer column. * {@inheritDoc}
*
* @param array $columnDef
* @return string
*/ */
public function getSmallIntTypeDeclarationSQL(array $columnDef) public function getSmallIntTypeDeclarationSQL(array $columnDef)
{ {
...@@ -129,10 +113,7 @@ class DB2Platform extends AbstractPlatform ...@@ -129,10 +113,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Gets the SQL snippet that declares common properties of an integer column. * {@inheritDoc}
*
* @param array $columnDef
* @return string
*/ */
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{ {
...@@ -140,15 +121,12 @@ class DB2Platform extends AbstractPlatform ...@@ -140,15 +121,12 @@ class DB2Platform extends AbstractPlatform
if ( ! empty($columnDef['autoincrement'])) { if ( ! empty($columnDef['autoincrement'])) {
$autoinc = ' GENERATED BY DEFAULT AS IDENTITY'; $autoinc = ' GENERATED BY DEFAULT AS IDENTITY';
} }
return $autoinc; return $autoinc;
} }
/** /**
* Obtain DBMS specific SQL to be used to create datetime fields in * {@inheritDoc}
* statements like CREATE TABLE
*
* @param array $fieldDeclaration
* @return string
*/ */
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -160,11 +138,7 @@ class DB2Platform extends AbstractPlatform ...@@ -160,11 +138,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Obtain DBMS specific SQL to be used to create date fields in statements * {@inheritDoc}
* like CREATE TABLE.
*
* @param array $fieldDeclaration
* @return string
*/ */
public function getDateTypeDeclarationSQL(array $fieldDeclaration) public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -172,11 +146,7 @@ class DB2Platform extends AbstractPlatform ...@@ -172,11 +146,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Obtain DBMS specific SQL to be used to create time fields in statements * {@inheritDoc}
* like CREATE TABLE.
*
* @param array $fieldDeclaration
* @return string
*/ */
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -203,6 +173,7 @@ class DB2Platform extends AbstractPlatform ...@@ -203,6 +173,7 @@ class DB2Platform extends AbstractPlatform
* *
* @license New BSD License * @license New BSD License
* @param string $table * @param string $table
* @param string $database
* @return string * @return string
*/ */
public function getListTableColumnsSQL($table, $database = null) public function getListTableColumnsSQL($table, $database = null)
...@@ -232,16 +203,16 @@ class DB2Platform extends AbstractPlatform ...@@ -232,16 +203,16 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Get the SQL to list all views of a database or user. * {@inheritDoc}
*
* @param string $database
* @return string
*/ */
public function getListViewsSQL($database) public function getListViewsSQL($database)
{ {
return "SELECT NAME, TEXT FROM SYSIBM.SYSVIEWS"; return "SELECT NAME, TEXT FROM SYSIBM.SYSVIEWS";
} }
/**
* {@inheritDoc}
*/
public function getListTableIndexesSQL($table, $currentDatabase = null) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
return "SELECT NAME, COLNAMES, UNIQUERULE FROM SYSIBM.SYSINDEXES WHERE TBNAME = UPPER('" . $table . "')"; return "SELECT NAME, COLNAMES, UNIQUERULE FROM SYSIBM.SYSINDEXES WHERE TBNAME = UPPER('" . $table . "')";
...@@ -263,6 +234,9 @@ class DB2Platform extends AbstractPlatform ...@@ -263,6 +234,9 @@ class DB2Platform extends AbstractPlatform
return "DROP VIEW ".$name; return "DROP VIEW ".$name;
} }
/**
* {@inheritDoc}
*/
public function getDropSequenceSQL($sequence) public function getDropSequenceSQL($sequence)
{ {
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
...@@ -273,25 +247,32 @@ class DB2Platform extends AbstractPlatform ...@@ -273,25 +247,32 @@ class DB2Platform extends AbstractPlatform
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
} }
/**
* {@inheritDoc}
*/
public function getCreateDatabaseSQL($database) public function getCreateDatabaseSQL($database)
{ {
return "CREATE DATABASE ".$database; return "CREATE DATABASE ".$database;
} }
/**
* {@inheritDoc}
*/
public function getDropDatabaseSQL($database) public function getDropDatabaseSQL($database)
{ {
return "DROP DATABASE ".$database.";"; return "DROP DATABASE ".$database.";";
} }
/**
* {@inheritDoc}
*/
public function supportsCreateDropDatabase() public function supportsCreateDropDatabase()
{ {
return false; return false;
} }
/** /**
* Whether the platform supports releasing savepoints. * {@inheritDoc}
*
* @return boolean
*/ */
public function supportsReleaseSavepoints() public function supportsReleaseSavepoints()
{ {
...@@ -299,9 +280,7 @@ class DB2Platform extends AbstractPlatform ...@@ -299,9 +280,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Gets the SQL specific for the platform to get the current date. * {@inheritDoc}
*
* @return string
*/ */
public function getCurrentDateSQL() public function getCurrentDateSQL()
{ {
...@@ -309,9 +288,7 @@ class DB2Platform extends AbstractPlatform ...@@ -309,9 +288,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Gets the SQL specific for the platform to get the current time. * {@inheritDoc}
*
* @return string
*/ */
public function getCurrentTimeSQL() public function getCurrentTimeSQL()
{ {
...@@ -319,23 +296,15 @@ class DB2Platform extends AbstractPlatform ...@@ -319,23 +296,15 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Gets the SQL specific for the platform to get the current timestamp * {@inheritDoc}
*
* @return string
*/ */
public function getCurrentTimestampSQL() public function getCurrentTimestampSQL()
{ {
return "VALUES CURRENT TIMESTAMP"; return "VALUES CURRENT TIMESTAMP";
} }
/** /**
* Obtain DBMS specific SQL code portion needed to set an index * {@inheritDoc}
* declaration to be used in statements like CREATE TABLE.
*
* @param string $name name of the index
* @param Index $index index definition
* @return string DBMS specific SQL code portion needed to set an index
*/ */
public function getIndexDeclarationSQL($name, Index $index) public function getIndexDeclarationSQL($name, Index $index)
{ {
...@@ -343,10 +312,7 @@ class DB2Platform extends AbstractPlatform ...@@ -343,10 +312,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* @param string $tableName * {@inheritDoc}
* @param array $columns
* @param array $options
* @return array
*/ */
protected function _getCreateTableSQL($tableName, array $columns, array $options = array()) protected function _getCreateTableSQL($tableName, array $columns, array $options = array())
{ {
...@@ -365,10 +331,7 @@ class DB2Platform extends AbstractPlatform ...@@ -365,10 +331,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Gets the SQL to alter an existing table. * {@inheritDoc}
*
* @param TableDiff $diff
* @return array
*/ */
public function getAlterTableSQL(TableDiff $diff) public function getAlterTableSQL(TableDiff $diff)
{ {
...@@ -428,6 +391,9 @@ class DB2Platform extends AbstractPlatform ...@@ -428,6 +391,9 @@ class DB2Platform extends AbstractPlatform
return array_merge($sql, $tableSql, $columnSql); return array_merge($sql, $tableSql, $columnSql);
} }
/**
* {@inheritDoc}
*/
public function getDefaultValueDeclarationSQL($field) public function getDefaultValueDeclarationSQL($field)
{ {
if (isset($field['notnull']) && $field['notnull'] && !isset($field['default'])) { if (isset($field['notnull']) && $field['notnull'] && !isset($field['default'])) {
...@@ -455,11 +421,7 @@ class DB2Platform extends AbstractPlatform ...@@ -455,11 +421,7 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* Get the insert sql for an empty insert statement * {@inheritDoc}
*
* @param string $tableName
* @param string $identifierColumnName
* @return string $sql
*/ */
public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName) public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName)
{ {
...@@ -472,16 +434,16 @@ class DB2Platform extends AbstractPlatform ...@@ -472,16 +434,16 @@ class DB2Platform extends AbstractPlatform
} }
/** /**
* DB2 automatically moves temporary tables into the SESSION. schema. * {@inheritDoc}
*
* @param string $tableName
* @return string
*/ */
public function getTemporaryTableName($tableName) public function getTemporaryTableName($tableName)
{ {
return "SESSION." . $tableName; return "SESSION." . $tableName;
} }
/**
* {@inheritDoc}
*/
protected function doModifyLimitQuery($query, $limit, $offset = null) protected function doModifyLimitQuery($query, $limit, $offset = null)
{ {
if ($limit === null && $offset === null) { if ($limit === null && $offset === null) {
...@@ -494,64 +456,54 @@ class DB2Platform extends AbstractPlatform ...@@ -494,64 +456,54 @@ class DB2Platform extends AbstractPlatform
// Todo OVER() needs ORDER BY data! // Todo OVER() needs ORDER BY data!
$sql = 'SELECT db22.* FROM (SELECT ROW_NUMBER() OVER() AS DC_ROWNUM, db21.* '. $sql = 'SELECT db22.* FROM (SELECT ROW_NUMBER() OVER() AS DC_ROWNUM, db21.* '.
'FROM (' . $query . ') db21) db22 WHERE db22.DC_ROWNUM BETWEEN ' . ($offset+1) .' AND ' . ($offset+$limit); 'FROM (' . $query . ') db21) db22 WHERE db22.DC_ROWNUM BETWEEN ' . ($offset+1) .' AND ' . ($offset+$limit);
return $sql; return $sql;
} }
/** /**
* returns the position of the first occurrence of substring $substr in string $str * {@inheritDoc}
*
* @param string $substr literal string to find
* @param string $str literal string
* @param int $pos position to start at, beginning of string by default
* @return integer
*/ */
public function getLocateExpression($str, $substr, $startPos = false) public function getLocateExpression($str, $substr, $startPos = false)
{ {
if ($startPos == false) { if ($startPos == false) {
return 'LOCATE(' . $substr . ', ' . $str . ')'; return 'LOCATE(' . $substr . ', ' . $str . ')';
} else {
return 'LOCATE(' . $substr . ', ' . $str . ', '.$startPos.')';
} }
return 'LOCATE(' . $substr . ', ' . $str . ', '.$startPos.')';
} }
/** /**
* return string to call a function to get a substring inside an SQL statement * {@inheritDoc}
*
* Note: Not SQL92, but common functionality.
*
* SQLite only supports the 2 parameter variant of this function
*
* @param string $value an sql string literal or column name/alias
* @param integer $from where to start the substring portion
* @param integer $len the substring portion length
* @return string
*/ */
public function getSubstringExpression($value, $from, $len = null) public function getSubstringExpression($value, $from, $length = null)
{ {
if ($len === null) if ($length === null) {
return 'SUBSTR(' . $value . ', ' . $from . ')'; return 'SUBSTR(' . $value . ', ' . $from . ')';
else {
return 'SUBSTR(' . $value . ', ' . $from . ', ' . $len . ')';
} }
return 'SUBSTR(' . $value . ', ' . $from . ', ' . $length . ')';
} }
/**
* {@inheritDoc}
*/
public function supportsIdentityColumns() public function supportsIdentityColumns()
{ {
return true; return true;
} }
/**
* {@inheritDoc}
*/
public function prefersIdentityColumns() public function prefersIdentityColumns()
{ {
return true; return true;
} }
/** /**
* Gets the character casing of a column in an SQL result set of this platform. * {@inheritDoc}
* *
* DB2 returns all column names in SQL result sets in uppercase. * DB2 returns all column names in SQL result sets in uppercase.
*
* @param string $column The column name for which to get the correct character casing.
* @return string The column name in the character casing used in SQL result sets.
*/ */
public function getSQLResultCasing($column) public function getSQLResultCasing($column)
{ {
...@@ -563,23 +515,29 @@ class DB2Platform extends AbstractPlatform ...@@ -563,23 +515,29 @@ class DB2Platform extends AbstractPlatform
return ' WITH RR USE AND KEEP UPDATE LOCKS'; return ' WITH RR USE AND KEEP UPDATE LOCKS';
} }
/**
* {@inheritDoc}
*/
public function getDummySelectSQL() public function getDummySelectSQL()
{ {
return 'SELECT 1 FROM sysibm.sysdummy1'; return 'SELECT 1 FROM sysibm.sysdummy1';
} }
/** /**
* {@inheritDoc}
*
* DB2 supports savepoints, but they work semantically different than on other vendor platforms. * DB2 supports savepoints, but they work semantically different than on other vendor platforms.
* *
* TODO: We have to investigate how to get DB2 up and running with savepoints. * TODO: We have to investigate how to get DB2 up and running with savepoints.
*
* @return bool
*/ */
public function supportsSavepoints() public function supportsSavepoints()
{ {
return false; return false;
} }
/**
* {@inheritDoc}
*/
protected function getReservedKeywordsClass() protected function getReservedKeywordsClass()
{ {
return 'Doctrine\DBAL\Platforms\Keywords\DB2Keywords'; return 'Doctrine\DBAL\Platforms\Keywords\DB2Keywords';
......
...@@ -32,7 +32,7 @@ use Doctrine\DBAL\DBALException, ...@@ -32,7 +32,7 @@ use Doctrine\DBAL\DBALException,
class DrizzlePlatform extends AbstractPlatform class DrizzlePlatform extends AbstractPlatform
{ {
/** /**
* {@inheritdoc} * {@inheritDoc}
*/ */
public function getName() public function getName()
{ {
...@@ -40,59 +40,82 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -40,59 +40,82 @@ class DrizzlePlatform extends AbstractPlatform
} }
/** /**
* {@inheritdoc} * {@inheritDoc}
*/ */
public function getIdentifierQuoteCharacter() public function getIdentifierQuoteCharacter()
{ {
return '`'; return '`';
} }
public function getConcatExpression()
/**
* {@inheritDoc}
*/ public function getConcatExpression()
{ {
$args = func_get_args(); $args = func_get_args();
return 'CONCAT(' . join(', ', (array) $args) . ')'; return 'CONCAT(' . join(', ', (array) $args) . ')';
} }
/**
* {@inheritDoc}
*/
public function getDateDiffExpression($date1, $date2) public function getDateDiffExpression($date1, $date2)
{ {
return 'DATEDIFF(' . $date1 . ', ' . $date2 . ')'; return 'DATEDIFF(' . $date1 . ', ' . $date2 . ')';
} }
/**
* {@inheritDoc}
*/
public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
{ {
return 'DATE_ADD(' . $date . ', INTERVAL ' . $days . ' DAY)'; return 'DATE_ADD(' . $date . ', INTERVAL ' . $days . ' DAY)';
} }
/**
* {@inheritDoc}
*/
public function getDateSubDaysExpression($date, $days) public function getDateSubDaysExpression($date, $days)
{ {
return 'DATE_SUB(' . $date . ', INTERVAL ' . $days . ' DAY)'; return 'DATE_SUB(' . $date . ', INTERVAL ' . $days . ' DAY)';
} }
/**
* {@inheritDoc}
*/
public function getDateAddMonthExpression($date, $months) public function getDateAddMonthExpression($date, $months)
{ {
return 'DATE_ADD(' . $date . ', INTERVAL ' . $months . ' MONTH)'; return 'DATE_ADD(' . $date . ', INTERVAL ' . $months . ' MONTH)';
} }
/**
* {@inheritDoc}
*/
public function getDateSubMonthExpression($date, $months) public function getDateSubMonthExpression($date, $months)
{ {
return 'DATE_SUB(' . $date . ', INTERVAL ' . $months . ' MONTH)'; return 'DATE_SUB(' . $date . ', INTERVAL ' . $months . ' MONTH)';
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getBooleanTypeDeclarationSQL(array $field) public function getBooleanTypeDeclarationSQL(array $field)
{ {
return 'BOOLEAN'; return 'BOOLEAN';
} }
/**
* {@inheritDoc}
*/
public function getIntegerTypeDeclarationSQL(array $field) public function getIntegerTypeDeclarationSQL(array $field)
{ {
return 'INT' . $this->_getCommonIntegerTypeDeclarationSQL($field); return 'INT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
} }
/**
* {@inheritDoc}
*/
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{ {
$autoinc = ''; $autoinc = '';
...@@ -102,22 +125,33 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -102,22 +125,33 @@ class DrizzlePlatform extends AbstractPlatform
return $autoinc; return $autoinc;
} }
/**
* {@inheritDoc}
*/
public function getBigIntTypeDeclarationSQL(array $field) public function getBigIntTypeDeclarationSQL(array $field)
{ {
return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSQL($field); return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
} }
/**
* {@inheritDoc}
*/
public function getSmallIntTypeDeclarationSQL(array $field) public function getSmallIntTypeDeclarationSQL(array $field)
{ {
return 'INT' . $this->_getCommonIntegerTypeDeclarationSQL($field); return 'INT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
} }
/**
* {@inheritDoc}
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{ {
return $length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)'; return $length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)';
} }
/**
* {@inheritDoc}
*/
protected function initializeDoctrineTypeMappings() protected function initializeDoctrineTypeMappings()
{ {
$this->doctrineTypeMapping = array( $this->doctrineTypeMapping = array(
...@@ -136,24 +170,33 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -136,24 +170,33 @@ class DrizzlePlatform extends AbstractPlatform
); );
} }
/**
* {@inheritDoc}
*/
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
return 'TEXT'; return 'TEXT';
} }
/** /**
* Gets the SQL Snippet used to declare a BLOB column type. * {@inheritDoc}
*/ */
public function getBlobTypeDeclarationSQL(array $field) public function getBlobTypeDeclarationSQL(array $field)
{ {
return 'BLOB'; return 'BLOB';
} }
/**
* {@inheritDoc}
*/
public function getCreateDatabaseSQL($name) public function getCreateDatabaseSQL($name)
{ {
return 'CREATE DATABASE ' . $name; return 'CREATE DATABASE ' . $name;
} }
/**
* {@inheritDoc}
*/
public function getDropDatabaseSQL($name) public function getDropDatabaseSQL($name)
{ {
return 'DROP DATABASE ' . $name; return 'DROP DATABASE ' . $name;
...@@ -164,6 +207,9 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -164,6 +207,9 @@ class DrizzlePlatform extends AbstractPlatform
return "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE CATALOG_NAME='LOCAL'"; return "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE CATALOG_NAME='LOCAL'";
} }
/**
* {@inheritDoc}
*/
protected function getReservedKeywordsClass() protected function getReservedKeywordsClass()
{ {
return 'Doctrine\DBAL\Platforms\Keywords\DrizzleKeywords'; return 'Doctrine\DBAL\Platforms\Keywords\DrizzleKeywords';
...@@ -201,6 +247,9 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -201,6 +247,9 @@ class DrizzlePlatform extends AbstractPlatform
" WHERE CONSTRAINT_SCHEMA=" . $database . " AND CONSTRAINT_TABLE='" . $table . "'"; " WHERE CONSTRAINT_SCHEMA=" . $database . " AND CONSTRAINT_TABLE='" . $table . "'";
} }
/**
* {@inheritDoc}
*/
public function getListTableIndexesSQL($table, $database = null) public function getListTableIndexesSQL($table, $database = null)
{ {
if ($database) { if ($database) {
...@@ -214,37 +263,52 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -214,37 +263,52 @@ class DrizzlePlatform extends AbstractPlatform
" WHERE TABLE_SCHEMA=" . $database . " AND TABLE_NAME='" . $table . "'"; " WHERE TABLE_SCHEMA=" . $database . " AND TABLE_NAME='" . $table . "'";
} }
/**
* {@inheritDoc}
*/
public function prefersIdentityColumns() public function prefersIdentityColumns()
{ {
return true; return true;
} }
/**
* {@inheritDoc}
*/
public function supportsIdentityColumns() public function supportsIdentityColumns()
{ {
return true; return true;
} }
/**
* {@inheritDoc}
*/
public function supportsInlineColumnComments() public function supportsInlineColumnComments()
{ {
return true; return true;
} }
/**
* {@inheritDoc}
*/
public function supportsViews() public function supportsViews()
{ {
return false; return false;
} }
/**
* {@inheritDoc}
*/
public function getDropIndexSQL($index, $table=null) public function getDropIndexSQL($index, $table=null)
{ {
if($index instanceof Index) { if ($index instanceof Index) {
$indexName = $index->getQuotedName($this); $indexName = $index->getQuotedName($this);
} else if(is_string($index)) { } else if (is_string($index)) {
$indexName = $index; $indexName = $index;
} else { } else {
throw new \InvalidArgumentException('DrizzlePlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); throw new \InvalidArgumentException('DrizzlePlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
} }
if($table instanceof Table) { if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} else if(!is_string($table)) { } else if(!is_string($table)) {
throw new \InvalidArgumentException('DrizzlePlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); throw new \InvalidArgumentException('DrizzlePlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
...@@ -262,36 +326,44 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -262,36 +326,44 @@ class DrizzlePlatform extends AbstractPlatform
/** /**
* @param Index $index * @param Index $index
* @param Table $table * @param Table $table
*
* @return string
*/ */
protected function getDropPrimaryKeySQL($table) protected function getDropPrimaryKeySQL($table)
{ {
return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY'; return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
} }
/**
* {@inheritDoc}
*/
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] == true) { if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] == true) {
return 'TIMESTAMP'; return 'TIMESTAMP';
} else {
return 'DATETIME';
} }
return 'DATETIME';
} }
/**
* {@inheritDoc}
*/
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
return 'TIME'; return 'TIME';
} }
/**
* {@inheritDoc}
*/
public function getDateTypeDeclarationSQL(array $fieldDeclaration) public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{ {
return 'DATE'; return 'DATE';
} }
/** /**
* C/P from mysql platform * {@inheritDoc}
*
* @param TableDiff $diff
* @return string
*/ */
public function getAlterTableSQL(TableDiff $diff) public function getAlterTableSQL(TableDiff $diff)
{ {
...@@ -302,7 +374,7 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -302,7 +374,7 @@ class DrizzlePlatform extends AbstractPlatform
$queryParts[] = 'RENAME TO ' . $diff->newName; $queryParts[] = 'RENAME TO ' . $diff->newName;
} }
foreach ($diff->addedColumns as $fieldName => $column) { foreach ($diff->addedColumns as $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) { if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
continue; continue;
} }
...@@ -361,9 +433,12 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -361,9 +433,12 @@ class DrizzlePlatform extends AbstractPlatform
return array_merge($sql, $tableSql, $columnSql); return array_merge($sql, $tableSql, $columnSql);
} }
/**
* {@inheritDoc}
*/
public function getDropTemporaryTableSQL($table) public function getDropTemporaryTableSQL($table)
{ {
if ($table instanceof \Doctrine\DBAL\Schema\Table) { if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} else if(!is_string($table)) { } else if(!is_string($table)) {
throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
...@@ -372,6 +447,9 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -372,6 +447,9 @@ class DrizzlePlatform extends AbstractPlatform
return 'DROP TEMPORARY TABLE ' . $table; return 'DROP TEMPORARY TABLE ' . $table;
} }
/**
* {@inheritDoc}
*/
public function convertBooleans($item) public function convertBooleans($item)
{ {
if (is_array($item)) { if (is_array($item)) {
...@@ -380,28 +458,36 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -380,28 +458,36 @@ class DrizzlePlatform extends AbstractPlatform
$item[$key] = ($value) ? 'true' : 'false'; $item[$key] = ($value) ? 'true' : 'false';
} }
} }
} else { } else if (is_bool($item) || is_numeric($item)) {
if (is_bool($item) || is_numeric($item)) {
$item = ($item) ? 'true' : 'false'; $item = ($item) ? 'true' : 'false';
} }
}
return $item; return $item;
} }
/**
* {@inheritDoc}
*/
public function getLocateExpression($str, $substr, $startPos = false) public function getLocateExpression($str, $substr, $startPos = false)
{ {
if ($startPos == false) { if ($startPos == false) {
return 'LOCATE(' . $substr . ', ' . $str . ')'; return 'LOCATE(' . $substr . ', ' . $str . ')';
} else {
return 'LOCATE(' . $substr . ', ' . $str . ', '.$startPos.')';
} }
return 'LOCATE(' . $substr . ', ' . $str . ', '.$startPos.')';
} }
/**
* {@inheritDoc}
*/
public function getGuidExpression() public function getGuidExpression()
{ {
return 'UUID()'; return 'UUID()';
} }
/**
* {@inheritDoc}
*/
public function getRegexpExpression() public function getRegexpExpression()
{ {
return 'RLIKE'; return 'RLIKE';
......
...@@ -37,10 +37,7 @@ use Doctrine\DBAL\DBALException, ...@@ -37,10 +37,7 @@ use Doctrine\DBAL\DBALException,
class MySqlPlatform extends AbstractPlatform class MySqlPlatform extends AbstractPlatform
{ {
/** /**
* Gets the character used for identifier quoting. * {@inheritDoc}
*
* @return string
* @override
*/ */
public function getIdentifierQuoteCharacter() public function getIdentifierQuoteCharacter()
{ {
...@@ -48,10 +45,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -48,10 +45,7 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* Returns the regular expression operator. * {@inheritDoc}
*
* @return string
* @override
*/ */
public function getRegexpExpression() public function getRegexpExpression()
{ {
...@@ -59,10 +53,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -59,10 +53,7 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* Returns global unique identifier * {@inheritDoc}
*
* @return string to get global unique identifier
* @override
*/ */
public function getGuidExpression() public function getGuidExpression()
{ {
...@@ -70,30 +61,19 @@ class MySqlPlatform extends AbstractPlatform ...@@ -70,30 +61,19 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* returns the position of the first occurrence of substring $substr in string $str * {@inheritDoc}
*
* @param string $substr literal string to find
* @param string $str literal string
* @param int $pos position to start at, beginning of string by default
* @return integer
*/ */
public function getLocateExpression($str, $substr, $startPos = false) public function getLocateExpression($str, $substr, $startPos = false)
{ {
if ($startPos == false) { if ($startPos == false) {
return 'LOCATE(' . $substr . ', ' . $str . ')'; return 'LOCATE(' . $substr . ', ' . $str . ')';
} else {
return 'LOCATE(' . $substr . ', ' . $str . ', '.$startPos.')';
} }
return 'LOCATE(' . $substr . ', ' . $str . ', '.$startPos.')';
} }
/** /**
* Returns a series of strings concatenated * {@inheritDoc}
*
* concat() accepts an arbitrary number of parameters. Each parameter
* must contain an expression or an array with expressions.
*
* @param string|array(string) strings that will be concatenated.
* @override
*/ */
public function getConcatExpression() public function getConcatExpression()
{ {
...@@ -101,26 +81,41 @@ class MySqlPlatform extends AbstractPlatform ...@@ -101,26 +81,41 @@ class MySqlPlatform extends AbstractPlatform
return 'CONCAT(' . join(', ', (array) $args) . ')'; return 'CONCAT(' . join(', ', (array) $args) . ')';
} }
/**
* {@inheritDoc}
*/
public function getDateDiffExpression($date1, $date2) public function getDateDiffExpression($date1, $date2)
{ {
return 'DATEDIFF(' . $date1 . ', ' . $date2 . ')'; return 'DATEDIFF(' . $date1 . ', ' . $date2 . ')';
} }
/**
* {@inheritDoc}
*/
public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
{ {
return 'DATE_ADD(' . $date . ', INTERVAL ' . $days . ' DAY)'; return 'DATE_ADD(' . $date . ', INTERVAL ' . $days . ' DAY)';
} }
/**
* {@inheritDoc}
*/
public function getDateSubDaysExpression($date, $days) public function getDateSubDaysExpression($date, $days)
{ {
return 'DATE_SUB(' . $date . ', INTERVAL ' . $days . ' DAY)'; return 'DATE_SUB(' . $date . ', INTERVAL ' . $days . ' DAY)';
} }
/**
* {@inheritDoc}
*/
public function getDateAddMonthExpression($date, $months) public function getDateAddMonthExpression($date, $months)
{ {
return 'DATE_ADD(' . $date . ', INTERVAL ' . $months . ' MONTH)'; return 'DATE_ADD(' . $date . ', INTERVAL ' . $months . ' MONTH)';
} }
/**
* {@inheritDoc}
*/
public function getDateSubMonthExpression($date, $months) public function getDateSubMonthExpression($date, $months)
{ {
return 'DATE_SUB(' . $date . ', INTERVAL ' . $months . ' MONTH)'; return 'DATE_SUB(' . $date . ', INTERVAL ' . $months . ' MONTH)';
...@@ -137,12 +132,10 @@ class MySqlPlatform extends AbstractPlatform ...@@ -137,12 +132,10 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* {@inheritDoc}
*
* Two approaches to listing the table indexes. The information_schema is * Two approaches to listing the table indexes. The information_schema is
* preferred, because it doesn't cause problems with SQL keywords such as "order" or "table". * preferred, because it doesn't cause problems with SQL keywords such as "order" or "table".
*
* @param string $table
* @param string $currentDatabase
* @return string
*/ */
public function getListTableIndexesSQL($table, $currentDatabase = null) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
...@@ -152,9 +145,9 @@ class MySqlPlatform extends AbstractPlatform ...@@ -152,9 +145,9 @@ class MySqlPlatform extends AbstractPlatform
"CARDINALITY AS Cardinality, SUB_PART AS Sub_Part, PACKED AS Packed, " . "CARDINALITY AS Cardinality, SUB_PART AS Sub_Part, PACKED AS Packed, " .
"NULLABLE AS `Null`, INDEX_TYPE AS Index_Type, COMMENT AS Comment " . "NULLABLE AS `Null`, INDEX_TYPE AS Index_Type, COMMENT AS Comment " .
"FROM information_schema.STATISTICS WHERE TABLE_NAME = '" . $table . "' AND TABLE_SCHEMA = '" . $currentDatabase . "'"; "FROM information_schema.STATISTICS WHERE TABLE_NAME = '" . $table . "' AND TABLE_SCHEMA = '" . $currentDatabase . "'";
} else {
return 'SHOW INDEX FROM ' . $table;
} }
return 'SHOW INDEX FROM ' . $table;
} }
public function getListViewsSQL($database) public function getListViewsSQL($database)
...@@ -191,9 +184,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -191,9 +184,7 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* Gets the SQL snippet used to declare a VARCHAR column on the MySql platform. * {@inheritDoc}
*
* @params array $field
*/ */
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{ {
...@@ -201,36 +192,43 @@ class MySqlPlatform extends AbstractPlatform ...@@ -201,36 +192,43 @@ class MySqlPlatform extends AbstractPlatform
: ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)'); : ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
} }
/** @override */ /**
* {@inheritDoc}
*/
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
if ( ! empty($field['length']) && is_numeric($field['length'])) { if ( ! empty($field['length']) && is_numeric($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 255) { if ($length <= 255) {
return 'TINYTEXT'; return 'TINYTEXT';
} else if ($length <= 65532) { }
if ($length <= 65532) {
return 'TEXT'; return 'TEXT';
} else if ($length <= 16777215) { }
if ($length <= 16777215) {
return 'MEDIUMTEXT'; return 'MEDIUMTEXT';
} }
} }
return 'LONGTEXT'; return 'LONGTEXT';
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] == true) { if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] == true) {
return 'TIMESTAMP'; return 'TIMESTAMP';
} else {
return 'DATETIME';
} }
return 'DATETIME';
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTypeDeclarationSQL(array $fieldDeclaration) public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -238,7 +236,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -238,7 +236,7 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -246,7 +244,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -246,7 +244,7 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getBooleanTypeDeclarationSQL(array $field) public function getBooleanTypeDeclarationSQL(array $field)
{ {
...@@ -258,6 +256,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -258,6 +256,7 @@ class MySqlPlatform extends AbstractPlatform
* of a field declaration to be used in statements like CREATE TABLE. * of a field declaration to be used in statements like CREATE TABLE.
* *
* @param string $collation name of the collation * @param string $collation name of the collation
*
* @return string DBMS specific SQL code portion needed to set the COLLATION * @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration. * of a field declaration.
*/ */
...@@ -267,12 +266,10 @@ class MySqlPlatform extends AbstractPlatform ...@@ -267,12 +266,10 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* Whether the platform prefers identity columns for ID generation. * {@inheritDoc}
*
* MySql prefers "autoincrement" identity columns since sequences can only * MySql prefers "autoincrement" identity columns since sequences can only
* be emulated with a table. * be emulated with a table.
*
* @return boolean
* @override
*/ */
public function prefersIdentityColumns() public function prefersIdentityColumns()
{ {
...@@ -280,22 +277,26 @@ class MySqlPlatform extends AbstractPlatform ...@@ -280,22 +277,26 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* Whether the platform supports identity columns. * {@inheritDoc}
* MySql supports this through AUTO_INCREMENT columns.
* *
* @return boolean * MySql supports this through AUTO_INCREMENT columns.
* @override
*/ */
public function supportsIdentityColumns() public function supportsIdentityColumns()
{ {
return true; return true;
} }
/**
* {@inheritDoc}
*/
public function supportsInlineColumnComments() public function supportsInlineColumnComments()
{ {
return true; return true;
} }
/**
* {@inheritDoc}
*/
public function getShowDatabasesSQL() public function getShowDatabasesSQL()
{ {
return 'SHOW DATABASES'; return 'SHOW DATABASES';
...@@ -313,17 +314,13 @@ class MySqlPlatform extends AbstractPlatform ...@@ -313,17 +314,13 @@ class MySqlPlatform extends AbstractPlatform
"COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS Extra, COLUMN_COMMENT AS Comment, " . "COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS Extra, COLUMN_COMMENT AS Comment, " .
"CHARACTER_SET_NAME AS CharacterSet, COLLATION_NAME AS CollactionName ". "CHARACTER_SET_NAME AS CharacterSet, COLLATION_NAME AS CollactionName ".
"FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . $database . "' AND TABLE_NAME = '" . $table . "'"; "FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . $database . "' AND TABLE_NAME = '" . $table . "'";
} else {
return 'DESCRIBE ' . $table;
} }
return 'DESCRIBE ' . $table;
} }
/** /**
* create a new database * {@inheritDoc}
*
* @param string $name name of the database that should be created
* @return string
* @override
*/ */
public function getCreateDatabaseSQL($name) public function getCreateDatabaseSQL($name)
{ {
...@@ -331,11 +328,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -331,11 +328,7 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* drop an existing database * {@inheritDoc}
*
* @param string $name name of the database that should be dropped
* @return string
* @override
*/ */
public function getDropDatabaseSQL($name) public function getDropDatabaseSQL($name)
{ {
...@@ -343,45 +336,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -343,45 +336,7 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* create a new table * {@inheritDoc}
*
* @param string $tableName Name of the database that should be created
* @param array $columns Associative array that contains the definition of each field of the new table
* The indexes of the array entries are the names of the fields of the table an
* the array entry values are associative arrays like those that are meant to be
* passed with the field definitions to get[Type]Declaration() functions.
* array(
* 'id' => array(
* 'type' => 'integer',
* 'unsigned' => 1
* 'notnull' => 1
* 'default' => 0
* ),
* 'name' => array(
* 'type' => 'text',
* 'length' => 12
* ),
* 'password' => array(
* 'type' => 'text',
* 'length' => 12
* )
* );
* @param array $options An associative array of table options:
* array(
* 'comment' => 'Foo',
* 'charset' => 'utf8',
* 'collate' => 'utf8_unicode_ci',
* 'engine' => 'innodb',
* 'foreignKeys' => array(
* new ForeignKeyConstraint(),
* new ForeignKeyConstraint(),
* new ForeignKeyConstraint(),
* // etc
* )
* );
*
* @return string
* @override
*/ */
protected function _getCreateTableSQL($tableName, array $columns, array $options = array()) protected function _getCreateTableSQL($tableName, array $columns, array $options = array())
{ {
...@@ -444,10 +399,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -444,10 +399,7 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* Gets the SQL to alter an existing table. * {@inheritDoc}
*
* @param TableDiff $diff
* @return array
*/ */
public function getAlterTableSQL(TableDiff $diff) public function getAlterTableSQL(TableDiff $diff)
{ {
...@@ -517,10 +469,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -517,10 +469,7 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* Fix for DROP/CREATE index after foreign key change from OneToOne to ManyToOne * {@inheritDoc}
*
* @param TableDiff $diff
* @return array
*/ */
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
{ {
...@@ -557,9 +506,8 @@ class MySqlPlatform extends AbstractPlatform ...@@ -557,9 +506,8 @@ class MySqlPlatform extends AbstractPlatform
return $sql; return $sql;
} }
/** /**
* @override * {@inheritDoc}
*/ */
protected function getCreateIndexSQLFlags(Index $index) protected function getCreateIndexSQLFlags(Index $index)
{ {
...@@ -573,51 +521,33 @@ class MySqlPlatform extends AbstractPlatform ...@@ -573,51 +521,33 @@ class MySqlPlatform extends AbstractPlatform
return $type; return $type;
} }
/** /**
* Obtain DBMS specific SQL code portion needed to declare an integer type * {@inheritDoc}
* field to be used in statements like CREATE TABLE.
*
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes.
* Currently, the types of supported field
* properties are as follows:
*
* unsigned
* Boolean flag that indicates whether the field
* should be declared as unsigned integer if
* possible.
*
* default
* Integer value to be used as default for this
* field.
*
* notnull
* Boolean flag that indicates whether this field is
* constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
* @override
*/ */
public function getIntegerTypeDeclarationSQL(array $field) public function getIntegerTypeDeclarationSQL(array $field)
{ {
return 'INT' . $this->_getCommonIntegerTypeDeclarationSQL($field); return 'INT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
} }
/** @override */ /**
* {@inheritDoc}
*/
public function getBigIntTypeDeclarationSQL(array $field) public function getBigIntTypeDeclarationSQL(array $field)
{ {
return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSQL($field); return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
} }
/** @override */ /**
* {@inheritDoc}
*/
public function getSmallIntTypeDeclarationSQL(array $field) public function getSmallIntTypeDeclarationSQL(array $field)
{ {
return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSQL($field); return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
} }
/** @override */ /**
* {@inheritDoc}
*/
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{ {
$autoinc = ''; $autoinc = '';
...@@ -630,12 +560,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -630,12 +560,7 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* Return the FOREIGN KEY query section dealing with non-standard options * {@inheritDoc}
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
*
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey
* @return string
* @override
*/ */
public function getAdvancedForeignKeyOptionsSQL(\Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey) public function getAdvancedForeignKeyOptionsSQL(\Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey)
{ {
...@@ -648,15 +573,11 @@ class MySqlPlatform extends AbstractPlatform ...@@ -648,15 +573,11 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* Gets the SQL to drop an index of a table. * {@inheritDoc}
*
* @param Index $index name of the index to be dropped
* @param string|Table $table name of table that should be used in method
* @override
*/ */
public function getDropIndexSQL($index, $table=null) public function getDropIndexSQL($index, $table=null)
{ {
if($index instanceof Index) { if ($index instanceof Index) {
$indexName = $index->getQuotedName($this); $indexName = $index->getQuotedName($this);
} else if(is_string($index)) { } else if(is_string($index)) {
$indexName = $index; $indexName = $index;
...@@ -664,7 +585,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -664,7 +585,7 @@ class MySqlPlatform extends AbstractPlatform
throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
} }
if($table instanceof Table) { if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} else if(!is_string($table)) { } else if(!is_string($table)) {
throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
...@@ -680,34 +601,42 @@ class MySqlPlatform extends AbstractPlatform ...@@ -680,34 +601,42 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* @param Index $index * @param string $table
* @param Table $table *
* @return string
*/ */
protected function getDropPrimaryKeySQL($table) protected function getDropPrimaryKeySQL($table)
{ {
return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY'; return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
} }
/**
* {@inheritDoc}
*/
public function getSetTransactionIsolationSQL($level) public function getSetTransactionIsolationSQL($level)
{ {
return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level); return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level);
} }
/** /**
* Get the platform name for this instance. * {@inheritDoc}
*
* @return string
*/ */
public function getName() public function getName()
{ {
return 'mysql'; return 'mysql';
} }
/**
* {@inheritDoc}
*/
public function getReadLockSQL() public function getReadLockSQL()
{ {
return 'LOCK IN SHARE MODE'; return 'LOCK IN SHARE MODE';
} }
/**
* {@inheritDoc}
*/
protected function initializeDoctrineTypeMappings() protected function initializeDoctrineTypeMappings()
{ {
$this->doctrineTypeMapping = array( $this->doctrineTypeMapping = array(
...@@ -743,29 +672,31 @@ class MySqlPlatform extends AbstractPlatform ...@@ -743,29 +672,31 @@ class MySqlPlatform extends AbstractPlatform
); );
} }
/**
* {@inheritDoc}
*/
public function getVarcharMaxLength() public function getVarcharMaxLength()
{ {
return 65535; return 65535;
} }
/**
* {@inheritDoc}
*/
protected function getReservedKeywordsClass() protected function getReservedKeywordsClass()
{ {
return 'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords'; return 'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords';
} }
/** /**
* Get SQL to safely drop a temporary table WITHOUT implicitly committing an open transaction. * {@inheritDoc}
* *
* MySQL commits a transaction implicitly when DROP TABLE is executed, however not * MySQL commits a transaction implicitly when DROP TABLE is executed, however not
* if DROP TEMPORARY TABLE is executed. * if DROP TEMPORARY TABLE is executed.
*
* @throws \InvalidArgumentException
* @param $table
* @return string
*/ */
public function getDropTemporaryTableSQL($table) public function getDropTemporaryTableSQL($table)
{ {
if ($table instanceof \Doctrine\DBAL\Schema\Table) { if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} else if(!is_string($table)) { } else if(!is_string($table)) {
throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
...@@ -775,7 +706,7 @@ class MySqlPlatform extends AbstractPlatform ...@@ -775,7 +706,7 @@ class MySqlPlatform extends AbstractPlatform
} }
/** /**
* Gets the SQL Snippet used to declare a BLOB column type. * {@inheritDoc}
*/ */
public function getBlobTypeDeclarationSQL(array $field) public function getBlobTypeDeclarationSQL(array $field)
{ {
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
namespace Doctrine\DBAL\Platforms; namespace Doctrine\DBAL\Platforms;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
...@@ -36,7 +40,9 @@ class OraclePlatform extends AbstractPlatform ...@@ -36,7 +40,9 @@ class OraclePlatform extends AbstractPlatform
* Assertion for Oracle identifiers * Assertion for Oracle identifiers
* *
* @link http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements008.htm * @link http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements008.htm
*
* @param string * @param string
*
* @throws DBALException * @throws DBALException
*/ */
static public function assertValidIdentifier($identifier) static public function assertValidIdentifier($identifier)
...@@ -47,15 +53,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -47,15 +53,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* return string to call a function to get a substring inside an SQL statement * {@inheritDoc}
*
* Note: Not SQL92, but common functionality.
*
* @param string $value an sql string literal or column name/alias
* @param integer $position where to start the substring portion
* @param integer $length the substring portion length
* @return string SQL substring function with given parameters
* @override
*/ */
public function getSubstringExpression($value, $position, $length = null) public function getSubstringExpression($value, $position, $length = null)
{ {
...@@ -67,14 +65,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -67,14 +65,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* Return string to call a variable with the current timestamp inside an SQL statement * {@inheritDoc}
* There are three special variables for current date and time:
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
* - CURRENT_DATE (date, DATE type)
* - CURRENT_TIME (time, TIME type)
*
* @return string to call a variable with the current timestamp
* @override
*/ */
public function getNowExpression($type = 'timestamp') public function getNowExpression($type = 'timestamp')
{ {
...@@ -88,27 +79,19 @@ class OraclePlatform extends AbstractPlatform ...@@ -88,27 +79,19 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* returns the position of the first occurrence of substring $substr in string $str * {@inheritDoc}
*
* @param string $substr literal string to find
* @param string $str literal string
* @param int $pos position to start at, beginning of string by default
* @return integer
*/ */
public function getLocateExpression($str, $substr, $startPos = false) public function getLocateExpression($str, $substr, $startPos = false)
{ {
if ($startPos == false) { if ($startPos == false) {
return 'INSTR('.$str.', '.$substr.')'; return 'INSTR('.$str.', '.$substr.')';
} else {
return 'INSTR('.$str.', '.$substr.', '.$startPos.')';
} }
return 'INSTR('.$str.', '.$substr.', '.$startPos.')';
} }
/** /**
* Returns global unique identifier * {@inheritDoc}
*
* @return string to get global unique identifier
* @override
*/ */
public function getGuidExpression() public function getGuidExpression()
{ {
...@@ -116,15 +99,11 @@ class OraclePlatform extends AbstractPlatform ...@@ -116,15 +99,11 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* Get the number of days difference between two dates. * {@inheritDoc}
* *
* Note: Since Oracle timestamp differences are calculated down to the microsecond we have to truncate * Note: Since Oracle timestamp differences are calculated down to the microsecond we have to truncate
* them to the difference in days. This is obviously a restriction of the original functionality, but we * them to the difference in days. This is obviously a restriction of the original functionality, but we
* need to make this a portable function. * need to make this a portable function.
*
* @param string $date1
* @param string $date2
* @return string
*/ */
public function getDateDiffExpression($date1, $date2) public function getDateDiffExpression($date1, $date2)
{ {
...@@ -132,7 +111,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -132,7 +111,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* {@inheritdoc} * {@inheritDoc}
*/ */
public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
{ {
...@@ -140,7 +119,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -140,7 +119,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* {@inheritdoc} * {@inheritDoc}
*/ */
public function getDateSubDaysExpression($date, $days) public function getDateSubDaysExpression($date, $days)
{ {
...@@ -148,7 +127,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -148,7 +127,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* {@inheritdoc} * {@inheritDoc}
*/ */
public function getDateAddMonthExpression($date, $months) public function getDateAddMonthExpression($date, $months)
{ {
...@@ -156,7 +135,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -156,7 +135,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* {@inheritdoc} * {@inheritDoc}
*/ */
public function getDateSubMonthExpression($date, $months) public function getDateSubMonthExpression($date, $months)
{ {
...@@ -164,7 +143,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -164,7 +143,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* {@inheritdoc} * {@inheritDoc}
*/ */
public function getBitAndComparisonExpression($value1, $value2) public function getBitAndComparisonExpression($value1, $value2)
{ {
...@@ -172,7 +151,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -172,7 +151,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* {@inheritdoc} * {@inheritDoc}
*/ */
public function getBitOrComparisonExpression($value1, $value2) public function getBitOrComparisonExpression($value1, $value2)
{ {
...@@ -182,17 +161,13 @@ class OraclePlatform extends AbstractPlatform ...@@ -182,17 +161,13 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* Gets the SQL used to create a sequence that starts with a given value * {@inheritDoc}
* and increments by the given allocation size.
* *
* Need to specifiy minvalue, since start with is hidden in the system and MINVALUE <= START WITH. * Need to specifiy minvalue, since start with is hidden in the system and MINVALUE <= START WITH.
* Therefore we can use MINVALUE to be able to get a hint what START WITH was for later introspection * Therefore we can use MINVALUE to be able to get a hint what START WITH was for later introspection
* in {@see listSequences()} * in {@see listSequences()}
*
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @return string
*/ */
public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence) public function getCreateSequenceSQL(Sequence $sequence)
{ {
return 'CREATE SEQUENCE ' . $sequence->getQuotedName($this) . return 'CREATE SEQUENCE ' . $sequence->getQuotedName($this) .
' START WITH ' . $sequence->getInitialValue() . ' START WITH ' . $sequence->getInitialValue() .
...@@ -200,6 +175,9 @@ class OraclePlatform extends AbstractPlatform ...@@ -200,6 +175,9 @@ class OraclePlatform extends AbstractPlatform
' INCREMENT BY ' . $sequence->getAllocationSize(); ' INCREMENT BY ' . $sequence->getAllocationSize();
} }
/**
* {@inheritDoc}
*/
public function getAlterSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence) public function getAlterSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
{ {
return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) . return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) .
...@@ -207,10 +185,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -207,10 +185,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* {@inheritdoc} * {@inheritDoc}
*
* @param string $sequenceName
* @override
*/ */
public function getSequenceNextValSQL($sequenceName) public function getSequenceNextValSQL($sequenceName)
{ {
...@@ -218,16 +193,16 @@ class OraclePlatform extends AbstractPlatform ...@@ -218,16 +193,16 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* {@inheritdoc} * {@inheritDoc}
*
* @param integer $level
* @override
*/ */
public function getSetTransactionIsolationSQL($level) public function getSetTransactionIsolationSQL($level)
{ {
return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level); return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level);
} }
/**
* {@inheritDoc}
*/
protected function _getTransactionIsolationLevelSQL($level) protected function _getTransactionIsolationLevelSQL($level)
{ {
switch ($level) { switch ($level) {
...@@ -244,7 +219,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -244,7 +219,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getBooleanTypeDeclarationSQL(array $field) public function getBooleanTypeDeclarationSQL(array $field)
{ {
...@@ -252,7 +227,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -252,7 +227,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getIntegerTypeDeclarationSQL(array $field) public function getIntegerTypeDeclarationSQL(array $field)
{ {
...@@ -260,7 +235,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -260,7 +235,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getBigIntTypeDeclarationSQL(array $field) public function getBigIntTypeDeclarationSQL(array $field)
{ {
...@@ -268,7 +243,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -268,7 +243,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getSmallIntTypeDeclarationSQL(array $field) public function getSmallIntTypeDeclarationSQL(array $field)
{ {
...@@ -276,7 +251,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -276,7 +251,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -284,7 +259,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -284,7 +259,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -292,7 +267,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -292,7 +267,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTypeDeclarationSQL(array $fieldDeclaration) public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -300,7 +275,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -300,7 +275,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -308,7 +283,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -308,7 +283,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{ {
...@@ -316,10 +291,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -316,10 +291,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* Gets the SQL snippet used to declare a VARCHAR column on the Oracle platform. * {@inheritDoc}
*
* @params array $field
* @override
*/ */
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{ {
...@@ -327,7 +299,9 @@ class OraclePlatform extends AbstractPlatform ...@@ -327,7 +299,9 @@ class OraclePlatform extends AbstractPlatform
: ($length ? 'VARCHAR2(' . $length . ')' : 'VARCHAR2(4000)'); : ($length ? 'VARCHAR2(' . $length . ')' : 'VARCHAR2(4000)');
} }
/** @override */ /**
* {@inheritDoc}
*/
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
return 'CLOB'; return 'CLOB';
...@@ -345,11 +319,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -345,11 +319,7 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* * {@inheritDoc}
* @param string $table
* @param array $columns
* @param array $options
* @return array
*/ */
protected function _getCreateTableSQL($table, array $columns, array $options = array()) protected function _getCreateTableSQL($table, array $columns, array $options = array())
{ {
...@@ -378,10 +348,10 @@ class OraclePlatform extends AbstractPlatform ...@@ -378,10 +348,10 @@ class OraclePlatform extends AbstractPlatform
} }
/** /**
* {@inheritDoc}
*
* @license New BSD License * @license New BSD License
* @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaOracleReader.html * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaOracleReader.html
* @param string $table
* @return string
*/ */
public function getListTableIndexesSQL($table, $currentDatabase = null) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
...@@ -402,6 +372,9 @@ class OraclePlatform extends AbstractPlatform ...@@ -402,6 +372,9 @@ class OraclePlatform extends AbstractPlatform
return 'SELECT * FROM sys.user_tables'; return 'SELECT * FROM sys.user_tables';
} }
/**
* {@inheritDoc}
*/
public function getListViewsSQL($database) public function getListViewsSQL($database)
{ {
return 'SELECT view_name, text FROM sys.user_views'; return 'SELECT view_name, text FROM sys.user_views';
...@@ -424,7 +397,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -424,7 +397,7 @@ class OraclePlatform extends AbstractPlatform
$indexName = $table . '_AI_PK'; $indexName = $table . '_AI_PK';
$idx = new \Doctrine\DBAL\Schema\Index($indexName, array($name), true, true); $idx = new Index($indexName, array($name), true, true);
$sql[] = 'DECLARE $sql[] = 'DECLARE
constraints_Count NUMBER; constraints_Count NUMBER;
...@@ -436,7 +409,7 @@ BEGIN ...@@ -436,7 +409,7 @@ BEGIN
END;'; END;';
$sequenceName = $table . '_SEQ'; $sequenceName = $table . '_SEQ';
$sequence = new \Doctrine\DBAL\Schema\Sequence($sequenceName, $start); $sequence = new Sequence($sequenceName, $start);
$sql[] = $this->getCreateSequenceSQL($sequence); $sql[] = $this->getCreateSequenceSQL($sequence);
$triggerName = $table . '_AI_PK'; $triggerName = $table . '_AI_PK';
...@@ -461,6 +434,7 @@ BEGIN ...@@ -461,6 +434,7 @@ BEGIN
END LOOP; END LOOP;
END IF; END IF;
END;'; END;';
return $sql; return $sql;
} }
...@@ -469,13 +443,11 @@ END;'; ...@@ -469,13 +443,11 @@ END;';
$table = strtoupper($table); $table = strtoupper($table);
$trigger = $table . '_AI_PK'; $trigger = $table . '_AI_PK';
if ($trigger) {
$sql[] = 'DROP TRIGGER ' . $trigger; $sql[] = 'DROP TRIGGER ' . $trigger;
$sql[] = $this->getDropSequenceSQL($table.'_SEQ'); $sql[] = $this->getDropSequenceSQL($table.'_SEQ');
$indexName = $table . '_AI_PK'; $indexName = $table . '_AI_PK';
$sql[] = $this->getDropConstraintSQL($indexName, $table); $sql[] = $this->getDropConstraintSQL($indexName, $table);
}
return $sql; return $sql;
} }
...@@ -516,7 +488,8 @@ LEFT JOIN user_cons_columns r_cols ...@@ -516,7 +488,8 @@ LEFT JOIN user_cons_columns r_cols
$tabColumnsTableName = "user_tab_columns"; $tabColumnsTableName = "user_tab_columns";
$ownerCondition = ''; $ownerCondition = '';
if(null !== $database){
if (null !== $database){
$database = strtoupper($database); $database = strtoupper($database);
$tabColumnsTableName = "all_tab_columns"; $tabColumnsTableName = "all_tab_columns";
$ownerCondition = "AND c.owner = '".$database."'"; $ownerCondition = "AND c.owner = '".$database."'";
...@@ -528,13 +501,11 @@ LEFT JOIN user_cons_columns r_cols ...@@ -528,13 +501,11 @@ LEFT JOIN user_cons_columns r_cols
} }
/** /**
* * {@inheritDoc}
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @return string
*/ */
public function getDropSequenceSQL($sequence) public function getDropSequenceSQL($sequence)
{ {
if ($sequence instanceof \Doctrine\DBAL\Schema\Sequence) { if ($sequence instanceof Sequence) {
$sequence = $sequence->getQuotedName($this); $sequence = $sequence->getQuotedName($this);
} }
...@@ -542,39 +513,31 @@ LEFT JOIN user_cons_columns r_cols ...@@ -542,39 +513,31 @@ LEFT JOIN user_cons_columns r_cols
} }
/** /**
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint|string $foreignKey * {@inheritDoc}
* @param \Doctrine\DBAL\Schema\Table|string $table
* @return string
*/ */
public function getDropForeignKeySQL($foreignKey, $table) public function getDropForeignKeySQL($foreignKey, $table)
{ {
if ($foreignKey instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) { if ($foreignKey instanceof ForeignKeyConstraint) {
$foreignKey = $foreignKey->getQuotedName($this); $foreignKey = $foreignKey->getQuotedName($this);
} }
if ($table instanceof \Doctrine\DBAL\Schema\Table) { if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} }
return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $foreignKey; return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $foreignKey;
} }
/**
* {@inheritDoc}
*/
public function getDropDatabaseSQL($database) public function getDropDatabaseSQL($database)
{ {
return 'DROP USER ' . $database . ' CASCADE'; return 'DROP USER ' . $database . ' CASCADE';
} }
/** /**
* Gets the sql statements for altering an existing table. * {@inheritDoc}
*
* The method returns an array of sql statements, since some platforms need several statements.
*
* @param string $diff->name name of the table that is intended to be changed.
* @param array $changes associative array that contains the details of each type *
* @param boolean $check indicates whether the function should just check if the DBMS driver
* can perform the requested table alterations if the value is true or
* actually perform them otherwise.
* @return array
*/ */
public function getAlterTableSQL(TableDiff $diff) public function getAlterTableSQL(TableDiff $diff)
{ {
...@@ -583,6 +546,7 @@ LEFT JOIN user_cons_columns r_cols ...@@ -583,6 +546,7 @@ LEFT JOIN user_cons_columns r_cols
$columnSql = array(); $columnSql = array();
$fields = array(); $fields = array();
foreach ($diff->addedColumns as $column) { foreach ($diff->addedColumns as $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) { if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
continue; continue;
...@@ -593,6 +557,7 @@ LEFT JOIN user_cons_columns r_cols ...@@ -593,6 +557,7 @@ LEFT JOIN user_cons_columns r_cols
$commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment); $commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment);
} }
} }
if (count($fields)) { if (count($fields)) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ADD (' . implode(', ', $fields) . ')'; $sql[] = 'ALTER TABLE ' . $diff->name . ' ADD (' . implode(', ', $fields) . ')';
} }
...@@ -609,6 +574,7 @@ LEFT JOIN user_cons_columns r_cols ...@@ -609,6 +574,7 @@ LEFT JOIN user_cons_columns r_cols
$commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment); $commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment);
} }
} }
if (count($fields)) { if (count($fields)) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' MODIFY (' . implode(', ', $fields) . ')'; $sql[] = 'ALTER TABLE ' . $diff->name . ' MODIFY (' . implode(', ', $fields) . ')';
} }
...@@ -629,6 +595,7 @@ LEFT JOIN user_cons_columns r_cols ...@@ -629,6 +595,7 @@ LEFT JOIN user_cons_columns r_cols
$fields[] = $column->getQuotedName($this); $fields[] = $column->getQuotedName($this);
} }
if (count($fields)) { if (count($fields)) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' DROP (' . implode(', ', $fields).')'; $sql[] = 'ALTER TABLE ' . $diff->name . ' DROP (' . implode(', ', $fields).')';
} }
...@@ -647,24 +614,23 @@ LEFT JOIN user_cons_columns r_cols ...@@ -647,24 +614,23 @@ LEFT JOIN user_cons_columns r_cols
} }
/** /**
* Whether the platform prefers sequences for ID generation. * {@inheritDoc}
*
* @return boolean
*/ */
public function prefersSequences() public function prefersSequences()
{ {
return true; return true;
} }
/**
* {@inheritDoc}
*/
public function supportsCommentOnStatement() public function supportsCommentOnStatement()
{ {
return true; return true;
} }
/** /**
* Get the platform name for this instance * {@inheritDoc}
*
* @return string
*/ */
public function getName() public function getName()
{ {
...@@ -672,17 +638,13 @@ LEFT JOIN user_cons_columns r_cols ...@@ -672,17 +638,13 @@ LEFT JOIN user_cons_columns r_cols
} }
/** /**
* Adds an driver-specific LIMIT clause to the query * {@inheritDoc}
*
* @param string $query query to modify
* @param integer $limit limit the number of rows
* @param integer $offset start reading from given offset
* @return string the modified query
*/ */
protected function doModifyLimitQuery($query, $limit, $offset = null) protected function doModifyLimitQuery($query, $limit, $offset = null)
{ {
$limit = (int) $limit; $limit = (int) $limit;
$offset = (int) $offset; $offset = (int) $offset;
if (preg_match('/^\s*SELECT/i', $query)) { if (preg_match('/^\s*SELECT/i', $query)) {
if (!preg_match('/\sFROM\s/i', $query)) { if (!preg_match('/\sFROM\s/i', $query)) {
$query .= " FROM dual"; $query .= " FROM dual";
...@@ -700,16 +662,14 @@ LEFT JOIN user_cons_columns r_cols ...@@ -700,16 +662,14 @@ LEFT JOIN user_cons_columns r_cols
} }
} }
} }
return $query; return $query;
} }
/** /**
* Gets the character casing of a column in an SQL result set of this platform. * {@inheritDoc}
* *
* Oracle returns all column names in SQL result sets in uppercase. * Oracle returns all column names in SQL result sets in uppercase.
*
* @param string $column The column name for which to get the correct character casing.
* @return string The column name in the character casing used in SQL result sets.
*/ */
public function getSQLResultCasing($column) public function getSQLResultCasing($column)
{ {
...@@ -721,34 +681,45 @@ LEFT JOIN user_cons_columns r_cols ...@@ -721,34 +681,45 @@ LEFT JOIN user_cons_columns r_cols
return "CREATE GLOBAL TEMPORARY TABLE"; return "CREATE GLOBAL TEMPORARY TABLE";
} }
/**
* {@inheritDoc}
*/
public function getDateTimeTzFormatString() public function getDateTimeTzFormatString()
{ {
return 'Y-m-d H:i:sP'; return 'Y-m-d H:i:sP';
} }
/**
* {@inheritDoc}
*/
public function getDateFormatString() public function getDateFormatString()
{ {
return 'Y-m-d 00:00:00'; return 'Y-m-d 00:00:00';
} }
/**
* {@inheritDoc}
*/
public function getTimeFormatString() public function getTimeFormatString()
{ {
return '1900-01-01 H:i:s'; return '1900-01-01 H:i:s';
} }
/**
* {@inheritDoc}
*/
public function fixSchemaElementName($schemaElementName) public function fixSchemaElementName($schemaElementName)
{ {
if (strlen($schemaElementName) > 30) { if (strlen($schemaElementName) > 30) {
// Trim it // Trim it
return substr($schemaElementName, 0, 30); return substr($schemaElementName, 0, 30);
} }
return $schemaElementName; return $schemaElementName;
} }
/** /**
* Maximum length of any given database identifier, like tables or column names. * {@inheritDoc}
*
* @return int
*/ */
public function getMaxIdentifierLength() public function getMaxIdentifierLength()
{ {
...@@ -756,24 +727,23 @@ LEFT JOIN user_cons_columns r_cols ...@@ -756,24 +727,23 @@ LEFT JOIN user_cons_columns r_cols
} }
/** /**
* Whether the platform supports sequences. * {@inheritDoc}
*
* @return boolean
*/ */
public function supportsSequences() public function supportsSequences()
{ {
return true; return true;
} }
/**
* {@inheritDoc}
*/
public function supportsForeignKeyOnUpdate() public function supportsForeignKeyOnUpdate()
{ {
return false; return false;
} }
/** /**
* Whether the platform supports releasing savepoints. * {@inheritDoc}
*
* @return boolean
*/ */
public function supportsReleaseSavepoints() public function supportsReleaseSavepoints()
{ {
...@@ -781,7 +751,7 @@ LEFT JOIN user_cons_columns r_cols ...@@ -781,7 +751,7 @@ LEFT JOIN user_cons_columns r_cols
} }
/** /**
* @inheritdoc * {@inheritDoc}
*/ */
public function getTruncateTableSQL($tableName, $cascade = false) public function getTruncateTableSQL($tableName, $cascade = false)
{ {
...@@ -789,15 +759,16 @@ LEFT JOIN user_cons_columns r_cols ...@@ -789,15 +759,16 @@ LEFT JOIN user_cons_columns r_cols
} }
/** /**
* This is for test reasons, many vendors have special requirements for dummy statements. * {@inheritDoc}
*
* @return string
*/ */
public function getDummySelectSQL() public function getDummySelectSQL()
{ {
return 'SELECT 1 FROM DUAL'; return 'SELECT 1 FROM DUAL';
} }
/**
* {@inheritDoc}
*/
protected function initializeDoctrineTypeMappings() protected function initializeDoctrineTypeMappings()
{ {
$this->doctrineTypeMapping = array( $this->doctrineTypeMapping = array(
...@@ -826,23 +797,23 @@ LEFT JOIN user_cons_columns r_cols ...@@ -826,23 +797,23 @@ LEFT JOIN user_cons_columns r_cols
} }
/** /**
* Generate SQL to release a savepoint * {@inheritDoc}
*
* @param string $savepoint
* @return string
*/ */
public function releaseSavePoint($savepoint) public function releaseSavePoint($savepoint)
{ {
return ''; return '';
} }
/**
* {@inheritDoc}
*/
protected function getReservedKeywordsClass() protected function getReservedKeywordsClass()
{ {
return 'Doctrine\DBAL\Platforms\Keywords\OracleKeywords'; return 'Doctrine\DBAL\Platforms\Keywords\OracleKeywords';
} }
/** /**
* Gets the SQL Snippet used to declare a BLOB column type. * {@inheritDoc}
*/ */
public function getBlobTypeDeclarationSQL(array $field) public function getBlobTypeDeclarationSQL(array $field)
{ {
......
...@@ -34,29 +34,19 @@ use Doctrine\DBAL\Schema\TableDiff, ...@@ -34,29 +34,19 @@ use Doctrine\DBAL\Schema\TableDiff,
class PostgreSqlPlatform extends AbstractPlatform class PostgreSqlPlatform extends AbstractPlatform
{ {
/** /**
* Returns part of a string. * {@inheritDoc}
*
* Note: Not SQL92, but common functionality.
*
* @param string $value the target $value the string or the string column.
* @param int $from extract from this character.
* @param int $len extract this amount of characters.
* @return string sql that extracts part of a string.
* @override
*/ */
public function getSubstringExpression($value, $from, $len = null) public function getSubstringExpression($value, $from, $length = null)
{ {
if ($len === null) { if ($length === null) {
return 'SUBSTR(' . $value . ', ' . $from . ')'; return 'SUBSTR(' . $value . ', ' . $from . ')';
} else {
return 'SUBSTR(' . $value . ', ' . $from . ', ' . $len . ')';
} }
return 'SUBSTR(' . $value . ', ' . $from . ', ' . $length . ')';
} }
/** /**
* Returns the SQL string to return the current system date and time. * {@inheritDoc}
*
* @return string
*/ */
public function getNowExpression() public function getNowExpression()
{ {
...@@ -64,10 +54,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -64,10 +54,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* regexp * {@inheritDoc}
*
* @return string the regular expression operator
* @override
*/ */
public function getRegexpExpression() public function getRegexpExpression()
{ {
...@@ -75,65 +62,61 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -75,65 +62,61 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* returns the position of the first occurrence of substring $substr in string $str * {@inheritDoc}
*
* @param string $substr literal string to find
* @param string $str literal string
* @param int $pos position to start at, beginning of string by default
* @return integer
*/ */
public function getLocateExpression($str, $substr, $startPos = false) public function getLocateExpression($str, $substr, $startPos = false)
{ {
if ($startPos !== false) { if ($startPos !== false) {
$str = $this->getSubstringExpression($str, $startPos); $str = $this->getSubstringExpression($str, $startPos);
return 'CASE WHEN (POSITION('.$substr.' IN '.$str.') = 0) THEN 0 ELSE (POSITION('.$substr.' IN '.$str.') + '.($startPos-1).') END'; return 'CASE WHEN (POSITION('.$substr.' IN '.$str.') = 0) THEN 0 ELSE (POSITION('.$substr.' IN '.$str.') + '.($startPos-1).') END';
} else {
return 'POSITION('.$substr.' IN '.$str.')';
} }
return 'POSITION('.$substr.' IN '.$str.')';
} }
/**
* {@inheritDoc}
*/
public function getDateDiffExpression($date1, $date2) public function getDateDiffExpression($date1, $date2)
{ {
return '(DATE(' . $date1 . ')-DATE(' . $date2 . '))'; return '(DATE(' . $date1 . ')-DATE(' . $date2 . '))';
} }
/**
* {@inheritDoc}
*/
public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
{ {
return "(" . $date ." + (" . $days . " || ' day')::interval)"; return "(" . $date ." + (" . $days . " || ' day')::interval)";
} }
/**
* {@inheritDoc}
*/
public function getDateSubDaysExpression($date, $days) public function getDateSubDaysExpression($date, $days)
{ {
return "(" . $date ." - (" . $days . " || ' day')::interval)"; return "(" . $date ." - (" . $days . " || ' day')::interval)";
} }
/**
* {@inheritDoc}
*/
public function getDateAddMonthExpression($date, $months) public function getDateAddMonthExpression($date, $months)
{ {
return "(" . $date ." + (" . $months . " || ' month')::interval)"; return "(" . $date ." + (" . $months . " || ' month')::interval)";
} }
/**
* {@inheritDoc}
*/
public function getDateSubMonthExpression($date, $months) public function getDateSubMonthExpression($date, $months)
{ {
return "(" . $date ." - (" . $months . " || ' month')::interval)"; return "(" . $date ." - (" . $months . " || ' month')::interval)";
} }
/** /**
* parses a literal boolean value and returns * {@inheritDoc}
* proper sql equivalent
*
* @param string $value boolean value to be parsed
* @return string parsed boolean value
*/
/*public function parseBoolean($value)
{
return $value;
}*/
/**
* Whether the platform supports sequences.
* Postgres has native support for sequences.
*
* @return boolean
*/ */
public function supportsSequences() public function supportsSequences()
{ {
...@@ -141,9 +124,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -141,9 +124,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* Whether the platform supports database schemas. * {@inheritDoc}
*
* @return boolean
*/ */
public function supportsSchemas() public function supportsSchemas()
{ {
...@@ -151,25 +132,23 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -151,25 +132,23 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* Whether the platform supports identity columns. * {@inheritDoc}
* Postgres supports these through the SERIAL keyword.
*
* @return boolean
*/ */
public function supportsIdentityColumns() public function supportsIdentityColumns()
{ {
return true; return true;
} }
/**
* {@inheritDoc}
*/
public function supportsCommentOnStatement() public function supportsCommentOnStatement()
{ {
return true; return true;
} }
/** /**
* Whether the platform prefers sequences for ID generation. * {@inheritDoc}
*
* @return boolean
*/ */
public function prefersSequences() public function prefersSequences()
{ {
...@@ -197,6 +176,9 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -197,6 +176,9 @@ class PostgreSqlPlatform extends AbstractPlatform
FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' AND schemaname != 'information_schema' AND tablename != 'geometry_columns' AND tablename != 'spatial_ref_sys'"; FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' AND schemaname != 'information_schema' AND tablename != 'geometry_columns' AND tablename != 'spatial_ref_sys'";
} }
/**
* {@inheritDoc}
*/
public function getListViewsSQL($database) public function getListViewsSQL($database)
{ {
return 'SELECT viewname, definition FROM pg_views'; return 'SELECT viewname, definition FROM pg_views';
...@@ -241,10 +223,10 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -241,10 +223,10 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* {@inheritDoc}
*
* @license New BSD License * @license New BSD License
* @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html
* @param string $table
* @return string
*/ */
public function getListTableIndexesSQL($table, $currentDatabase = null) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
...@@ -262,6 +244,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -262,6 +244,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* @param string $table * @param string $table
* @param string $classAlias * @param string $classAlias
* @param string $namespaceAlias * @param string $namespaceAlias
*
* @return string * @return string
*/ */
private function getTableWhereClause($table, $classAlias = 'c', $namespaceAlias = 'n') private function getTableWhereClause($table, $classAlias = 'c', $namespaceAlias = 'n')
...@@ -313,11 +296,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -313,11 +296,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* create a new database * {@inheritDoc}
*
* @param string $name name of the database that should be created
* @return string
* @override
*/ */
public function getCreateDatabaseSQL($name) public function getCreateDatabaseSQL($name)
{ {
...@@ -325,55 +304,35 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -325,55 +304,35 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* drop an existing database * {@inheritDoc}
*
* @param string $name name of the database that should be dropped
* @access public
*/
public function getDropDatabaseSQL($name)
{
return 'DROP DATABASE ' . $name;
}
/**
* Return the FOREIGN KEY query section dealing with non-standard options
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
*
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey foreign key definition
* @return string
* @override
*/ */
public function getAdvancedForeignKeyOptionsSQL(\Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey) public function getAdvancedForeignKeyOptionsSQL(\Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey)
{ {
$query = ''; $query = '';
if ($foreignKey->hasOption('match')) { if ($foreignKey->hasOption('match')) {
$query .= ' MATCH ' . $foreignKey->getOption('match'); $query .= ' MATCH ' . $foreignKey->getOption('match');
} }
$query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey); $query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey);
if ($foreignKey->hasOption('deferrable') && $foreignKey->getOption('deferrable') !== false) { if ($foreignKey->hasOption('deferrable') && $foreignKey->getOption('deferrable') !== false) {
$query .= ' DEFERRABLE'; $query .= ' DEFERRABLE';
} else { } else {
$query .= ' NOT DEFERRABLE'; $query .= ' NOT DEFERRABLE';
} }
if ($foreignKey->hasOption('feferred') && $foreignKey->getOption('feferred') !== false) { if ($foreignKey->hasOption('feferred') && $foreignKey->getOption('feferred') !== false) {
$query .= ' INITIALLY DEFERRED'; $query .= ' INITIALLY DEFERRED';
} else { } else {
$query .= ' INITIALLY IMMEDIATE'; $query .= ' INITIALLY IMMEDIATE';
} }
return $query; return $query;
} }
/** /**
* generates the sql for altering an existing table on postgresql * {@inheritDoc}
*
* @param string $name name of the table that is intended to be changed.
* @param array $changes associative array that contains the details of each type *
* @param boolean $check indicates whether the function should just check if the DBMS driver
* can perform the requested table alterations if the value is true or
* actually perform them otherwise.
* @see Doctrine_Export::alterTable()
* @return array
* @override
*/ */
public function getAlterTableSQL(TableDiff $diff) public function getAlterTableSQL(TableDiff $diff)
{ {
...@@ -403,6 +362,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -403,6 +362,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
foreach ($diff->changedColumns as $columnDiff) { foreach ($diff->changedColumns as $columnDiff) {
/** @var $columnDiff \Doctrine\DBAL\Schema\ColumnDiff */
if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) { if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) {
continue; continue;
} }
...@@ -417,14 +377,17 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -417,14 +377,17 @@ class PostgreSqlPlatform extends AbstractPlatform
$query = 'ALTER ' . $oldColumnName . ' TYPE ' . $type->getSqlDeclaration($column->toArray(), $this); $query = 'ALTER ' . $oldColumnName . ' TYPE ' . $type->getSqlDeclaration($column->toArray(), $this);
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; $sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query;
} }
if ($columnDiff->hasChanged('default')) { if ($columnDiff->hasChanged('default')) {
$query = 'ALTER ' . $oldColumnName . ' SET ' . $this->getDefaultValueDeclarationSQL($column->toArray()); $query = 'ALTER ' . $oldColumnName . ' SET ' . $this->getDefaultValueDeclarationSQL($column->toArray());
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; $sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query;
} }
if ($columnDiff->hasChanged('notnull')) { if ($columnDiff->hasChanged('notnull')) {
$query = 'ALTER ' . $oldColumnName . ' ' . ($column->getNotNull() ? 'SET' : 'DROP') . ' NOT NULL'; $query = 'ALTER ' . $oldColumnName . ' ' . ($column->getNotNull() ? 'SET' : 'DROP') . ' NOT NULL';
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; $sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query;
} }
if ($columnDiff->hasChanged('autoincrement')) { if ($columnDiff->hasChanged('autoincrement')) {
if ($column->getAutoincrement()) { if ($column->getAutoincrement()) {
// add autoincrement // add autoincrement
...@@ -440,6 +403,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -440,6 +403,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$sql[] = "ALTER TABLE " . $diff->name . " " . $query; $sql[] = "ALTER TABLE " . $diff->name . " " . $query;
} }
} }
if ($columnDiff->hasChanged('comment') && $comment = $this->getColumnComment($column)) { if ($columnDiff->hasChanged('comment') && $comment = $this->getColumnComment($column)) {
$commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment); $commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment);
} }
...@@ -467,10 +431,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -467,10 +431,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* Gets the SQL to create a sequence on this platform. * {@inheritDoc}
*
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @return string
*/ */
public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence) public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
{ {
...@@ -480,6 +441,9 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -480,6 +441,9 @@ class PostgreSqlPlatform extends AbstractPlatform
' START ' . $sequence->getInitialValue(); ' START ' . $sequence->getInitialValue();
} }
/**
* {@inheritDoc}
*/
public function getAlterSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence) public function getAlterSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
{ {
return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) . return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) .
...@@ -487,9 +451,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -487,9 +451,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* Drop existing sequence * {@inheritDoc}
* @param \Doctrine\DBAL\Schema\Sequence $sequence
* @return string
*/ */
public function getDropSequenceSQL($sequence) public function getDropSequenceSQL($sequence)
{ {
...@@ -500,9 +462,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -500,9 +462,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint|string $foreignKey * {@inheritDoc}
* @param Table|string $table
* @return string
*/ */
public function getDropForeignKeySQL($foreignKey, $table) public function getDropForeignKeySQL($foreignKey, $table)
{ {
...@@ -510,12 +470,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -510,12 +470,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* Gets the SQL used to create a table. * {@inheritDoc}
*
* @param string $tableName
* @param array $columns
* @param array $options
* @return string
*/ */
protected function _getCreateTableSQL($tableName, array $columns, array $options = array()) protected function _getCreateTableSQL($tableName, array $columns, array $options = array())
{ {
...@@ -546,10 +501,9 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -546,10 +501,9 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* Postgres wants boolean values converted to the strings 'true'/'false'. * {@inheritDoc}
* *
* @param array $item * Postgres wants boolean values converted to the strings 'true'/'false'.
* @override
*/ */
public function convertBooleans($item) public function convertBooleans($item)
{ {
...@@ -564,6 +518,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -564,6 +518,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$item = ($item) ? 'true' : 'false'; $item = ($item) ? 'true' : 'false';
} }
} }
return $item; return $item;
} }
...@@ -572,6 +527,9 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -572,6 +527,9 @@ class PostgreSqlPlatform extends AbstractPlatform
return "SELECT NEXTVAL('" . $sequenceName . "')"; return "SELECT NEXTVAL('" . $sequenceName . "')";
} }
/**
* {@inheritDoc}
*/
public function getSetTransactionIsolationSQL($level) public function getSetTransactionIsolationSQL($level)
{ {
return 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' return 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL '
...@@ -579,7 +537,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -579,7 +537,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getBooleanTypeDeclarationSQL(array $field) public function getBooleanTypeDeclarationSQL(array $field)
{ {
...@@ -587,7 +545,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -587,7 +545,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getIntegerTypeDeclarationSQL(array $field) public function getIntegerTypeDeclarationSQL(array $field)
{ {
...@@ -599,7 +557,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -599,7 +557,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getBigIntTypeDeclarationSQL(array $field) public function getBigIntTypeDeclarationSQL(array $field)
{ {
...@@ -610,7 +568,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -610,7 +568,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getSmallIntTypeDeclarationSQL(array $field) public function getSmallIntTypeDeclarationSQL(array $field)
{ {
...@@ -618,10 +576,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -618,10 +576,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* Declaration for a UUID field in PostgreSQL * {@inheritDoc}
*
* @param array $field
* @return string
*/ */
public function getGuidTypeDeclarationSQL(array $field) public function getGuidTypeDeclarationSQL(array $field)
{ {
...@@ -629,7 +584,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -629,7 +584,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -637,7 +592,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -637,7 +592,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -645,7 +600,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -645,7 +600,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTypeDeclarationSQL(array $fieldDeclaration) public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -653,7 +608,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -653,7 +608,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -661,7 +616,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -661,7 +616,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{ {
...@@ -669,10 +624,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -669,10 +624,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* Gets the SQL snippet used to declare a VARCHAR column on the MySql platform. * {@inheritDoc}
*
* @params array $field
* @override
*/ */
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{ {
...@@ -680,16 +632,16 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -680,16 +632,16 @@ class PostgreSqlPlatform extends AbstractPlatform
: ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)'); : ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
} }
/** @override */ /**
* {@inheritDoc}
*/
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
return 'TEXT'; return 'TEXT';
} }
/** /**
* Get the platform name for this instance * {@inheritDoc}
*
* @return string
*/ */
public function getName() public function getName()
{ {
...@@ -697,29 +649,25 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -697,29 +649,25 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* Gets the character casing of a column in an SQL result set. * {@inheritDoc}
* *
* PostgreSQL returns all column names in SQL result sets in lowercase. * PostgreSQL returns all column names in SQL result sets in lowercase.
*
* @param string $column The column name for which to get the correct character casing.
* @return string The column name in the character casing used in SQL result sets.
*/ */
public function getSQLResultCasing($column) public function getSQLResultCasing($column)
{ {
return strtolower($column); return strtolower($column);
} }
/**
* {@inheritDoc}
*/
public function getDateTimeTzFormatString() public function getDateTimeTzFormatString()
{ {
return 'Y-m-d H:i:sO'; return 'Y-m-d H:i:sO';
} }
/** /**
* Get the insert sql for an empty insert statement * {@inheritDoc}
*
* @param string $tableName
* @param string $identifierColumnName
* @return string $sql
*/ */
public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierColumnName) public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierColumnName)
{ {
...@@ -727,18 +675,24 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -727,18 +675,24 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
/** /**
* @inheritdoc * {@inheritDoc}
*/ */
public function getTruncateTableSQL($tableName, $cascade = false) public function getTruncateTableSQL($tableName, $cascade = false)
{ {
return 'TRUNCATE '.$tableName.' '.(($cascade)?'CASCADE':''); return 'TRUNCATE '.$tableName.' '.(($cascade)?'CASCADE':'');
} }
/**
* {@inheritDoc}
*/
public function getReadLockSQL() public function getReadLockSQL()
{ {
return 'FOR SHARE'; return 'FOR SHARE';
} }
/**
* {@inheritDoc}
*/
protected function initializeDoctrineTypeMappings() protected function initializeDoctrineTypeMappings()
{ {
$this->doctrineTypeMapping = array( $this->doctrineTypeMapping = array(
...@@ -782,18 +736,24 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -782,18 +736,24 @@ class PostgreSqlPlatform extends AbstractPlatform
); );
} }
/**
* {@inheritDoc}
*/
public function getVarcharMaxLength() public function getVarcharMaxLength()
{ {
return 65535; return 65535;
} }
/**
* {@inheritDoc}
*/
protected function getReservedKeywordsClass() protected function getReservedKeywordsClass()
{ {
return 'Doctrine\DBAL\Platforms\Keywords\PostgreSQLKeywords'; return 'Doctrine\DBAL\Platforms\Keywords\PostgreSQLKeywords';
} }
/** /**
* Gets the SQL Snippet used to declare a BLOB column type. * {@inheritDoc}
*/ */
public function getBlobTypeDeclarationSQL(array $field) public function getBlobTypeDeclarationSQL(array $field)
{ {
......
...@@ -30,6 +30,9 @@ use Doctrine\DBAL\Schema\Table; ...@@ -30,6 +30,9 @@ use Doctrine\DBAL\Schema\Table;
*/ */
class SQLAzurePlatform extends SQLServer2008Platform class SQLAzurePlatform extends SQLServer2008Platform
{ {
/**
* {@inheritDoc}
*/
public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXES) public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXES)
{ {
$sql = parent::getCreateTableSQL($table, $createFlags); $sql = parent::getCreateTableSQL($table, $createFlags);
...@@ -41,6 +44,7 @@ class SQLAzurePlatform extends SQLServer2008Platform ...@@ -41,6 +44,7 @@ class SQLAzurePlatform extends SQLServer2008Platform
$sql[0] = $sql[0] . $stmt; $sql[0] = $sql[0] . $stmt;
} }
return $sql; return $sql;
} }
} }
......
...@@ -36,14 +36,16 @@ namespace Doctrine\DBAL\Platforms; ...@@ -36,14 +36,16 @@ namespace Doctrine\DBAL\Platforms;
class SQLServer2005Platform extends SQLServerPlatform class SQLServer2005Platform extends SQLServerPlatform
{ {
/** /**
* @override * {@inheritDoc}
*/ */
public function supportsLimitOffset() public function supportsLimitOffset()
{ {
return true; return true;
} }
/** @override */ /**
* {@inheritDoc}
*/
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
return 'VARCHAR(MAX)'; return 'VARCHAR(MAX)';
......
...@@ -28,7 +28,7 @@ namespace Doctrine\DBAL\Platforms; ...@@ -28,7 +28,7 @@ namespace Doctrine\DBAL\Platforms;
class SQLServer2008Platform extends SQLServer2005Platform class SQLServer2008Platform extends SQLServer2005Platform
{ {
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -38,7 +38,7 @@ class SQLServer2008Platform extends SQLServer2005Platform ...@@ -38,7 +38,7 @@ class SQLServer2008Platform extends SQLServer2005Platform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTypeDeclarationSQL(array $fieldDeclaration) public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -46,7 +46,7 @@ class SQLServer2008Platform extends SQLServer2005Platform ...@@ -46,7 +46,7 @@ class SQLServer2008Platform extends SQLServer2005Platform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -54,7 +54,7 @@ class SQLServer2008Platform extends SQLServer2005Platform ...@@ -54,7 +54,7 @@ class SQLServer2008Platform extends SQLServer2005Platform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTimeFormatString() public function getDateTimeFormatString()
{ {
...@@ -62,7 +62,7 @@ class SQLServer2008Platform extends SQLServer2005Platform ...@@ -62,7 +62,7 @@ class SQLServer2008Platform extends SQLServer2005Platform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTimeTzFormatString() public function getDateTimeTzFormatString()
{ {
...@@ -70,7 +70,7 @@ class SQLServer2008Platform extends SQLServer2005Platform ...@@ -70,7 +70,7 @@ class SQLServer2008Platform extends SQLServer2005Platform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateFormatString() public function getDateFormatString()
{ {
...@@ -78,7 +78,7 @@ class SQLServer2008Platform extends SQLServer2005Platform ...@@ -78,7 +78,7 @@ class SQLServer2008Platform extends SQLServer2005Platform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getTimeFormatString() public function getTimeFormatString()
{ {
...@@ -86,6 +86,8 @@ class SQLServer2008Platform extends SQLServer2005Platform ...@@ -86,6 +86,8 @@ class SQLServer2008Platform extends SQLServer2005Platform
} }
/** /**
* {@inheritDoc}
*
* Adding Datetime2 Type * Adding Datetime2 Type
*/ */
protected function initializeDoctrineTypeMappings() protected function initializeDoctrineTypeMappings()
......
...@@ -22,8 +22,9 @@ namespace Doctrine\DBAL\Platforms; ...@@ -22,8 +22,9 @@ namespace Doctrine\DBAL\Platforms;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Index, use Doctrine\DBAL\Schema\ForeignKeyConstraint;
Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Table;
/** /**
* The SQLServerPlatform provides the behavior, features and SQL dialect of the * The SQLServerPlatform provides the behavior, features and SQL dialect of the
...@@ -44,33 +45,43 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -44,33 +45,43 @@ class SQLServerPlatform extends AbstractPlatform
return 'DATEDIFF(day, ' . $date2 . ',' . $date1 . ')'; return 'DATEDIFF(day, ' . $date2 . ',' . $date1 . ')';
} }
/**
* {@inheritDoc}
*/
public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
{ {
return 'DATEADD(day, ' . $days . ', ' . $date . ')'; return 'DATEADD(day, ' . $days . ', ' . $date . ')';
} }
/**
* {@inheritDoc}
*/
public function getDateSubDaysExpression($date, $days) public function getDateSubDaysExpression($date, $days)
{ {
return 'DATEADD(day, -1 * ' . $days . ', ' . $date . ')'; return 'DATEADD(day, -1 * ' . $days . ', ' . $date . ')';
} }
/**
* {@inheritDoc}
*/
public function getDateAddMonthExpression($date, $months) public function getDateAddMonthExpression($date, $months)
{ {
return 'DATEADD(month, ' . $months . ', ' . $date . ')'; return 'DATEADD(month, ' . $months . ', ' . $date . ')';
} }
/**
* {@inheritDoc}
*/
public function getDateSubMonthExpression($date, $months) public function getDateSubMonthExpression($date, $months)
{ {
return 'DATEADD(month, -1 * ' . $months . ', ' . $date . ')'; return 'DATEADD(month, -1 * ' . $months . ', ' . $date . ')';
} }
/** /**
* Whether the platform prefers identity columns for ID generation. * {@inheritDoc}
*
* MsSql prefers "autoincrement" identity columns since sequences can only * MsSql prefers "autoincrement" identity columns since sequences can only
* be emulated with a table. * be emulated with a table.
*
* @return boolean
* @override
*/ */
public function prefersIdentityColumns() public function prefersIdentityColumns()
{ {
...@@ -78,11 +89,9 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -78,11 +89,9 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* Whether the platform supports identity columns. * {@inheritDoc}
* MsSql supports this through AUTO_INCREMENT columns.
* *
* @return boolean * MsSql supports this through AUTO_INCREMENT columns.
* @override
*/ */
public function supportsIdentityColumns() public function supportsIdentityColumns()
{ {
...@@ -90,9 +99,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -90,9 +99,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* Whether the platform supports releasing savepoints. * {@inheritDoc}
*
* @return boolean
*/ */
public function supportsReleaseSavepoints() public function supportsReleaseSavepoints()
{ {
...@@ -100,11 +107,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -100,11 +107,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* create a new database * {@inheritDoc}
*
* @param string $name name of the database that should be created
* @return string
* @override
*/ */
public function getCreateDatabaseSQL($name) public function getCreateDatabaseSQL($name)
{ {
...@@ -112,11 +115,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -112,11 +115,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* drop an existing database * {@inheritDoc}
*
* @param string $name name of the database that should be dropped
* @return string
* @override
*/ */
public function getDropDatabaseSQL($name) public function getDropDatabaseSQL($name)
{ {
...@@ -124,7 +123,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -124,7 +123,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function supportsCreateDropDatabase() public function supportsCreateDropDatabase()
{ {
...@@ -132,15 +131,15 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -132,15 +131,15 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDropForeignKeySQL($foreignKey, $table) public function getDropForeignKeySQL($foreignKey, $table)
{ {
if ($foreignKey instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) { if ($foreignKey instanceof ForeignKeyConstraint) {
$foreignKey = $foreignKey->getQuotedName($this); $foreignKey = $foreignKey->getQuotedName($this);
} }
if ($table instanceof \Doctrine\DBAL\Schema\Table) { if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} }
...@@ -148,11 +147,11 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -148,11 +147,11 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDropIndexSQL($index, $table=null) public function getDropIndexSQL($index, $table = null)
{ {
if ($index instanceof \Doctrine\DBAL\Schema\Index) { if ($index instanceof Index) {
$index = $index->getQuotedName($this); $index = $index->getQuotedName($this);
} else if (!is_string($index)) { } else if (!is_string($index)) {
throw new \InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); throw new \InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
...@@ -160,8 +159,9 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -160,8 +159,9 @@ class SQLServerPlatform extends AbstractPlatform
if (!isset($table)) { if (!isset($table)) {
return 'DROP INDEX ' . $index; return 'DROP INDEX ' . $index;
} else { }
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
if ($table instanceof Table) {
$table = $table->getQuotedName($this); $table = $table->getQuotedName($this);
} }
...@@ -170,15 +170,14 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -170,15 +170,14 @@ class SQLServerPlatform extends AbstractPlatform
ELSE ELSE
DROP INDEX " . $index . " ON " . $table; DROP INDEX " . $index . " ON " . $table;
} }
}
/** /**
* @override * {@inheritDoc}
*/ */
protected function _getCreateTableSQL($tableName, array $columns, array $options = array()) protected function _getCreateTableSQL($tableName, array $columns, array $options = array())
{ {
// @todo does other code breaks because of this? // @todo does other code breaks because of this?
// foce primary keys to be not null // force primary keys to be not null
foreach ($columns as &$column) { foreach ($columns as &$column) {
if (isset($column['primary']) && $column['primary']) { if (isset($column['primary']) && $column['primary']) {
$column['notnull'] = true; $column['notnull'] = true;
...@@ -227,11 +226,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -227,11 +226,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* Get SQL to create an unnamed primary key constraint. * {@inheritDoc}
*
* @param Index $index
* @param string|Table $table
* @return string
*/ */
public function getCreatePrimaryKeySQL(Index $index, $table) public function getCreatePrimaryKeySQL(Index $index, $table)
{ {
...@@ -243,7 +238,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -243,7 +238,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getUniqueConstraintDeclarationSQL($name, Index $index) public function getUniqueConstraintDeclarationSQL($name, Index $index)
{ {
...@@ -255,7 +250,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -255,7 +250,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getCreateIndexSQL(Index $index, $table) public function getCreateIndexSQL(Index $index, $table)
{ {
...@@ -269,7 +264,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -269,7 +264,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
protected function getCreateIndexSQLFlags(Index $index) protected function getCreateIndexSQLFlags(Index $index)
{ {
...@@ -292,6 +287,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -292,6 +287,7 @@ class SQLServerPlatform extends AbstractPlatform
* *
* @param string $sql * @param string $sql
* @param Index $index * @param Index $index
*
* @return string * @return string
*/ */
private function _appendUniqueConstraintDefinition($sql, Index $index) private function _appendUniqueConstraintDefinition($sql, Index $index)
...@@ -309,7 +305,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -309,7 +305,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getAlterTableSQL(TableDiff $diff) public function getAlterTableSQL(TableDiff $diff)
{ {
...@@ -374,7 +370,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -374,7 +370,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierColumnName) public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierColumnName)
{ {
...@@ -382,7 +378,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -382,7 +378,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getShowDatabasesSQL() public function getShowDatabasesSQL()
{ {
...@@ -390,7 +386,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -390,7 +386,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getListTablesSQL() public function getListTablesSQL()
{ {
...@@ -399,7 +395,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -399,7 +395,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getListTableColumnsSQL($table, $database = null) public function getListTableColumnsSQL($table, $database = null)
{ {
...@@ -407,7 +403,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -407,7 +403,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getListTableForeignKeysSQL($table, $database = null) public function getListTableForeignKeysSQL($table, $database = null)
{ {
...@@ -428,7 +424,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -428,7 +424,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getListTableIndexesSQL($table, $currentDatabase = null) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
...@@ -436,7 +432,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -436,7 +432,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getCreateViewSQL($name, $sql) public function getCreateViewSQL($name, $sql)
{ {
...@@ -444,7 +440,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -444,7 +440,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getListViewsSQL($database) public function getListViewsSQL($database)
{ {
...@@ -452,7 +448,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -452,7 +448,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDropViewSQL($name) public function getDropViewSQL($name)
{ {
...@@ -460,10 +456,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -460,10 +456,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* Returns the regular expression operator. * {@inheritDoc}
*
* @return string
* @override
*/ */
public function getRegexpExpression() public function getRegexpExpression()
{ {
...@@ -471,10 +464,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -471,10 +464,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* Returns global unique identifier * {@inheritDoc}
*
* @return string to get global unique identifier
* @override
*/ */
public function getGuidExpression() public function getGuidExpression()
{ {
...@@ -482,19 +472,19 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -482,19 +472,19 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getLocateExpression($str, $substr, $startPos = false) public function getLocateExpression($str, $substr, $startPos = false)
{ {
if ($startPos == false) { if ($startPos == false) {
return 'CHARINDEX(' . $substr . ', ' . $str . ')'; return 'CHARINDEX(' . $substr . ', ' . $str . ')';
} else {
return 'CHARINDEX(' . $substr . ', ' . $str . ', ' . $startPos . ')';
} }
return 'CHARINDEX(' . $substr . ', ' . $str . ', ' . $startPos . ')';
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getModExpression($expression1, $expression2) public function getModExpression($expression1, $expression2)
{ {
...@@ -502,23 +492,27 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -502,23 +492,27 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false) public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false)
{ {
$trimFn = '';
if ( ! $char) { if ( ! $char) {
if ($pos == self::TRIM_LEADING) { switch ($pos) {
case self::TRIM_LEADING:
$trimFn = 'LTRIM'; $trimFn = 'LTRIM';
} else if ($pos == self::TRIM_TRAILING) { break;
case self::TRIM_TRAILING:
$trimFn = 'RTRIM'; $trimFn = 'RTRIM';
} else { break;
default:
return 'LTRIM(RTRIM(' . $str . '))'; return 'LTRIM(RTRIM(' . $str . '))';
} }
return $trimFn . '(' . $str . ')'; return $trimFn . '(' . $str . ')';
} else { }
/** Original query used to get those expressions /** Original query used to get those expressions
declare @c varchar(100) = 'xxxBarxxx', @trim_char char(1) = 'x'; declare @c varchar(100) = 'xxxBarxxx', @trim_char char(1) = 'x';
declare @pat varchar(10) = '%[^' + @trim_char + ']%'; declare @pat varchar(10) = '%[^' + @trim_char + ']%';
...@@ -532,20 +526,22 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -532,20 +526,22 @@ class SQLServerPlatform extends AbstractPlatform
if ($pos == self::TRIM_LEADING) { if ($pos == self::TRIM_LEADING) {
return 'stuff(' . $str . ', 1, patindex(' . $pattern . ', ' . $str . ') - 1, null)'; return 'stuff(' . $str . ', 1, patindex(' . $pattern . ', ' . $str . ') - 1, null)';
} else if ($pos == self::TRIM_TRAILING) {
return 'reverse(stuff(reverse(' . $str . '), 1, patindex(' . $pattern . ', reverse(' . $str . ')) - 1, null))';
} else {
return 'reverse(stuff(reverse(stuff(' . $str . ', 1, patindex(' . $pattern . ', ' . $str . ') - 1, null)), 1, patindex(' . $pattern . ', reverse(stuff(' . $str . ', 1, patindex(' . $pattern . ', ' . $str . ') - 1, null))) - 1, null))';
} }
if ($pos == self::TRIM_TRAILING) {
return 'reverse(stuff(reverse(' . $str . '), 1, patindex(' . $pattern . ', reverse(' . $str . ')) - 1, null))';
} }
return 'reverse(stuff(reverse(stuff(' . $str . ', 1, patindex(' . $pattern . ', ' . $str . ') - 1, null)), 1, patindex(' . $pattern . ', reverse(stuff(' . $str . ', 1, patindex(' . $pattern . ', ' . $str . ') - 1, null))) - 1, null))';
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getConcatExpression() public function getConcatExpression()
{ {
$args = func_get_args(); $args = func_get_args();
return '(' . implode(' + ', $args) . ')'; return '(' . implode(' + ', $args) . ')';
} }
...@@ -555,18 +551,19 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -555,18 +551,19 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getSubstringExpression($value, $from, $len = null) public function getSubstringExpression($value, $from, $length = null)
{ {
if (!is_null($len)) { if (!is_null($length)) {
return 'SUBSTRING(' . $value . ', ' . $from . ', ' . $len . ')'; return 'SUBSTRING(' . $value . ', ' . $from . ', ' . $length . ')';
} }
return 'SUBSTRING(' . $value . ', ' . $from . ', LEN(' . $value . ') - ' . $from . ' + 1)'; return 'SUBSTRING(' . $value . ', ' . $from . ', LEN(' . $value . ') - ' . $from . ' + 1)';
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getLengthExpression($column) public function getLengthExpression($column)
{ {
...@@ -574,7 +571,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -574,7 +571,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getSetTransactionIsolationSQL($level) public function getSetTransactionIsolationSQL($level)
{ {
...@@ -582,7 +579,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -582,7 +579,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getIntegerTypeDeclarationSQL(array $field) public function getIntegerTypeDeclarationSQL(array $field)
{ {
...@@ -590,7 +587,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -590,7 +587,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getBigIntTypeDeclarationSQL(array $field) public function getBigIntTypeDeclarationSQL(array $field)
{ {
...@@ -598,7 +595,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -598,7 +595,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getSmallIntTypeDeclarationSQL(array $field) public function getSmallIntTypeDeclarationSQL(array $field)
{ {
...@@ -606,30 +603,31 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -606,30 +603,31 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* Declaration for a UNIQUEIDENTIFIER (GUID) field in SQL Server * {@inheritDoc}
*
* @param array $field
* @return string
*/ */
public function getGuidTypeDeclarationSQL(array $field) public function getGuidTypeDeclarationSQL(array $field)
{ {
return 'UNIQUEIDENTIFIER'; return 'UNIQUEIDENTIFIER';
} }
/** @override */ /**
* {@inheritDoc}
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{ {
return $fixed ? ($length ? 'NCHAR(' . $length . ')' : 'CHAR(255)') : ($length ? 'NVARCHAR(' . $length . ')' : 'NVARCHAR(255)'); return $fixed ? ($length ? 'NCHAR(' . $length . ')' : 'CHAR(255)') : ($length ? 'NVARCHAR(' . $length . ')' : 'NVARCHAR(255)');
} }
/** @override */ /**
* {@inheritDoc}
*/
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
return 'TEXT'; return 'TEXT';
} }
/** /**
* @override * {@inheritDoc}
*/ */
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{ {
...@@ -643,7 +641,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -643,7 +641,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -651,7 +649,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -651,7 +649,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTypeDeclarationSQL(array $fieldDeclaration) public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -659,7 +657,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -659,7 +657,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -667,7 +665,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -667,7 +665,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getBooleanTypeDeclarationSQL(array $field) public function getBooleanTypeDeclarationSQL(array $field)
{ {
...@@ -675,13 +673,9 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -675,13 +673,9 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* Adds an adapter-specific LIMIT clause to the SELECT statement. * {@inheritDoc}
* *
* @param string $query
* @param integer $limit
* @param integer $offset
* @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html * @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html
* @return string
*/ */
protected function doModifyLimitQuery($query, $limit, $offset = null) protected function doModifyLimitQuery($query, $limit, $offset = null)
{ {
...@@ -712,7 +706,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -712,7 +706,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function supportsLimitOffset() public function supportsLimitOffset()
{ {
...@@ -720,7 +714,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -720,7 +714,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function convertBooleans($item) public function convertBooleans($item)
{ {
...@@ -730,16 +724,15 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -730,16 +724,15 @@ class SQLServerPlatform extends AbstractPlatform
$item[$key] = ($value) ? 1 : 0; $item[$key] = ($value) ? 1 : 0;
} }
} }
} else { } else if (is_bool($item) || is_numeric($item)) {
if (is_bool($item) || is_numeric($item)) {
$item = ($item) ? 1 : 0; $item = ($item) ? 1 : 0;
} }
}
return $item; return $item;
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getCreateTemporaryTableSnippetSQL() public function getCreateTemporaryTableSnippetSQL()
{ {
...@@ -747,7 +740,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -747,7 +740,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getTemporaryTableName($tableName) public function getTemporaryTableName($tableName)
{ {
...@@ -755,7 +748,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -755,7 +748,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTimeFormatString() public function getDateTimeFormatString()
{ {
...@@ -763,7 +756,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -763,7 +756,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateFormatString() public function getDateFormatString()
{ {
...@@ -771,7 +764,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -771,7 +764,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getTimeFormatString() public function getTimeFormatString()
{ {
...@@ -779,7 +772,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -779,7 +772,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTimeTzFormatString() public function getDateTimeTzFormatString()
{ {
...@@ -787,9 +780,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -787,9 +780,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* Get the platform name for this instance * {@inheritDoc}
*
* @return string
*/ */
public function getName() public function getName()
{ {
...@@ -797,7 +788,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -797,7 +788,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
protected function initializeDoctrineTypeMappings() protected function initializeDoctrineTypeMappings()
{ {
...@@ -832,10 +823,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -832,10 +823,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* Generate SQL to create a new savepoint * {@inheritDoc}
*
* @param string $savepoint
* @return string
*/ */
public function createSavePoint($savepoint) public function createSavePoint($savepoint)
{ {
...@@ -843,10 +831,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -843,10 +831,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* Generate SQL to release a savepoint * {@inheritDoc}
*
* @param string $savepoint
* @return string
*/ */
public function releaseSavePoint($savepoint) public function releaseSavePoint($savepoint)
{ {
...@@ -854,10 +839,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -854,10 +839,7 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* Generate SQL to rollback a savepoint * {@inheritDoc}
*
* @param string $savepoint
* @return string
*/ */
public function rollbackSavePoint($savepoint) public function rollbackSavePoint($savepoint)
{ {
...@@ -865,28 +847,33 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -865,28 +847,33 @@ class SQLServerPlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function appendLockHint($fromClause, $lockMode) public function appendLockHint($fromClause, $lockMode)
{ {
// @todo correct // @todo correct
if ($lockMode == \Doctrine\DBAL\LockMode::PESSIMISTIC_READ) { if ($lockMode == \Doctrine\DBAL\LockMode::PESSIMISTIC_READ) {
return $fromClause . ' WITH (tablockx)'; return $fromClause . ' WITH (tablockx)';
} else if ($lockMode == \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE) { }
if ($lockMode == \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE) {
return $fromClause . ' WITH (tablockx)'; return $fromClause . ' WITH (tablockx)';
} else {
return $fromClause;
} }
return $fromClause;
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getForUpdateSQL() public function getForUpdateSQL()
{ {
return ' '; return ' ';
} }
/**
* {@inheritDoc}
*/
protected function getReservedKeywordsClass() protected function getReservedKeywordsClass()
{ {
return 'Doctrine\DBAL\Platforms\Keywords\MsSQLKeywords'; return 'Doctrine\DBAL\Platforms\Keywords\MsSQLKeywords';
...@@ -900,13 +887,16 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -900,13 +887,16 @@ class SQLServerPlatform extends AbstractPlatform
return "[" . str_replace("]", "][", $str) . "]"; return "[" . str_replace("]", "][", $str) . "]";
} }
/**
* {@inheritDoc}
*/
public function getTruncateTableSQL($tableName, $cascade = false) public function getTruncateTableSQL($tableName, $cascade = false)
{ {
return 'TRUNCATE TABLE '.$tableName; return 'TRUNCATE TABLE '.$tableName;
} }
/** /**
* Gets the SQL Snippet used to declare a BLOB column type. * {@inheritDoc}
*/ */
public function getBlobTypeDeclarationSQL(array $field) public function getBlobTypeDeclarationSQL(array $field)
{ {
......
...@@ -33,10 +33,7 @@ use Doctrine\DBAL\DBALException; ...@@ -33,10 +33,7 @@ use Doctrine\DBAL\DBALException;
class SqlitePlatform extends AbstractPlatform class SqlitePlatform extends AbstractPlatform
{ {
/** /**
* returns the regular expression operator * {@inheritDoc}
*
* @return string
* @override
*/ */
public function getRegexpExpression() public function getRegexpExpression()
{ {
...@@ -44,11 +41,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -44,11 +41,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* Return string to call a variable with the current timestamp inside an SQL statement * {@inheritDoc}
* There are three special variables for current date and time.
*
* @return string sqlite function as string
* @override
*/ */
public function getNowExpression($type = 'timestamp') public function getNowExpression($type = 'timestamp')
{ {
...@@ -64,23 +57,22 @@ class SqlitePlatform extends AbstractPlatform ...@@ -64,23 +57,22 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* Trim a string, leading/trailing/both and with a given char which defaults to space. * {@inheritDoc}
*
* @param string $str
* @param int $pos
* @param string $char
* @return string
*/ */
public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false) public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false)
{ {
$trimFn = '';
$trimChar = ($char != false) ? (', ' . $char) : ''; $trimChar = ($char != false) ? (', ' . $char) : '';
if ($pos == self::TRIM_LEADING) { switch ($pos) {
case self::TRIM_LEADING:
$trimFn = 'LTRIM'; $trimFn = 'LTRIM';
} else if($pos == self::TRIM_TRAILING) { break;
case self::TRIM_TRAILING:
$trimFn = 'RTRIM'; $trimFn = 'RTRIM';
} else { break;
default:
$trimFn = 'TRIM'; $trimFn = 'TRIM';
} }
...@@ -88,68 +80,74 @@ class SqlitePlatform extends AbstractPlatform ...@@ -88,68 +80,74 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* return string to call a function to get a substring inside an SQL statement * {@inheritDoc}
*
* Note: Not SQL92, but common functionality.
* *
* SQLite only supports the 2 parameter variant of this function * SQLite only supports the 2 parameter variant of this function
*
* @param string $value an sql string literal or column name/alias
* @param integer $position where to start the substring portion
* @param integer $length the substring portion length
* @return string SQL substring function with given parameters
* @override
*/ */
public function getSubstringExpression($value, $position, $length = null) public function getSubstringExpression($value, $position, $length = null)
{ {
if ($length !== null) { if ($length !== null) {
return 'SUBSTR(' . $value . ', ' . $position . ', ' . $length . ')'; return 'SUBSTR(' . $value . ', ' . $position . ', ' . $length . ')';
} }
return 'SUBSTR(' . $value . ', ' . $position . ', LENGTH(' . $value . '))'; return 'SUBSTR(' . $value . ', ' . $position . ', LENGTH(' . $value . '))';
} }
/** /**
* returns the position of the first occurrence of substring $substr in string $str * {@inheritDoc}
*
* @param string $substr literal string to find
* @param string $str literal string
* @param int $pos position to start at, beginning of string by default
* @return integer
*/ */
public function getLocateExpression($str, $substr, $startPos = false) public function getLocateExpression($str, $substr, $startPos = false)
{ {
if ($startPos == false) { if ($startPos == false) {
return 'LOCATE('.$str.', '.$substr.')'; return 'LOCATE('.$str.', '.$substr.')';
} else {
return 'LOCATE('.$str.', '.$substr.', '.$startPos.')';
} }
return 'LOCATE('.$str.', '.$substr.', '.$startPos.')';
} }
/**
* {@inheritDoc}
*/
public function getDateDiffExpression($date1, $date2) public function getDateDiffExpression($date1, $date2)
{ {
return 'ROUND(JULIANDAY('.$date1 . ')-JULIANDAY('.$date2.'))'; return 'ROUND(JULIANDAY('.$date1 . ')-JULIANDAY('.$date2.'))';
} }
/**
* {@inheritDoc}
*/
public function getDateAddDaysExpression($date, $days) public function getDateAddDaysExpression($date, $days)
{ {
return "DATE(" . $date . ",'+". $days . " day')"; return "DATE(" . $date . ",'+". $days . " day')";
} }
/**
* {@inheritDoc}
*/
public function getDateSubDaysExpression($date, $days) public function getDateSubDaysExpression($date, $days)
{ {
return "DATE(" . $date . ",'-". $days . " day')"; return "DATE(" . $date . ",'-". $days . " day')";
} }
/**
* {@inheritDoc}
*/
public function getDateAddMonthExpression($date, $months) public function getDateAddMonthExpression($date, $months)
{ {
return "DATE(" . $date . ",'+". $months . " month')"; return "DATE(" . $date . ",'+". $months . " month')";
} }
/**
* {@inheritDoc}
*/
public function getDateSubMonthExpression($date, $months) public function getDateSubMonthExpression($date, $months)
{ {
return "DATE(" . $date . ",'-". $months . " month')"; return "DATE(" . $date . ",'-". $months . " month')";
} }
/**
* {@inheritDoc}
*/
protected function _getTransactionIsolationLevelSQL($level) protected function _getTransactionIsolationLevelSQL($level)
{ {
switch ($level) { switch ($level) {
...@@ -164,13 +162,16 @@ class SqlitePlatform extends AbstractPlatform ...@@ -164,13 +162,16 @@ class SqlitePlatform extends AbstractPlatform
} }
} }
/**
* {@inheritDoc}
*/
public function getSetTransactionIsolationSQL($level) public function getSetTransactionIsolationSQL($level)
{ {
return 'PRAGMA read_uncommitted = ' . $this->_getTransactionIsolationLevelSQL($level); return 'PRAGMA read_uncommitted = ' . $this->_getTransactionIsolationLevelSQL($level);
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function prefersIdentityColumns() public function prefersIdentityColumns()
{ {
...@@ -178,7 +179,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -178,7 +179,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getBooleanTypeDeclarationSQL(array $field) public function getBooleanTypeDeclarationSQL(array $field)
{ {
...@@ -186,7 +187,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -186,7 +187,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getIntegerTypeDeclarationSQL(array $field) public function getIntegerTypeDeclarationSQL(array $field)
{ {
...@@ -194,7 +195,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -194,7 +195,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getBigIntTypeDeclarationSQL(array $field) public function getBigIntTypeDeclarationSQL(array $field)
{ {
...@@ -202,7 +203,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -202,7 +203,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getTinyIntTypeDeclarationSql(array $field) public function getTinyIntTypeDeclarationSql(array $field)
{ {
...@@ -210,7 +211,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -210,7 +211,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getSmallIntTypeDeclarationSQL(array $field) public function getSmallIntTypeDeclarationSQL(array $field)
{ {
...@@ -218,7 +219,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -218,7 +219,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getMediumIntTypeDeclarationSql(array $field) public function getMediumIntTypeDeclarationSql(array $field)
{ {
...@@ -226,7 +227,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -226,7 +227,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -234,7 +235,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -234,7 +235,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getDateTypeDeclarationSQL(array $fieldDeclaration) public function getDateTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -242,7 +243,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -242,7 +243,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
{ {
...@@ -250,7 +251,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -250,7 +251,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* @override * {@inheritDoc}
*/ */
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{ {
...@@ -258,33 +259,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -258,33 +259,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* create a new table * {@inheritDoc}
*
* @param string $name Name of the database that should be created
* @param array $fields Associative array that contains the definition of each field of the new table
* The indexes of the array entries are the names of the fields of the table an
* the array entry values are associative arrays like those that are meant to be
* passed with the field definitions to get[Type]Declaration() functions.
* array(
* 'id' => array(
* 'type' => 'integer',
* 'unsigned' => 1
* 'notnull' => 1
* 'default' => 0
* ),
* 'name' => array(
* 'type' => 'text',
* 'length' => 12
* ),
* 'password' => array(
* 'type' => 'text',
* 'length' => 12
* )
* );
* @param array $options An associative array of table options:
*
* @return string
* @override
*/ */
protected function _getCreateTableSQL($name, array $columns, array $options = array()) protected function _getCreateTableSQL($name, array $columns, array $options = array())
{ {
...@@ -303,16 +278,18 @@ class SqlitePlatform extends AbstractPlatform ...@@ -303,16 +278,18 @@ class SqlitePlatform extends AbstractPlatform
$query[] = $this->getCreateIndexSQL($indexDef, $name); $query[] = $this->getCreateIndexSQL($indexDef, $name);
} }
} }
if (isset($options['unique']) && ! empty($options['unique'])) { if (isset($options['unique']) && ! empty($options['unique'])) {
foreach ($options['unique'] as $index => $indexDef) { foreach ($options['unique'] as $index => $indexDef) {
$query[] = $this->getCreateIndexSQL($indexDef, $name); $query[] = $this->getCreateIndexSQL($indexDef, $name);
} }
} }
return $query; return $query;
} }
/** /**
* {@inheritdoc} * {@inheritDoc}
*/ */
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{ {
...@@ -320,6 +297,9 @@ class SqlitePlatform extends AbstractPlatform ...@@ -320,6 +297,9 @@ class SqlitePlatform extends AbstractPlatform
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT'); : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
} }
/**
* {@inheritDoc}
*/
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field)
{ {
return 'CLOB'; return 'CLOB';
...@@ -328,18 +308,24 @@ class SqlitePlatform extends AbstractPlatform ...@@ -328,18 +308,24 @@ class SqlitePlatform extends AbstractPlatform
public function getListTableConstraintsSQL($table) public function getListTableConstraintsSQL($table)
{ {
$table = str_replace(".", "__", $table); $table = str_replace(".", "__", $table);
return "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name = '$table' AND sql NOT NULL ORDER BY name"; return "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name = '$table' AND sql NOT NULL ORDER BY name";
} }
public function getListTableColumnsSQL($table, $currentDatabase = null) public function getListTableColumnsSQL($table, $currentDatabase = null)
{ {
$table = str_replace(".", "__", $table); $table = str_replace(".", "__", $table);
return "PRAGMA table_info($table)"; return "PRAGMA table_info($table)";
} }
/**
* {@inheritDoc}
*/
public function getListTableIndexesSQL($table, $currentDatabase = null) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
$table = str_replace(".", "__", $table); $table = str_replace(".", "__", $table);
return "PRAGMA index_list($table)"; return "PRAGMA index_list($table)";
} }
...@@ -350,6 +336,9 @@ class SqlitePlatform extends AbstractPlatform ...@@ -350,6 +336,9 @@ class SqlitePlatform extends AbstractPlatform
. "WHERE type = 'table' ORDER BY name"; . "WHERE type = 'table' ORDER BY name";
} }
/**
* {@inheritDoc}
*/
public function getListViewsSQL($database) public function getListViewsSQL($database)
{ {
return "SELECT name, sql FROM sqlite_master WHERE type='view' AND sql NOT NULL"; return "SELECT name, sql FROM sqlite_master WHERE type='view' AND sql NOT NULL";
...@@ -366,32 +355,35 @@ class SqlitePlatform extends AbstractPlatform ...@@ -366,32 +355,35 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* {@inheritDoc}
*
* SQLite does support foreign key constraints, but only in CREATE TABLE statements... * SQLite does support foreign key constraints, but only in CREATE TABLE statements...
* This really limits their usefulness and requires SQLite specific handling, so * This really limits their usefulness and requires SQLite specific handling, so
* we simply say that SQLite does NOT support foreign keys for now... * we simply say that SQLite does NOT support foreign keys for now...
*
* @return boolean FALSE
* @override
*/ */
public function supportsForeignKeyConstraints() public function supportsForeignKeyConstraints()
{ {
return false; return false;
} }
/**
* {@inheritDoc}
*/
public function supportsAlterTable() public function supportsAlterTable()
{ {
return false; return false;
} }
/**
* {@inheritDoc}
*/
public function supportsIdentityColumns() public function supportsIdentityColumns()
{ {
return true; return true;
} }
/** /**
* Get the platform name for this instance * {@inheritDoc}
*
* @return string
*/ */
public function getName() public function getName()
{ {
...@@ -399,7 +391,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -399,7 +391,7 @@ class SqlitePlatform extends AbstractPlatform
} }
/** /**
* @inheritdoc * {@inheritDoc}
*/ */
public function getTruncateTableSQL($tableName, $cascade = false) public function getTruncateTableSQL($tableName, $cascade = false)
{ {
...@@ -411,6 +403,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -411,6 +403,7 @@ class SqlitePlatform extends AbstractPlatform
* User-defined function for Sqlite that is used with PDO::sqliteCreateFunction() * User-defined function for Sqlite that is used with PDO::sqliteCreateFunction()
* *
* @param int|float $value * @param int|float $value
*
* @return float * @return float
*/ */
static public function udfSqrt($value) static public function udfSqrt($value)
...@@ -420,6 +413,11 @@ class SqlitePlatform extends AbstractPlatform ...@@ -420,6 +413,11 @@ class SqlitePlatform extends AbstractPlatform
/** /**
* User-defined function for Sqlite that implements MOD(a, b) * User-defined function for Sqlite that implements MOD(a, b)
*
* @param integer $a
* @param integer $b
*
* @return integer
*/ */
static public function udfMod($a, $b) static public function udfMod($a, $b)
{ {
...@@ -429,7 +427,9 @@ class SqlitePlatform extends AbstractPlatform ...@@ -429,7 +427,9 @@ class SqlitePlatform extends AbstractPlatform
/** /**
* @param string $str * @param string $str
* @param string $substr * @param string $substr
* @param int $offset * @param integer $offset
*
* @return integer
*/ */
static public function udfLocate($str, $substr, $offset = 0) static public function udfLocate($str, $substr, $offset = 0)
{ {
...@@ -437,6 +437,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -437,6 +437,7 @@ class SqlitePlatform extends AbstractPlatform
if ($pos !== false) { if ($pos !== false) {
return $pos+1; return $pos+1;
} }
return 0; return 0;
} }
...@@ -445,6 +446,9 @@ class SqlitePlatform extends AbstractPlatform ...@@ -445,6 +446,9 @@ class SqlitePlatform extends AbstractPlatform
return ''; return '';
} }
/**
* {@inheritDoc}
*/
protected function initializeDoctrineTypeMappings() protected function initializeDoctrineTypeMappings()
{ {
$this->doctrineTypeMapping = array( $this->doctrineTypeMapping = array(
...@@ -483,33 +487,40 @@ class SqlitePlatform extends AbstractPlatform ...@@ -483,33 +487,40 @@ class SqlitePlatform extends AbstractPlatform
); );
} }
/**
* {@inheritDoc}
*/
protected function getReservedKeywordsClass() protected function getReservedKeywordsClass()
{ {
return 'Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords'; return 'Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords';
} }
/** /**
* Gets the SQL Snippet used to declare a BLOB column type. * {@inheritDoc}
*/ */
public function getBlobTypeDeclarationSQL(array $field) public function getBlobTypeDeclarationSQL(array $field)
{ {
return 'BLOB'; return 'BLOB';
} }
/**
* {@inheritDoc}
*/
public function getTemporaryTableName($tableName) public function getTemporaryTableName($tableName)
{ {
$tableName = str_replace(".", "__", $tableName); $tableName = str_replace(".", "__", $tableName);
return $tableName; return $tableName;
} }
/** /**
* {@inheritDoc}
*
* Sqlite Platform emulates schema by underscoring each dot and generating tables * Sqlite Platform emulates schema by underscoring each dot and generating tables
* into the default database. * into the default database.
* *
* This hack is implemented to be able to use SQLite as testdriver when * This hack is implemented to be able to use SQLite as testdriver when
* using schema supporting databases. * using schema supporting databases.
*
* @return bool
*/ */
public function canEmulateSchemas() public function canEmulateSchemas()
{ {
......
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