cvs: pear /MDB2/MDB2/Driver/Datatype Common.php fbsql.php ibase.php mssql.php mysql.php mysqli.php oci8.php pgsql.php sqlite.php

From: Date: Fri, 14 Oct 2005 22:39:54 +0000
Subject: cvs: pear /MDB2/MDB2/Driver/Datatype Common.php fbsql.php ibase.php mssql.php mysql.php mysqli.php oci8.php pgsql.php sqlite.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-35555@lists.php.net to get a copy of this message
lsmith Fri Oct 14 18:39:54 2005 EDT Modified files: /pear/MDB2/MDB2/Driver/Datatype Common.php fbsql.php ibase.php mssql.php mysql.php mysqli.php oci8.php pgsql.php sqlite.php Log: - refactored get*Declaration() methods to use getTypeDeclaration() - quote field names in get*Declaration methods

http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/Common.php?r1=1.44&r2=1.45&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/Common.php diff -u pear/MDB2/MDB2/Driver/Datatype/Common.php:1.44 pear/MDB2/MDB2/Driver/Datatype/Common.php:1.45 --- pear/MDB2/MDB2/Driver/Datatype/Common.php:1.44 Mon Oct 10 03:41:25 2005 +++ pear/MDB2/MDB2/Driver/Datatype/Common.php Fri Oct 14 18:39:52 2005 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.44 2005/10/10 07:41:25 lsmith Exp $ +// $Id: Common.php,v 1.45 2005/10/14 22:39:52 lsmith Exp $ require_once 'MDB2/LOB.php'; @@ -254,6 +254,105 @@ } // }}} + // {{{ getTypeDeclaration() + + /** + * 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. + * @access public + */ + function getTypeDeclaration($field) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + + switch ($field['type']) { + case 'text': + return array_key_exists('length', $field) ? 'CHAR ('.$field['length'].')' : 'TEXT'; + case 'clob': + return 'TEXT'; + case 'blob': + return 'TEXT'; + case 'integer': + return 'INT'; + case 'boolean': + return 'CHAR (1)'; + case 'date': + return 'CHAR ('.strlen('YYYY-MM-DD').')'; + case 'time': + return 'CHAR ('.strlen('HH:MM:SS').')'; + case 'timestamp': + return 'CHAR ('.strlen('YYYY-MM-DD HH:MM:SS').')'; + case 'float': + return 'TEXT'; + case 'decimal': + return 'TEXT'; + } + return ''; + } + + // }}} + // {{{ _getDeclaration() + + /** + * Obtain DBMS specific SQL code portion needed to declare a generic 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 + * 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. + * @access protected + */ + function _getDeclaration($name, $field) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + + $default = array_key_exists('default', $field) ? ' DEFAULT '. + $this->quote($field['default'], $field['type']) : ''; + $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; + $name = $db->quoteIdentifier($name); + return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; + } + + // }}} // {{{ _getIntegerDeclaration() /** @@ -289,10 +388,7 @@ $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer"; } - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'integer') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' INT'.$default.$notnull; + return $this->_getDeclaration($name, $field); } // }}} @@ -324,11 +420,7 @@ */ function _getTextDeclaration($name, $field) { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'text') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - $type = array_key_exists('length', $field) ? 'CHAR ('.$field['length'].')' : 'TEXT'; - return $name.' '.$type.$default.$notnull; + return $this->_getDeclaration($name, $field); } // }}} @@ -340,26 +432,31 @@ * * @param string $name name the field to be declared. * @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: + * 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 large - * object field. If this argument is missing the field should be - * declared to have the longest length allowed by the DBMS. - * - * notnull - * Boolean flag that indicates whether this field is constrained - * to not be set to null. + * length + * Integer value that determines the maximum length of the large + * object field. If this argument is missing the field should be + * declared to have the longest length allowed by the DBMS. + * + * 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. - * @access protected + * declare the specified field. + * @access public */ function _getCLOBDeclaration($name, $field) { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - $type = array_key_exists('length', $field) ? 'CHAR ('.$field['length'].')' : 'TEXT'; - return $name.' '.$type.$notnull; + $name = $db->quoteIdentifier($name); + return $name.' '.$this->getTypeDeclaration($field).$notnull; } // }}} @@ -371,26 +468,31 @@ * * @param string $name name the field to be declared. * @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 large - * object field. If this argument is missing the field should be - * declared to have the longest length allowed by the DBMS. + * of the field being declared as array indexes. Currently, the types + * of supported field properties are as follows: * - * notnull - * Boolean flag that indicates whether this field is constrained - * to not be set to null. + * length + * Integer value that determines the maximum length of the large + * object field. If this argument is missing the field should be + * declared to have the longest length allowed by the DBMS. + * + * 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. + * declare the specified field. * @access protected */ function _getBLOBDeclaration($name, $field) { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - $type = array_key_exists('length', $field) ? 'CHAR ('.$field['length'].')' : 'TEXT'; - return $name.' '.$type.$notnull; + $name = $db->quoteIdentifier($name); + return $name.' '.$this->getTypeDeclaration($field).$notnull; } // }}} @@ -417,10 +519,7 @@ */ function _getBooleanDeclaration($name, $field) { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'boolean') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' CHAR (1)'.$default.$notnull; + return $this->_getDeclaration($name, $field); } // }}} @@ -447,10 +546,7 @@ */ function _getDateDeclaration($name, $field) { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'date') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' CHAR ('.strlen('YYYY-MM-DD').')'.$default.$notnull; + return $this->_getDeclaration($name, $field); } // }}} @@ -477,10 +573,7 @@ */ function _getTimestampDeclaration($name, $field) { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'timestamp') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' CHAR ('.strlen('YYYY-MM-DD HH:MM:SS').')'.$default.$notnull; + return $this->_getDeclaration($name, $field); } // }}} @@ -507,10 +600,7 @@ */ function _getTimeDeclaration($name, $field) { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'time') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' CHAR ('.strlen('HH:MM:SS').')'.$default.$notnull; + return $this->_getDeclaration($name, $field); } // }}} @@ -537,10 +627,7 @@ */ function _getFloatDeclaration($name, $field) { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'float') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' TEXT'.$default.$notnull; + return $this->_getDeclaration($name, $field); } // }}} @@ -567,10 +654,7 @@ */ function _getDecimalDeclaration($name, $field) { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'decimal') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' TEXT'.$default.$notnull; + return $this->_getDeclaration($name, $field); } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/fbsql.php?r1=1.21&r2=1.22&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/fbsql.php diff -u pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.21 pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.22 --- pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.21 Thu Sep 29 10:38:16 2005 +++ pear/MDB2/MDB2/Driver/Datatype/fbsql.php Fri Oct 14 18:39:52 2005 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.21 2005/09/29 14:38:16 lsmith Exp $ +// $Id: fbsql.php,v 1.22 2005/10/14 22:39:52 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -89,341 +89,62 @@ } // }}} - // {{{ _getIntegerDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an integer type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * unsigned - * Boolean flag that indicates whether the field - * should be declared as unsigned integer if - * possible. - * - * default - * Integer 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. - * @access protected - */ - function _getIntegerDeclaration($name, $field) - { - if (array_key_exists('unsigned', $field) && $field['unsigned']) { - $db =& $this->getDBInstance(); - if (PEAR::isError($db)) { - return $db; - } - - $db->warnings[] = "unsigned integer field \"$name\" is being - declared as signed integer"; - } - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'integer') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' INT'.$default.$notnull; - } - - // }}} - // {{{ _getTextDeclaration() + // {{{ getTypeDeclaration() /** * Obtain DBMS specific SQL code portion needed to declare an text 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 - * 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. - * @access protected - */ - function _getTextDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'text') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - $length = array_key_exists('length', $field) ? $field['length'] : 32768; - return $name.' VARCHAR ('.$length.')'.$default.$notnull; - } - - // }}} - // {{{ _getCLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an character - * large object type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the - * properties of the field being declared as array - * indexes. Currently, the types of supported field - * properties are as follows: - * - * length - * Integer value that determines the maximum length - * of the large object field. If this argument is - * missing the field should be declared to have the - * longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getCLOBDeclaration($name, $field) - { - return "$name CLOB".((array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''); - } - - // }}} - // {{{ _getBLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an binary large - * object type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * length - * Integer value that determines the maximum length - * of the large object field. If this argument is - * missing the field should be declared to have the - * longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getBLOBDeclaration($name, $field) - { - return "$name BLOB".((array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''); - } - - // }}} - // {{{ _getBooleanDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a boolean 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Boolean value to be used as default for this field. - * - * notnullL - * 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. - * @access protected - */ - function _getBooleanDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'boolean') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' BOOLEAN)'.$default.$notnull; - } - - // }}} - // {{{ _getDateDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an date type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field properties - * are as follows: - * - * default - * Date 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. - * @access protected - */ - function _getDateDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT DATE '. - $this->quote($field['default'], 'date') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' DATE'.$default.$notnull; - } - - // }}} - // {{{ _getTimestampDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an timestamp - * type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * default - * Time stamp 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. - * @access protected - */ - function _getTimestampDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT TIMESTAMP '. - $this->quote($field['default'], 'timestamp') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' TIMESTAMP'.$default.$notnull; - } - - // }}} - // {{{ _getTimeDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an time type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * default - * Time 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. + * @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. - * @access protected - */ - function _getTimeDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT TIME '. - $this->quote($field['default'], 'time') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' TIME'.$default.$notnull; - } - - // }}} - // {{{ _getFloatDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an float type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * default - * Integer 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. - * @access protected - */ - function _getFloatDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'float') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' FLOAT'.$default.$notnull; - } - - // }}} - // {{{ _getDecimalDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an decimal type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * default - * Integer 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. - * @access protected + * declare the specified field. + * @access public */ - function _getDecimalDeclaration($name, $field) + function getTypeDeclaration($field) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - $type = 'DECIMAL(18,'.$db->options['decimal_places'].')'; - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'decimal') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$default.$notnull; + switch ($field['type']) { + case 'text': + $length = (array_key_exists('length', $field) ? $field['length'] : (!PEAR::isError($length = $db->options['default_text_field_length']) ? $length : 4000)); + return 'VARCHAR ('.$length.')'; + case 'clob': + return 'CLOB'; + case 'blob': + return 'BLOB'; + case 'integer': + return 'INT'; + case 'boolean': + return 'BOOLEAN'; + case 'date': + return 'DATE'; + case 'time': + return 'TIME'; + case 'timestamp': + return 'TIMESTAMP'; + case 'float': + return 'FLOAT'; + case 'decimal': + return 'DECIMAL(18,'.$db->options['decimal_places'].')'; + } + return ''; } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/ibase.php?r1=1.44&r2=1.45&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/ibase.php diff -u pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.44 pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.45 --- pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.44 Fri Oct 14 12:30:56 2005 +++ pear/MDB2/MDB2/Driver/Datatype/ibase.php Fri Oct 14 18:39:52 2005 @@ -44,7 +44,7 @@ // | Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.44 2005/10/14 16:30:56 lsmith Exp $ +// $Id: ibase.php,v 1.45 2005/10/14 22:39:52 lsmith Exp $ require_once 'MDB2/Driver/Datatype/Common.php'; @@ -130,7 +130,7 @@ case 'blob': return 'BLOB SUB_TYPE 0'; case 'integer': - return 'INTEGER'; + return 'INT'; case 'boolean': return 'CHAR (1)'; case 'date': @@ -175,267 +175,24 @@ */ function _getIntegerDeclaration($name, $field) { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + if (array_key_exists('unsigned', $field) && $field['unsigned']) { - $db =& $this->getDBInstance(); - if (PEAR::isError($db)) { - return $db; - } $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer"; } if (array_key_exists('autoincrement', $field) && $field['autoincrement']) { + $name = $db->quoteIdentifier($name); return $name.' PRIMARY KEY'; } $default = array_key_exists('default', $field) ? ' DEFAULT '. $this->quote($field['default'], 'integer') : ''; $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' INT'.$default.$notnull; - } - - // }}} - // {{{ _getTextDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a text 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 - * 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. - * @access protected - */ - function _getTextDeclaration($name, $field) - { - $type = $this->getTypeDeclaration($field); - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'text') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$default.$notnull; - } - - // }}} - // {{{ _getCLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a character - * large object 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 - * 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 large - * object field. If this argument is missing the field should be - * declared to have the longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getCLOBDeclaration($name, $field) - { - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$notnull; - } - - // }}} - // {{{ _getBLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a binary large - * object 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 - * 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 large - * object field. If this argument is missing the field should be - * declared to have the longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getBLOBDeclaration($name, $field) - { - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$notnull; - } - - // }}} - // {{{ _getDateDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a date 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Date 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. - * @access protected - */ - function _getDateDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'date') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getTimeDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a time - * 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Time 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. - * @access protected - */ - function _getTimeDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'time') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getTimestampDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a timestamp - * 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Timestamp 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. - * @access protected - */ - function _getTimestampDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'timestamp') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getFloatDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a float 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Float 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. - * @access protected - */ - function _getFloatDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'float') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getDecimalDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a decimal 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Decimal 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. - * @access protected - */ - function _getDecimalDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'decimal') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; + $name = $db->quoteIdentifier($name); return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mssql.php?r1=1.22&r2=1.23&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mssql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.22 pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.23 --- pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.22 Thu Sep 29 10:38:16 2005 +++ pear/MDB2/MDB2/Driver/Datatype/mssql.php Fri Oct 14 18:39:52 2005 @@ -44,7 +44,7 @@ // | Daniel Convissor <danielc@php.net> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.22 2005/09/29 14:38:16 lsmith Exp $ +// $Id: mssql.php,v 1.23 2005/10/14 22:39:52 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -90,357 +90,74 @@ return $this->_baseConvertResult($value,$type); } } - - // }}} - // {{{ _getIntegerDeclaration() - - /** - * 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * unsigned - * Boolean flag that indicates whether the field should be - * declared as unsigned integer if possible. - * - * default - * Integer 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. - * @access protected - */ - function _getIntegerDeclaration($name, $field) - { - if (array_key_exists('unsigned', $field) && $field['unsigned']) { - $db =& $this->getDBInstance(); - if (PEAR::isError($db)) { - return $db; - } - - $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer"; - } - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'integer') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ' NULL'; - return $name.' INT'.$default.$notnull; - } - // }}} - // {{{ _getTextDeclaration() + // {{{ getTypeDeclaration() /** * Obtain DBMS specific SQL code portion needed to declare an text 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 - * 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. - * @access protected - */ - function _getTextDeclaration($name, $field) - { - $type = array_key_exists('length', $field) ? 'VARCHAR ('.$field['length'].')' : 'TEXT'; - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'text') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ' NULL'; - return $name.' '.$type.$default.$notnull; - } - - // }}} - // {{{ _getCLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an character - * large object type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the - * properties of the field being declared as array - * indexes. Currently, the types of supported field - * properties are as follows: - * - * length - * Integer value that determines the maximum length - * of the large object field. If this argument is - * missing the field should be declared to have the - * longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getCLOBDeclaration($name, $field) - { - if (array_key_exists('length', $field)) { - $length = $field['length']; - if ($length <= 8000) { - $type = "VARCHAR($length)"; - } else { - $type = 'TEXT'; - } - } else { - $type = 'TEXT'; - } - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ' NULL'; - return $name.' '.$type.$notnull; - } - - // }}} - // {{{ _getBLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an binary large - * object type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * length - * Integer value that determines the maximum length - * of the large object field. If this argument is - * missing the field should be declared to have the - * longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getBLOBDeclaration($name, $field) - { - if (array_key_exists('length', $field)) { - $length = $field['length']; - if ($length <= 8000) { - $type = "VARBINARY($length)"; - } else { - $type = 'IMAGE'; - } - } else { - $type = 'IMAGE'; - } - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ' NULL'; - return $name.' '.$type.$notnull; - } - - // }}} - // {{{ _getBooleanDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a boolean 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Boolean 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. - * @access protected - */ - function _getBooleanDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'boolean') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ' NULL'; - return $name.' BIT'.$default.$notnull; - } - - // }}} - // {{{ _getDateDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a date 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Date 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. - * @access protected - */ - function _getDateDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'date') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ' NULL'; - return $name.' CHAR ('.strlen('YYYY-MM-DD').')'.$default.$notnull; - } - - // }}} - // {{{ _getTimestampDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a timestamp - * 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Timestamp 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. - * @access protected - */ - function _getTimestampDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'timestamp') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ' NULL'; - return $name.' CHAR ('.strlen('YYYY-MM-DD HH:MM:SS').')'.$default.$notnull; - } - - // }}} - // {{{ _getTimeDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a time - * 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Time 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. - * @access protected - */ - function _getTimeDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'time') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ' NULL'; - return $name.' CHAR ('.strlen('HH:MM:SS').')'.$default.$notnull; - } - - // }}} - // {{{ _getFloatDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an float type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * default - * Integer 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. - * @access protected - */ - function _getFloatDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'float') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ' NULL'; - return $name.' FLOAT'.$default.$notnull; - } - - // }}} - // {{{ _getDecimalDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an decimal type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * default - * Integer 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. + * @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. - * @access protected + * declare the specified field. + * @access public */ - function _getDecimalDeclaration($name, $field) + function getTypeDeclaration($field) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - $type = 'DECIMAL(18,'.$db->options['decimal_places'].')'; - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'decimal') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ' NULL'; - return $name.' '.$type.$default.$notnull; + switch ($field['type']) { + case 'text': + return array_key_exists('length', $field) ? 'VARCHAR ('.$field['length'].')' : 'TEXT'; + case 'clob': + if (array_key_exists('length', $field)) { + $length = $field['length']; + if ($length <= 8000) { + return "VARCHAR($length)"; + } + } + return 'TEXT'; + case 'blob': + if (array_key_exists('length', $field)) { + $length = $field['length']; + if ($length <= 8000) { + return "VARBINARY($length)"; + } + } + return 'IMAGE'; + case 'integer': + return 'INT'; + case 'boolean': + return 'BIT'; + case 'date': + return 'CHAR ('.strlen('YYYY-MM-DD').')'; + case 'time': + return 'CHAR ('.strlen('HH:MM:SS').')'; + case 'timestamp': + return 'CHAR ('.strlen('YYYY-MM-DD HH:MM:SS').')'; + case 'float': + return 'FLOAT'; + case 'decimal': + return 'DECIMAL(18,'.$db->options['decimal_places'].')'; + } + return ''; } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mysql.php?r1=1.20&r2=1.21&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mysql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.20 pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.21 --- pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.20 Thu Sep 29 10:45:36 2005 +++ pear/MDB2/MDB2/Driver/Datatype/mysql.php Fri Oct 14 18:39:52 2005 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.20 2005/09/29 14:45:36 lsmith Exp $ +// $Id: mysql.php,v 1.21 2005/10/14 22:39:52 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -58,249 +58,92 @@ class MDB2_Driver_Datatype_mysql extends MDB2_Driver_Datatype_Common { // }}} - // {{{ _getIntegerDeclaration() + // {{{ getTypeDeclaration() /** - * Obtain DBMS specific SQL code portion needed to declare an integer type + * Obtain DBMS specific SQL code portion needed to declare an text type * field to be used in statements like CREATE TABLE. * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * unsigned - * Boolean flag that indicates whether the field - * should be declared as unsigned integer if - * possible. - * - * default - * Integer 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. + * @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. - * @access protected + * declare the specified field. + * @access public */ - function _getIntegerDeclaration($name, $field) + function getTypeDeclaration($field) { - if (array_key_exists('autoincrement', $field) && $field['autoincrement']) { - $autoinc = ' AUTO_INCREMENT PRIMARY KEY'; - $default = ''; - } else { - $autoinc = ''; - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'integer') : ''; + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; } - $unsigned = (array_key_exists('unsigned', $field) && $field['unsigned']) ? ' UNSIGNED' : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' INT'.$unsigned.$default.$notnull.$autoinc; - } - - // }}} - // {{{ _getCLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an character - * large object type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the - * properties of the field being declared as array - * indexes. Currently, the types of supported field - * properties are as follows: - * - * length - * Integer value that determines the maximum length - * of the large object field. If this argument is - * missing the field should be declared to have the - * longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getCLOBDeclaration($name, $field) - { - if (array_key_exists('length', $field)) { - $length = $field['length']; - if ($length <= 255) { - $type = 'TINYTEXT'; - } else { - if ($length <= 65535) { - $type = 'TEXT'; + switch ($field['type']) { + case 'text': + return array_key_exists('length', $field) ? 'CHAR ('.$field['length'].')' : 'TEXT'; + case 'clob': + if (array_key_exists('length', $field)) { + $length = $field['length']; + if ($length <= 255) { + return 'TINYTEXT'; } else { - if ($length <= 16777215) { - $type = 'MEDIUMTEXT'; - } else { - $type = 'LONGTEXT'; + if ($length <= 65535) { + return 'TEXT'; + } elseif ($length <= 16777215) { + return 'MEDIUMTEXT'; } } } - } else { - $type = 'LONGTEXT'; - } - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$notnull; - } - - // }}} - // {{{ _getBLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an binary large - * object type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * length - * Integer value that determines the maximum length - * of the large object field. If this argument is - * missing the field should be declared to have the - * longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getBLOBDeclaration($name, $field) - { - if (array_key_exists('length', $field)) { - $length = $field['length']; - if ($length <= 255) { - $type = 'TINYBLOB'; - } else { - if ($length <= 65535) { - $type = 'BLOB'; + return 'LONGTEXT'; + case 'blob': + if (array_key_exists('length', $field)) { + $length = $field['length']; + if ($length <= 255) { + return 'TINYBLOB'; } else { - if ($length <= 16777215) { + if ($length <= 65535) { + return 'BLOB'; + } elseif ($length <= 16777215) { $type = 'MEDIUMBLOB'; - } else { - $type = 'LONGBLOB'; } } } - } else { - $type = 'LONGBLOB'; + return 'LONGBLOB'; + case 'integer': + return 'INT'; + case 'boolean': + return 'BOOLEAN'; + case 'date': + return 'DATE'; + case 'time': + return 'TIME'; + case 'timestamp': + return 'DATETIME'; + case 'float': + return 'DOUBLE'; + case 'decimal': + return 'DECIMAL(18,'.$db->options['decimal_places'].')'; } - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$notnull; - } - - // }}} - // {{{ _getDateDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an date type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field properties - * are as follows: - * - * default - * Date 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. - * @access protected - */ - function _getDateDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'date') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' DATE'.$default.$notnull; - } - - // }}} - // {{{ _getTimestampDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an timestamp - * type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * default - * Time stamp 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. - * @access protected - */ - function _getTimestampDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'timestamp') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' DATETIME'.$default.$notnull; + return ''; } // }}} - // {{{ _getTimeDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an time type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * default - * Time 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. - * @access protected - */ - function _getTimeDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'time') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' TIME'.$default.$notnull; - } - - // }}} - // {{{ _getFloatDeclaration() + // {{{ _getIntegerDeclaration() /** - * Obtain DBMS specific SQL code portion needed to declare an float type + * 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. @@ -309,38 +152,10 @@ * Currently, the types of supported field * properties are as follows: * - * default - * Integer 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. - * @access protected - */ - function _getFloatDeclaration($name, $field) - { - $type = 'DOUBLE'; - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'float') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$default.$notnull; - } - - // }}} - // {{{ _getDecimalDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an decimal type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: + * unsigned + * Boolean flag that indicates whether the field + * should be declared as unsigned integer if + * possible. * * default * Integer value to be used as default for this @@ -353,18 +168,26 @@ * declare the specified field. * @access protected */ - function _getDecimalDeclaration($name, $field) + function _getIntegerDeclaration($name, $field) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - $type = 'DECIMAL(18,'.$db->options['decimal_places'].')'; - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'decimal') : ''; + if (array_key_exists('autoincrement', $field) && $field['autoincrement']) { + $autoinc = ' AUTO_INCREMENT PRIMARY KEY'; + $default = ''; + } else { + $autoinc = ''; + $default = array_key_exists('default', $field) ? ' DEFAULT '. + $this->quote($field['default'], 'integer') : ''; + } + + $unsigned = (array_key_exists('unsigned', $field) && $field['unsigned']) ? ' UNSIGNED' : ''; $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$default.$notnull; + $name = $db->quoteIdentifier($name); + return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc; } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mysqli.php?r1=1.15&r2=1.16&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mysqli.php diff -u pear/MDB2/MDB2/Driver/Datatype/mysqli.php:1.15 pear/MDB2/MDB2/Driver/Datatype/mysqli.php:1.16 --- pear/MDB2/MDB2/Driver/Datatype/mysqli.php:1.15 Wed Oct 5 07:02:16 2005 +++ pear/MDB2/MDB2/Driver/Datatype/mysqli.php Fri Oct 14 18:39:52 2005 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysqli.php,v 1.15 2005/10/05 11:02:16 lsmith Exp $ +// $Id: mysqli.php,v 1.16 2005/10/14 22:39:52 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -58,249 +58,92 @@ class MDB2_Driver_Datatype_mysqli extends MDB2_Driver_Datatype_Common { // }}} - // {{{ _getIntegerDeclaration() + // {{{ getTypeDeclaration() /** - * Obtain DBMS specific SQL code portion needed to declare an integer type + * Obtain DBMS specific SQL code portion needed to declare an text type * field to be used in statements like CREATE TABLE. * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * unsigned - * Boolean flag that indicates whether the field - * should be declared as unsigned integer if - * possible. - * - * default - * Integer 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. + * @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. - * @access protected + * declare the specified field. + * @access public */ - function _getIntegerDeclaration($name, $field) + function getTypeDeclaration($field) { - if (array_key_exists('autoincrement', $field) && $field['autoincrement']) { - $autoinc = ' AUTO_INCREMENT PRIMARY KEY'; - $default = ''; - } else { - $autoinc = ''; - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'integer') : ''; + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; } - $unsigned = (array_key_exists('unsigned', $field) && $field['unsigned']) ? ' UNSIGNED' : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' INT'.$unsigned.$default.$notnull.$autoinc; - } - - // }}} - // {{{ _getCLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an character - * large object type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the - * properties of the field being declared as array - * indexes. Currently, the types of supported field - * properties are as follows: - * - * length - * Integer value that determines the maximum length - * of the large object field. If this argument is - * missing the field should be declared to have the - * longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getCLOBDeclaration($name, $field) - { - if (array_key_exists('length', $field)) { - $length = $field['length']; - if ($length <= 255) { - $type = 'TINYTEXT'; - } else { - if ($length <= 65535) { - $type = 'TEXT'; + switch ($field['type']) { + case 'text': + return array_key_exists('length', $field) ? 'CHAR ('.$field['length'].')' : 'TEXT'; + case 'clob': + if (array_key_exists('length', $field)) { + $length = $field['length']; + if ($length <= 255) { + return 'TINYTEXT'; } else { - if ($length <= 16777215) { - $type = 'MEDIUMTEXT'; - } else { - $type = 'LONGTEXT'; + if ($length <= 65535) { + return 'TEXT'; + } elseif ($length <= 16777215) { + return 'MEDIUMTEXT'; } } } - } else { - $type = 'LONGTEXT'; - } - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$notnull; - } - - // }}} - // {{{ _getBLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an binary large - * object type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * length - * Integer value that determines the maximum length - * of the large object field. If this argument is - * missing the field should be declared to have the - * longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getBLOBDeclaration($name, $field) - { - if (array_key_exists('length', $field)) { - $length = $field['length']; - if ($length <= 255) { - $type = 'TINYBLOB'; - } else { - if ($length <= 65535) { - $type = 'BLOB'; + return 'LONGTEXT'; + case 'blob': + if (array_key_exists('length', $field)) { + $length = $field['length']; + if ($length <= 255) { + return 'TINYBLOB'; } else { - if ($length <= 16777215) { + if ($length <= 65535) { + return 'BLOB'; + } elseif ($length <= 16777215) { $type = 'MEDIUMBLOB'; - } else { - $type = 'LONGBLOB'; } } } - } else { - $type = 'LONGBLOB'; + return 'LONGBLOB'; + case 'integer': + return 'INT'; + case 'boolean': + return 'BOOLEAN'; + case 'date': + return 'DATE'; + case 'time': + return 'TIME'; + case 'timestamp': + return 'DATETIME'; + case 'float': + return 'DOUBLE'; + case 'decimal': + return 'DECIMAL(18,'.$db->options['decimal_places'].')'; } - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$notnull; - } - - // }}} - // {{{ _getDateDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an date type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field properties - * are as follows: - * - * default - * Date 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. - * @access protected - */ - function _getDateDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'date') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' DATE'.$default.$notnull; - } - - // }}} - // {{{ _getTimestampDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an timestamp - * type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * default - * Time stamp 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. - * @access protected - */ - function _getTimestampDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'timestamp') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' DATETIME'.$default.$notnull; + return ''; } // }}} - // {{{ _getTimeDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an time type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * default - * Time 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. - * @access protected - */ - function _getTimeDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'time') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' TIME'.$default.$notnull; - } - - // }}} - // {{{ _getFloatDeclaration() + // {{{ _getIntegerDeclaration() /** - * Obtain DBMS specific SQL code portion needed to declare an float type + * 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. @@ -309,38 +152,10 @@ * Currently, the types of supported field * properties are as follows: * - * default - * Integer 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. - * @access protected - */ - function _getFloatDeclaration($name, $field) - { - $type = 'DOUBLE'; - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'float') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$default.$notnull; - } - - // }}} - // {{{ _getDecimalDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an decimal type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: + * unsigned + * Boolean flag that indicates whether the field + * should be declared as unsigned integer if + * possible. * * default * Integer value to be used as default for this @@ -353,18 +168,26 @@ * declare the specified field. * @access protected */ - function _getDecimalDeclaration($name, $field) + function _getIntegerDeclaration($name, $field) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - $type = 'DECIMAL(18,'.$db->options['decimal_places'].')'; - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'decimal') : ''; + if (array_key_exists('autoincrement', $field) && $field['autoincrement']) { + $autoinc = ' AUTO_INCREMENT PRIMARY KEY'; + $default = ''; + } else { + $autoinc = ''; + $default = array_key_exists('default', $field) ? ' DEFAULT '. + $this->quote($field['default'], 'integer') : ''; + } + + $unsigned = (array_key_exists('unsigned', $field) && $field['unsigned']) ? ' UNSIGNED' : ''; $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$default.$notnull; + $name = $db->quoteIdentifier($name); + return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc; } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/oci8.php?r1=1.33&r2=1.34&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/oci8.php diff -u pear/MDB2/MDB2/Driver/Datatype/oci8.php:1.33 pear/MDB2/MDB2/Driver/Datatype/oci8.php:1.34 --- pear/MDB2/MDB2/Driver/Datatype/oci8.php:1.33 Fri Oct 7 09:02:32 2005 +++ pear/MDB2/MDB2/Driver/Datatype/oci8.php Fri Oct 14 18:39:52 2005 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.33 2005/10/07 13:02:32 lsmith Exp $ +// $Id: oci8.php,v 1.34 2005/10/14 22:39:52 lsmith Exp $ require_once 'MDB2/Driver/Datatype/Common.php'; @@ -137,295 +137,6 @@ } // }}} - // {{{ _getIntegerDeclaration() - - /** - * 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * unsigned - * Boolean flag that indicates whether the field should be - * declared as unsigned integer if possible. - * - * default - * Integer 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. - * @param string $table name of the current table being processed - * by alterTable(), used for autoincrement emulation - * @return string DBMS specific SQL code portion that should be used to - * declare the specified field. - * @access protected - */ - function _getIntegerDeclaration($name, $field, $table = null) - { - if (array_key_exists('unsigned', $field) && $field['unsigned']) { - $db =& $this->getDBInstance(); - if (PEAR::isError($db)) { - return $db; - } - $db->warning[] = "unsigned integer field \"$name\" is being declared as signed integer"; - } - - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'integer') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getTextDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an text 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 - * 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. - * @access protected - */ - function _getTextDeclaration($name, $field) - { - $type = $this->getTypeDeclaration($field); - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'text') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$default.$notnull; - } - - // }}} - // {{{ _getCLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an character - * large object 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 - * 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 large - * object field. If this argument is missing the field should be - * declared to have the longest length allowed by the DBMS. - * - * 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. - * @access public - */ - function _getCLOBDeclaration($name, $field) - { - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$notnull; - } - - // }}} - // {{{ _getBLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an binary large - * object 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 - * 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 large - * object field. If this argument is missing the field should be - * declared to have the longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getBLOBDeclaration($name, $field) - { - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$notnull; - } - - // }}} - // {{{ _getDateDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a date 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Date 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. - * @access protected - */ - function _getDateDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'date') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getTimestampDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a timestamp - * 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Timestamp 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. - * @access protected - */ - function _getTimestampDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'timestamp') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } - - // }}} - // {{{ _getTimeDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a time - * 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Time 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. - * @access protected - */ - function _getTimeDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'time') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getFloatDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a float 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Float 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. - * @access protected - */ - function _getFloatDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'float') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getDecimalDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a decimal 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Decimal 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. - * @access protected - */ - function _getDecimalDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'decimal') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} // {{{ _quoteCLOB() /** http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/pgsql.php?r1=1.34&r2=1.35&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/pgsql.php diff -u pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.34 pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.35 --- pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.34 Fri Oct 14 12:30:56 2005 +++ pear/MDB2/MDB2/Driver/Datatype/pgsql.php Fri Oct 14 18:39:53 2005 @@ -42,7 +42,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.34 2005/10/14 16:30:56 lsmith Exp $ +// $Id: pgsql.php,v 1.35 2005/10/14 22:39:53 lsmith Exp $ require_once 'MDB2/Driver/Datatype/Common.php'; @@ -174,300 +174,22 @@ */ function _getIntegerDeclaration($name, $field) { - if (array_key_exists('unsigned', $field) && $field['unsigned']) { - $db =& $this->getDBInstance(); - if (PEAR::isError($db)) { - return $db; - } + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + if (array_key_exists('unsigned', $field) && $field['unsigned']) { $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer"; } if (array_key_exists('autoincrement', $field) && $field['autoincrement']) { + $name = $db->quoteIdentifier($name); return $name.' '.$this->getTypeDeclaration($field); } $default = array_key_exists('default', $field) ? ' DEFAULT '. $this->quote($field['default'], 'integer') : ''; $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getTextDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a text 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 - * 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. - * @access protected - */ - function _getTextDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'text') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getCLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a character - * large object 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 - * 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 large - * object field. If this argument is missing the field should be - * declared to have the longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getCLOBDeclaration($name, $field) - { - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$notnull; - } - - // }}} - // {{{ _getBLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a binary large - * object 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 - * 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 large - * object field. If this argument is missing the field should be - * declared to have the longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getBLOBDeclaration($name, $field) - { - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$notnull; - } - - // }}} - // {{{ _getBooleanDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a boolean 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Boolean value to be used as default for this field. - * - * notnullL - * 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. - * @access protected - */ - function _getBooleanDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'boolean') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getDateDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a date 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Date 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. - * @access protected - */ - function _getDateDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'date') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getTimeDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a time - * 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Time 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. - * @access protected - */ - function _getTimeDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'time') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getTimestampDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a timestamp - * 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Timestamp 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. - * @access protected - */ - function _getTimestampDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'timestamp') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getFloatDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a float 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Float 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. - * @access protected - */ - function _getFloatDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'float') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; - } - - // }}} - // {{{ _getDecimalDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare a decimal 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 - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: - * - * default - * Decimal 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. - * @access protected - */ - function _getDecimalDeclaration($name, $field) - { - $db =& $this->getDBInstance(); - if (PEAR::isError($db)) { - return $db; - } - - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'float') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; + $name = $db->quoteIdentifier($name); return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/sqlite.php?r1=1.26&r2=1.27&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/sqlite.php diff -u pear/MDB2/MDB2/Driver/Datatype/sqlite.php:1.26 pear/MDB2/MDB2/Driver/Datatype/sqlite.php:1.27 --- pear/MDB2/MDB2/Driver/Datatype/sqlite.php:1.26 Fri Oct 14 06:41:58 2005 +++ pear/MDB2/MDB2/Driver/Datatype/sqlite.php Fri Oct 14 18:39:53 2005 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: sqlite.php,v 1.26 2005/10/14 10:41:58 lsmith Exp $ +// $Id: sqlite.php,v 1.27 2005/10/14 22:39:53 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -58,218 +58,93 @@ class MDB2_Driver_Datatype_sqlite extends MDB2_Driver_Datatype_Common { // }}} - // {{{ _getIntegerDeclaration() + // {{{ getTypeDeclaration() /** - * Obtain DBMS specific SQL code portion needed to declare an integer type + * Obtain DBMS specific SQL code portion needed to declare an text type * field to be used in statements like CREATE TABLE. * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * unsigned - * Boolean flag that indicates whether the field - * should be declared as unsigned integer if - * possible. - * - * default - * Integer 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. + * @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. - * @access protected + * declare the specified field. + * @access public */ - function _getIntegerDeclaration($name, $field) + function getTypeDeclaration($field) { - if (array_key_exists('autoincrement', $field) && $field['autoincrement']) { - $autoinc = ' PRIMARY KEY AUTO_INCREMENT'; - $default = ''; - } else { - $autoinc = ''; - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'integer') : ''; + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; } - $unsigned = (array_key_exists('unsigned', $field) && $field['unsigned']) ? ' UNSIGNED' : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' INT'.$unsigned.$default.$notnull.$autoinc; - } - - // }}} - // {{{ _getCLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an character - * large object type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the - * properties of the field being declared as array - * indexes. Currently, the types of supported field - * properties are as follows: - * - * length - * Integer value that determines the maximum length - * of the large object field. If this argument is - * missing the field should be declared to have the - * longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getCLOBDeclaration($name, $field) - { - if (array_key_exists('length', $field)) { - $length = $field['length']; - if ($length <= 255) { - $type = 'TINYTEXT'; - } else { - if ($length <= 65535) { - $type = 'TEXT'; + switch ($field['type']) { + case 'text': + return array_key_exists('length', $field) ? 'CHAR ('.$field['length'].')' : 'TEXT'; + case 'clob': + if (array_key_exists('length', $field)) { + $length = $field['length']; + if ($length <= 255) { + return 'TINYTEXT'; } else { - if ($length <= 16777215) { - $type = 'MEDIUMTEXT'; - } else { - $type = 'LONGTEXT'; + if ($length <= 65535) { + return 'TEXT'; + } elseif ($length <= 16777215) { + return 'MEDIUMTEXT'; } } } - } else { - $type = 'LONGTEXT'; - } - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$notnull; - } - - // }}} - // {{{ _getBLOBDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an binary large - * object type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * length - * Integer value that determines the maximum length - * of the large object field. If this argument is - * missing the field should be declared to have the - * longest length allowed by the DBMS. - * - * 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. - * @access protected - */ - function _getBLOBDeclaration($name, $field) - { - if (array_key_exists('length', $field)) { - $length = $field['length']; - if ($length <= 255) { - $type = 'TINYBLOB'; - } else { - if ($length <= 65535) { - $type = 'BLOB'; + return 'LONGTEXT'; + case 'blob': + if (array_key_exists('length', $field)) { + $length = $field['length']; + if ($length <= 255) { + return 'TINYBLOB'; } else { - if ($length <= 16777215) { + if ($length <= 65535) { + return 'BLOB'; + } elseif ($length <= 16777215) { $type = 'MEDIUMBLOB'; - } else { - $type = 'LONGBLOB'; } } } - } else { - $type = 'LONGBLOB'; + return 'LONGBLOB'; + case 'integer': + return 'INT'; + case 'boolean': + return 'BOOLEAN'; + case 'date': + return 'DATE'; + case 'time': + return 'TIME'; + case 'timestamp': + return 'DATETIME'; + case 'float': + return 'DOUBLE'.($db->options['fixed_float'] ? '('. + ($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : ''); + case 'decimal': + return 'BIGINT'; } - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$notnull; - } - - // }}} - // {{{ _getDateDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an date type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field properties - * are as follows: - * - * default - * Date 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. - * @access protected - */ - function _getDateDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'date') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' DATE'.$default.$notnull; + return ''; } // }}} - // {{{ _getTimestampDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an timestamp - * type field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * default - * Time stamp 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. - * @access protected - */ - function _getTimestampDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'timestamp') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' DATETIME'.$default.$notnull; - } - - // }}} - // {{{ _getTimeDeclaration() + // {{{ _getIntegerDeclaration() /** - * Obtain DBMS specific SQL code portion needed to declare an time type + * 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. @@ -278,36 +153,10 @@ * Currently, the types of supported field * properties are as follows: * - * default - * Time 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. - * @access protected - */ - function _getTimeDeclaration($name, $field) - { - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'time') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' TIME'.$default.$notnull; - } - - // }}} - // {{{ _getFloatDeclaration() - - /** - * Obtain DBMS specific SQL code portion needed to declare an float type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: + * unsigned + * Boolean flag that indicates whether the field + * should be declared as unsigned integer if + * possible. * * default * Integer value to be used as default for this @@ -320,52 +169,26 @@ * declare the specified field. * @access protected */ - function _getFloatDeclaration($name, $field) + function _getIntegerDeclaration($name, $field) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - $type = 'DOUBLE'.($db->options['fixed_float'] ? '('. - ($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : ''); - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'float') : ''; - $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$default.$notnull; - } - - // }}} - // {{{ _getDecimalDeclaration() + if (array_key_exists('autoincrement', $field) && $field['autoincrement']) { + $autoinc = ' PRIMARY KEY AUTO_INCREMENT'; + $default = ''; + } else { + $autoinc = ''; + $default = array_key_exists('default', $field) ? ' DEFAULT '. + $this->quote($field['default'], 'integer') : ''; + } - /** - * Obtain DBMS specific SQL code portion needed to declare an decimal type - * field to be used in statements like CREATE TABLE. - * - * @param string $name name the field to be declared. - * @param string $field associative array with the name of the properties - * of the field being declared as array indexes. - * Currently, the types of supported field - * properties are as follows: - * - * default - * Integer 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. - * @access protected - */ - function _getDecimalDeclaration($name, $field) - { - $type = 'BIGINT'; - $default = array_key_exists('default', $field) ? ' DEFAULT '. - $this->quote($field['default'], 'decimal') : ''; + $unsigned = (array_key_exists('unsigned', $field) && $field['unsigned']) ? ' UNSIGNED' : ''; $notnull = (array_key_exists('notnull', $field) && $field['notnull']) ? ' NOT NULL' : ''; - return $name.' '.$type.$default.$notnull; + $name = $db->quoteIdentifier($name); + return $name.' '.$this->getTypeDeclaration($field).$unsigned.$default.$notnull.$autoinc; } // }}}
« previous php.pear.cvs (#35555) next »