From: <tr...@us...> - 2002-09-10 23:01:58
|
Update of /cvsroot/basedb/basedb/www In directory usw-pr-cvs1:/tmp/cvs-serv7338 Modified Files: pgsql.inc.php Log Message: Made db_fetch_assoc not return numerical keys Index: pgsql.inc.php =================================================================== RCS file: /cvsroot/basedb/basedb/www/pgsql.inc.php,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** pgsql.inc.php 10 Sep 2002 10:57:41 -0000 1.12 --- pgsql.inc.php 10 Sep 2002 23:01:42 -0000 1.13 *************** *** 27,34 **** class BaseDatabase { ! var $serv, $affected; function BaseDatabase($server, $user, $password, $database) { $this->affected = 0; $cstring = "host='".addslashes($server)."' ". "user = '".addslashes($user)."' ". --- 27,35 ---- class BaseDatabase { ! var $serv, $affected, $nextrow; function BaseDatabase($server, $user, $password, $database) { $this->affected = 0; + $this->nextrow = array(); $cstring = "host='".addslashes($server)."' ". "user = '".addslashes($user)."' ". *************** *** 53,57 **** - function &db_fetch_row(&$r) { --- 54,57 ---- *************** *** 60,66 **** function &db_fetch_assoc(&$r) { ! // print_r(get_defined_vars()); ! // return pg_fetch_array($GLOBALS["curDb"]->serv, $r, PGSQL_ASSOC); ! return pg_fetch_array($r); } function db_num_rows(&$r) --- 60,81 ---- function &db_fetch_assoc(&$r) { ! // To emulate the missing pg_fetch_assoc() we need to know the ! // current row number, as pg_fetch_array() won't accept a third ! // argument (PGSQL_ASSOC) otherwise. ! // There are two main reasons that we want _assoc rather than _array. ! // The first reason is that mysql_fetch_array does not give a string ! // key for fields that are NULL. pg_fetch_array doesn't have that bug. ! // The second reason is that we want to be able to implode() the array ! // and output it to e.g. a tab-separated file. A more efficient solution ! // than this one is to use pg_fetch_array($r) and then have another ! // db_something function to clean up the numeric keys when needed, ! // but this would introduce unnecessary function calls in places where ! // it could hurt performance for MySQL users (the inner loop when ! // exporting a spot BASEfile, for instance). ! $row = $GLOBALS["curDb"]->nextrow[(int)$r]++; ! if($row >= pg_num_rows($r)) ! return false; ! return pg_fetch_array($r, $row, PGSQL_ASSOC); ! // return pg_fetch_array($r); } function db_num_rows(&$r) *************** *** 86,89 **** --- 101,105 ---- else $GLOBALS["curDb"]->affected = -1; + $GLOBALS["curDb"]->nextrow[(int)$res] = 0; return $res; } |