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