<?php

class SQLDataSource extends DataSource {



	protected $adapter;
	protected $sql;



	public function __construct($id, $sql, DBAdapter $adapter = null) {
		parent::__construct($id);
		$this->sql = $sql;
		if ($adapter) {
			$this->adapter = $adapter;
		} else {
			$this->adapter = DBFactory::getAdapter();
		}
	}



    public function fetch() {
		$this->adapter->execute($this->getSQL());
		return $this->adapter->getIterator();
	}



	public function getSQL() {
		$dialect = $this->adapter->getDialect();
		return $dialect->getSQL($this->sql, $this->getOrder(), $this->isDescending(), $this->getOffset(), $this->getLimit());
	}



} // class SQLDataSource

?>