cvs: pear /MDB_QueryTool/QueryTool Query.php
| From: | Lorenzo Alberton | Date: | Tue, 22 Feb 2005 01:27:17 +0000 |
| Subject: | cvs: pear /MDB_QueryTool/QueryTool Query.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-29646@lists.php.net to get a copy of this message | ||
quipo Mon Feb 21 20:27:17 2005 EDT
Modified files:
/pear/MDB_QueryTool/QueryTool Query.php
Log:
some ibase fixes:
- LOWER() is not defined => use UPPER()
- never use double quotes inside a query
- honor $mdb->options['optimize'] = 'portability' in _metadata()
- return an empty array() on getCol() failure/empty result
http://cvs.php.net/diff.php/pear/MDB_QueryTool/QueryTool/Query.php?r1=1.40&r2=1.41&ty=u
Index: pear/MDB_QueryTool/QueryTool/Query.php
diff -u pear/MDB_QueryTool/QueryTool/Query.php:1.40 pear/MDB_QueryTool/QueryTool/Query.php:1.41
--- pear/MDB_QueryTool/QueryTool/Query.php:1.40 Mon Feb 21 12:48:39 2005
+++ pear/MDB_QueryTool/QueryTool/Query.php Mon Feb 21 20:27:17 2005
@@ -14,7 +14,7 @@
// | Author: Lorenzo Alberton <l.alberton at quipo.it> |
// +----------------------------------------------------------------------+
//
-// $Id: Query.php,v 1.40 2005/02/21 17:48:39 quipo Exp $
+// $Id: Query.php,v 1.41 2005/02/22 01:27:17 quipo Exp $
//
// This is just a port of DB_QueryTool, originally written by
// Wolfram Kriesing and Paolo Panto, vision:produktion <wk@visionp.de>
@@ -434,7 +434,8 @@
if ($count) {
$query['limit'] = array($from, $count);
}
- return $this->returnResult($this->execute($this->_buildSelectQuery($query),
'getCol'));
+ $res = $this->returnResult($this->execute($this->_buildSelectQuery($query),
'getCol'));
+ return ($res === false) ? array() : $res;
}
// }}}
@@ -618,14 +619,14 @@
//unset($newData[$this->primaryCol]);
- $newData = $this->_checkColumns($newData,'add');
+ $newData = $this->_checkColumns($newData, 'add');
$newData = $this->_quoteArray($newData);
- $query = sprintf( 'INSERT INTO %s (%s) VALUES (%s)',
- $this->table,
- implode(', ', array_keys($newData)),
- implode(', ', $newData)
- );
+ $query = sprintf('INSERT INTO %s (%s) VALUES (%s)',
+ $this->table,
+ implode(', ', array_keys($newData)),
+ implode(', ', $newData)
+ );
return $this->execute($query, 'query') ? $id : false;
}
@@ -896,8 +897,9 @@
}
}
- $string = $this->_quote('%'.str_replace(' ', '%',
strtolower($string)).'%');
- $this->addWhere("LOWER($column) LIKE $string", $condition);
+ //ibase doesn't have the LOWER() function, so using UPPER() here...
+ $string = $this->_quote('%'.str_replace(' ', '%',
strtoupper($string)).'%');
+ $this->addWhere("UPPER($column) LIKE $string", $condition);
}
// }}}
@@ -1418,13 +1420,12 @@
// if the current column exists, check the length too, not to write content that is
too long
// prevent DB-errors here
// do only check the data length if this field is given
-// FIXXME use PEAR-defined field for 'DATA_LENGTH'
- if (isset($meta[$colName]['DATA_LENGTH']) &&
- ($oldLength=strlen($newData[$colName])) >
$meta[$colName]['DATA_LENGTH'])
+ if (isset($meta[$colName]['len']) &&
+ ($oldLength=strlen($newData[$colName])) > $meta[$colName]['len'])
{
$this->_errorLog("_checkColumns, had to trim column
'$colName' from $oldLength to ".
- $meta[$colName]['DATA_LENGTH'].'
characters.',__LINE__);
- $newData[$colName] =
substr($newData[$colName],0,$meta[$colName]['DATA_LENGTH']);
+ $meta[$colName]['len'].'
characters.',__LINE__);
+ $newData[$colName] =
substr($newData[$colName],0,$meta[$colName]['len']);
}
}
}
@@ -1512,7 +1513,7 @@
if (!is_object($this->db)) {
return false;
}
- $res = $this->db->tableinfo($table);
+ $res = $this->db->tableInfo($table);
if (MDB::isError($res)) {
$this->_errorSet($res->getUserInfo());
return false;
@@ -1523,6 +1524,9 @@
foreach ($res as $key => $val) {
$ret[$val['name']] = $val;
}
+ if ($this->db->options['optimize'] == 'portability') {
+ $ret = array_change_key_case($ret, CASE_LOWER);
+ }
$this->_metadata[$table] = $ret;
return $ret;
}
@@ -1695,8 +1699,14 @@
// put " around them to enable use of reserved words, i.e. SELECT
table.option as option FROM...
// and 'option' actually is a reserved word, at least in mysql
// put double quotes around them, since pgsql doesnt work with single
quotes
+ // but don't do this for ibase because it doesn't work!
if ($aTable == $this->table) {
- $cols[$aTable][] = $this->table. '.' .$colName . ' AS
"'. $colName .'"';
+ if ($this->db->phptype == 'ibase') {
+ $cols[$aTable][] = $this->table. '.' .$colName .
' AS '. $colName;
+ } else {
+ $cols[$aTable][] = $this->table. '.' .$colName .
' AS "'. $colName .'"';
+ }
+
} else {
//$cols[$aTable][] = "$aTable.$colName AS
\"_".$this->getTableShortName($aTable)."_$colName\"";
$cols[$aTable][] = $aTable. '.' .$colName .' AS
"_'. $this->getTableShortName($aTable) .'_'. $colName .'"';
@@ -1995,6 +2005,7 @@
$this->debug($query);
$this->writeLog('start query');
if (MDB::isError($res = $this->db->$method($query))) {
+
if ($this->getOption('verbose')) {
//$this->_errorSet($this->db->errorMessage($res->getCode()));
$this->_errorSet($res->getMessage() .'-'. $res->getUserInfo());