cvs: php4 /pear/DB pgsql.php

From: Date: Sun, 10 Dec 2000 00:51:26 +0000
Subject: cvs: php4 /pear/DB pgsql.php
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-3046@lists.php.net to get a copy of this message
ssb Sat Dec 9 16:51:26 2000 EDT Modified files: /php4/pear/DB pgsql.php Log: * removed some logic duplication, "SELECT" (not "SELECT INTO" is now the only command that will return a result object. # Postgres's default behaviour is to print "notices" (output from # commands such as "EXPLAIN") to standard error, which is extremely # useless for PHP. ext/pgsql needs to be fixed, but my head started # aching when I looked at it (the pgsql resource needs to use a # different struct) Index: php4/pear/DB/pgsql.php diff -u php4/pear/DB/pgsql.php:1.19 php4/pear/DB/pgsql.php:1.20 --- php4/pear/DB/pgsql.php:1.19 Thu Dec 7 19:22:15 2000 +++ php4/pear/DB/pgsql.php Sat Dec 9 16:51:26 2000 @@ -144,37 +144,20 @@ * on failure */ function &query($query) { - $this->last_query = $query; - $result = @pg_exec($this->connection, $query); - if (!$result) { - return $this->raiseError(pg_errormessage($this->connection)); - } - if ($this->autocommit && DB::isManip($query)) { - $this->commit(); + $result = $this->simpleQuery($query); + if (DB::isError($result) || $result === DB_OK) { + return $result; + } else { + return new DB_result($this, $result); } - // Determine which queries that should return data, and which - // should return an error code only. - if (DB::isManip($query)) { - $this->affected = pg_cmdtuples($result); - return DB_OK; - } elseif (preg_match('/^\s*(SELECT|SHOW)\s+/i', $query)) { - $resultObj = new DB_result($this, $result); - $this->row[$result] = 0; // reset the row counter. - $this->numrows[$result] = pg_numrows($result); - $this->affected = 0; - return $resultObj; - } else { - $this->affected = 0; - return DB_OK; - } } // }}} // {{{ simpleQuery() /** - * Send a query to PostgreSQL and return the results as a PostgreSQL resource - * identifier. + * Send a query to PostgreSQL and return the results as a + * PostgreSQL resource identifier. * * @param $query the SQL query * @@ -196,7 +179,15 @@ if (DB::isManip($query)) { $this->affected = pg_cmdtuples($result); return DB_OK; - } elseif (preg_match('/(SELECT|SHOW)/i', $query)) { + } elseif (preg_match('/^\s*(SELECT)\s/i', $query) && + !preg_match('/^\s*(SELECT\s+INTO)\s/i', $query)) { + /* PostgreSQL commands: + ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY, + CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH, + GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET, + REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW, + UNLISTEN, UPDATE, VACUUM + */ $this->row[$result] = 0; // reset the row counter. $this->numrows[$result] = pg_numrows($result); $this->affected = 0; @@ -394,25 +385,12 @@ function execute($stmt, $data = false) { $realquery = $this->execute_emulate_query($stmt, $data); $this->last_query = $realquery; - $result = @pg_exec($this->connection, $realquery); - if (!$result) { - return $this->raiseError(pg_errormessage($this->connection)); - } - if ($this->autocommit && DB::isManip($query)) { - $this->commit(); + $result = $this->simpleQuery($realquery); + if (DB::isError($result) || $result === DB_OK) { + return $result; + } else { + return new DB_result($this, $result); } - if (DB::isManip($query)) { - $this->affected = pg_cmdtuples($result); - return DB_OK; - } elseif (preg_match('/(SELECT|SHOW)/i', $realquery)) { - $this->row[$result] = 0; // reset the row counter. - $this->numrows[$result] = pg_numrows($result); - $this->affected = 0; - return $result; - } else { - $this->affected = 0; - return DB_OK; - } } // }}}

« previous php.cvs (#3046) next »