cvs: pear /DB_DataObject DataObject.php

From: Date: Sat, 12 Mar 2005 03:12:01 +0000
Subject: cvs: pear /DB_DataObject DataObject.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-30228@lists.php.net to get a copy of this message
alan_k Fri Mar 11 22:12:01 2005 EDT Modified files: /pear/DB_DataObject DataObject.php Log: fix bug/feature #3783 allow distinct as the argument to count to prefix table key. http://cvs.php.net/diff.php/pear/DB_DataObject/DataObject.php?r1=1.333&r2=1.334&ty=u Index: pear/DB_DataObject/DataObject.php diff -u pear/DB_DataObject/DataObject.php:1.333 pear/DB_DataObject/DataObject.php:1.334 --- pear/DB_DataObject/DataObject.php:1.333 Sun Mar 6 23:58:45 2005 +++ pear/DB_DataObject/DataObject.php Fri Mar 11 22:12:00 2005 @@ -20,7 +20,7 @@ * @package DB_DataObject * @category DB * - * $Id: DataObject.php,v 1.333 2005/03/07 04:58:45 alan_k Exp $ + * $Id: DataObject.php,v 1.334 2005/03/12 03:12:00 alan_k Exp $ */ /* =========================================================================== @@ -1373,15 +1373,18 @@ * $object->name = "fred"; * echo $object->count(); * echo $object->count(true); // dont use object vars. - * echo $object->count('distinct mycol'); + * echo $object->count('distinct mycol'); count distinct mycol. * echo $object->count('distinct mycol',true); // dont use object vars. + * echo $object->count('distinct'); // count distinct id (eg. the primary key) * * * @param bool|string (optional) - * (true|false = see below not on whereAddonly) + * (true|false => see below not on whereAddonly) * (string) - * $countWhat (optional) normally it counts primary keys - you can use - * this to do things like $do->count('distinct mycol'); + * "DISTINCT" => does a distinct count on the tables 'key' column + * otherwise => normally it counts primary keys - you can use + * this to do things like $do->count('distinct mycol'); + * * @param bool $whereAddOnly (optional) If DB_DATAOBJECT_WHEREADD_ONLY is passed in then * we will build the condition only using the whereAdd's. Default is to * build the condition using the object parameters as well. @@ -1431,6 +1434,10 @@ $as = ($quoteIdentifiers ? $DB->quoteIdentifier('DATAOBJECT_NUM') : 'DATAOBJECT_NUM'); + // support distinct on default keys. + $countWhat = (false !== strcmp($countWhat,'DISTINCT')) ? + "DISTINCT {$table}.{$key_col}" : $countWhat; + $countWhat = is_string($countWhat) ? $countWhat : "{$table}.{$key_col}"; $r = $t->_query( @@ -2833,19 +2840,18 @@ $quoteIdentifiers = !empty($_DB_DATAOBJECT['CONFIG']['quote_identifiers']); - $database_prefix = in_array($DB->dsn["phptype"],array('mysql','mysqli')) ? + $database_prefix = in_array($DB->type,array('mysql','mysqli')) ? $obj->_database . '.' : ''; // not sure how portable adding database prefixes is.. $objTable = $quoteIdentifiers ? $DB->quoteIdentifier($database_prefix . '.' . $obj->__table) : - $database_prefix . $obj->__table ; + $database_prefix . '.' . $obj->__table ; // add database prefix if they are different databases if ($database_prefix && ($obj->_database != $this->_database) && strlen($obj->_database )) { // ojbjTable is already quoted???? - $objTable = ($quoteIdentifiers ? - $DB->quoteIdentifier($obj->_database) : $obj->_database) . '.' . $objTable; + $objTable = ($quoteIdentifiers ? $DB->quoteIdentifier($obj->_database) : $obj->_database) . '.' . $objTable; }

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