1
0
mirror of synced 2024-12-14 23:26:04 +03:00

- s/\$db/\$this->conn

- turned raiseError() calls into throw Exception
This commit is contained in:
lsmith 2007-01-05 22:05:55 +00:00
parent 260558e032
commit 1a21a43e52
6 changed files with 1527 additions and 1528 deletions

View File

@ -1,77 +1,76 @@
<?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_DataDict * 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
* @category Object Relational Mapping * @category Object Relational Mapping
* @link www.phpdoctrine.com * @link www.phpdoctrine.com
* @since 1.0 * @since 1.0
* @version $Revision$ * @version $Revision$
* @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)
*/ */
class Doctrine_DataDict extends Doctrine_Connection_Module class Doctrine_DataDict extends Doctrine_Connection_Module
{ {
/** /**
* Obtain an array of changes that may need to applied * Obtain an array of changes that may need to applied
* *
* @param array $current new definition * @param array $current new definition
* @param array $previous old definition * @param array $previous old definition
* @return array containing all changes that will need to be applied * @return array containing all changes that will need to be applied
*/ */
public function compareDefinition($current, $previous) public function compareDefinition($current, $previous)
{ {
$type = !empty($current['type']) ? $current['type'] : null; $type = !empty($current['type']) ? $current['type'] : null;
if (!method_exists($this, "_compare{$type}Definition")) { if (!method_exists($this, "_compare{$type}Definition")) {
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, throw new Doctrine_DataDict_Exception('type "'.$current['type'].'" is not yet supported');
'type "'.$current['type'].'" is not yet supported', __FUNCTION__); }
}
if (empty($previous['type']) || $previous['type'] != $type) {
if (empty($previous['type']) || $previous['type'] != $type) { return $current;
return $current; }
}
$change = $this->{"_compare{$type}Definition"}($current, $previous);
$change = $this->{"_compare{$type}Definition"}($current, $previous);
if ($previous['type'] != $type) {
if ($previous['type'] != $type) { $change['type'] = true;
$change['type'] = true; }
}
$previous_notnull = !empty($previous['notnull']) ? $previous['notnull'] : false;
$previous_notnull = !empty($previous['notnull']) ? $previous['notnull'] : false; $notnull = !empty($current['notnull']) ? $current['notnull'] : false;
$notnull = !empty($current['notnull']) ? $current['notnull'] : false; if ($previous_notnull != $notnull) {
if ($previous_notnull != $notnull) { $change['notnull'] = true;
$change['notnull'] = true; }
}
$previous_default = array_key_exists('default', $previous) ? $previous['default'] :
$previous_default = array_key_exists('default', $previous) ? $previous['default'] : ($previous_notnull ? '' : null);
($previous_notnull ? '' : null); $default = array_key_exists('default', $current) ? $current['default'] :
$default = array_key_exists('default', $current) ? $current['default'] : ($notnull ? '' : null);
($notnull ? '' : null); if ($previous_default !== $default) {
if ($previous_default !== $default) { $change['default'] = true;
$change['default'] = true; }
}
return $change;
return $change; }
} }
}

View File

@ -1,205 +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: $this->conn->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.','.$this->conn->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) { switch ($dbType) {
case 'smallint': case 'smallint':
case 'integer': case 'integer':
case 'int64': case 'int64':
//these may be 'numeric' or 'decimal' //these may be 'numeric' or 'decimal'
if (isset($field['field_sub_type'])) { if (isset($field['field_sub_type'])) {
$field['type'] = $field['field_sub_type']; $field['type'] = $field['field_sub_type'];
return $this->getPortableDeclaration($field); return $this->getPortableDeclaration($field);
} }
case 'bigint': case 'bigint':
case 'quad': case 'quad':
$type[] = 'integer'; $type[] = 'integer';
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);
} }
} }
break; break;
case 'varchar': case 'varchar':
$fixed = false; $fixed = false;
case 'char': case 'char':
case 'cstring': case 'cstring':
$type[] = 'string'; $type[] = '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);
} }
} }
if ($fixed !== false) { if ($fixed !== false) {
$fixed = true; $fixed = true;
} }
break; break;
case 'date': case 'date':
$type[] = 'date'; $type[] = 'date';
$length = null; $length = null;
break; break;
case 'timestamp': case 'timestamp':
$type[] = 'timestamp'; $type[] = 'timestamp';
$length = null; $length = null;
break; break;
case 'time': case 'time':
$type[] = 'time'; $type[] = 'time';
$length = null; $length = null;
break; break;
case 'float': case 'float':
case 'double': case 'double':
case 'double precision': case 'double precision':
case 'd_float': case 'd_float':
$type[] = 'float'; $type[] = 'float';
break; break;
case 'decimal': case 'decimal':
case 'numeric': case 'numeric':
$type[] = 'decimal'; $type[] = 'decimal';
break; break;
case 'blob': case 'blob':
$type[] = ($field['field_sub_type'] == 'text') ? 'clob' : 'blob'; $type[] = ($field['field_sub_type'] == 'text') ? 'clob' : 'blob';
$length = null; $length = null;
break; break;
default: default:
throw new Doctrine_DataDict_Firebird_Exception('unknown database attribute type: '.$dbType); 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 * Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration to be used in statements like CREATE TABLE. * of a field declaration to be used in statements like CREATE TABLE.
* *
* @param string $charset name of the charset * @param string $charset name of the charset
* @return string DBMS specific SQL code portion needed to set the CHARACTER SET * @return string DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration. * 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 * Obtain DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration to be used in statements like CREATE TABLE. * of a field declaration to be used in statements like CREATE TABLE.
* *
* @param string $collation name of the collation * @param string $collation name of the collation
* @return string DBMS specific SQL code portion needed to set the COLLATION * @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration. * 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('.$this->conn->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.','.$this->conn->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,182 +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: $this->conn->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(*,'.$this->conn->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) { switch ($db_type) {
case 'integer': case 'integer':
case 'pls_integer': case 'pls_integer':
case 'binary_integer': case 'binary_integer':
$type[] = 'integer'; $type[] = 'integer';
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);
} }
} }
break; break;
case 'varchar': case 'varchar':
case 'varchar2': case 'varchar2':
case 'nvarchar2': case 'nvarchar2':
$fixed = false; $fixed = false;
case 'char': case 'char':
case 'nchar': case 'nchar':
$type[] = 'string'; $type[] = '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);
} }
} }
if ($fixed !== false) { if ($fixed !== false) {
$fixed = true; $fixed = true;
} }
break; break;
case 'date': case 'date':
case 'timestamp': case 'timestamp':
$type[] = 'timestamp'; $type[] = 'timestamp';
$length = null; $length = null;
break; break;
case 'float': case 'float':
$type[] = 'float'; $type[] = 'float';
break; break;
case 'number': case 'number':
if (!empty($field['scale'])) { if (!empty($field['scale'])) {
$type[] = 'decimal'; $type[] = 'decimal';
} else { } else {
$type[] = 'integer'; $type[] = 'integer';
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);
} }
} }
} }
break; break;
case 'long': case 'long':
$type[] = 'string'; $type[] = 'string';
case 'clob': case 'clob':
case 'nclob': case 'nclob':
$type[] = 'clob'; $type[] = 'clob';
break; break;
case 'blob': case 'blob':
case 'raw': case 'raw':
case 'long raw': case 'long raw':
case 'bfile': case 'bfile':
$type[] = 'blob'; $type[] = 'blob';
$length = null; $length = null;
break; break;
case 'rowid': case 'rowid':
case 'urowid': case 'urowid':
default: default:
throw new Doctrine_DataDict_Oracle_Exception('unknown database attribute type: '.$db_type); 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,286 +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';//($this->conn->options['fixed_float'] ? '('.
//($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : ''); //($this->conn->options['fixed_float']+2).','.$this->conn->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.','.$this->conn->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) { switch ($dbType) {
case 'boolean': case 'boolean':
$type[] = 'boolean'; $type[] = 'boolean';
break; break;
case 'tinyint': case 'tinyint':
$type[] = 'integer'; $type[] = 'integer';
$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);
} }
$unsigned = preg_match('/ unsigned/i', $field['type']); $unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 1; $length = 1;
break; break;
case 'smallint': case 'smallint':
$type[] = 'integer'; $type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']); $unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 2; $length = 2;
break; break;
case 'mediumint': case 'mediumint':
$type[] = 'integer'; $type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']); $unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 3; $length = 3;
break; break;
case 'int': case 'int':
case 'integer': case 'integer':
case 'serial': case 'serial':
$type[] = 'integer'; $type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']); $unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 4; $length = 4;
break; break;
case 'bigint': case 'bigint':
case 'bigserial': case 'bigserial':
$type[] = 'integer'; $type[] = 'integer';
$unsigned = preg_match('/ unsigned/i', $field['type']); $unsigned = preg_match('/ unsigned/i', $field['type']);
$length = 8; $length = 8;
break; break;
case 'clob': case 'clob':
case 'tinytext': case 'tinytext':
case 'mediumtext': case 'mediumtext':
case 'longtext': case 'longtext':
case 'text': case 'text':
case 'varchar': case 'varchar':
case 'varchar2': case 'varchar2':
$fixed = false; $fixed = false;
case 'char': case 'char':
$type[] = 'text'; $type[] = 'text';
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($dbType, 'text')) { } elseif (strstr($dbType, 'text')) {
$type[] = 'clob'; $type[] = 'clob';
} }
if ($fixed !== false) { if ($fixed !== false) {
$fixed = true; $fixed = true;
} }
break; break;
case 'date': case 'date':
$type[] = 'date'; $type[] = 'date';
$length = null; $length = null;
break; break;
case 'datetime': case 'datetime':
case 'timestamp': case 'timestamp':
$type[] = 'timestamp'; $type[] = 'timestamp';
$length = null; $length = null;
break; break;
case 'time': case 'time':
$type[] = 'time'; $type[] = 'time';
$length = null; $length = null;
break; break;
case 'float': case 'float':
case 'double': case 'double':
case 'real': case 'real':
$type[] = 'float'; $type[] = 'float';
$length = null; $length = null;
break; break;
case 'decimal': case 'decimal':
case 'numeric': case 'numeric':
$type[] = 'decimal'; $type[] = 'decimal';
$length = null; $length = null;
break; break;
case 'tinyblob': case 'tinyblob':
case 'mediumblob': case 'mediumblob':
case 'longblob': case 'longblob':
case 'blob': case 'blob':
$type[] = 'blob'; $type[] = 'blob';
$length = null; $length = null;
break; break;
case 'year': case 'year':
$type[] = 'integer'; $type[] = 'integer';
$type[] = 'date'; $type[] = 'date';
$length = null; $length = null;
break; break;
default: default:
throw new Doctrine_DataDict_Sqlite_Exception('unknown database attribute type: '.$dbType); 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 * Obtain DBMS specific SQL code portion needed to declare an integer type
* field to be used in statements like CREATE TABLE. * field to be used in statements like CREATE TABLE.
* *
* @param string $name name the field to be declared. * @param string $name name the field to be declared.
* @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. * of the field being declared as array indexes.
* Currently, the types of supported field * Currently, the types of supported field
* properties are as follows: * properties are as follows:
* *
* unsigned * unsigned
* Boolean flag that indicates whether the field * Boolean flag that indicates whether the field
* should be declared as unsigned integer if * should be declared as unsigned integer if
* possible. * possible.
* *
* default * default
* Integer value to be used as default for this * Integer value to be used as default for this
* field. * field.
* *
* notnull * notnull
* Boolean flag that indicates whether this field is * Boolean flag that indicates whether this field is
* constrained to not be set to null. * constrained 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.
* @access protected * @access protected
*/ */
public function getIntegerDeclaration($name, array $field) public function getIntegerDeclaration($name, array $field)
{ {
$default = $autoinc = ''; $default = $autoinc = '';
$type = $this->getNativeDeclaration($field); $type = $this->getNativeDeclaration($field);
if (isset($field['autoincrement']) && $field['autoincrement']) { if (isset($field['autoincrement']) && $field['autoincrement']) {
$autoinc = ' PRIMARY KEY AUTOINCREMENT'; $autoinc = ' PRIMARY KEY AUTOINCREMENT';
$type = 'INTEGER'; $type = 'INTEGER';
} elseif (array_key_exists('default', $field)) { } elseif (array_key_exists('default', $field)) {
if ($field['default'] === '') { if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0; $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'])) { elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL'; $default = ' DEFAULT NULL';
} }
*/ */
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : ''; $notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : ''; $unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : '';
$name = $this->conn->quoteIdentifier($name, true); $name = $this->conn->quoteIdentifier($name, true);
return $name . ' ' . $type . $unsigned . $default . $notnull . $autoinc; return $name . ' ' . $type . $unsigned . $default . $notnull . $autoinc;
} }
} }