cvs: php4 /pear/DB MAINTAINERS STATUS common.php mysql.php pgsql.php /pear/DB/tests fetchmodes.inc numrows.inc sequences.inc /pear/DB/tests/mysql
001.phpt 002.phpt 005.phpt 009.phpt connect.inc mktable.inc /pear/DB/tests/pgsql .cvsignore 001.phpt 002.phpt 005.phpt 009.phpt connect.inc
mktable.inc

From: Date: Wed, 13 Dec 2000 14:41:06 +0000
Subject: cvs: php4 /pear/DB MAINTAINERS STATUS common.php mysql.php pgsql.php /pear/DB/tests fetchmodes.inc numrows.inc sequences.inc /pear/DB/tests/mysql
001.phpt 002.phpt 005.phpt 009.phpt connect.inc mktable.inc /pear/DB/tests/pgsql .cvsignore 001.phpt 002.phpt 005.phpt 009.phpt connect.inc
mktable.inc
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-3124@lists.php.net to get a copy of this message
ssb Wed Dec 13 06:41:06 2000 EDT Added files: /php4/pear/DB/tests sequences.inc /php4/pear/DB/tests/mysql connect.inc /php4/pear/DB/tests/pgsql .cvsignore connect.inc Modified files: /php4/pear/DB MAINTAINERS STATUS common.php mysql.php pgsql.php /php4/pear/DB/tests fetchmodes.inc numrows.inc /php4/pear/DB/tests/mysql 001.phpt 002.phpt 005.phpt 009.phpt mktable.inc /php4/pear/DB/tests/pgsql 001.phpt 002.phpt 005.phpt 009.phpt mktable.inc Log: * added {mysql,pgsql}RaiseError() methods to DB_{mysql,pgsql} for more consistent behaviour * fixed DB_{pgsql,mysql}::numRows bug (returned an error on 0 rows), added test for it * added sequence support to DB_pgsql, and dropSequence() to pgsql/mysql with some fixes by Alexey Borzov * fixed a bug in DB_pgsql::fetchInto * improved fetchmode tests

Index: php4/pear/DB/MAINTAINERS diff -u php4/pear/DB/MAINTAINERS:1.2 php4/pear/DB/MAINTAINERS:1.3 --- php4/pear/DB/MAINTAINERS:1.2 Thu Dec 7 07:38:09 2000 +++ php4/pear/DB/MAINTAINERS Wed Dec 13 06:41:04 2000 @@ -7,4 +7,5 @@ oci8 : odbc : pgsql : Rui Hirokawa <louis@cityfujisawa.ne.jp> + Stig Bakken <ssb@fast.no> sybase : Index: php4/pear/DB/STATUS diff -u php4/pear/DB/STATUS:1.11 php4/pear/DB/STATUS:1.12 --- php4/pear/DB/STATUS:1.11 Sat Dec 9 18:31:26 2000 +++ php4/pear/DB/STATUS Wed Dec 13 06:41:04 2000 @@ -16,8 +16,8 @@ numCols x x x T x x T x numRows n x x T n n T n errorNative n n n T x n T n -prepare/execute x e e E e e E e -sequences n n n E n n n n +prepare/execute x e e E x e E e +sequences n n n E n n T n affectedRows n n n T x n T n fetch modes x x x T x x T x transactions x n n n x x x n Index: php4/pear/DB/common.php diff -u php4/pear/DB/common.php:1.33 php4/pear/DB/common.php:1.34 --- php4/pear/DB/common.php:1.33 Sat Dec 9 19:18:56 2000 +++ php4/pear/DB/common.php Wed Dec 13 06:41:04 2000 @@ -128,10 +128,9 @@ } //php_error(E_WARNING, get_class($this)."::errorCode: no mapping for $nativecode"); - // Fall back to DB_ERROR if there was no mapping. Ideally, - // this should never happen. + // Fall back to DB_ERROR if there was no mapping. - return $this->raiseError(DB_ERROR, false, false, false, $nativecode); + return DB_ERROR; } // }}} @@ -850,6 +849,14 @@ // {{{ createSequence() function createSequence($seq_name) + { + return $this->raiseError(DB_ERROR_NOT_CAPABLE); + } + + // }}} + // {{{ dropSequence() + + function dropSequence($seq_name) { return $this->raiseError(DB_ERROR_NOT_CAPABLE); } Index: php4/pear/DB/mysql.php diff -u php4/pear/DB/mysql.php:1.40 php4/pear/DB/mysql.php:1.41 --- php4/pear/DB/mysql.php:1.40 Sat Dec 9 19:18:56 2000 +++ php4/pear/DB/mysql.php Wed Dec 13 06:41:04 2000 @@ -167,7 +167,7 @@ $query = $this->modifyQuery($query); $result = mysql_query($query, $this->connection); if (!$result) { - return $this->raiseError($this->errorCode(mysql_errno($this->connection))); + return $this->mysqlRaiseError(); } // Determine which queries that should return data, and which // should return an error code only. @@ -207,7 +207,7 @@ return NULL; } - return $this->raiseError($this->errorCode($errno)); + return $this->mysqlRaiseError($errno); } return $row; @@ -246,7 +246,7 @@ return NULL; } - return $this->raiseError($this->errorCode($errno)); + return $this->mysqlRaiseError($errno); } return DB_OK; @@ -297,7 +297,7 @@ $cols = mysql_num_fields($result); if (!$cols) { - return $this->raiseError($this->errorCode(mysql_errno($this->connection))); + return $this->mysqlRaiseError(); } return $cols; @@ -317,12 +317,9 @@ */ function numRows($result) { - $rows = mysql_num_rows($result); - - if (!$rows) { - return - $this->raiseError($this->errorCode( - mysql_errno($this->connection))); + $rows = @mysql_num_rows($result); + if ($rows === null) { + return $this->mysqlRaiseError(); } return $rows; @@ -344,10 +341,6 @@ } else { $result = 0; } - // [Sebastian]: Do we need to perform checks on $result here? - // [Stig]: Nope, but it will be 0 for "DELETE FROM table". - // Could be emulated by doing a select count(*) before - // such queries are processed. return $result; } @@ -384,38 +377,50 @@ * * @return a sequence integer, or a DB error */ - function nextId($seq_name, $ondemand = true) { - $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name); - $repeat = 0; - do { - $result = $this->query("INSERT INTO db_seq_${sqn} VALUES(NULL)"); - if ($ondemand && DB::isError($result) && - $result->getCode() == DB_ERROR_NOSUCHTABLE) { - $repeat = 1; - $result = $this->createSequence($seq_name); - if (DB::isError($result)) { - return $result; - } - } else { - $repeat = 0; - } - } while ($repeat); - if (DB::isError($result)) { - return $result; - } + function nextId($seq_name, $ondemand = true) + { + $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name); + $repeat = 0; + do { + $result = $this->query("INSERT INTO db_seq_${sqn} VALUES(NULL)"); + if ($ondemand && DB::isError($result) && + $result->getCode() == DB_ERROR_NOSUCHTABLE) { + $repeat = 1; + $result = $this->createSequence($seq_name); + if (DB::isError($result)) { + return $result; + } + } else { + $repeat = 0; + } + } while ($repeat); + if (DB::isError($result)) { + return $result; + } return mysql_insert_id($this->connection); } // }}} // {{{ createSequence() + + function createSequence($seq_name) + { + $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name); + return $this->query("CREATE TABLE db_seq_${sqn} ". + "(id INTEGER AUTO_INCREMENT, PRIMARY KEY(id))"); + } + + // }}} + // {{{ dropSequence() - function createSequence($seq_name) { - $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name); - return $this->query("CREATE TABLE db_seq_${sqn} ". - "(id INTEGER AUTO_INCREMENT, PRIMARY KEY(id))"); + function dropSequence($seq_name) + { + $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name); + return $this->query("DROP TABLE db_seq_${sqn}"); } // }}} + // {{{ modifyQuery() function modifyQuery($query) { @@ -429,6 +434,19 @@ } return $query; } + + // }}} + // {{{ mysqlRaiseError() + + function mysqlRaiseError($errno = null) + { + if ($errno === null) { + return $this->raiseError($this->errorCode(mysql_errno($this->connection))); + } + return $this->raiseError($this->errorCode($errno)); + } + + // }}} // TODO/wishlist: // simpleFetch Index: php4/pear/DB/pgsql.php diff -u php4/pear/DB/pgsql.php:1.23 php4/pear/DB/pgsql.php:1.24 --- php4/pear/DB/pgsql.php:1.23 Sat Dec 9 19:18:56 2000 +++ php4/pear/DB/pgsql.php Wed Dec 13 06:41:04 2000 @@ -103,9 +103,9 @@ if ($pw) { $connect_params .= " password=$pw"; } - $conn = $connect_function($connect_params); + $conn = @$connect_function($connect_params); } elseif ($dbhost && $user && $pw && $dbname) { - $conn = $connect_function( + $conn = @$connect_function( "host=$dbhost port=$port dbname=$dbname user=$user password=$pw"); } elseif ($dbhost && $dbname && $options && $tty) { $conn = $connect_function($dbhost, $port, $options, $tty, $dbname); @@ -131,7 +131,7 @@ */ function disconnect() { - return pg_close($this->connection); // XXX ERRORMSG + return @pg_close($this->connection); // XXX ERRORMSG } // }}} @@ -153,7 +153,7 @@ $query = $this->modifyQuery($query); $result = @pg_exec($this->connection, $query); if (!$result) { - return $this->raiseError(pg_errormessage($this->connection)); + return $this->pgsqlRaiseError(); } if ($this->autocommit && DB::isManip($query)) { $this->commit(); @@ -161,7 +161,7 @@ // Determine which queries that should return data, and which // should return an error code only. if (DB::isManip($query)) { - $this->affected = pg_cmdtuples($result); + $this->affected = @pg_cmdtuples($result); return DB_OK; } elseif (preg_match('/^\s*(SELECT)\s/i', $query) && !preg_match('/^\s*(SELECT\s+INTO)\s/i', $query)) { @@ -173,7 +173,7 @@ UNLISTEN, UPDATE, VACUUM */ $this->row[$result] = 0; // reset the row counter. - $this->numrows[$result] = pg_numrows($result); + $this->numrows[$result] = @pg_numrows($result); $this->affected = 0; return $result; } else { @@ -203,12 +203,12 @@ return NULL; } if ($fetchmode & DB_FETCHMODE_ASSOC) { - $row = pg_fetch_array($result, $this->row[$result], PGSQL_ASSOC); + $row = @pg_fetch_array($result, $this->row[$result], PGSQL_ASSOC); } else { - $row = pg_fetch_row($result, $this->row[$result]); + $row = @pg_fetch_row($result, $this->row[$result]); } if (!$row) { - $err = $this->raiseError(pg_errormessage($this->connection)); + $err = $this->pgsqlRaiseError(); if (!$err) { return NULL; } @@ -239,9 +239,9 @@ return NULL; } if ($fetchmode & DB_FETCHMODE_ASSOC) { - $arr = pg_fetch_array($result, $this->row[$result]); + $arr = @pg_fetch_array($result, $this->row[$result], PGSQL_ASSOC); } else { - $arr = pg_fetch_row($result, $this->row[$result]); + $arr = @pg_fetch_row($result, $this->row[$result]); } if (!$arr) { /* @@ -252,7 +252,7 @@ return $errno; */ // the error codes are not supported in pgsql. - return $this->raiseError(DB_ERROR_NOT_CAPABLE); + return $this->raiseError(DB_ERROR_NOT_CAPABLE); // XXX ERRORMSG } $this->row[$result]++; return DB_OK; @@ -271,7 +271,7 @@ function freeResult($result) { if (is_resource($result)) { - return pg_freeresult($result); + return @pg_freeresult($result); } if (!isset($this->prepare_tokens[$result])) { return false; @@ -296,9 +296,9 @@ */ function numCols($result) { - $cols = pg_numfields($result); + $cols = @pg_numfields($result); if (!$cols) { - return $this->raiseError(pg_errormessage($this->connection)); + return $this->pgsqlRaiseError(); } return $cols; } @@ -315,14 +315,22 @@ */ function numRows($result) { - $rows = pg_numrows($result); - if (!$rows) { - return $this->raiseError(pg_errormessage($this->connection)); + $rows = @pg_numrows($result); + if ($rows === null) { + return $this->pgsqlRaiseError(); } return $rows; } // }}} + // {{{ errorCode() + + function errorCode($msg) + { + return DB_ERROR; + } + + // }}} // {{{ errorNative() /** @@ -408,7 +416,7 @@ @fclose(@fopen("php://stderr", "w")); $result = @pg_exec($this->connection, "end;"); if (!$result) { - return $this->raiseError(pg_errormessage($this->connection)); + return $this->pgsqlRaiseError(); } return DB_OK; } @@ -423,7 +431,7 @@ { $result = @pg_exec($this->connection, "abort;"); if (!$result) { - return $this->raiseError(pg_errormessage($this->connection)); + return $this->pgsqlRaiseError(); } return DB_OK; } @@ -446,6 +454,88 @@ return $result; } // }}} + // {{{ nextId() + + /** + * Get the next value in a sequence. + * + * We are using native PostgreSQL sequences. If a sequence does + * not exist, it will be created, unless $ondemand is false. + * + * @access public + * @param string $seq_name the name of the sequence + * @param bool $ondemand whether to create the sequence on demand + * @return a sequence integer, or a DB error + */ + function nextId($seq_name, $ondemand = true) + { + $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name); + $repeat = 0; + do { + $result = $this->query("SELECT NEXTVAL('db_seq_${sqn}')"); + if ($ondemand && DB::isError($result) && + $result->getMessage() == "DB Error: ERROR: db_seq_test.nextval: sequence does not exist\n") { + $repeat = 1; + $result = $this->createSequence($seq_name); + if (DB::isError($result)) { + return $result; + } + } else { + $repeat = 0; + } + } while ($repeat); + if (DB::isError($result)) { + return $result; + } + $arr = $result->fetchRow(DB_FETCHMODE_ORDERED); + $result->free(); + return $arr[0]; + } + + // }}} + // {{{ createSequence() + + /** + * Create the sequence + * + * @param string $seq_name the name of the sequence + * @return DB error + * @access public + */ + function createSequence($seq_name) + { + $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name); + return $this->query("CREATE SEQUENCE db_seq_${sqn}"); + } + + // }}} + // {{{ dropSequence() + + /** + * Drop a sequence + * + * @param string $seq_name the name of the sequence + * @return DB error + * @access public + */ + function dropSequence($seq_name) + { + $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name); + return $this->query("DROP SEQUENCE db_seq_${sqn}"); + } + + // }}} + // {{{ pgsqlRaiseError() + + function pgsqlRaiseError($errno = null) + { + if ($errno === null && pg_errormessage($this->connection)) { + return $this->raiseError(pg_errormessage($this->connection)); + } + return $this->raiseError($this->errorCode($errno)); + } + + // }}} } // Local variables: Index: php4/pear/DB/tests/fetchmodes.inc diff -u php4/pear/DB/tests/fetchmodes.inc:1.2 php4/pear/DB/tests/fetchmodes.inc:1.3 --- php4/pear/DB/tests/fetchmodes.inc:1.2 Thu Dec 7 19:22:15 2000 +++ php4/pear/DB/tests/fetchmodes.inc Wed Dec 13 06:41:04 2000 @@ -2,38 +2,67 @@ $dbh->setErrorHandling(PEAR_ERROR_DIE); -print "testing default default\n"; +print "testing fetchrow default default\n"; $sth = $dbh->query("SELECT * FROM phptest"); $row = $sth->fetchRow(); -//var_dump($row); print implode(" ", array_keys($row))."\n"; -print "testing ordered default\n"; +print "testing fetchinto default default\n"; +$sth = $dbh->query("SELECT * FROM phptest"); +$row = array(); +$sth->fetchInto($row); +print implode(" ", array_keys($row))."\n"; + +print "testing fetchrow 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"; -print "testing assoc default\n"; +print "testing fetchrow 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"; -print "testing ordered default with assoc specified\n"; +print "testing fetchrow 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"; -print "testing assoc default with ordered specified\n"; +print "testing fetchrow assoc default with ordered specified\n"; $dbh->setFetchMode(DB_FETCHMODE_ASSOC); $sth = $dbh->query("SELECT * FROM phptest"); $row = $sth->fetchRow(DB_FETCHMODE_ORDERED); -//var_dump($row); +print implode(" ", array_keys($row))."\n"; + +print "testing fetchinto ordered default\n"; +$dbh->setFetchMode(DB_FETCHMODE_ORDERED); +$sth = $dbh->query("SELECT * FROM phptest"); +$row = array(); +$sth->fetchInto($row); +print implode(" ", array_keys($row))."\n"; + +print "testing fetchinto assoc default\n"; +$dbh->setFetchMode(DB_FETCHMODE_ASSOC); +$sth = $dbh->query("SELECT * FROM phptest"); +$row = array(); +$sth->fetchInto($row); +print implode(" ", array_keys($row))."\n"; + +print "testing fetchinto ordered default with assoc specified\n"; +$dbh->setFetchMode(DB_FETCHMODE_ORDERED); +$sth = $dbh->query("SELECT * FROM phptest"); +$row = array(); +$sth->fetchInto($row, DB_FETCHMODE_ASSOC); +print implode(" ", array_keys($row))."\n"; + +print "testing fetchinto assoc default with ordered specified\n"; +$dbh->setFetchMode(DB_FETCHMODE_ASSOC); +$sth = $dbh->query("SELECT * FROM phptest"); +$row = array(); +$sth->fetchInto($row, DB_FETCHMODE_ORDERED); print implode(" ", array_keys($row))."\n"; ?> Index: php4/pear/DB/tests/numrows.inc diff -u php4/pear/DB/tests/numrows.inc:1.1 php4/pear/DB/tests/numrows.inc:1.2 --- php4/pear/DB/tests/numrows.inc:1.1 Sat Dec 9 17:13:12 2000 +++ php4/pear/DB/tests/numrows.inc Wed Dec 13 06:41:04 2000 @@ -11,5 +11,9 @@ $dbh->query("DELETE FROM phptest WHERE a < 4"); $sth = $dbh->query("SELECT a FROM phptest"); printf("%d\n", $sth->numRows()); +$sth = $dbh->query("SELECT a FROM phptest where a < 0"); +printf("%d\n", $sth->numRows()); +$dbh->setErrorHandling(PEAR_ERROR_PRINT); +$test = $dbh->numRows(false); ?> Index: php4/pear/DB/tests/mysql/001.phpt diff -u php4/pear/DB/tests/mysql/001.phpt:1.2 php4/pear/DB/tests/mysql/001.phpt:1.3 --- php4/pear/DB/tests/mysql/001.phpt:1.2 Wed Dec 6 12:18:41 2000 +++ php4/pear/DB/tests/mysql/001.phpt Wed Dec 13 06:41:04 2000 @@ -1,11 +1,10 @@ --TEST-- DB_mysql::connect test --SKIPIF-- -<?php include("skipif.inc"); ?> +<?php require "skipif.inc"; ?> --FILE-- <?php -require_once "DB.php"; -$dbh = DB::connect("mysql://localhost/test"); +require "connect.inc"; if (is_object($dbh)) { print "\$dbh is an object\n"; } Index: php4/pear/DB/tests/mysql/002.phpt diff -u php4/pear/DB/tests/mysql/002.phpt:1.3 php4/pear/DB/tests/mysql/002.phpt:1.4 --- php4/pear/DB/tests/mysql/002.phpt:1.3 Thu Dec 7 19:22:15 2000 +++ php4/pear/DB/tests/mysql/002.phpt Wed Dec 13 06:41:04 2000 @@ -9,13 +9,23 @@ include("../fetchmodes.inc"); ?> --EXPECT-- -testing default default +testing fetchrow default default 0 1 2 3 -testing ordered default +testing fetchinto default default 0 1 2 3 -testing assoc default +testing fetchrow ordered default +0 1 2 3 +testing fetchrow assoc default +a b c d +testing fetchrow ordered default with assoc specified +a b c d +testing fetchrow assoc default with ordered specified +0 1 2 3 +testing fetchinto ordered default +0 1 2 3 +testing fetchinto assoc default a b c d -testing ordered default with assoc specified +testing fetchinto ordered default with assoc specified a b c d -testing assoc default with ordered specified +testing fetchinto assoc default with ordered specified 0 1 2 3 Index: php4/pear/DB/tests/mysql/005.phpt diff -u php4/pear/DB/tests/mysql/005.phpt:1.2 php4/pear/DB/tests/mysql/005.phpt:1.3 --- php4/pear/DB/tests/mysql/005.phpt:1.2 Wed Dec 6 12:18:41 2000 +++ php4/pear/DB/tests/mysql/005.phpt Wed Dec 13 06:41:04 2000 @@ -1,21 +1,13 @@ --TEST-- -DB_mysql::nextId test +DB_mysql sequences --SKIPIF-- -<?php include("skipif.inc"); ?> +<?php require "skipif.inc"; ?> --FILE-- <?php -require_once "DB.php"; -$dbh = DB::connect("mysql://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"); +require "connect.inc"; +require "../sequences.inc"; ?> --EXPECT-- DB Error: no such table -first=1 second=2 +a=1 +b=2 Index: php4/pear/DB/tests/mysql/009.phpt diff -u php4/pear/DB/tests/mysql/009.phpt:1.1 php4/pear/DB/tests/mysql/009.phpt:1.2 --- php4/pear/DB/tests/mysql/009.phpt:1.1 Sat Dec 9 17:13:12 2000 +++ php4/pear/DB/tests/mysql/009.phpt Wed Dec 13 06:41:04 2000 @@ -1,10 +1,10 @@ --TEST-- DB_mysql::numRows test --SKIPIF-- -<?php include("skipif.inc"); ?> +<?php require "skipif.inc"; ?> --FILE-- <?php -require_once "DB.php"; +require "connect.inc"; require "mktable.inc"; require "../numrows.inc"; ?> @@ -16,3 +16,5 @@ 5 6 2 +0 +DB Error: unknown error Index: php4/pear/DB/tests/mysql/mktable.inc diff -u php4/pear/DB/tests/mysql/mktable.inc:1.1 php4/pear/DB/tests/mysql/mktable.inc:1.2 --- php4/pear/DB/tests/mysql/mktable.inc:1.1 Mon Sep 11 17:27:50 2000 +++ php4/pear/DB/tests/mysql/mktable.inc Wed Dec 13 06:41:04 2000 @@ -1,6 +1,6 @@ <?php -$dbh = DB::connect("mysql://localhost/test"); +require "connect.inc"; $dbh->setErrorHandling(PEAR_ERROR_RETURN); $dbh->query("DROP TABLE phptest"); Index: php4/pear/DB/tests/pgsql/001.phpt diff -u php4/pear/DB/tests/pgsql/001.phpt:1.1 php4/pear/DB/tests/pgsql/001.phpt:1.2 --- php4/pear/DB/tests/pgsql/001.phpt:1.1 Thu Dec 7 19:22:15 2000 +++ php4/pear/DB/tests/pgsql/001.phpt Wed Dec 13 06:41:04 2000 @@ -1,11 +1,10 @@ --TEST-- DB_pgsql::connect test --SKIPIF-- -<?php include("skipif.inc"); ?> +<?php require "skipif.inc"; ?> --FILE-- <?php -require_once "DB.php"; -$dbh = DB::connect("pgsql://localhost/test"); +require "connect.inc"; if (is_object($dbh)) { print "\$dbh is an object\n"; } Index: php4/pear/DB/tests/pgsql/002.phpt diff -u php4/pear/DB/tests/pgsql/002.phpt:1.1 php4/pear/DB/tests/pgsql/002.phpt:1.2 --- php4/pear/DB/tests/pgsql/002.phpt:1.1 Thu Dec 7 19:22:15 2000 +++ php4/pear/DB/tests/pgsql/002.phpt Wed Dec 13 06:41:04 2000 @@ -9,13 +9,23 @@ include("../fetchmodes.inc"); ?> --EXPECT-- -testing default default +testing fetchrow default default 0 1 2 3 -testing ordered default +testing fetchinto default default 0 1 2 3 -testing assoc default +testing fetchrow ordered default +0 1 2 3 +testing fetchrow assoc default +a b c d +testing fetchrow ordered default with assoc specified +a b c d +testing fetchrow assoc default with ordered specified +0 1 2 3 +testing fetchinto ordered default +0 1 2 3 +testing fetchinto assoc default a b c d -testing ordered default with assoc specified +testing fetchinto ordered default with assoc specified a b c d -testing assoc default with ordered specified +testing fetchinto assoc default with ordered specified 0 1 2 3 Index: php4/pear/DB/tests/pgsql/005.phpt diff -u php4/pear/DB/tests/pgsql/005.phpt:1.1 php4/pear/DB/tests/pgsql/005.phpt:1.2 --- php4/pear/DB/tests/pgsql/005.phpt:1.1 Thu Dec 7 19:22:15 2000 +++ php4/pear/DB/tests/pgsql/005.phpt Wed Dec 13 06:41:04 2000 @@ -1,21 +1,14 @@ --TEST-- -DB_pgsql::nextId test +DB_pgsql sequences --SKIPIF-- -<?php die("skip\n"); /* include("skipif.inc"); */ ?> +<?php require "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"); +require "connect.inc"; +require "../sequences.inc"; ?> --EXPECT-- -DB Error: no such table -first=1 second=2 +DB Error: ERROR: db_seq_test.nextval: sequence does not exist + +a=1 +b=2 Index: php4/pear/DB/tests/pgsql/009.phpt diff -u php4/pear/DB/tests/pgsql/009.phpt:1.1 php4/pear/DB/tests/pgsql/009.phpt:1.2 --- php4/pear/DB/tests/pgsql/009.phpt:1.1 Sat Dec 9 17:13:12 2000 +++ php4/pear/DB/tests/pgsql/009.phpt Wed Dec 13 06:41:04 2000 @@ -1,10 +1,10 @@ --TEST-- DB_pgsql::numRows test --SKIPIF-- -<?php include("skipif.inc"); ?> +<?php require "skipif.inc"; ?> --FILE-- <?php -require_once "DB.php"; +require "connect.inc"; require "mktable.inc"; require "../numrows.inc"; ?> @@ -16,3 +16,5 @@ 5 6 2 +0 +DB Error: unknown error Index: php4/pear/DB/tests/pgsql/mktable.inc diff -u php4/pear/DB/tests/pgsql/mktable.inc:1.1 php4/pear/DB/tests/pgsql/mktable.inc:1.2 --- php4/pear/DB/tests/pgsql/mktable.inc:1.1 Thu Dec 7 19:22:15 2000 +++ php4/pear/DB/tests/pgsql/mktable.inc Wed Dec 13 06:41:04 2000 @@ -1,6 +1,6 @@ <?php -$dbh = DB::connect("pgsql://localhost/test"); +require "connect.inc"; $dbh->setErrorHandling(PEAR_ERROR_RETURN); $dbh->query("DROP TABLE phptest"); Index: php4/pear/DB/tests/sequences.inc +++ php4/pear/DB/tests/sequences.inc <?php $dbh->dropSequence("test"); $e = $dbh->nextId("test", false); if (DB::isError($e)) { print $e->getMessage() . "\n"; } $a = $dbh->nextId("test"); $b = $dbh->nextId("test"); if (DB::isError($a)) { print "a: ".$a->getMessage()."\n"; } else { print "a=$a\n"; } if (DB::isError($b)) { print "b: ".$b->getMessage()."\n"; } else { print "b=$b\n"; } $dbh->dropSequence("test"); ?> Index: php4/pear/DB/tests/mysql/connect.inc +++ php4/pear/DB/tests/mysql/connect.inc <?php require_once "DB.php"; $dbh = DB::connect("mysql://localhost/test"); if (DB::isError($dbh)) { die("connect.inc: ".$dbh->getMessage()); } ?> Index: php4/pear/DB/tests/pgsql/.cvsignore +++ php4/pear/DB/tests/pgsql/.cvsignore *.exp *.out *.php phpt.* Index: php4/pear/DB/tests/pgsql/connect.inc +++ php4/pear/DB/tests/pgsql/connect.inc <?php require_once "DB.php"; $dbh = DB::connect("pgsql://localhost/test"); ?>
« previous php.cvs (#3124) next »