164 if ($this->doctrineTypeMapping ===
null) {
172 $dbType = strtolower($dbType);
173 $this->doctrineTypeMapping[$dbType] = $doctrineType;
184 if ($this->doctrineTypeMapping ===
null) {
188 $dbType = strtolower($dbType);
189 if (isset($this->doctrineTypeMapping[$dbType])) {
190 return $this->doctrineTypeMapping[$dbType];
192 throw new \Doctrine\DBAL\DBALException(
"Unknown database type ".$dbType.
" requested, " . get_class($this) .
" may not support it.");
204 if ($this->doctrineTypeMapping ===
null) {
208 $dbType = strtolower($dbType);
209 return isset($this->doctrineTypeMapping[$dbType]);
269 return array(
'%',
'_');
290 return 'AVG(' . $column .
')';
304 return 'COUNT(' . $column .
')';
315 return 'MAX(' . $column .
')';
326 return 'MIN(' . $column .
')';
337 return 'SUM(' . $column .
')';
351 return 'MD5(' . $column .
')';
363 return 'LENGTH(' . $column .
')';
375 return 'ROUND(' . $column .
', ' . $decimals .
')';
388 return 'MOD(' . $expression1 .
', ' . $expression2 .
')';
402 $trimChar = ($char !=
false) ? $char .
' FROM ' :
'';
404 if ($pos == self::TRIM_LEADING) {
405 $posStr =
'LEADING '.$trimChar;
406 }
else if($pos == self::TRIM_TRAILING) {
407 $posStr =
'TRAILING '.$trimChar;
408 }
else if($pos == self::TRIM_BOTH) {
409 $posStr =
'BOTH '.$trimChar;
412 return 'TRIM(' . $posStr . $str .
')';
424 return 'RTRIM(' . $str .
')';
436 return 'LTRIM(' . $str .
')';
449 return 'UPPER(' . $str .
')';
462 return 'LOWER(' . $str .
')';
503 return 'SUBSTRING(' . $value .
' FROM ' . $from .
')';
505 return 'SUBSTRING(' . $value .
' FROM ' . $from .
' FOR ' . $len .
')';
520 return join(
' || ' , func_get_args());
538 return 'NOT(' . $expression .
')';
556 if ( ! is_array($values)) {
557 $values = array($values);
559 $values = $this->getIdentifiers($values);
561 if (count($values) == 0) {
562 throw \InvalidArgumentException(
'Values must not be empty.');
564 return $column .
' IN (' . implode(
', ', $values) .
')';
575 return $expression .
' IS NULL';
586 return $expression .
' IS NOT NULL';
606 return $expression .
' BETWEEN ' .$value1 .
' AND ' . $value2;
611 return 'ACOS(' . $value .
')';
616 return 'SIN(' . $value .
')';
626 return 'COS(' . $value .
')';
673 return 'DROP DATABASE ' . $database;
684 if ($table instanceof \Doctrine\DBAL\Schema\
Table) {
685 $table = $table->getQuotedName($this);
688 return 'DROP TABLE ' . $table;
700 if($index instanceof \Doctrine\DBAL\Schema\
Index) {
701 $index = $index->getQuotedName($this);
702 }
else if(!is_string($index)) {
703 throw new \InvalidArgumentException(
'AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
706 return 'DROP INDEX ' . $index;
718 if ($constraint instanceof \Doctrine\DBAL\Schema\Constraint) {
719 $constraint = $constraint->getQuotedName($this);
722 if ($table instanceof \Doctrine\DBAL\Schema\
Table) {
723 $table = $table->getQuotedName($this);
726 return 'ALTER TABLE ' . $table .
' DROP CONSTRAINT ' . $constraint;
737 $foreignKey = $foreignKey->getQuotedName($this);
740 if ($table instanceof \Doctrine\DBAL\Schema\
Table) {
741 $table = $table->getQuotedName($this);
744 return 'ALTER TABLE ' . $table .
' DROP FOREIGN KEY ' . $foreignKey;
757 if ( ! is_int($createFlags)) {
758 throw new \InvalidArgumentException(
"Second argument of AbstractPlatform::getCreateTableSQL() has to be integer.");
767 $options[
'uniqueConstraints'] = array();
768 $options[
'indexes'] = array();
769 $options[
'primary'] = array();
771 if (($createFlags&self::CREATE_INDEXES) > 0) {
774 if ($index->isPrimary()) {
775 $options[
'primary'] = $index->getColumns();
777 $options[
'indexes'][$index->getName()] = $index;
785 $columnData = array();
786 $columnData[
'name'] = $column->getQuotedName($this);
787 $columnData[
'type'] = $column->getType();
788 $columnData[
'length'] = $column->getLength();
789 $columnData[
'notnull'] = $column->getNotNull();
790 $columnData[
'unique'] =
false;
791 $columnData[
'version'] = ($column->hasPlatformOption(
"version"))?$column->getPlatformOption(
'version'):
false;
792 if(strtolower($columnData[
'type']) ==
"string" && $columnData[
'length'] ===
null) {
793 $columnData[
'length'] = 255;
795 $columnData[
'precision'] = $column->getPrecision();
796 $columnData[
'scale'] = $column->getScale();
797 $columnData[
'default'] = $column->getDefault();
798 $columnData[
'columnDefinition'] = $column->getColumnDefinition();
799 $columnData[
'autoincrement'] = $column->getAutoincrement();
801 if(in_array($column->getName(), $options[
'primary'])) {
802 $columnData[
'primary'] =
true;
805 $columns[$columnData[
'name']] = $columnData;
808 if (($createFlags&self::CREATE_FOREIGNKEYS) > 0) {
809 $options[
'foreignKeys'] = array();
811 $options[
'foreignKeys'][] = $fkConstraint;
828 if (isset($options[
'uniqueConstraints']) && ! empty($options[
'uniqueConstraints'])) {
829 foreach ($options[
'uniqueConstraints'] as $name => $definition) {
834 if (isset($options[
'primary']) && ! empty($options[
'primary'])) {
835 $columnListSql .=
', PRIMARY KEY(' . implode(
', ', array_unique(array_values($options[
'primary']))) .
')';
838 if (isset($options[
'indexes']) && ! empty($options[
'indexes'])) {
839 foreach($options[
'indexes'] as $index => $definition) {
844 $query =
'CREATE TABLE ' . $tableName .
' (' . $columnListSql;
847 if ( ! empty($check)) {
848 $query .=
', ' . $check;
854 if (isset($options[
'foreignKeys'])) {
855 foreach ((array) $options[
'foreignKeys'] AS $definition) {
865 return "CREATE TEMPORARY TABLE";
888 if ($table instanceof \Doctrine\DBAL\Schema\
Table) {
889 $table = $table->getQuotedName($this);
892 $query =
'ALTER TABLE ' . $table .
' ADD CONSTRAINT ' . $constraint->getQuotedName($this);
895 foreach ($constraint->getColumns() as $column) {
896 $columns[] = $column;
898 $columnList =
'('. implode(
', ', $columns) .
')';
900 $referencesClause =
'';
901 if ($constraint instanceof \Doctrine\DBAL\Schema\
Index) {
902 if($constraint->isPrimary()) {
903 $query .=
' PRIMARY KEY';
904 } elseif ($constraint->isUnique()) {
907 throw new \InvalidArgumentException(
908 'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().'
912 $query .=
' FOREIGN KEY';
914 $foreignColumns = array();
915 foreach ($constraint->getForeignColumns() AS $column) {
916 $foreignColumns[] = $column;
919 $referencesClause =
' REFERENCES '.$constraint->getForeignTableName().
' ('.implode(
', ', $foreignColumns).
')';
921 $query .=
' '.$columnList.$referencesClause;
935 if ($table instanceof
Table) {
936 $table = $table->getQuotedName($this);
941 if (count($columns) == 0) {
942 throw new \InvalidArgumentException(
"Incomplete definition. 'columns' required.");
950 $query =
'CREATE ' . $type .
'INDEX ' . $name .
' ON ' . $table;
972 return $c . $str . $c;
984 if ($table instanceof \Doctrine\DBAL\Schema\
Table) {
985 $table = $table->getQuotedName($this);
1014 if ($diff->newName !==
false) {
1015 $tableName = $diff->newName;
1017 $tableName = $diff->name;
1022 foreach ($diff->removedForeignKeys AS $foreignKey) {
1025 foreach ($diff->addedForeignKeys AS $foreignKey) {
1028 foreach ($diff->changedForeignKeys AS $foreignKey) {
1034 foreach ($diff->addedIndexes AS $index) {
1037 foreach ($diff->removedIndexes AS $index) {
1040 foreach ($diff->changedIndexes AS $index) {
1079 $queryFields = array();
1080 foreach ($fields as $fieldName => $field) {
1082 $queryFields[] = $query;
1084 return implode(
', ', $queryFields);
1122 if (isset($field[
'columnDefinition'])) {
1127 $charset = (isset($field[
'charset']) && $field[
'charset']) ?
1130 $collation = (isset($field[
'collation']) && $field[
'collation']) ?
1133 $notnull = (isset($field[
'notnull']) && $field[
'notnull']) ?
' NOT NULL' :
'';
1135 $unique = (isset($field[
'unique']) && $field[
'unique']) ?
1138 $check = (isset($field[
'check']) && $field[
'check']) ?
1139 ' ' . $field[
'check'] :
'';
1141 $typeDecl = $field[
'type']->getSqlDeclaration($field, $this);
1142 $columnDef = $typeDecl .
$charset . $default . $notnull . $unique . $check . $collation;
1145 return $name .
' ' . $columnDef;
1156 $columnDef[
'precision'] = ( ! isset($columnDef[
'precision']) || empty($columnDef[
'precision']))
1157 ? 10 : $columnDef[
'precision'];
1158 $columnDef[
'scale'] = ( ! isset($columnDef[
'scale']) || empty($columnDef[
'scale']))
1159 ? 0 : $columnDef[
'scale'];
1161 return 'NUMERIC(' . $columnDef[
'precision'] .
', ' . $columnDef[
'scale'] .
')';
1173 $default = empty($field[
'notnull']) ?
' DEFAULT NULL' :
'';
1175 if (isset($field[
'default'])) {
1176 $default =
" DEFAULT '".$field[
'default'].
"'";
1177 if (isset($field[
'type'])) {
1178 if (in_array((
string)$field[
'type'], array(
"Integer",
"BigInteger",
"SmallInteger"))) {
1179 $default =
" DEFAULT ".$field[
'default'];
1180 }
else if ((
string)$field[
'type'] ==
'DateTime' && $field[
'default'] == $this->
getCurrentTimestampSQL()) {
1181 $default =
" DEFAULT ".$this->getCurrentTimestampSQL();
1197 $constraints = array();
1198 foreach ($definition as $field => $def) {
1199 if (is_string($def)) {
1200 $constraints[] =
'CHECK (' . $def .
')';
1202 if (isset($def[
'min'])) {
1203 $constraints[] =
'CHECK (' . $field .
' >= ' . $def[
'min'] .
')';
1206 if (isset($def[
'max'])) {
1207 $constraints[] =
'CHECK (' . $field .
' <= ' . $def[
'max'] .
')';
1212 return implode(
', ', $constraints);
1227 throw \InvalidArgumentException(
"Incomplete definition. 'columns' required.");
1230 return 'CONSTRAINT ' . $name .
' UNIQUE ('
1252 throw \InvalidArgumentException(
"Incomplete definition. 'columns' required.");
1255 return $type .
'INDEX ' . $name .
' ('
1270 return $columnDef[
'columnDefinition'];
1283 foreach ($fields as $field => $definition) {
1284 if (is_array($definition)) {
1287 $ret[] = $definition;
1290 return implode(
', ', $ret);
1395 if ($foreignKey->
hasOption(
'onDelete')) {
1421 throw new \InvalidArgumentException(
'Invalid foreign key action: ' . $upper);
1435 if (strlen($foreignKey->
getName())) {
1436 $sql .=
'CONSTRAINT ' . $foreignKey->
getQuotedName($this) .
' ';
1438 $sql .=
'FOREIGN KEY (';
1441 throw new \InvalidArgumentException(
"Incomplete definition. 'local' required.");
1444 throw new \InvalidArgumentException(
"Incomplete definition. 'foreign' required.");
1447 throw new \InvalidArgumentException(
"Incomplete definition. 'foreignTable' required.");
1527 if (is_array($item)) {
1528 foreach ($item as $k => $value) {
1529 if (is_bool($value)) {
1530 $item[$k] = (int) $value;
1533 }
else if (is_bool($item)) {
1534 $item = (int) $item;
1550 return "SET NAMES '".$charset.
"'";
1560 return 'CURRENT_DATE';
1570 return 'CURRENT_TIME';
1580 return 'CURRENT_TIMESTAMP';
1592 return 'READ UNCOMMITTED';
1594 return 'READ COMMITTED';
1596 return 'REPEATABLE READ';
1598 return 'SERIALIZABLE';
1600 throw new \InvalidArgumentException(
'Invalid isolation level:' . $level);
1739 return 'DOUBLE PRECISION';
1896 return 'Y-m-d H:i:s';
1907 return 'Y-m-d H:i:s';
1934 if ( ! is_null($limit)) {
1935 $query .=
' LIMIT ' . $limit;
1938 if ( ! is_null($offset)) {
1939 $query .=
' OFFSET ' . $offset;
1965 return $schemaElementName;
1987 return 'INSERT INTO ' . $tableName .
' (' . $identifierColumnName .
') VALUES (null)';
2002 return 'TRUNCATE '.$tableName;
2023 return 'SAVEPOINT ' . $savepoint;
2034 return 'RELEASE SAVEPOINT ' . $savepoint;
2045 return 'ROLLBACK TO SAVEPOINT ' . $savepoint;
const TRANSACTION_REPEATABLE_READ
const TRANSACTION_READ_COMMITTED
const TRANSACTION_READ_UNCOMMITTED
const TRANSACTION_SERIALIZABLE
static typeNotFound($name)
static notSupported($method)
static noColumnsSpecifiedForTable($tableName)
getQuotedName(AbstractPlatform $platform)