*** Select.php.orig 2009-02-26 11:45:48.000000000 -0600 --- Select.php 2009-02-26 12:24:22.000000000 -0600 *************** *** 181,186 **** --- 181,224 ---- } /** + * Specifies the columns used in the FROM clause. + * + * The parameter can be a single string or Zend_Db_Expr object, + * or else an array of strings or Zend_Db_Expr objects. + * + * Only columns from the primary table will be used! + * + * @param array|string|Zend_Db_Expr $cols The columns to select from this table. + * @param string $correlationName Correlation name of target table. OPTIONAL + * @return Zend_Db_Table_Select This Zend_Db_Table_Select object. + */ + public function columns($cols = '*', $correlationName = null) + { + // Default to columns from the primary table + if (is_null($correlationName)) { + $correlationName = $this->_info[Zend_Db_Table_Abstract::NAME]; + } + + // If we are doing integrity checks, throw an error when a field from a different table is requested + if ($this->_integrityCheck !== false and $correlationName != $this->_info[Zend_Db_Table_Abstract::NAME]) { + /** + * @see Zend_Db_Select_Exception + */ + require_once 'Zend/Db/Select/Exception.php'; + throw new Zend_Db_Select_Exception("Only columns from the primary table may be selected"); + } + + if (!array_key_exists($correlationName, $this->_parts[self::FROM])) { + $schema = $this->_info[Zend_Db_Table_Abstract::SCHEMA]; + $this->from($correlationName, $cols, $schema); + } else { + $this->_tableCols($correlationName, $cols); + } + + return $this; + } + + /** * Performs a validation on the select query before passing back to the parent class. * Ensures that only columns from the primary Zend_Db_Table are returned in the result. * *************** *** 190,200 **** { $fields = $this->getPart(Zend_Db_Table_Select::COLUMNS); $primary = $this->_info[Zend_Db_Table_Abstract::NAME]; - $schema = $this->_info[Zend_Db_Table_Abstract::SCHEMA]; // If no fields are specified we assume all fields from primary table if (!count($fields)) { ! $this->from($primary, self::SQL_WILDCARD, $schema); $fields = $this->getPart(Zend_Db_Table_Select::COLUMNS); } --- 228,238 ---- { $fields = $this->getPart(Zend_Db_Table_Select::COLUMNS); $primary = $this->_info[Zend_Db_Table_Abstract::NAME]; // If no fields are specified we assume all fields from primary table if (!count($fields)) { ! // include all columns from primary table ! $this->columns(); $fields = $this->getPart(Zend_Db_Table_Select::COLUMNS); }