cvs: pear /MDB2 MDB2.php /MDB2/MDB2/Driver fbsql.php ibase.php mssql.php mysql.php mysqli.php oci8.php pgsql.php querysim.php sqlite.php
/MDB2/MDB2/Driver/Datatype Common.php querysim.php
| From: | Lukas Smith | Date: | Sun, 20 Aug 2006 08:20:55 +0000 |
| Subject: | cvs: pear /MDB2 MDB2.php /MDB2/MDB2/Driver fbsql.php ibase.php mssql.php mysql.php mysqli.php oci8.php pgsql.php querysim.php sqlite.php /MDB2/MDB2/Driver/Datatype Common.php querysim.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-41753@lists.php.net to get a copy of this message | ||
lsmith Sun Aug 20 08:20:55 2006 UTC
Added files:
/pear/MDB2/MDB2/Driver/Datatype querysim.php
Modified files:
/pear/MDB2 MDB2.php
/pear/MDB2/MDB2/Driver fbsql.php ibase.php mssql.php mysql.php
mysqli.php oci8.php pgsql.php querysim.php
sqlite.php
/pear/MDB2/MDB2/Driver/Datatype Common.php
Log:
- refactored _fixResultArrayValues() into convertResultRow of the datatype module
- force loading of the datatype module in MDB2::factory()
- only apply RTRIM for type 'text' or null
http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2.php?r1=1.252&r2=1.253&diff_format=u Index: pear/MDB2/MDB2.php diff -u pear/MDB2/MDB2.php:1.252 pear/MDB2/MDB2.php:1.253 --- pear/MDB2/MDB2.php:1.252 Sat Aug 19 15:21:41 2006 +++ pear/MDB2/MDB2.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: MDB2.php,v 1.252 2006/08/19 15:21:41 lsmith Exp $ +// $Id: MDB2.php,v 1.253 2006/08/20 08:20:54 lsmith Exp $ // /** @@ -393,6 +393,7 @@ if (PEAR::isError($err)) { return $err; } + $db->loadModule('Datatype', null, true); return $db; } @@ -1721,87 +1722,6 @@ } // }}} - // {{{ function _fixResultArrayValues(&$array, $mode) - - /** - * Do all necessary conversions on result arrays to fix DBMS quirks - * - * @param array the array to be fixed (passed by reference) - * @param array bit-wise addition of the required portability modes - * - * @return void - * - * @access protected - */ - function _fixResultArrayValues(&$array, $mode) - { - switch ($mode) { - case MDB2_PORTABILITY_RTRIM: - foreach ($array as $key => $value) { - if (is_string($value)) { - $array[$key] = rtrim($value); - } - } - break; - case MDB2_PORTABILITY_EMPTY_TO_NULL: - foreach ($array as $key => $value) { - if ($value === '') { - $array[$key] = null; - } - } - break; - case MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES: - $tmp_array = array(); - foreach ($array as $key => $value) { - $tmp_array[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value; - } - $array = $tmp_array; - break; - case (MDB2_PORTABILITY_RTRIM + MDB2_PORTABILITY_EMPTY_TO_NULL): - foreach ($array as $key => $value) { - if ($value === '') { - $array[$key] = null; - } elseif (is_string($value)) { - $array[$key] = rtrim($value); - } - } - break; - case (MDB2_PORTABILITY_RTRIM + MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES): - $tmp_array = array(); - foreach ($array as $key => $value) { - if (is_string($value)) { - $value = rtrim($value); - } - $tmp_array[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value; - } - $array = $tmp_array; - break; - case (MDB2_PORTABILITY_EMPTY_TO_NULL + MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES): - $tmp_array = array(); - foreach ($array as $key => $value) { - if ($value === '') { - $value = null; - } - $tmp_array[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value; - } - $array = $tmp_array; - break; - case (MDB2_PORTABILITY_RTRIM + MDB2_PORTABILITY_EMPTY_TO_NULL + MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES): - $tmp_array = array(); - foreach ($array as $key => $value) { - if ($value === '') { - $value = null; - } elseif (is_string($value)) { - $value = rtrim($value); - } - $tmp_array[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value; - } - $array = $tmp_array; - break; - } - } - - // }}} // {{{ function &loadModule($module, $property = null, $phptype_specific = null) /** http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/fbsql.php?r1=1.121&r2=1.122&diff_format=u Index: pear/MDB2/MDB2/Driver/fbsql.php diff -u pear/MDB2/MDB2/Driver/fbsql.php:1.121 pear/MDB2/MDB2/Driver/fbsql.php:1.122 --- pear/MDB2/MDB2/Driver/fbsql.php:1.121 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/fbsql.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.121 2006/08/17 10:56:12 lsmith Exp $ +// $Id: fbsql.php,v 1.122 2006/08/20 08:20:54 lsmith Exp $ // /** @@ -597,15 +597,11 @@ $null = null; return $null; } - if ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) { - $this->db->_fixResultArrayValues($row, MDB2_PORTABILITY_EMPTY_TO_NULL); - } + $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL; + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/ibase.php?r1=1.185&r2=1.186&diff_format=u Index: pear/MDB2/MDB2/Driver/ibase.php diff -u pear/MDB2/MDB2/Driver/ibase.php:1.185 pear/MDB2/MDB2/Driver/ibase.php:1.186 --- pear/MDB2/MDB2/Driver/ibase.php:1.185 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/ibase.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.185 2006/08/17 10:56:12 lsmith Exp $ +// $Id: ibase.php,v 1.186 2006/08/20 08:20:54 lsmith Exp $ /** * MDB2 FireBird/InterBase driver @@ -1049,17 +1049,12 @@ $null = null; return $null; } - if (($mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) - + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) - ) { - $this->db->_fixResultArrayValues($row, $mode); - } + $mode = $mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) + + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL); + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { @@ -1267,17 +1262,12 @@ } $row = $column_names; } - if (($mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) - + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) - ) { - $this->db->_fixResultArrayValues($row, $mode); - } + $mode = $mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) + + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL); + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/mssql.php?r1=1.141&r2=1.142&diff_format=u Index: pear/MDB2/MDB2/Driver/mssql.php diff -u pear/MDB2/MDB2/Driver/mssql.php:1.141 pear/MDB2/MDB2/Driver/mssql.php:1.142 --- pear/MDB2/MDB2/Driver/mssql.php:1.141 Fri Aug 4 05:33:36 2006 +++ pear/MDB2/MDB2/Driver/mssql.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Frank M. Kromann <frank@kromann.info> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.141 2006/08/04 05:33:36 lsmith Exp $ +// $Id: mssql.php,v 1.142 2006/08/20 08:20:54 lsmith Exp $ // // {{{ Class MDB2_Driver_mssql /** @@ -731,15 +731,11 @@ $null = null; return $null; } - if ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) { - $this->db->_fixResultArrayValues($row, MDB2_PORTABILITY_EMPTY_TO_NULL); - } + $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL; + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/mysql.php?r1=1.154&r2=1.155&diff_format=u Index: pear/MDB2/MDB2/Driver/mysql.php diff -u pear/MDB2/MDB2/Driver/mysql.php:1.154 pear/MDB2/MDB2/Driver/mysql.php:1.155 --- pear/MDB2/MDB2/Driver/mysql.php:1.154 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/mysql.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.154 2006/08/17 10:56:12 lsmith Exp $ +// $Id: mysql.php,v 1.155 2006/08/20 08:20:54 lsmith Exp $ // /** @@ -1109,15 +1109,11 @@ $null = null; return $null; } - if ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) { - $this->db->_fixResultArrayValues($row, MDB2_PORTABILITY_EMPTY_TO_NULL); - } + $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL; + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/mysqli.php?r1=1.130&r2=1.131&diff_format=u Index: pear/MDB2/MDB2/Driver/mysqli.php diff -u pear/MDB2/MDB2/Driver/mysqli.php:1.130 pear/MDB2/MDB2/Driver/mysqli.php:1.131 --- pear/MDB2/MDB2/Driver/mysqli.php:1.130 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/mysqli.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysqli.php,v 1.130 2006/08/17 10:56:12 lsmith Exp $ +// $Id: mysqli.php,v 1.131 2006/08/20 08:20:54 lsmith Exp $ // /** @@ -1151,15 +1151,11 @@ $null = null; return $null; } - if ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) { - $this->db->_fixResultArrayValues($row, MDB2_PORTABILITY_EMPTY_TO_NULL); - } + $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL; + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/oci8.php?r1=1.172&r2=1.173&diff_format=u Index: pear/MDB2/MDB2/Driver/oci8.php diff -u pear/MDB2/MDB2/Driver/oci8.php:1.172 pear/MDB2/MDB2/Driver/oci8.php:1.173 --- pear/MDB2/MDB2/Driver/oci8.php:1.172 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/oci8.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.172 2006/08/17 10:56:12 lsmith Exp $ +// $Id: oci8.php,v 1.173 2006/08/20 08:20:54 lsmith Exp $ /** * MDB2 OCI8 driver @@ -990,15 +990,11 @@ if ($this->offset > 0) { array_pop($row); } - if ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) { - $this->db->_fixResultArrayValues($row, MDB2_PORTABILITY_RTRIM); - } + $mode = $this->db->options['portability'] & MDB2_PORTABILITY_RTRIM; + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { @@ -1189,15 +1185,11 @@ } $row = $column_names; } + $mode = $this->db->options['portability'] & MDB2_PORTABILITY_RTRIM; + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } - if ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) { - $this->db->_fixResultArrayValues($row, MDB2_PORTABILITY_RTRIM); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/pgsql.php?r1=1.152&r2=1.153&diff_format=u Index: pear/MDB2/MDB2/Driver/pgsql.php diff -u pear/MDB2/MDB2/Driver/pgsql.php:1.152 pear/MDB2/MDB2/Driver/pgsql.php:1.153 --- pear/MDB2/MDB2/Driver/pgsql.php:1.152 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/pgsql.php Sun Aug 20 08:20:55 2006 @@ -43,7 +43,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.152 2006/08/17 10:56:12 lsmith Exp $ +// $Id: pgsql.php,v 1.153 2006/08/20 08:20:55 lsmith Exp $ /** * MDB2 PostGreSQL driver @@ -999,17 +999,12 @@ $null = null; return $null; } - if (($mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) - + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) - ) { - $this->db->_fixResultArrayValues($row, $mode); - } + $mode = $mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) + + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL); + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/querysim.php?r1=1.73&r2=1.74&diff_format=u Index: pear/MDB2/MDB2/Driver/querysim.php diff -u pear/MDB2/MDB2/Driver/querysim.php:1.73 pear/MDB2/MDB2/Driver/querysim.php:1.74 --- pear/MDB2/MDB2/Driver/querysim.php:1.73 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/querysim.php Sun Aug 20 08:20:55 2006 @@ -61,7 +61,7 @@ // | please contact Alan Richmond. | // +----------------------------------------------------------------------+ // -// $Id: querysim.php,v 1.73 2006/08/17 10:56:12 lsmith Exp $ +// $Id: querysim.php,v 1.74 2006/08/20 08:20:55 lsmith Exp $ // /* @@ -649,17 +649,12 @@ } $row = $column_names; } - if (($mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) - + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) - ) { - $this->db->_fixResultArrayValues($row, $mode); - } + $mode = $mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) + + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL); + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/sqlite.php?r1=1.135&r2=1.136&diff_format=u Index: pear/MDB2/MDB2/Driver/sqlite.php diff -u pear/MDB2/MDB2/Driver/sqlite.php:1.135 pear/MDB2/MDB2/Driver/sqlite.php:1.136 --- pear/MDB2/MDB2/Driver/sqlite.php:1.135 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/sqlite.php Sun Aug 20 08:20:55 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: sqlite.php,v 1.135 2006/08/17 10:56:12 lsmith Exp $ +// $Id: sqlite.php,v 1.136 2006/08/20 08:20:55 lsmith Exp $ // /** @@ -878,17 +878,12 @@ $null = null; return $null; } - if (($mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) - + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) - ) { - $this->db->_fixResultArrayValues($row, $mode); - } + $mode = $mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) + + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL); + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Datatype/Common.php?r1=1.106&r2=1.107&diff_format=u Index: pear/MDB2/MDB2/Driver/Datatype/Common.php diff -u pear/MDB2/MDB2/Driver/Datatype/Common.php:1.106 pear/MDB2/MDB2/Driver/Datatype/Common.php:1.107 --- pear/MDB2/MDB2/Driver/Datatype/Common.php:1.106 Sun Aug 20 07:21:42 2006 +++ pear/MDB2/MDB2/Driver/Datatype/Common.php Sun Aug 20 08:20:55 2006 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.106 2006/08/20 07:21:42 lsmith Exp $ +// $Id: Common.php,v 1.107 2006/08/20 08:20:55 lsmith Exp $ require_once 'MDB2/LOB.php'; @@ -166,10 +166,13 @@ * @return object a MDB2 error on failure * @access protected */ - function _baseConvertResult($value, $type) + function _baseConvertResult($value, $type, $mode) { switch ($type) { case 'text': + if ($mode & MDB2_PORTABILITY_RTRIM) { + $value = rtrim($value); + } return $value; case 'integer': return intval($value); @@ -202,6 +205,13 @@ return fopen('MDB2LOB://'.$lob_index.'@'.$this->db_index, 'r+'); } + if (is_null($type)) { + if ($mode & MDB2_PORTABILITY_RTRIM) { + $value = rtrim($value); + } + return $value; + } + $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; @@ -222,7 +232,7 @@ * @return mixed converted value or a MDB2 error on failure * @access public */ - function convertResult($value, $type) + function convertResult($value, $type, $mode = MDB2_PORTABILITY_ALL) { if (is_null($value)) { return null; @@ -234,11 +244,11 @@ if (!empty($db->options['datatype_map'][$type])) { $type = $db->options['datatype_map'][$type]; if (!empty($db->options['datatype_map_callback'][$type])) { - $parameter = array('type' => $type, 'value' => $value); + $parameter = array('type' => $type, 'value' => $value, 'mode' => $mode); return call_user_func_array($db->options['datatype_map_callback'][$type], array(&$db, __FUNCTION__, $parameter)); } } - return $this->_baseConvertResult($value, $type); + return $this->_baseConvertResult($value, $type, $mode); } // }}} @@ -252,32 +262,43 @@ * @return mixed MDB2_OK on success, a MDB2 error on failure * @access public */ - function convertResultRow($types, $row) + function convertResultRow($types, $row, $mode = MDB2_PORTABILITY_ALL) { - if (is_array($types)) { - reset($types); - $current_column = -1; - foreach ($row as $key => $column) { - ++$current_column; - if (!isset($column)) { - continue; - } - if (isset($types[$current_column])) { - $type = $types[$current_column]; - } elseif (isset($types[$key])) { - $type = $types[$key]; - } elseif (current($types)) { - $type = current($types); - next($types); - } else { - continue; - } - $value = $this->convertResult($row[$key], $type); - if (PEAR::isError($value)) { - return $value; - } - $row[$key] = $value; + if ($mode & MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES) { + $tmp_row = array(); + foreach ($row as $key => $value) { + $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value; + } + $row = $tmp_row; + } + if (!is_array($types)) { + $types = array(); + } + reset($types); + $current_column = -1; + foreach ($row as $key => $value) { + if (($mode & MDB2_PORTABILITY_EMPTY_TO_NULL) && $value === '') { + $row[$key] = null; + } + ++$current_column; + if (!isset($value)) { + continue; + } + if (isset($types[$current_column])) { + $type = $types[$current_column]; + } elseif (isset($types[$key])) { + $type = $types[$key]; + } elseif (current($types)) { + $type = current($types); + next($types); + } else { + $type = null; + } + $value = $this->convertResult($row[$key], $type, $mode); + if (PEAR::isError($value)) { + return $value; } + $row[$key] = $value; } return $row; } @@ -1423,14 +1444,6 @@ { if (is_null($lob['value'])) { $lob['value'] = $lob['resource']; - - $db =& $this->getDBInstance(); - if (PEAR::isError($db)) { - return $db; - } - if ($db->options['portability'] & MDB2_PORTABILITY_RTRIM) { - $lob['value'] = rtrim($lob['value']); - } } $lob['loaded'] = true; return MDB2_OK; http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Datatype/querysim.php?view=markup&rev=1.1 Index: pear/MDB2/MDB2/Driver/Datatype/querysim.php +++ pear/MDB2/MDB2/Driver/Datatype/querysim.php <?php // vim: set et ts=4 sw=4 fdm=marker: // +----------------------------------------------------------------------+ // | PHP versions 4 and 5 | // +----------------------------------------------------------------------+ // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | // | Stig. S. Bakken, Lukas Smith | // | All rights reserved. | // +----------------------------------------------------------------------+ // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | API as well as database abstraction for PHP applications. | // | This LICENSE is in the BSD license style. | // | | // | Redistribution and use in source and binary forms, with or without | // | modification, are permitted provided that the following conditions | // | are met: | // | | // | Redistributions of source code must retain the above copyright | // | notice, this list of conditions and the following disclaimer. | // | | // | Redistributions in binary form must reproduce the above copyright | // | notice, this list of conditions and the following disclaimer in the | // | documentation and/or other materials provided with the distribution. | // | | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Lukas Smith nor the names of his contributors may be used to endorse | // | or promote products derived from this software without specific prior| // | written permission. | // | | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | POSSIBILITY OF SUCH DAMAGE. | // +----------------------------------------------------------------------+ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // // $Id: querysim.php,v 1.1 2006/08/20 08:20:55 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; /** * MDB2 QuerySim driver * * @package MDB2 * @category Database * @author Lukas Smith <smith@pooteeweet.org> */ class MDB2_Driver_Datatype_querysim extends MDB2_Driver_Datatype_Common { // }}} // {{{ getTypeDeclaration() /** * Obtain DBMS specific SQL code portion needed to declare an text type * field to be used in statements like CREATE TABLE. * * @param array $field associative array with the name of the properties * of the field being declared as array indexes. Currently, the types * of supported field properties are as follows: * * length * Integer value that determines the maximum length of the text * field. If this argument is missing the field should be * declared to have the longest length allowed by the DBMS. * * default * Text value to be used as default for this field. * * notnull * Boolean flag that indicates whether this field is constrained * to not be set to null. * @return string DBMS specific SQL code portion that should be used to * declare the specified field. * @access public */ function getTypeDeclaration($field) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'method not implemented', __FUNCTION__); } } ?>
http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2.php?r1=1.252&r2=1.253&diff_format=u Index: pear/MDB2/MDB2.php diff -u pear/MDB2/MDB2.php:1.252 pear/MDB2/MDB2.php:1.253 --- pear/MDB2/MDB2.php:1.252 Sat Aug 19 15:21:41 2006 +++ pear/MDB2/MDB2.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: MDB2.php,v 1.252 2006/08/19 15:21:41 lsmith Exp $ +// $Id: MDB2.php,v 1.253 2006/08/20 08:20:54 lsmith Exp $ // /** @@ -393,6 +393,7 @@ if (PEAR::isError($err)) { return $err; } + $db->loadModule('Datatype', null, true); return $db; } @@ -1721,87 +1722,6 @@ } // }}} - // {{{ function _fixResultArrayValues(&$array, $mode) - - /** - * Do all necessary conversions on result arrays to fix DBMS quirks - * - * @param array the array to be fixed (passed by reference) - * @param array bit-wise addition of the required portability modes - * - * @return void - * - * @access protected - */ - function _fixResultArrayValues(&$array, $mode) - { - switch ($mode) { - case MDB2_PORTABILITY_RTRIM: - foreach ($array as $key => $value) { - if (is_string($value)) { - $array[$key] = rtrim($value); - } - } - break; - case MDB2_PORTABILITY_EMPTY_TO_NULL: - foreach ($array as $key => $value) { - if ($value === '') { - $array[$key] = null; - } - } - break; - case MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES: - $tmp_array = array(); - foreach ($array as $key => $value) { - $tmp_array[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value; - } - $array = $tmp_array; - break; - case (MDB2_PORTABILITY_RTRIM + MDB2_PORTABILITY_EMPTY_TO_NULL): - foreach ($array as $key => $value) { - if ($value === '') { - $array[$key] = null; - } elseif (is_string($value)) { - $array[$key] = rtrim($value); - } - } - break; - case (MDB2_PORTABILITY_RTRIM + MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES): - $tmp_array = array(); - foreach ($array as $key => $value) { - if (is_string($value)) { - $value = rtrim($value); - } - $tmp_array[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value; - } - $array = $tmp_array; - break; - case (MDB2_PORTABILITY_EMPTY_TO_NULL + MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES): - $tmp_array = array(); - foreach ($array as $key => $value) { - if ($value === '') { - $value = null; - } - $tmp_array[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value; - } - $array = $tmp_array; - break; - case (MDB2_PORTABILITY_RTRIM + MDB2_PORTABILITY_EMPTY_TO_NULL + MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES): - $tmp_array = array(); - foreach ($array as $key => $value) { - if ($value === '') { - $value = null; - } elseif (is_string($value)) { - $value = rtrim($value); - } - $tmp_array[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value; - } - $array = $tmp_array; - break; - } - } - - // }}} // {{{ function &loadModule($module, $property = null, $phptype_specific = null) /** http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/fbsql.php?r1=1.121&r2=1.122&diff_format=u Index: pear/MDB2/MDB2/Driver/fbsql.php diff -u pear/MDB2/MDB2/Driver/fbsql.php:1.121 pear/MDB2/MDB2/Driver/fbsql.php:1.122 --- pear/MDB2/MDB2/Driver/fbsql.php:1.121 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/fbsql.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.121 2006/08/17 10:56:12 lsmith Exp $ +// $Id: fbsql.php,v 1.122 2006/08/20 08:20:54 lsmith Exp $ // /** @@ -597,15 +597,11 @@ $null = null; return $null; } - if ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) { - $this->db->_fixResultArrayValues($row, MDB2_PORTABILITY_EMPTY_TO_NULL); - } + $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL; + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/ibase.php?r1=1.185&r2=1.186&diff_format=u Index: pear/MDB2/MDB2/Driver/ibase.php diff -u pear/MDB2/MDB2/Driver/ibase.php:1.185 pear/MDB2/MDB2/Driver/ibase.php:1.186 --- pear/MDB2/MDB2/Driver/ibase.php:1.185 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/ibase.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.185 2006/08/17 10:56:12 lsmith Exp $ +// $Id: ibase.php,v 1.186 2006/08/20 08:20:54 lsmith Exp $ /** * MDB2 FireBird/InterBase driver @@ -1049,17 +1049,12 @@ $null = null; return $null; } - if (($mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) - + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) - ) { - $this->db->_fixResultArrayValues($row, $mode); - } + $mode = $mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) + + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL); + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { @@ -1267,17 +1262,12 @@ } $row = $column_names; } - if (($mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) - + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) - ) { - $this->db->_fixResultArrayValues($row, $mode); - } + $mode = $mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) + + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL); + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/mssql.php?r1=1.141&r2=1.142&diff_format=u Index: pear/MDB2/MDB2/Driver/mssql.php diff -u pear/MDB2/MDB2/Driver/mssql.php:1.141 pear/MDB2/MDB2/Driver/mssql.php:1.142 --- pear/MDB2/MDB2/Driver/mssql.php:1.141 Fri Aug 4 05:33:36 2006 +++ pear/MDB2/MDB2/Driver/mssql.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Frank M. Kromann <frank@kromann.info> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.141 2006/08/04 05:33:36 lsmith Exp $ +// $Id: mssql.php,v 1.142 2006/08/20 08:20:54 lsmith Exp $ // // {{{ Class MDB2_Driver_mssql /** @@ -731,15 +731,11 @@ $null = null; return $null; } - if ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) { - $this->db->_fixResultArrayValues($row, MDB2_PORTABILITY_EMPTY_TO_NULL); - } + $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL; + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/mysql.php?r1=1.154&r2=1.155&diff_format=u Index: pear/MDB2/MDB2/Driver/mysql.php diff -u pear/MDB2/MDB2/Driver/mysql.php:1.154 pear/MDB2/MDB2/Driver/mysql.php:1.155 --- pear/MDB2/MDB2/Driver/mysql.php:1.154 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/mysql.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.154 2006/08/17 10:56:12 lsmith Exp $ +// $Id: mysql.php,v 1.155 2006/08/20 08:20:54 lsmith Exp $ // /** @@ -1109,15 +1109,11 @@ $null = null; return $null; } - if ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) { - $this->db->_fixResultArrayValues($row, MDB2_PORTABILITY_EMPTY_TO_NULL); - } + $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL; + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/mysqli.php?r1=1.130&r2=1.131&diff_format=u Index: pear/MDB2/MDB2/Driver/mysqli.php diff -u pear/MDB2/MDB2/Driver/mysqli.php:1.130 pear/MDB2/MDB2/Driver/mysqli.php:1.131 --- pear/MDB2/MDB2/Driver/mysqli.php:1.130 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/mysqli.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysqli.php,v 1.130 2006/08/17 10:56:12 lsmith Exp $ +// $Id: mysqli.php,v 1.131 2006/08/20 08:20:54 lsmith Exp $ // /** @@ -1151,15 +1151,11 @@ $null = null; return $null; } - if ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL) { - $this->db->_fixResultArrayValues($row, MDB2_PORTABILITY_EMPTY_TO_NULL); - } + $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL; + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/oci8.php?r1=1.172&r2=1.173&diff_format=u Index: pear/MDB2/MDB2/Driver/oci8.php diff -u pear/MDB2/MDB2/Driver/oci8.php:1.172 pear/MDB2/MDB2/Driver/oci8.php:1.173 --- pear/MDB2/MDB2/Driver/oci8.php:1.172 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/oci8.php Sun Aug 20 08:20:54 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.172 2006/08/17 10:56:12 lsmith Exp $ +// $Id: oci8.php,v 1.173 2006/08/20 08:20:54 lsmith Exp $ /** * MDB2 OCI8 driver @@ -990,15 +990,11 @@ if ($this->offset > 0) { array_pop($row); } - if ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) { - $this->db->_fixResultArrayValues($row, MDB2_PORTABILITY_RTRIM); - } + $mode = $this->db->options['portability'] & MDB2_PORTABILITY_RTRIM; + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { @@ -1189,15 +1185,11 @@ } $row = $column_names; } + $mode = $this->db->options['portability'] & MDB2_PORTABILITY_RTRIM; + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } - if ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) { - $this->db->_fixResultArrayValues($row, MDB2_PORTABILITY_RTRIM); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/pgsql.php?r1=1.152&r2=1.153&diff_format=u Index: pear/MDB2/MDB2/Driver/pgsql.php diff -u pear/MDB2/MDB2/Driver/pgsql.php:1.152 pear/MDB2/MDB2/Driver/pgsql.php:1.153 --- pear/MDB2/MDB2/Driver/pgsql.php:1.152 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/pgsql.php Sun Aug 20 08:20:55 2006 @@ -43,7 +43,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.152 2006/08/17 10:56:12 lsmith Exp $ +// $Id: pgsql.php,v 1.153 2006/08/20 08:20:55 lsmith Exp $ /** * MDB2 PostGreSQL driver @@ -999,17 +999,12 @@ $null = null; return $null; } - if (($mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) - + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) - ) { - $this->db->_fixResultArrayValues($row, $mode); - } + $mode = $mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) + + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL); + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/querysim.php?r1=1.73&r2=1.74&diff_format=u Index: pear/MDB2/MDB2/Driver/querysim.php diff -u pear/MDB2/MDB2/Driver/querysim.php:1.73 pear/MDB2/MDB2/Driver/querysim.php:1.74 --- pear/MDB2/MDB2/Driver/querysim.php:1.73 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/querysim.php Sun Aug 20 08:20:55 2006 @@ -61,7 +61,7 @@ // | please contact Alan Richmond. | // +----------------------------------------------------------------------+ // -// $Id: querysim.php,v 1.73 2006/08/17 10:56:12 lsmith Exp $ +// $Id: querysim.php,v 1.74 2006/08/20 08:20:55 lsmith Exp $ // /* @@ -649,17 +649,12 @@ } $row = $column_names; } - if (($mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) - + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) - ) { - $this->db->_fixResultArrayValues($row, $mode); - } + $mode = $mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) + + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL); + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/sqlite.php?r1=1.135&r2=1.136&diff_format=u Index: pear/MDB2/MDB2/Driver/sqlite.php diff -u pear/MDB2/MDB2/Driver/sqlite.php:1.135 pear/MDB2/MDB2/Driver/sqlite.php:1.136 --- pear/MDB2/MDB2/Driver/sqlite.php:1.135 Thu Aug 17 10:56:12 2006 +++ pear/MDB2/MDB2/Driver/sqlite.php Sun Aug 20 08:20:55 2006 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: sqlite.php,v 1.135 2006/08/17 10:56:12 lsmith Exp $ +// $Id: sqlite.php,v 1.136 2006/08/20 08:20:55 lsmith Exp $ // /** @@ -878,17 +878,12 @@ $null = null; return $null; } - if (($mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) - + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) - ) { - $this->db->_fixResultArrayValues($row, $mode); - } + $mode = $mode = ($this->db->options['portability'] & MDB2_PORTABILITY_RTRIM) + + ($this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL); + $row = $this->db->datatype->convertResultRow($this->types, $row); if (!empty($this->values)) { $this->_assignBindColumns($row); } - if (!empty($this->types)) { - $row = $this->db->datatype->convertResultRow($this->types, $row); - } if ($fetchmode === MDB2_FETCHMODE_OBJECT) { $object_class = $this->db->options['fetch_class']; if ($object_class == 'stdClass') { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Datatype/Common.php?r1=1.106&r2=1.107&diff_format=u Index: pear/MDB2/MDB2/Driver/Datatype/Common.php diff -u pear/MDB2/MDB2/Driver/Datatype/Common.php:1.106 pear/MDB2/MDB2/Driver/Datatype/Common.php:1.107 --- pear/MDB2/MDB2/Driver/Datatype/Common.php:1.106 Sun Aug 20 07:21:42 2006 +++ pear/MDB2/MDB2/Driver/Datatype/Common.php Sun Aug 20 08:20:55 2006 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.106 2006/08/20 07:21:42 lsmith Exp $ +// $Id: Common.php,v 1.107 2006/08/20 08:20:55 lsmith Exp $ require_once 'MDB2/LOB.php'; @@ -166,10 +166,13 @@ * @return object a MDB2 error on failure * @access protected */ - function _baseConvertResult($value, $type) + function _baseConvertResult($value, $type, $mode) { switch ($type) { case 'text': + if ($mode & MDB2_PORTABILITY_RTRIM) { + $value = rtrim($value); + } return $value; case 'integer': return intval($value); @@ -202,6 +205,13 @@ return fopen('MDB2LOB://'.$lob_index.'@'.$this->db_index, 'r+'); } + if (is_null($type)) { + if ($mode & MDB2_PORTABILITY_RTRIM) { + $value = rtrim($value); + } + return $value; + } + $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; @@ -222,7 +232,7 @@ * @return mixed converted value or a MDB2 error on failure * @access public */ - function convertResult($value, $type) + function convertResult($value, $type, $mode = MDB2_PORTABILITY_ALL) { if (is_null($value)) { return null; @@ -234,11 +244,11 @@ if (!empty($db->options['datatype_map'][$type])) { $type = $db->options['datatype_map'][$type]; if (!empty($db->options['datatype_map_callback'][$type])) { - $parameter = array('type' => $type, 'value' => $value); + $parameter = array('type' => $type, 'value' => $value, 'mode' => $mode); return call_user_func_array($db->options['datatype_map_callback'][$type], array(&$db, __FUNCTION__, $parameter)); } } - return $this->_baseConvertResult($value, $type); + return $this->_baseConvertResult($value, $type, $mode); } // }}} @@ -252,32 +262,43 @@ * @return mixed MDB2_OK on success, a MDB2 error on failure * @access public */ - function convertResultRow($types, $row) + function convertResultRow($types, $row, $mode = MDB2_PORTABILITY_ALL) { - if (is_array($types)) { - reset($types); - $current_column = -1; - foreach ($row as $key => $column) { - ++$current_column; - if (!isset($column)) { - continue; - } - if (isset($types[$current_column])) { - $type = $types[$current_column]; - } elseif (isset($types[$key])) { - $type = $types[$key]; - } elseif (current($types)) { - $type = current($types); - next($types); - } else { - continue; - } - $value = $this->convertResult($row[$key], $type); - if (PEAR::isError($value)) { - return $value; - } - $row[$key] = $value; + if ($mode & MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES) { + $tmp_row = array(); + foreach ($row as $key => $value) { + $tmp_row[preg_replace('/^(?:.*\.)?([^.]+)$/', '\\1', $key)] = $value; + } + $row = $tmp_row; + } + if (!is_array($types)) { + $types = array(); + } + reset($types); + $current_column = -1; + foreach ($row as $key => $value) { + if (($mode & MDB2_PORTABILITY_EMPTY_TO_NULL) && $value === '') { + $row[$key] = null; + } + ++$current_column; + if (!isset($value)) { + continue; + } + if (isset($types[$current_column])) { + $type = $types[$current_column]; + } elseif (isset($types[$key])) { + $type = $types[$key]; + } elseif (current($types)) { + $type = current($types); + next($types); + } else { + $type = null; + } + $value = $this->convertResult($row[$key], $type, $mode); + if (PEAR::isError($value)) { + return $value; } + $row[$key] = $value; } return $row; } @@ -1423,14 +1444,6 @@ { if (is_null($lob['value'])) { $lob['value'] = $lob['resource']; - - $db =& $this->getDBInstance(); - if (PEAR::isError($db)) { - return $db; - } - if ($db->options['portability'] & MDB2_PORTABILITY_RTRIM) { - $lob['value'] = rtrim($lob['value']); - } } $lob['loaded'] = true; return MDB2_OK; http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Datatype/querysim.php?view=markup&rev=1.1 Index: pear/MDB2/MDB2/Driver/Datatype/querysim.php +++ pear/MDB2/MDB2/Driver/Datatype/querysim.php <?php // vim: set et ts=4 sw=4 fdm=marker: // +----------------------------------------------------------------------+ // | PHP versions 4 and 5 | // +----------------------------------------------------------------------+ // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, | // | Stig. S. Bakken, Lukas Smith | // | All rights reserved. | // +----------------------------------------------------------------------+ // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | // | API as well as database abstraction for PHP applications. | // | This LICENSE is in the BSD license style. | // | | // | Redistribution and use in source and binary forms, with or without | // | modification, are permitted provided that the following conditions | // | are met: | // | | // | Redistributions of source code must retain the above copyright | // | notice, this list of conditions and the following disclaimer. | // | | // | Redistributions in binary form must reproduce the above copyright | // | notice, this list of conditions and the following disclaimer in the | // | documentation and/or other materials provided with the distribution. | // | | // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | // | Lukas Smith nor the names of his contributors may be used to endorse | // | or promote products derived from this software without specific prior| // | written permission. | // | | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | // | POSSIBILITY OF SUCH DAMAGE. | // +----------------------------------------------------------------------+ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // // $Id: querysim.php,v 1.1 2006/08/20 08:20:55 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; /** * MDB2 QuerySim driver * * @package MDB2 * @category Database * @author Lukas Smith <smith@pooteeweet.org> */ class MDB2_Driver_Datatype_querysim extends MDB2_Driver_Datatype_Common { // }}} // {{{ getTypeDeclaration() /** * Obtain DBMS specific SQL code portion needed to declare an text type * field to be used in statements like CREATE TABLE. * * @param array $field associative array with the name of the properties * of the field being declared as array indexes. Currently, the types * of supported field properties are as follows: * * length * Integer value that determines the maximum length of the text * field. If this argument is missing the field should be * declared to have the longest length allowed by the DBMS. * * default * Text value to be used as default for this field. * * notnull * Boolean flag that indicates whether this field is constrained * to not be set to null. * @return string DBMS specific SQL code portion that should be used to * declare the specified field. * @access public */ function getTypeDeclaration($field) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'method not implemented', __FUNCTION__); } } ?>