cvs: pear /MDB_QueryTool/QueryTool Query.php

From: Date: Tue, 23 Sep 2003 13:23:49 +0000
Subject: cvs: pear /MDB_QueryTool/QueryTool Query.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-13014@lists.php.net to get a copy of this message
quipo Tue Sep 23 09:23:49 2003 EDT Modified files: /pear/MDB_QueryTool/QueryTool Query.php Log: * keep up-to-date with DB_QueryTool 0.9.8 - added new method getQueryString() which returns the rendered query - added setDbInstance() which lets you supply an existing MDB-instance to work with using this you dont need to pass a DSN to the constructor! - use Log 1.7 API - bugfix in addMultiple() - addWhereSearch now only prefixes known columns as it is supposed to be - make setLimit also work to unset it Index: pear/MDB_QueryTool/QueryTool/Query.php diff -u pear/MDB_QueryTool/QueryTool/Query.php:1.17 pear/MDB_QueryTool/QueryTool/Query.php:1.18 --- pear/MDB_QueryTool/QueryTool/Query.php:1.17 Wed Jul 16 11:59:00 2003 +++ pear/MDB_QueryTool/QueryTool/Query.php Tue Sep 23 09:23:49 2003 @@ -15,7 +15,7 @@ // | Author: Lorenzo Alberton <l.alberton at quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: Query.php,v 1.17 2003/07/16 15:59:00 quipo Exp $ +// $Id: Query.php,v 1.18 2003/09/23 13:23:49 quipo Exp $ // // This is just a port of DB_QueryTool, originally written by // Wolfram Kriesing and Paolo Panto, vision:produktion <wk@visionp.de> @@ -96,7 +96,7 @@ var $_group = ''; /** - * @var array the limit + * @var array the limit * @access private */ var $_limit = array(); @@ -181,7 +181,7 @@ * @access private */ var $_logObject = null; - + /** * Some internal data the logging needs * @access private @@ -196,7 +196,7 @@ * @param array options array * @access public */ - function __construct($dsn, $options=array()) + function __construct($dsn=false, $options=array()) { if (!isset($options['autoConnect'])) { $autoConnect = true; @@ -211,7 +211,7 @@ $this->setErrorLogCallback($options['errorLogCallback']); } - if ($autoConnect) { + if ($autoConnect && $dsn) { $this->connect($dsn); } @@ -241,7 +241,7 @@ * @param array options array * @access public */ - function MDB_QueryTool_Query($dsn, $options=array()) + function MDB_QueryTool_Query($dsn=false, $options=array()) { $this->__construct($dsn, $options); } @@ -256,6 +256,20 @@ } /** + * Setup using an existing connection. + * this also sets the MDB_FETCHMODE_ASSOC since this class + * needs this to be set! + * + * @param object a reference to an existing DB-object + * @return void + */ + function setDbInstance( &$dbh) + { + $this->db =& $dbh; + $this->db->setFetchMode(MDB_FETCHMODE_ASSOC); + } + + /** * get the data of a single entry * if the second parameter is only one column the result will be returned * directly not as an array! @@ -332,13 +346,13 @@ } /** - * this method only returns one column, so the result will be a one dimensional array - * this does also mean that using setSelect() should be set to *one* column, the one you want to + * this method only returns one column, so the result will be a one dimensional array + * this does also mean that using setSelect() should be set to *one* column, the one you want to * have returned a most common use case for this could be: * $table->setSelect('id'); * $ids = $table->getCol(); * OR - * $ids = $table->getCol('id'); + * $ids = $table->getCol('id'); * so ids will ba an array with all the id's * * @param string the column that shall be retreived @@ -353,7 +367,7 @@ $query = array(); if ($column != null) { // by using _buildSelect() I can be sure that the table name will not be ambiguous - // i.e. in a join, where all the joined tables have a col 'id' + // i.e. in a join, where all the joined tables have a col 'id' // _buildSelect() will put the proper table name in front in case there is none $query['select'] = $this->_buildSelect(trim($column)); } @@ -362,7 +376,7 @@ } return $this->returnResult($this->execute($this->_buildSelectQuery($query), 'getCol')); } - + /** * get the number of entries * @@ -430,6 +444,16 @@ } /** + * Render the current query and return it as a string. + * + * @return string the current query + */ + function getQueryString() + { + return $this->_buildSelectQuery(); + } + + /** * save data, calls either update or add * if the primaryCol is given in the data this method knows that the * data passed to it are meant to be updated (call 'update'), otherwise it will @@ -671,7 +695,7 @@ $this->_limit = array($from, $count); } } - + /** * gets query limits * @@ -1483,7 +1507,7 @@ // $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); } // replace all 'joinedTable.columnName' by '_joinedTable_columnName' @@ -1696,7 +1720,7 @@ ); return $updateString; } - + /** * * @param string $query @@ -1737,7 +1761,7 @@ /** * Write events to the logfile. * - * It does some additional work, like time measuring etc. to + * It does some additional work, like time measuring etc. to * see some additional info * * @param string $text @@ -1745,11 +1769,11 @@ */ function writeLog($text='START') { -//its still really a quicky.... 'refactor' (nice word) that +//its still really a quicky.... 'refactor' (nice word) that if (!isset($this->options['logfile'])) { return; } - + include_once 'Log.php'; if (!class_exists('Log')) { return; @@ -1773,7 +1797,7 @@ return; } if ($text === 'end query') { - $text .= ' result size: '.((int)$bytesSent-(int)$this->_logData['startBytesSent']).' bytes'; + $text .= ' result size: '.((int)$bytesSent-(int)$this->_logData['startBytesSent']).' bytes'; $endTime = split(" ", microtime()); $endTime = $endTime[1] + $endTime[0]; $text .= ', took: '.(($endTime - $this->_logData['startQueryTime'])).' seconds'; @@ -1784,14 +1808,13 @@ $this->writeLog('query building took: '.(($endTime - $this->_logData['startTime'])).' seconds'); } $this->_logObject->log($text); - + if (strpos($text, 'end query') === 0) { $endTime = split(' ', microtime()); $endTime = $endTime[1] + $endTime[0]; $text = 'time over all: '.(($endTime - $this->_logData['startTime'])).' seconds'; - $this->writeLog($text); - $this->_logObject->writeOut(); - } + $this->_logObject->log($text); + } } /**

« previous php.pear.cvs (#13014) next »