2008-09-12 12:51:56 +04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
2009-02-04 19:35:36 +03:00
|
|
|
* <http://www.doctrine-project.org>.
|
2008-09-12 12:51:56 +04:00
|
|
|
*/
|
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
namespace Doctrine\DBAL\Platforms;
|
|
|
|
|
2009-11-03 21:30:21 +03:00
|
|
|
use Doctrine\DBAL\DBALException,
|
2009-08-11 14:51:38 +04:00
|
|
|
Doctrine\DBAL\Connection,
|
2009-12-02 21:52:21 +03:00
|
|
|
Doctrine\DBAL\Types,
|
|
|
|
Doctrine\DBAL\Schema\Table,
|
|
|
|
Doctrine\DBAL\Schema\Index,
|
2009-12-06 12:47:54 +03:00
|
|
|
Doctrine\DBAL\Schema\ForeignKeyConstraint,
|
|
|
|
Doctrine\DBAL\Schema\TableDiff;
|
2008-09-12 12:51:56 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for all DatabasePlatforms. The DatabasePlatforms are the central
|
|
|
|
* point of abstraction of platform-specific behaviors, features and SQL dialects.
|
|
|
|
* They are a passive source of information.
|
|
|
|
*
|
2009-08-07 01:42:07 +04:00
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @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>
|
|
|
|
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
2008-09-12 12:51:56 +04:00
|
|
|
*/
|
2009-01-22 22:38:10 +03:00
|
|
|
abstract class AbstractPlatform
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-12-05 00:40:03 +03:00
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
const CREATE_INDEXES = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
const CREATE_FOREIGNKEYS = 2;
|
|
|
|
|
2010-02-12 00:19:54 +03:00
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
const TRIM_UNSPECIFIED = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
const TRIM_LEADING = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
const TRIM_TRAILING = 2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
const TRIM_BOTH = 3;
|
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
public function __construct() {}
|
2009-02-05 20:34:44 +03:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
|
|
|
* Gets the character used for identifier quoting.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getIdentifierQuoteCharacter()
|
|
|
|
{
|
|
|
|
return '"';
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
|
|
|
* Gets the string portion that starts an SQL comment.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSqlCommentStartString()
|
|
|
|
{
|
|
|
|
return "--";
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
2009-05-03 22:07:57 +04:00
|
|
|
* Gets the string portion that ends an SQL comment.
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSqlCommentEndString()
|
|
|
|
{
|
|
|
|
return "\n";
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
|
|
|
* Gets the maximum length of a varchar field.
|
|
|
|
*
|
|
|
|
* @return integer
|
|
|
|
*/
|
|
|
|
public function getVarcharMaxLength()
|
|
|
|
{
|
|
|
|
return 255;
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
|
|
|
* Gets all SQL wildcard characters of the platform.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getWildcards()
|
|
|
|
{
|
|
|
|
return array('%', '_');
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
|
|
|
* Returns the regular expression operator.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRegexpExpression()
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
return 'AVG(' . $column . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of rows (without a NULL value) of a column
|
|
|
|
*
|
|
|
|
* If a '*' is used instead of a column the number of selected rows
|
|
|
|
* is returned.
|
|
|
|
*
|
|
|
|
* @param string|integer $column the column to use
|
|
|
|
* @return string generated sql including a COUNT aggregate function
|
|
|
|
*/
|
|
|
|
public function getCountExpression($column)
|
|
|
|
{
|
|
|
|
return 'COUNT(' . $column . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the highest value of a column
|
|
|
|
*
|
|
|
|
* @param string $column the column to use
|
|
|
|
* @return string generated sql including a MAX aggregate function
|
|
|
|
*/
|
|
|
|
public function getMaxExpression($column)
|
|
|
|
{
|
|
|
|
return 'MAX(' . $column . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the lowest value of a column
|
|
|
|
*
|
|
|
|
* @param string $column the column to use
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getMinExpression($column)
|
|
|
|
{
|
|
|
|
return 'MIN(' . $column . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the total sum of a column
|
|
|
|
*
|
|
|
|
* @param string $column the column to use
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSumExpression($column)
|
|
|
|
{
|
|
|
|
return 'SUM(' . $column . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
// scalar functions
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the md5 sum of a field.
|
|
|
|
*
|
|
|
|
* Note: Not SQL92, but common functionality
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getMd5Expression($column)
|
|
|
|
{
|
|
|
|
return 'MD5(' . $column . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the length of a text field.
|
|
|
|
*
|
|
|
|
* @param string $expression1
|
|
|
|
* @param string $expression2
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLengthExpression($column)
|
|
|
|
{
|
|
|
|
return 'LENGTH(' . $column . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rounds a numeric field to the number of decimals specified.
|
|
|
|
*
|
|
|
|
* @param string $expression1
|
|
|
|
* @param string $expression2
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRoundExpression($column, $decimals = 0)
|
|
|
|
{
|
|
|
|
return 'ROUND(' . $column . ', ' . $decimals . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the remainder of the division operation
|
|
|
|
* $expression1 / $expression2.
|
|
|
|
*
|
|
|
|
* @param string $expression1
|
|
|
|
* @param string $expression2
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getModExpression($expression1, $expression2)
|
|
|
|
{
|
|
|
|
return 'MOD(' . $expression1 . ', ' . $expression2 . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-02-12 00:19:54 +03:00
|
|
|
* Trim a string, leading/trailing/both and with a given char which defaults to space.
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
2010-02-12 00:19:54 +03:00
|
|
|
* @param string $str
|
|
|
|
* @param int $pos
|
|
|
|
* @param string $char has to be quoted already
|
2008-09-12 12:51:56 +04:00
|
|
|
* @return string
|
|
|
|
*/
|
2010-02-12 00:19:54 +03:00
|
|
|
public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2010-02-12 00:19:54 +03:00
|
|
|
$posStr = '';
|
|
|
|
$trimChar = ($char != false) ? $char . ' FROM ' : '';
|
|
|
|
|
|
|
|
if ($pos == self::TRIM_LEADING) {
|
|
|
|
$posStr = 'LEADING '.$trimChar;
|
|
|
|
} else if($pos == self::TRIM_TRAILING) {
|
|
|
|
$posStr = 'TRAILING '.$trimChar;
|
|
|
|
} else if($pos == self::TRIM_BOTH) {
|
|
|
|
$posStr = 'BOTH '.$trimChar;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'TRIM(' . $posStr . $str . ')';
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* rtrim
|
|
|
|
* returns the string $str with proceeding space characters removed
|
|
|
|
*
|
|
|
|
* @param string $str literal string or column name
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRtrimExpression($str)
|
|
|
|
{
|
|
|
|
return 'RTRIM(' . $str . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ltrim
|
|
|
|
* returns the string $str with leading space characters removed
|
|
|
|
*
|
|
|
|
* @param string $str literal string or column name
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLtrimExpression($str)
|
|
|
|
{
|
|
|
|
return 'LTRIM(' . $str . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* upper
|
|
|
|
* Returns the string $str with all characters changed to
|
|
|
|
* uppercase according to the current character set mapping.
|
|
|
|
*
|
|
|
|
* @param string $str literal string or column name
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getUpperExpression($str)
|
|
|
|
{
|
|
|
|
return 'UPPER(' . $str . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lower
|
|
|
|
* Returns the string $str with all characters changed to
|
|
|
|
* lowercase according to the current character set mapping.
|
|
|
|
*
|
|
|
|
* @param string $str literal string or column name
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLowerExpression($str)
|
|
|
|
{
|
|
|
|
return 'LOWER(' . $str . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2010-02-12 01:38:23 +03:00
|
|
|
* @param int $pos position to start at, beginning of string by default
|
2008-09-12 12:51:56 +04:00
|
|
|
* @return integer
|
|
|
|
*/
|
2010-02-12 01:38:23 +03:00
|
|
|
public function getLocateExpression($str, $substr, $startPos = false)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2010-02-12 01:38:23 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current system date.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getNowExpression()
|
|
|
|
{
|
|
|
|
return 'NOW()';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2010-02-11 23:19:05 +03:00
|
|
|
* @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
|
2008-09-12 12:51:56 +04:00
|
|
|
*/
|
|
|
|
public function getSubstringExpression($value, $from, $len = null)
|
|
|
|
{
|
|
|
|
if ($len === null)
|
|
|
|
return 'SUBSTRING(' . $value . ' FROM ' . $from . ')';
|
|
|
|
else {
|
|
|
|
return 'SUBSTRING(' . $value . ' FROM ' . $from . ' FOR ' . $len . ')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a series of strings concatinated
|
|
|
|
*
|
|
|
|
* concat() accepts an arbitrary number of parameters. Each parameter
|
|
|
|
* must contain an expression
|
|
|
|
*
|
|
|
|
* @param string $arg1, $arg2 ... $argN strings that will be concatinated.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getConcatExpression()
|
|
|
|
{
|
2009-05-03 22:07:57 +04:00
|
|
|
return join(' || ' , func_get_args());
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the SQL for a logical not.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* <code>
|
|
|
|
* $q = new Doctrine_Query();
|
|
|
|
* $e = $q->expr;
|
|
|
|
* $q->select('*')->from('table')
|
|
|
|
* ->where($e->eq('id', $e->not('null'));
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* @return string a logical expression
|
|
|
|
*/
|
|
|
|
public function getNotExpression($expression)
|
|
|
|
{
|
2009-08-11 14:51:38 +04:00
|
|
|
return 'NOT(' . $expression . ')';
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the SQL to check if a value is one in a set of
|
2009-05-03 22:07:57 +04:00
|
|
|
* given values.
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
|
|
|
* in() accepts an arbitrary number of parameters. The first parameter
|
|
|
|
* must always specify the value that should be matched against. Successive
|
|
|
|
* must contain a logical expression or an array with logical expressions.
|
|
|
|
* These expressions will be matched against the first parameter.
|
|
|
|
*
|
|
|
|
* @param string $column the value that should be matched against
|
|
|
|
* @param string|array(string) values that will be matched against $column
|
|
|
|
* @return string logical expression
|
|
|
|
*/
|
|
|
|
public function getInExpression($column, $values)
|
|
|
|
{
|
|
|
|
if ( ! is_array($values)) {
|
|
|
|
$values = array($values);
|
|
|
|
}
|
|
|
|
$values = $this->getIdentifiers($values);
|
|
|
|
|
|
|
|
if (count($values) == 0) {
|
2009-11-03 21:30:21 +03:00
|
|
|
throw \InvalidArgumentException('Values must not be empty.');
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
return $column . ' IN (' . implode(', ', $values) . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
return $expression . ' IS NULL';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
return $expression . ' IS NOT NULL';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns SQL that checks if an expression evaluates to a value between
|
|
|
|
* two values.
|
|
|
|
*
|
|
|
|
* The parameter $expression is checked if it is between $value1 and $value2.
|
|
|
|
*
|
|
|
|
* Note: There is a slight difference in the way BETWEEN works on some databases.
|
|
|
|
* http://www.w3schools.com/sql/sql_between.asp. If you want complete database
|
|
|
|
* independence you should avoid using between().
|
|
|
|
*
|
|
|
|
* @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)
|
|
|
|
{
|
|
|
|
return $expression . ' BETWEEN ' .$value1 . ' AND ' . $value2;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAcosExpression($value)
|
|
|
|
{
|
|
|
|
return 'ACOS(' . $value . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSinExpression($value)
|
|
|
|
{
|
|
|
|
return 'SIN(' . $value . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPiExpression()
|
|
|
|
{
|
|
|
|
return 'PI()';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCosExpression($value)
|
|
|
|
{
|
|
|
|
return 'COS(' . $value . ')';
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
public function getForUpdateSql()
|
|
|
|
{
|
|
|
|
return 'FOR UPDATE';
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
public function getDropDatabaseSql($database)
|
|
|
|
{
|
|
|
|
return 'DROP DATABASE ' . $database;
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2009-12-03 01:28:38 +03:00
|
|
|
/**
|
|
|
|
* Drop a Table
|
|
|
|
*
|
|
|
|
* @param Table|string $table
|
|
|
|
* @return string
|
|
|
|
*/
|
2008-09-12 12:51:56 +04:00
|
|
|
public function getDropTableSql($table)
|
|
|
|
{
|
2009-12-03 01:28:38 +03:00
|
|
|
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
|
|
|
|
$table = $table->getName();
|
|
|
|
}
|
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
return 'DROP TABLE ' . $table;
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2009-12-02 21:52:21 +03:00
|
|
|
/**
|
|
|
|
* Drop index from a table
|
|
|
|
*
|
|
|
|
* @param Index|string $name
|
|
|
|
* @param string|Table $table
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDropIndexSql($index, $table=null)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-12-02 21:52:21 +03:00
|
|
|
if($index instanceof \Doctrine\DBAL\Schema\Index) {
|
|
|
|
$index = $index->getName();
|
|
|
|
} else if(!is_string($index)) {
|
|
|
|
throw new \InvalidArgumentException('AbstractPlatform::getDropIndexSql() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'DROP INDEX ' . $index;
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2009-12-03 01:28:38 +03:00
|
|
|
/**
|
|
|
|
* Get drop constraint sql
|
|
|
|
*
|
|
|
|
* @param \Doctrine\DBAL\Schema\Constraint $constraint
|
|
|
|
* @param string|Table $table
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDropConstraintSql($constraint, $table)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-12-03 01:33:01 +03:00
|
|
|
if ($constraint instanceof \Doctrine\DBAL\Schema\Constraint) {
|
2009-12-03 01:28:38 +03:00
|
|
|
$constraint = $constraint->getName();
|
|
|
|
}
|
|
|
|
|
2009-12-03 01:33:01 +03:00
|
|
|
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
|
2009-12-03 01:28:38 +03:00
|
|
|
$table = $table->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $constraint;
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2009-12-03 01:28:38 +03:00
|
|
|
/**
|
|
|
|
* @param ForeignKeyConstraint|string $foreignKey
|
|
|
|
* @param Table|string $table
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDropForeignKeySql($foreignKey, $table)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-12-03 01:28:38 +03:00
|
|
|
if ($foreignKey instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) {
|
|
|
|
$foreignKey = $foreignKey->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
|
|
|
|
$table = $table->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $foreignKey;
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
2009-08-21 22:13:22 +04:00
|
|
|
* Gets the SQL statement(s) to create a table with the specified name, columns and constraints
|
2009-05-05 21:20:55 +04:00
|
|
|
* on this platform.
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
2009-08-21 22:13:22 +04:00
|
|
|
* @param string $table The name of the table.
|
2009-12-05 00:40:03 +03:00
|
|
|
* @param int $createFlags
|
2009-08-21 22:13:22 +04:00
|
|
|
* @return array The sequence of SQL statements.
|
2008-09-12 12:51:56 +04:00
|
|
|
*/
|
2009-12-05 00:40:03 +03:00
|
|
|
public function getCreateTableSql(Table $table, $createFlags=self::CREATE_INDEXES)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-12-05 00:40:03 +03:00
|
|
|
if (!is_int($createFlags)) {
|
|
|
|
throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSql() has to be integer.");
|
|
|
|
}
|
|
|
|
|
2009-12-02 21:52:21 +03:00
|
|
|
$tableName = $table->getName();
|
|
|
|
$options = $table->getOptions();
|
|
|
|
$options['uniqueConstraints'] = array();
|
|
|
|
$options['indexes'] = array();
|
|
|
|
$options['primary'] = array();
|
|
|
|
|
2009-12-05 00:40:03 +03:00
|
|
|
if (($createFlags&self::CREATE_INDEXES) > 0) {
|
|
|
|
foreach ($table->getIndexes() AS $index) {
|
|
|
|
/* @var $index Index */
|
|
|
|
if ($index->isPrimary()) {
|
|
|
|
$options['primary'] = $index->getColumns();
|
|
|
|
} else {
|
|
|
|
$options['indexes'][$index->getName()] = $index;
|
|
|
|
}
|
2009-12-02 21:52:21 +03:00
|
|
|
}
|
|
|
|
}
|
2008-09-12 12:51:56 +04:00
|
|
|
|
2009-12-02 21:52:21 +03:00
|
|
|
$columns = array();
|
2009-12-05 00:40:03 +03:00
|
|
|
foreach ($table->getColumns() AS $column) {
|
2009-12-02 21:52:21 +03:00
|
|
|
/* @var \Doctrine\DBAL\Schema\Column $column */
|
|
|
|
$columnData = array();
|
|
|
|
$columnData['name'] = $column->getName();
|
|
|
|
$columnData['type'] = $column->getType();
|
|
|
|
$columnData['length'] = $column->getLength();
|
|
|
|
$columnData['notnull'] = $column->getNotNull();
|
|
|
|
$columnData['unique'] = ($column->hasPlatformOption("unique"))?$column->getPlatformOption('unique'):false;
|
|
|
|
$columnData['version'] = ($column->hasPlatformOption("version"))?$column->getPlatformOption('version'):false;
|
|
|
|
if(strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
|
|
|
|
$columnData['length'] = 255;
|
|
|
|
}
|
|
|
|
$columnData['precision'] = $column->getPrecision();
|
|
|
|
$columnData['scale'] = $column->getScale();
|
|
|
|
$columnData['default'] = $column->getDefault();
|
2010-01-21 01:35:18 +03:00
|
|
|
$columnData['columnDefinition'] = $column->getColumnDefinition();
|
2009-12-02 21:52:21 +03:00
|
|
|
|
|
|
|
if(in_array($column->getName(), $options['primary'])) {
|
|
|
|
$columnData['primary'] = true;
|
|
|
|
|
|
|
|
if($table->isIdGeneratorIdentity()) {
|
|
|
|
$columnData['autoincrement'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$columns[$columnData['name']] = $columnData;
|
|
|
|
}
|
|
|
|
|
2009-12-05 00:40:03 +03:00
|
|
|
if (($createFlags&self::CREATE_FOREIGNKEYS) > 0) {
|
|
|
|
$options['foreignKeys'] = array();
|
|
|
|
foreach ($table->getForeignKeys() AS $fkConstraint) {
|
|
|
|
$options['foreignKeys'][] = $fkConstraint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-02 21:52:21 +03:00
|
|
|
return $this->_getCreateTableSql($tableName, $columns, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-05 00:40:03 +03:00
|
|
|
* @param string $tableName
|
2009-12-02 21:52:21 +03:00
|
|
|
* @param array $columns
|
|
|
|
* @param array $options
|
|
|
|
* @return array
|
|
|
|
*/
|
2009-12-05 00:40:03 +03:00
|
|
|
protected function _getCreateTableSql($tableName, array $columns, array $options = array())
|
2009-12-02 21:52:21 +03:00
|
|
|
{
|
|
|
|
$columnListSql = $this->getColumnDeclarationListSql($columns);
|
|
|
|
|
2009-08-21 22:13:22 +04:00
|
|
|
if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
|
2010-01-06 16:23:56 +03:00
|
|
|
foreach ($options['uniqueConstraints'] as $name => $definition) {
|
|
|
|
$columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSql($name, $definition);
|
2009-08-21 22:13:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
if (isset($options['primary']) && ! empty($options['primary'])) {
|
2009-05-05 21:20:55 +04:00
|
|
|
$columnListSql .= ', PRIMARY KEY(' . implode(', ', array_unique(array_values($options['primary']))) . ')';
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['indexes']) && ! empty($options['indexes'])) {
|
|
|
|
foreach($options['indexes'] as $index => $definition) {
|
2009-05-05 21:20:55 +04:00
|
|
|
$columnListSql .= ', ' . $this->getIndexDeclarationSql($index, $definition);
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-05 00:40:03 +03:00
|
|
|
$query = 'CREATE TABLE ' . $tableName . ' (' . $columnListSql;
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2009-05-05 21:20:55 +04:00
|
|
|
$check = $this->getCheckDeclarationSql($columns);
|
2008-09-12 12:51:56 +04:00
|
|
|
if ( ! empty($check)) {
|
|
|
|
$query .= ', ' . $check;
|
2009-05-05 21:20:55 +04:00
|
|
|
}
|
2008-09-12 12:51:56 +04:00
|
|
|
$query .= ')';
|
|
|
|
|
|
|
|
$sql[] = $query;
|
|
|
|
|
|
|
|
if (isset($options['foreignKeys'])) {
|
2009-12-02 21:52:21 +03:00
|
|
|
foreach ((array) $options['foreignKeys'] AS $definition) {
|
2009-12-05 00:40:03 +03:00
|
|
|
$sql[] = $this->getCreateForeignKeySql($definition, $tableName);
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
return $sql;
|
|
|
|
}
|
2009-08-28 21:25:28 +04:00
|
|
|
|
|
|
|
public function getCreateTemporaryTableSnippetSql()
|
|
|
|
{
|
|
|
|
return "CREATE TEMPORARY TABLE";
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
2009-05-05 21:20:55 +04:00
|
|
|
* Gets the SQL to create a sequence on this platform.
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
2009-12-02 22:07:38 +03:00
|
|
|
* @param \Doctrine\DBAL\Schema\Sequence $sequence
|
2009-05-05 21:20:55 +04:00
|
|
|
* @throws DoctrineException
|
2008-09-12 12:51:56 +04:00
|
|
|
*/
|
2009-12-02 22:07:38 +03:00
|
|
|
public function getCreateSequenceSql(\Doctrine\DBAL\Schema\Sequence $sequence)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
2009-05-05 21:20:55 +04:00
|
|
|
* Gets the SQL to create a constraint on a table on this platform.
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
2009-12-03 01:28:38 +03:00
|
|
|
* @param Constraint $constraint
|
|
|
|
* @param string|Table $table
|
2009-05-05 21:20:55 +04:00
|
|
|
* @return string
|
2008-09-12 12:51:56 +04:00
|
|
|
*/
|
2009-12-03 01:28:38 +03:00
|
|
|
public function getCreateConstraintSql(\Doctrine\DBAL\Schema\Constraint $constraint, $table)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-12-03 01:28:38 +03:00
|
|
|
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
|
|
|
|
$table = $table->getName();
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
|
2009-12-03 01:28:38 +03:00
|
|
|
$query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $constraint->getName();
|
|
|
|
|
2009-10-07 02:38:34 +04:00
|
|
|
$columns = array();
|
2009-12-03 01:28:38 +03:00
|
|
|
foreach ($constraint->getColumns() as $column) {
|
2009-10-07 02:38:34 +04:00
|
|
|
$columns[] = $column;
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
2009-12-03 01:28:38 +03:00
|
|
|
$columnList = '('. implode(', ', $columns) . ')';
|
|
|
|
|
|
|
|
$referencesClause = '';
|
|
|
|
if ($constraint instanceof \Doctrine\DBAL\Schema\Index) {
|
|
|
|
if($constraint->isPrimary()) {
|
|
|
|
$query .= ' PRIMARY KEY';
|
|
|
|
} elseif ($constraint->isUnique()) {
|
|
|
|
$query .= ' UNIQUE';
|
|
|
|
} else {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Can only create primary or unique constraints, no common indexes with getCreateConstraintSql().'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else if ($constraint instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) {
|
|
|
|
$query .= ' FOREIGN KEY';
|
|
|
|
|
|
|
|
$foreignColumns = array();
|
|
|
|
foreach ($constraint->getForeignColumns() AS $column) {
|
|
|
|
$foreignColumns[] = $column;
|
|
|
|
}
|
|
|
|
|
|
|
|
$referencesClause = ' REFERENCES '.$constraint->getForeignTableName(). ' ('.implode(', ', $foreignColumns).')';
|
|
|
|
}
|
|
|
|
$query .= ' '.$columnList.$referencesClause;
|
2008-09-12 12:51:56 +04:00
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
2009-05-05 21:20:55 +04:00
|
|
|
* Gets the SQL to create an index on a table on this platform.
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
2009-12-02 21:52:21 +03:00
|
|
|
* @param Index $index
|
|
|
|
* @param string|Table $table name of the table on which the index is to be created
|
2008-09-12 12:51:56 +04:00
|
|
|
* @return string
|
|
|
|
*/
|
2009-12-02 21:52:21 +03:00
|
|
|
public function getCreateIndexSql(Index $index, $table)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-12-02 21:52:21 +03:00
|
|
|
if ($table instanceof Table) {
|
|
|
|
$table = $table->getName();
|
|
|
|
}
|
|
|
|
$name = $index->getName();
|
|
|
|
$columns = $index->getColumns();
|
|
|
|
|
|
|
|
if (count($columns) == 0) {
|
|
|
|
throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
$type = '';
|
2009-12-02 21:52:21 +03:00
|
|
|
if ($index->isUnique()) {
|
|
|
|
$type = 'UNIQUE ';
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$query = 'CREATE ' . $type . 'INDEX ' . $name . ' ON ' . $table;
|
|
|
|
|
2009-12-02 21:52:21 +03:00
|
|
|
$query .= ' (' . $this->getIndexFieldDeclarationListSql($columns) . ')';
|
2008-09-12 12:51:56 +04:00
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
2009-05-05 21:20:55 +04:00
|
|
|
* Quotes a string so that it can be safely used as a table or column name,
|
|
|
|
* even if it is a reserved word of the platform.
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
2009-05-05 21:20:55 +04:00
|
|
|
* NOTE: Just because you CAN use quoted identifiers doesn't mean
|
2008-09-12 12:51:56 +04:00
|
|
|
* you SHOULD use them. In general, they end up causing way more
|
|
|
|
* problems than they solve.
|
|
|
|
*
|
|
|
|
* @param string $str identifier name to be quoted
|
|
|
|
* @return string quoted identifier string
|
|
|
|
*/
|
|
|
|
public function quoteIdentifier($str)
|
|
|
|
{
|
|
|
|
$c = $this->getIdentifierQuoteCharacter();
|
|
|
|
|
2009-08-11 14:51:38 +04:00
|
|
|
return $c . $str . $c;
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
2009-12-02 21:52:21 +03:00
|
|
|
* Create a new foreign key
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
2009-12-02 21:52:21 +03:00
|
|
|
* @param ForeignKeyConstraint $foreignKey ForeignKey instance
|
|
|
|
* @param string|Table $table name of the table on which the foreign key is to be created
|
2008-09-12 12:51:56 +04:00
|
|
|
* @return string
|
|
|
|
*/
|
2009-12-02 21:52:21 +03:00
|
|
|
public function getCreateForeignKeySql(ForeignKeyConstraint $foreignKey, $table)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-12-02 21:52:21 +03:00
|
|
|
if ($table instanceof \Doctrine\DBAL\Schema\Table) {
|
|
|
|
$table = $table->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSql($foreignKey);
|
2008-09-12 12:51:56 +04:00
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
2009-11-02 18:08:51 +03:00
|
|
|
* Gets the sql statements for altering an existing table.
|
|
|
|
*
|
|
|
|
* The method returns an array of sql statements, since some platforms need several statements.
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
2009-12-06 12:47:54 +03:00
|
|
|
* @param TableDiff $diff
|
2009-11-02 18:08:51 +03:00
|
|
|
* @return array
|
2008-09-12 12:51:56 +04:00
|
|
|
*/
|
2009-12-06 12:47:54 +03:00
|
|
|
public function getAlterTableSql(TableDiff $diff)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2009-12-06 15:13:15 +03:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2009-12-06 16:00:49 +03:00
|
|
|
if ($diff->newName !== false) {
|
|
|
|
$tableName = $diff->newName;
|
|
|
|
} else {
|
|
|
|
$tableName = $diff->name;
|
|
|
|
}
|
|
|
|
|
2009-12-06 15:13:15 +03:00
|
|
|
$sql = array();
|
|
|
|
if ($this->supportsForeignKeyConstraints()) {
|
|
|
|
foreach ($diff->removedForeignKeys AS $foreignKey) {
|
2009-12-06 16:00:49 +03:00
|
|
|
$sql[] = $this->getDropForeignKeySql($foreignKey, $tableName);
|
2009-12-06 15:13:15 +03:00
|
|
|
}
|
2010-02-07 15:36:30 +03:00
|
|
|
foreach ($diff->addedForeignKeys AS $foreignKey) {
|
|
|
|
$sql[] = $this->getCreateForeignKeySql($foreignKey, $tableName);
|
|
|
|
}
|
2009-12-06 15:13:15 +03:00
|
|
|
foreach ($diff->changedForeignKeys AS $foreignKey) {
|
2009-12-06 16:00:49 +03:00
|
|
|
$sql[] = $this->getDropForeignKeySql($foreignKey, $tableName);
|
|
|
|
$sql[] = $this->getCreateForeignKeySql($foreignKey, $tableName);
|
2009-12-06 15:13:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($diff->addedIndexes AS $index) {
|
2009-12-06 16:00:49 +03:00
|
|
|
$sql[] = $this->getCreateIndexSql($index, $tableName);
|
2009-12-06 15:13:15 +03:00
|
|
|
}
|
|
|
|
foreach ($diff->removedIndexes AS $index) {
|
2009-12-06 16:00:49 +03:00
|
|
|
$sql[] = $this->getDropIndexSql($index, $tableName);
|
2009-12-06 15:13:15 +03:00
|
|
|
}
|
|
|
|
foreach ($diff->changedIndexes AS $index) {
|
2009-12-06 16:00:49 +03:00
|
|
|
$sql[] = $this->getDropIndexSql($index, $tableName);
|
|
|
|
$sql[] = $this->getCreateIndexSql($index, $tableName);
|
2009-12-06 15:13:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $sql;
|
|
|
|
}
|
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
2009-01-07 20:46:02 +03:00
|
|
|
* Get declaration of a number of fields in bulk
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
|
|
|
* @param array $fields a multidimensional associative array.
|
|
|
|
* The first dimension determines the field name, while the second
|
|
|
|
* dimension is keyed with the name of the properties
|
|
|
|
* of the field being declared as array indexes. Currently, the types
|
|
|
|
* of supported field properties are as follows:
|
|
|
|
*
|
|
|
|
* length
|
|
|
|
* Integer value that determines the maximum length of the text
|
|
|
|
* field. If this argument is missing the field should be
|
|
|
|
* declared to have the longest length allowed by the DBMS.
|
|
|
|
*
|
|
|
|
* default
|
|
|
|
* Text 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.
|
|
|
|
* charset
|
|
|
|
* Text value with the default CHARACTER SET for this field.
|
|
|
|
* collation
|
|
|
|
* Text value with the default COLLATION for this field.
|
|
|
|
* unique
|
|
|
|
* unique constraint
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2009-05-03 22:07:57 +04:00
|
|
|
public function getColumnDeclarationListSql(array $fields)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-01-07 20:46:02 +03:00
|
|
|
$queryFields = array();
|
2008-09-12 12:51:56 +04:00
|
|
|
foreach ($fields as $fieldName => $field) {
|
2009-05-03 22:07:57 +04:00
|
|
|
$query = $this->getColumnDeclarationSql($fieldName, $field);
|
2008-09-12 12:51:56 +04:00
|
|
|
$queryFields[] = $query;
|
|
|
|
}
|
|
|
|
return implode(', ', $queryFields);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain DBMS specific SQL code portion needed to declare a generic type
|
|
|
|
* field to be used in statements like CREATE TABLE.
|
|
|
|
*
|
|
|
|
* @param string $name name the field to be declared.
|
|
|
|
* @param array $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:
|
|
|
|
*
|
|
|
|
* length
|
|
|
|
* Integer value that determines the maximum length of the text
|
|
|
|
* field. If this argument is missing the field should be
|
|
|
|
* declared to have the longest length allowed by the DBMS.
|
|
|
|
*
|
|
|
|
* default
|
|
|
|
* Text 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.
|
|
|
|
* charset
|
|
|
|
* Text value with the default CHARACTER SET for this field.
|
|
|
|
* collation
|
|
|
|
* Text value with the default COLLATION for this field.
|
|
|
|
* unique
|
|
|
|
* unique constraint
|
|
|
|
* check
|
|
|
|
* column check constraint
|
2010-01-21 01:35:18 +03:00
|
|
|
* columnDefinition
|
|
|
|
* a string that defines the complete column
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
2009-05-03 22:07:57 +04:00
|
|
|
* @return string DBMS specific SQL code portion that should be used to declare the column.
|
2008-09-12 12:51:56 +04:00
|
|
|
*/
|
2009-05-03 22:07:57 +04:00
|
|
|
public function getColumnDeclarationSql($name, array $field)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2010-01-21 01:35:18 +03:00
|
|
|
if (isset($field['columnDefinition'])) {
|
|
|
|
$columnDef = $this->getCustomTypeDeclarationSql($field);
|
|
|
|
} else {
|
|
|
|
$default = $this->getDefaultValueDeclarationSql($field);
|
2009-05-03 22:07:57 +04:00
|
|
|
|
2010-01-21 01:35:18 +03:00
|
|
|
$charset = (isset($field['charset']) && $field['charset']) ?
|
|
|
|
' ' . $this->getColumnCharsetDeclarationSql($field['charset']) : '';
|
2009-05-03 22:07:57 +04:00
|
|
|
|
2010-01-21 01:35:18 +03:00
|
|
|
$collation = (isset($field['collation']) && $field['collation']) ?
|
|
|
|
' ' . $this->getColumnCollationDeclarationSql($field['collation']) : '';
|
2009-05-03 22:07:57 +04:00
|
|
|
|
2010-01-21 01:35:18 +03:00
|
|
|
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
|
2009-05-03 22:07:57 +04:00
|
|
|
|
2010-01-21 01:35:18 +03:00
|
|
|
$unique = (isset($field['unique']) && $field['unique']) ?
|
|
|
|
' ' . $this->getUniqueFieldDeclarationSql() : '';
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2010-01-21 01:35:18 +03:00
|
|
|
$check = (isset($field['check']) && $field['check']) ?
|
|
|
|
' ' . $field['check'] : '';
|
2008-09-12 12:51:56 +04:00
|
|
|
|
2010-01-21 01:35:18 +03:00
|
|
|
$typeDecl = $field['type']->getSqlDeclaration($field, $this);
|
|
|
|
$columnDef = $typeDecl . $charset . $default . $notnull . $unique . $check . $collation;
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2010-01-21 01:35:18 +03:00
|
|
|
return $name . ' ' . $columnDef;
|
2009-01-07 20:46:02 +03:00
|
|
|
}
|
2009-09-04 23:08:32 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the SQL snippet that declares a floating point column of arbitrary precision.
|
|
|
|
*
|
|
|
|
* @param array $columnDef
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDecimalTypeDeclarationSql(array $columnDef)
|
|
|
|
{
|
|
|
|
$columnDef['precision'] = ( ! isset($columnDef['precision']) || empty($columnDef['precision']))
|
2009-10-20 03:23:54 +04:00
|
|
|
? 10 : $columnDef['precision'];
|
2009-09-04 23:08:32 +04:00
|
|
|
$columnDef['scale'] = ( ! isset($columnDef['scale']) || empty($columnDef['scale']))
|
|
|
|
? 0 : $columnDef['scale'];
|
|
|
|
|
|
|
|
return 'NUMERIC(' . $columnDef['precision'] . ', ' . $columnDef['scale'] . ')';
|
|
|
|
}
|
2008-09-12 12:51:56 +04:00
|
|
|
|
2009-09-05 06:23:24 +04:00
|
|
|
/**
|
|
|
|
* Gets the SQL snippet that declares a boolean column.
|
|
|
|
*
|
|
|
|
* @param array $columnDef
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
abstract public function getBooleanTypeDeclarationSql(array $columnDef);
|
|
|
|
|
2009-01-07 20:46:02 +03:00
|
|
|
/**
|
2009-03-28 23:59:07 +03:00
|
|
|
* Gets the SQL snippet that declares a 4 byte integer column.
|
2009-01-07 20:46:02 +03:00
|
|
|
*
|
2009-09-04 23:08:32 +04:00
|
|
|
* @param array $columnDef
|
|
|
|
* @return string
|
2009-01-07 20:46:02 +03:00
|
|
|
*/
|
|
|
|
abstract public function getIntegerTypeDeclarationSql(array $columnDef);
|
2008-09-12 12:51:56 +04:00
|
|
|
|
2009-01-07 20:46:02 +03:00
|
|
|
/**
|
2009-03-28 23:59:07 +03:00
|
|
|
* Gets the SQL snippet that declares an 8 byte integer column.
|
2009-01-07 20:46:02 +03:00
|
|
|
*
|
2009-09-04 23:08:32 +04:00
|
|
|
* @param array $columnDef
|
2009-01-07 20:46:02 +03:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
abstract public function getBigIntTypeDeclarationSql(array $columnDef);
|
2008-09-12 12:51:56 +04:00
|
|
|
|
2009-01-07 20:46:02 +03:00
|
|
|
/**
|
2009-03-28 23:59:07 +03:00
|
|
|
* Gets the SQL snippet that declares a 2 byte integer column.
|
2009-01-07 20:46:02 +03:00
|
|
|
*
|
2009-09-04 23:08:32 +04:00
|
|
|
* @param array $columnDef
|
2009-01-07 20:46:02 +03:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
abstract public function getSmallIntTypeDeclarationSql(array $columnDef);
|
2008-09-12 12:51:56 +04:00
|
|
|
|
2009-01-07 20:46:02 +03:00
|
|
|
/**
|
|
|
|
* Gets the SQL snippet that declares common properties of an integer column.
|
|
|
|
*
|
2009-09-04 23:08:32 +04:00
|
|
|
* @param array $columnDef
|
2009-01-07 20:46:02 +03:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
abstract protected function _getCommonIntegerTypeDeclarationSql(array $columnDef);
|
2008-09-12 12:51:56 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain DBMS specific SQL code portion needed to set a default value
|
|
|
|
* 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
|
|
|
|
*/
|
2009-05-03 22:07:57 +04:00
|
|
|
public function getDefaultValueDeclarationSql($field)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-05-03 22:07:57 +04:00
|
|
|
$default = empty($field['notnull']) ? ' DEFAULT NULL' : '';
|
2008-09-12 12:51:56 +04:00
|
|
|
|
2009-05-03 22:07:57 +04:00
|
|
|
if (isset($field['default'])) {
|
2009-12-06 15:13:15 +03:00
|
|
|
$default = " DEFAULT '".$field['default']."'";
|
|
|
|
if (isset($field['type'])) {
|
|
|
|
if (in_array((string)$field['type'], array("Integer", "BigInteger", "SmallInteger"))) {
|
|
|
|
$default = " DEFAULT ".$field['default'];
|
|
|
|
} else if ((string)$field['type'] == 'DateTime' && $field['default'] == $this->getCurrentTimestampSql()) {
|
|
|
|
$default = " DEFAULT ".$this->getCurrentTimestampSql();
|
|
|
|
}
|
|
|
|
}
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain DBMS specific SQL code portion needed to set a CHECK constraint
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
$constraints = array();
|
|
|
|
foreach ($definition as $field => $def) {
|
|
|
|
if (is_string($def)) {
|
|
|
|
$constraints[] = 'CHECK (' . $def . ')';
|
|
|
|
} else {
|
|
|
|
if (isset($def['min'])) {
|
|
|
|
$constraints[] = 'CHECK (' . $field . ' >= ' . $def['min'] . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($def['max'])) {
|
|
|
|
$constraints[] = 'CHECK (' . $field . ' <= ' . $def['max'] . ')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode(', ', $constraints);
|
|
|
|
}
|
2010-01-06 16:23:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain DBMS specific SQL code portion needed to set a unique
|
|
|
|
* constraint declaration to be used in statements like CREATE TABLE.
|
|
|
|
*
|
|
|
|
* @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) {
|
|
|
|
throw \InvalidArgumentException("Incomplete definition. 'columns' required.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'CONSTRAINT' . $name . ' UNIQUE ('
|
|
|
|
. $this->getIndexFieldDeclarationListSql($index->getColumns())
|
|
|
|
. ')';
|
|
|
|
}
|
2008-09-12 12:51:56 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2010-01-06 16:23:56 +03:00
|
|
|
* @param Index $index index definition
|
2008-09-12 12:51:56 +04:00
|
|
|
* @return string DBMS specific SQL code portion needed to set an index
|
|
|
|
*/
|
2009-12-02 21:52:21 +03:00
|
|
|
public function getIndexDeclarationSql($name, Index $index)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2010-01-06 16:23:56 +03:00
|
|
|
$type = '';
|
2008-09-12 12:51:56 +04:00
|
|
|
|
2009-12-02 21:52:21 +03:00
|
|
|
if($index->isUnique()) {
|
2010-01-06 16:23:56 +03:00
|
|
|
$type = 'UNIQUE ';
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
|
2009-12-02 21:52:21 +03:00
|
|
|
if (count($index->getColumns()) == 0) {
|
2009-11-03 21:30:21 +03:00
|
|
|
throw \InvalidArgumentException("Incomplete definition. 'columns' required.");
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
|
2010-01-06 16:23:56 +03:00
|
|
|
return $type . 'INDEX ' . $name . ' ('
|
|
|
|
. $this->getIndexFieldDeclarationListSql($index->getColumns())
|
|
|
|
. ')';
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
|
2010-01-21 01:35:18 +03:00
|
|
|
/**
|
|
|
|
* getCustomTypeDeclarationSql
|
|
|
|
* Obtail SQL code portion needed to create a custom column,
|
|
|
|
* e.g. when a field has the "columnDefinition" keyword.
|
|
|
|
* Only "AUTOINCREMENT" and "PRIMARY KEY" are added if appropriate.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getCustomTypeDeclarationSql(array $columnDef)
|
|
|
|
{
|
|
|
|
return $columnDef['columnDefinition'];
|
|
|
|
}
|
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
|
|
|
* getIndexFieldDeclarationList
|
|
|
|
* Obtain DBMS specific SQL code portion needed to set an index
|
|
|
|
* declaration to be used in statements like CREATE TABLE.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getIndexFieldDeclarationListSql(array $fields)
|
|
|
|
{
|
|
|
|
$ret = array();
|
|
|
|
foreach ($fields as $field => $definition) {
|
|
|
|
if (is_array($definition)) {
|
2009-08-11 14:51:38 +04:00
|
|
|
$ret[] = $field;
|
2008-09-12 12:51:56 +04:00
|
|
|
} else {
|
2009-08-11 14:51:38 +04:00
|
|
|
$ret[] = $definition;
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return implode(', ', $ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A method to return the required SQL string that fits between CREATE ... TABLE
|
|
|
|
* to create the table as a temporary table.
|
|
|
|
*
|
|
|
|
* Should be overridden in driver classes to return the correct string for the
|
|
|
|
* specific database type.
|
|
|
|
*
|
|
|
|
* The default is to return the string "TEMPORARY" - this will result in a
|
|
|
|
* SQL error for any database that does not support temporary tables, or that
|
|
|
|
* requires a different SQL command from "CREATE TEMPORARY TABLE".
|
|
|
|
*
|
|
|
|
* @return string The string required to be placed between "CREATE" and "TABLE"
|
|
|
|
* to generate a temporary table, if possible.
|
|
|
|
*/
|
|
|
|
public function getTemporaryTableSql()
|
|
|
|
{
|
|
|
|
return 'TEMPORARY';
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
2009-05-27 22:54:40 +04:00
|
|
|
* Get sql query to show a list of database
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
|
|
|
public function getShowDatabasesSql()
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
|
|
|
* getForeignKeyDeclaration
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* @return string DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
|
|
|
|
* of a field declaration.
|
|
|
|
*/
|
2009-12-02 21:52:21 +03:00
|
|
|
public function getForeignKeyDeclarationSql(ForeignKeyConstraint $foreignKey)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
2009-12-02 21:52:21 +03:00
|
|
|
$sql = $this->getForeignKeyBaseDeclarationSql($foreignKey);
|
|
|
|
$sql .= $this->getAdvancedForeignKeyOptionsSql($foreignKey);
|
2008-09-12 12:51:56 +04:00
|
|
|
|
|
|
|
return $sql;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the FOREIGN KEY query section dealing with non-standard options
|
|
|
|
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
|
|
|
|
*
|
2009-12-02 21:52:21 +03:00
|
|
|
* @param ForeignKeyConstraint $foreignKey foreign key definition
|
2008-09-12 12:51:56 +04:00
|
|
|
* @return string
|
|
|
|
*/
|
2009-12-02 21:52:21 +03:00
|
|
|
public function getAdvancedForeignKeyOptionsSql(ForeignKeyConstraint $foreignKey)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
|
|
|
$query = '';
|
2009-12-02 21:52:21 +03:00
|
|
|
if ($this->supportsForeignKeyOnUpdate() && $foreignKey->hasOption('onUpdate')) {
|
|
|
|
$query .= ' ON UPDATE ' . $this->getForeignKeyReferentialActionSql($foreignKey->getOption('onUpdate'));
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
2009-12-02 21:52:21 +03:00
|
|
|
if ($foreignKey->hasOption('onDelete')) {
|
|
|
|
$query .= ' ON DELETE ' . $this->getForeignKeyReferentialActionSql($foreignKey->getOption('onDelete'));
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns given referential action in uppercase if valid, otherwise throws
|
|
|
|
* an exception
|
|
|
|
*
|
|
|
|
* @throws Doctrine_Exception_Exception if unknown referential action given
|
|
|
|
* @param string $action foreign key referential action
|
|
|
|
* @param string foreign key referential action in uppercase
|
|
|
|
*/
|
|
|
|
public function getForeignKeyReferentialActionSql($action)
|
|
|
|
{
|
|
|
|
$upper = strtoupper($action);
|
|
|
|
switch ($upper) {
|
|
|
|
case 'CASCADE':
|
|
|
|
case 'SET NULL':
|
|
|
|
case 'NO ACTION':
|
|
|
|
case 'RESTRICT':
|
|
|
|
case 'SET DEFAULT':
|
|
|
|
return $upper;
|
|
|
|
break;
|
|
|
|
default:
|
2009-11-03 21:30:21 +03:00
|
|
|
throw \InvalidArgumentException('Invalid foreign key action: ' . $upper);
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2009-12-02 21:52:21 +03:00
|
|
|
* @param ForeignKeyConstraint $foreignKey
|
2008-09-12 12:51:56 +04:00
|
|
|
* @return string
|
|
|
|
*/
|
2009-12-02 21:52:21 +03:00
|
|
|
public function getForeignKeyBaseDeclarationSql(ForeignKeyConstraint $foreignKey)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
|
|
|
$sql = '';
|
2009-12-02 21:52:21 +03:00
|
|
|
if (strlen($foreignKey->getName())) {
|
|
|
|
$sql .= 'CONSTRAINT ' . $foreignKey->getName() . ' ';
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
$sql .= 'FOREIGN KEY (';
|
|
|
|
|
2009-12-02 21:52:21 +03:00
|
|
|
if (count($foreignKey->getLocalColumns()) == 0) {
|
2009-11-03 21:30:21 +03:00
|
|
|
throw new \InvalidArgumentException("Incomplete definition. 'local' required.");
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
2009-12-02 21:52:21 +03:00
|
|
|
if (count($foreignKey->getForeignColumns()) == 0) {
|
2009-11-03 21:30:21 +03:00
|
|
|
throw new \InvalidArgumentException("Incomplete definition. 'foreign' required.");
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
2009-12-02 21:52:21 +03:00
|
|
|
if (strlen($foreignKey->getForeignTableName()) == 0) {
|
2009-11-03 21:30:21 +03:00
|
|
|
throw new \InvalidArgumentException("Incomplete definition. 'foreignTable' required.");
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
|
2009-12-02 21:52:21 +03:00
|
|
|
$sql .= implode(', ', $foreignKey->getLocalColumns())
|
2008-09-12 12:51:56 +04:00
|
|
|
. ') REFERENCES '
|
2009-12-02 21:52:21 +03:00
|
|
|
. $foreignKey->getForeignTableName() . '('
|
|
|
|
. implode(', ', $foreignKey->getForeignColumns()) . ')';
|
2008-09-12 12:51:56 +04:00
|
|
|
|
|
|
|
return $sql;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain DBMS specific SQL code portion needed to set the UNIQUE constraint
|
|
|
|
* of a field declaration to be used in statements like CREATE TABLE.
|
|
|
|
*
|
|
|
|
* @return string DBMS specific SQL code portion needed to set the UNIQUE constraint
|
|
|
|
* of a field declaration.
|
|
|
|
*/
|
|
|
|
public function getUniqueFieldDeclarationSql()
|
|
|
|
{
|
|
|
|
return 'UNIQUE';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
|
|
|
|
* 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.
|
|
|
|
*/
|
2009-05-03 22:07:57 +04:00
|
|
|
public function getColumnCharsetDeclarationSql($charset)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain DBMS specific SQL code portion needed to set the COLLATION
|
|
|
|
* 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.
|
|
|
|
*/
|
2009-05-03 22:07:57 +04:00
|
|
|
public function getColumnCollationDeclarationSql($collation)
|
2008-09-12 12:51:56 +04:00
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
|
|
|
* Whether the platform prefers sequences for ID generation.
|
|
|
|
* Subclasses should override this method to return TRUE if they prefer sequences.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function prefersSequences()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
|
|
|
* Whether the platform prefers identity columns (eg. autoincrement) for ID generation.
|
|
|
|
* Subclasses should override this method to return TRUE if they prefer identity columns.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function prefersIdentityColumns()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/**
|
|
|
|
* Some platforms need the boolean values to be converted.
|
2009-10-13 14:48:46 +04:00
|
|
|
*
|
|
|
|
* The default conversion in this implementation converts to integers (false => 0, true => 1).
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
2009-10-13 14:48:46 +04:00
|
|
|
* @param mixed $item
|
2008-09-12 12:51:56 +04:00
|
|
|
*/
|
|
|
|
public function convertBooleans($item)
|
|
|
|
{
|
|
|
|
if (is_array($item)) {
|
|
|
|
foreach ($item as $k => $value) {
|
|
|
|
if (is_bool($value)) {
|
|
|
|
$item[$k] = (int) $value;
|
|
|
|
}
|
|
|
|
}
|
2009-06-14 21:34:28 +04:00
|
|
|
} else if (is_bool($item)) {
|
|
|
|
$item = (int) $item;
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-02-05 20:34:44 +03:00
|
|
|
* Gets the SQL statement specific for the platform to set the charset.
|
2008-09-12 12:51:56 +04:00
|
|
|
*
|
2009-11-03 02:13:46 +03:00
|
|
|
* This function is MySQL specific and required by
|
|
|
|
* {@see \Doctrine\DBAL\Connection::setCharset($charset)}
|
|
|
|
*
|
2009-02-05 20:34:44 +03:00
|
|
|
* @param string $charset
|
2008-09-12 12:51:56 +04:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSetCharsetSql($charset)
|
|
|
|
{
|
2009-11-03 02:13:46 +03:00
|
|
|
return "SET NAMES '".$charset."'";
|
2008-09-12 12:51:56 +04:00
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2009-06-20 16:59:33 +04:00
|
|
|
/**
|
|
|
|
* Gets the SQL specific for the platform to get the current date.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getCurrentDateSql()
|
|
|
|
{
|
|
|
|
return 'CURRENT_DATE';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the SQL specific for the platform to get the current time.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getCurrentTimeSql()
|
|
|
|
{
|
|
|
|
return 'CURRENT_TIME';
|
|
|
|
}
|
|
|
|
|
2009-06-20 18:24:21 +04:00
|
|
|
/**
|
|
|
|
* Gets the SQL specific for the platform to get the current timestamp
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getCurrentTimestampSql()
|
|
|
|
{
|
|
|
|
return 'CURRENT_TIMESTAMP';
|
|
|
|
}
|
2009-06-20 16:59:33 +04:00
|
|
|
|
2008-09-12 21:25:38 +04:00
|
|
|
/**
|
2009-05-27 22:54:40 +04:00
|
|
|
* Get sql for transaction isolation level Connection constant
|
2008-09-12 21:25:38 +04:00
|
|
|
*
|
2009-02-05 20:34:44 +03:00
|
|
|
* @param integer $level
|
2008-09-12 21:25:38 +04:00
|
|
|
*/
|
|
|
|
protected function _getTransactionIsolationLevelSql($level)
|
|
|
|
{
|
|
|
|
switch ($level) {
|
2009-01-22 22:38:10 +03:00
|
|
|
case Connection::TRANSACTION_READ_UNCOMMITTED:
|
2008-09-12 21:25:38 +04:00
|
|
|
return 'READ UNCOMMITTED';
|
2009-01-22 22:38:10 +03:00
|
|
|
case Connection::TRANSACTION_READ_COMMITTED:
|
2008-09-12 21:25:38 +04:00
|
|
|
return 'READ COMMITTED';
|
2009-01-22 22:38:10 +03:00
|
|
|
case Connection::TRANSACTION_REPEATABLE_READ:
|
2008-09-12 21:25:38 +04:00
|
|
|
return 'REPEATABLE READ';
|
2009-01-22 22:38:10 +03:00
|
|
|
case Connection::TRANSACTION_SERIALIZABLE:
|
2008-09-12 21:25:38 +04:00
|
|
|
return 'SERIALIZABLE';
|
|
|
|
default:
|
2009-11-03 21:30:21 +03:00
|
|
|
throw new \InvalidArgumentException('Invalid isolation level:' . $level);
|
2009-05-27 22:54:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getListDatabasesSql()
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-27 22:54:40 +04:00
|
|
|
}
|
|
|
|
|
2009-05-28 06:04:51 +04:00
|
|
|
public function getListSequencesSql($database)
|
2009-05-27 22:54:40 +04:00
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-27 22:54:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getListTableConstraintsSql($table)
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-27 22:54:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getListTableColumnsSql($table)
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-27 22:54:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getListTablesSql()
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-27 22:54:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getListUsersSql()
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-27 22:54:40 +04:00
|
|
|
}
|
|
|
|
|
2010-02-11 02:41:35 +03:00
|
|
|
/**
|
|
|
|
* Get the SQL to list all views of a database or user.
|
|
|
|
*
|
|
|
|
* @param string $database
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getListViewsSql($database)
|
2009-05-27 22:54:40 +04:00
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-27 22:54:40 +04:00
|
|
|
}
|
|
|
|
|
2009-05-28 06:04:51 +04:00
|
|
|
public function getListTableIndexesSql($table)
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2009-05-29 01:34:35 +04:00
|
|
|
public function getListTableForeignKeysSql($table)
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-29 01:34:35 +04:00
|
|
|
}
|
|
|
|
|
2009-05-28 06:04:51 +04:00
|
|
|
public function getCreateViewSql($name, $sql)
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getDropViewSql($name)
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-28 06:04:51 +04:00
|
|
|
}
|
|
|
|
|
2009-12-03 01:28:38 +03:00
|
|
|
public function getDropSequenceSql($sequence)
|
2009-05-27 22:54:40 +04:00
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-27 22:54:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSequenceNextValSql($sequenceName)
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2008-09-12 21:25:38 +04:00
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
|
|
|
public function getCreateDatabaseSql($database)
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-05-27 22:54:40 +04:00
|
|
|
}
|
|
|
|
|
2008-09-12 21:25:38 +04:00
|
|
|
/**
|
2009-05-27 22:54:40 +04:00
|
|
|
* Get sql to set the transaction isolation level
|
2008-09-12 21:25:38 +04:00
|
|
|
*
|
2009-02-05 20:34:44 +03:00
|
|
|
* @param integer $level
|
2008-09-12 21:25:38 +04:00
|
|
|
*/
|
|
|
|
public function getSetTransactionIsolationSql($level)
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2008-09-12 21:25:38 +04:00
|
|
|
}
|
2009-05-26 22:14:19 +04:00
|
|
|
|
2009-06-20 16:59:33 +04:00
|
|
|
/**
|
|
|
|
* Obtain DBMS specific SQL to be used to create datetime fields in
|
|
|
|
* statements like CREATE TABLE
|
|
|
|
*
|
|
|
|
* @param array $fieldDeclaration
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDateTimeTypeDeclarationSql(array $fieldDeclaration)
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-06-20 16:59:33 +04:00
|
|
|
}
|
2009-08-28 21:25:28 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain DBMS specific SQL to be used to create date fields in statements
|
|
|
|
* like CREATE TABLE.
|
|
|
|
*
|
|
|
|
* @param array $fieldDeclaration
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDateTypeDeclarationSql(array $fieldDeclaration)
|
|
|
|
{
|
2009-11-03 21:30:21 +03:00
|
|
|
throw DBALException::notSupported(__METHOD__);
|
2009-08-28 21:25:28 +04:00
|
|
|
}
|
2009-06-20 16:59:33 +04:00
|
|
|
|
2009-11-03 19:56:05 +03:00
|
|
|
/**
|
|
|
|
* Obtain DBMS specific SQL to be used to create time fields in statements
|
|
|
|
* like CREATE TABLE.
|
|
|
|
*
|
|
|
|
* @param array $fieldDeclaration
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getTimeTypeDeclarationSql(array $fieldDeclaration)
|
|
|
|
{
|
|
|
|
throw DoctrineException::getTimeTypeDeclarationNotSupported($this);
|
|
|
|
}
|
|
|
|
|
2008-09-12 21:25:38 +04:00
|
|
|
/**
|
|
|
|
* Gets the default transaction isolation level of the platform.
|
|
|
|
*
|
|
|
|
* @return integer The default isolation level.
|
2009-02-05 20:34:44 +03:00
|
|
|
* @see Doctrine\DBAL\Connection\TRANSACTION_* constants.
|
2008-09-12 21:25:38 +04:00
|
|
|
*/
|
|
|
|
public function getDefaultTransactionIsolationLevel()
|
|
|
|
{
|
2009-01-22 22:38:10 +03:00
|
|
|
return Connection::TRANSACTION_READ_COMMITTED;
|
2008-09-12 21:25:38 +04:00
|
|
|
}
|
2009-05-27 22:54:40 +04:00
|
|
|
|
2008-09-12 12:51:56 +04:00
|
|
|
/* supports*() metods */
|
2009-02-05 20:34:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the platform supports sequences.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2008-09-12 12:51:56 +04:00
|
|
|
public function supportsSequences()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-02-05 20:34:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the platform supports identity columns.
|
|
|
|
* Identity columns are columns that recieve an auto-generated value from the
|
|
|
|
* database on insert of a row.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2008-09-12 12:51:56 +04:00
|
|
|
public function supportsIdentityColumns()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-02-05 20:34:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the platform supports indexes.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2008-09-12 12:51:56 +04:00
|
|
|
public function supportsIndexes()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-02-05 20:34:44 +03:00
|
|
|
|
2009-12-06 15:13:15 +03:00
|
|
|
public function supportsAlterTable()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-02-05 20:34:44 +03:00
|
|
|
/**
|
|
|
|
* Whether the platform supports transactions.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2008-09-12 12:51:56 +04:00
|
|
|
public function supportsTransactions()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-02-05 20:34:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the platform supports savepoints.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2008-09-12 12:51:56 +04:00
|
|
|
public function supportsSavepoints()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-02-05 20:34:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the platform supports primary key constraints.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2008-09-12 12:51:56 +04:00
|
|
|
public function supportsPrimaryConstraints()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-02-05 20:34:44 +03:00
|
|
|
|
|
|
|
/**
|
2009-12-02 21:52:21 +03:00
|
|
|
* Does the platform supports foreign key constraints?
|
2009-02-05 20:34:44 +03:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2008-09-12 12:51:56 +04:00
|
|
|
public function supportsForeignKeyConstraints()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-12-02 21:52:21 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Does this platform supports onUpdate in foreign key constraints?
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function supportsForeignKeyOnUpdate()
|
|
|
|
{
|
|
|
|
return ($this->supportsForeignKeyConstraints() && true);
|
|
|
|
}
|
2009-08-11 14:51:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the platform supports database schemas.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function supportsSchemas()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-02-05 20:34:44 +03:00
|
|
|
|
2009-12-06 21:36:46 +03:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function createsExplicitIndexForForeignKeys()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-05 20:34:44 +03:00
|
|
|
/**
|
2009-05-03 22:07:57 +04:00
|
|
|
* Whether the platform supports getting the affected rows of a recent
|
2009-02-05 20:34:44 +03:00
|
|
|
* update/delete type query.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2008-09-12 12:51:56 +04:00
|
|
|
public function supportsGettingAffectedRows()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-07 20:46:02 +03:00
|
|
|
|
|
|
|
public function getIdentityColumnNullInsertSql()
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2009-06-20 16:59:33 +04:00
|
|
|
/**
|
2009-06-22 22:48:42 +04:00
|
|
|
* Gets the format string, as accepted by the date() function, that describes
|
|
|
|
* the format of a stored datetime value of this platform.
|
|
|
|
*
|
|
|
|
* @return string The format string.
|
2009-08-28 16:36:06 +04:00
|
|
|
*
|
|
|
|
* @todo We need to get the specific format for each dbms and override this
|
2009-06-20 16:59:33 +04:00
|
|
|
* function for each platform
|
|
|
|
*/
|
|
|
|
public function getDateTimeFormatString()
|
|
|
|
{
|
|
|
|
return 'Y-m-d H:i:s';
|
|
|
|
}
|
|
|
|
|
2009-06-22 22:48:42 +04:00
|
|
|
/**
|
|
|
|
* Gets the format string, as accepted by the date() function, that describes
|
|
|
|
* the format of a stored date value of this platform.
|
|
|
|
*
|
|
|
|
* @return string The format string.
|
|
|
|
*/
|
2009-06-20 18:24:21 +04:00
|
|
|
public function getDateFormatString()
|
|
|
|
{
|
2010-01-16 11:52:58 +03:00
|
|
|
return 'Y-m-d';
|
2009-06-20 18:24:21 +04:00
|
|
|
}
|
2009-06-22 22:48:42 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the format string, as accepted by the date() function, that describes
|
|
|
|
* the format of a stored time value of this platform.
|
|
|
|
*
|
|
|
|
* @return string The format string.
|
|
|
|
*/
|
2009-06-20 18:24:21 +04:00
|
|
|
public function getTimeFormatString()
|
|
|
|
{
|
|
|
|
return 'H:i:s';
|
|
|
|
}
|
|
|
|
|
2009-07-14 02:59:36 +04:00
|
|
|
public function modifyLimitQuery($query, $limit, $offset = null)
|
2009-07-10 21:53:48 +04:00
|
|
|
{
|
2009-07-14 02:59:36 +04:00
|
|
|
if ( ! is_null($limit)) {
|
|
|
|
$query .= ' LIMIT ' . $limit;
|
2009-07-10 21:53:48 +04:00
|
|
|
}
|
|
|
|
|
2009-10-12 23:10:41 +04:00
|
|
|
if ( ! is_null($offset)) {
|
|
|
|
$query .= ' OFFSET ' . $offset;
|
|
|
|
}
|
|
|
|
|
2009-07-10 21:53:48 +04:00
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
2009-01-07 20:46:02 +03:00
|
|
|
/**
|
2009-05-03 22:07:57 +04:00
|
|
|
* Gets the SQL snippet used to declare a VARCHAR column type.
|
2009-01-07 20:46:02 +03:00
|
|
|
*
|
2009-05-27 22:54:40 +04:00
|
|
|
* @param array $field
|
2009-01-07 20:46:02 +03:00
|
|
|
*/
|
2009-05-03 22:07:57 +04:00
|
|
|
abstract public function getVarcharTypeDeclarationSql(array $field);
|
2009-10-01 16:00:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the SQL snippet used to declare a CLOB column type.
|
|
|
|
*
|
|
|
|
* @param array $field
|
|
|
|
*/
|
|
|
|
abstract public function getClobTypeDeclarationSql(array $field);
|
2009-05-27 22:54:40 +04:00
|
|
|
|
|
|
|
/**
|
2009-06-22 22:48:42 +04:00
|
|
|
* Gets the name of the platform.
|
2009-05-27 22:54:40 +04:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
abstract public function getName();
|
2009-08-11 14:51:38 +04:00
|
|
|
|
2009-08-15 22:11:51 +04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2009-08-11 14:51:38 +04:00
|
|
|
public function getSqlResultCasing($column)
|
|
|
|
{
|
|
|
|
return $column;
|
|
|
|
}
|
2009-08-28 21:25:28 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes any fixes to a name of a schema element (table, sequence, ...) that are required
|
|
|
|
* by restrictions of the platform, like a maximum length.
|
|
|
|
*
|
|
|
|
* @param string $schemaName
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function fixSchemaElementName($schemaElementName)
|
|
|
|
{
|
|
|
|
return $schemaElementName;
|
|
|
|
}
|
2009-09-08 23:31:26 +04:00
|
|
|
|
2009-12-11 01:39:28 +03:00
|
|
|
/**
|
|
|
|
* Maximum length of any given databse identifier, like tables or column names.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getMaxIdentifierLength()
|
|
|
|
{
|
|
|
|
return 63;
|
|
|
|
}
|
|
|
|
|
2009-09-08 23:31:26 +04:00
|
|
|
/**
|
|
|
|
* Get the insert sql for an empty insert statement
|
|
|
|
*
|
|
|
|
* @param string $tableName
|
|
|
|
* @param string $identifierColumnName
|
|
|
|
* @return string $sql
|
|
|
|
*/
|
|
|
|
public function getEmptyIdentityInsertSql($tableName, $identifierColumnName)
|
|
|
|
{
|
|
|
|
return 'INSERT INTO ' . $tableName . ' (' . $identifierColumnName . ') VALUES (null)';
|
|
|
|
}
|
2010-02-07 15:36:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a Truncate Table SQL statement for a given table.
|
|
|
|
*
|
|
|
|
* Cascade is not supported on many platforms but would optionally cascade the truncate by
|
|
|
|
* following the foreign keys.
|
|
|
|
*
|
|
|
|
* @param string $tableName
|
|
|
|
* @param bool $cascade
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getTruncateTableSql($tableName, $cascade = false)
|
|
|
|
{
|
|
|
|
return 'TRUNCATE '.$tableName;
|
|
|
|
}
|
2009-11-03 19:56:05 +03:00
|
|
|
}
|