[phplib-dev] cvs commit From: ssilk (phplib-dev <email protected>)
Date: 07/11/00

From: ssilk
Date: Wed Jul 12 01:20:52 2000
Modified files:
      php-lib/php/query_sql.inc

Log message:
- In PHP4 the function query() from DB_Sql collides with the name of the
  extension (Query). So the class must be renamed to Query_SQL.
- Bugfix with empty/unset Array indizes.
- wrong varname $params fixed
- New function capture_table_array($table,$arr) - returns every var from $arr
  (is an assoc array) whose name is a field in table $table.
- new function getexrow() (get existing row), which is the same as getrow()
  but dosn't complain about non existing index
- TODO: Changelog, Docs...

Index: php-lib/php/query_sql.inc
diff -u php-lib/php/query_sql.inc:1.18 php-lib/php/query_sql.inc:1.19
--- php-lib/php/query_sql.inc:1.18 Fri Jun 30 03:55:23 2000
+++ php-lib/php/query_sql.inc Wed Jul 12 01:20:50 2000
@@ -18,7 +18,7 @@
  * is based in November 1997,
  * it was a collection of functions for PHP/FI and mSQL.
  *
- * $Id: query_sql.inc,v 1.18 2000/06/30 01:55:23 ssilk Exp $
+ * $Id: query_sql.inc,v 1.19 2000/07/11 23:20:50 ssilk Exp $
  *
  */
 
@@ -27,7 +27,7 @@
 ## See PHPLib-documention to use it!
 
 
-class Query extends DB_Sql {
+class Query_SQL extends DB_Sql {
 
         ## DONT FORGET to set the variables from DB_Sql! See there!
 
@@ -287,7 +287,7 @@
                 # add information for $special-fields which are not used
                 # in the above loop
                 for (reset($special); list($key,$val)=each($special); ) {
- if ( isset($meta[meta][$key]) && empty($fields[$key]) ) {
+ if ( isset($meta[meta][$key]) && !isset($fields[$key]) ) {
                                 $j=$meta[meta][$key];
                                 list($vals[],$names[])=
                                      $this->convert($fields[$key],$meta[$j],$val);
@@ -369,7 +369,7 @@
                 for ($i=0; $i < $meta["num_fields"]; $i++) {
                         $j=$meta[$i]["name"];
                         if (!isset($fields[$j])) {
- if ($param[nullisnull]) {
+ if ($params[nullisnull]) {
                                         $special[$j]='NULL';
                                 } else {
                                         $fields[$j]='';
@@ -454,7 +454,7 @@
                 for ($i=0; $i < $meta["num_fields"]; $i++) {
                         $j=$meta[$i]["name"];
                         if (!isset($fields[$j])) {
- if ($param[nullisnull]) {
+ if ($params[nullisnull]) {
                                         $special[$j]='NULL';
                                 } else {
                                         $fields[$j]='';
@@ -556,6 +556,7 @@
                 if (!is_Array($special)) $special=ARRAY();
                 if (!$andor) $andor='AND';
                 if (!is_Array($fields)) $fields=ARRAY();
+ if (!is_string($where)) echo "WARNING: WHERE is not string\n";
 
                 $q='';
                 $meta=$this->metadata_buffered($table);
@@ -605,7 +606,7 @@
                         return(false);
                 }
                 $uniq=split(" ",$meta[unique]);
- $where=ARRAY();
+ $wfields=ARRAY();
                 for ( reset($uniq) ; list(,$name)=each($uniq) ; ) {
                         if (isset($meta[meta][$name])) {
                                 $tmp= $this->convert($fields[$name],
@@ -613,14 +614,14 @@
                                                      $special[$name]);
                                 if ( (string)$tmp[0] !='NULL' &&
                                      empty($special[removenull]) ) {
- $where[$name]=$fields[$name];
+ $wfields[$name]=$fields[$name];
                                 }
                         } else {
                                 echo "ERROR: unique_where_Clause(): This unique index dosn't exist: '$name'<br>";
                                 return(false);
                         }
                 }
- $whereclause=$this->where_Clause($table,$where,$op,$special,
+ $whereclause=$this->where_Clause($table,$wfields,$op,$special,
                              $andor,$where,$special);
                 if (!$whereclause) {
                         echo "ERROR: unique_where_Clause(): The result of generating a where-clause to this uniqe identifers is empty:<br>";
@@ -745,14 +746,25 @@
         ## This function creates a query like exists, but returns
         ## an assoc array of the first found row, or false if nothing found
         ## field $name is set with value $val
+ ##
+ function getrow ($table,$name_or_fields,$val='') {
+ if (!$res=$this->getexrow(&$table,&$name_or_fields,&$val)) {
+ echo "<BR><B>WARNING:</B> getrow(): '$where' not found<BR>";
+ return(false);
+ }
+ return($res);
+ }
+ ## This function creates a query like exists, but returns
+ ## an assoc array of the first found row, or false if nothing found
+ ## field $name is set with value $val
         ##
- function getrow ($table,$name_or_fields,$val) {
+ function getexrow ($table,$name_or_fields,$val='') {
                 $meta=$this->metadata_buffered($table);
                 list($fields,$name)=$this->special_or_where($name_or_fields);
 
                 if (empty($name)) {
                         $where=$this->where_Clause($table,$fields,'strong');
- } elseif ($name && !emtpy($val) ) {
+ } elseif ($name && !empty($val) ) {
                         $where=$this->where_Clause($table,ARRAY($name=>$val),'strong');
                 } else {
                         $this->halt("exists(): Val was not set");
@@ -764,7 +776,6 @@
                 if ($this->next_record()) {
                         return($this->Record);
                 } else {
- echo "<BR><B>WARNING:</B> getrow(): KEY: $name VAL: $val not found<BR>";
                         return(false);
                 }
         }
@@ -793,9 +804,6 @@
         }
 
 
-
-
-
         ##
         ## capture-vars
         ##
@@ -813,6 +821,25 @@
                         $j=$meta[$i]["name"];
                         if (isset($GLOBALS[$j])) {
                             $r[$j] = $GLOBALS[$j];
+ $this->_QDebug("Found $j: $r[$j]");
+ }
+ }
+ return($r);
+ }
+
+ ##
+ ## capture_table_array
+ ##
+ ## Returns an assoc array, wich will hold only those name=>value
+ ## pairs wich are in the given table
+ ##
+ function capture_table_array ($table,$arr) {
+ $meta=$this->metadata_buffered($table);
+ $r=Array();
+ for ($i=0; $i < $meta["num_fields"]; $i++) {
+ $j=$meta[$i]["name"];
+ if (isset($arr[$j])) {
+ $r[$j] = $arr[$j];
                                 $this->_QDebug("Found $j: $r[$j]");
                         }
                 }

---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-dev-unsubscribe <email protected>
For additional commands, e-mail: phplib-dev-help <email protected>