[PHPLIB-DEV] cvs commit From: ssilk (phplib-dev <email protected>)
Date: 04/02/00

From: ssilk
Date: Mon Apr 3 01:47:30 2000
Modified files:
      php-lib/php/query_sql.inc

Log message:
- Explicite casting of values before check
- Bugfix "full" instead of "strong"
- function exists() now takes also an array as WHERE-parameter

Index: php-lib/php/query_sql.inc
diff -u php-lib/php/query_sql.inc:1.15 php-lib/php/query_sql.inc:1.16
--- php-lib/php/query_sql.inc:1.15 Sat Mar 25 02:37:52 2000
+++ php-lib/php/query_sql.inc Mon Apr 3 01:47:00 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.15 2000/03/25 01:37:52 ssilk Exp $
+ * $Id: query_sql.inc,v 1.16 2000/04/02 23:47:00 ssilk Exp $
  *
  */
 
@@ -208,10 +208,10 @@
 
         function convert ($val,$meta,$special="") {
                 list($type,$subtype)=$this->sql2phptype($meta);
- if ((strtoupper($val) == "NULL" &&
+ if (( (string)strtoupper($val) == 'NULL' &&
                     ($type != "string" || $type[1] != "")) ||
- strtoupper($special) == "NULL") {
- $type="NULL";
+ (string)strtoupper($special) == 'NULL') {
+ $type='NULL';
                 } else {
                         if ($special) {
                                 $type=$special;
@@ -221,14 +221,15 @@
                                 }
                         }
                 }
- switch ($type) {
+ switch ((string)$type) {
                         case "string" :
                                 $val=(string)$val;
- if ($val=='' && $this->EmptyStringIsNull) {
+ if (empty($val) && $this->EmptyStringIsNull) {
                                         $val='NULL';
                                         $subtype='NULL';
                                 }
- if (strtoupper($val)=='NULL' && $this->NULLIsSpace) {
+ if ((string)strtoupper($val)=='NULL'
+ && $this->NULLIsSpace) {
                                         $val=' ';
                                         $subtype='';
                                 }
@@ -247,12 +248,12 @@
                                                                 echo ", TRUNCATING!";
                                                         }
                                                 }
- if ($this->StrLengTrunc && $subtype!='NULL') {
+ if ($this->StrLengTrunc && (string)$subtype!='NULL') {
                                                         $val=substr($val,0,$meta[len]);
                                                 }
                                         }
                                 }
- if ($subtype!='NULL') {
+ if ((string)$subtype!='NULL') {
                                         $val=$this->Quotechar . $val . $this->Quotechar;
                                 }
                                 break;
@@ -286,6 +287,7 @@
                 } else {
                         $check=strtolower($params[check]);
                 }
+ if (empty($check)) $check='soft';
                 if (! ereg("strong|soft|weak",$check) ) {
                         $this->halt("chkprms(): Parameter \$check is not valid: '$check'");
                 }
@@ -409,7 +411,7 @@
         ## and send it to your DB
         ##
         function insert_Clause ($table,$fields,$special='',$params="soft") {
- if (''==$special) $special=ARRAY();
+ if (empty($special)) $special=ARRAY();
                 list($params,$check)=$this->chkprms($params);
 
                 $meta=$this->metadata_buffered($table);
@@ -451,7 +453,7 @@
         ## and send it to your DB
         ##
         function insert_plain_Clause ($table,$fields,$special='',$params="soft") {
- if (''==$special) $special=ARRAY();
+ if (empty($special)) $special=ARRAY();
                 list($params,$check)=$this->chkprms($params);
 
                 $meta=$this->metadata_buffered($table);
@@ -528,7 +530,7 @@
         ##
         function update_plain_Clause ($table,$fields,
                  $special_or_where='',$where_or_special='',$params="soft") {
- list($special,$where)=special_or_where($where_or_special,$special_or_where);
+ list($special,$where)=$this->special_or_where($where_or_special,$special_or_where);
                 list($params,$check)=$this->chkprms($params);
 
                 $meta=$this->metadata_buffered($table);
@@ -572,7 +574,7 @@
                 list($fields,$where)=$this->special_or_where($where_or_wfields);
                 list($params,$check)=$this->chkprms($params);
 
- if (! empty($where)) {
+ if (empty($where)) {
                         ## then fields must hold some values
                         $meta=$this->metadata_buffered($table);
                         $uniq=split(" ",$meta[unique]);
@@ -583,7 +585,7 @@
                         }
                         if ($check=="strong" && !count($where)) {
                                 echo "ERROR: delete_Clause(): A unique identifier dosn't exist.<br>";
- echo "Turn of check='strong' or call it with wfields-params.";
+ echo "Turn off check='strong' or call it with wfields-params.";
                                 return(false);
                         } elseif (count($where)) {
                                 $fields=$where;
@@ -645,7 +647,7 @@
 
                 for ($i=0; $i < Count($names) ; $i++) {
                         if (empty($op[$names[$i]])) $o='='; else $o=$op[$names[$i]];
- if ('NULL'==$vals[$i]) {
+ if ((string)$vals[$i]=='NULL') {
                                 if ($o=='=' || strtoupper($o)=='IS') $o = 'IS';
                                 else $o = 'IS NOT';
                         }
@@ -655,7 +657,7 @@
                         $where=eregi_Replace("^[[:space:]]*WHERE","",$where);
                         $q.=" $andor $where";
                 }
- if (!$q && $ckeck=='full') {
+ if (!$q && $ckeck=='strong') {
                         echo "WARNING: where_Clause(): WHERE-clause is empty!<BR>";
                 }
                 $q=$this->uniform_where(ereg_Replace("^ $andor ","",$q));
@@ -722,7 +724,7 @@
         ## the parameter is taken over to
         ## forceinsert => true
         function IU_Clause ($table,$fields,$special='',$params='soft') {
- if (''==$special) $special=ARRAY();
+ if (empty($special)) $special=ARRAY();
                 list($params,$check)=$this->chkprms($params);
 
                 $meta=$this->metadata_buffered($table);
@@ -739,7 +741,7 @@
                                 $tmp= $this->convert($fields[$name],
                                                      $meta[$meta[meta][$name]],
                                                      $special[$name]);
- if ( $tmp[0] !="NULL" ) {
+ if ( (string)$tmp[0] !="NULL" ) {
                                         $where[$name]=$fields[$name];
                                 }
                         } else {
@@ -782,13 +784,20 @@
         ##
         ## it returns the number of found matches or zero
         ##
- function exists ($table,$name,$val) {
+ function exists ($table,$name_or_fields,$val='') {
                 $meta=$this->metadata_buffered($table);
- $j=$meta["meta"][$name];
- list($k)=$this->convert($val,$meta[$j]);
- $q=sprintf("SELECT COUNT(%s) as c FROM %s WHERE %s=%s",
- $name,$table,$name,$k);
- $this->_QDebugs($q);
+ list($fields,$name)=$this->special_or_where($name_or_fields);
+
+ if (empty($name)) {
+ $where=$this->where_Clause($table,$fields,'strong');
+ } elseif ($name && !emtpy($val) ) {
+ $where=$this->where_Clause($table,ARRAY($name=>$val),'strong');
+ } else {
+ $this->halt("exists(): Val was not set");
+ }
+ $q=sprintf("SELECT COUNT(*) as c FROM %s%s",
+ $table,$where);
+ $this->_QDebug($q);
                 $this->query($q);
                 $this->next_record();
                 return($this->f("c"));
@@ -828,8 +837,10 @@
                 $this->_QDebug($q);
                 $this->query($q);
                 if ($this->next_record()) {
+ $this->_QDebug("getrow_where(): found");
                         return($this->Record);
                 } else {
+ $this->_QDebug("getrow_where(): not found");
                         return(false);
                 }
         }
@@ -1078,7 +1089,7 @@
                 $tmp=' '; $mod=0;
                 for ($i=0 ; $i < strlen($string) ; $i++ ) {
                         $j=substr($string,$i,1);
- if ( '"'==$j ) {
+ if ( '"'==(string)$j ) {
                                 if (!$mod && ereg("[ +-]",$tmp) ) {
                                         $mod=1; $merker=$i;
                                 }
@@ -1090,7 +1101,7 @@
                                         $mod=0; $i--;
                                 }
                         }
- elseif ($j==' ' && $mod) {
+ elseif ((string)$j==' ' && $mod) {
                                 $string=substr($string,0,$i) .$this->fireball_replace_char.
                                         substr($string,$i+1);
                         }

-
PHPLIB Developers Mailing List. Send messages to <phplib-dev <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in
the body, not the subject, of your message.