1
0
mirror of synced 2025-02-08 00:09:26 +03:00

- CS fixes

This commit is contained in:
lsmith 2007-01-02 15:24:43 +00:00
parent 9f6a652a62
commit dcdc049588
8 changed files with 2662 additions and 2658 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,204 +1,205 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
Doctrine::autoload('Doctrine_DataDict'); Doctrine::autoload('Doctrine_DataDict');
/** /**
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver) * @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$ * @version $Revision$
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_DataDict_Firebird extends Doctrine_DataDict class Doctrine_DataDict_Firebird extends Doctrine_DataDict
{ {
/** /**
* Obtain DBMS specific SQL code portion needed to declare an text type * Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
* *
* @param array $field associative array with the name of the properties * @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types * of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows: * of supported field properties are as follows:
* *
* length * length
* Integer value that determines the maximum length of the text * Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be * field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS. * declared to have the longest length allowed by the DBMS.
* *
* default * default
* Text value to be used as default for this field. * Text value to be used as default for this field.
* *
* notnull * notnull
* Boolean flag that indicates whether this field is constrained * Boolean flag that indicates whether this field is constrained
* to not be set to null. * to not be set to null.
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration($field) public function getNativeDeclaration($field)
{ {
switch ($field['type']) { switch ($field['type']) {
case 'varchar': case 'varchar':
case 'string': case 'string':
case 'array': case 'array':
case 'object': case 'object':
case 'char': case 'char':
case 'text': case 'text':
$length = !empty($field['length']) $length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length']; ? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false; $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR('.$length.')'; return $fixed ? 'CHAR('.$length.')' : 'VARCHAR('.$length.')';
case 'clob': case 'clob':
return 'BLOB SUB_TYPE 1'; return 'BLOB SUB_TYPE 1';
case 'blob': case 'blob':
return 'BLOB SUB_TYPE 0'; return 'BLOB SUB_TYPE 0';
case 'integer': case 'integer':
case 'enum': case 'enum':
return 'INT'; return 'INT';
case 'boolean': case 'boolean':
return 'SMALLINT'; return 'SMALLINT';
case 'date': case 'date':
return 'DATE'; return 'DATE';
case 'time': case 'time':
return 'TIME'; return 'TIME';
case 'timestamp': case 'timestamp':
return 'TIMESTAMP'; return 'TIMESTAMP';
case 'float': case 'float':
return 'DOUBLE PRECISION'; return 'DOUBLE PRECISION';
case 'decimal': case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18; $length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')'; return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
} }
return ''; return '';
} }
/** /**
* Maps a native array description of a field to a Doctrine datatype and length * Maps a native array description of a field to a Doctrine datatype and length
* *
* @param array $field native field description * @param array $field native field description
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
*/ */
public function getPortableDeclaration($field) public function getPortableDeclaration($field)
{ {
$length = (isset($field['length']) && $field['length'] > 0) ? $field['length'] : null; $length = (isset($field['length']) && $field['length'] > 0) ? $field['length'] : null;
$type = array(); $type = array();
$unsigned = $fixed = null; $unsigned = $fixed = null;
$dbType = strtolower($field['type']); $dbType = strtolower($field['type']);
$field['field_sub_type'] = !empty($field['field_sub_type']) $field['field_sub_type'] = !empty($field['field_sub_type'])
? strtolower($field['field_sub_type']) : null; ? strtolower($field['field_sub_type']) : null;
if( ! isset($field['name'])) if ( ! isset($field['name'])) {
$field['name'] = ''; $field['name'] = '';
}
switch ($dbType) {
case 'smallint': switch ($dbType) {
case 'integer': case 'smallint':
case 'int64': case 'integer':
//these may be 'numeric' or 'decimal' case 'int64':
if (isset($field['field_sub_type'])) { //these may be 'numeric' or 'decimal'
$field['type'] = $field['field_sub_type']; if (isset($field['field_sub_type'])) {
return $this->getPortableDeclaration($field); $field['type'] = $field['field_sub_type'];
} return $this->getPortableDeclaration($field);
case 'bigint': }
case 'quad': case 'bigint':
$type[] = 'integer'; case 'quad':
if ($length == '1') { $type[] = 'integer';
$type[] = 'boolean'; if ($length == '1') {
if (preg_match('/^(is|has)/', $field['name'])) { $type[] = 'boolean';
$type = array_reverse($type); if (preg_match('/^(is|has)/', $field['name'])) {
} $type = array_reverse($type);
} }
break; }
case 'varchar': break;
$fixed = false; case 'varchar':
case 'char': $fixed = false;
case 'cstring': case 'char':
$type[] = 'string'; case 'cstring':
if ($length == '1') { $type[] = 'string';
$type[] = 'boolean'; if ($length == '1') {
if (preg_match('/^(is|has)/', $field['name'])) { $type[] = 'boolean';
$type = array_reverse($type); if (preg_match('/^(is|has)/', $field['name'])) {
} $type = array_reverse($type);
} }
if ($fixed !== false) { }
$fixed = true; if ($fixed !== false) {
} $fixed = true;
break; }
case 'date': break;
$type[] = 'date'; case 'date':
$length = null; $type[] = 'date';
break; $length = null;
case 'timestamp': break;
$type[] = 'timestamp'; case 'timestamp':
$length = null; $type[] = 'timestamp';
break; $length = null;
case 'time': break;
$type[] = 'time'; case 'time':
$length = null; $type[] = 'time';
break; $length = null;
case 'float': break;
case 'double': case 'float':
case 'double precision': case 'double':
case 'd_float': case 'double precision':
$type[] = 'float'; case 'd_float':
break; $type[] = 'float';
case 'decimal': break;
case 'numeric': case 'decimal':
$type[] = 'decimal'; case 'numeric':
break; $type[] = 'decimal';
case 'blob': break;
$type[] = ($field['field_sub_type'] == 'text') ? 'clob' : 'blob'; case 'blob':
$length = null; $type[] = ($field['field_sub_type'] == 'text') ? 'clob' : 'blob';
break; $length = null;
default: break;
throw new Doctrine_DataDict_Firebird_Exception('unknown database attribute type: '.$dbType); default:
} throw new Doctrine_DataDict_Firebird_Exception('unknown database attribute type: '.$dbType);
}
return array($type, $length, $unsigned, $fixed);
} return array($type, $length, $unsigned, $fixed);
/** }
* Obtain DBMS specific SQL code portion needed to set the CHARACTER SET /**
* of a field declaration to be used in statements like CREATE TABLE. * 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 * @param string $charset name of the charset
* of a field declaration. * @return string DBMS specific SQL code portion needed to set the CHARACTER SET
*/ * of a field declaration.
public function getCharsetFieldDeclaration($charset) */
{ public function getCharsetFieldDeclaration($charset)
return 'CHARACTER SET '.$charset; {
} 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. * 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 * @param string $collation name of the collation
* of a field declaration. * @return string DBMS specific SQL code portion needed to set the COLLATION
*/ * of a field declaration.
public function getCollationFieldDeclaration($collation) */
{ public function getCollationFieldDeclaration($collation)
return 'COLLATE '.$collation; {
} return 'COLLATE '.$collation;
} }
}

View File

@ -1,180 +1,180 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
Doctrine::autoload('Doctrine_DataDict'); Doctrine::autoload('Doctrine_DataDict');
/** /**
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @author Frank M. Kromann <frank@kromann.info> (PEAR MDB2 Mssql driver) * @author Frank M. Kromann <frank@kromann.info> (PEAR MDB2 Mssql driver)
* @author David Coallier <davidc@php.net> (PEAR MDB2 Mssql driver) * @author David Coallier <davidc@php.net> (PEAR MDB2 Mssql driver)
* @version $Revision$ * @version $Revision$
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_DataDict_Mssql extends Doctrine_DataDict class Doctrine_DataDict_Mssql extends Doctrine_DataDict
{ {
/** /**
* Obtain DBMS specific SQL code portion needed to declare an text type * Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
* *
* @param array $field associative array with the name of the properties * @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types * of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows: * of supported field properties are as follows:
* *
* length * length
* Integer value that determines the maximum length of the text * Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be * field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS. * declared to have the longest length allowed by the DBMS.
* *
* default * default
* Text value to be used as default for this field. * Text value to be used as default for this field.
* *
* notnull * notnull
* Boolean flag that indicates whether this field is constrained * Boolean flag that indicates whether this field is constrained
* to not be set to null. * to not be set to null.
* *
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration($field) public function getNativeDeclaration($field)
{ {
switch ($field['type']) { switch ($field['type']) {
case 'array': case 'array':
case 'object': case 'object':
case 'text': case 'text':
case 'char': case 'char':
case 'varchar': case 'varchar':
case 'string': case 'string':
$length = !empty($field['length']) $length = !empty($field['length'])
? $field['length'] : false; ? $field['length'] : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false; $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')') return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT'); : ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob': case 'clob':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 8000) { if ($length <= 8000) {
return 'VARCHAR('.$length.')'; return 'VARCHAR('.$length.')';
} }
} }
return 'TEXT'; return 'TEXT';
case 'blob': case 'blob':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 8000) { if ($length <= 8000) {
return "VARBINARY($length)"; return "VARBINARY($length)";
} }
} }
return 'IMAGE'; return 'IMAGE';
case 'integer': case 'integer':
case 'enum': case 'enum':
return 'INT'; return 'INT';
case 'boolean': case 'boolean':
return 'BIT'; return 'BIT';
case 'date': case 'date':
return 'CHAR(' . strlen('YYYY-MM-DD') . ')'; return 'CHAR(' . strlen('YYYY-MM-DD') . ')';
case 'time': case 'time':
return 'CHAR(' . strlen('HH:MM:SS') . ')'; return 'CHAR(' . strlen('HH:MM:SS') . ')';
case 'timestamp': case 'timestamp':
return 'CHAR(' . strlen('YYYY-MM-DD HH:MM:SS') . ')'; return 'CHAR(' . strlen('YYYY-MM-DD HH:MM:SS') . ')';
case 'float': case 'float':
return 'FLOAT'; return 'FLOAT';
case 'decimal': case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18; $length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')'; return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
} }
return ''; return '';
} }
/** /**
* Maps a native array description of a field to a MDB2 datatype and length * Maps a native array description of a field to a MDB2 datatype and length
* *
* @param array $field native field description * @param array $field native field description
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
*/ */
public function getPortableDeclaration($field) public function getPortableDeclaration($field)
{ {
$db_type = preg_replace('/\d/','', strtolower($field['type']) ); $db_type = preg_replace('/\d/','', strtolower($field['type']) );
$length = (isset($field['length']) && $field['length'] > 0) ? $field['length'] : null; $length = (isset($field['length']) && $field['length'] > 0) ? $field['length'] : null;
$type = array(); $type = array();
// todo: unsigned handling seems to be missing // todo: unsigned handling seems to be missing
$unsigned = $fixed = null; $unsigned = $fixed = null;
if( ! isset($field['name'])) if ( ! isset($field['name']))
$field['name'] = ''; $field['name'] = '';
switch ($db_type) { switch ($db_type) {
case 'bit': case 'bit':
$type[0] = 'boolean'; $type[0] = 'boolean';
break; break;
case 'int': case 'int':
$type[0] = 'integer'; $type[0] = 'integer';
if($length == 1) { if ($length == 1) {
$type[] = 'boolean'; $type[] = 'boolean';
} }
break; break;
case 'datetime': case 'datetime':
$type[0] = 'timestamp'; $type[0] = 'timestamp';
break; break;
case 'float': case 'float':
case 'real': case 'real':
case 'numeric': case 'numeric':
$type[0] = 'float'; $type[0] = 'float';
break; break;
case 'decimal': case 'decimal':
case 'money': case 'money':
$type[0] = 'decimal'; $type[0] = 'decimal';
break; break;
case 'text': case 'text':
case 'varchar': case 'varchar':
$fixed = false; $fixed = false;
case 'char': case 'char':
$type[0] = 'string'; $type[0] = 'string';
if ($length == '1') { if ($length == '1') {
$type[] = 'boolean'; $type[] = 'boolean';
if (preg_match('/^[is|has]/', $field['name'])) { if (preg_match('/^[is|has]/', $field['name'])) {
$type = array_reverse($type); $type = array_reverse($type);
} }
} elseif (strstr($db_type, 'text')) { } elseif (strstr($db_type, 'text')) {
$type[] = 'clob'; $type[] = 'clob';
} }
if ($fixed !== false) { if ($fixed !== false) {
$fixed = true; $fixed = true;
} }
break; break;
case 'image': case 'image':
case 'varbinary': case 'varbinary':
$type[] = 'blob'; $type[] = 'blob';
$length = null; $length = null;
break; break;
default: default:
throw new Doctrine_DataDict_Mssql_Exception('unknown database attribute type: '.$db_type); throw new Doctrine_DataDict_Mssql_Exception('unknown database attribute type: '.$db_type);
} }
return array($type, $length, $unsigned, $fixed); return array($type, $length, $unsigned, $fixed);
} }
} }

View File

@ -1,439 +1,440 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
Doctrine::autoload('Doctrine_DataDict'); Doctrine::autoload('Doctrine_DataDict');
/** /**
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$ * @version $Revision$
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_DataDict_Mysql extends Doctrine_DataDict class Doctrine_DataDict_Mysql extends Doctrine_DataDict
{ {
protected $keywords = array( protected $keywords = array(
'ADD', 'ALL', 'ALTER', 'ADD', 'ALL', 'ALTER',
'ANALYZE', 'AND', 'AS', 'ANALYZE', 'AND', 'AS',
'ASC', 'ASENSITIVE', 'BEFORE', 'ASC', 'ASENSITIVE', 'BEFORE',
'BETWEEN', 'BIGINT', 'BINARY', 'BETWEEN', 'BIGINT', 'BINARY',
'BLOB', 'BOTH', 'BY', 'BLOB', 'BOTH', 'BY',
'CALL', 'CASCADE', 'CASE', 'CALL', 'CASCADE', 'CASE',
'CHANGE', 'CHAR', 'CHARACTER', 'CHANGE', 'CHAR', 'CHARACTER',
'CHECK', 'COLLATE', 'COLUMN', 'CHECK', 'COLLATE', 'COLUMN',
'CONDITION', 'CONNECTION', 'CONSTRAINT', 'CONDITION', 'CONNECTION', 'CONSTRAINT',
'CONTINUE', 'CONVERT', 'CREATE', 'CONTINUE', 'CONVERT', 'CREATE',
'CROSS', 'CURRENT_DATE', 'CURRENT_TIME', 'CROSS', 'CURRENT_DATE', 'CURRENT_TIME',
'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURSOR', 'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURSOR',
'DATABASE', 'DATABASES', 'DAY_HOUR', 'DATABASE', 'DATABASES', 'DAY_HOUR',
'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND',
'DEC', 'DECIMAL', 'DECLARE', 'DEC', 'DECIMAL', 'DECLARE',
'DEFAULT', 'DELAYED', 'DELETE', 'DEFAULT', 'DELAYED', 'DELETE',
'DESC', 'DESCRIBE', 'DETERMINISTIC', 'DESC', 'DESCRIBE', 'DETERMINISTIC',
'DISTINCT', 'DISTINCTROW', 'DIV', 'DISTINCT', 'DISTINCTROW', 'DIV',
'DOUBLE', 'DROP', 'DUAL', 'DOUBLE', 'DROP', 'DUAL',
'EACH', 'ELSE', 'ELSEIF', 'EACH', 'ELSE', 'ELSEIF',
'ENCLOSED', 'ESCAPED', 'EXISTS', 'ENCLOSED', 'ESCAPED', 'EXISTS',
'EXIT', 'EXPLAIN', 'FALSE', 'EXIT', 'EXPLAIN', 'FALSE',
'FETCH', 'FLOAT', 'FLOAT4', 'FETCH', 'FLOAT', 'FLOAT4',
'FLOAT8', 'FOR', 'FORCE', 'FLOAT8', 'FOR', 'FORCE',
'FOREIGN', 'FROM', 'FULLTEXT', 'FOREIGN', 'FROM', 'FULLTEXT',
'GRANT', 'GROUP', 'HAVING', 'GRANT', 'GROUP', 'HAVING',
'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE',
'HOUR_SECOND', 'IF', 'IGNORE', 'HOUR_SECOND', 'IF', 'IGNORE',
'IN', 'INDEX', 'INFILE', 'IN', 'INDEX', 'INFILE',
'INNER', 'INOUT', 'INSENSITIVE', 'INNER', 'INOUT', 'INSENSITIVE',
'INSERT', 'INT', 'INT1', 'INSERT', 'INT', 'INT1',
'INT2', 'INT3', 'INT4', 'INT2', 'INT3', 'INT4',
'INT8', 'INTEGER', 'INTERVAL', 'INT8', 'INTEGER', 'INTERVAL',
'INTO', 'IS', 'ITERATE', 'INTO', 'IS', 'ITERATE',
'JOIN', 'KEY', 'KEYS', 'JOIN', 'KEY', 'KEYS',
'KILL', 'LEADING', 'LEAVE', 'KILL', 'LEADING', 'LEAVE',
'LEFT', 'LIKE', 'LIMIT', 'LEFT', 'LIKE', 'LIMIT',
'LINES', 'LOAD', 'LOCALTIME', 'LINES', 'LOAD', 'LOCALTIME',
'LOCALTIMESTAMP', 'LOCK', 'LONG', 'LOCALTIMESTAMP', 'LOCK', 'LONG',
'LONGBLOB', 'LONGTEXT', 'LOOP', 'LONGBLOB', 'LONGTEXT', 'LOOP',
'LOW_PRIORITY', 'MATCH', 'MEDIUMBLOB', 'LOW_PRIORITY', 'MATCH', 'MEDIUMBLOB',
'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT', 'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT',
'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MOD', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MOD',
'MODIFIES', 'NATURAL', 'NOT', 'MODIFIES', 'NATURAL', 'NOT',
'NO_WRITE_TO_BINLOG', 'NULL', 'NUMERIC', 'NO_WRITE_TO_BINLOG', 'NULL', 'NUMERIC',
'ON', 'OPTIMIZE', 'OPTION', 'ON', 'OPTIMIZE', 'OPTION',
'OPTIONALLY', 'OR', 'ORDER', 'OPTIONALLY', 'OR', 'ORDER',
'OUT', 'OUTER', 'OUTFILE', 'OUT', 'OUTER', 'OUTFILE',
'PRECISION', 'PRIMARY', 'PROCEDURE', 'PRECISION', 'PRIMARY', 'PROCEDURE',
'PURGE', 'RAID0', 'READ', 'PURGE', 'RAID0', 'READ',
'READS', 'REAL', 'REFERENCES', 'READS', 'REAL', 'REFERENCES',
'REGEXP', 'RELEASE', 'RENAME', 'REGEXP', 'RELEASE', 'RENAME',
'REPEAT', 'REPLACE', 'REQUIRE', 'REPEAT', 'REPLACE', 'REQUIRE',
'RESTRICT', 'RETURN', 'REVOKE', 'RESTRICT', 'RETURN', 'REVOKE',
'RIGHT', 'RLIKE', 'SCHEMA', 'RIGHT', 'RLIKE', 'SCHEMA',
'SCHEMAS', 'SECOND_MICROSECOND', 'SELECT', 'SCHEMAS', 'SECOND_MICROSECOND', 'SELECT',
'SENSITIVE', 'SEPARATOR', 'SET', 'SENSITIVE', 'SEPARATOR', 'SET',
'SHOW', 'SMALLINT', 'SONAME', 'SHOW', 'SMALLINT', 'SONAME',
'SPATIAL', 'SPECIFIC', 'SQL', 'SPATIAL', 'SPECIFIC', 'SQL',
'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING',
'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT', 'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT',
'SSL', 'STARTING', 'STRAIGHT_JOIN', 'SSL', 'STARTING', 'STRAIGHT_JOIN',
'TABLE', 'TERMINATED', 'THEN', 'TABLE', 'TERMINATED', 'THEN',
'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TINYBLOB', 'TINYINT', 'TINYTEXT',
'TO', 'TRAILING', 'TRIGGER', 'TO', 'TRAILING', 'TRIGGER',
'TRUE', 'UNDO', 'UNION', 'TRUE', 'UNDO', 'UNION',
'UNIQUE', 'UNLOCK', 'UNSIGNED', 'UNIQUE', 'UNLOCK', 'UNSIGNED',
'UPDATE', 'USAGE', 'USE', 'UPDATE', 'USAGE', 'USE',
'USING', 'UTC_DATE', 'UTC_TIME', 'USING', 'UTC_DATE', 'UTC_TIME',
'UTC_TIMESTAMP', 'VALUES', 'VARBINARY', 'UTC_TIMESTAMP', 'VALUES', 'VARBINARY',
'VARCHAR', 'VARCHARACTER', 'VARYING', 'VARCHAR', 'VARCHARACTER', 'VARYING',
'WHEN', 'WHERE', 'WHILE', 'WHEN', 'WHERE', 'WHILE',
'WITH', 'WRITE', 'X509', 'WITH', 'WRITE', 'X509',
'XOR', 'YEAR_MONTH', 'ZEROFILL' 'XOR', 'YEAR_MONTH', 'ZEROFILL'
); );
/** /**
* Obtain DBMS specific SQL code portion needed to declare an text type * Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
* *
* @param array $field associative array with the name of the properties * @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types * of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows: * of supported field properties are as follows:
* *
* length * length
* Integer value that determines the maximum length of the text * Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be * field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS. * declared to have the longest length allowed by the DBMS.
* *
* default * default
* Text value to be used as default for this field. * Text value to be used as default for this field.
* *
* notnull * notnull
* Boolean flag that indicates whether this field is constrained * Boolean flag that indicates whether this field is constrained
* to not be set to null. * to not be set to null.
* *
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration($field) public function getNativeDeclaration($field)
{ {
switch ($field['type']) { switch ($field['type']) {
case 'char': case 'char':
$length = (! empty($field['length'])) ? $field['length'] : false; $length = (! empty($field['length'])) ? $field['length'] : false;
return $length ? 'CHAR('.$length.')' : 'CHAR(255)'; return $length ? 'CHAR('.$length.')' : 'CHAR(255)';
case 'varchar': case 'varchar':
case 'array': case 'array':
case 'object': case 'object':
case 'string': case 'string':
if ( ! isset($field['length'])) { if ( ! isset($field['length'])) {
if (array_key_exists('default', $field)) { if (array_key_exists('default', $field)) {
$field['length'] = $this->conn->varchar_max_length; $field['length'] = $this->conn->varchar_max_length;
} else { } else {
$field['length'] = false; $field['length'] = false;
} }
} }
$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; $fixed = (isset($field['fixed'])) ? $field['fixed'] : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)') return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT'); : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
case 'clob': case 'clob':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 255) { if ($length <= 255) {
return 'TINYTEXT'; return 'TINYTEXT';
} elseif ($length <= 65532) { } elseif ($length <= 65532) {
return 'TEXT'; return 'TEXT';
} elseif ($length <= 16777215) { } elseif ($length <= 16777215) {
return 'MEDIUMTEXT'; return 'MEDIUMTEXT';
} }
} }
return 'LONGTEXT'; return 'LONGTEXT';
case 'blob': case 'blob':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 255) { if ($length <= 255) {
return 'TINYBLOB'; return 'TINYBLOB';
} elseif ($length <= 65532) { } elseif ($length <= 65532) {
return 'BLOB'; return 'BLOB';
} elseif ($length <= 16777215) { } elseif ($length <= 16777215) {
return 'MEDIUMBLOB'; return 'MEDIUMBLOB';
} }
} }
return 'LONGBLOB'; return 'LONGBLOB';
case 'integer': case 'integer':
case 'enum': case 'enum':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 1) { if ($length <= 1) {
return 'TINYINT'; return 'TINYINT';
} elseif ($length == 2) { } elseif ($length == 2) {
return 'SMALLINT'; return 'SMALLINT';
} elseif ($length == 3) { } elseif ($length == 3) {
return 'MEDIUMINT'; return 'MEDIUMINT';
} elseif ($length == 4) { } elseif ($length == 4) {
return 'INT'; return 'INT';
} elseif ($length > 4) { } elseif ($length > 4) {
return 'BIGINT'; return 'BIGINT';
} }
} }
return 'INT'; return 'INT';
case 'boolean': case 'boolean':
return 'TINYINT(1)'; return 'TINYINT(1)';
case 'date': case 'date':
return 'DATE'; return 'DATE';
case 'time': case 'time':
return 'TIME'; return 'TIME';
case 'timestamp': case 'timestamp':
return 'DATETIME'; return 'DATETIME';
case 'float': case 'float':
return 'DOUBLE'; return 'DOUBLE';
case 'decimal': case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18; $length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL(' . $length . ',' . 0 . ')'; //$this->dbh->options['decimal_places'] . ')'; return 'DECIMAL(' . $length . ',' . 0 . ')'; //$this->dbh->options['decimal_places'] . ')';
} }
return ''; return '';
} }
/** /**
* Maps a native array description of a field to a MDB2 datatype and length * Maps a native array description of a field to a MDB2 datatype and length
* *
* @param array $field native field description * @param array $field native field description
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
*/ */
public function getPortableDeclaration(array $field) public function getPortableDeclaration(array $field)
{ {
$dbType = strtolower($field['type']); $dbType = strtolower($field['type']);
$dbType = strtok($dbType, '(), '); $dbType = strtok($dbType, '(), ');
if ($dbType == 'national') { if ($dbType == 'national') {
$dbType = strtok('(), '); $dbType = strtok('(), ');
} }
if (isset($field['length'])) { if (isset($field['length'])) {
$length = $field['length']; $length = $field['length'];
$decimal = ''; $decimal = '';
} else { } else {
$length = strtok('(), '); $length = strtok('(), ');
$decimal = strtok('(), '); $decimal = strtok('(), ');
} }
$type = array(); $type = array();
$unsigned = $fixed = null; $unsigned = $fixed = null;
if( ! isset($field['name'])) if ( ! isset($field['name'])) {
$field['name'] = ''; $field['name'] = '';
}
switch ($dbType) {
case 'tinyint': switch ($dbType) {
$type[] = 'integer'; case 'tinyint':
$type[] = 'boolean'; $type[] = 'integer';
if (preg_match('/^(is|has)/', $field['name'])) { $type[] = 'boolean';
$type = array_reverse($type); if (preg_match('/^(is|has)/', $field['name'])) {
} $type = array_reverse($type);
$unsigned = preg_match('/ unsigned/i', $field['type']); }
$length = 1; $unsigned = preg_match('/ unsigned/i', $field['type']);
break; $length = 1;
case 'smallint': break;
$type[] = 'integer'; case 'smallint':
$unsigned = preg_match('/ unsigned/i', $field['type']); $type[] = 'integer';
$length = 2; $unsigned = preg_match('/ unsigned/i', $field['type']);
break; $length = 2;
case 'mediumint': break;
$type[] = 'integer'; case 'mediumint':
$unsigned = preg_match('/ unsigned/i', $field['type']); $type[] = 'integer';
$length = 3; $unsigned = preg_match('/ unsigned/i', $field['type']);
break; $length = 3;
case 'int': break;
case 'integer': case 'int':
$type[] = 'integer'; case 'integer':
$unsigned = preg_match('/ unsigned/i', $field['type']); $type[] = 'integer';
$length = 4; $unsigned = preg_match('/ unsigned/i', $field['type']);
break; $length = 4;
case 'bigint': break;
$type[] = 'integer'; case 'bigint':
$unsigned = preg_match('/ unsigned/i', $field['type']); $type[] = 'integer';
$length = 8; $unsigned = preg_match('/ unsigned/i', $field['type']);
break; $length = 8;
case 'tinytext': break;
case 'mediumtext': case 'tinytext':
case 'longtext': case 'mediumtext':
case 'text': case 'longtext':
case 'text': case 'text':
case 'varchar': case 'text':
$fixed = false; case 'varchar':
case 'string': $fixed = false;
case 'char': case 'string':
$type[] = 'string'; case 'char':
if ($length == '1') { $type[] = 'string';
$type[] = 'boolean'; if ($length == '1') {
if (preg_match('/^(is|has)/', $field['name'])) { $type[] = 'boolean';
$type = array_reverse($type); if (preg_match('/^(is|has)/', $field['name'])) {
} $type = array_reverse($type);
} elseif (strstr($dbType, 'text')) { }
$type[] = 'clob'; } elseif (strstr($dbType, 'text')) {
if ($decimal == 'binary') { $type[] = 'clob';
$type[] = 'blob'; if ($decimal == 'binary') {
} $type[] = 'blob';
} }
if ($fixed !== false) { }
$fixed = true; if ($fixed !== false) {
} $fixed = true;
break; }
case 'enum': break;
$type[] = 'text'; case 'enum':
preg_match_all('/\'.+\'/U', $field['type'], $matches); $type[] = 'text';
$length = 0; preg_match_all('/\'.+\'/U', $field['type'], $matches);
$fixed = false; $length = 0;
if (is_array($matches)) { $fixed = false;
foreach ($matches[0] as $value) { if (is_array($matches)) {
$length = max($length, strlen($value)-2); foreach ($matches[0] as $value) {
} $length = max($length, strlen($value)-2);
if ($length == '1' && count($matches[0]) == 2) { }
$type[] = 'boolean'; if ($length == '1' && count($matches[0]) == 2) {
if (preg_match('/^(is|has)/', $field['name'])) { $type[] = 'boolean';
$type = array_reverse($type); if (preg_match('/^(is|has)/', $field['name'])) {
} $type = array_reverse($type);
} }
} }
$type[] = 'integer'; }
case 'set': $type[] = 'integer';
$fixed = false; case 'set':
$type[] = 'text'; $fixed = false;
$type[] = 'integer'; $type[] = 'text';
break; $type[] = 'integer';
case 'date': break;
$type[] = 'date'; case 'date':
$length = null; $type[] = 'date';
break; $length = null;
case 'datetime': break;
case 'timestamp': case 'datetime':
$type[] = 'timestamp'; case 'timestamp':
$length = null; $type[] = 'timestamp';
break; $length = null;
case 'time': break;
$type[] = 'time'; case 'time':
$length = null; $type[] = 'time';
break; $length = null;
case 'float': break;
case 'double': case 'float':
case 'real': case 'double':
$type[] = 'float'; case 'real':
$unsigned = preg_match('/ unsigned/i', $field['type']); $type[] = 'float';
break; $unsigned = preg_match('/ unsigned/i', $field['type']);
case 'unknown': break;
case 'decimal': case 'unknown':
case 'numeric': case 'decimal':
$type[] = 'decimal'; case 'numeric':
$unsigned = preg_match('/ unsigned/i', $field['type']); $type[] = 'decimal';
break; $unsigned = preg_match('/ unsigned/i', $field['type']);
case 'tinyblob': break;
case 'mediumblob': case 'tinyblob':
case 'longblob': case 'mediumblob':
case 'blob': case 'longblob':
$type[] = 'blob'; case 'blob':
$length = null; $type[] = 'blob';
break; $length = null;
case 'year': break;
$type[] = 'integer'; case 'year':
$type[] = 'date'; $type[] = 'integer';
$length = null; $type[] = 'date';
break; $length = null;
default: break;
throw new Doctrine_DataDict_Mysql_Exception('unknown database attribute type: '.$dbType); default:
} throw new Doctrine_DataDict_Mysql_Exception('unknown database attribute type: '.$dbType);
}
$length = ((int) $length == 0) ? null : (int) $length;
$length = ((int) $length == 0) ? null : (int) $length;
return array($type, $length, $unsigned, $fixed);
} return array($type, $length, $unsigned, $fixed);
/** }
* Obtain DBMS specific SQL code portion needed to set the CHARACTER SET /**
* of a field declaration to be used in statements like CREATE TABLE. * 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 * @param string $charset name of the charset
* of a field declaration. * @return string DBMS specific SQL code portion needed to set the CHARACTER SET
*/ * of a field declaration.
public function getCharsetFieldDeclaration($charset) */
{ public function getCharsetFieldDeclaration($charset)
return 'CHARACTER SET '.$charset; {
} 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. * 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 * @param string $collation name of the collation
* of a field declaration. * @return string DBMS specific SQL code portion needed to set the COLLATION
*/ * of a field declaration.
public function getCollationFieldDeclaration($collation) */
{ public function getCollationFieldDeclaration($collation)
return 'COLLATE '.$collation; {
} return 'COLLATE '.$collation;
/** }
* Obtain DBMS specific SQL code portion needed to declare an integer type /**
* field to be used in statements like CREATE TABLE. * 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 * @param string $name name the field to be declared.
* of the field being declared as array indexes. * @param string $field associative array with the name of the properties
* Currently, the types of supported field * of the field being declared as array indexes.
* properties are as follows: * Currently, the types of supported field
* * properties are as follows:
* unsigned *
* Boolean flag that indicates whether the field * unsigned
* should be declared as unsigned integer if * Boolean flag that indicates whether the field
* possible. * should be declared as unsigned integer if
* * possible.
* default *
* Integer value to be used as default for this * default
* field. * Integer value to be used as default for this
* * field.
* notnull *
* Boolean flag that indicates whether this field is * notnull
* constrained to not be set to null. * Boolean flag that indicates whether this field is
* @return string DBMS specific SQL code portion that should be used to * constrained to not be set to null.
* declare the specified field. * @return string DBMS specific SQL code portion that should be used to
*/ * declare the specified field.
public function getIntegerDeclaration($name, $field) */
{ public function getIntegerDeclaration($name, $field)
$default = $autoinc = ''; {
if (!empty($field['autoincrement'])) { $default = $autoinc = '';
$autoinc = ' AUTO_INCREMENT PRIMARY KEY'; if (!empty($field['autoincrement'])) {
} elseif (array_key_exists('default', $field)) { $autoinc = ' AUTO_INCREMENT PRIMARY KEY';
if ($field['default'] === '') { } elseif (array_key_exists('default', $field)) {
$field['default'] = empty($field['notnull']) ? null : 0; if ($field['default'] === '') {
} $field['default'] = empty($field['notnull']) ? null : 0;
$default = ' DEFAULT '.$this->conn->getDbh()->quote($field['default']); }
} $default = ' DEFAULT '.$this->conn->getDbh()->quote($field['default']);
/** }
elseif (empty($field['notnull'])) { /**
$default = ' DEFAULT NULL'; elseif (empty($field['notnull'])) {
} $default = ' DEFAULT NULL';
*/ }
*/
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : ''; $notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : '';
$name = $this->conn->quoteIdentifier($name, true);
$name = $this->conn->quoteIdentifier($name, true);
return $name . ' ' . $this->getNativeDeclaration($field) . $unsigned . $default . $notnull . $autoinc;
} return $name . ' ' . $this->getNativeDeclaration($field) . $unsigned . $default . $notnull . $autoinc;
} }
}

View File

@ -1,181 +1,182 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
/** /**
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @version $Revision$ * @version $Revision$
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_DataDict_Oracle extends Doctrine_DataDict class Doctrine_DataDict_Oracle extends Doctrine_DataDict
{ {
/** /**
* Obtain DBMS specific SQL code portion needed to declare an text type * Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
* *
* @param array $field associative array with the name of the properties * @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types * of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows: * of supported field properties are as follows:
* *
* length * length
* Integer value that determines the maximum length of the text * Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be * field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS. * declared to have the longest length allowed by the DBMS.
* *
* default * default
* Text value to be used as default for this field. * Text value to be used as default for this field.
* *
* notnull * notnull
* Boolean flag that indicates whether this field is constrained * Boolean flag that indicates whether this field is constrained
* to not be set to null. * to not be set to null.
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration(array $field) public function getNativeDeclaration(array $field)
{ {
switch ($field['type']) { switch ($field['type']) {
case 'string': case 'string':
case 'array': case 'array':
case 'object': case 'object':
case 'gzip': case 'gzip':
case 'char': case 'char':
case 'varchar': case 'varchar':
$length = !empty($field['length']) $length = !empty($field['length'])
? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length']; ? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length'];
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false; $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR2('.$length.')'; return $fixed ? 'CHAR('.$length.')' : 'VARCHAR2('.$length.')';
case 'clob': case 'clob':
return 'CLOB'; return 'CLOB';
case 'blob': case 'blob':
return 'BLOB'; return 'BLOB';
case 'integer': case 'integer':
case 'enum': case 'enum':
if (!empty($field['length'])) { if (!empty($field['length'])) {
return 'NUMBER('.$field['length'].')'; return 'NUMBER('.$field['length'].')';
} }
return 'INT'; return 'INT';
case 'boolean': case 'boolean':
return 'NUMBER(1)'; return 'NUMBER(1)';
case 'date': case 'date':
case 'time': case 'time':
case 'timestamp': case 'timestamp':
return 'DATE'; return 'DATE';
case 'float': case 'float':
return 'NUMBER'; return 'NUMBER';
case 'decimal': case 'decimal':
return 'NUMBER(*,'.$db->options['decimal_places'].')'; return 'NUMBER(*,'.$db->options['decimal_places'].')';
} }
} }
/** /**
* Maps a native array description of a field to a doctrine datatype and length * Maps a native array description of a field to a doctrine datatype and length
* *
* @param array $field native field description * @param array $field native field description
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
* @throws Doctrine_DataDict_Oracle_Exception * @throws Doctrine_DataDict_Oracle_Exception
*/ */
public function getPortableDeclaration(array $field) public function getPortableDeclaration(array $field)
{ {
$db_type = strtolower($field['type']); $db_type = strtolower($field['type']);
$type = array(); $type = array();
$length = $unsigned = $fixed = null; $length = $unsigned = $fixed = null;
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
} }
if( ! isset($field['name'])) if ( ! isset($field['name'])) {
$field['name'] = ''; $field['name'] = '';
}
switch ($db_type) {
case 'integer': switch ($db_type) {
case 'pls_integer': case 'integer':
case 'binary_integer': case 'pls_integer':
$type[] = 'integer'; case 'binary_integer':
if ($length == '1') { $type[] = 'integer';
$type[] = 'boolean'; if ($length == '1') {
if (preg_match('/^(is|has)/', $field['name'])) { $type[] = 'boolean';
$type = array_reverse($type); if (preg_match('/^(is|has)/', $field['name'])) {
} $type = array_reverse($type);
} }
break; }
case 'varchar': break;
case 'varchar2': case 'varchar':
case 'nvarchar2': case 'varchar2':
$fixed = false; case 'nvarchar2':
case 'char': $fixed = false;
case 'nchar': case 'char':
$type[] = 'string'; case 'nchar':
if ($length == '1') { $type[] = 'string';
$type[] = 'boolean'; if ($length == '1') {
if (preg_match('/^(is|has)/', $field['name'])) { $type[] = 'boolean';
$type = array_reverse($type); if (preg_match('/^(is|has)/', $field['name'])) {
} $type = array_reverse($type);
} }
if ($fixed !== false) { }
$fixed = true; if ($fixed !== false) {
} $fixed = true;
break; }
case 'date': break;
case 'timestamp': case 'date':
$type[] = 'timestamp'; case 'timestamp':
$length = null; $type[] = 'timestamp';
break; $length = null;
case 'float': break;
$type[] = 'float'; case 'float':
break; $type[] = 'float';
case 'number': break;
if (!empty($field['scale'])) { case 'number':
$type[] = 'decimal'; if (!empty($field['scale'])) {
} else { $type[] = 'decimal';
$type[] = 'integer'; } else {
if ($length == '1') { $type[] = 'integer';
$type[] = 'boolean'; if ($length == '1') {
if (preg_match('/^(is|has)/', $field['name'])) { $type[] = 'boolean';
$type = array_reverse($type); if (preg_match('/^(is|has)/', $field['name'])) {
} $type = array_reverse($type);
} }
} }
break; }
case 'long': break;
$type[] = 'string'; case 'long':
case 'clob': $type[] = 'string';
case 'nclob': case 'clob':
$type[] = 'clob'; case 'nclob':
break; $type[] = 'clob';
case 'blob': break;
case 'raw': case 'blob':
case 'long raw': case 'raw':
case 'bfile': case 'long raw':
$type[] = 'blob'; case 'bfile':
$length = null; $type[] = 'blob';
break; $length = null;
case 'rowid': break;
case 'urowid': case 'rowid':
default: case 'urowid':
throw new Doctrine_DataDict_Oracle_Exception('unknown database attribute type: '.$db_type); default:
} throw new Doctrine_DataDict_Oracle_Exception('unknown database attribute type: '.$db_type);
}
return array($type, $length, $unsigned, $fixed);
} return array($type, $length, $unsigned, $fixed);
} }
}

File diff suppressed because it is too large Load Diff

View File

@ -1,285 +1,286 @@
<?php <?php
/* /*
* $Id$ * $Id$
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* This software consists of voluntary contributions made by many individuals * This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see * and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>. * <http://www.phpdoctrine.com>.
*/ */
Doctrine::autoload('Doctrine_DataDict'); Doctrine::autoload('Doctrine_DataDict');
/** /**
* @package Doctrine * @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi> * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Revision$ * @version $Revision$
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
*/ */
class Doctrine_DataDict_Sqlite extends Doctrine_DataDict class Doctrine_DataDict_Sqlite extends Doctrine_DataDict
{ {
/** /**
* Obtain DBMS specific SQL code portion needed to declare an text type * Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
* *
* @param array $field associative array with the name of the properties * @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types * of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows: * of supported field properties are as follows:
* *
* length * length
* Integer value that determines the maximum length of the text * Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be * field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS. * declared to have the longest length allowed by the DBMS.
* *
* default * default
* Text value to be used as default for this field. * Text value to be used as default for this field.
* *
* notnull * notnull
* Boolean flag that indicates whether this field is constrained * Boolean flag that indicates whether this field is constrained
* to not be set to null. * to not be set to null.
* @author Lukas Smith (PEAR MDB2 library) * @author Lukas Smith (PEAR MDB2 library)
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getNativeDeclaration(array $field) public function getNativeDeclaration(array $field)
{ {
switch ($field['type']) { switch ($field['type']) {
case 'text': case 'text':
case 'object': case 'object':
case 'array': case 'array':
case 'string': case 'string':
case 'char': case 'char':
case 'gzip': case 'gzip':
case 'varchar': case 'varchar':
$length = (isset($field['length']) && $field['length']) ? $field['length'] : null; $length = (isset($field['length']) && $field['length']) ? $field['length'] : null;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false; $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$this->conn->getAttribute(Doctrine::ATTR_DEFAULT_TEXTFLD_LENGTH).')') return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$this->conn->getAttribute(Doctrine::ATTR_DEFAULT_TEXTFLD_LENGTH).')')
: ($length ? 'VARCHAR('.$length.')' : 'TEXT'); : ($length ? 'VARCHAR('.$length.')' : 'TEXT');
case 'clob': case 'clob':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 255) { if ($length <= 255) {
return 'TINYTEXT'; return 'TINYTEXT';
} elseif ($length <= 65535) { } elseif ($length <= 65535) {
return 'TEXT'; return 'TEXT';
} elseif ($length <= 16777215) { } elseif ($length <= 16777215) {
return 'MEDIUMTEXT'; return 'MEDIUMTEXT';
} }
} }
return 'LONGTEXT'; return 'LONGTEXT';
case 'blob': case 'blob':
if (!empty($field['length'])) { if (!empty($field['length'])) {
$length = $field['length']; $length = $field['length'];
if ($length <= 255) { if ($length <= 255) {
return 'TINYBLOB'; return 'TINYBLOB';
} elseif ($length <= 65535) { } elseif ($length <= 65535) {
return 'BLOB'; return 'BLOB';
} elseif ($length <= 16777215) { } elseif ($length <= 16777215) {
return 'MEDIUMBLOB'; return 'MEDIUMBLOB';
} }
} }
return 'LONGBLOB'; return 'LONGBLOB';
case 'enum': case 'enum':
case 'integer': case 'integer':
case 'boolean': case 'boolean':
return 'INTEGER'; return 'INTEGER';
case 'date': case 'date':
return 'DATE'; return 'DATE';
case 'time': case 'time':
return 'TIME'; return 'TIME';
case 'timestamp': case 'timestamp':
return 'DATETIME'; return 'DATETIME';
case 'float': case 'float':
case 'double': case 'double':
return 'DOUBLE';//($db->options['fixed_float'] ? '('. return 'DOUBLE';//($db->options['fixed_float'] ? '('.
//($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : ''); //($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : '');
case 'decimal': case 'decimal':
$length = !empty($field['length']) ? $field['length'] : 18; $length = !empty($field['length']) ? $field['length'] : 18;
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')'; return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
} }
throw new Doctrine_DataDict_Sqlite_Exception('Unknown datatype ' . $field['type']); throw new Doctrine_DataDict_Sqlite_Exception('Unknown datatype ' . $field['type']);
} }
/** /**
* Maps a native array description of a field to Doctrine datatype and length * Maps a native array description of a field to Doctrine datatype and length
* *
* @param array $field native field description * @param array $field native field description
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
*/ */
public function getPortableDeclaration(array $field) public function getPortableDeclaration(array $field)
{ {
$dbType = strtolower($field['type']); $dbType = strtolower($field['type']);
$length = (isset($field['length'])) ? $field['length'] : null; $length = (isset($field['length'])) ? $field['length'] : null;
$unsigned = (isset($field['unsigned'])) ? $field['unsigned'] : null; $unsigned = (isset($field['unsigned'])) ? $field['unsigned'] : null;
$fixed = null; $fixed = null;
$type = array(); $type = array();
if( ! isset($field['name'])) if ( ! isset($field['name'])) {
$field['name'] = ''; $field['name'] = '';
}
switch ($dbType) {
case 'boolean': switch ($dbType) {
$type[] = 'boolean'; case 'boolean':
break; $type[] = 'boolean';
case 'tinyint': break;
$type[] = 'integer'; case 'tinyint':
$type[] = 'boolean'; $type[] = 'integer';
if (preg_match('/^(is|has)/', $field['name'])) { $type[] = 'boolean';
$type = array_reverse($type); if (preg_match('/^(is|has)/', $field['name'])) {
} $type = array_reverse($type);
$unsigned = preg_match('/ unsigned/i', $field['type']); }
$length = 1; $unsigned = preg_match('/ unsigned/i', $field['type']);
break; $length = 1;
case 'smallint': break;
$type[] = 'integer'; case 'smallint':
$unsigned = preg_match('/ unsigned/i', $field['type']); $type[] = 'integer';
$length = 2; $unsigned = preg_match('/ unsigned/i', $field['type']);
break; $length = 2;
case 'mediumint': break;
$type[] = 'integer'; case 'mediumint':
$unsigned = preg_match('/ unsigned/i', $field['type']); $type[] = 'integer';
$length = 3; $unsigned = preg_match('/ unsigned/i', $field['type']);
break; $length = 3;
case 'int': break;
case 'integer': case 'int':
case 'serial': case 'integer':
$type[] = 'integer'; case 'serial':
$unsigned = preg_match('/ unsigned/i', $field['type']); $type[] = 'integer';
$length = 4; $unsigned = preg_match('/ unsigned/i', $field['type']);
break; $length = 4;
case 'bigint': break;
case 'bigserial': case 'bigint':
$type[] = 'integer'; case 'bigserial':
$unsigned = preg_match('/ unsigned/i', $field['type']); $type[] = 'integer';
$length = 8; $unsigned = preg_match('/ unsigned/i', $field['type']);
break; $length = 8;
case 'clob': break;
case 'tinytext': case 'clob':
case 'mediumtext': case 'tinytext':
case 'longtext': case 'mediumtext':
case 'text': case 'longtext':
case 'varchar': case 'text':
case 'varchar2': case 'varchar':
$fixed = false; case 'varchar2':
case 'char': $fixed = false;
$type[] = 'text'; case 'char':
if ($length == '1') { $type[] = 'text';
$type[] = 'boolean'; if ($length == '1') {
if (preg_match('/^(is|has)/', $field['name'])) { $type[] = 'boolean';
$type = array_reverse($type); if (preg_match('/^(is|has)/', $field['name'])) {
} $type = array_reverse($type);
} elseif (strstr($dbType, 'text')) { }
$type[] = 'clob'; } elseif (strstr($dbType, 'text')) {
} $type[] = 'clob';
if ($fixed !== false) { }
$fixed = true; if ($fixed !== false) {
} $fixed = true;
break; }
case 'date': break;
$type[] = 'date'; case 'date':
$length = null; $type[] = 'date';
break; $length = null;
case 'datetime': break;
case 'timestamp': case 'datetime':
$type[] = 'timestamp'; case 'timestamp':
$length = null; $type[] = 'timestamp';
break; $length = null;
case 'time': break;
$type[] = 'time'; case 'time':
$length = null; $type[] = 'time';
break; $length = null;
case 'float': break;
case 'double': case 'float':
case 'real': case 'double':
$type[] = 'float'; case 'real':
$length = null; $type[] = 'float';
break; $length = null;
case 'decimal': break;
case 'numeric': case 'decimal':
$type[] = 'decimal'; case 'numeric':
$length = null; $type[] = 'decimal';
break; $length = null;
case 'tinyblob': break;
case 'mediumblob': case 'tinyblob':
case 'longblob': case 'mediumblob':
case 'blob': case 'longblob':
$type[] = 'blob'; case 'blob':
$length = null; $type[] = 'blob';
break; $length = null;
case 'year': break;
$type[] = 'integer'; case 'year':
$type[] = 'date'; $type[] = 'integer';
$length = null; $type[] = 'date';
break; $length = null;
default: break;
throw new Doctrine_DataDict_Sqlite_Exception('unknown database attribute type: '.$dbType); default:
} throw new Doctrine_DataDict_Sqlite_Exception('unknown database attribute type: '.$dbType);
}
return array($type, $length, $unsigned, $fixed);
} return array($type, $length, $unsigned, $fixed);
/** }
* Obtain DBMS specific SQL code portion needed to declare an integer type /**
* field to be used in statements like CREATE TABLE. * 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 array $field associative array with the name of the properties * @param string $name name the field to be declared.
* of the field being declared as array indexes. * @param array $field associative array with the name of the properties
* Currently, the types of supported field * of the field being declared as array indexes.
* properties are as follows: * Currently, the types of supported field
* * properties are as follows:
* unsigned *
* Boolean flag that indicates whether the field * unsigned
* should be declared as unsigned integer if * Boolean flag that indicates whether the field
* possible. * should be declared as unsigned integer if
* * possible.
* default *
* Integer value to be used as default for this * default
* field. * Integer value to be used as default for this
* * field.
* notnull *
* Boolean flag that indicates whether this field is * notnull
* constrained to not be set to null. * Boolean flag that indicates whether this field is
* @return string DBMS specific SQL code portion that should be used to * constrained to not be set to null.
* declare the specified field. * @return string DBMS specific SQL code portion that should be used to
* @access protected * declare the specified field.
*/ * @access protected
public function getIntegerDeclaration($name, array $field) */
{ public function getIntegerDeclaration($name, array $field)
$default = $autoinc = ''; {
$type = $this->getNativeDeclaration($field); $default = $autoinc = '';
$type = $this->getNativeDeclaration($field);
if (isset($field['autoincrement']) && $field['autoincrement']) {
$autoinc = ' PRIMARY KEY AUTOINCREMENT'; if (isset($field['autoincrement']) && $field['autoincrement']) {
$type = 'INTEGER'; $autoinc = ' PRIMARY KEY AUTOINCREMENT';
} elseif (array_key_exists('default', $field)) { $type = 'INTEGER';
if ($field['default'] === '') { } elseif (array_key_exists('default', $field)) {
$field['default'] = empty($field['notnull']) ? null : 0; if ($field['default'] === '') {
} $field['default'] = empty($field['notnull']) ? null : 0;
$default = ' DEFAULT ' . $this->conn->quote($field['default'], $field['type']); }
}/** $default = ' DEFAULT ' . $this->conn->quote($field['default'], $field['type']);
elseif (empty($field['notnull'])) { }/**
$default = ' DEFAULT NULL'; elseif (empty($field['notnull'])) {
} $default = ' DEFAULT NULL';
*/ }
*/
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : ''; $notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : '';
$name = $this->conn->quoteIdentifier($name, true);
return $name . ' ' . $type . $unsigned . $default . $notnull . $autoinc; $name = $this->conn->quoteIdentifier($name, true);
} return $name . ' ' . $type . $unsigned . $default . $notnull . $autoinc;
} }
}

View File

@ -182,10 +182,9 @@ class Doctrine_Validator
*/ */
private function validateLength($column, $key, $value) private function validateLength($column, $key, $value)
{ {
if($column[0] == "timestamp") { if ($column[0] == "timestamp") {
return true; return true;
} } else if ($column[0] == "array" || $column[0] == "object") {
else if ($column[0] == "array" || $column[0] == "object") {
$length = strlen(serialize($value)); $length = strlen(serialize($value));
} else { } else {
$length = strlen($value); $length = strlen($value);