80 if ($startPos ==
false) {
81 return 'LOCATE(' . $substr .
', ' . $str .
')';
83 return 'LOCATE(' . $substr .
', ' . $str .
', '.$startPos.
')';
98 $args = func_get_args();
99 return 'CONCAT(' . join(
', ', (array) $args) .
')';
104 return 'SHOW DATABASES';
109 return 'SHOW INDEX FROM ' . $table;
114 return 'SHOW INDEX FROM ' . $table;
119 return "SELECT * FROM information_schema.VIEWS WHERE TABLE_SCHEMA = '".$database.
"'";
124 $sql =
"SELECT DISTINCT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`, ".
125 "k.`REFERENCED_COLUMN_NAME` /*!50116 , c.update_rule, c.delete_rule */ ".
126 "FROM information_schema.key_column_usage k /*!50116 ".
127 "INNER JOIN information_schema.referential_constraints c ON ".
128 " c.constraint_name = k.constraint_name AND ".
129 " c.table_name = '$table' */ WHERE k.table_name = '$table'";
132 $sql .=
" AND k.table_schema = '$database' /*!50116 AND c.constraint_schema = '$database' */";
135 $sql .=
" AND k.`REFERENCED_COLUMN_NAME` is not NULL";
142 return 'CREATE VIEW ' . $name .
' AS ' . $sql;
147 return 'DROP VIEW '. $name;
157 if ( ! isset($field[
'length'])) {
158 if (array_key_exists(
'default', $field)) {
161 $field[
'length'] =
false;
166 $fixed = (isset($field[
'fixed'])) ? $field[
'fixed'] :
false;
168 return $fixed ? ($length ?
'CHAR(' . $length .
')' :
'CHAR(255)')
169 : ($length ?
'VARCHAR(' . $length .
')' :
'VARCHAR(255)');
175 if ( ! empty($field[
'length']) && is_numeric($field[
'length'])) {
176 $length = $field[
'length'];
177 if ($length <= 255) {
179 }
else if ($length <= 65532) {
181 }
else if ($length <= 16777215) {
193 if (isset($fieldDeclaration[
'version']) && $fieldDeclaration[
'version'] ==
true) {
234 return 'COLLATE ' . $collation;
264 return 'SHOW DATABASES';
269 return 'SHOW FULL TABLES WHERE Table_type = "BASE TABLE"';
274 return 'DESCRIBE ' . $table;
286 return 'CREATE DATABASE ' . $name;
298 return 'DROP DATABASE ' . $name;
340 if (isset($options[
'uniqueConstraints']) && ! empty($options[
'uniqueConstraints'])) {
341 foreach ($options[
'uniqueConstraints'] as $index => $definition) {
347 if (isset($options[
'indexes']) && ! empty($options[
'indexes'])) {
348 foreach($options[
'indexes'] as $index => $definition) {
354 if (isset($options[
'primary']) && ! empty($options[
'primary'])) {
355 $keyColumns = array_unique(array_values($options[
'primary']));
356 $queryFields .=
', PRIMARY KEY(' . implode(
', ', $keyColumns) .
')';
360 if (!empty($options[
'temporary'])) {
361 $query .=
'TEMPORARY ';
363 $query.=
'TABLE ' . $tableName .
' (' . $queryFields .
')';
365 $optionStrings = array();
367 if (isset($options[
'comment'])) {
368 $optionStrings[
'comment'] =
'COMMENT = ' . $this->quote($options[
'comment'],
'text');
370 if (isset($options[
'charset'])) {
371 $optionStrings[
'charset'] =
'DEFAULT CHARACTER SET ' . $options[
'charset'];
372 if (isset($options[
'collate'])) {
373 $optionStrings[
'charset'] .=
' COLLATE ' . $options[
'collate'];
378 if (isset($options[
'engine'])) {
379 $optionStrings[] =
'ENGINE = ' . $options[
'engine'];
382 $optionStrings[] =
'ENGINE = InnoDB';
385 if ( ! empty($optionStrings)) {
386 $query.=
' '.implode(
' ', $optionStrings);
390 if (isset($options[
'foreignKeys'])) {
391 foreach ((array) $options[
'foreignKeys'] as $definition) {
407 $queryParts = array();
408 if ($diff->newName !==
false) {
409 $queryParts[] =
'RENAME TO ' . $diff->newName;
412 foreach ($diff->addedColumns AS $fieldName => $column) {
416 foreach ($diff->removedColumns AS $column) {
417 $queryParts[] =
'DROP ' . $column->getQuotedName($this);
420 foreach ($diff->changedColumns AS $columnDiff) {
422 $column = $columnDiff->column;
423 $queryParts[] =
'CHANGE ' . ($columnDiff->oldColumnName) .
' '
427 foreach ($diff->renamedColumns AS $oldColumnName => $column) {
428 $queryParts[] =
'CHANGE ' . $oldColumnName .
' '
433 if (count($queryParts) > 0) {
434 $sql[] =
'ALTER TABLE ' . $diff->name .
' ' . implode(
", ", $queryParts);
487 if ( ! empty($columnDef[
'autoincrement'])) {
488 $autoinc =
' AUTO_INCREMENT';
490 $unsigned = (isset($columnDef[
'unsigned']) && $columnDef[
'unsigned']) ?
' UNSIGNED' :
'';
492 return $unsigned . $autoinc;
506 if ($foreignKey->hasOption(
'match')) {
507 $query .=
' MATCH ' . $foreignKey->getOption(
'match');
509 $query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey);
522 if($index instanceof \Doctrine\DBAL\Schema\
Index) {
523 $index = $index->getQuotedName($this);
524 }
else if(!is_string($index)) {
525 throw new \InvalidArgumentException(
'MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
528 if($table instanceof \Doctrine\DBAL\Schema\
Table) {
529 $table = $table->getQuotedName($this);
530 }
else if(!is_string($table)) {
531 throw new \InvalidArgumentException(
'MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
534 return 'DROP INDEX ' . $index .
' ON ' . $table;
545 if ($table instanceof \Doctrine\DBAL\Schema\
Table) {
546 $table = $table->getQuotedName($this);
547 }
else if(!is_string($table)) {
548 throw new \InvalidArgumentException(
'MysqlPlatform::getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
551 return 'DROP TABLE ' . $table;
571 return 'LOCK IN SHARE MODE';
576 $this->doctrineTypeMapping = array(
577 'tinyint' =>
'boolean',
578 'smallint' =>
'smallint',
579 'mediumint' =>
'integer',
581 'integer' =>
'integer',
582 'bigint' =>
'bigint',
583 'tinytext' =>
'text',
584 'mediumtext' =>
'text',
585 'longtext' =>
'text',
587 'varchar' =>
'string',
588 'string' =>
'string',
591 'datetime' =>
'datetime',
592 'timestamp' =>
'datetime',
597 'decimal' =>
'decimal',
598 'numeric' =>
'decimal',