cvs: pear /MDB2 MDB2.php /MDB2/MDB2 LOB.php /MDB2/MDB2/Driver fbsql.php mssql.php mysql.php oci8.php pgsql.php querysim.php sqlite.php /MDB2/tests
MDB2_bugs_testcase.php MDB2_usage_testcase.php testUtils.php

From: Date: Sat, 04 Sep 2004 22:23:07 +0000
Subject: cvs: pear /MDB2 MDB2.php /MDB2/MDB2 LOB.php /MDB2/MDB2/Driver fbsql.php mssql.php mysql.php oci8.php pgsql.php querysim.php sqlite.php /MDB2/tests
MDB2_bugs_testcase.php MDB2_usage_testcase.php testUtils.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-23632@lists.php.net to get a copy of this message
lsmith Sat Sep 4 18:23:07 2004 EDT Modified files: /pear/MDB2 MDB2.php /pear/MDB2/MDB2 LOB.php /pear/MDB2/MDB2/Driver fbsql.php mssql.php mysql.php oci8.php pgsql.php querysim.php sqlite.php /pear/MDB2/tests MDB2_bugs_testcase.php MDB2_usage_testcase.php testUtils.php Log: - moved prepare/execute API towards PDO (mysql and sqlite tested only)

http://cvs.php.net/diff.php/pear/MDB2/MDB2.php?r1=1.36&r2=1.37&ty=u Index: pear/MDB2/MDB2.php diff -u pear/MDB2/MDB2.php:1.36 pear/MDB2/MDB2.php:1.37 --- pear/MDB2/MDB2.php:1.36 Fri Aug 6 11:24:33 2004 +++ pear/MDB2/MDB2.php Sat Sep 4 18:23:06 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: MDB2.php,v 1.36 2004/08/06 15:24:33 lsmith Exp $ +// $Id: MDB2.php,v 1.37 2004/09/04 22:23:06 lsmith Exp $ // /** @@ -279,24 +279,23 @@ * @return mixed a newly created MDB2 object, or false on error * @access public */ - function &factory($type, $debug = false) + function &factory($type) { - $class_name = 'MDB2_Driver_'.$type; - $include = 'MDB2/Driver/'.$type.'.php'; + $class_name = 'MDB2_Driver_'.$type; + $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php'; - if ($debug) { - include_once $include; - $db =& new $class_name(); - } else { - @include_once $include; - if (!class_exists($class_name)) { - $error =& MDB2_Driver_Common::raiseError(MDB2_ERROR_NOT_FOUND, - null, null, 'Unable to include the '.$include.' file'); - return $error; - } - @$db =& new $class_name(); + if (!MDB2::fileExists($file_name)) { + $error =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, + 'unable to find: '.$file_name); + return $error; + } + if (!include_once($file_name)) { + $error =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, + 'unable to load driver class: '.$file_name); + return $error; } + $db =& new $class_name(); return $db; } @@ -339,16 +338,7 @@ } $type = $dsninfo['phptype']; - if (is_array($options) - && isset($options['debug']) - && $options['debug'] >= 2 - ) { - $debug = true; - } else { - $debug = false; - } - - $db =& MDB2::factory($type, $debug); + $db =& MDB2::factory($type); if (MDB2::isError($db)) { return $db; } @@ -364,6 +354,7 @@ $err = $db->connect(); if (MDB2::isError($err)) { $dsn = $db->getDSN(); + $db->disconnect(); $err->addUserInfo($dsn); return $err; } @@ -427,9 +418,7 @@ } } } else { - if (is_array($GLOBALS['_MDB2_databases']) - && reset($GLOBALS['_MDB2_databases']) - ) { + if (is_array($GLOBALS['_MDB2_databases']) && reset($GLOBALS['_MDB2_databases'])) { $db =& $GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])]; return $db; } @@ -445,12 +434,23 @@ * load a file (like 'Date') * * @param string $file name of the file in the MDB2 directory (without '.php') - * @return $module name of the file to be included from the MDB2 modules dir + * @return string name of the file that was included * @access public */ function loadFile($file) { - include_once 'MDB2/'.$file.'.php'; + $file_name = 'MDB2'.DIRECTORY_SEPARATOR.$file.'.php'; + if (!MDB2::fileExists($file_name)) { + $error =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, + 'unable to find: '.$file_name); + return $error; + } + if (!include_once($file_name)) { + $error =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, + 'unable to load driver class: '.$file_name); + return $error; + } + return $file_name; } // }}} @@ -767,6 +767,28 @@ return $parsed; } + + // }}} + // {{{ fileExists() + + /** + * checks if a file exists in the include path + * + * @access public + * @param string filename + * + * @return boolean true success and false on error + */ + function fileExists($file) + { + $dirs = split(PATH_SEPARATOR, ini_get('include_path')); + foreach ($dirs as $dir) { + if (file_exists($dir . DIRECTORY_SEPARATOR . $file)) { + return true; + } + } + return false; + } } /** @@ -778,14 +800,6 @@ */ class MDB2_Driver_Common extends PEAR { - // {{{ properties - /** - * php version used - * @var integer - * @access public - */ - var $phpversion = 5; - /** * index of the MDB2 object within the $GLOBALS['_MDB2_databases'] array * @var integer @@ -1375,24 +1389,60 @@ if (!$property) { $property = $module; } + if (!isset($this->{$property})) { - $include_dir = 'MDB2/'; - if (@include_once($include_dir.ucfirst($module).'.php')) { - $class_name = 'MDB2_'.ucfirst($module); - } elseif (@include_once($include_dir.'/Driver/'.ucfirst($module).'/'.$this->phptype.'.php')) { + $version = false; + $class_name = 'MDB2_'.ucfirst($module); + $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php'; + if (!MDB2::fileExists($file_name)) { $class_name = 'MDB2_Driver_'.ucfirst($module).'_'.$this->phptype; - } else { + $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php'; + $version = true; + if (!MDB2::fileExists($file_name)) { + $error =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, + 'unable to find module: '.$file_name); + return $error; + } + } + + if (!include_once($file_name)) { $error =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, - 'unable to find module: '.$module); + 'unable to load manager driver class: '.$file_name); return $error; } + // load modul in a specific version + if ($version) { + if (method_exists($class_name, 'factory')) { + $class_name_new = call_user_func(array($class_name, 'factory'), $this->db_index); + if ($class_name != $class_name_new) { + $class_name != $class_name_new; + $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php'; + if (!MDB2::fileExists($file_name)) { + $error =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, + 'unable to find module: '.$file_name); + return $error; + } + if (!include_once($file_name)) { + $error =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, + 'unable to load manager driver class: '.$file_name); + return $error; + } + } + } + } + if (!class_exists($class_name)) { $error =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, 'unable to load module: '.$module.' into property: '.$property); return $error; } $this->{$property} =& new $class_name($this->db_index); + if ($version) { + // this wil be used in the connect method to determine if the module + // needs to be loaded with a different version + $this->loaded_version_modules[] = $property; + } } else if (!is_object($this->{$property})) { $error =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, 'unable to load module: '.$module.' into property: '.$property); @@ -1650,6 +1700,47 @@ } // }}} + // {{{ _wrapResult() + + /** + * wrap a result set into the correct class + * + * @param ressource $result + * @param mixed $types array that contains the types of the columns in + * the result set + * @param mixed $result_class string which specifies which result class to use + * @param mixed $result_wrap_class string which specifies which class to wrap results in + * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure + * @access private + */ + function _wrapResult($result, $ismanip, $types, $result_class, $result_wrap_class, $offset, $limit) + { + if (!$ismanip) { + if (!$result_class) { + $result_class = $this->options['result_buffering'] + ? $this->options['buffered_result_class'] : $this->options['result_class']; + } + $class_name = sprintf($result_class, $this->phptype); + $result =& new $class_name($this, $result, $offset, $limit); + if ($types) { + $err = $result->setResultTypes($types); + if (MDB2::isError($err)) { + $result->free(); + return $err; + } + } + if (!$result_wrap_class) { + $result_wrap_class = $this->options['result_wrap_class']; + } + if ($result_wrap_class) { + $result =& new $result_wrap_class($result); + } + return $result; + } + return MDB2_OK; + } + + // }}} // {{{ setLimit() /** @@ -1850,14 +1941,12 @@ * ? - a quoted scalar value, i.e. strings, integers * * @param string $query the query to prepare - * @param array $types specifies the types of the fields - * @param array $fields specifies the names of the fields (required for LOBs only) * @return mixed resource handle for the prepared query on success, a DB * error on failure * @access public * @see execute */ - function prepare($query, $types = null, $fields = array()) + function prepare($query, $types = null, $result_types = null) { $this->debug($query, 'prepare'); $positions = array(); @@ -1870,264 +1959,30 @@ 'prepare: query with an unterminated text string specified'); } switch ($this->escape_quotes) { - case '': - case "'": + case '': + case "'": + $position = $end_quote + 1; + break; + default: + if ($end_quote == $quote + 1) { $position = $end_quote + 1; - break; - default: - if ($end_quote == $quote + 1) { - $position = $end_quote + 1; + } else { + if ($query[$end_quote-1] == $this->escape_quotes) { + $position = $end_quote; } else { - if ($query[$end_quote-1] == $this->escape_quotes) { - $position = $end_quote; - } else { - $position = $end_quote + 1; - } + $position = $end_quote + 1; } - break; + } + break; } } else { $positions[] = $question; $position = $question + 1; } } - if (!$types) { - if ($count = count($positions)) { - $types = array_fill(0, $count, null); - } else { - $types = array(); - } - } elseif (!is_array($types)) { - if ($count = count($positions)) { - $types = array_fill(0, $count, $types); - } else { - $types = array(); - } - } - $result = $this->loadModule('datatype'); - if (MDB2::isError($result)) { - return $result; - } - end($this->prepared_queries); - $prepared_query = key($this->prepared_queries)+1; - $this->prepared_queries[$prepared_query] = array( - 'query' => $query, - 'positions' => $positions, - 'fields' => array_values($fields), - 'types' => array_values($types), - 'values' => array(), - ); - if ($this->row_limit > 0) { - $this->prepared_queries[$prepared_query]['offset'] = $this->row_offset; - $this->prepared_queries[$prepared_query]['limit'] = $this->row_limit; - } - return $prepared_query; - } - - // }}} - // {{{ _validatePrepared() - - /** - * validate that a handle is infact a prepared query - * - * @param int $prepared_query argument is a handle that was returned by - * the function prepare() - * @access private - */ - function _validatePrepared($prepared_query) - { - if ($prepared_query < 1 || $prepared_query > count($this->prepared_queries)) { - return $this->raiseError(MDB2_ERROR_INVALID, null, null, - 'invalid prepared query'); - } - if (!is_array($this->prepared_queries[$prepared_query])) { - return $this->raiseError(MDB2_ERROR_INVALID, null, null, - 'prepared query was already freed'); - } - return MDB2_OK; - } - - // }}} - // {{{ setParam() - - /** - * Set the value of a parameter of a prepared query. - * - * @param int $prepared_query argument is a handle that was returned - * by the function prepare() - * @param int $parameter the order number of the parameter in the query - * statement. The order number of the first parameter is 1. - * @param mixed $value value that is meant to be assigned to specified - * parameter. The type of the value depends on the $type argument. - * @return mixed MDB2_OK on success, a MDB2 error on failure - * @access public - */ - function setParam($prepared_query, $parameter, $value) - { - $result = $this->_validatePrepared($prepared_query); - if (MDB2::isError($result)) { - return $result; - } - - $this->prepared_queries[$prepared_query]['values'][$parameter] = $value; - return MDB2_OK; - } - - // }}} - // {{{ setParamArray() - - /** - * Set the values of multiple a parameter of a prepared query in bulk. - * - * @param int $prepared_query argument is a handle that was returned by - * the function prepare() - * @param array $params array thats specifies all necessary infromation - * for setParam() the array elements must use keys corresponding to - * the number of the position of the parameter. - * @return mixed MDB2_OK on success, a MDB2 error on failure - * @access public - * @see setParam() - */ - function setParamArray($prepared_query, $params) - { - foreach ($params as $name => $param) { - $success = $this->setParam($prepared_query, $name, $param); - if (MDB2::isError($success)) { - return $success; - } - } - return MDB2_OK; - } - - // }}} - // {{{ freePrepared() - - /** - * Release resources allocated for the specified prepared query. - * - * @param int $prepared_query argument is a handle that was returned by - * the function prepare() - * @return mixed MDB2_OK on success, a MDB2 error on failure - * @access public - */ - function freePrepared($prepared_query) - { - $result = $this->_validatePrepared($prepared_query); - if (MDB2::isError($result)) { - return $result; - } - $this->prepared_queries[$prepared_query] = ''; - return MDB2_OK; - } - - // }}} - // {{{ _executePrepared() - - /** - * Execute a prepared query statement. - * - * @param int $prepared_query argument is a handle that was returned by - * the function prepare() - * @param string $query query to be executed - * @param array $types array that contains the types of the columns in - * the result set - * @param mixed $result_class string which specifies which result class to use - * @param mixed $result_wrap_class string which specifies which class to wrap results in - * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure - * @access private - */ - function &_executePrepared($prepared_query, $query, $types = null, - $result_class = false, $result_wrap_class = false) - { - $result =& $this->query($query, $types, $result_class, $result_wrap_class); - return $result; - } - - // }}} - // {{{ execute() - - /** - * Execute a prepared query statement. - * - * @param int $prepared_query argument is a handle that was returned by - * the function prepare() - * @param array $types array that contains the types of the columns in the - * result set - * @param mixed $result_class string which specifies which result class to use - * @param mixed $result_wrap_class string which specifies which class to wrap results in - * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure - * @access public - */ - function &execute($prepared_query, $types = null, - $result_class = false, $result_wrap_class = false) - { - $result = $this->_validatePrepared($prepared_query); - if (MDB2::isError($result)) { - return $result; - } - $query = ''; - $this->clobs[$prepared_query] = $this->blobs[$prepared_query] = array(); - $count = count($this->prepared_queries[$prepared_query]['positions']); - for ($last_position = $parameter = 0; $parameter < $count; $parameter++) { - $current_position = $this->prepared_queries[$prepared_query]['positions'][$parameter]; - $query .= substr($this->prepared_queries[$prepared_query]['query'], - $last_position, $current_position - $last_position); - if (!isset($this->prepared_queries[$prepared_query]['values'][$parameter])) { - $value_quoted = 'NULL'; - } else { - $value = $this->prepared_queries[$prepared_query]['values'][$parameter]; - $type = $this->prepared_queries[$prepared_query]['types'][$parameter]; - $lob_type = substr($type, 0, 4); - if ($lob_type == 'clob' || $lob_type == 'blob') { - if (is_array($value)) { - $lob = $value; - } elseif ($type == 'clobfile' || $type == 'blobfile') { - $lob = array('type' => 'inputfile', 'file_name' => $value); - } else { - $lob = array('data' => $value); - } - $type = $lob_type; - $lob['prepared_query'] = $prepared_query; - $lob['parameter'] = $parameter; - $value = $this->datatype->createLOB($lob); - if (MDB2::isError($value)) { - return $value; - } - } - $value_quoted = $this->quote($value, $type); - if (MDB2::isError($value_quoted)) { - return $value_quoted; - } - if (is_numeric($value)) { - if ($type == 'clob') { - $this->clobs[$prepared_query][$value] = $value_quoted; - } elseif ($type == 'blob') { - $this->blobs[$prepared_query][$value] = $value_quoted; - } - } - } - $query .= $value_quoted; - $last_position = $current_position + 1; - } - $query .= substr($this->prepared_queries[$prepared_query]['query'], $last_position); - - if ($this->row_limit > 0 || $this->row_offset > 0) { - $this->prepared_queries[$prepared_query]['offset'] = $this->row_offset; - $this->prepared_queries[$prepared_query]['limit'] = $this->row_limit; - } - $success =& $this->_executePrepared($prepared_query, $query, $types, $result_class, $result_wrap_class); - - foreach ($this->clobs[$prepared_query] as $key => $value) { - $this->datatype->destroyLOB($key); - $this->datatype->freeCLOBValue($key, $value); - } - unset($this->clobs[$prepared_query]); - foreach ($this->blobs[$prepared_query] as $key => $value) { - $this->datatype->destroyLOB($key); - $this->datatype->freeBLOBValue($key, $value); - } - unset($this->blobs[$prepared_query]); - return $success; + $class_name = 'MDB2_Statement_'.$this->phptype; + $statement =& new $class_name($this, $query, $positions, $types, $result_types); + return $statement; } // }}} @@ -2974,6 +2829,171 @@ function MDB2_Row(&$row) { $this->__construct($row); + } +} + +class MDB2_Statement_Common +{ + var $mdb; + var $query; + var $positions; + var $result_types; + var $row_offset; + var $row_limit; + var $types; + var $values; + + // {{{ constructor + + /** + * Constructor + */ + function __construct(&$mdb, $query, $positions, $types, $result_types, $statement = null) + { + $this->mdb =& $mdb; + $this->query = $query; + $this->positions = $positions; + $this->types = $types; + $this->result_types = $result_types; + $this->statement = $statement; + $this->mdb->loadModule('datatype'); + } + + function MDB2_Statement_Common(&$mdb, $query, $positions, $types, $result_types, $statement = null) + { + $this->__construct($mdb, $query, $positions, $types, $result_types, $statement); + } + + // }}} + // {{{ bindParam() + + /** + * Set the value of a parameter of a prepared query. + * + * @param int $parameter the order number of the parameter in the query + * statement. The order number of the first parameter is 1. + * @param mixed $value value that is meant to be assigned to specified + * parameter. The type of the value depends on the $type argument. + * @param string $type specifies the type of the field + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function bindParam($parameter, &$value) + { + $this->values[$parameter] =& $value; + return MDB2_OK; + } + + // }}} + // {{{ bindParamArray() + + /** + * Set the values of multiple a parameter of a prepared query in bulk. + * + * @param array $values array thats specifies all necessary infromation + * for setParam() the array elements must use keys corresponding to + * the number of the position of the parameter. + * @param array $types specifies the types of the fields + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + * @see setParam() + */ + function bindParamArray(&$values) + { + $this->values =& $values; + return MDB2_OK; + } + + // }}} + // {{{ _executePrepared() + + /** + * Execute a prepared query statement. + * + * @param mixed $result_class string which specifies which result class to use + * @param mixed $result_wrap_class string which specifies which class to wrap results in + * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure + * @access private + */ + function &_executePrepared($result_class = false, $result_wrap_class = false) + { + $query = ''; + $this->clobs = $this->blobs = array(); + $last_position = $parameter_num = 0; + foreach ($this->values as $parameter => $value) { + $current_position = $this->positions[$parameter_num]; + $query .= substr($this->query, + $last_position, $current_position - $last_position); + if (!isset($value)) { + $value_quoted = 'NULL'; + } else { + $type = isset($this->types[$parameter]) ? $this->types[$parameter] : null; + $lob_type = substr($type, 0, 4); + if ($lob_type == 'clob' || $lob_type == 'blob') { + if ($type == 'clobfile' || $type == 'blobfile') { + $value = file_get_contents($value); + $type = $lob_type; + } elseif (is_resource($value)) { + $value = @fread($value); + } + } + $value_quoted = $this->mdb->quote($value, $type); + if (MDB2::isError($value_quoted)) { + return $value_quoted; + } + } + $query .= $value_quoted; + $last_position = $current_position + 1; + ++$parameter_num; + } + $query .= substr($this->query, $last_position); + + $this->mdb->row_offset = $this->row_offset; + $this->mdb->row_limit = $this->row_limit; + $result =& $this->mdb->query($query, $this->result_types, $result_class, $result_wrap_class); + return $result; + } + + // }}} + // {{{ execute() + + /** + * Execute a prepared query statement. + * + * @param mixed $result_class string which specifies which result class to use + * @param mixed $result_wrap_class string which specifies which class to wrap results in + * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function &execute($result_class = false, $result_wrap_class = false) + { + $success =& $this->_executePrepared($result_class, $result_wrap_class); + + foreach ($this->clobs as $key => $value) { + $this->mdb->datatype->destroyLOB($key); + $this->mdb->datatype->freeCLOBValue($key, $value); + } + unset($this->clobs); + foreach ($this->blobs as $key => $value) { + $this->mdb->datatype->destroyLOB($key); + $this->mdb->datatype->freeBLOBValue($key, $value); + } + unset($this->blobs); + return $success; + } + + // }}} + // {{{ free() + + /** + * Release resources allocated for the specified prepared query. + * + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function free() + { + return MDB2_OK; } } http://cvs.php.net/diff.php/pear/MDB2/MDB2/LOB.php?r1=1.3&r2=1.4&ty=u Index: pear/MDB2/MDB2/LOB.php diff -u pear/MDB2/MDB2/LOB.php:1.3 pear/MDB2/MDB2/LOB.php:1.4 --- pear/MDB2/MDB2/LOB.php:1.3 Sun Feb 15 11:51:36 2004 +++ pear/MDB2/MDB2/LOB.php Sat Sep 4 18:23:06 2004 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: LOB.php,v 1.3 2004/02/15 16:51:36 lsmith Exp $ +// $Id: LOB.php,v 1.4 2004/09/04 22:23:06 lsmith Exp $ // @@ -74,9 +74,6 @@ if (isset($arguments['data'])) { $this->data = $arguments['data']; } - if (isset($arguments['prepared_query'])) { - $this->prepared_query = $arguments['prepared_query']; - } if (isset($arguments['parameter'])) { $this->parameter = $arguments['parameter']; } @@ -163,9 +160,6 @@ function create(&$arguments) { - if (isset($arguments['prepared_query'])) { - $this->prepared_query = $arguments['prepared_query']; - } if (isset($arguments['parameter'])) { $this->parameter = $arguments['parameter']; } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/fbsql.php?r1=1.21&r2=1.22&ty=u Index: pear/MDB2/MDB2/Driver/fbsql.php diff -u pear/MDB2/MDB2/Driver/fbsql.php:1.21 pear/MDB2/MDB2/Driver/fbsql.php:1.22 --- pear/MDB2/MDB2/Driver/fbsql.php:1.21 Thu Jun 3 18:41:45 2004 +++ pear/MDB2/MDB2/Driver/fbsql.php Sat Sep 4 18:23:06 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.21 2004/06/03 22:41:45 quipo Exp $ +// $Id: fbsql.php,v 1.22 2004/09/04 22:23:06 lsmith Exp $ // /** @@ -402,34 +402,13 @@ // Add ; to the end of the query. This is required by FrontBase $query .= ';'; - if ($result = @fbsql_query($query, $this->connection)) { - if ($ismanip) { - return MDB2_OK; - } else { - if (!$result_class) { - $result_class = $this->options['result_buffering'] - ? $this->options['buffered_result_class'] : $this->options['result_class']; - } - $class_name = sprintf($result_class, $this->phptype); - $result =& new $class_name($this, $result, $offset, $limit); - if ($types) { - $err = $result->setResultTypes($types); - if (MDB2::isError($err)) { - $result->free(); - return $err; - } - } - if (!$result_wrap_class) { - $result_wrap_class = $this->options['result_wrap_class']; - } - if ($result_wrap_class) { - $result =& new $result_wrap_class($result); - } - return $result; - } + $result = @fbsql_query($query, $this->connection); + if (!$result) { + $error =& $this->raiseError(); + return $error; } - $error =& $this->raiseError(); - return $error; + $result_obj =& $this->_wrapResult($result, $ismanip, $types, $result_class, $result_wrap_class, $offset, $limit); + return $result_obj; } // }}} @@ -784,6 +763,11 @@ } return $rows; } +} + +class MDB2_Statement_fbsql extends MDB2_Statement_Common +{ + } ?> http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/mssql.php?r1=1.22&r2=1.23&ty=u Index: pear/MDB2/MDB2/Driver/mssql.php diff -u pear/MDB2/MDB2/Driver/mssql.php:1.22 pear/MDB2/MDB2/Driver/mssql.php:1.23 --- pear/MDB2/MDB2/Driver/mssql.php:1.22 Thu Jun 3 18:41:45 2004 +++ pear/MDB2/MDB2/Driver/mssql.php Sat Sep 4 18:23:06 2004 @@ -43,7 +43,7 @@ // | Author: Frank M. Kromann <frank@kromann.info> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.22 2004/06/03 22:41:45 quipo Exp $ +// $Id: mssql.php,v 1.23 2004/09/04 22:23:06 lsmith Exp $ // /** @@ -251,12 +251,6 @@ return $this->query('BEGIN TRANSACTION'); } - function _doQuery($query) - { - $this->current_row = $this->affected_rows = -1; - return @mssql_query($query, $this->connection); - } - // }}} // {{{ connect() @@ -311,7 +305,7 @@ if ($this->supports('transactions') && !$this->auto_commit - && MDB2::isError($this->_doQuery('BEGIN TRANSACTION')) + && !@mssql_query('BEGIN TRANSACTION', $this->connection) ) { @mssql_close($this->connection); $this->connection = 0; @@ -332,16 +326,18 @@ function _close() { if ($this->connection != 0) { + $result = true; if ($this->supports('transactions') && !$this->auto_commit) { - $result = $this->_doQuery('ROLLBACK TRANSACTION'); + $result = !@mssql_query('ROLLBACK TRANSACTION', $this->connection) } @mssql_close($this->connection); $this->connection = 0; $this->affected_rows = -1; unset($GLOBALS['_MDB2_databases'][$this->db_index]); - if (isset($result) && MDB2::isError($result)) { - return $result; + if (!$result) { + $error = $this->raiseError(); + return $error; } } @@ -424,34 +420,14 @@ } $this->connected_database_name = $this->database_name; } - if ($result = $this->_doQuery($query)) { - if ($ismanip) { - return MDB2_OK; - } else { - if (!$result_class) { - $result_class = $this->options['result_buffering'] - ? $this->options['buffered_result_class'] : $this->options['result_class']; - } - $class_name = sprintf($result_class, $this->phptype); - $result =& new $class_name($this, $result, $offset, $limit); - if ($types) { - $err = $result->setResultTypes($types); - if (MDB2::isError($err)) { - $result->free(); - return $err; - } - } - if (!$result_wrap_class) { - $result_wrap_class = $this->options['result_wrap_class']; - } - if ($result_wrap_class) { - $result =& new $result_wrap_class($result); - } - return $result; - } + + $result = @mssql_query($query, $this->connection); + if (!$result) { + $error =& $this->raiseError(); + return $error; } - $error =& $this->raiseError(); - return $error; + $result_obj =& $this->_wrapResult($result, $ismanip, $types, $result_class, $result_wrap_class, $offset, $limit); + return $result_obj; } // }}} @@ -800,6 +776,11 @@ } return $rows; } +} + +class MDB2_Statement_mssql extends MDB2_Statement_Common +{ + } ?> http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/mysql.php?r1=1.23&r2=1.24&ty=u Index: pear/MDB2/MDB2/Driver/mysql.php diff -u pear/MDB2/MDB2/Driver/mysql.php:1.23 pear/MDB2/MDB2/Driver/mysql.php:1.24 --- pear/MDB2/MDB2/Driver/mysql.php:1.23 Thu Jun 3 18:41:45 2004 +++ pear/MDB2/MDB2/Driver/mysql.php Sat Sep 4 18:23:06 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.23 2004/06/03 22:41:45 quipo Exp $ +// $Id: mysql.php,v 1.24 2004/09/04 22:23:06 lsmith Exp $ // /** @@ -418,7 +418,7 @@ * @return the new (modified) query * @access private */ - function _modifyQuery($query) + function _modifyQuery($query, $ismanip, $offset, $limit) { // "DELETE FROM table" gives 0 affected rows in mysql. // This little hack lets you know how many rows were deleted. @@ -428,6 +428,13 @@ 'DELETE FROM \1 WHERE 1=1', $query ); } + if ($limit > 0) { + if ($ismanip) { + $query .= " LIMIT $limit"; + } else { + $query .= " LIMIT $offset,$limit"; + } + } return $query; } @@ -452,23 +459,14 @@ $offset = $this->row_offset; $limit = $this->row_limit; $this->row_offset = $this->row_limit = 0; - if ($limit > 0) { - if ($ismanip) { - $query .= " LIMIT $limit"; - } else { - $query .= " LIMIT $offset,$limit"; - } - } - if ($this->options['portability'] & MDB2_PORTABILITY_DELETE_COUNT) { - $query = $this->_modifyQuery($query); - } + $query = $this->_modifyQuery($query, $ismanip, $offset, $limit); $this->last_query = $query; $this->debug($query, 'query'); if ($this->options['disable_query']) { if ($ismanip) { return MDB2_OK; } - return NULL; + return null; } $connected = $this->connect(); @@ -488,34 +486,14 @@ $function = $this->options['result_buffering'] ? 'mysql_query' : 'mysql_unbuffered_query'; - if ($result = @$function($query, $this->connection)) { - if ($ismanip) { - return MDB2_OK; - } else { - if (!$result_class) { - $result_class = $this->options['result_buffering'] - ? $this->options['buffered_result_class'] : $this->options['result_class']; - } - $class_name = sprintf($result_class, $this->phptype); - $result =& new $class_name($this, $result, $offset, $limit); - if ($types) { - $err = $result->setResultTypes($types); - if (MDB2::isError($err)) { - $result->free(); - return $err; - } - } - if (!$result_wrap_class) { - $result_wrap_class = $this->options['result_wrap_class']; - } - if ($result_wrap_class) { - $result =& new $result_wrap_class($result); - } - return $result; - } + $result = @$function($query, $this->connection); + + if (!$result) { + $error =& $this->raiseError(); + return $error; } - $error =& $this->raiseError(); - return $error; + $result_obj =& $this->_wrapResult($result, $ismanip, $types, $result_class, $result_wrap_class, $offset, $limit); + return $result_obj; } // }}} @@ -688,8 +666,9 @@ function nextID($seq_name, $ondemand = true) { $sequence_name = $this->getSequenceName($seq_name); + $query = "INSERT INTO $sequence_name (".$this->options['seqname_col_name'].") VALUES (NULL)"; $this->expectError(MDB2_ERROR_NOSUCHTABLE); - $result =& $this->query("INSERT INTO $sequence_name (".$this->options['seqname_col_name'].") VALUES (NULL)"); + $result =& $this->query($query); $this->popExpect(); if (MDB2::isError($result)) { if ($ondemand && $result->getCode() == MDB2_ERROR_NOSUCHTABLE) { @@ -812,6 +791,7 @@ } else { $row = @mysql_fetch_row($this->result); } + if (!$row) { if (is_null($this->result)) { return $this->mdb->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, @@ -932,7 +912,7 @@ */ function seek($rownum = 0) { - if (!@mysql_data_seek($this->result, $rownum)) { + if ($this->rownum != ($rownum - 1) && !@mysql_data_seek($this->result, $rownum)) { if (is_null($this->result)) { return $this->mdb->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'seek: resultset has already been freed'); @@ -985,4 +965,8 @@ } } +class MDB2_Statement_mysql extends MDB2_Statement_Common +{ + +} ?> http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/oci8.php?r1=1.18&r2=1.19&ty=u Index: pear/MDB2/MDB2/Driver/oci8.php diff -u pear/MDB2/MDB2/Driver/oci8.php:1.18 pear/MDB2/MDB2/Driver/oci8.php:1.19 --- pear/MDB2/MDB2/Driver/oci8.php:1.18 Thu Jun 3 18:41:45 2004 +++ pear/MDB2/MDB2/Driver/oci8.php Sat Sep 4 18:23:06 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.18 2004/06/03 22:41:45 quipo Exp $ +// $Id: oci8.php,v 1.19 2004/09/04 22:23:06 lsmith Exp $ /** * MDB2 OCI8 driver @@ -377,165 +377,15 @@ * @return mixed result identifier if query executed, else MDB2_error * @access private **/ - function _doQuery($query, $ismanip = null, $prepared_query = 0) + function _doQuery($query) { - $lobs = 0; - $success = MDB2_OK; - $result = 0; - $descriptors = array(); - - if ($prepared_query) { - $columns = ''; - $variables = ''; - for (reset($this->clobs[$prepared_query]), $clob = 0; - $clob < count($this->clobs[$prepared_query]); - $clob++, next($this->clobs[$prepared_query]) - ) { - $clob_stream = key($this->clobs[$prepared_query]); - $descriptors[$clob_stream] = @OCINewDescriptor($this->connection, OCI_D_LOB); - if (!is_object($descriptors[$clob_stream])) { - $success = $this->raiseError(MDB2_ERROR, null, null, - 'Could not create descriptor for clob parameter'); - break; - } - $parameter = $GLOBALS['_MDB2_LOBs'][$clob_stream]->parameter; - $columns.= ($lobs == 0 ? ' RETURNING ' : ','). - $this->prepared_queries[$prepared_query]['fields'][$parameter]; - $variables.= ($lobs == 0 ? ' INTO ' : ',').':clob'.($parameter+1); - ++$lobs; - } - if (!MDB2::isError($success)) { - for (reset($this->blobs[$prepared_query]), $blob = 0; - $blob < count($this->blobs[$prepared_query]); - $blob++, next($this->blobs[$prepared_query]) - ) { - $blob_stream = key($this->blobs[$prepared_query]); - $descriptors[$blob_stream] = @OCINewDescriptor($this->connection, OCI_D_LOB); - if (!is_object($descriptors[$blob_stream])) { - $success = $this->raiseError(MDB2_ERROR, null, null, - 'Could not create descriptor for blob parameter'); - break; - } - $parameter = $GLOBALS['_MDB2_LOBs'][$blob_stream]->parameter; - $columns.= ($lobs == 0 ? ' RETURNING ' : ','). - $this->prepared_queries[$prepared_query]['fields'][$parameter]; - $variables.= ($lobs == 0 ? ' INTO ' : ',').':blob'.($parameter+1); - ++$lobs; - } - $query.= $columns.$variables; - } - } - - if (!MDB2::isError($success)) { - if (($statement = @OCIParse($this->connection, $query))) { - if ($lobs) { - for (reset($this->clobs[$prepared_query]), $clob = 0; - $clob < count($this->clobs[$prepared_query]); - $clob++, next($this->clobs[$prepared_query]) - ) { - $clob_stream = key($this->clobs[$prepared_query]); - $parameter = $GLOBALS['_MDB2_LOBs'][$clob_stream]->parameter; - if (!OCIBindByName($statement, ':clob'.($parameter+1), $descriptors[$clob_stream], -1, OCI_B_CLOB)) { - $success = $this->raiseError(); - break; - } - } - if (!MDB2::isError($success)) { - for (reset($this->blobs[$prepared_query]), $blob = 0; - $blob < count($this->blobs[$prepared_query]); - $blob++, next($this->blobs[$prepared_query]) - ) { - $blob_stream = key($this->blobs[$prepared_query]); - $parameter = $GLOBALS['_MDB2_LOBs'][$blob_stream]->parameter; - if (!OCIBindByName($statement, ':blob'.($parameter+1), $descriptors[$blob_stream], -1, OCI_B_BLOB)) { - $success = $this->raiseError(); - break; - } - } - } - } - if (!MDB2::isError($success)) { - $mode = ($lobs == 0 && $this->auto_commit) ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT; - $result = @OCIExecute($statement, $mode); - if ($result) { - if ($lobs) { - for (reset($this->clobs[$prepared_query]), $clob = 0; - $clob < count($this->clobs[$prepared_query]); - $clob++, next($this->clobs[$prepared_query]) - ) { - $clob_stream = key($this->clobs[$prepared_query]); - for ($value = ''; !$this->datatype->endOfLOB($clob_stream);) { - if ($this->datatype->readLOB($clob_stream, $data, $this->options['lob_buffer_length']) < 0) { - $success = $this->raiseError(); - break; - } - $value.= $data; - } - if (!MDB2::isError($success) && !$descriptors[$clob_stream]->save($value)) { - $success = $this->raiseError(); - } - } - if (!MDB2::isError($success)) { - for (reset($this->blobs[$prepared_query]), $blob = 0; - $blob < count($this->blobs[$prepared_query]); - $blob++, next($this->blobs[$prepared_query]) - ) { - $blob_stream = key($this->blobs[$prepared_query]); - for ($value = ''; !$this->datatype->endOfLOB($blob_stream);) { - if ($this->datatype->readLOB($blob_stream, $data, $this->options['lob_buffer_length']) < 0) { - $success = $this->raiseError(); - break; - } - $value.= $data; - } - if (!MDB2::isError($success) && !$descriptors[$blob_stream]->save($value)) { - $success = $this->raiseError(); - } - } - } - } - if ($this->auto_commit) { - if ($lobs) { - if (MDB2::isError($success)) { - if (!OCIRollback($this->connection)) { - $success = $this->raiseError(); - } - } else { - if (!OCICommit($this->connection)) { - $success = $this->raiseError(); - } - } - } - } else { - ++$this->uncommitedqueries; - } - if (!MDB2::isError($success)) { - if (is_null($ismanip)) { - $ismanip = MDB2::isManip($query); - } - if ($ismanip) { - $this->affected_rows = @OCIRowCount($statement); - @OCIFreeCursor($statement); - } - $result = $statement; - } - } else { - return $this->raiseError($statement); - } - } - } else { - return $this->raiseError(); - } - } - for (reset($descriptors), $descriptor = 0; - $descriptor < count($descriptors); - $descriptor++, next($descriptors) - ) { - @$descriptors[key($descriptors)]->free(); - } - if (MDB2::isError($success)) { - return $success; + if (!($statement = @OCIParse($this->connection, $stmt)) { + $error =& $this->raiseError(MDB2_ERROR, null, null, + 'Could not create statement'); + return $error; } + $mode = $this->auto_commit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT; + $result = @OCIExecute($statement, $mode); return $result; } @@ -572,91 +422,92 @@ } // }}} - // {{{ _executePrepared() + // {{{ query() /** - * Execute a prepared query statement. + * Send a query to the database and return any results * - * @param int $prepared_query argument is a handle that was returned by - * the function prepare() - * @param string $query query to be executed + * @param string $query the SQL query * @param array $types array that contains the types of the columns in the result set * @param mixed $result_class string which specifies which result class to use * @param mixed $result_wrap_class string which specifies which class to wrap results in * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure * - * @access private + * @access public */ - function &_executePrepared($prepared_query, $query, $types = null, - $result_class = false, $result_wrap_class = false) + function &query($query, $types = null, $result_class = false, $result_wrap_class = false) { - $ismanip = MDB2::isManip($query); + $connected = $this->connect(); + if (MDB2::isError($connected)) { + return $connected; + } + $offset = $this->row_offset; $limit = $this->row_limit; $this->row_offset = $this->row_limit = 0; $query = $this->_modifyQuery($query); $this->last_query = $query; $this->debug($query, 'query'); - if ($this->options['disable_query']) { + if ($this->getOption('disable_query')) { if ($ismanip) { return MDB2_OK; } - return NULL; + return null; } - $connected = $this->connect(); - if (MDB2::isError($connected)) { - return $connected; + $result = $this->_doQuery($query); + if (MDB::isError($result)) { + return $result; } - - $result = $this->_doQuery($query, $ismanip, $prepared_query); - if (!MDB2::isError($result)) { - if ($ismanip) { - return MDB2_OK; - } else { - if (!$result_class) { - $result_class = $this->options['result_buffering'] - ? $this->options['buffered_result_class'] : $this->options['result_class']; - } - $class_name = sprintf($result_class, $this->phptype); - $result =& new $class_name($this, $result, $offset, $limit); - if ($types) { - $err = $result->setResultTypes($types); - if (MDB2::isError($err)) { - $result->free(); - return $err; - } - } - if (!$result_wrap_class) { - $result_wrap_class = $this->options['result_wrap_class']; - } - if ($result_wrap_class) { - $result =& new $result_wrap_class($result); - } - return $result; - } + if ($ismanip) { + $this->affected_rows = @OCIRowCount($result); } - return $result; + $result_obj =& $this->_wrapResult($result, $ismanip, $types, $result_class, $result_wrap_class, $offset, $limit); + return $result_obj; } // }}} - // {{{ query() + // {{{ prepare() /** - * Send a query to the database and return any results - * - * @param string $query the SQL query - * @param array $types array that contains the types of the columns in the result set - * @param mixed $result_class string which specifies which result class to use - * @param mixed $result_wrap_class string which specifies which class to wrap results in - * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure + * Prepares a query for multiple execution with execute(). + * With some database backends, this is emulated. + * prepare() requires a generic query as string like + * 'INSERT INTO numbers VALUES(?,?,?)'. The ? are wildcards. + * Types of wildcards: + * ? - a quoted scalar value, i.e. strings, integers * + * @param string $query the query to prepare + * @param array $fields specifies the names of the fields (required for LOBs only) + * @return mixed resource handle for the prepared query on success, a DB + * error on failure * @access public + * @see execute */ - function &query($query, $types = null, $result_class = false, $result_wrap_class = false) + function prepare($query, $types = null, $result_types = null) { - $result =& $this->_executePrepared(false, $query, $types, $result_class, $result_wrap_class); - return $result; + $this->debug($query, 'prepare'); + if (is_array($types)) { + $columns = ''; + $variables = ''; + foreach ($types as $parameter => $type) { + $lob_type = substr($type, 1, 3); + if ($lob_type == 'lob') { + $columns.= ($columns ? ' RETURNING ' : ',').$parameter; + $variables.= ($columns ? ' INTO ' : ',').':'.$parameter; + } + } + $query.= $columns.$variables; + } + if (!($statement = @OCIParse($this->connection, $query)) { + $error =& $this->raiseError(MDB2_ERROR, null, null, + 'Could not create statement'); + return $error; + } + + $class_name = 'MDB2_Statement_'.$this->phptype; + $statement =& new $class_name($this, $query, $positions, $types, $result_types, $statement); + return $statement } // }}} @@ -1073,4 +924,140 @@ } } +class MDB2_Statement_oci8 extends MDB2_Statement +{ + // }}} + // {{{ _executePrepared() + + /** + * Execute a prepared query statement. + * + * @param mixed $result_class string which specifies which result class to use + * @param mixed $result_wrap_class string which specifies which class to wrap results in + * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure + * + * @access private + */ + function &_executePrepared($result_class = false, $result_wrap_class = false) + { + $ismanip = MDB2::isManip($query); + $query = $this->mdb->_modifyQuery($this->query); + $this->mdb->last_query = $query; + $this->mdb->debug($query, 'query'); + if ($this->mdb->getOption('disable_query')) { + if ($ismanip) { + return MDB2_OK; + } + return null; + } + + $connected = $this->mdb->connect(); + if (MDB2::isError($connected)) { + return $connected; + } + + $lob = array(); + $descriptors = array(); + foreach($this->values as $parameter => $value) { + $type = isset($this->types[$parameter]) ? $this->types[$parameter] : null; + $lob_type = substr($type, 0, 4); + if ($lob_type == 'clob' || $lob_type == 'blob') { + if ($type == 'clobfile' || $type == 'blobfile') { + $value = @fopen($value); + $type = $lob_type; + } elseif (is_string($value)) { + // create stream + } + $type = $lob_type; + $descriptors[$parameter] = @OCINewDescriptor($this->mdb->connection, OCI_D_LOB); + if (!is_object($descriptors[$parameter])) { + $success = $this->mdb->raiseError(); + break; + } + } + $value_quoted = $this->quote($value, $type); + if (MDB2::isError($value_quoted)) { + return $value_quoted; + } + if (isset($lob_type)) { + $lobs[$parameter] = $value; + if (!OCIBindByName($statement, ':'.$parameter, $descriptors[$parameter], -1, ($lob_type == 'lob' ? OCI_B_CLOB : OCI_B_BLOB))) { + $success = $this->mdb->raiseError(); + break; + } + } else { + if (!OCIBindByName($statement, ':'.$parameter, $descriptors[$parameter], -1))) { + $success = $this->mdb->raiseError(); + break; + } + } + } + + $mode = ($lobs == 0 && $this->auto_commit) ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT; + $result = @OCIExecute($statement, $mode); + if (!$result) { + $error =& $this->mdb->raiseError(); + return $error; + } + + if (!empty($lobs)) { + foreach ($lobs as $parameter => $stream) { + while (($data = @fread($stream, $this->getOption('lob_buffer_length')))) { + if (!$descriptors[$parameter]->write($data, $this->getOption('lob_buffer_length'))) { + $success = $this->mdb->raiseError(); + break(2); + } + } + } + + if (!MDB2::isError($success)) { + if ($this->auto_commit) { + if (MDB2::isError($success)) { + if (!OCIRollback($this->mdb->connection)) { + $success = $this->mdb->raiseError(); + } + } else { + if (!OCICommit($this->mdb->connection)) { + $success = $this->mdb->raiseError(); + } + } + } else { + ++$this->mdb->uncommitedqueries; + } + } + } + + reset($descriptors); + for ($j = count($descriptors); $descriptor < $j; next($descriptors)) { + @$descriptors[key($descriptors)]->free(); + } + + if (MDB2::isError($success)) { + return $success;; + } + + if ($ismanip) { + $this->mdb->affected_rows = @OCIRowCount($statement); + } + + $result_obj =& $this->mdb->_wrapResult($result, $ismanip, $this->types, + $result_class, $result_wrap_class, $this->row_offset, $lthis->row_imit); + return $result_obj; + } + + // }}} + // {{{ free() + + /** + * Release resources allocated for the specified prepared query. + * + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function free() + { + @OCIFreeStatement($this->statement); + return MDB2_OK; + } +} ?> http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/pgsql.php?r1=1.20&r2=1.21&ty=u Index: pear/MDB2/MDB2/Driver/pgsql.php diff -u pear/MDB2/MDB2/Driver/pgsql.php:1.20 pear/MDB2/MDB2/Driver/pgsql.php:1.21 --- pear/MDB2/MDB2/Driver/pgsql.php:1.20 Thu Jun 3 18:41:45 2004 +++ pear/MDB2/MDB2/Driver/pgsql.php Sat Sep 4 18:23:06 2004 @@ -43,7 +43,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.20 2004/06/03 22:41:45 quipo Exp $ +// $Id: pgsql.php,v 1.21 2004/09/04 22:23:06 lsmith Exp $ /** * MDB2 PostGreSQL driver @@ -396,6 +396,32 @@ } // }}} + // {{{ _modifyQuery() + + /** + * This method is used by backends to alter queries for various + * reasons. + * + * @param string $query query to modify + * @return the new (modified) query + * @access private + */ + function _modifyQuery($query, $ismanip, $offset, $limit) + { + if ($limit > 0) { + if ($ismanip) { + $manip = preg_replace('/^(DELETE FROM|UPDATE).*$/', '\\1', $query); + $form = $match[2]; + $where = $match[3]; + $query = $manip.' '.$from." WHERE ctid=(SELECT ctid FROM $from $where LIMIT $limit"); + } else { + $query .= " LIMIT $limit OFFSET $offset"; + } + } + return $query; + } + + // }}} // {{{ query() /** @@ -416,6 +442,7 @@ $offset = $this->row_offset; $limit = $this->row_limit; $this->row_offset = $this->row_limit = 0; + $query = $this->_modifyQuery($query, $ismanip, $offset, $limit); $this->last_query = $query; $this->debug($query, 'query'); if ($this->options['disable_query']) { @@ -430,70 +457,22 @@ return $connected; } - if (!$ismanip && $limit > 0) { - if ($this->auto_commit && MDB2::isError($result = $this->_doQuery('BEGIN'))) { - return $result; - } - $result = $this->_doQuery('DECLARE select_cursor SCROLL CURSOR FOR '.$query); - if (!MDB2::isError($result)) { - if ($offset > 0 - && MDB2::isError($result = $this->_doQuery("MOVE FORWARD $offset FROM select_cursor")) - ) { - @pg_free_result($result); - return $result; - } - $result = $this->_doQuery("FETCH FORWARD $limit FROM select_cursor"); - if (MDB2::isError($result)) { - @pg_free_result($result); - return $result; - } - } else { - return $result; - } - if ($this->auto_commit && MDB2::isError($result2 = $this->_doQuery('END'))) { - @pg_free_result($result); - return $result2; - } - } else { - $result = $this->_doQuery($query); - if (MDB2::isError($result)) { - return $result; - } + $result = $this->_doQuery($query); + if (MDB::isError($result)) { + return $result; } - if (!MDB2::isError($result)) { - if ($ismanip) { - $this->affected_rows = @pg_affected_rows($result); - return MDB2_OK; - } elseif ((preg_match('/^\s*\(?\s*SELECT\s+/si', $query) - && !preg_match('/^\s*\(?\s*SELECT\s+INTO\s/si', $query)) - || preg_match('/^\s*EXPLAIN/si',$query) - ) { - if (!$result_class) { - $result_class = $this->options['result_buffering'] - ? $this->options['buffered_result_class'] : $this->options['result_class']; - } - $class_name = sprintf($result_class, $this->phptype); - $result =& new $class_name($this, $result, $offset, $limit); - if ($types) { - $err = $result->setResultTypes($types); - if (MDB2::isError($err)) { - $result->free(); - return $err; - } - } - if (!$result_wrap_class) { - $result_wrap_class = $this->options['result_wrap_class']; - } - if ($result_wrap_class) { - $result =& new $result_wrap_class($result); - } - return $result; - } else { - $this->affected_rows = 0; - return MDB2_OK; - } + if ($ismanip) { + $this->affected_rows = @pg_affected_rows($result); + } elseif ((preg_match('/^\s*\(?\s*SELECT\s+/si', $query) + && !preg_match('/^\s*\(?\s*SELECT\s+INTO\s/si', $query)) + || preg_match('/^\s*EXPLAIN/si',$query) + ) { + $result_obj =& $this->_wrapResult($result, $ismanip, $types, $result_class, $result_wrap_class, $offset, $limit); + return $result_obj; + } else { + $this->affected_rows = 0; + return MDB2_OK; } - return $result; } // }}} @@ -805,4 +784,8 @@ } } +class MDB2_Statement_pgsql extends MDB2_Statement_Common +{ + +} ?> http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/querysim.php?r1=1.15&r2=1.16&ty=u Index: pear/MDB2/MDB2/Driver/querysim.php diff -u pear/MDB2/MDB2/Driver/querysim.php:1.15 pear/MDB2/MDB2/Driver/querysim.php:1.16 --- pear/MDB2/MDB2/Driver/querysim.php:1.15 Mon May 24 17:51:40 2004 +++ pear/MDB2/MDB2/Driver/querysim.php Sat Sep 4 18:23:06 2004 @@ -61,7 +61,7 @@ // | please contact Alan Richmond. | // +----------------------------------------------------------------------+ // -// $Id: querysim.php,v 1.15 2004/05/24 21:51:40 quipo Exp $ +// $Id: querysim.php,v 1.16 2004/09/04 22:23:06 lsmith Exp $ // /* @@ -376,33 +376,15 @@ return $connected; } - if ($result = $this->_buildResult($query)) { - if ($limit > 0) { - $result[1] = array_slice($result[1], $offset-1, $limit); - } - if (!$result_class) { - $result_class = $this->options['result_buffering'] - ? $this->options['buffered_result_class'] : $this->options['result_class']; - } - $class_name = sprintf($result_class, $this->phptype); - $result =& new $class_name($this, $result, $offset, $limit); - if ($types) { - $err = $result->setResultTypes($types); - if (MDB2::isError($err)) { - $result->free(); - return $err; - } - } - if (!$result_wrap_class) { - $result_wrap_class = $this->options['result_wrap_class']; - } - if ($result_wrap_class) { - $result =& new $result_wrap_class($result); - } - return $result; + if (!$result) { + $error =& $this->raiseError(); + return $error; + } + if ($limit > 0) { + $result[1] = array_slice($result[1], $offset-1, $limit); } - $error =& $this->raiseError(); - return $error; + $result_obj =& $this->_wrapResult($result, $ismanip, $types, $result_class, $result_wrap_class, $offset, $limit); + return $result_obj; } // }}} @@ -741,6 +723,12 @@ $rows = count($this->result[1]); return $rows; } +} + + +class MDB2_Statement_querysim extends MDB2_Statement_Common +{ + } ?> http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/sqlite.php?r1=1.24&r2=1.25&ty=u Index: pear/MDB2/MDB2/Driver/sqlite.php diff -u pear/MDB2/MDB2/Driver/sqlite.php:1.24 pear/MDB2/MDB2/Driver/sqlite.php:1.25 --- pear/MDB2/MDB2/Driver/sqlite.php:1.24 Mon May 24 17:51:40 2004 +++ pear/MDB2/MDB2/Driver/sqlite.php Sat Sep 4 18:23:06 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: sqlite.php,v 1.24 2004/05/24 21:51:40 quipo Exp $ +// $Id: sqlite.php,v 1.25 2004/09/04 22:23:06 lsmith Exp $ // /** @@ -397,7 +397,7 @@ * @return the new (modified) query * @access private */ - function _modifyQuery($query) + function _modifyQuery($query, $ismanip, $offset, $limit) { // "DELETE FROM table" gives 0 affected rows in sqlite. // This little hack lets you know how many rows were deleted. @@ -407,6 +407,13 @@ 'DELETE FROM \1 WHERE 1=1', $query ); } + if ($limit > 0) { + if ($ismanip) { + $query .= " LIMIT $limit"; + } else { + $query .= " LIMIT $offset,$limit"; + } + } return $query; } @@ -431,23 +438,14 @@ $offset = $this->row_offset; $limit = $this->row_limit; $this->row_offset = $this->row_limit = 0; - if ($limit > 0) { - if ($ismanip) { - $query .= " LIMIT $limit"; - } else { - $query .= " LIMIT $limit OFFSET $offset"; - } - } - if ($this->options['portability'] & MDB2_PORTABILITY_DELETE_COUNT) { - $query = $this->_modifyQuery($query); - } + $query = $this->_modifyQuery($query, $ismanip, $offset, $limit); $this->last_query = $query; $this->debug($query, 'query'); if ($this->options['disable_query']) { if ($ismanip) { return MDB2_OK; } - return NULL; + return null; } $connected = $this->connect(); @@ -461,34 +459,13 @@ $result = @$function($query.';', $this->connection); ini_restore('track_errors'); $this->_lasterror = isset($php_errormsg) ? $php_errormsg : ''; - if ($result) { - if ($ismanip) { - return MDB2_OK; - } else { - if (!$result_class) { - $result_class = $this->options['result_buffering'] - ? $this->options['buffered_result_class'] : $this->options['result_class']; - } - $class_name = sprintf($result_class, $this->phptype); - $result =& new $class_name($this, $result, $offset, $limit); - if ($types) { - $err = $result->setResultTypes($types); - if (MDB2::isError($err)) { - $result->free(); - return $err; - } - } - if (!$result_wrap_class) { - $result_wrap_class = $this->options['result_wrap_class']; - } - if ($result_wrap_class) { - $result =& new $result_wrap_class($result); - } - return $result; - } + + if (!$result) { + $error =& $this->raiseError(); + return $error; } - $error =& $this->raiseError(); - return $error; + $result_obj =& $this->_wrapResult($result, $ismanip, $types, $result_class, $result_wrap_class, $offset, $limit); + return $result_obj; } // }}} @@ -896,6 +873,11 @@ } return $rows; } +} + +class MDB2_Statement_sqlite extends MDB2_Statement_Common +{ + } ?> http://cvs.php.net/diff.php/pear/MDB2/tests/MDB2_bugs_testcase.php?r1=1.9&r2=1.10&ty=u Index: pear/MDB2/tests/MDB2_bugs_testcase.php diff -u pear/MDB2/tests/MDB2_bugs_testcase.php:1.9 pear/MDB2/tests/MDB2_bugs_testcase.php:1.10 --- pear/MDB2/tests/MDB2_bugs_testcase.php:1.9 Wed May 12 08:58:47 2004 +++ pear/MDB2/tests/MDB2_bugs_testcase.php Sat Sep 4 18:23:06 2004 @@ -114,9 +114,9 @@ } } - function insertTestValues($prepared_query, &$data) { + function insertTestValues(&$prepared_query, &$data) { for ($i = 0; $i < count($this->fields); $i++) { - $this->db->setParam($prepared_query, $i, $data[$this->fields[$i]]); + $prepared_query->bindParam($i, $data[$this->fields[$i]]); } } @@ -140,13 +140,13 @@ $this->insertTestValues($prepared_query, $data); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); if (MDB2::isError($result)) { $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage()); } - $this->db->freePrepared($prepared_query); + $prepared_query->free(); $result =& $this->db->query('SELECT * FROM users ORDER BY user_name'); @@ -203,7 +203,7 @@ $prepared_query = $this->db->prepare('INSERT INTO users (user_name, user_password, subscribed, user_id, quota, weight, access_date, access_time, approved) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->types); $this->insertTestValues($prepared_query, $data); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); $result = $this->db->query('SELECT user_name FROM users'); $col = $result->fetchCol('user_name'); @@ -215,7 +215,7 @@ $data['user_id'] = 2; $this->insertTestValues($prepared_query, $data); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); $result = $this->db->query('SELECT user_name FROM users'); $col = $result->fetchCol('user_name'); @@ -225,7 +225,7 @@ $data['user_name'] = null; - $this->db->freePrepared($prepared_query); + $prepared_query->free(); } /** @@ -249,13 +249,13 @@ $prepared_query = $this->db->prepare('INSERT INTO users (user_name, user_password, subscribed, user_id, quota, weight, access_date, access_time, approved) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->types); $this->insertTestValues($prepared_query, $data); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); $result = $this->db->query('SELECT * FROM users'); $numrows = $result->numRows(); $this->assertEquals(1, $numrows, "Numrows is not returning proper value"); - $this->db->freePrepared($prepared_query); + $prepared_query->free(); } /** @@ -274,12 +274,12 @@ $prepared_query = $this->db->prepare('INSERT INTO users (user_name, user_password, subscribed, user_id, quota, weight, access_date, access_time, approved) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->types); $this->insertTestValues($prepared_query, $data); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); $row = $this->db->queryRow('SELECT a.user_id, b.user_id FROM users a, users b where a.user_id = b.user_id', array('integer', 'integer'), MDB2_FETCHMODE_ORDERED); $this->assertEquals(2, count($row), "Columns with the same name get overwritten in ordered mode"); - $this->db->freePrepared($prepared_query); + $prepared_query->free(); } /** @@ -304,13 +304,13 @@ $this->insertTestValues($prepared_query, $data[$row]); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); if (MDB2::isError($result)) { $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage()); } } - $this->db->freePrepared($prepared_query); + $prepared_query->free(); $this->db->setLimit(3, 1); $result = $this->db->query('SELECT * FROM users'); http://cvs.php.net/diff.php/pear/MDB2/tests/MDB2_usage_testcase.php?r1=1.14&r2=1.15&ty=u Index: pear/MDB2/tests/MDB2_usage_testcase.php diff -u pear/MDB2/tests/MDB2_usage_testcase.php:1.14 pear/MDB2/tests/MDB2_usage_testcase.php:1.15 --- pear/MDB2/tests/MDB2_usage_testcase.php:1.14 Fri May 21 06:59:05 2004 +++ pear/MDB2/tests/MDB2_usage_testcase.php Sat Sep 4 18:23:06 2004 @@ -41,7 +41,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: MDB2_usage_testcase.php,v 1.14 2004/05/21 10:59:05 lsmith Exp $ +// $Id: MDB2_usage_testcase.php,v 1.15 2004/09/04 22:23:06 lsmith Exp $ class MDB2_Usage_TestCase extends PHPUnit_TestCase { //contains the dsn of the database we are testing @@ -123,9 +123,9 @@ return true; } - function insertTestValues($prepared_query, &$data) { + function insertTestValues(&$prepared_query, &$data) { for ($i = 0; $i < count($this->fields); $i++) { - $this->db->setParam($prepared_query, $i, $data[$this->fields[$i]]); + $prepared_query->bindParam($i, $data[$this->fields[$i]]); } } @@ -169,9 +169,9 @@ $this->insertTestValues($prepared_query, $data); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); - $this->db->freePrepared($prepared_query); + $prepared_query->free(); if (MDB2::isError($result)) { $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage()); @@ -212,14 +212,14 @@ $this->insertTestValues($prepared_query, $data[$row]); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); if (MDB2::isError($result)) { $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage()); } } - $this->db->freePrepared($prepared_query); + $prepared_query->free(); $total_fields = count($this->fields); for ($i = 0; $i < $total_fields; $i++) { @@ -261,14 +261,14 @@ $this->insertTestValues($prepared_query, $data[$row]); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); if (MDB2::isError($result)) { $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage()); } } - $this->db->freePrepared($prepared_query); + $prepared_query->free(); $first_col = array(); for ($row = 0; $row < $total_rows; $row++) { @@ -329,7 +329,7 @@ $this->insertTestValues($prepared_query, $data[$row]); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); if (MDB2::isError($result)) { $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage()); @@ -338,7 +338,7 @@ $fields = array_keys($data[0]); $query = 'SELECT '. implode (', ', $fields). ' FROM users ORDER BY user_name'; - $this->db->freePrepared($prepared_query); + $prepared_query->free(); //$result =& $this->db->query('SELECT user_name, user_password, FROM users', $this->types); //$result =& $this->db->query('SELECT * FROM users'); @@ -369,11 +369,12 @@ $prepared_query = $this->db->prepare("INSERT INTO users (user_name, user_password, user_id) VALUES (?, $question_value, 1)", array('text')); - $this->db->setParam($prepared_query, 0, 'Sure!'); + $value = 'Sure!'; + $prepared_query->bindParam(0, $value); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); - $this->db->freePrepared($prepared_query); + $prepared_query->free(); if (MDB2::isError($result)) { $error = $result->getMessage(); @@ -385,11 +386,12 @@ $prepared_query = $this->db->prepare("INSERT INTO users (user_name, user_password, user_id) VALUES (?, $question_value, 2)", array('text')); - $this->db->setParam($prepared_query, 0, 'For Sure!'); + $value = 'For Sure!'; + $prepared_query->bindParam(0, $value); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); - $this->db->freePrepared($prepared_query); + $prepared_query->free(); if (MDB2::isError($result)) { $error = $result->getMessage(); @@ -423,9 +425,9 @@ $this->insertTestValues($prepared_query, $data); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); - $this->db->freePrepared($prepared_query); + $prepared_query->free(); if (MDB2::isError($result)) { $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage()); @@ -583,14 +585,14 @@ $this->insertTestValues($prepared_query, $data[$row]); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); if (MDB2::isError($result)) { $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage()); } } - $this->db->freePrepared($prepared_query); + $prepared_query->free(); for ($rows = 2, $start_row = 0; $start_row < $total_rows; $start_row += $rows) { @@ -853,7 +855,11 @@ $this->insertTestValues($prepared_query, $data[$row]); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); + + if (MDB2::isError($result)) { + $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage()); + } $affected_rows = $this->db->affectedRows(); if (MDB2::isError($affected_rows)) { @@ -861,21 +867,20 @@ } else { $this->assertEquals(1, $affected_rows, "Inserting the row $row returned $affected_rows affected row count instead of 1 as expected"); } - - if (MDB2::isError($result)) { - $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage()); - } } - $this->db->freePrepared($prepared_query); + $prepared_query->free(); $prepared_query = $this->db->prepare('UPDATE users SET user_password=? WHERE user_id < ?', array('text', 'integer')); for ($row = 0; $row < $total_rows; $row++) { - $this->db->setParam($prepared_query, 0, "another_password_$row"); - $this->db->setParam($prepared_query, 1, $row); + $password = "another_password_$row"; + if ($row == 0) { + $prepared_query->bindParam(0, $password); + $prepared_query->bindParam(1, $row); + } - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); if (MDB2::isError($result)) { $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage()); @@ -889,14 +894,16 @@ } } - $this->db->freePrepared($prepared_query); + $prepared_query->free(); $prepared_query = $this->db->prepare('DELETE FROM users WHERE user_id >= ?', array('integer')); + $row = intval($total_rows / 2); + $prepared_query->bindParam(0, $row); for ($row = $total_rows; $total_rows; $total_rows = $row) { - $this->db->setParam($prepared_query, 0, $row = intval($total_rows / 2)); + $row = intval($total_rows / 2); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); if (MDB2::isError($result)) { $this->assertTrue(false, 'Error executing prepared query'.$result->getMessage()); @@ -912,7 +919,7 @@ } - $this->db->freePrepared($prepared_query); + $prepared_query->free(); } /** @@ -940,7 +947,7 @@ $prepared_query = $this->db->prepare('INSERT INTO users (user_name, user_password, subscribed, user_id, quota, weight, access_date, access_time, approved) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->types); $this->insertTestValues($prepared_query, $data); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); $this->db->rollback(); $result =& $this->db->query('SELECT * FROM users'); @@ -952,7 +959,7 @@ $result->free(); $this->insertTestValues($prepared_query, $data); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); $this->db->commit(); $result =& $this->db->query('SELECT * FROM users'); @@ -972,7 +979,7 @@ $autocommit = $this->db->autocommit(1); $this->assertTrue(!MDB2::isError($autocommit), 'Error autocommiting transactions'); - $this->db->freePrepared($prepared_query); + $prepared_query->free(); $result =& $this->db->query('SELECT * FROM users'); if (MDB2::isError($result)) { @@ -992,7 +999,8 @@ return; } - $prepared_query = $this->db->prepare('INSERT INTO files (ID, document, picture) VALUES (1,?,?)', array('clob', 'blob'), array('document', 'picture')); + $query = 'INSERT INTO files (ID, document, picture) VALUES (1,?,?)'; + $prepared_query = $this->db->prepare($query, array('document' => 'clob', 'picture' => 'blob')); $character_lob = ''; for ($code = 32; $code <= 127; $code++) { @@ -1003,16 +1011,16 @@ $binary_lob .= chr($code); } - $this->db->setParam($prepared_query, 0, $character_lob); - $this->db->setParam($prepared_query, 1, $binary_lob); + $prepared_query->bindParam('document', $character_lob); + $prepared_query->bindParam('picture', $binary_lob); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); if (MDB2::isError($result)) { $this->assertTrue(false, 'Error executing prepared query: '.$result->getUserInfo()); } - $this->db->freePrepared($prepared_query); + $prepared_query->free(); $result =& $this->db->query('SELECT document, picture FROM files', array('clob', 'blob')); if (MDB2::isError($result)) { @@ -1060,7 +1068,8 @@ return; } - $prepared_query = $this->db->prepare('INSERT INTO files (ID, document, picture) VALUES (1,?,?)', array('clobfile', 'blobfile'), array('document', 'picture')); + $query = 'INSERT INTO files (ID, document, picture) VALUES (1,?,?)'; + $prepared_query = $this->db->prepare($query, array('document' => 'clobfile', 'picture' => 'blobfile')); $character_data_file = 'character_data'; if (($file = fopen($character_data_file, 'w'))) { @@ -1080,13 +1089,13 @@ fclose($file); } - $this->db->setParam($prepared_query, 0, $character_data_file); - $this->db->setParam($prepared_query, 1, $binary_data_file); + $prepared_query->bindParam('document', $character_data_file); + $prepared_query->bindParam('picture', $binary_data_file); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); $this->assertTrue(!MDB2::isError($result), 'Error executing prepared query - inserting LOB from files'); - $this->db->freePrepared($prepared_query); + $prepared_query->free(); $result =& $this->db->query('SELECT document, picture FROM files', array('clob', 'blob')); if (MDB2::isError($result)) { @@ -1139,15 +1148,17 @@ return; } - $prepared_query = $this->db->prepare('INSERT INTO files (ID, document,picture) VALUES (1,?,?)', array('clob', 'blob'), array('document', 'picture')); + $query = 'INSERT INTO files (ID, document, picture) VALUES (1,?,?)'; + $prepared_query = $this->db->prepare($query, array('document' => 'clob', 'picture' => 'blob')); - $this->db->setParam($prepared_query, 0, null); - $this->db->setParam($prepared_query, 1, null); + $null = null; + $prepared_query->bindParam('document', $null); + $prepared_query->bindParam('picture', $null); - $result = $this->db->execute($prepared_query); + $result = $prepared_query->execute(); $this->assertTrue(!MDB2::isError($result), 'Error executing prepared query - inserting NULL lobs'); - $this->db->freePrepared($prepared_query); + $prepared_query->free(); $result =& $this->db->query('SELECT document, picture FROM files', array('clob', 'blob')); if (MDB2::isError($result)) { http://cvs.php.net/diff.php/pear/MDB2/tests/testUtils.php?r1=1.4&r2=1.5&ty=u Index: pear/MDB2/tests/testUtils.php diff -u pear/MDB2/tests/testUtils.php:1.4 pear/MDB2/tests/testUtils.php:1.5 --- pear/MDB2/tests/testUtils.php:1.4 Fri Jul 23 07:32:03 2004 +++ pear/MDB2/tests/testUtils.php Sat Sep 4 18:23:06 2004 @@ -17,7 +17,7 @@ * @return array of methods beginning with test */ function getTests($class) { - $methods = get_class_methods($class); + $methods = array_flip(array_change_key_case(array_flip(get_class_methods($class)), CASE_LOWER)); return array_filter($methods, 'grepForTest'); }
« previous php.pear.cvs (#23632) next »