cvs: pear /MDB2 MDB2.php /MDB2/MDB2/Driver/Datatype Common.php fbsql.php ibase.php mssql.php mysql.php oci8.php pgsql.php sqlite.php
| From: | Lukas Smith | Date: | Thu, 09 Sep 2004 11:59:46 +0000 |
| Subject: | cvs: pear /MDB2 MDB2.php /MDB2/MDB2/Driver/Datatype Common.php fbsql.php ibase.php mssql.php mysql.php oci8.php pgsql.php sqlite.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-23749@lists.php.net to get a copy of this message | ||
lsmith Thu Sep 9 07:59:46 2004 EDT
Modified files:
/pear/MDB2 MDB2.php
/pear/MDB2/MDB2/Driver/Datatype Common.php fbsql.php ibase.php
mssql.php mysql.php oci8.php
pgsql.php sqlite.php
Log:
- reworked quote handling: moved all implementation details into the extension,
made all quote methods private except for quote() itself, honor portability
MDB2_PORTABILITY_EMPTY_TO_NULL in quote(), removed MDB2_TYPE_* constants
- added serialize datatype but commented it out for now
http://cvs.php.net/diff.php/pear/MDB2/MDB2.php?r1=1.38&r2=1.39&ty=u Index: pear/MDB2/MDB2.php diff -u pear/MDB2/MDB2.php:1.38 pear/MDB2/MDB2.php:1.39 --- pear/MDB2/MDB2.php:1.38 Sat Sep 4 18:44:21 2004 +++ pear/MDB2/MDB2.php Thu Sep 9 07:59:38 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: MDB2.php,v 1.38 2004/09/04 22:44:21 lsmith Exp $ +// $Id: MDB2.php,v 1.39 2004/09/09 11:59:38 lsmith Exp $ // /** @@ -2026,51 +2026,11 @@ */ function quote($value, $type = null) { - if (is_null($value)) { - return 'NULL'; - } elseif (is_null($type)) { - switch (gettype($value)) { - case 'integer': - $type = 'integer'; - break; - case 'double': - // todo - $type = 'decimal'; - $type = 'float'; - break; - case 'boolean': - $type = 'boolean'; - break; - case 'array': - // todo - if (true && isset($value['data'])) { - $type = 'blob'; - } else { - $type = 'clob'; - } - break; - default: - if (preg_match('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/', $value)) { - $type = 'timestamp'; - } elseif (preg_match('/\d{2}:\d{2}/', $value)) { - $type = 'time'; - } elseif (preg_match('/\d{4}-\d{2}-\d{2}/', $value)) { - $type = 'date'; - } else { - $type = 'text'; - } - break; - } - } - $result = $this->loadModule('datatype'); if (MDB2::isError($result)) { return $result; } - if (method_exists($this->datatype, "quote{$type}")) { - return $this->datatype->{"quote{$type}"}($value); - } - return $this->raiseError('type not defined: '.$type); + return $this->datatype->quote($value, $type); } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/Common.php?r1=1.11&r2=1.12&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/Common.php diff -u pear/MDB2/MDB2/Driver/Datatype/Common.php:1.11 pear/MDB2/MDB2/Driver/Datatype/Common.php:1.12 --- pear/MDB2/MDB2/Driver/Datatype/Common.php:1.11 Sat Sep 4 18:20:54 2004 +++ pear/MDB2/MDB2/Driver/Datatype/Common.php Thu Sep 9 07:59:43 2004 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.11 2004/09/04 22:20:54 lsmith Exp $ +// $Id: Common.php,v 1.12 2004/09/09 11:59:43 lsmith Exp $ /** * @package MDB2 @@ -51,20 +51,6 @@ */ /** - * define contants for all datatypes - */ -define('MDB2_TYPE_TEXT' , 0); -define('MDB2_TYPE_BOOLEAN' , 1); -define('MDB2_TYPE_INTEGER' , 2); -define('MDB2_TYPE_DECIMAL' , 3); -define('MDB2_TYPE_FLOAT' , 4); -define('MDB2_TYPE_DATE' , 5); -define('MDB2_TYPE_TIME' , 6); -define('MDB2_TYPE_TIMESTAMP' , 7); -define('MDB2_TYPE_CLOB' , 8); -define('MDB2_TYPE_BLOB' , 9); - -/** * MDB2_Driver_Common: Base class that is extended by each MDB2 driver * * @package MDB2 @@ -74,16 +60,17 @@ class MDB2_Driver_Datatype_Common { var $valid_types = array( - 'text' => MDB2_TYPE_TEXT, - 'boolean' => MDB2_TYPE_BOOLEAN, - 'integer' => MDB2_TYPE_INTEGER, - 'decimal' => MDB2_TYPE_DECIMAL, - 'float' => MDB2_TYPE_FLOAT, - 'date' => MDB2_TYPE_DATE, - 'time' => MDB2_TYPE_TIME, - 'timestamp' => MDB2_TYPE_TIMESTAMP, - 'clob' => MDB2_TYPE_CLOB, - 'blob' => MDB2_TYPE_BLOB + 'text' => true, +# 'serialize' => true, + 'boolean' => true, + 'integer' => true, + 'decimal' => true, + 'float' => true, + 'date' => true, + 'time' => true, + 'timestamp' => true, + 'clob' => true, + 'blob' => true, ); var $db_index; @@ -137,8 +124,8 @@ return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'setResultTypes: ' . $type . ' is not a supported column type'); } - $result->types[$key] = $this->valid_types[$type]; } + $result->types = $types; return MDB2_OK; } @@ -157,24 +144,26 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_TEXT: + case 'text': return $value; - case MDB2_TYPE_INTEGER: +# case 'serialize': +# return $value ? @unserialize($value) : $value; + case 'integer': return intval($value); - case MDB2_TYPE_BOOLEAN: + case 'boolean': return $value == 'Y'; - case MDB2_TYPE_DECIMAL: + case 'decimal': return $value; - case MDB2_TYPE_FLOAT: + case 'float': return doubleval($value); - case MDB2_TYPE_DATE: + case 'date': return $value; - case MDB2_TYPE_TIME: + case 'time': return $value; - case MDB2_TYPE_TIMESTAMP: + case 'timestamp': return $value; - case MDB2_TYPE_CLOB: - case MDB2_TYPE_BLOB: + case 'clob': + case 'blob': $db->lobs[] = array( 'value' => $value, 'position' => 0 @@ -236,9 +225,9 @@ } $type = $types[$current_column]; switch ($type) { - case MDB2_TYPE_TEXT: + case 'text': break; - case MDB2_TYPE_INTEGER: + case 'integer': $row[$key] = intval($row[$key]); break; default: @@ -287,7 +276,7 @@ $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer"; } $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteInteger($field['default']) : ''; + $this->quote($field['default'], 'integer') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' INT'.$default.$notnull; } @@ -323,13 +312,45 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteText($field['default']) : ''; + $this->quote($field['default'], 'text') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; $type = isset($field['length']) ? 'CHAR ('.$field['length'].')' : 'TEXT'; return $name.' '.$type.$default.$notnull; } // }}} + // {{{ getSerializeDeclaration() + + /** + * 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: + * + * 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 getSerializeDeclaration($name, $field) +# { +# return $this->getTextDeclaration($name, $field); +# } + + // }}} // {{{ getCLOBDeclaration() /** @@ -419,7 +440,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteBoolean($field['default']) : ''; + $this->quote($field['default'], 'boolean') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' CHAR (1)'.$default.$notnull; } @@ -450,7 +471,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' CHAR ('.strlen('YYYY-MM-DD').')'.$default.$notnull; } @@ -481,7 +502,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTimestamp($field['default']) : ''; + $this->quote($field['default'], 'timestamp') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' CHAR ('.strlen('YYYY-MM-DD HH:MM:SS').')'.$default.$notnull; } @@ -512,7 +533,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTime($field['default']) : ''; + $this->quote($field['default'], 'time') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' CHAR ('.strlen('HH:MM:SS').')'.$default.$notnull; } @@ -543,7 +564,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TEXT'.$default.$notnull; } @@ -574,31 +595,88 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TEXT'.$default.$notnull; } // }}} - // {{{ quoteInteger() + // {{{ quote() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string value that is intended to be converted. + * @param string $type type to which the value should be converted to * @return string text string that represents the given argument value in * a DBMS specific format. * @access public */ - function quoteInteger($value) + function quote($value, $type = null) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : (int)$value; + if (is_null($value) + || ($value === '' && $db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) + ) { + return 'NULL'; + } elseif (is_null($type)) { + switch (gettype($value)) { + case 'integer': + $type = 'integer'; + break; + case 'double': + // todo + $type = 'decimal'; + $type = 'float'; + break; + case 'boolean': + $type = 'boolean'; + break; + case 'array': + case 'object': +# $type = 'serialize'; + $type = 'text'; + break; + default: + if (preg_match('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/', $value)) { + $type = 'timestamp'; + } elseif (preg_match('/\d{2}:\d{2}/', $value)) { + $type = 'time'; + } elseif (preg_match('/\d{4}-\d{2}-\d{2}/', $value)) { + $type = 'date'; + } else { + $type = 'text'; + } + break; + } + } + + if (method_exists($this, "_quote{$type}")) { + return $this->{"_quote{$type}"}($value); + } + return $db->raiseError('type not defined: '.$type); + } + + // }}} + // {{{ _quoteInteger() + + /** + * Convert a text value into a DBMS specific format that is suitable to + * compose query statements. + * + * @param string $value text string value that is intended to be converted. + * @return string text string that represents the given argument value in + * a DBMS specific format. + * @access private + */ + function _quoteInteger($value) + { + return (int)$value; } // }}} - // {{{ quoteText() + // {{{ _quoteText() /** * Convert a text value into a DBMS specific format that is suitable to @@ -607,30 +685,49 @@ * @param string $value text string value that is intended to be converted. * @return string text string that already contains any DBMS specific * escaped character sequences. - * @access public + * @access private */ - function quoteText($value) + function _quoteText($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'".$db->escape($value)."'"; + return "'".$db->escape($value)."'"; } + // {{{ _quoteSerialize() + + /** + * Convert a serialize value into a DBMS specific format that is suitable to + * compose query statements. + * + * @param string $value text string value that is intended to be converted. + * @return string text string that already contains any DBMS specific + * escaped character sequences. + * @access private + */ +# function _quoteSerialize($value) +# { +# return $this->quote(serialize($value), 'text'); +# } + // }}} - // {{{ quoteCLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param resource $prepared_query query handle from prepare() - * @param $value + * @param $parameter + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteCLOB($value) + function _quoteCLOB($clob) { - return $this->quoteText($value); + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, + 'quoteCLOB: prepared queries with values of type "clob" are not yet supported'); } // }}} @@ -639,31 +736,34 @@ /** * free a character large object * - * @param int $value lob index + * @param int $clob lob index * @access public */ - function freeCLOBValue($value) + function freeCLOBValue($clob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - unset($db->lobs[$value]); + unset($db->lobs[$clob]); } // }}} - // {{{ quoteBLOB() + // {{{ _quoteBLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param resource $prepared_query query handle from prepare() - * @param $value + * @param $parameter + * @param $blob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBLOB($value) + function _quoteBLOB($blob) { - return $this->quoteText($value); + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, + 'quoteBLOB: prepared queries with values of type "blob" are not yet supported'); } // }}} @@ -672,17 +772,17 @@ /** * free a binary large object * - * @param int $value lob index + * @param int $blob lob index * @access public */ - function freeBLOBValue($value) + function freeBLOBValue($blob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - unset($db->lobs[$value]); + unset($db->lobs[$blob]); } // }}} - // {{{ quoteBoolean() + // {{{ _quoteBoolean() /** * Convert a text value into a DBMS specific format that is suitable to @@ -691,16 +791,15 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBoolean($value) + function _quoteBoolean($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : ($value ? "'Y'" : "'N'"); + return ($value ? "'Y'" : "'N'"); } // }}} - // {{{ quoteDate() + // {{{ _quoteDate() /** * Convert a text value into a DBMS specific format that is suitable to @@ -709,16 +808,15 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDate($value) + function _quoteDate($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'$value'"; + return "'$value'"; } // }}} - // {{{ quoteTimestamp() + // {{{ _quoteTimestamp() /** * Convert a text value into a DBMS specific format that is suitable to @@ -727,16 +825,15 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteTimestamp($value) + function _quoteTimestamp($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'$value'"; + return "'$value'"; } // }}} - // {{{ quoteTime() + // {{{ _quoteTime() /** * Convert a text value into a DBMS specific format that is suitable to @@ -745,16 +842,15 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteTime($value) + function _quoteTime($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'$value'"; + return "'$value'"; } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -763,16 +859,15 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'$value'"; + return "'$value'"; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -781,12 +876,11 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'$value'"; + return "'$value'"; } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/fbsql.php?r1=1.7&r2=1.8&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/fbsql.php diff -u pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.7 pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.8 --- pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.7 Sat Sep 4 18:20:54 2004 +++ pear/MDB2/MDB2/Driver/Datatype/fbsql.php Thu Sep 9 07:59:43 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.7 2004/09/04 22:20:54 lsmith Exp $ +// $Id: fbsql.php,v 1.8 2004/09/09 11:59:43 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -72,9 +72,9 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_BOOLEAN: + case 'boolean': return $value == 'T'; - case MDB2_TYPE_TIME: + case 'time': if ($value[0] == '+') { return substr($value, 1); } else { @@ -123,7 +123,7 @@ declared as signed integer"; } $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteInteger($field['default']) : ''; + $this->quote($field['default'], 'integer') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' INT'.$default.$notnull; } @@ -159,7 +159,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteText($field['default']) : ''; + $this->quote($field['default'], 'text') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; $length = isset($field['length']) ? $field['length'] : $db->max_text_length; return $name.' VARCHAR ('.$length.')'.$default.$notnull; @@ -253,7 +253,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteBoolean($field['default']) : ''; + $this->quote($field['default'], 'boolean') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' BOOLEAN)'.$default.$notnull; } @@ -285,7 +285,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT DATE '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' DATE'.$default.$notnull; } @@ -318,7 +318,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT TIMESTAMP '. - $this->quoteTimestamp($field['default']) : ''; + $this->quote($field['default'], 'timestamp') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TIMESTAMP'.$default.$notnull; } @@ -350,7 +350,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT TIME '. - $this->quoteTime($field['default']) : ''; + $this->quote($field['default'], 'time') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TIME'.$default.$notnull; } @@ -383,7 +383,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' FLOAT'.$default.$notnull; } @@ -417,31 +417,75 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = 'DECIMAL(18,'.$db->options['decimal_places'].')'; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } // }}} - // {{{ quoteBLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBLOB($value) + function _quoteCLOB($clob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'".addslashes($value)."'"; + if ($clob === null) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($clob)) { + $result = $this->readLOB($clob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= $db->escape($data); + } + $value .= "'"; + return $value; } // }}} - // {{{ quoteBoolean() + // {{{ _quoteBLOB() + + /** + * Convert a text value into a DBMS specific format that is suitable to + * compose query statements. + * + * @param $blob + * @return string text string that represents the given argument value in + * a DBMS specific format. + * @access private + */ + function _quoteBLOB($blob) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + if ($blob === null) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($blob)) { + $result = $this->readLOB($blob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= addslashes($data); + } + $value .= "'"; + return $value; + } + + // }}} + // {{{ _quoteBoolean() /** * Convert a text value into a DBMS specific format that is suitable to @@ -450,16 +494,15 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBoolean($value) + function _quoteBoolean($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : ($value ? 'True' : 'False'); + return ($value ? 'True' : 'False'); } // }}} - // {{{ quoteDate() + // {{{ _quoteDate() /** * Convert a text value into a DBMS specific format that is suitable to @@ -468,16 +511,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDate($value) + function _quoteDate($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : "DATE'$value'"; + return "DATE'$value'"; } // }}} - // {{{ quoteTimestamp() + // {{{ _quoteTimestamp() /** * Convert a text value into a DBMS specific format that is suitable to @@ -486,16 +529,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteTimestamp($value) + function _quoteTimestamp($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : "TIMESTAMP'$value'"; + return "TIMESTAMP'$value'"; } // }}} - // {{{ quoteTime() + // {{{ _quoteTime() /** * Convert a text value into a DBMS specific format that is suitable to @@ -504,16 +547,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteTime($value) + function _quoteTime($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : "TIME'$value'"; + return "TIME'$value'"; } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -522,16 +565,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : (float)$value; + return (float)$value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -540,12 +583,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : $value; + return $value; } } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/ibase.php?r1=1.9&r2=1.10&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/ibase.php diff -u pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.9 pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.10 --- pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.9 Sat Sep 4 18:16:03 2004 +++ pear/MDB2/MDB2/Driver/Datatype/ibase.php Thu Sep 9 07:59:43 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.9 2004/09/04 22:16:03 lsmith Exp $ +// $Id: ibase.php,v 1.10 2004/09/09 11:59:43 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -71,9 +71,9 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_DECIMAL: + case 'decimal': return sprintf('%.'.$db->options['decimal_places'].'f', doubleval($value)/pow(10.0, $db->options['decimal_places'])); - case MDB2_TYPE_TIMESTAMP: + case 'timestamp': return substr($value, 0, strlen('YYYY-MM-DD HH:MM:SS')); default: return $this->_baseConvertResult($value, $type); @@ -168,7 +168,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = $this->getTypeDeclaration($field); $default = isset($field['default']) ? ' DEFAULT TIME'. - $this->quoteText($field['default']) : ''; + $this->quote($field['default'], 'text') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } @@ -261,7 +261,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -294,7 +294,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTimestamp($field['default']) : ''; + $this->quote($field['default'], 'timestamp') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -325,7 +325,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTime($field['default']) : ''; + $this->quote($field['default'], 'time') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -356,7 +356,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -388,7 +388,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -457,49 +457,49 @@ } // }}} - // {{{ quoteCLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteCLOB($value) + function _quoteCLOB($clob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - if ($value === null) { + if ($clob === null) { return 'NULL'; } - return $this->_quoteLOB($value); + return $this->_quoteLOB($clob); } // }}} - // {{{ quoteBLOB() + // {{{ _quoteBLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $blob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBLOB($value) + function _quoteBLOB($blob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - if ($value === null) { + if ($blob === null) { return 'NULL'; } - return $this->_quoteLOB($value); + return $this->_quoteLOB($blob); } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -508,16 +508,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (($value === null) ? 'NULL' : $value); + return $value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -526,12 +526,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (($value === null) ? 'NULL' : strval(round($value*pow(10.0, $db->options['decimal_places'])))); + return (strval(round($value*pow(10.0, $db->options['decimal_places'])))); } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mssql.php?r1=1.7&r2=1.8&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mssql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.7 pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.8 --- pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.7 Sat Sep 4 18:20:54 2004 +++ pear/MDB2/MDB2/Driver/Datatype/mssql.php Thu Sep 9 07:59:43 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.7 2004/09/04 22:20:54 lsmith Exp $ +// $Id: mssql.php,v 1.8 2004/09/09 11:59:43 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -71,14 +71,14 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_BOOLEAN: + case 'boolean': return $value == '1'; - case MDB2_TYPE_DATE: + case 'date': if (strlen($value) > 10) { $value = substr($value,0,10); } return $value; - case MDB2_TYPE_TIME: + case 'time': if (strlen($value) > 8) { $value = substr($value,11,8); } @@ -120,7 +120,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = isset($field['length']) ? 'VARCHAR ('.$field['length'].')' : 'TEXT'; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteText($field['default']) : ''; + $this->quote($field['default'], 'text') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } @@ -237,7 +237,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteBoolean($field['default']) : ''; + $this->quote($field['default'], 'boolean') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' BIT'.$default.$notnull; } @@ -270,7 +270,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' FLOAT'.$default.$notnull; } @@ -304,31 +304,74 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = 'DECIMAL(18,'.$db->options['decimal_places'].')'; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } // }}} - // {{{ quoteBLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBLOB($value) + function _quoteCLOB($clob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'".bin2hex($value)."'"; + if ($clob === null) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($clob)) { + $result = $this->readLOB($clob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= $db->escape($data); + } + $value .= "'"; + return $value; } // }}} - // {{{ quoteBoolean() + // {{{ _quoteBLOB() + + /** + * Convert a text value into a DBMS specific format that is suitable to + * compose query statements. + * + * @param $blob + * @return string text string that represents the given argument value in + * a DBMS specific format. + * @access private + */ + function _quoteBLOB($blob) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + if ($blob === null) { + return 'NULL'; + } + $value = "0x"; + $data = null; + while (!$this->endOfLOB($blob)) { + $result = $this->readLOB($blob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= bin2hex($data); + } + return $value; + } + + // }}} + // {{{ _quoteBoolean() /** * Convert a text value into a DBMS specific format that is suitable to @@ -337,16 +380,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBoolean($value) + function _quoteBoolean($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : ($value ? 1 : 0); + return ($value ? 1 : 0); } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -355,16 +398,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : $value; + return $value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -373,12 +416,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : $value; + return $value; } } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mysql.php?r1=1.6&r2=1.7&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mysql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.6 pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.7 --- pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.6 Sat Sep 4 18:20:54 2004 +++ pear/MDB2/MDB2/Driver/Datatype/mysql.php Thu Sep 9 07:59:43 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.6 2004/09/04 22:20:54 lsmith Exp $ +// $Id: mysql.php,v 1.7 2004/09/09 11:59:43 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -107,7 +107,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $unsigned = isset($field['unsigned']) ? ' UNSIGNED' : ''; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteInteger($field['default']) : ''; + $this->quote($field['default'], 'integer') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' INT'.$unsigned.$default.$notnull; ; @@ -243,7 +243,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' DATE'.$default.$notnull; } @@ -276,7 +276,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTimestamp($field['default']) : ''; + $this->quote($field['default'], 'timestamp') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' DATETIME'.$default.$notnull; } @@ -308,7 +308,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTime($field['default']) : ''; + $this->quote($field['default'], 'time') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TIME'.$default.$notnull; } @@ -342,7 +342,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = 'DOUBLE'; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } @@ -376,31 +376,75 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = 'DECIMAL(18,'.$db->options['decimal_places'].')'; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } // }}} - // {{{ quoteBLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private + */ + function _quoteCLOB($clob) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + if (is_null($clob)) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($clob)) { + $result = $this->readLOB($clob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= $db->escape($data); + } + $value .= "'"; + return $value; + } + + // }}} + // {{{ _quoteBLOB() + + /** + * Convert a text value into a DBMS specific format that is suitable to + * compose query statements. + * + * @param $blob + * @return string text string that represents the given argument value in + * a DBMS specific format. + * @access private */ - function quoteBLOB($value) + function _quoteBLOB($blob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'".addslashes($value)."'"; + if (is_null($blob)) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($blob)) { + $result = $this->readLOB($blob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= addslashes($data); + } + $value .= "'"; + return $value; } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -409,16 +453,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : (float)$value; + return (float)$value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -427,12 +471,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : $value; + return $value; } } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/oci8.php?r1=1.9&r2=1.10&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/oci8.php diff -u pear/MDB2/MDB2/Driver/Datatype/oci8.php:1.9 pear/MDB2/MDB2/Driver/Datatype/oci8.php:1.10 --- pear/MDB2/MDB2/Driver/Datatype/oci8.php:1.9 Sat Sep 4 18:15:45 2004 +++ pear/MDB2/MDB2/Driver/Datatype/oci8.php Thu Sep 9 07:59:44 2004 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.9 2004/09/04 22:15:45 lsmith Exp $ +// $Id: oci8.php,v 1.10 2004/09/09 11:59:44 lsmith Exp $ require_once 'MDB2/Driver/Datatype/Common.php'; @@ -69,9 +69,9 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_DATE: + case 'date': return substr($value, 0, strlen('YYYY-MM-DD')); - case MDB2_TYPE_TIME: + case 'time': return substr($value, strlen('YYYY-MM-DD '), strlen('HH:MI:SS')); default: return $this->_baseConvertResult($value, $type); @@ -165,7 +165,7 @@ $db->warning = "unsigned integer field \"$name\" is being declared as signed integer"; } $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteInteger($field['default']) : ''; + $this->quote($field['default'], 'integer') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -201,8 +201,8 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = $this->getTypeDeclaration($field); - $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteText($field['default']) : ''; + $default = isset($field['default']) ? ' DEFAULT TIME'. + $this->quote($field['default'], 'text') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } @@ -295,7 +295,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -326,7 +326,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTimestamp($field['default']) : ''; + $this->quoteTimstamp($field['default']) : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -356,7 +356,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $db->quoteTime($field['default']) : ''; + $db->quoteime($field['default']) : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -387,7 +387,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -418,55 +418,55 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } // }}} - // {{{ quoteCLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteCLOB($value) + function _quoteCLOB($clob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - if ($value === null) { + if ($clob === null) { return 'NULL'; } return 'EMPTY_CLOB()'; } // }}} - // {{{ quoteBLOB() + // {{{ _quoteBLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $blob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBLOB($value) + function _quoteBLOB($blob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - if ($value === null) { + if ($blob === null) { return 'NULL'; } return 'EMPTY_BLOB()'; } // }}} - // {{{ quoteDate() + // {{{ _quoteDate() /** * Convert a text value into a DBMS specific format that is suitable to @@ -475,16 +475,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDate($value) + function _quoteDate($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : "TO_DATE('$value','YYYY-MM-DD')"; + return "TO_DATE('$value','YYYY-MM-DD')"; } // }}} - // {{{ quoteTimestamp() + // {{{ _quoteTimestamp() /** * Convert a text value into a DBMS specific format that is suitable to @@ -493,16 +493,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteTimestamp($value) + function _quoteTimestamp($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : "TO_DATE('$value','YYYY-MM-DD HH24:MI:SS')"; + return "TO_DATE('$value','YYYY-MM-DD HH24:MI:SS')"; } // }}} - // {{{ quoteTime() + // {{{ _quoteTime() /** * Convert a text value into a DBMS specific format that is suitable to @@ -511,16 +511,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteTime($value) + function _quoteTime($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : "TO_DATE('0001-01-01 $value','YYYY-MM-DD HH24:MI:SS')"; + return "TO_DATE('0001-01-01 $value','YYYY-MM-DD HH24:MI:SS')"; } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -529,16 +529,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : (float)$value; + return (float)$value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -547,12 +547,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : $value; + return $value; } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/pgsql.php?r1=1.6&r2=1.7&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/pgsql.php diff -u pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.6 pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.7 --- pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.6 Sat Sep 4 18:16:22 2004 +++ pear/MDB2/MDB2/Driver/Datatype/pgsql.php Thu Sep 9 07:59:44 2004 @@ -42,7 +42,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.6 2004/09/04 22:16:22 lsmith Exp $ +// $Id: pgsql.php,v 1.7 2004/09/09 11:59:44 lsmith Exp $ require_once 'MDB2/Driver/Datatype/Common.php'; @@ -70,15 +70,15 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_BOOLEAN: + case 'boolean': return $value == 't'; - case MDB2_TYPE_FLOAT: + case 'float': return doubleval($value); - case MDB2_TYPE_DATE: + case 'date': return $value; - case MDB2_TYPE_TIME: + case 'time': return $value; - case MDB2_TYPE_TIMESTAMP: + case 'timestamp': return substr($value, 0, strlen('YYYY-MM-DD HH:MM:SS')); default: return $this->_baseConvertResult($value, $type); @@ -117,7 +117,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = isset($field['length']) ? 'VARCHAR ('.$field['length'].')' : 'TEXT'; $default = isset($field['default']) ? ' DEFAULT TIME'. - $this->quoteText($field['default']) : ''; + $this->quote($field['default'], 'text') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } @@ -210,7 +210,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteBoolean($field['default']) : ''; + $this->quote($field['default'], 'boolean') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' BOOLEAN'.$default.$notnull; } @@ -241,7 +241,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' DATE'.$default.$notnull; } @@ -272,7 +272,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTime($field['default']) : ''; + $this->quote($field['default'], 'time') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TIME without time zone'.$default.$notnull; } @@ -303,7 +303,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTimestamp($field['default']) : ''; + $this->quote($field['default'], 'timestamp') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TIMESTAMP without time zone'.$default.$notnull; } @@ -334,7 +334,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' FLOAT8'.$default.$notnull; } @@ -365,7 +365,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' NUMERIC(18, '.$db->options['decimal_places'].')'.$default.$notnull; } @@ -432,49 +432,49 @@ } // }}} - // {{{ quoteCLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteCLOB($value) + function _quoteCLOB($clob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - if ($value === null) { + if ($clob === null) { return 'NULL'; } - return $this->_quoteLOB($value); + return $this->_quoteLOB($clob); } // }}} - // {{{ quoteBLOB() + // {{{ _quoteBLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $blob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBLOB($value) + function _quoteBLOB($blob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - if ($value === null) { + if ($blob === null) { return 'NULL'; } - return $this->_quoteLOB($value); + return $this->_quoteLOB($blob); } // }}} - // {{{ quoteBoolean() + // {{{ _quoteBoolean() /** * Convert a text value into a DBMS specific format that is suitable to @@ -483,16 +483,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBoolean($value) + function _quoteBoolean($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : ($value ? "'t'" : "'f'"); + return ($value ? "'t'" : "'f'"); } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -501,16 +501,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : $value; + return $value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -519,12 +519,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : $value; + return $value; } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/sqlite.php?r1=1.8&r2=1.9&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/sqlite.php diff -u pear/MDB2/MDB2/Driver/Datatype/sqlite.php:1.8 pear/MDB2/MDB2/Driver/Datatype/sqlite.php:1.9 --- pear/MDB2/MDB2/Driver/Datatype/sqlite.php:1.8 Sat Sep 4 18:20:54 2004 +++ pear/MDB2/MDB2/Driver/Datatype/sqlite.php Thu Sep 9 07:59:44 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: sqlite.php,v 1.8 2004/09/04 22:20:54 lsmith Exp $ +// $Id: sqlite.php,v 1.9 2004/09/09 11:59:44 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -71,7 +71,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_DECIMAL: + case 'decimal': return sprintf('%.'.$db->options['decimal_places'].'f', doubleval($value)/pow(10.0, $db->options['decimal_places'])); default: return $this->_baseConvertResult($value, $type); @@ -112,7 +112,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $unsigned = isset($field['unsigned']) ? ' UNSIGNED' : ''; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteInteger($field['default']) : ''; + $this->quote($field['default'], 'integer') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' INT'.$unsigned.$default.$notnull; ; @@ -248,7 +248,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' DATE'.$default.$notnull; } @@ -281,7 +281,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTimestamp($field['default']) : ''; + $this->quote($field['default'], 'timestamp') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' DATETIME'.$default.$notnull; } @@ -313,7 +313,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTime($field['default']) : ''; + $this->quote($field['default'], 'time') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TIME'.$default.$notnull; } @@ -347,7 +347,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = 'DOUBLE'.($db->options['fixed_float'] ? '('.($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : ''); $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } @@ -381,21 +381,75 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = 'BIGINT'; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } // }}} - // {{{ quoteCLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * + * @param $clob + * @return string text string that represents the given argument value in + * a DBMS specific format. + * @access private + */ + function _quoteCLOB($clob) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + if ($clob === null) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($clob)) { + $result = $this->readLOB($clob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= $db->escape($data); + } + $value .= "'"; + return $value; + } // }}} - // {{{ quoteFloat() + // {{{ _quoteBLOB() + + /** + * Convert a text value into a DBMS specific format that is suitable to + * compose query statements. + * + * @param $blob + * @return string text string that represents the given argument value in + * a DBMS specific format. + * @access private + */ + function _quoteBLOB($blob) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + if ($blob === null) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($blob)) { + $result = $this->readLOB($blob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= $db->escape($data); + } + $value .= "'"; + return $value; + } + + // }}} + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -404,16 +458,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : (float)$value; + return (float)$value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -422,12 +476,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (($value === null) ? 'NULL' : strval(round(doubleval($value)*pow(10.0, $db->options['decimal_places'])))); + return (strval(round(doubleval($value)*pow(10.0, $db->options['decimal_places'])))); } }
http://cvs.php.net/diff.php/pear/MDB2/MDB2.php?r1=1.38&r2=1.39&ty=u Index: pear/MDB2/MDB2.php diff -u pear/MDB2/MDB2.php:1.38 pear/MDB2/MDB2.php:1.39 --- pear/MDB2/MDB2.php:1.38 Sat Sep 4 18:44:21 2004 +++ pear/MDB2/MDB2.php Thu Sep 9 07:59:38 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: MDB2.php,v 1.38 2004/09/04 22:44:21 lsmith Exp $ +// $Id: MDB2.php,v 1.39 2004/09/09 11:59:38 lsmith Exp $ // /** @@ -2026,51 +2026,11 @@ */ function quote($value, $type = null) { - if (is_null($value)) { - return 'NULL'; - } elseif (is_null($type)) { - switch (gettype($value)) { - case 'integer': - $type = 'integer'; - break; - case 'double': - // todo - $type = 'decimal'; - $type = 'float'; - break; - case 'boolean': - $type = 'boolean'; - break; - case 'array': - // todo - if (true && isset($value['data'])) { - $type = 'blob'; - } else { - $type = 'clob'; - } - break; - default: - if (preg_match('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/', $value)) { - $type = 'timestamp'; - } elseif (preg_match('/\d{2}:\d{2}/', $value)) { - $type = 'time'; - } elseif (preg_match('/\d{4}-\d{2}-\d{2}/', $value)) { - $type = 'date'; - } else { - $type = 'text'; - } - break; - } - } - $result = $this->loadModule('datatype'); if (MDB2::isError($result)) { return $result; } - if (method_exists($this->datatype, "quote{$type}")) { - return $this->datatype->{"quote{$type}"}($value); - } - return $this->raiseError('type not defined: '.$type); + return $this->datatype->quote($value, $type); } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/Common.php?r1=1.11&r2=1.12&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/Common.php diff -u pear/MDB2/MDB2/Driver/Datatype/Common.php:1.11 pear/MDB2/MDB2/Driver/Datatype/Common.php:1.12 --- pear/MDB2/MDB2/Driver/Datatype/Common.php:1.11 Sat Sep 4 18:20:54 2004 +++ pear/MDB2/MDB2/Driver/Datatype/Common.php Thu Sep 9 07:59:43 2004 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.11 2004/09/04 22:20:54 lsmith Exp $ +// $Id: Common.php,v 1.12 2004/09/09 11:59:43 lsmith Exp $ /** * @package MDB2 @@ -51,20 +51,6 @@ */ /** - * define contants for all datatypes - */ -define('MDB2_TYPE_TEXT' , 0); -define('MDB2_TYPE_BOOLEAN' , 1); -define('MDB2_TYPE_INTEGER' , 2); -define('MDB2_TYPE_DECIMAL' , 3); -define('MDB2_TYPE_FLOAT' , 4); -define('MDB2_TYPE_DATE' , 5); -define('MDB2_TYPE_TIME' , 6); -define('MDB2_TYPE_TIMESTAMP' , 7); -define('MDB2_TYPE_CLOB' , 8); -define('MDB2_TYPE_BLOB' , 9); - -/** * MDB2_Driver_Common: Base class that is extended by each MDB2 driver * * @package MDB2 @@ -74,16 +60,17 @@ class MDB2_Driver_Datatype_Common { var $valid_types = array( - 'text' => MDB2_TYPE_TEXT, - 'boolean' => MDB2_TYPE_BOOLEAN, - 'integer' => MDB2_TYPE_INTEGER, - 'decimal' => MDB2_TYPE_DECIMAL, - 'float' => MDB2_TYPE_FLOAT, - 'date' => MDB2_TYPE_DATE, - 'time' => MDB2_TYPE_TIME, - 'timestamp' => MDB2_TYPE_TIMESTAMP, - 'clob' => MDB2_TYPE_CLOB, - 'blob' => MDB2_TYPE_BLOB + 'text' => true, +# 'serialize' => true, + 'boolean' => true, + 'integer' => true, + 'decimal' => true, + 'float' => true, + 'date' => true, + 'time' => true, + 'timestamp' => true, + 'clob' => true, + 'blob' => true, ); var $db_index; @@ -137,8 +124,8 @@ return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'setResultTypes: ' . $type . ' is not a supported column type'); } - $result->types[$key] = $this->valid_types[$type]; } + $result->types = $types; return MDB2_OK; } @@ -157,24 +144,26 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_TEXT: + case 'text': return $value; - case MDB2_TYPE_INTEGER: +# case 'serialize': +# return $value ? @unserialize($value) : $value; + case 'integer': return intval($value); - case MDB2_TYPE_BOOLEAN: + case 'boolean': return $value == 'Y'; - case MDB2_TYPE_DECIMAL: + case 'decimal': return $value; - case MDB2_TYPE_FLOAT: + case 'float': return doubleval($value); - case MDB2_TYPE_DATE: + case 'date': return $value; - case MDB2_TYPE_TIME: + case 'time': return $value; - case MDB2_TYPE_TIMESTAMP: + case 'timestamp': return $value; - case MDB2_TYPE_CLOB: - case MDB2_TYPE_BLOB: + case 'clob': + case 'blob': $db->lobs[] = array( 'value' => $value, 'position' => 0 @@ -236,9 +225,9 @@ } $type = $types[$current_column]; switch ($type) { - case MDB2_TYPE_TEXT: + case 'text': break; - case MDB2_TYPE_INTEGER: + case 'integer': $row[$key] = intval($row[$key]); break; default: @@ -287,7 +276,7 @@ $db->warnings[] = "unsigned integer field \"$name\" is being declared as signed integer"; } $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteInteger($field['default']) : ''; + $this->quote($field['default'], 'integer') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' INT'.$default.$notnull; } @@ -323,13 +312,45 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteText($field['default']) : ''; + $this->quote($field['default'], 'text') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; $type = isset($field['length']) ? 'CHAR ('.$field['length'].')' : 'TEXT'; return $name.' '.$type.$default.$notnull; } // }}} + // {{{ getSerializeDeclaration() + + /** + * 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: + * + * 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 getSerializeDeclaration($name, $field) +# { +# return $this->getTextDeclaration($name, $field); +# } + + // }}} // {{{ getCLOBDeclaration() /** @@ -419,7 +440,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteBoolean($field['default']) : ''; + $this->quote($field['default'], 'boolean') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' CHAR (1)'.$default.$notnull; } @@ -450,7 +471,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' CHAR ('.strlen('YYYY-MM-DD').')'.$default.$notnull; } @@ -481,7 +502,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTimestamp($field['default']) : ''; + $this->quote($field['default'], 'timestamp') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' CHAR ('.strlen('YYYY-MM-DD HH:MM:SS').')'.$default.$notnull; } @@ -512,7 +533,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTime($field['default']) : ''; + $this->quote($field['default'], 'time') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' CHAR ('.strlen('HH:MM:SS').')'.$default.$notnull; } @@ -543,7 +564,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TEXT'.$default.$notnull; } @@ -574,31 +595,88 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TEXT'.$default.$notnull; } // }}} - // {{{ quoteInteger() + // {{{ quote() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param string $value text string value that is intended to be converted. + * @param string $type type to which the value should be converted to * @return string text string that represents the given argument value in * a DBMS specific format. * @access public */ - function quoteInteger($value) + function quote($value, $type = null) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : (int)$value; + if (is_null($value) + || ($value === '' && $db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) + ) { + return 'NULL'; + } elseif (is_null($type)) { + switch (gettype($value)) { + case 'integer': + $type = 'integer'; + break; + case 'double': + // todo + $type = 'decimal'; + $type = 'float'; + break; + case 'boolean': + $type = 'boolean'; + break; + case 'array': + case 'object': +# $type = 'serialize'; + $type = 'text'; + break; + default: + if (preg_match('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/', $value)) { + $type = 'timestamp'; + } elseif (preg_match('/\d{2}:\d{2}/', $value)) { + $type = 'time'; + } elseif (preg_match('/\d{4}-\d{2}-\d{2}/', $value)) { + $type = 'date'; + } else { + $type = 'text'; + } + break; + } + } + + if (method_exists($this, "_quote{$type}")) { + return $this->{"_quote{$type}"}($value); + } + return $db->raiseError('type not defined: '.$type); + } + + // }}} + // {{{ _quoteInteger() + + /** + * Convert a text value into a DBMS specific format that is suitable to + * compose query statements. + * + * @param string $value text string value that is intended to be converted. + * @return string text string that represents the given argument value in + * a DBMS specific format. + * @access private + */ + function _quoteInteger($value) + { + return (int)$value; } // }}} - // {{{ quoteText() + // {{{ _quoteText() /** * Convert a text value into a DBMS specific format that is suitable to @@ -607,30 +685,49 @@ * @param string $value text string value that is intended to be converted. * @return string text string that already contains any DBMS specific * escaped character sequences. - * @access public + * @access private */ - function quoteText($value) + function _quoteText($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'".$db->escape($value)."'"; + return "'".$db->escape($value)."'"; } + // {{{ _quoteSerialize() + + /** + * Convert a serialize value into a DBMS specific format that is suitable to + * compose query statements. + * + * @param string $value text string value that is intended to be converted. + * @return string text string that already contains any DBMS specific + * escaped character sequences. + * @access private + */ +# function _quoteSerialize($value) +# { +# return $this->quote(serialize($value), 'text'); +# } + // }}} - // {{{ quoteCLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param resource $prepared_query query handle from prepare() - * @param $value + * @param $parameter + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteCLOB($value) + function _quoteCLOB($clob) { - return $this->quoteText($value); + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, + 'quoteCLOB: prepared queries with values of type "clob" are not yet supported'); } // }}} @@ -639,31 +736,34 @@ /** * free a character large object * - * @param int $value lob index + * @param int $clob lob index * @access public */ - function freeCLOBValue($value) + function freeCLOBValue($clob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - unset($db->lobs[$value]); + unset($db->lobs[$clob]); } // }}} - // {{{ quoteBLOB() + // {{{ _quoteBLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param resource $prepared_query query handle from prepare() - * @param $value + * @param $parameter + * @param $blob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBLOB($value) + function _quoteBLOB($blob) { - return $this->quoteText($value); + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, + 'quoteBLOB: prepared queries with values of type "blob" are not yet supported'); } // }}} @@ -672,17 +772,17 @@ /** * free a binary large object * - * @param int $value lob index + * @param int $blob lob index * @access public */ - function freeBLOBValue($value) + function freeBLOBValue($blob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - unset($db->lobs[$value]); + unset($db->lobs[$blob]); } // }}} - // {{{ quoteBoolean() + // {{{ _quoteBoolean() /** * Convert a text value into a DBMS specific format that is suitable to @@ -691,16 +791,15 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBoolean($value) + function _quoteBoolean($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : ($value ? "'Y'" : "'N'"); + return ($value ? "'Y'" : "'N'"); } // }}} - // {{{ quoteDate() + // {{{ _quoteDate() /** * Convert a text value into a DBMS specific format that is suitable to @@ -709,16 +808,15 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDate($value) + function _quoteDate($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'$value'"; + return "'$value'"; } // }}} - // {{{ quoteTimestamp() + // {{{ _quoteTimestamp() /** * Convert a text value into a DBMS specific format that is suitable to @@ -727,16 +825,15 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteTimestamp($value) + function _quoteTimestamp($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'$value'"; + return "'$value'"; } // }}} - // {{{ quoteTime() + // {{{ _quoteTime() /** * Convert a text value into a DBMS specific format that is suitable to @@ -745,16 +842,15 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteTime($value) + function _quoteTime($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'$value'"; + return "'$value'"; } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -763,16 +859,15 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'$value'"; + return "'$value'"; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -781,12 +876,11 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'$value'"; + return "'$value'"; } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/fbsql.php?r1=1.7&r2=1.8&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/fbsql.php diff -u pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.7 pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.8 --- pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.7 Sat Sep 4 18:20:54 2004 +++ pear/MDB2/MDB2/Driver/Datatype/fbsql.php Thu Sep 9 07:59:43 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.7 2004/09/04 22:20:54 lsmith Exp $ +// $Id: fbsql.php,v 1.8 2004/09/09 11:59:43 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -72,9 +72,9 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_BOOLEAN: + case 'boolean': return $value == 'T'; - case MDB2_TYPE_TIME: + case 'time': if ($value[0] == '+') { return substr($value, 1); } else { @@ -123,7 +123,7 @@ declared as signed integer"; } $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteInteger($field['default']) : ''; + $this->quote($field['default'], 'integer') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' INT'.$default.$notnull; } @@ -159,7 +159,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteText($field['default']) : ''; + $this->quote($field['default'], 'text') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; $length = isset($field['length']) ? $field['length'] : $db->max_text_length; return $name.' VARCHAR ('.$length.')'.$default.$notnull; @@ -253,7 +253,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteBoolean($field['default']) : ''; + $this->quote($field['default'], 'boolean') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' BOOLEAN)'.$default.$notnull; } @@ -285,7 +285,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT DATE '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' DATE'.$default.$notnull; } @@ -318,7 +318,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT TIMESTAMP '. - $this->quoteTimestamp($field['default']) : ''; + $this->quote($field['default'], 'timestamp') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TIMESTAMP'.$default.$notnull; } @@ -350,7 +350,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT TIME '. - $this->quoteTime($field['default']) : ''; + $this->quote($field['default'], 'time') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TIME'.$default.$notnull; } @@ -383,7 +383,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' FLOAT'.$default.$notnull; } @@ -417,31 +417,75 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = 'DECIMAL(18,'.$db->options['decimal_places'].')'; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } // }}} - // {{{ quoteBLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBLOB($value) + function _quoteCLOB($clob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'".addslashes($value)."'"; + if ($clob === null) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($clob)) { + $result = $this->readLOB($clob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= $db->escape($data); + } + $value .= "'"; + return $value; } // }}} - // {{{ quoteBoolean() + // {{{ _quoteBLOB() + + /** + * Convert a text value into a DBMS specific format that is suitable to + * compose query statements. + * + * @param $blob + * @return string text string that represents the given argument value in + * a DBMS specific format. + * @access private + */ + function _quoteBLOB($blob) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + if ($blob === null) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($blob)) { + $result = $this->readLOB($blob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= addslashes($data); + } + $value .= "'"; + return $value; + } + + // }}} + // {{{ _quoteBoolean() /** * Convert a text value into a DBMS specific format that is suitable to @@ -450,16 +494,15 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBoolean($value) + function _quoteBoolean($value) { - $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : ($value ? 'True' : 'False'); + return ($value ? 'True' : 'False'); } // }}} - // {{{ quoteDate() + // {{{ _quoteDate() /** * Convert a text value into a DBMS specific format that is suitable to @@ -468,16 +511,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDate($value) + function _quoteDate($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : "DATE'$value'"; + return "DATE'$value'"; } // }}} - // {{{ quoteTimestamp() + // {{{ _quoteTimestamp() /** * Convert a text value into a DBMS specific format that is suitable to @@ -486,16 +529,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteTimestamp($value) + function _quoteTimestamp($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : "TIMESTAMP'$value'"; + return "TIMESTAMP'$value'"; } // }}} - // {{{ quoteTime() + // {{{ _quoteTime() /** * Convert a text value into a DBMS specific format that is suitable to @@ -504,16 +547,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteTime($value) + function _quoteTime($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : "TIME'$value'"; + return "TIME'$value'"; } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -522,16 +565,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : (float)$value; + return (float)$value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -540,12 +583,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : $value; + return $value; } } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/ibase.php?r1=1.9&r2=1.10&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/ibase.php diff -u pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.9 pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.10 --- pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.9 Sat Sep 4 18:16:03 2004 +++ pear/MDB2/MDB2/Driver/Datatype/ibase.php Thu Sep 9 07:59:43 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.9 2004/09/04 22:16:03 lsmith Exp $ +// $Id: ibase.php,v 1.10 2004/09/09 11:59:43 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -71,9 +71,9 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_DECIMAL: + case 'decimal': return sprintf('%.'.$db->options['decimal_places'].'f', doubleval($value)/pow(10.0, $db->options['decimal_places'])); - case MDB2_TYPE_TIMESTAMP: + case 'timestamp': return substr($value, 0, strlen('YYYY-MM-DD HH:MM:SS')); default: return $this->_baseConvertResult($value, $type); @@ -168,7 +168,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = $this->getTypeDeclaration($field); $default = isset($field['default']) ? ' DEFAULT TIME'. - $this->quoteText($field['default']) : ''; + $this->quote($field['default'], 'text') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } @@ -261,7 +261,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -294,7 +294,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTimestamp($field['default']) : ''; + $this->quote($field['default'], 'timestamp') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -325,7 +325,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTime($field['default']) : ''; + $this->quote($field['default'], 'time') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -356,7 +356,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -388,7 +388,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -457,49 +457,49 @@ } // }}} - // {{{ quoteCLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteCLOB($value) + function _quoteCLOB($clob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - if ($value === null) { + if ($clob === null) { return 'NULL'; } - return $this->_quoteLOB($value); + return $this->_quoteLOB($clob); } // }}} - // {{{ quoteBLOB() + // {{{ _quoteBLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $blob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBLOB($value) + function _quoteBLOB($blob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - if ($value === null) { + if ($blob === null) { return 'NULL'; } - return $this->_quoteLOB($value); + return $this->_quoteLOB($blob); } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -508,16 +508,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (($value === null) ? 'NULL' : $value); + return $value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -526,12 +526,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (($value === null) ? 'NULL' : strval(round($value*pow(10.0, $db->options['decimal_places'])))); + return (strval(round($value*pow(10.0, $db->options['decimal_places'])))); } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mssql.php?r1=1.7&r2=1.8&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mssql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.7 pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.8 --- pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.7 Sat Sep 4 18:20:54 2004 +++ pear/MDB2/MDB2/Driver/Datatype/mssql.php Thu Sep 9 07:59:43 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.7 2004/09/04 22:20:54 lsmith Exp $ +// $Id: mssql.php,v 1.8 2004/09/09 11:59:43 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -71,14 +71,14 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_BOOLEAN: + case 'boolean': return $value == '1'; - case MDB2_TYPE_DATE: + case 'date': if (strlen($value) > 10) { $value = substr($value,0,10); } return $value; - case MDB2_TYPE_TIME: + case 'time': if (strlen($value) > 8) { $value = substr($value,11,8); } @@ -120,7 +120,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = isset($field['length']) ? 'VARCHAR ('.$field['length'].')' : 'TEXT'; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteText($field['default']) : ''; + $this->quote($field['default'], 'text') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } @@ -237,7 +237,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteBoolean($field['default']) : ''; + $this->quote($field['default'], 'boolean') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' BIT'.$default.$notnull; } @@ -270,7 +270,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' FLOAT'.$default.$notnull; } @@ -304,31 +304,74 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = 'DECIMAL(18,'.$db->options['decimal_places'].')'; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } // }}} - // {{{ quoteBLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBLOB($value) + function _quoteCLOB($clob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'".bin2hex($value)."'"; + if ($clob === null) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($clob)) { + $result = $this->readLOB($clob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= $db->escape($data); + } + $value .= "'"; + return $value; } // }}} - // {{{ quoteBoolean() + // {{{ _quoteBLOB() + + /** + * Convert a text value into a DBMS specific format that is suitable to + * compose query statements. + * + * @param $blob + * @return string text string that represents the given argument value in + * a DBMS specific format. + * @access private + */ + function _quoteBLOB($blob) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + if ($blob === null) { + return 'NULL'; + } + $value = "0x"; + $data = null; + while (!$this->endOfLOB($blob)) { + $result = $this->readLOB($blob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= bin2hex($data); + } + return $value; + } + + // }}} + // {{{ _quoteBoolean() /** * Convert a text value into a DBMS specific format that is suitable to @@ -337,16 +380,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBoolean($value) + function _quoteBoolean($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : ($value ? 1 : 0); + return ($value ? 1 : 0); } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -355,16 +398,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : $value; + return $value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -373,12 +416,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : $value; + return $value; } } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mysql.php?r1=1.6&r2=1.7&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mysql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.6 pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.7 --- pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.6 Sat Sep 4 18:20:54 2004 +++ pear/MDB2/MDB2/Driver/Datatype/mysql.php Thu Sep 9 07:59:43 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.6 2004/09/04 22:20:54 lsmith Exp $ +// $Id: mysql.php,v 1.7 2004/09/09 11:59:43 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -107,7 +107,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $unsigned = isset($field['unsigned']) ? ' UNSIGNED' : ''; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteInteger($field['default']) : ''; + $this->quote($field['default'], 'integer') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' INT'.$unsigned.$default.$notnull; ; @@ -243,7 +243,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' DATE'.$default.$notnull; } @@ -276,7 +276,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTimestamp($field['default']) : ''; + $this->quote($field['default'], 'timestamp') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' DATETIME'.$default.$notnull; } @@ -308,7 +308,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTime($field['default']) : ''; + $this->quote($field['default'], 'time') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TIME'.$default.$notnull; } @@ -342,7 +342,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = 'DOUBLE'; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } @@ -376,31 +376,75 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = 'DECIMAL(18,'.$db->options['decimal_places'].')'; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } // }}} - // {{{ quoteBLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private + */ + function _quoteCLOB($clob) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + if (is_null($clob)) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($clob)) { + $result = $this->readLOB($clob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= $db->escape($data); + } + $value .= "'"; + return $value; + } + + // }}} + // {{{ _quoteBLOB() + + /** + * Convert a text value into a DBMS specific format that is suitable to + * compose query statements. + * + * @param $blob + * @return string text string that represents the given argument value in + * a DBMS specific format. + * @access private */ - function quoteBLOB($value) + function _quoteBLOB($blob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : "'".addslashes($value)."'"; + if (is_null($blob)) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($blob)) { + $result = $this->readLOB($blob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= addslashes($data); + } + $value .= "'"; + return $value; } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -409,16 +453,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : (float)$value; + return (float)$value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -427,12 +471,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (is_null($value)) ? 'NULL' : $value; + return $value; } } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/oci8.php?r1=1.9&r2=1.10&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/oci8.php diff -u pear/MDB2/MDB2/Driver/Datatype/oci8.php:1.9 pear/MDB2/MDB2/Driver/Datatype/oci8.php:1.10 --- pear/MDB2/MDB2/Driver/Datatype/oci8.php:1.9 Sat Sep 4 18:15:45 2004 +++ pear/MDB2/MDB2/Driver/Datatype/oci8.php Thu Sep 9 07:59:44 2004 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.9 2004/09/04 22:15:45 lsmith Exp $ +// $Id: oci8.php,v 1.10 2004/09/09 11:59:44 lsmith Exp $ require_once 'MDB2/Driver/Datatype/Common.php'; @@ -69,9 +69,9 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_DATE: + case 'date': return substr($value, 0, strlen('YYYY-MM-DD')); - case MDB2_TYPE_TIME: + case 'time': return substr($value, strlen('YYYY-MM-DD '), strlen('HH:MI:SS')); default: return $this->_baseConvertResult($value, $type); @@ -165,7 +165,7 @@ $db->warning = "unsigned integer field \"$name\" is being declared as signed integer"; } $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteInteger($field['default']) : ''; + $this->quote($field['default'], 'integer') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -201,8 +201,8 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = $this->getTypeDeclaration($field); - $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteText($field['default']) : ''; + $default = isset($field['default']) ? ' DEFAULT TIME'. + $this->quote($field['default'], 'text') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } @@ -295,7 +295,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -326,7 +326,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTimestamp($field['default']) : ''; + $this->quoteTimstamp($field['default']) : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -356,7 +356,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $db->quoteTime($field['default']) : ''; + $db->quoteime($field['default']) : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -387,7 +387,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } @@ -418,55 +418,55 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$this->getTypeDeclaration($field).$default.$notnull; } // }}} - // {{{ quoteCLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteCLOB($value) + function _quoteCLOB($clob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - if ($value === null) { + if ($clob === null) { return 'NULL'; } return 'EMPTY_CLOB()'; } // }}} - // {{{ quoteBLOB() + // {{{ _quoteBLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $blob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBLOB($value) + function _quoteBLOB($blob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - if ($value === null) { + if ($blob === null) { return 'NULL'; } return 'EMPTY_BLOB()'; } // }}} - // {{{ quoteDate() + // {{{ _quoteDate() /** * Convert a text value into a DBMS specific format that is suitable to @@ -475,16 +475,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDate($value) + function _quoteDate($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : "TO_DATE('$value','YYYY-MM-DD')"; + return "TO_DATE('$value','YYYY-MM-DD')"; } // }}} - // {{{ quoteTimestamp() + // {{{ _quoteTimestamp() /** * Convert a text value into a DBMS specific format that is suitable to @@ -493,16 +493,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteTimestamp($value) + function _quoteTimestamp($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : "TO_DATE('$value','YYYY-MM-DD HH24:MI:SS')"; + return "TO_DATE('$value','YYYY-MM-DD HH24:MI:SS')"; } // }}} - // {{{ quoteTime() + // {{{ _quoteTime() /** * Convert a text value into a DBMS specific format that is suitable to @@ -511,16 +511,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteTime($value) + function _quoteTime($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : "TO_DATE('0001-01-01 $value','YYYY-MM-DD HH24:MI:SS')"; + return "TO_DATE('0001-01-01 $value','YYYY-MM-DD HH24:MI:SS')"; } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -529,16 +529,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : (float)$value; + return (float)$value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -547,12 +547,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : $value; + return $value; } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/pgsql.php?r1=1.6&r2=1.7&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/pgsql.php diff -u pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.6 pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.7 --- pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.6 Sat Sep 4 18:16:22 2004 +++ pear/MDB2/MDB2/Driver/Datatype/pgsql.php Thu Sep 9 07:59:44 2004 @@ -42,7 +42,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.6 2004/09/04 22:16:22 lsmith Exp $ +// $Id: pgsql.php,v 1.7 2004/09/09 11:59:44 lsmith Exp $ require_once 'MDB2/Driver/Datatype/Common.php'; @@ -70,15 +70,15 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_BOOLEAN: + case 'boolean': return $value == 't'; - case MDB2_TYPE_FLOAT: + case 'float': return doubleval($value); - case MDB2_TYPE_DATE: + case 'date': return $value; - case MDB2_TYPE_TIME: + case 'time': return $value; - case MDB2_TYPE_TIMESTAMP: + case 'timestamp': return substr($value, 0, strlen('YYYY-MM-DD HH:MM:SS')); default: return $this->_baseConvertResult($value, $type); @@ -117,7 +117,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = isset($field['length']) ? 'VARCHAR ('.$field['length'].')' : 'TEXT'; $default = isset($field['default']) ? ' DEFAULT TIME'. - $this->quoteText($field['default']) : ''; + $this->quote($field['default'], 'text') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } @@ -210,7 +210,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteBoolean($field['default']) : ''; + $this->quote($field['default'], 'boolean') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' BOOLEAN'.$default.$notnull; } @@ -241,7 +241,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' DATE'.$default.$notnull; } @@ -272,7 +272,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTime($field['default']) : ''; + $this->quote($field['default'], 'time') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TIME without time zone'.$default.$notnull; } @@ -303,7 +303,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTimestamp($field['default']) : ''; + $this->quote($field['default'], 'timestamp') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TIMESTAMP without time zone'.$default.$notnull; } @@ -334,7 +334,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' FLOAT8'.$default.$notnull; } @@ -365,7 +365,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' NUMERIC(18, '.$db->options['decimal_places'].')'.$default.$notnull; } @@ -432,49 +432,49 @@ } // }}} - // {{{ quoteCLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $clob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteCLOB($value) + function _quoteCLOB($clob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - if ($value === null) { + if ($clob === null) { return 'NULL'; } - return $this->_quoteLOB($value); + return $this->_quoteLOB($clob); } // }}} - // {{{ quoteBLOB() + // {{{ _quoteBLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param $value + * @param $blob * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBLOB($value) + function _quoteBLOB($blob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - if ($value === null) { + if ($blob === null) { return 'NULL'; } - return $this->_quoteLOB($value); + return $this->_quoteLOB($blob); } // }}} - // {{{ quoteBoolean() + // {{{ _quoteBoolean() /** * Convert a text value into a DBMS specific format that is suitable to @@ -483,16 +483,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteBoolean($value) + function _quoteBoolean($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : ($value ? "'t'" : "'f'"); + return ($value ? "'t'" : "'f'"); } // }}} - // {{{ quoteFloat() + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -501,16 +501,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : $value; + return $value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -519,12 +519,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : $value; + return $value; } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/sqlite.php?r1=1.8&r2=1.9&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/sqlite.php diff -u pear/MDB2/MDB2/Driver/Datatype/sqlite.php:1.8 pear/MDB2/MDB2/Driver/Datatype/sqlite.php:1.9 --- pear/MDB2/MDB2/Driver/Datatype/sqlite.php:1.8 Sat Sep 4 18:20:54 2004 +++ pear/MDB2/MDB2/Driver/Datatype/sqlite.php Thu Sep 9 07:59:44 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: sqlite.php,v 1.8 2004/09/04 22:20:54 lsmith Exp $ +// $Id: sqlite.php,v 1.9 2004/09/09 11:59:44 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -71,7 +71,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; switch ($type) { - case MDB2_TYPE_DECIMAL: + case 'decimal': return sprintf('%.'.$db->options['decimal_places'].'f', doubleval($value)/pow(10.0, $db->options['decimal_places'])); default: return $this->_baseConvertResult($value, $type); @@ -112,7 +112,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $unsigned = isset($field['unsigned']) ? ' UNSIGNED' : ''; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteInteger($field['default']) : ''; + $this->quote($field['default'], 'integer') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' INT'.$unsigned.$default.$notnull; ; @@ -248,7 +248,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDate($field['default']) : ''; + $this->quote($field['default'], 'date') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' DATE'.$default.$notnull; } @@ -281,7 +281,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTimestamp($field['default']) : ''; + $this->quote($field['default'], 'timestamp') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' DATETIME'.$default.$notnull; } @@ -313,7 +313,7 @@ { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteTime($field['default']) : ''; + $this->quote($field['default'], 'time') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' TIME'.$default.$notnull; } @@ -347,7 +347,7 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = 'DOUBLE'.($db->options['fixed_float'] ? '('.($db->options['fixed_float']+2).','.$db->options['fixed_float'].')' : ''); $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteFloat($field['default']) : ''; + $this->quote($field['default'], 'float') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } @@ -381,21 +381,75 @@ $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $type = 'BIGINT'; $default = isset($field['default']) ? ' DEFAULT '. - $this->quoteDecimal($field['default']) : ''; + $this->quote($field['default'], 'decimal') : ''; $notnull = isset($field['notnull']) ? ' NOT NULL' : ''; return $name.' '.$type.$default.$notnull; } // }}} - // {{{ quoteCLOB() + // {{{ _quoteCLOB() /** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * + * @param $clob + * @return string text string that represents the given argument value in + * a DBMS specific format. + * @access private + */ + function _quoteCLOB($clob) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + if ($clob === null) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($clob)) { + $result = $this->readLOB($clob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= $db->escape($data); + } + $value .= "'"; + return $value; + } // }}} - // {{{ quoteFloat() + // {{{ _quoteBLOB() + + /** + * Convert a text value into a DBMS specific format that is suitable to + * compose query statements. + * + * @param $blob + * @return string text string that represents the given argument value in + * a DBMS specific format. + * @access private + */ + function _quoteBLOB($blob) + { + $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; + if ($blob === null) { + return 'NULL'; + } + $value = "'"; + $data = null; + while (!$this->endOfLOB($blob)) { + $result = $this->readLOB($blob, $data, $db->options['lob_buffer_length']); + if (MDB2::isError($result)) { + return $result; + } + $value .= $db->escape($data); + } + $value .= "'"; + return $value; + } + + // }}} + // {{{ _quoteFloat() /** * Convert a text value into a DBMS specific format that is suitable to @@ -404,16 +458,16 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteFloat($value) + function _quoteFloat($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return ($value === null) ? 'NULL' : (float)$value; + return (float)$value; } // }}} - // {{{ quoteDecimal() + // {{{ _quoteDecimal() /** * Convert a text value into a DBMS specific format that is suitable to @@ -422,12 +476,12 @@ * @param string $value text string value that is intended to be converted. * @return string text string that represents the given argument value in * a DBMS specific format. - * @access public + * @access private */ - function quoteDecimal($value) + function _quoteDecimal($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; - return (($value === null) ? 'NULL' : strval(round(doubleval($value)*pow(10.0, $db->options['decimal_places'])))); + return (strval(round(doubleval($value)*pow(10.0, $db->options['decimal_places'])))); } }