* @copyright 2010-2014 Justin Swanhart and André Rothe * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version SVN: $Id: CheckBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $ * */ require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php'; require_once dirname(__FILE__) . '/ReservedBuilder.php'; require_once dirname(__FILE__) . '/SelectBracketExpressionBuilder.php'; require_once dirname(__FILE__) . '/../utils/ExpressionType.php'; /** * This class implements the builder for the CHECK statement part 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 CheckBuilder { protected function buildSelectBracketExpression($parsed) { $builder = new SelectBracketExpressionBuilder(); return $builder->build($parsed); } protected function buildReserved($parsed) { $builder = new ReservedBuilder(); return $builder->build($parsed); } public function build($parsed) { if ($parsed['expr_type'] !== ExpressionType::CHECK) { return ""; } $sql = ""; foreach ($parsed['sub_tree'] as $k => $v) { $len = strlen($sql); $sql .= $this->buildReserved($v); $sql .= $this->buildSelectBracketExpression($v); if ($len == strlen($sql)) { throw new UnableToCreateSQLException('CREATE TABLE check subtree', $k, $v, 'expr_type'); } $sql .= " "; } return substr($sql, 0, -1); } } ?>