<?php

require_once 'orm/OrmSql.php';

/**
 * Update SQL class.
 * 
 * This class holds a 'update' Sql query.
 * 
 * @author  $Author: pruna $
 * @package orm/sql
 * @version $Revision: 1.3 $
 * @created 02-Apr-2005
 * @modified $Date: 2005/12/06 02:56:45 $
 */
class OrmSqlUpdate extends OrmSql {
    
    /**
     * Constructor that defines basic properties for this Bean.
     * 
     * It follows Collection rules for constructor.
     * Basic elements are: 
     * <ul>
     * <li>columns: array of columns (array)</li>
     * <li>where: array of conditions (array)</li>
     * </ul>
     * Default values may serve as guide for preferred data types.
     * For a full description about this elements, see @docs
     * 
     * @access  public
     * @param   ICollection    $collection    Initial elements
     */
    public function __construct($collection = null) {
        parent::__construct(array(
            'columns' => array(),
            'where' => array(),
        ));
        $this->setAll($collection);
    }
    
    /**
     * Returns a SQL query string representation of this object.
     *
     * @access    public
     * @return    string
     */
    public function __toString() {
        return 'UPDATE ' . implode(', ', $this->getTable()) 
           . ' SET ' . implode(', ', $this->getColumns()) 
           . ($this->getWhere() ? ' WHERE ' 
           . implode(' AND ', $this->getWhere()) : '');
    }
    
}

?>