cvs: pear /MDB_QueryTool/QueryTool Query.php
| From: | Lorenzo Alberton | Date: | Fri, 19 Mar 2004 01:07:03 +0000 |
| Subject: | cvs: pear /MDB_QueryTool/QueryTool Query.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-17529@lists.php.net to get a copy of this message | ||
quipo Thu Mar 18 20:07:03 2004 EDT
Modified files:
/pear/MDB_QueryTool/QueryTool Query.php
Log:
- MDB::nextId() will return an int => no need for _quote()
- add a check on metadata() return type before feeding a foreach()
- cosmetic fixes
http://cvs.php.net/diff.php/pear/MDB_QueryTool/QueryTool/Query.php?r1=1.24&r2=1.25&ty=u
Index: pear/MDB_QueryTool/QueryTool/Query.php
diff -u pear/MDB_QueryTool/QueryTool/Query.php:1.24 pear/MDB_QueryTool/QueryTool/Query.php:1.25
--- pear/MDB_QueryTool/QueryTool/Query.php:1.24 Thu Mar 18 05:29:01 2004
+++ pear/MDB_QueryTool/QueryTool/Query.php Thu Mar 18 20:07:02 2004
@@ -15,7 +15,7 @@
// | Author: Lorenzo Alberton <l.alberton at quipo.it> |
// +----------------------------------------------------------------------+
//
-// $Id: Query.php,v 1.24 2004/03/18 10:29:01 quipo Exp $
+// $Id: Query.php,v 1.25 2004/03/19 01:07:02 quipo Exp $
//
// This is just a port of DB_QueryTool, originally written by
// Wolfram Kriesing and Paolo Panto, vision:produktion <wk@visionp.de>
@@ -416,7 +416,7 @@
/* the following query works on mysql
SELECT count(DISTINCT image.id) FROM image2tree
RIGHT JOIN image ON image.id = image2tree.image_id
-the reason why this is needed - i jsut wanted to get the number of rows that do exist if the result
is grouped by image.id
+the reason why this is needed - i just wanted to get the number of rows that do exist if the result
is grouped by image.id
the following query is what i tried first, but that returns the number of rows that have been
grouped together
for each image.id
SELECT count(*) FROM image2tree
@@ -427,10 +427,10 @@
//FIXXME see comment above if this is absolutely correct!!!
if ($group = $this->_buildGroup()) {
- $query['select'] = 'count(DISTINCT '.$group.')';
+ $query['select'] = 'COUNT(DISTINCT '.$group.')';
$query['group'] = '';
} else {
- $query['select'] = 'count(*)';
+ $query['select'] = 'COUNT(*)';
}
$query['order'] = ''; // order is not of importance and might freak
up the special group-handling up there, since the order-col is not be known
@@ -477,7 +477,11 @@
*/
function getQueryString()
{
- return $this->_buildSelectQuery();
+ $ret = $this->_buildSelectQuery();
+ if (is_string($ret)) {
+ $ret = trim($ret);
+ }
+ return $ret;
}
/**
@@ -550,8 +554,8 @@
if ($this->primaryCol) { // do only use the sequence if a primary column is given
// otherwise the data are written as given
- $id = $this->db->nextId($this->sequenceName);
- $newData[$this->primaryCol] = $this->_quote($id);
+ $id = (int)$this->db->nextId($this->sequenceName);
+ $newData[$this->primaryCol] = (int)$id;
} else {
// if no primary col is given return true on success
$id = true;
@@ -1529,16 +1533,18 @@
if ($this->getJoin()) {
// replace all 'column' by '$this->table.column' to prevent
ambigious errors
- foreach ($this->metadata() as $aCol => $x) {
- // handle ',id as xid,MAX(id),id' etc.
+ $metadata = $this->metadata();
+ if (is_array($metadata)) {
+ foreach ($this->metadata() as $aCol => $x) {
+ // handle ',id as xid,MAX(id),id' etc.
// FIXXME do this better!!!
- $what = preg_replace( "/(^|,|\()(\s*)$aCol(\)|\s|,|as|$)/i",
- // $2 is actually just to keep the spaces, is not really
- // necessary, but this way the test works independent of
this functionality here
- "$1$2{$this->table}.$aCol$3",
- $what);
+ $what = preg_replace( "/(^|,|\()(\s*)$aCol(\)|\s|,|as|$)/i",
+ // $2 is actually just to keep the spaces, is not
really
+ // necessary, but this way the test works independent
of this functionality here
+ "$1$2{$this->table}.$aCol$3",
+ $what);
+ }
}
-
// replace all 'joinedTable.columnName' by
'_joinedTable_columnName'
// this actually only has an effect if there was no 'table.*' for
'table'
// if that was there, then it has already been done before