cvs: php4 /pear/DB STATUS mysql.php pgsql.php /pear/DB/tests fetchmodes.inc /pear/DB/tests/mysql 002.phpt /pear/DB/tests/pgsql 001.phpt 002.phpt
003.phpt 004.phpt 005.phpt 006.phpt 007.phpt 008.phpt mktable.inc skipif.inc
| From: | Stig Bakken | Date: | Fri, 08 Dec 2000 03:22:16 +0000 |
| Subject: | cvs: php4 /pear/DB STATUS mysql.php pgsql.php /pear/DB/tests fetchmodes.inc /pear/DB/tests/mysql 002.phpt /pear/DB/tests/pgsql 001.phpt 002.phpt 003.phpt 004.phpt 005.phpt 006.phpt 007.phpt 008.phpt mktable.inc skipif.inc |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-3023@lists.php.net to get a copy of this message | ||
ssb Thu Dec 7 19:22:16 2000 EDT
Added files:
/php4/pear/DB/tests/pgsql 001.phpt 002.phpt 003.phpt 004.phpt
005.phpt 006.phpt 007.phpt 008.phpt
mktable.inc skipif.inc
Modified files:
/php4/pear/DB STATUS mysql.php pgsql.php
/php4/pear/DB/tests fetchmodes.inc
/php4/pear/DB/tests/mysql 002.phpt
Log:
* ported the mysql tests to pgsql (the nextId test is skipped for now)
* giving pgsql auto-commit a shot
* fixed error reporting some places in pgsql
* added horrible hack to avoid getting notices on stderr if
DB_pgsql::commit is called at the wrong time
Index: php4/pear/DB/STATUS diff -u php4/pear/DB/STATUS:1.7 php4/pear/DB/STATUS:1.8 --- php4/pear/DB/STATUS:1.7 Thu Dec 7 18:39:29 2000 +++ php4/pear/DB/STATUS Thu Dec 7 19:22:15 2000 @@ -20,6 +20,6 @@ sequences - - - E - - - - affectedRows - - - T x - x - fetch modes x x x T x - x x -transactions x n n n x - n n -auto-commit x n n n x - n n +transactions x n n n x - x n +auto-commit x n n n x - - n error mapping - - - x - x - - Index: php4/pear/DB/mysql.php diff -u php4/pear/DB/mysql.php:1.35 php4/pear/DB/mysql.php:1.36 --- php4/pear/DB/mysql.php:1.35 Thu Dec 7 18:30:43 2000 +++ php4/pear/DB/mysql.php Thu Dec 7 19:22:15 2000 @@ -365,7 +365,8 @@ } // [Sebastian]: Do we need to perform checks on $result here? // [Stig]: Nope, but it will be 0 for "DELETE FROM table". - // Can't really think of a way to get around that though. + // Could be emulated by doing a select count(*) before + // such queries are processed. return $result; } Index: php4/pear/DB/pgsql.php diff -u php4/pear/DB/pgsql.php:1.18 php4/pear/DB/pgsql.php:1.19 --- php4/pear/DB/pgsql.php:1.18 Thu Dec 7 18:50:29 2000 +++ php4/pear/DB/pgsql.php Thu Dec 7 19:22:15 2000 @@ -40,6 +40,7 @@ var $numrows; var $row; var $affected; + var $autocommit = 1; // }}} @@ -144,10 +145,13 @@ */ function &query($query) { $this->last_query = $query; - $result = pg_exec($this->connection, $query); + $result = @pg_exec($this->connection, $query); if (!$result) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } + if ($this->autocommit && DB::isManip($query)) { + $this->commit(); + } // Determine which queries that should return data, and which // should return an error code only. if (DB::isManip($query)) { @@ -157,8 +161,10 @@ $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; } } @@ -178,10 +184,13 @@ */ function simpleQuery($query) { $this->last_query = $query; - $result = pg_exec($this->connection, $query); + $result = @pg_exec($this->connection, $query); if (!$result) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } + if ($this->autocommit && DB::isManip($query)) { + $this->commit(); + } // Determine which queries that should return data, and which // should return an error code only. if (DB::isManip($query)) { @@ -190,8 +199,10 @@ } elseif (preg_match('/(SELECT|SHOW)/i', $query)) { $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; } } @@ -221,7 +232,7 @@ $row = pg_fetch_row($result, $this->row[$result]); } if (!$row) { - $err = pg_errormessage($this->connection); + $err = $this->raiseError(pg_errormessage($this->connection)); if (!$err) { return NULL; } @@ -308,7 +319,7 @@ function numCols($result) { $cols = pg_numfields($result); if (!$cols) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } return $cols; } @@ -326,7 +337,7 @@ function numRows($result) { $rows = pg_numrows($result); if (!$rows) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } return $rows; } @@ -341,9 +352,7 @@ * @return int native PostgreSQL error code */ function errorNative() { - /* return pg_errormessage($this->connection); */ - // the error codes are not supported in pgsql. - return $this->raiseError(); + return pg_errormessage($this->connection); } // }}} @@ -385,18 +394,23 @@ function execute($stmt, $data = false) { $realquery = $this->execute_emulate_query($stmt, $data); $this->last_query = $realquery; - $result = pg_exec($this->connection, $realquery); + $result = @pg_exec($this->connection, $realquery); if (!$result) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } + if ($this->autocommit && DB::isManip($query)) { + $this->commit(); + } 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; } } @@ -405,10 +419,11 @@ // {{{ autoCommit() /** - * Enable/disable automatic commits [not supported by PostgreSQL] + * Enable/disable automatic commits */ function autoCommit($onoff = false) { - return $this->raiseError(DB_ERROR_NOT_CAPABLE); + $this->autocommit = $onoff ? true : false; + return DB_OK; } // }}} @@ -418,9 +433,11 @@ * Commit transactions on the current connection */ function commit() { - $result = pg_exec($this->connection, "end;"); + // hack to shut up error messages from ext/pgsql or libpq.a + @fclose(@fopen("php://stderr", "w")); + $result = @pg_exec($this->connection, "end;"); if (!$result) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } return DB_OK; } @@ -432,9 +449,9 @@ * Roll back all uncommitted transactions on the current connection. */ function rollback() { - $result = pg_exec($this->connection, "abort;"); + $result = @pg_exec($this->connection, "abort;"); if (!$result) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } return DB_OK; } Index: php4/pear/DB/tests/fetchmodes.inc diff -u php4/pear/DB/tests/fetchmodes.inc:1.1 php4/pear/DB/tests/fetchmodes.inc:1.2 --- php4/pear/DB/tests/fetchmodes.inc:1.1 Mon Sep 11 17:27:50 2000 +++ php4/pear/DB/tests/fetchmodes.inc Thu Dec 7 19:22:15 2000 @@ -2,34 +2,34 @@ $dbh->setErrorHandling(PEAR_ERROR_DIE); -// testing default default +print "testing default default\n"; $sth = $dbh->query("SELECT * FROM phptest"); $row = $sth->fetchRow(); //var_dump($row); print implode(" ", array_keys($row))."\n"; -// testing ordered default +print "testing ordered default\n"; $dbh->setFetchMode(DB_FETCHMODE_ORDERED); $sth = $dbh->query("SELECT * FROM phptest"); $row = $sth->fetchRow(); //var_dump($row); print implode(" ", array_keys($row))."\n"; -// testing assoc default +print "testing assoc default\n"; $dbh->setFetchMode(DB_FETCHMODE_ASSOC); $sth = $dbh->query("SELECT * FROM phptest"); $row = $sth->fetchRow(); //var_dump($row); print implode(" ", array_keys($row))."\n"; -// testing ordered default with assoc specified +print "testing ordered default with assoc specified\n"; $dbh->setFetchMode(DB_FETCHMODE_ORDERED); $sth = $dbh->query("SELECT * FROM phptest"); $row = $sth->fetchRow(DB_FETCHMODE_ASSOC); //var_dump($row); print implode(" ", array_keys($row))."\n"; -// testing assoc default with ordered specified +print "testing assoc default with ordered specified\n"; $dbh->setFetchMode(DB_FETCHMODE_ASSOC); $sth = $dbh->query("SELECT * FROM phptest"); $row = $sth->fetchRow(DB_FETCHMODE_ORDERED); Index: php4/pear/DB/tests/mysql/002.phpt diff -u php4/pear/DB/tests/mysql/002.phpt:1.2 php4/pear/DB/tests/mysql/002.phpt:1.3 --- php4/pear/DB/tests/mysql/002.phpt:1.2 Wed Dec 6 12:18:41 2000 +++ php4/pear/DB/tests/mysql/002.phpt Thu Dec 7 19:22:15 2000 @@ -9,8 +9,13 @@ include("../fetchmodes.inc"); ?> --EXPECT-- +testing default default 0 1 2 3 +testing ordered default 0 1 2 3 +testing assoc default a b c d +testing ordered default with assoc specified a b c d +testing assoc default with ordered specified 0 1 2 3 Index: php4/pear/DB/tests/pgsql/001.phpt +++ php4/pear/DB/tests/pgsql/001.phpt --TEST-- DB_pgsql::connect test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; $dbh = DB::connect("pgsql://localhost/test"); if (is_object($dbh)) { print "\$dbh is an object\n"; } if (is_resource($dbh->connection)) { print "\$dbh is connected\n"; } ?> --EXPECT-- $dbh is an object $dbh is connected Index: php4/pear/DB/tests/pgsql/002.phpt +++ php4/pear/DB/tests/pgsql/002.phpt --TEST-- DB_pgsql fetch modes test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; include("mktable.inc"); include("../fetchmodes.inc"); ?> --EXPECT-- testing default default 0 1 2 3 testing ordered default 0 1 2 3 testing assoc default a b c d testing ordered default with assoc specified a b c d testing assoc default with ordered specified 0 1 2 3 Index: php4/pear/DB/tests/pgsql/003.phpt +++ php4/pear/DB/tests/pgsql/003.phpt --TEST-- DB_pgsql::simpleQuery test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; include("mktable.inc"); include("../simplequery.inc"); ?> --EXPECT-- resource Index: php4/pear/DB/tests/pgsql/004.phpt +++ php4/pear/DB/tests/pgsql/004.phpt --TEST-- DB_pgsql::numCols test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; include("mktable.inc"); include("../numcols.inc"); ?> --EXPECT-- 1 2 3 4 Index: php4/pear/DB/tests/pgsql/005.phpt +++ php4/pear/DB/tests/pgsql/005.phpt --TEST-- DB_pgsql::nextId test --SKIPIF-- <?php die("skip\n"); /* include("skipif.inc"); */ ?> --FILE-- <?php require_once "DB.php"; $dbh = DB::connect("pgsql://localhost/test"); $dbh->query("DROP TABLE db_seq_test"); $e = $dbh->nextId("test", false); if (DB::isError($e)) { print $e->getMessage() . "\n"; } $a = $dbh->nextId("test"); $b = $dbh->nextId("test"); print "first=$a second=$b\n"; $dbh->query("DROP TABLE db_seq_test"); ?> --EXPECT-- DB Error: no such table first=1 second=2 Index: php4/pear/DB/tests/pgsql/006.phpt +++ php4/pear/DB/tests/pgsql/006.phpt --TEST-- DB_pgsql::prepare/execute test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; include("mktable.inc"); include("../prepexe.inc"); ?> --EXPECT-- sth1,sth2,sth3 created sth1 executed sth2 executed sth3 executed results: 72 - - - 72 - bing - - 72 - gazonk - opaque placeholder test - Index: php4/pear/DB/tests/pgsql/007.phpt +++ php4/pear/DB/tests/pgsql/007.phpt --TEST-- DB_pgsql::errorNative test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; include("mktable.inc"); $dbh->query("syntax error please"); print $dbh->errorNative() . "\n"; ?> --EXPECT-- ERROR: parser: parse error at or near "syntax" Index: php4/pear/DB/tests/pgsql/008.phpt +++ php4/pear/DB/tests/pgsql/008.phpt --TEST-- DB_pgsql::affectedRows test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; include("mktable.inc"); $dbh->query("INSERT INTO phptest (a,b) VALUES(1, 'test')"); $dbh->query("INSERT INTO phptest (a,b) VALUES(2, 'test')"); printf("%d after insert\n", $dbh->affectedRows()); $dbh->query("SELECT * FROM phptest"); printf("%d after select\n", $dbh->affectedRows()); $dbh->query("DELETE FROM phptest WHERE b = 'test'"); printf("%d after delete\n", $dbh->affectedRows()); $dbh->query("INSERT INTO phptest (a,b) VALUES(1, 'test')"); $dbh->query("INSERT INTO phptest (a,b) VALUES(2, 'test')"); $dbh->query("DELETE FROM phptest"); printf("%d after delete all\n", $dbh->affectedRows()); ?> --EXPECT-- 1 after insert 0 after select 2 after delete 3 after delete all Index: php4/pear/DB/tests/pgsql/mktable.inc +++ php4/pear/DB/tests/pgsql/mktable.inc <?php $dbh = DB::connect("pgsql://localhost/test"); $dbh->setErrorHandling(PEAR_ERROR_RETURN); $dbh->query("DROP TABLE phptest"); $dbh->setErrorHandling(PEAR_ERROR_TRIGGER); $dbh->query("CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d DATE)"); $dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test', '1999-11-21')"); $dbh->setErrorHandling(PEAR_ERROR_RETURN); ?> Index: php4/pear/DB/tests/pgsql/skipif.inc +++ php4/pear/DB/tests/pgsql/skipif.inc <?php // This script prints "skip" unless: // * the pgsql extension is built-in or loadable, AND // * there is a database called "test" accessible // with no username/password, AND // * we have create/drop privileges on the entire "test" // database if (!extension_loaded("pgsql")) { $dlext = (substr(PHP_OS, 0, 3) == "WIN") ? ".dll" : ".so"; @dl("pgsql$dlext"); } if (!extension_loaded("pgsql")) { die("skip\n"); } $conn = @pg_connect("host=localhost dbname=test"); if (!is_resource($conn)) { die("skip\n"); } ?>
Index: php4/pear/DB/STATUS diff -u php4/pear/DB/STATUS:1.7 php4/pear/DB/STATUS:1.8 --- php4/pear/DB/STATUS:1.7 Thu Dec 7 18:39:29 2000 +++ php4/pear/DB/STATUS Thu Dec 7 19:22:15 2000 @@ -20,6 +20,6 @@ sequences - - - E - - - - affectedRows - - - T x - x - fetch modes x x x T x - x x -transactions x n n n x - n n -auto-commit x n n n x - n n +transactions x n n n x - x n +auto-commit x n n n x - - n error mapping - - - x - x - - Index: php4/pear/DB/mysql.php diff -u php4/pear/DB/mysql.php:1.35 php4/pear/DB/mysql.php:1.36 --- php4/pear/DB/mysql.php:1.35 Thu Dec 7 18:30:43 2000 +++ php4/pear/DB/mysql.php Thu Dec 7 19:22:15 2000 @@ -365,7 +365,8 @@ } // [Sebastian]: Do we need to perform checks on $result here? // [Stig]: Nope, but it will be 0 for "DELETE FROM table". - // Can't really think of a way to get around that though. + // Could be emulated by doing a select count(*) before + // such queries are processed. return $result; } Index: php4/pear/DB/pgsql.php diff -u php4/pear/DB/pgsql.php:1.18 php4/pear/DB/pgsql.php:1.19 --- php4/pear/DB/pgsql.php:1.18 Thu Dec 7 18:50:29 2000 +++ php4/pear/DB/pgsql.php Thu Dec 7 19:22:15 2000 @@ -40,6 +40,7 @@ var $numrows; var $row; var $affected; + var $autocommit = 1; // }}} @@ -144,10 +145,13 @@ */ function &query($query) { $this->last_query = $query; - $result = pg_exec($this->connection, $query); + $result = @pg_exec($this->connection, $query); if (!$result) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } + if ($this->autocommit && DB::isManip($query)) { + $this->commit(); + } // Determine which queries that should return data, and which // should return an error code only. if (DB::isManip($query)) { @@ -157,8 +161,10 @@ $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; } } @@ -178,10 +184,13 @@ */ function simpleQuery($query) { $this->last_query = $query; - $result = pg_exec($this->connection, $query); + $result = @pg_exec($this->connection, $query); if (!$result) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } + if ($this->autocommit && DB::isManip($query)) { + $this->commit(); + } // Determine which queries that should return data, and which // should return an error code only. if (DB::isManip($query)) { @@ -190,8 +199,10 @@ } elseif (preg_match('/(SELECT|SHOW)/i', $query)) { $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; } } @@ -221,7 +232,7 @@ $row = pg_fetch_row($result, $this->row[$result]); } if (!$row) { - $err = pg_errormessage($this->connection); + $err = $this->raiseError(pg_errormessage($this->connection)); if (!$err) { return NULL; } @@ -308,7 +319,7 @@ function numCols($result) { $cols = pg_numfields($result); if (!$cols) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } return $cols; } @@ -326,7 +337,7 @@ function numRows($result) { $rows = pg_numrows($result); if (!$rows) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } return $rows; } @@ -341,9 +352,7 @@ * @return int native PostgreSQL error code */ function errorNative() { - /* return pg_errormessage($this->connection); */ - // the error codes are not supported in pgsql. - return $this->raiseError(); + return pg_errormessage($this->connection); } // }}} @@ -385,18 +394,23 @@ function execute($stmt, $data = false) { $realquery = $this->execute_emulate_query($stmt, $data); $this->last_query = $realquery; - $result = pg_exec($this->connection, $realquery); + $result = @pg_exec($this->connection, $realquery); if (!$result) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } + if ($this->autocommit && DB::isManip($query)) { + $this->commit(); + } 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; } } @@ -405,10 +419,11 @@ // {{{ autoCommit() /** - * Enable/disable automatic commits [not supported by PostgreSQL] + * Enable/disable automatic commits */ function autoCommit($onoff = false) { - return $this->raiseError(DB_ERROR_NOT_CAPABLE); + $this->autocommit = $onoff ? true : false; + return DB_OK; } // }}} @@ -418,9 +433,11 @@ * Commit transactions on the current connection */ function commit() { - $result = pg_exec($this->connection, "end;"); + // hack to shut up error messages from ext/pgsql or libpq.a + @fclose(@fopen("php://stderr", "w")); + $result = @pg_exec($this->connection, "end;"); if (!$result) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } return DB_OK; } @@ -432,9 +449,9 @@ * Roll back all uncommitted transactions on the current connection. */ function rollback() { - $result = pg_exec($this->connection, "abort;"); + $result = @pg_exec($this->connection, "abort;"); if (!$result) { - return pg_errormessage($this->connection); + return $this->raiseError(pg_errormessage($this->connection)); } return DB_OK; } Index: php4/pear/DB/tests/fetchmodes.inc diff -u php4/pear/DB/tests/fetchmodes.inc:1.1 php4/pear/DB/tests/fetchmodes.inc:1.2 --- php4/pear/DB/tests/fetchmodes.inc:1.1 Mon Sep 11 17:27:50 2000 +++ php4/pear/DB/tests/fetchmodes.inc Thu Dec 7 19:22:15 2000 @@ -2,34 +2,34 @@ $dbh->setErrorHandling(PEAR_ERROR_DIE); -// testing default default +print "testing default default\n"; $sth = $dbh->query("SELECT * FROM phptest"); $row = $sth->fetchRow(); //var_dump($row); print implode(" ", array_keys($row))."\n"; -// testing ordered default +print "testing ordered default\n"; $dbh->setFetchMode(DB_FETCHMODE_ORDERED); $sth = $dbh->query("SELECT * FROM phptest"); $row = $sth->fetchRow(); //var_dump($row); print implode(" ", array_keys($row))."\n"; -// testing assoc default +print "testing assoc default\n"; $dbh->setFetchMode(DB_FETCHMODE_ASSOC); $sth = $dbh->query("SELECT * FROM phptest"); $row = $sth->fetchRow(); //var_dump($row); print implode(" ", array_keys($row))."\n"; -// testing ordered default with assoc specified +print "testing ordered default with assoc specified\n"; $dbh->setFetchMode(DB_FETCHMODE_ORDERED); $sth = $dbh->query("SELECT * FROM phptest"); $row = $sth->fetchRow(DB_FETCHMODE_ASSOC); //var_dump($row); print implode(" ", array_keys($row))."\n"; -// testing assoc default with ordered specified +print "testing assoc default with ordered specified\n"; $dbh->setFetchMode(DB_FETCHMODE_ASSOC); $sth = $dbh->query("SELECT * FROM phptest"); $row = $sth->fetchRow(DB_FETCHMODE_ORDERED); Index: php4/pear/DB/tests/mysql/002.phpt diff -u php4/pear/DB/tests/mysql/002.phpt:1.2 php4/pear/DB/tests/mysql/002.phpt:1.3 --- php4/pear/DB/tests/mysql/002.phpt:1.2 Wed Dec 6 12:18:41 2000 +++ php4/pear/DB/tests/mysql/002.phpt Thu Dec 7 19:22:15 2000 @@ -9,8 +9,13 @@ include("../fetchmodes.inc"); ?> --EXPECT-- +testing default default 0 1 2 3 +testing ordered default 0 1 2 3 +testing assoc default a b c d +testing ordered default with assoc specified a b c d +testing assoc default with ordered specified 0 1 2 3 Index: php4/pear/DB/tests/pgsql/001.phpt +++ php4/pear/DB/tests/pgsql/001.phpt --TEST-- DB_pgsql::connect test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; $dbh = DB::connect("pgsql://localhost/test"); if (is_object($dbh)) { print "\$dbh is an object\n"; } if (is_resource($dbh->connection)) { print "\$dbh is connected\n"; } ?> --EXPECT-- $dbh is an object $dbh is connected Index: php4/pear/DB/tests/pgsql/002.phpt +++ php4/pear/DB/tests/pgsql/002.phpt --TEST-- DB_pgsql fetch modes test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; include("mktable.inc"); include("../fetchmodes.inc"); ?> --EXPECT-- testing default default 0 1 2 3 testing ordered default 0 1 2 3 testing assoc default a b c d testing ordered default with assoc specified a b c d testing assoc default with ordered specified 0 1 2 3 Index: php4/pear/DB/tests/pgsql/003.phpt +++ php4/pear/DB/tests/pgsql/003.phpt --TEST-- DB_pgsql::simpleQuery test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; include("mktable.inc"); include("../simplequery.inc"); ?> --EXPECT-- resource Index: php4/pear/DB/tests/pgsql/004.phpt +++ php4/pear/DB/tests/pgsql/004.phpt --TEST-- DB_pgsql::numCols test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; include("mktable.inc"); include("../numcols.inc"); ?> --EXPECT-- 1 2 3 4 Index: php4/pear/DB/tests/pgsql/005.phpt +++ php4/pear/DB/tests/pgsql/005.phpt --TEST-- DB_pgsql::nextId test --SKIPIF-- <?php die("skip\n"); /* include("skipif.inc"); */ ?> --FILE-- <?php require_once "DB.php"; $dbh = DB::connect("pgsql://localhost/test"); $dbh->query("DROP TABLE db_seq_test"); $e = $dbh->nextId("test", false); if (DB::isError($e)) { print $e->getMessage() . "\n"; } $a = $dbh->nextId("test"); $b = $dbh->nextId("test"); print "first=$a second=$b\n"; $dbh->query("DROP TABLE db_seq_test"); ?> --EXPECT-- DB Error: no such table first=1 second=2 Index: php4/pear/DB/tests/pgsql/006.phpt +++ php4/pear/DB/tests/pgsql/006.phpt --TEST-- DB_pgsql::prepare/execute test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; include("mktable.inc"); include("../prepexe.inc"); ?> --EXPECT-- sth1,sth2,sth3 created sth1 executed sth2 executed sth3 executed results: 72 - - - 72 - bing - - 72 - gazonk - opaque placeholder test - Index: php4/pear/DB/tests/pgsql/007.phpt +++ php4/pear/DB/tests/pgsql/007.phpt --TEST-- DB_pgsql::errorNative test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; include("mktable.inc"); $dbh->query("syntax error please"); print $dbh->errorNative() . "\n"; ?> --EXPECT-- ERROR: parser: parse error at or near "syntax" Index: php4/pear/DB/tests/pgsql/008.phpt +++ php4/pear/DB/tests/pgsql/008.phpt --TEST-- DB_pgsql::affectedRows test --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php require_once "DB.php"; include("mktable.inc"); $dbh->query("INSERT INTO phptest (a,b) VALUES(1, 'test')"); $dbh->query("INSERT INTO phptest (a,b) VALUES(2, 'test')"); printf("%d after insert\n", $dbh->affectedRows()); $dbh->query("SELECT * FROM phptest"); printf("%d after select\n", $dbh->affectedRows()); $dbh->query("DELETE FROM phptest WHERE b = 'test'"); printf("%d after delete\n", $dbh->affectedRows()); $dbh->query("INSERT INTO phptest (a,b) VALUES(1, 'test')"); $dbh->query("INSERT INTO phptest (a,b) VALUES(2, 'test')"); $dbh->query("DELETE FROM phptest"); printf("%d after delete all\n", $dbh->affectedRows()); ?> --EXPECT-- 1 after insert 0 after select 2 after delete 3 after delete all Index: php4/pear/DB/tests/pgsql/mktable.inc +++ php4/pear/DB/tests/pgsql/mktable.inc <?php $dbh = DB::connect("pgsql://localhost/test"); $dbh->setErrorHandling(PEAR_ERROR_RETURN); $dbh->query("DROP TABLE phptest"); $dbh->setErrorHandling(PEAR_ERROR_TRIGGER); $dbh->query("CREATE TABLE phptest (a INTEGER, b VARCHAR(40), c TEXT, d DATE)"); $dbh->query("INSERT INTO phptest VALUES(42, 'bing', 'This is a test', '1999-11-21')"); $dbh->setErrorHandling(PEAR_ERROR_RETURN); ?> Index: php4/pear/DB/tests/pgsql/skipif.inc +++ php4/pear/DB/tests/pgsql/skipif.inc <?php // This script prints "skip" unless: // * the pgsql extension is built-in or loadable, AND // * there is a database called "test" accessible // with no username/password, AND // * we have create/drop privileges on the entire "test" // database if (!extension_loaded("pgsql")) { $dlext = (substr(PHP_OS, 0, 3) == "WIN") ? ".dll" : ".so"; @dl("pgsql$dlext"); } if (!extension_loaded("pgsql")) { die("skip\n"); } $conn = @pg_connect("host=localhost dbname=test"); if (!is_resource($conn)) { die("skip\n"); } ?>