* @copyright 2010-2014 Justin Swanhart and André Rothe * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version SVN: $Id: ColumnListBuilder.php 894 2013-12-31 00:27:03Z phosco@gmx.de $ * */ require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php'; require_once dirname(__FILE__) . '/IndexColumnBuilder.php'; require_once dirname(__FILE__) . '/../utils/ExpressionType.php'; /** * This class implements the builder for column-list parts of CREATE TABLE. * 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 ColumnListBuilder { protected function buildIndexColumn($parsed) { $builder = new IndexColumnBuilder(); return $builder->build($parsed); } public function build($parsed) { if ($parsed['expr_type'] !== ExpressionType::COLUMN_LIST) { return ""; } $sql = ""; foreach ($parsed['sub_tree'] as $k => $v) { $len = strlen($sql); $sql .= $this->buildIndexColumn($v); if ($len == strlen($sql)) { throw new UnableToCreateSQLException('CREATE TABLE column-list subtree', $k, $v, 'expr_type'); } $sql .= " "; } return "(" . substr($sql, 0, -1) . ")"; } } ?>