* @copyright 2010-2014 Justin Swanhart and André Rothe * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version SVN: $Id: FromBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $ * */ require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php'; require_once dirname(__FILE__) . '/TableBuilder.php'; require_once dirname(__FILE__) . '/TableExpressionBuilder.php'; require_once dirname(__FILE__) . '/SubQueryBuilder.php'; /** * This class implements the builder for the [FROM] part. You can overwrite * all functions to achieve another handling. * * @author André Rothe * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * */ class FromBuilder { protected function buildTable($parsed, $key) { $builder = new TableBuilder(); return $builder->build($parsed, $key); } protected function buildTableExpression($parsed, $key) { $builder = new TableExpressionBuilder(); return $builder->build($parsed, $key); } protected function buildSubQuery($parsed, $key) { $builder = new SubQueryBuilder(); return $builder->build($parsed, $key); } public function build($parsed) { $sql = ""; foreach ($parsed as $k => $v) { $len = strlen($sql); $sql .= $this->buildTable($v, $k); $sql .= $this->buildTableExpression($v, $k); $sql .= $this->buildSubquery($v, $k); if ($len == strlen($sql)) { throw new UnableToCreateSQLException('FROM', $k, $v, 'expr_type'); } } return "FROM " . $sql; } } ?>