cvs: pear /MDB pgsql.php

From: Date: Thu, 18 Jul 2002 11:40:41 +0000
Subject: cvs: pear /MDB pgsql.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-5174@lists.php.net to get a copy of this message
lsmith Thu Jul 18 07:40:41 2002 EDT Modified files: /pear/MDB pgsql.php Log: more fixes by Paul Cooper: "I've just noticed that we seem to have two fetch methods in pgsql.php. In this patch I've picked my favourite, plus there are lots of other cleanups in the patch for LOB stuff (still not working)." Index: pear/MDB/pgsql.php diff -u pear/MDB/pgsql.php:1.9 pear/MDB/pgsql.php:1.10 --- pear/MDB/pgsql.php:1.9 Thu Jul 18 06:19:18 2002 +++ pear/MDB/pgsql.php Thu Jul 18 07:40:41 2002 @@ -42,7 +42,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ -// $Id: pgsql.php,v 1.9 2002/07/18 10:19:18 lsmith Exp $ +// $Id: pgsql.php,v 1.10 2002/07/18 11:40:41 lsmith Exp $ // MDB postgresql driver. @@ -367,6 +367,15 @@ return DB_OK; } elseif (preg_match('/^\s*\(?\s*SELECT\s+/si', $query) && !preg_match('/^\s*\(?\s*SELECT\s+INTO\s/si', $query)) { $this->highest_fetched_row[$result] = -1; + if ($types != NULL) { + if (!is_array($types)) { + $types = array($types); + } + if (MDB::isError($err = $this->setResultTypes($result, $types))) { + $this->freeResult($result); + return $err; + } + } return $result; } else { $this->affected_rows = 0; @@ -394,24 +403,6 @@ return ($this->highest_fetched_row[$result] >= $this->numRows($result) - 1); } - // }}} - // {{{ fetch() - /** - * fetch value from a result set - * - * @param resource $result result identifier - * @param int $row number of the row where the data can be found - * @param int $field field number where the data can be found - * - * @return mixed string on success, a DB error on failure - * - * @access public - */ - function fetch($result, $row, $field) - { - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $row); - return (pg_result($result, $row, $field)); - } // }}} // {{{ retrieveLob() @@ -427,23 +418,23 @@ function retrieveLOB($lob) { if (!isset($this->lobs[$lob])) { - return ($this->SetError("Retrieve LOB", "it was not specified a valid lob")); + return ($this->raiseError(DB_ERROR_INVALID, NULL, NULL, "Retrieve LOB: did not specified a valid lob")); } if (!isset($this->lobs[$lob]["Value"])) { if ($this->auto_commit) { - if (!@pg_Exec($this->connection, "BEGIN")) { - return ($this->SetError("Retrieve LOB", pg_ErrorMessage($this->connection))); + if (!@pg_exec($this->connection, "BEGIN")) { + return ($this->raiseError(DB_ERROR, NULL, NULL, "Retrieve LOB: " . pg_ErrorMessage($this->connection))); } $this->lobs[$lob]["InTransaction"] = 1; } - $this->lobs[$lob]["Value"] = $this->FetchResult($this->lobs[$lob]["Result"], $this->lobs[$lob]["Row"], $this->lobs[$lob]["Field"]); - if (!($this->lobs[$lob]["Handle"] = pg_loopen($this->connection, $this->lobs[$lob]["Value"], "r"))) { + $this->lobs[$lob]["Value"] = $this->fetch($this->lobs[$lob]["Result"], $this->lobs[$lob]["Row"], $this->lobs[$lob]["Field"]); + if (!($this->lobs[$lob]["Handle"] = @pg_loopen($this->connection, $this->lobs[$lob]["Value"], "r"))) { if (isset($this->lobs[$lob]["InTransaction"])) { @pg_Exec($this->connection, "END"); - UnSet($this->lobs[$lob]["InTransaction"]); + unSet($this->lobs[$lob]["InTransaction"]); } - Unset($this->lobs[$lob]["Value"]); - return ($this->SetError("Retrieve LOB", pg_ErrorMessage($this->connection))); + unset($this->lobs[$lob]["Value"]); + return ($this->raiseError(DB_ERROR, NULL, NULL, "Retrieve LOB: " . pg_ErrorMessage($this->connection))); } } return (DB_OK); @@ -463,8 +454,9 @@ */ function endOfResultLOB($lob) { - if (!$this->retrieveLOB($lob)) { - return (0); + $lobresult = $this->retrieveLOB($lob); + if (MDB::isError($lobresult)) { + return ($lobresult); } return (isset($this->lobs[$lob]["EndOfLOB"])); } @@ -486,13 +478,13 @@ */ function readResultLOB($lob, &$data, $length) { - if (!$this->RetrieveLOB($lob)) { - return (-1); + $lobresult = $this->retrieveLOB($lob); + if (MDB::isError($lobresult)) { + return ($lobresult); } $data = pg_loread($this->lobs[$lob]["Handle"], $length); if (GetType($data) != "string") { - $this->SetError("Read Result LOB", pg_ErrorMessage($this->connection)); - return (-1); + $this->raiseError(DB_ERROR, NULL, NULL, "Read Result LOB: " . pg_ErrorMessage($this->connection)); } if (($length = strlen($data)) == 0) { $this->lobs[$lob]["EndOfLOB"] = 1; @@ -869,31 +861,34 @@ if (($handle = pg_loopen($this->connection, $lo, "w"))) { while (!endOfLOB($lob)) { if (readLOB($lob, $data, $this->options['lob_buffer_length']) < 0) { - $this->SetError("Get LOB field value", lobError($lob)); + $this->raiseError(DB_ERROR, NULL, NULL, "Get LOB field value: " . lobError($lob)); $success = 0; break; } if (!pg_lowrite($handle, $data)) { - $this->SetError("Get LOB field value", pg_ErrorMessage($this->connection)); + $this->raiseError(DB_ERROR, NULL, NULL, "Get LOB field value: " . pg_ErrorMessage($this->connection)); $success = 0; break; } } pg_loclose($handle); - if ($success) + if ($success) { $value = strval($lo); + } } else { - $this->SetError("Get LOB field value", pg_ErrorMessage($this->connection)); + $this->raiseError(DB_ERROR, NULL, NULL, "Get LOB field value: " . pg_ErrorMessage($this->connection)); $success = 0; } - if (!$success) + if (!$success) { pg_lounlink($this->connection, $lo); + } } else { - $this->SetError("Get LOB field value", pg_ErrorMessage($this->connection)); + $this->raiseError(DB_ERROR, NULL, NULL, "Get LOB field value: " . pg_ErrorMessage($this->connection)); $success = 0; } - if ($this->auto_commit) + if ($this->auto_commit) { @pg_Exec($this->connection, "END"); + } return ($value); } @@ -912,9 +907,9 @@ * @return string text string that represents the given argument value in * a DBMS specific format. */ - function getClobValue($prepared_query, $parameter, $clob, &$value) + function getClobValue($prepared_query, $parameter, $clob) { - return ($this->getLobValue($prepared_query, $parameter, $clob, $value)); + return ($this->getLobValue($prepared_query, $parameter, $clob)); } // }}} @@ -948,9 +943,9 @@ * @return string text string that represents the given argument value in * a DBMS specific format. */ - function getBlobValue($prepared_query, $parameter, $blob, &$value) + function getBlobValue($prepared_query, $parameter, $blob) { - return ($this->getLobValue($prepared_query, $parameter, $blob, $value)); + return ($this->getLobValue($prepared_query, $parameter, $blob)); } // }}}

« previous php.pear.cvs (#5174) next »