cvs: pear /MDB2/MDB2/Driver/Datatype fbsql.php ibase.php mssql.php mysql.php pgsql.php
| From: | Lukas Smith | Date: | Fri, 22 Oct 2004 20:38:34 +0000 |
| Subject: | cvs: pear /MDB2/MDB2/Driver/Datatype fbsql.php ibase.php mssql.php mysql.php pgsql.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-25080@lists.php.net to get a copy of this message | ||
lsmith Fri Oct 22 16:38:34 2004 EDT
Modified files:
/pear/MDB2/MDB2/Driver/Datatype fbsql.php ibase.php mssql.php
mysql.php pgsql.php
Log:
- refactored LOB handling
http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/fbsql.php?r1=1.10&r2=1.11&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/fbsql.php diff -u pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.10 pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.11 --- pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.10 Thu Sep 9 15:13:37 2004 +++ pear/MDB2/MDB2/Driver/Datatype/fbsql.php Fri Oct 22 16:38:34 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.10 2004/09/09 19:13:37 lsmith Exp $ +// $Id: fbsql.php,v 1.11 2004/10/22 20:38:34 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -436,6 +436,7 @@ */ function _quoteBLOB($value) { + $value = $this->_readFile($value); return "'".addslashes($value)."'"; } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/ibase.php?r1=1.12&r2=1.13&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/ibase.php diff -u pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.12 pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.13 --- pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.12 Thu Sep 9 15:13:37 2004 +++ pear/MDB2/MDB2/Driver/Datatype/ibase.php Fri Oct 22 16:38:34 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.12 2004/09/09 19:13:37 lsmith Exp $ +// $Id: ibase.php,v 1.13 2004/10/22 20:38:34 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -400,47 +400,60 @@ * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param resource $prepared_query query handle from prepare() - * @param $parameter - * @param $lob + * @param $value * @return string text string that represents the given argument value in * a DBMS specific format. * @access private */ - function _quoteLOB($lob) + function _quoteLOB($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; if (MDB2::isError($connect = $db->connect())) { return $connect; } - $prepared_query = $GLOBALS['_MDB2_LOBs'][$lob]->prepared_query; - $parameter = $GLOBALS['_MDB2_LOBs'][$lob]->parameter; - $value = ''; // DEAL WITH ME if (!$db->transaction_id = @ibase_trans(IBASE_COMMITTED, $db->connection)) { return $db->raiseError(MDB2_ERROR, null, null, 'Could not start a new transaction: '.ibase_errmsg()); } - - if (($lo = @ibase_blob_create($db->auto_commit ? $db->connection : $db->transaction_id))) { - while (!$this->endOfLOB($lob)) { - $result = $this->readLOB($lob, $data, $db->options['lob_buffer_length']); - if (MDB2::isError($result)) { - break; - } - if (@ibase_blob_add($lo, $data) === false) { + $close = true; + if (is_resource($value)) { + $close = false; + } elseif (preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) { + if ($match[1] == 'file://') { + $value = $match[2]; + } + $value = @fopen($value, 'r'); + } else { + $fp = @tmpfile(); + @fwrite($fp, $value); + @rewind($fp); + $value = $fp; + } +/* + $prepared_query = $GLOBALS['_MDB2_LOBs'][$lob]->prepared_query; + $parameter = $GLOBALS['_MDB2_LOBs'][$lob]->parameter; +*/ + if (($handle = @ibase_blob_create($db->auto_commit ? $db->connection : $db->transaction_id))) { + while (!@feof($value)) { + $data = @fread($value, $db->options['lob_buffer_length']); + if (@ibase_blob_add($handle, $data) === false) { $result = $db->raiseError(MDB2_ERROR, null, null, 'Could not add data to a large object: '.ibase_errmsg()); break; } } + if ($close) { + @fclose($value); + } if (MDB2::isError($result)) { - @ibase_blob_cancel($lo); + @ibase_blob_cancel($handle); } else { - $value = @ibase_blob_close($lo); + $value = @ibase_blob_close($handle); } } else { $result = $db->raiseError(); } +/* if (!isset($db->query_parameters[$prepared_query])) { $db->query_parameters[$prepared_query] = array(0, ''); $db->query_parameter_values[$prepared_query] = array(); @@ -449,7 +462,7 @@ $db->query_parameters[$prepared_query][$query_parameter] = $value; $db->query_parameter_values[$prepared_query][$parameter] = $query_parameter; $value = '?'; - +*/ if (!$db->auto_commit) { $db->commit(); } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mssql.php?r1=1.10&r2=1.11&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mssql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.10 pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.11 --- pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.10 Thu Sep 9 15:13:37 2004 +++ pear/MDB2/MDB2/Driver/Datatype/mssql.php Fri Oct 22 16:38:34 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.10 2004/09/09 19:13:37 lsmith Exp $ +// $Id: mssql.php,v 1.11 2004/10/22 20:38:34 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -323,8 +323,8 @@ */ function _quoteBLOB($value) { + $value = $this->_readFile($value); return bin2hex("0x".$value); - } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mysql.php?r1=1.9&r2=1.10&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mysql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.9 pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.10 --- pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.9 Thu Sep 9 15:13:37 2004 +++ pear/MDB2/MDB2/Driver/Datatype/mysql.php Fri Oct 22 16:38:34 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.9 2004/09/09 19:13:37 lsmith Exp $ +// $Id: mysql.php,v 1.10 2004/10/22 20:38:34 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -395,6 +395,7 @@ */ function _quoteBLOB($value) { + $value = $this->_readFile($value); return "'".addslashes($value)."'"; } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/pgsql.php?r1=1.9&r2=1.10&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/pgsql.php diff -u pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.9 pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.10 --- pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.9 Thu Sep 9 15:13:37 2004 +++ pear/MDB2/MDB2/Driver/Datatype/pgsql.php Fri Oct 22 16:38:34 2004 @@ -42,7 +42,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.9 2004/09/09 19:13:37 lsmith Exp $ +// $Id: pgsql.php,v 1.10 2004/10/22 20:38:34 lsmith Exp $ require_once 'MDB2/Driver/Datatype/Common.php'; @@ -377,38 +377,48 @@ * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param resource $prepared_query query handle from prepare() - * @param $parameter - * @param $lob + * @param $value * @return string text string that represents the given argument value in * a DBMS specific format. * @access private */ - function _quoteLOB($lob) + function _quoteLOB($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $connect = $db->connect(); if (MDB2::isError($connect)) { return $connect; } - $prepared_query = $GLOBALS['_MDB2_LOBs'][$lob]->prepared_query; - $parameter = $GLOBALS['_MDB2_LOBs'][$lob]->parameter; if ($db->auto_commit && !@pg_exec($db->connection, 'BEGIN')) { return $db->raiseError(MDB2_ERROR, null, null, 'error starting transaction'); } + $close = true; + if (is_resource($value)) { + $close = false; + } elseif (preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) { + if ($match[1] == 'file://') { + $value = $match[2]; + } + $value = @fopen($value, 'r'); + } else { + $fp = @tmpfile(); + @fwrite($fp, $value); + @rewind($fp); + $value = $fp; + } if (($lo = @pg_locreate($db->connection))) { if (($handle = @pg_loopen($db->connection, $lo, 'w'))) { - while (!$this->endOfLOB($lob)) { - $result = $this->readLOB($lob, $data, $db->options['lob_buffer_length']); - if (MDB2::isError($result)) { - break; - } - if (!pg_lowrite($handle, $data)) { + while (!@feof($value)) { + $data = @fread($value, $db->options['lob_buffer_length']); + if (!@pg_lowrite($handle, $data)) { $result = $db->raiseError(); break; } } + if ($close) { + @fclose($value); + } @pg_loclose($handle); if (!MDB2::isError($result)) { $value = strval($lo);
http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/fbsql.php?r1=1.10&r2=1.11&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/fbsql.php diff -u pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.10 pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.11 --- pear/MDB2/MDB2/Driver/Datatype/fbsql.php:1.10 Thu Sep 9 15:13:37 2004 +++ pear/MDB2/MDB2/Driver/Datatype/fbsql.php Fri Oct 22 16:38:34 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.10 2004/09/09 19:13:37 lsmith Exp $ +// $Id: fbsql.php,v 1.11 2004/10/22 20:38:34 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -436,6 +436,7 @@ */ function _quoteBLOB($value) { + $value = $this->_readFile($value); return "'".addslashes($value)."'"; } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/ibase.php?r1=1.12&r2=1.13&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/ibase.php diff -u pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.12 pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.13 --- pear/MDB2/MDB2/Driver/Datatype/ibase.php:1.12 Thu Sep 9 15:13:37 2004 +++ pear/MDB2/MDB2/Driver/Datatype/ibase.php Fri Oct 22 16:38:34 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.12 2004/09/09 19:13:37 lsmith Exp $ +// $Id: ibase.php,v 1.13 2004/10/22 20:38:34 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -400,47 +400,60 @@ * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param resource $prepared_query query handle from prepare() - * @param $parameter - * @param $lob + * @param $value * @return string text string that represents the given argument value in * a DBMS specific format. * @access private */ - function _quoteLOB($lob) + function _quoteLOB($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; if (MDB2::isError($connect = $db->connect())) { return $connect; } - $prepared_query = $GLOBALS['_MDB2_LOBs'][$lob]->prepared_query; - $parameter = $GLOBALS['_MDB2_LOBs'][$lob]->parameter; - $value = ''; // DEAL WITH ME if (!$db->transaction_id = @ibase_trans(IBASE_COMMITTED, $db->connection)) { return $db->raiseError(MDB2_ERROR, null, null, 'Could not start a new transaction: '.ibase_errmsg()); } - - if (($lo = @ibase_blob_create($db->auto_commit ? $db->connection : $db->transaction_id))) { - while (!$this->endOfLOB($lob)) { - $result = $this->readLOB($lob, $data, $db->options['lob_buffer_length']); - if (MDB2::isError($result)) { - break; - } - if (@ibase_blob_add($lo, $data) === false) { + $close = true; + if (is_resource($value)) { + $close = false; + } elseif (preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) { + if ($match[1] == 'file://') { + $value = $match[2]; + } + $value = @fopen($value, 'r'); + } else { + $fp = @tmpfile(); + @fwrite($fp, $value); + @rewind($fp); + $value = $fp; + } +/* + $prepared_query = $GLOBALS['_MDB2_LOBs'][$lob]->prepared_query; + $parameter = $GLOBALS['_MDB2_LOBs'][$lob]->parameter; +*/ + if (($handle = @ibase_blob_create($db->auto_commit ? $db->connection : $db->transaction_id))) { + while (!@feof($value)) { + $data = @fread($value, $db->options['lob_buffer_length']); + if (@ibase_blob_add($handle, $data) === false) { $result = $db->raiseError(MDB2_ERROR, null, null, 'Could not add data to a large object: '.ibase_errmsg()); break; } } + if ($close) { + @fclose($value); + } if (MDB2::isError($result)) { - @ibase_blob_cancel($lo); + @ibase_blob_cancel($handle); } else { - $value = @ibase_blob_close($lo); + $value = @ibase_blob_close($handle); } } else { $result = $db->raiseError(); } +/* if (!isset($db->query_parameters[$prepared_query])) { $db->query_parameters[$prepared_query] = array(0, ''); $db->query_parameter_values[$prepared_query] = array(); @@ -449,7 +462,7 @@ $db->query_parameters[$prepared_query][$query_parameter] = $value; $db->query_parameter_values[$prepared_query][$parameter] = $query_parameter; $value = '?'; - +*/ if (!$db->auto_commit) { $db->commit(); } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mssql.php?r1=1.10&r2=1.11&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mssql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.10 pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.11 --- pear/MDB2/MDB2/Driver/Datatype/mssql.php:1.10 Thu Sep 9 15:13:37 2004 +++ pear/MDB2/MDB2/Driver/Datatype/mssql.php Fri Oct 22 16:38:34 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.10 2004/09/09 19:13:37 lsmith Exp $ +// $Id: mssql.php,v 1.11 2004/10/22 20:38:34 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -323,8 +323,8 @@ */ function _quoteBLOB($value) { + $value = $this->_readFile($value); return bin2hex("0x".$value); - } // }}} http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/mysql.php?r1=1.9&r2=1.10&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/mysql.php diff -u pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.9 pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.10 --- pear/MDB2/MDB2/Driver/Datatype/mysql.php:1.9 Thu Sep 9 15:13:37 2004 +++ pear/MDB2/MDB2/Driver/Datatype/mysql.php Fri Oct 22 16:38:34 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.9 2004/09/09 19:13:37 lsmith Exp $ +// $Id: mysql.php,v 1.10 2004/10/22 20:38:34 lsmith Exp $ // require_once 'MDB2/Driver/Datatype/Common.php'; @@ -395,6 +395,7 @@ */ function _quoteBLOB($value) { + $value = $this->_readFile($value); return "'".addslashes($value)."'"; } http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Datatype/pgsql.php?r1=1.9&r2=1.10&ty=u Index: pear/MDB2/MDB2/Driver/Datatype/pgsql.php diff -u pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.9 pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.10 --- pear/MDB2/MDB2/Driver/Datatype/pgsql.php:1.9 Thu Sep 9 15:13:37 2004 +++ pear/MDB2/MDB2/Driver/Datatype/pgsql.php Fri Oct 22 16:38:34 2004 @@ -42,7 +42,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.9 2004/09/09 19:13:37 lsmith Exp $ +// $Id: pgsql.php,v 1.10 2004/10/22 20:38:34 lsmith Exp $ require_once 'MDB2/Driver/Datatype/Common.php'; @@ -377,38 +377,48 @@ * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * - * @param resource $prepared_query query handle from prepare() - * @param $parameter - * @param $lob + * @param $value * @return string text string that represents the given argument value in * a DBMS specific format. * @access private */ - function _quoteLOB($lob) + function _quoteLOB($value) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; $connect = $db->connect(); if (MDB2::isError($connect)) { return $connect; } - $prepared_query = $GLOBALS['_MDB2_LOBs'][$lob]->prepared_query; - $parameter = $GLOBALS['_MDB2_LOBs'][$lob]->parameter; if ($db->auto_commit && !@pg_exec($db->connection, 'BEGIN')) { return $db->raiseError(MDB2_ERROR, null, null, 'error starting transaction'); } + $close = true; + if (is_resource($value)) { + $close = false; + } elseif (preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) { + if ($match[1] == 'file://') { + $value = $match[2]; + } + $value = @fopen($value, 'r'); + } else { + $fp = @tmpfile(); + @fwrite($fp, $value); + @rewind($fp); + $value = $fp; + } if (($lo = @pg_locreate($db->connection))) { if (($handle = @pg_loopen($db->connection, $lo, 'w'))) { - while (!$this->endOfLOB($lob)) { - $result = $this->readLOB($lob, $data, $db->options['lob_buffer_length']); - if (MDB2::isError($result)) { - break; - } - if (!pg_lowrite($handle, $data)) { + while (!@feof($value)) { + $data = @fread($value, $db->options['lob_buffer_length']); + if (!@pg_lowrite($handle, $data)) { $result = $db->raiseError(); break; } } + if ($close) { + @fclose($value); + } @pg_loclose($handle); if (!MDB2::isError($result)) { $value = strval($lo);