2006-10-27 19:07:22 +04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.phpdoctrine.com>.
|
|
|
|
*/
|
|
|
|
Doctrine::autoload('Doctrine_DataDict');
|
|
|
|
/**
|
2006-11-15 00:47:08 +03:00
|
|
|
* @package Doctrine
|
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
2006-10-27 19:07:22 +04:00
|
|
|
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
|
2006-11-15 00:47:08 +03:00
|
|
|
* @version $Revision$
|
|
|
|
* @category Object Relational Mapping
|
|
|
|
* @link www.phpdoctrine.com
|
|
|
|
* @since 1.0
|
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
class Doctrine_DataDict_Informix extends Doctrine_DataDict
|
|
|
|
{
|
2006-12-03 23:05:09 +03:00
|
|
|
/**
|
|
|
|
* Obtain DBMS specific SQL code portion needed to declare an text type
|
|
|
|
* field to be used in statements like CREATE TABLE.
|
|
|
|
*
|
|
|
|
* @param array $field associative array with the name of the properties
|
|
|
|
* of the field being declared as array indexes. Currently, the types
|
|
|
|
* of supported field properties are as follows:
|
|
|
|
*
|
|
|
|
* length
|
|
|
|
* Integer value that determines the maximum length of the text
|
|
|
|
* field. If this argument is missing the field should be
|
|
|
|
* declared to have the longest length allowed by the DBMS.
|
|
|
|
*
|
|
|
|
* default
|
|
|
|
* Text value to be used as default for this field.
|
|
|
|
*
|
|
|
|
* notnull
|
|
|
|
* Boolean flag that indicates whether this field is constrained
|
|
|
|
* to not be set to null.
|
|
|
|
*
|
|
|
|
* @return string DBMS specific SQL code portion that should be used to
|
|
|
|
* declare the specified field.
|
|
|
|
*/
|
2006-12-29 17:40:47 +03:00
|
|
|
public function getNativeDeclaration($field)
|
|
|
|
{
|
2007-09-03 18:57:18 +04:00
|
|
|
if ( ! isset($field['type'])) {
|
2007-04-18 15:11:07 +04:00
|
|
|
throw new Doctrine_DataDict_Exception('Missing column type.');
|
2007-09-03 18:57:18 +04:00
|
|
|
}
|
2006-12-03 23:05:09 +03:00
|
|
|
switch ($field['type']) {
|
2006-12-30 00:30:37 +03:00
|
|
|
case 'char':
|
|
|
|
case 'varchar':
|
|
|
|
case 'array':
|
|
|
|
case 'object':
|
|
|
|
case 'string':
|
|
|
|
if (empty($field['length']) && array_key_exists('default', $field)) {
|
|
|
|
$field['length'] = $this->conn->varchar_max_length;
|
2006-12-03 23:05:09 +03:00
|
|
|
}
|
2006-12-30 00:46:14 +03:00
|
|
|
|
2007-09-03 18:57:18 +04:00
|
|
|
$length = ( ! empty($field['length'])) ? $field['length'] : false;
|
2006-12-30 00:30:37 +03:00
|
|
|
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
|
2006-12-30 00:46:14 +03:00
|
|
|
|
2006-12-30 00:30:37 +03:00
|
|
|
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR(255)')
|
|
|
|
: ($length ? 'VARCHAR('.$length.')' : 'NVARCHAR');
|
|
|
|
case 'clob':
|
|
|
|
return 'TEXT';
|
|
|
|
case 'blob':
|
|
|
|
return 'BLOB';
|
|
|
|
case 'integer':
|
2007-09-03 18:57:18 +04:00
|
|
|
if ( ! empty($field['length'])) {
|
2006-12-30 00:30:37 +03:00
|
|
|
$length = $field['length'];
|
|
|
|
if ($length <= 1) {
|
|
|
|
return 'SMALLINT';
|
|
|
|
} elseif ($length == 2) {
|
|
|
|
return 'SMALLINT';
|
|
|
|
} elseif ($length == 3 || $length == 4) {
|
|
|
|
return 'INTEGER';
|
|
|
|
} elseif ($length > 4) {
|
|
|
|
return 'DECIMAL(20)';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 'INT';
|
|
|
|
case 'boolean':
|
|
|
|
return 'SMALLINT';
|
|
|
|
case 'date':
|
|
|
|
return 'DATE';
|
|
|
|
case 'time':
|
|
|
|
return 'DATETIME YEAR TO SECOND';
|
|
|
|
case 'timestamp':
|
|
|
|
return 'DATETIME';
|
|
|
|
case 'float':
|
|
|
|
return 'FLOAT';
|
|
|
|
case 'decimal':
|
|
|
|
return 'DECIMAL';
|
2006-12-03 23:05:09 +03:00
|
|
|
}
|
2007-04-18 15:11:07 +04:00
|
|
|
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
|
2006-12-03 23:05:09 +03:00
|
|
|
}
|
2006-11-15 00:47:08 +03:00
|
|
|
}
|