Date: 09/21/00
- Next message: Jeff Stuart: "[phplib-dev] How stable is PHPLib-Dev"
- Previous message: Phil Cole: "[phplib-dev] PHPLIB session should use & in GET mode"
- Next in thread: uw: "[phplib-dev] cvs commit"
- Maybe reply: uw: "[phplib-dev] cvs commit"
- Maybe reply: uw: "[phplib-dev] cvs commit"
- Maybe reply: uw: "[phplib-dev] cvs commit"
- Maybe reply: teo: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: ssilk
Date: Thu Sep 21 23:27:30 2000
Modified files:
php-lib/php/query_sql.inc
Log message:
Many, many bugfixes
Index: php-lib/php/query_sql.inc
diff -u php-lib/php/query_sql.inc:1.20 php-lib/php/query_sql.inc:1.21
--- php-lib/php/query_sql.inc:1.20 Mon Jul 24 03:17:50 2000
+++ php-lib/php/query_sql.inc Thu Sep 21 23:26:59 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.20 2000/07/24 01:17:50 ssilk Exp $
+ * $Id: query_sql.inc,v 1.21 2000/09/21 21:26:59 ssilk Exp $
*
*/
@@ -212,8 +212,10 @@
## without leaving query-class.
##
function table_quote($table,$name,$value,$spec='') {
- $meta=$this->metadata_buffered($table);
- return($this->convert($value,$meta[$meta['meta'][$name]],special));
+ list($table,$prefix)=$this->istableprefix($table,$spec);
+ $meta=$this->metadata_buffered($table,$prefix);
+ list($val,$name)=$this->convert($value,$meta[$meta['meta'][$name]],$spec);
+ return($val);
}
##
@@ -226,7 +228,7 @@
$check=strtolower($params);
$params=ARRAY('check'=>$check);
} else {
- $check=strtolower($params['check']);
+ $check=strtolower(@$params['check']);
}
if (empty($check)) $check='soft';
if (! ereg("strong|soft|weak",$check) ) {
@@ -247,22 +249,22 @@
if (empty($p1)) {
if (is_Array($p2)) {
$special=$p2;
- } elseif (strlen($p2) > 2) { # simplest possible where clause is a=1
+ } elseif (strlen($p2) > 0) { # simplest possible where clause is a=1
$where=$p2;
}
} elseif (empty($p2)) {
if (is_Array($p1)) {
$special=$p1;
- } elseif (strlen($p1) > 2) {
+ } elseif (strlen($p1) > 0) {
$where=$p1;
}
} elseif (empty($p1) && empty($p2)) {
# do nothing
} else {
- if (is_Array($p1) && (strlen($p2) > 2)) {
+ if (is_Array($p1) && (strlen($p2) > 0)) {
$special=$p1;
$where=$p2;
- } elseif (is_Array($p2) && (strlen($p1) > 2)) {
+ } elseif (is_Array($p2) && (strlen($p1) > 0)) {
$special=$p2;
$where=$p1;
} else {
@@ -279,8 +281,8 @@
## ( string $where )
## : string $where
function uniform_where ($where) {
+ $where=trim($where);
if (!empty($where)) {
- $where=trim($where);
if (!eregi("^WHERE[[:space:]]",$where)) {
## insert "WHERE" if not set
$where="WHERE $where";
@@ -300,6 +302,7 @@
## ( array $meta , array $fields , array $special )
## : array (array ($vals) , array($names) )
function uniform_vars (&$meta,&$fields,&$special) {
+ $vals=array(); $names=array();
for (reset($fields); list($key,$val)=each($fields); ) {
if ( isset($meta['meta'][$key]) ) {
$j=$meta['meta'][$key];
@@ -311,8 +314,8 @@
# 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]) && !isset($fields[$key]) ) {
- $j=$meta[meta][$key];
+ if ( isset($meta['meta'][$key]) && !isset($fields[$key]) ) {
+ $j=$meta['meta'][$key];
list($vals[],$names[])=
$this->convert($fields[$key],$meta[$j],$val);
}
@@ -415,7 +418,7 @@
list($table,$prefix)=$this->istableprefix($table,$special);
$meta=$this->metadata_buffered($table,$prefix);
- if (Count($fields)!=Count($val['name']) && $check=='strong') {
+ if (Count($fields)!=$meta['num_fields'] && $check=='strong') {
$this->halt("WARNING: insert_plain_clause(): There are not the same number of".
" fields as in table for INSERT");
}
@@ -423,7 +426,7 @@
for ($i=0; $i < $meta['num_fields']; $i++) {
$j=$meta[$i]['name'];
if (!isset($fields[$j])) {
- if ($params['nullisnull']) {
+ if (!empty($params['nullisnull'])) {
$special[$j]='NULL';
} else {
$fields[$j]='';
@@ -547,7 +550,7 @@
if (empty($where)) {
## then fields must hold some values
- list($table,$prefix)=$this->istableprefix($table,$special);
+ list($table,$prefix)=$this->istableprefix($table,$params);
$meta=$this->metadata_buffered($table,$prefix);
$uniq=split(" ",$meta['unique']);
$where=ARRAY();
@@ -635,7 +638,7 @@
$where=$this->uniform_add_where($where);
if ($where) $q.=" $andor $where";
}
- if (!$q && $ckeck=='strong') {
+ if (!$q && $check=='strong') {
echo "WARNING: where_Clause(): WHERE-clause is empty!<BR>";
}
$q=$this->uniform_where(ereg_Replace("^ $andor ","",$q));
@@ -673,7 +676,7 @@
if (isset($meta['meta'][$name])) {
$tmp= $this->convert($fields[$name],
$meta[$meta['meta'][$name]],
- $special[$name]);
+ @$special[$name]);
if ( (string)$tmp[0] !='NULL' &&
empty($special['removenull']) ) {
$wfields[$name]=$fields[$name];
@@ -797,6 +800,7 @@
} else {
$this->halt("exists(): Val was not set");
}
+
$q=sprintf("SELECT COUNT(*) as c FROM %s%s",
$table,$where);
$this->_QDebug($q);
@@ -829,7 +833,8 @@
} elseif ($name && !empty($val) ) {
$where=$this->where_Clause($table,ARRAY($name=>$val),'',$special,'','','strong');
} else {
- $this->halt("getexrow(): Val was not set");
+ $this->halt("getexrow(): Val was not set:
+'$name_or_fields' => '$val'");
}
$q=sprintf("SELECT * FROM %s%s",
$table,$where);
@@ -841,19 +846,23 @@
return(false);
}
}
- ## This function is like getrow(), and returns
+
+ ## This function is like getexrow(), and returns
## an assoc array of the first found row, or false if nothing found
- ## The where-parameter is a where-clause - could be generated by
- ## where_clause()...
- ##
- function getrow_where ($table,$where) {
- if ($where) {
- if (!eregi("^[[:space:]]*WHERE",$where)) {
- $where="WHERE $where";
- }
- }
+ ## If $where_or_wfields is an array it will run through
+ ## where_Clause() and $where will be added, otherwise the
+ ## where-parameter will be ignored!
+ ##
+ function getrow_where ($table,$where_or_wfields,$special='',$where='') {
+ list($fields)=$this->special_or_where($where_or_wfields);
+
+ if (is_array($fields))
+ $where=$this->where_Clause($table,$fields,'',
+ $special,'',$where);
+
+ list($table)=$this->istableprefix($table,$special);
$q=sprintf("SELECT * FROM %s %s",
- $table,$where);
+ $table,$this->uniform_where($where));
$this->_QDebug($q);
$this->query($q);
if ($this->next_record()) {
@@ -897,8 +906,7 @@
## pairs wich are in the given table
##
function capture_table_array ($table,$arr) {
- list($table,$prefix)=$this->istableprefix($table,$special);
- $meta=$this->metadata_buffered($table,$prefix);
+ $meta=$this->metadata_buffered($table);
$r=Array();
for ($i=0; $i < $meta['num_fields']; $i++) {
$j=$meta[$i]['name'];
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-dev-unsubscribe <email protected>
For additional commands, e-mail: phplib-dev-help <email protected>
- Next message: Jeff Stuart: "[phplib-dev] How stable is PHPLib-Dev"
- Previous message: Phil Cole: "[phplib-dev] PHPLIB session should use & in GET mode"
- Next in thread: uw: "[phplib-dev] cvs commit"
- Maybe reply: uw: "[phplib-dev] cvs commit"
- Maybe reply: uw: "[phplib-dev] cvs commit"
- Maybe reply: uw: "[phplib-dev] cvs commit"
- Maybe reply: teo: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

