cvs: pear /MDB2/MDB2/Driver/Datatype mssql.php
| From: | Daniel Convissor | Date: | Sun, 07 Nov 2004 21:46:08 +0000 |
| Subject: | cvs: pear /MDB2/MDB2/Driver/Datatype mssql.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-25749@lists.php.net to get a copy of this message | ||
danielc Sun Nov 7 16:46:08 2004 EDT
Modified files:
/pear/MDB2/MDB2/Driver/Datatype mssql.php
Log:
* Rework notnull because <notnull> can be 0 and SQL Server
defaults to NOT NULL unlike the rest of the DBMS's which
default to NULL.
* Copy over several _get*Declaration() methods from Common.php.
Need to specialize them here due to NULL situation.
* Add myself as co-author.
http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mssql.php?r1=1.12&r2=1.13&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mssql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.12 pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.13 --- pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.12 Wed Oct 27 12:56:57 2004 +++ pear/MDB2/MDB2/Driver/Datatype/mssql.php Sun Nov 7 16:46:07 2004 @@ -40,10 +40,11 @@ // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | POSSIBILITY OF SUCH DAMAGE. | // +----------------------------------------------------------------------+ -// | Author: Lukas Smith <smith@backendmedia.com> | +// | Authors: Lukas Smith <smith@backendmedia.com> | +// | Daniel Convissor <danielc@php.net> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.12 2004/10/27 16:56:57 lsmith Exp $ +// $Id: mssql.php,v 1.13 2004/11/07 21:46:07 danielc Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -89,6 +90,44 @@ } // }}} + // {{{ _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 private + */ + function _getIntegerDeclaration($name, $field) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + if (isset($field['unsigned'])) { + $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer"; + } + $default = isset($field['default']) ? ' DEFAULT '. + $this->quote($field['default'], 'integer') : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; + return $name.' INT'.$default.$notnull; + } + + // }}} // {{{ _getTextDeclaration() /** @@ -121,7 +160,7 @@ $type = isset($field['length']) ? 'VARCHAR ('.$field['length'].')' : 'TEXT'; $default = isset($field['default']) ? ' DEFAULT '. $this->quote($field['default'], 'text') : ''; - $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; return $name.' '.$type.$default.$notnull; } @@ -164,7 +203,7 @@ } else { $type = 'TEXT'; } - $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; return $name.' '.$type.$notnull; } @@ -207,7 +246,7 @@ } else { $type = 'IMAGE'; } - $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; return $name.' '.$type.$notnull; } @@ -238,11 +277,104 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. $this->quote($field['default'], 'boolean') : ''; - $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT 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 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 private + */ + function _getDateDeclaration($name, $field) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + $default = isset($field['default']) ? ' DEFAULT '. + $this->quote($field['default'], 'date') : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT 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 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 + * 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 private + */ + function _getTimestampDeclaration($name, $field) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + $default = isset($field['default']) ? ' DEFAULT '. + $this->quote($field['default'], 'timestamp') : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT 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 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 private + */ + function _getTimeDeclaration($name, $field) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + $default = isset($field['default']) ? ' DEFAULT '. + $this->quote($field['default'], 'time') : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; + return $name.' CHAR ('.strlen('HH:MM:SS').')'.$default.$notnull; + } + + // }}} // {{{ _getFloatDeclaration() /** @@ -271,7 +403,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. $this->quote($field['default'], 'float') : ''; - $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; return $name.' FLOAT'.$default.$notnull; } @@ -305,7 +437,7 @@ $type = 'DECIMAL(18,'.$db->options['decimal_places'].')'; $default = isset($field['default']) ? ' DEFAULT '. $this->quote($field['default'], 'decimal') : ''; - $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; return $name.' '.$type.$default.$notnull; }
http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mssql.php?r1=1.12&r2=1.13&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mssql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.12 pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.13 --- pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.12 Wed Oct 27 12:56:57 2004 +++ pear/MDB2/MDB2/Driver/Datatype/mssql.php Sun Nov 7 16:46:07 2004 @@ -40,10 +40,11 @@ // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | POSSIBILITY OF SUCH DAMAGE. | // +----------------------------------------------------------------------+ -// | Author: Lukas Smith <smith@backendmedia.com> | +// | Authors: Lukas Smith <smith@backendmedia.com> | +// | Daniel Convissor <danielc@php.net> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.12 2004/10/27 16:56:57 lsmith Exp $ +// $Id: mssql.php,v 1.13 2004/11/07 21:46:07 danielc Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -89,6 +90,44 @@ } // }}} + // {{{ _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 private + */ + function _getIntegerDeclaration($name, $field) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + if (isset($field['unsigned'])) { + $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer"; + } + $default = isset($field['default']) ? ' DEFAULT '. + $this->quote($field['default'], 'integer') : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; + return $name.' INT'.$default.$notnull; + } + + // }}} // {{{ _getTextDeclaration() /** @@ -121,7 +160,7 @@ $type = isset($field['length']) ? 'VARCHAR ('.$field['length'].')' : 'TEXT'; $default = isset($field['default']) ? ' DEFAULT '. $this->quote($field['default'], 'text') : ''; - $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; return $name.' '.$type.$default.$notnull; } @@ -164,7 +203,7 @@ } else { $type = 'TEXT'; } - $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; return $name.' '.$type.$notnull; } @@ -207,7 +246,7 @@ } else { $type = 'IMAGE'; } - $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; return $name.' '.$type.$notnull; } @@ -238,11 +277,104 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. $this->quote($field['default'], 'boolean') : ''; - $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT 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 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 private + */ + function _getDateDeclaration($name, $field) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + $default = isset($field['default']) ? ' DEFAULT '. + $this->quote($field['default'], 'date') : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT 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 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 + * 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 private + */ + function _getTimestampDeclaration($name, $field) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + $default = isset($field['default']) ? ' DEFAULT '. + $this->quote($field['default'], 'timestamp') : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT 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 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 private + */ + function _getTimeDeclaration($name, $field) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + $default = isset($field['default']) ? ' DEFAULT '. + $this->quote($field['default'], 'time') : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; + return $name.' CHAR ('.strlen('HH:MM:SS').')'.$default.$notnull; + } + + // }}} // {{{ _getFloatDeclaration() /** @@ -271,7 +403,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. $this->quote($field['default'], 'float') : ''; - $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; return $name.' FLOAT'.$default.$notnull; } @@ -305,7 +437,7 @@ $type = 'DECIMAL(18,'.$db->options['decimal_places'].')'; $default = isset($field['default']) ? ' DEFAULT '. $this->quote($field['default'], 'decimal') : ''; - $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; + $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL'; return $name.' '.$type.$default.$notnull; }