MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
AbstractPlatform.php
Ir para a documentação deste ficheiro.
1<?php
2/*
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 *
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the LGPL. For more information, see
17 * <http://www.doctrine-project.org>.
18 */
19
21
29
46abstract class AbstractPlatform
47{
51 const CREATE_INDEXES = 1;
52
57
62
66 const TRIM_LEADING = 1;
67
71 const TRIM_TRAILING = 2;
72
76 const TRIM_BOTH = 3;
77
81 protected $doctrineTypeMapping = null;
82
86 public function __construct() {}
87
94 abstract public function getBooleanTypeDeclarationSQL(array $columnDef);
95
102 abstract public function getIntegerTypeDeclarationSQL(array $columnDef);
103
110 abstract public function getBigIntTypeDeclarationSQL(array $columnDef);
111
118 abstract public function getSmallIntTypeDeclarationSQL(array $columnDef);
119
126 abstract protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef);
127
133 abstract protected function initializeDoctrineTypeMappings();
134
140 abstract public function getVarcharTypeDeclarationSQL(array $field);
141
147 abstract public function getClobTypeDeclarationSQL(array $field);
148
154 abstract public function getName();
155
162 public function registerDoctrineTypeMapping($dbType, $doctrineType)
163 {
164 if ($this->doctrineTypeMapping === null) {
166 }
167
168 if (!Types\Type::hasType($doctrineType)) {
169 throw DBALException::typeNotFound($doctrineType);
170 }
171
172 $dbType = strtolower($dbType);
173 $this->doctrineTypeMapping[$dbType] = $doctrineType;
174 }
175
182 public function getDoctrineTypeMapping($dbType)
183 {
184 if ($this->doctrineTypeMapping === null) {
186 }
187
188 $dbType = strtolower($dbType);
189 if (isset($this->doctrineTypeMapping[$dbType])) {
190 return $this->doctrineTypeMapping[$dbType];
191 } else {
192 throw new \Doctrine\DBAL\DBALException("Unknown database type ".$dbType." requested, " . get_class($this) . " may not support it.");
193 }
194 }
195
202 public function hasDoctrineTypeMappingFor($dbType)
203 {
204 if ($this->doctrineTypeMapping === null) {
206 }
207
208 $dbType = strtolower($dbType);
209 return isset($this->doctrineTypeMapping[$dbType]);
210 }
211
218 {
219 return '"';
220 }
221
227 public function getSqlCommentStartString()
228 {
229 return "--";
230 }
231
237 public function getSqlCommentEndString()
238 {
239 return "\n";
240 }
241
247 public function getVarcharMaxLength()
248 {
249 return 4000;
250 }
251
257 public function getVarcharDefaultLength()
258 {
259 return 255;
260 }
261
267 public function getWildcards()
268 {
269 return array('%', '_');
270 }
271
277 public function getRegexpExpression()
278 {
279 throw DBALException::notSupported(__METHOD__);
280 }
281
288 public function getAvgExpression($column)
289 {
290 return 'AVG(' . $column . ')';
291 }
292
302 public function getCountExpression($column)
303 {
304 return 'COUNT(' . $column . ')';
305 }
306
313 public function getMaxExpression($column)
314 {
315 return 'MAX(' . $column . ')';
316 }
317
324 public function getMinExpression($column)
325 {
326 return 'MIN(' . $column . ')';
327 }
328
335 public function getSumExpression($column)
336 {
337 return 'SUM(' . $column . ')';
338 }
339
340 // scalar functions
341
349 public function getMd5Expression($column)
350 {
351 return 'MD5(' . $column . ')';
352 }
353
361 public function getLengthExpression($column)
362 {
363 return 'LENGTH(' . $column . ')';
364 }
365
373 public function getRoundExpression($column, $decimals = 0)
374 {
375 return 'ROUND(' . $column . ', ' . $decimals . ')';
376 }
377
386 public function getModExpression($expression1, $expression2)
387 {
388 return 'MOD(' . $expression1 . ', ' . $expression2 . ')';
389 }
390
399 public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false)
400 {
401 $posStr = '';
402 $trimChar = ($char != false) ? $char . ' FROM ' : '';
403
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;
410 }
411
412 return 'TRIM(' . $posStr . $str . ')';
413 }
414
422 public function getRtrimExpression($str)
423 {
424 return 'RTRIM(' . $str . ')';
425 }
426
434 public function getLtrimExpression($str)
435 {
436 return 'LTRIM(' . $str . ')';
437 }
438
447 public function getUpperExpression($str)
448 {
449 return 'UPPER(' . $str . ')';
450 }
451
460 public function getLowerExpression($str)
461 {
462 return 'LOWER(' . $str . ')';
463 }
464
473 public function getLocateExpression($str, $substr, $startPos = false)
474 {
475 throw DBALException::notSupported(__METHOD__);
476 }
477
483 public function getNowExpression()
484 {
485 return 'NOW()';
486 }
487
500 public function getSubstringExpression($value, $from, $len = null)
501 {
502 if ($len === null)
503 return 'SUBSTRING(' . $value . ' FROM ' . $from . ')';
504 else {
505 return 'SUBSTRING(' . $value . ' FROM ' . $from . ' FOR ' . $len . ')';
506 }
507 }
508
518 public function getConcatExpression()
519 {
520 return join(' || ' , func_get_args());
521 }
522
536 public function getNotExpression($expression)
537 {
538 return 'NOT(' . $expression . ')';
539 }
540
554 public function getInExpression($column, $values)
555 {
556 if ( ! is_array($values)) {
557 $values = array($values);
558 }
559 $values = $this->getIdentifiers($values);
560
561 if (count($values) == 0) {
562 throw \InvalidArgumentException('Values must not be empty.');
563 }
564 return $column . ' IN (' . implode(', ', $values) . ')';
565 }
566
573 public function getIsNullExpression($expression)
574 {
575 return $expression . ' IS NULL';
576 }
577
584 public function getIsNotNullExpression($expression)
585 {
586 return $expression . ' IS NOT NULL';
587 }
588
604 public function getBetweenExpression($expression, $value1, $value2)
605 {
606 return $expression . ' BETWEEN ' .$value1 . ' AND ' . $value2;
607 }
608
609 public function getAcosExpression($value)
610 {
611 return 'ACOS(' . $value . ')';
612 }
613
614 public function getSinExpression($value)
615 {
616 return 'SIN(' . $value . ')';
617 }
618
619 public function getPiExpression()
620 {
621 return 'PI()';
622 }
623
624 public function getCosExpression($value)
625 {
626 return 'COS(' . $value . ')';
627 }
628
629 public function getForUpdateSQL()
630 {
631 return 'FOR UPDATE';
632 }
633
641 public function appendLockHint($fromClause, $lockMode)
642 {
643 return $fromClause;
644 }
645
654 public function getReadLockSQL()
655 {
656 return $this->getForUpdateSQL();
657 }
658
666 public function getWriteLockSQL()
667 {
668 return $this->getForUpdateSQL();
669 }
670
671 public function getDropDatabaseSQL($database)
672 {
673 return 'DROP DATABASE ' . $database;
674 }
675
682 public function getDropTableSQL($table)
683 {
684 if ($table instanceof \Doctrine\DBAL\Schema\Table) {
685 $table = $table->getQuotedName($this);
686 }
687
688 return 'DROP TABLE ' . $table;
689 }
690
698 public function getDropIndexSQL($index, $table=null)
699 {
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.');
704 }
705
706 return 'DROP INDEX ' . $index;
707 }
708
716 public function getDropConstraintSQL($constraint, $table)
717 {
718 if ($constraint instanceof \Doctrine\DBAL\Schema\Constraint) {
719 $constraint = $constraint->getQuotedName($this);
720 }
721
722 if ($table instanceof \Doctrine\DBAL\Schema\Table) {
723 $table = $table->getQuotedName($this);
724 }
725
726 return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $constraint;
727 }
728
734 public function getDropForeignKeySQL($foreignKey, $table)
735 {
736 if ($foreignKey instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) {
737 $foreignKey = $foreignKey->getQuotedName($this);
738 }
739
740 if ($table instanceof \Doctrine\DBAL\Schema\Table) {
741 $table = $table->getQuotedName($this);
742 }
743
744 return 'ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $foreignKey;
745 }
746
755 public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXES)
756 {
757 if ( ! is_int($createFlags)) {
758 throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSQL() has to be integer.");
759 }
760
761 if (count($table->getColumns()) == 0) {
763 }
764
765 $tableName = $table->getQuotedName($this);
766 $options = $table->getOptions();
767 $options['uniqueConstraints'] = array();
768 $options['indexes'] = array();
769 $options['primary'] = array();
770
771 if (($createFlags&self::CREATE_INDEXES) > 0) {
772 foreach ($table->getIndexes() AS $index) {
773 /* @var $index Index */
774 if ($index->isPrimary()) {
775 $options['primary'] = $index->getColumns();
776 } else {
777 $options['indexes'][$index->getName()] = $index;
778 }
779 }
780 }
781
782 $columns = array();
783 foreach ($table->getColumns() AS $column) {
784 /* @var \Doctrine\DBAL\Schema\Column $column */
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; // TODO: what do we do about this?
791 $columnData['version'] = ($column->hasPlatformOption("version"))?$column->getPlatformOption('version'):false;
792 if(strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
793 $columnData['length'] = 255;
794 }
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();
800
801 if(in_array($column->getName(), $options['primary'])) {
802 $columnData['primary'] = true;
803 }
804
805 $columns[$columnData['name']] = $columnData;
806 }
807
808 if (($createFlags&self::CREATE_FOREIGNKEYS) > 0) {
809 $options['foreignKeys'] = array();
810 foreach ($table->getForeignKeys() AS $fkConstraint) {
811 $options['foreignKeys'][] = $fkConstraint;
812 }
813 }
814
815 return $this->_getCreateTableSQL($tableName, $columns, $options);
816 }
817
824 protected function _getCreateTableSQL($tableName, array $columns, array $options = array())
825 {
826 $columnListSql = $this->getColumnDeclarationListSQL($columns);
827
828 if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
829 foreach ($options['uniqueConstraints'] as $name => $definition) {
830 $columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($name, $definition);
831 }
832 }
833
834 if (isset($options['primary']) && ! empty($options['primary'])) {
835 $columnListSql .= ', PRIMARY KEY(' . implode(', ', array_unique(array_values($options['primary']))) . ')';
836 }
837
838 if (isset($options['indexes']) && ! empty($options['indexes'])) {
839 foreach($options['indexes'] as $index => $definition) {
840 $columnListSql .= ', ' . $this->getIndexDeclarationSQL($index, $definition);
841 }
842 }
843
844 $query = 'CREATE TABLE ' . $tableName . ' (' . $columnListSql;
845
846 $check = $this->getCheckDeclarationSQL($columns);
847 if ( ! empty($check)) {
848 $query .= ', ' . $check;
849 }
850 $query .= ')';
851
852 $sql[] = $query;
853
854 if (isset($options['foreignKeys'])) {
855 foreach ((array) $options['foreignKeys'] AS $definition) {
856 $sql[] = $this->getCreateForeignKeySQL($definition, $tableName);
857 }
858 }
859
860 return $sql;
861 }
862
864 {
865 return "CREATE TEMPORARY TABLE";
866 }
867
874 public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
875 {
876 throw DBALException::notSupported(__METHOD__);
877 }
878
886 public function getCreateConstraintSQL(\Doctrine\DBAL\Schema\Constraint $constraint, $table)
887 {
888 if ($table instanceof \Doctrine\DBAL\Schema\Table) {
889 $table = $table->getQuotedName($this);
890 }
891
892 $query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $constraint->getQuotedName($this);
893
894 $columns = array();
895 foreach ($constraint->getColumns() as $column) {
896 $columns[] = $column;
897 }
898 $columnList = '('. implode(', ', $columns) . ')';
899
900 $referencesClause = '';
901 if ($constraint instanceof \Doctrine\DBAL\Schema\Index) {
902 if($constraint->isPrimary()) {
903 $query .= ' PRIMARY KEY';
904 } elseif ($constraint->isUnique()) {
905 $query .= ' UNIQUE';
906 } else {
907 throw new \InvalidArgumentException(
908 'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().'
909 );
910 }
911 } else if ($constraint instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) {
912 $query .= ' FOREIGN KEY';
913
914 $foreignColumns = array();
915 foreach ($constraint->getForeignColumns() AS $column) {
916 $foreignColumns[] = $column;
917 }
918
919 $referencesClause = ' REFERENCES '.$constraint->getForeignTableName(). ' ('.implode(', ', $foreignColumns).')';
920 }
921 $query .= ' '.$columnList.$referencesClause;
922
923 return $query;
924 }
925
933 public function getCreateIndexSQL(Index $index, $table)
934 {
935 if ($table instanceof Table) {
936 $table = $table->getQuotedName($this);
937 }
938 $name = $index->getQuotedName($this);
939 $columns = $index->getColumns();
940
941 if (count($columns) == 0) {
942 throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
943 }
944
945 $type = '';
946 if ($index->isUnique()) {
947 $type = 'UNIQUE ';
948 }
949
950 $query = 'CREATE ' . $type . 'INDEX ' . $name . ' ON ' . $table;
951
952 $query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')';
953
954 return $query;
955 }
956
968 public function quoteIdentifier($str)
969 {
970 $c = $this->getIdentifierQuoteCharacter();
971
972 return $c . $str . $c;
973 }
974
982 public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
983 {
984 if ($table instanceof \Doctrine\DBAL\Schema\Table) {
985 $table = $table->getQuotedName($this);
986 }
987
988 $query = 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSQL($foreignKey);
989
990 return $query;
991 }
992
1001 public function getAlterTableSQL(TableDiff $diff)
1002 {
1003 throw DBALException::notSupported(__METHOD__);
1004 }
1005
1013 {
1014 if ($diff->newName !== false) {
1015 $tableName = $diff->newName;
1016 } else {
1017 $tableName = $diff->name;
1018 }
1019
1020 $sql = array();
1021 if ($this->supportsForeignKeyConstraints()) {
1022 foreach ($diff->removedForeignKeys AS $foreignKey) {
1023 $sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
1024 }
1025 foreach ($diff->addedForeignKeys AS $foreignKey) {
1026 $sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName);
1027 }
1028 foreach ($diff->changedForeignKeys AS $foreignKey) {
1029 $sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
1030 $sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName);
1031 }
1032 }
1033
1034 foreach ($diff->addedIndexes AS $index) {
1035 $sql[] = $this->getCreateIndexSQL($index, $tableName);
1036 }
1037 foreach ($diff->removedIndexes AS $index) {
1038 $sql[] = $this->getDropIndexSQL($index, $tableName);
1039 }
1040 foreach ($diff->changedIndexes AS $index) {
1041 $sql[] = $this->getDropIndexSQL($index, $tableName);
1042 $sql[] = $this->getCreateIndexSQL($index, $tableName);
1043 }
1044
1045 return $sql;
1046 }
1047
1077 public function getColumnDeclarationListSQL(array $fields)
1078 {
1079 $queryFields = array();
1080 foreach ($fields as $fieldName => $field) {
1081 $query = $this->getColumnDeclarationSQL($fieldName, $field);
1082 $queryFields[] = $query;
1083 }
1084 return implode(', ', $queryFields);
1085 }
1086
1120 public function getColumnDeclarationSQL($name, array $field)
1121 {
1122 if (isset($field['columnDefinition'])) {
1123 $columnDef = $this->getCustomTypeDeclarationSQL($field);
1124 } else {
1125 $default = $this->getDefaultValueDeclarationSQL($field);
1126
1127 $charset = (isset($field['charset']) && $field['charset']) ?
1128 ' ' . $this->getColumnCharsetDeclarationSQL($field['charset']) : '';
1129
1130 $collation = (isset($field['collation']) && $field['collation']) ?
1131 ' ' . $this->getColumnCollationDeclarationSQL($field['collation']) : '';
1132
1133 $notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
1134
1135 $unique = (isset($field['unique']) && $field['unique']) ?
1136 ' ' . $this->getUniqueFieldDeclarationSQL() : '';
1137
1138 $check = (isset($field['check']) && $field['check']) ?
1139 ' ' . $field['check'] : '';
1140
1141 $typeDecl = $field['type']->getSqlDeclaration($field, $this);
1142 $columnDef = $typeDecl . $charset . $default . $notnull . $unique . $check . $collation;
1143 }
1144
1145 return $name . ' ' . $columnDef;
1146 }
1147
1154 public function getDecimalTypeDeclarationSQL(array $columnDef)
1155 {
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'];
1160
1161 return 'NUMERIC(' . $columnDef['precision'] . ', ' . $columnDef['scale'] . ')';
1162 }
1163
1171 public function getDefaultValueDeclarationSQL($field)
1172 {
1173 $default = empty($field['notnull']) ? ' DEFAULT NULL' : '';
1174
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();
1182 }
1183 }
1184 }
1185 return $default;
1186 }
1187
1195 public function getCheckDeclarationSQL(array $definition)
1196 {
1197 $constraints = array();
1198 foreach ($definition as $field => $def) {
1199 if (is_string($def)) {
1200 $constraints[] = 'CHECK (' . $def . ')';
1201 } else {
1202 if (isset($def['min'])) {
1203 $constraints[] = 'CHECK (' . $field . ' >= ' . $def['min'] . ')';
1204 }
1205
1206 if (isset($def['max'])) {
1207 $constraints[] = 'CHECK (' . $field . ' <= ' . $def['max'] . ')';
1208 }
1209 }
1210 }
1211
1212 return implode(', ', $constraints);
1213 }
1214
1224 public function getUniqueConstraintDeclarationSQL($name, Index $index)
1225 {
1226 if (count($index->getColumns()) == 0) {
1227 throw \InvalidArgumentException("Incomplete definition. 'columns' required.");
1228 }
1229
1230 return 'CONSTRAINT ' . $name . ' UNIQUE ('
1231 . $this->getIndexFieldDeclarationListSQL($index->getColumns())
1232 . ')';
1233 }
1234
1243 public function getIndexDeclarationSQL($name, Index $index)
1244 {
1245 $type = '';
1246
1247 if($index->isUnique()) {
1248 $type = 'UNIQUE ';
1249 }
1250
1251 if (count($index->getColumns()) == 0) {
1252 throw \InvalidArgumentException("Incomplete definition. 'columns' required.");
1253 }
1254
1255 return $type . 'INDEX ' . $name . ' ('
1256 . $this->getIndexFieldDeclarationListSQL($index->getColumns())
1257 . ')';
1258 }
1259
1268 public function getCustomTypeDeclarationSQL(array $columnDef)
1269 {
1270 return $columnDef['columnDefinition'];
1271 }
1272
1280 public function getIndexFieldDeclarationListSQL(array $fields)
1281 {
1282 $ret = array();
1283 foreach ($fields as $field => $definition) {
1284 if (is_array($definition)) {
1285 $ret[] = $field;
1286 } else {
1287 $ret[] = $definition;
1288 }
1289 }
1290 return implode(', ', $ret);
1291 }
1292
1307 public function getTemporaryTableSQL()
1308 {
1309 return 'TEMPORARY';
1310 }
1311
1318 public function getTemporaryTableName($tableName)
1319 {
1320 return $tableName;
1321 }
1322
1328 public function getShowDatabasesSQL()
1329 {
1330 throw DBALException::notSupported(__METHOD__);
1331 }
1332
1375 {
1376 $sql = $this->getForeignKeyBaseDeclarationSQL($foreignKey);
1377 $sql .= $this->getAdvancedForeignKeyOptionsSQL($foreignKey);
1378
1379 return $sql;
1380 }
1381
1390 {
1391 $query = '';
1392 if ($this->supportsForeignKeyOnUpdate() && $foreignKey->hasOption('onUpdate')) {
1393 $query .= ' ON UPDATE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onUpdate'));
1394 }
1395 if ($foreignKey->hasOption('onDelete')) {
1396 $query .= ' ON DELETE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onDelete'));
1397 }
1398 return $query;
1399 }
1400
1410 {
1411 $upper = strtoupper($action);
1412 switch ($upper) {
1413 case 'CASCADE':
1414 case 'SET NULL':
1415 case 'NO ACTION':
1416 case 'RESTRICT':
1417 case 'SET DEFAULT':
1418 return $upper;
1419 break;
1420 default:
1421 throw new \InvalidArgumentException('Invalid foreign key action: ' . $upper);
1422 }
1423 }
1424
1433 {
1434 $sql = '';
1435 if (strlen($foreignKey->getName())) {
1436 $sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' ';
1437 }
1438 $sql .= 'FOREIGN KEY (';
1439
1440 if (count($foreignKey->getLocalColumns()) == 0) {
1441 throw new \InvalidArgumentException("Incomplete definition. 'local' required.");
1442 }
1443 if (count($foreignKey->getForeignColumns()) == 0) {
1444 throw new \InvalidArgumentException("Incomplete definition. 'foreign' required.");
1445 }
1446 if (strlen($foreignKey->getForeignTableName()) == 0) {
1447 throw new \InvalidArgumentException("Incomplete definition. 'foreignTable' required.");
1448 }
1449
1450 $sql .= implode(', ', $foreignKey->getLocalColumns())
1451 . ') REFERENCES '
1452 . $foreignKey->getForeignTableName() . '('
1453 . implode(', ', $foreignKey->getForeignColumns()) . ')';
1454
1455 return $sql;
1456 }
1457
1466 {
1467 return 'UNIQUE';
1468 }
1469
1479 {
1480 return '';
1481 }
1482
1491 public function getColumnCollationDeclarationSQL($collation)
1492 {
1493 return '';
1494 }
1495
1502 public function prefersSequences()
1503 {
1504 return false;
1505 }
1506
1513 public function prefersIdentityColumns()
1514 {
1515 return false;
1516 }
1517
1525 public function convertBooleans($item)
1526 {
1527 if (is_array($item)) {
1528 foreach ($item as $k => $value) {
1529 if (is_bool($value)) {
1530 $item[$k] = (int) $value;
1531 }
1532 }
1533 } else if (is_bool($item)) {
1534 $item = (int) $item;
1535 }
1536 return $item;
1537 }
1538
1549 {
1550 return "SET NAMES '".$charset."'";
1551 }
1552
1558 public function getCurrentDateSQL()
1559 {
1560 return 'CURRENT_DATE';
1561 }
1562
1568 public function getCurrentTimeSQL()
1569 {
1570 return 'CURRENT_TIME';
1571 }
1572
1578 public function getCurrentTimestampSQL()
1579 {
1580 return 'CURRENT_TIMESTAMP';
1581 }
1582
1588 protected function _getTransactionIsolationLevelSQL($level)
1589 {
1590 switch ($level) {
1592 return 'READ UNCOMMITTED';
1594 return 'READ COMMITTED';
1596 return 'REPEATABLE READ';
1598 return 'SERIALIZABLE';
1599 default:
1600 throw new \InvalidArgumentException('Invalid isolation level:' . $level);
1601 }
1602 }
1603
1604 public function getListDatabasesSQL()
1605 {
1606 throw DBALException::notSupported(__METHOD__);
1607 }
1608
1609 public function getListSequencesSQL($database)
1610 {
1611 throw DBALException::notSupported(__METHOD__);
1612 }
1613
1614 public function getListTableConstraintsSQL($table)
1615 {
1616 throw DBALException::notSupported(__METHOD__);
1617 }
1618
1619 public function getListTableColumnsSQL($table)
1620 {
1621 throw DBALException::notSupported(__METHOD__);
1622 }
1623
1624 public function getListTablesSQL()
1625 {
1626 throw DBALException::notSupported(__METHOD__);
1627 }
1628
1629 public function getListUsersSQL()
1630 {
1631 throw DBALException::notSupported(__METHOD__);
1632 }
1633
1640 public function getListViewsSQL($database)
1641 {
1642 throw DBALException::notSupported(__METHOD__);
1643 }
1644
1645 public function getListTableIndexesSQL($table)
1646 {
1647 throw DBALException::notSupported(__METHOD__);
1648 }
1649
1650 public function getListTableForeignKeysSQL($table)
1651 {
1652 throw DBALException::notSupported(__METHOD__);
1653 }
1654
1655 public function getCreateViewSQL($name, $sql)
1656 {
1657 throw DBALException::notSupported(__METHOD__);
1658 }
1659
1660 public function getDropViewSQL($name)
1661 {
1662 throw DBALException::notSupported(__METHOD__);
1663 }
1664
1665 public function getDropSequenceSQL($sequence)
1666 {
1667 throw DBALException::notSupported(__METHOD__);
1668 }
1669
1670 public function getSequenceNextValSQL($sequenceName)
1671 {
1672 throw DBALException::notSupported(__METHOD__);
1673 }
1674
1675 public function getCreateDatabaseSQL($database)
1676 {
1677 throw DBALException::notSupported(__METHOD__);
1678 }
1679
1685 public function getSetTransactionIsolationSQL($level)
1686 {
1687 throw DBALException::notSupported(__METHOD__);
1688 }
1689
1697 public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
1698 {
1699 throw DBALException::notSupported(__METHOD__);
1700 }
1701
1707 public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration)
1708 {
1709 return $this->getDateTimeTypeDeclarationSQL($fieldDeclaration);
1710 }
1711
1712
1720 public function getDateTypeDeclarationSQL(array $fieldDeclaration)
1721 {
1722 throw DBALException::notSupported(__METHOD__);
1723 }
1724
1732 public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
1733 {
1734 throw DBALException::notSupported(__METHOD__);
1735 }
1736
1737 public function getFloatDeclarationSQL(array $fieldDeclaration)
1738 {
1739 return 'DOUBLE PRECISION';
1740 }
1741
1752
1753 /* supports*() metods */
1754
1760 public function supportsSequences()
1761 {
1762 return false;
1763 }
1764
1772 public function supportsIdentityColumns()
1773 {
1774 return false;
1775 }
1776
1782 public function supportsIndexes()
1783 {
1784 return true;
1785 }
1786
1787 public function supportsAlterTable()
1788 {
1789 return true;
1790 }
1791
1797 public function supportsTransactions()
1798 {
1799 return true;
1800 }
1801
1807 public function supportsSavepoints()
1808 {
1809 return true;
1810 }
1811
1818 {
1819 return $this->supportsSavepoints();
1820 }
1821
1828 {
1829 return true;
1830 }
1831
1838 {
1839 return true;
1840 }
1841
1848 {
1849 return ($this->supportsForeignKeyConstraints() && true);
1850 }
1851
1857 public function supportsSchemas()
1858 {
1859 return false;
1860 }
1861
1868 {
1869 return true;
1870 }
1871
1879 {
1880 return true;
1881 }
1882
1884 {
1885 return "";
1886 }
1887
1894 public function getDateTimeFormatString()
1895 {
1896 return 'Y-m-d H:i:s';
1897 }
1898
1906 {
1907 return 'Y-m-d H:i:s';
1908 }
1909
1916 public function getDateFormatString()
1917 {
1918 return 'Y-m-d';
1919 }
1920
1927 public function getTimeFormatString()
1928 {
1929 return 'H:i:s';
1930 }
1931
1932 public function modifyLimitQuery($query, $limit, $offset = null)
1933 {
1934 if ( ! is_null($limit)) {
1935 $query .= ' LIMIT ' . $limit;
1936 }
1937
1938 if ( ! is_null($offset)) {
1939 $query .= ' OFFSET ' . $offset;
1940 }
1941
1942 return $query;
1943 }
1944
1951 public function getSQLResultCasing($column)
1952 {
1953 return $column;
1954 }
1955
1963 public function fixSchemaElementName($schemaElementName)
1964 {
1965 return $schemaElementName;
1966 }
1967
1973 public function getMaxIdentifierLength()
1974 {
1975 return 63;
1976 }
1977
1985 public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName)
1986 {
1987 return 'INSERT INTO ' . $tableName . ' (' . $identifierColumnName . ') VALUES (null)';
1988 }
1989
2000 public function getTruncateTableSQL($tableName, $cascade = false)
2001 {
2002 return 'TRUNCATE '.$tableName;
2003 }
2004
2010 public function getDummySelectSQL()
2011 {
2012 return 'SELECT 1';
2013 }
2014
2021 public function createSavePoint($savepoint)
2022 {
2023 return 'SAVEPOINT ' . $savepoint;
2024 }
2025
2032 public function releaseSavePoint($savepoint)
2033 {
2034 return 'RELEASE SAVEPOINT ' . $savepoint;
2035 }
2036
2043 public function rollbackSavePoint($savepoint)
2044 {
2045 return 'ROLLBACK TO SAVEPOINT ' . $savepoint;
2046 }
2047}
static notSupported($method)
static noColumnsSpecifiedForTable($tableName)
getTimeTypeDeclarationSQL(array $fieldDeclaration)
modifyLimitQuery($query, $limit, $offset=null)
getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey)
getLocateExpression($str, $substr, $startPos=false)
getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey)
getUniqueConstraintDeclarationSQL($name, Index $index)
getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
_getCommonIntegerTypeDeclarationSQL(array $columnDef)
getBooleanTypeDeclarationSQL(array $columnDef)
getTrimExpression($str, $pos=self::TRIM_UNSPECIFIED, $char=false)
getModExpression($expression1, $expression2)
getSmallIntTypeDeclarationSQL(array $columnDef)
getEmptyIdentityInsertSQL($tableName, $identifierColumnName)
getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey)
getIntegerTypeDeclarationSQL(array $columnDef)
getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXES)
getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration)
getDateTypeDeclarationSQL(array $fieldDeclaration)
getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
getTruncateTableSQL($tableName, $cascade=false)
getSubstringExpression($value, $from, $len=null)
_getCreateTableSQL($tableName, array $columns, array $options=array())
getFloatDeclarationSQL(array $fieldDeclaration)
getBetweenExpression($expression, $value1, $value2)
getCreateConstraintSQL(\Doctrine\DBAL\Schema\Constraint $constraint, $table)
registerDoctrineTypeMapping($dbType, $doctrineType)
getQuotedName(AbstractPlatform $platform)
static hasType($name)
Definição Type.php:173
$action
Definição base.php:4
$charset
Definição base.php:7