Source for file Mysql.php
Documentation is available at Mysql.php
* $Id: Mysql.php 1730 2007-06-18 18:27:11Z zYne $
* 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
* <http://www.phpdoctrine.com>.
* @subpackage Doctrine_DataDict
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision: 1730 $
* @category Object Relational Mapping
* @link www.phpdoctrine.com
'ASC', 'ASENSITIVE', 'BEFORE',
'BETWEEN', 'BIGINT', 'BINARY',
'CALL', 'CASCADE', 'CASE',
'CHANGE', 'CHAR', 'CHARACTER',
'CHECK', 'COLLATE', 'COLUMN',
'CONDITION', 'CONNECTION', 'CONSTRAINT',
'CONTINUE', 'CONVERT', 'CREATE',
'CROSS', 'CURRENT_DATE', 'CURRENT_TIME',
'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURSOR',
'DATABASE', 'DATABASES', 'DAY_HOUR',
'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND',
'DEC', 'DECIMAL', 'DECLARE',
'DEFAULT', 'DELAYED', 'DELETE',
'DESC', 'DESCRIBE', 'DETERMINISTIC',
'DISTINCT', 'DISTINCTROW', 'DIV',
'DOUBLE', 'DROP', 'DUAL',
'EACH', 'ELSE', 'ELSEIF',
'ENCLOSED', 'ESCAPED', 'EXISTS',
'EXIT', 'EXPLAIN', 'FALSE',
'FETCH', 'FLOAT', 'FLOAT4',
'FLOAT8', 'FOR', 'FORCE',
'FOREIGN', 'FROM', 'FULLTEXT',
'GRANT', 'GROUP', 'HAVING',
'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE',
'HOUR_SECOND', 'IF', 'IGNORE',
'INNER', 'INOUT', 'INSENSITIVE',
'INT8', 'INTEGER', 'INTERVAL',
'KILL', 'LEADING', 'LEAVE',
'LINES', 'LOAD', 'LOCALTIME',
'LOCALTIMESTAMP', 'LOCK', 'LONG',
'LONGBLOB', 'LONGTEXT', 'LOOP',
'LOW_PRIORITY', 'MATCH', 'MEDIUMBLOB',
'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT',
'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MOD',
'MODIFIES', 'NATURAL', 'NOT',
'NO_WRITE_TO_BINLOG', 'NULL', 'NUMERIC',
'ON', 'OPTIMIZE', 'OPTION',
'OPTIONALLY', 'OR', 'ORDER',
'OUT', 'OUTER', 'OUTFILE',
'PRECISION', 'PRIMARY', 'PROCEDURE',
'PURGE', 'RAID0', 'READ',
'READS', 'REAL', 'REFERENCES',
'REGEXP', 'RELEASE', 'RENAME',
'REPEAT', 'REPLACE', 'REQUIRE',
'RESTRICT', 'RETURN', 'REVOKE',
'RIGHT', 'RLIKE', 'SCHEMA',
'SCHEMAS', 'SECOND_MICROSECOND', 'SELECT',
'SENSITIVE', 'SEPARATOR', 'SET',
'SHOW', 'SMALLINT', 'SONAME',
'SPATIAL', 'SPECIFIC', 'SQL',
'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING',
'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT',
'SSL', 'STARTING', 'STRAIGHT_JOIN',
'TABLE', 'TERMINATED', 'THEN',
'TINYBLOB', 'TINYINT', 'TINYTEXT',
'TO', 'TRAILING', 'TRIGGER',
'UNIQUE', 'UNLOCK', 'UNSIGNED',
'UPDATE', 'USAGE', 'USE',
'USING', 'UTC_DATE', 'UTC_TIME',
'UTC_TIMESTAMP', 'VALUES', 'VARBINARY',
'VARCHAR', 'VARCHARACTER', 'VARYING',
'WHEN', 'WHERE', 'WHILE',
'XOR', 'YEAR_MONTH', 'ZEROFILL'
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
* @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:
* 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.
* Text value to be used as default for this field.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
if ( ! isset
($field['type'])) {
switch ($field['type']) {
$length =
(! empty($field['length'])) ?
$field['length'] :
false;
return $length ?
'CHAR('.
$length.
')' :
'CHAR(255)';
if ( ! isset
($field['length'])) {
$field['length'] =
$this->conn->varchar_max_length;
$field['length'] =
false;
$length =
($field['length'] <=
$this->conn->varchar_max_length) ?
$field['length'] :
false;
$fixed =
(isset
($field['fixed'])) ?
$field['fixed'] :
false;
return $fixed ?
($length ?
'CHAR(' .
$length .
')' :
'CHAR(255)')
:
($length ?
'VARCHAR(' .
$length .
')' :
'TEXT');
if (!empty($field['length'])) {
$length =
$field['length'];
} elseif ($length <=
65532) {
} elseif ($length <=
16777215) {
if (!empty($field['length'])) {
$length =
$field['length'];
} elseif ($length <=
65532) {
} elseif ($length <=
16777215) {
if (!empty($field['length'])) {
$length =
$field['length'];
} elseif ($length ==
2) {
} elseif ($length ==
3) {
} elseif ($length ==
4) {
$length =
!empty($field['length']) ?
$field['length'] :
18;
$scale =
!empty($field['scale']) ?
$field['scale'] :
$this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.
$length.
','.
$scale.
')';
* Maps a native array description of a field to a MDB2 datatype and length
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
$dbType =
strtolower($field['type']);
$dbType =
strtok($dbType, '(), ');
if ($dbType ==
'national') {
$dbType =
strtok('(), ');
if (isset
($field['length'])) {
$length =
$field['length'];
$unsigned =
$fixed =
null;
if ( ! isset
($field['name'])) {
$unsigned =
preg_match('/ unsigned/i', $field['type']);
$unsigned =
preg_match('/ unsigned/i', $field['type']);
$unsigned =
preg_match('/ unsigned/i', $field['type']);
$unsigned =
preg_match('/ unsigned/i', $field['type']);
$unsigned =
preg_match('/ unsigned/i', $field['type']);
} elseif (strstr($dbType, 'text')) {
if ($decimal ==
'binary') {
foreach ($matches[0] as $value) {
if ($length ==
'1' &&
count($matches[0]) ==
2) {
$unsigned =
preg_match('/ unsigned/i', $field['type']);
$unsigned =
preg_match('/ unsigned/i', $field['type']);
$length =
((int)
$length ==
0) ?
null : (int)
$length;
return array('type' =>
$type, 'length' =>
$length, 'unsigned' =>
$unsigned, 'fixed' =>
$fixed);
return array('type' =>
$type, 'length' =>
$length, 'unsigned' =>
$unsigned, 'fixed' =>
$fixed, 'values' =>
$values);
* 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.
return 'CHARACTER SET ' .
$charset;
* 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.
return 'COLLATE ' .
$collation;
* Obtain DBMS specific SQL code portion needed to declare an integer type
* field to be used in statements like CREATE TABLE.
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes.
* Currently, the types of supported field
* properties are as follows:
* Boolean flag that indicates whether the field
* should be declared as unsigned integer if
* Integer value to be used as default for this
* Boolean flag that indicates whether this field is
* constrained to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
$default =
$autoinc =
'';
if (!empty($field['autoincrement'])) {
$autoinc =
' AUTO_INCREMENT';
if ($field['default'] ===
'') {
$field['default'] =
empty($field['notnull']) ?
null :
0;
$default =
' DEFAULT '.
$this->conn->quote($field['default']);
elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL';
$notnull =
(isset
($field['notnull']) &&
$field['notnull']) ?
' NOT NULL' :
'';
$unsigned =
(isset
($field['unsigned']) &&
$field['unsigned']) ?
' UNSIGNED' :
'';
$name =
$this->conn->quoteIdentifier($name, true);
return $name .
' ' .
$this->getNativeDeclaration($field) .
$unsigned .
$default .
$notnull .
$autoinc;