* @copyright 2010-2014 Justin Swanhart and André Rothe * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version SVN: $Id$ * */ namespace PHPSQLParser\builders; use PHPSQLParser\exceptions\UnableToCreateSQLException; use PHPSQLParser\utils\ExpressionType; /** * This class implements the builder for column-list parts of INSERT statements. * 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 InsertColumnListBuilder implements Builder { protected function buildColumn($parsed) { $builder = new ColumnReferenceBuilder(); return $builder->build($parsed); } public function build(array $parsed) { if ($parsed['expr_type'] !== ExpressionType::COLUMN_LIST) { return ""; } $sql = ""; foreach ($parsed['sub_tree'] as $k => $v) { $len = strlen($sql); $sql .= $this->buildColumn($v); if ($len == strlen($sql)) { throw new UnableToCreateSQLException('INSERT column-list subtree', $k, $v, 'expr_type'); } $sql .= ", "; } return "(" . substr($sql, 0, -2) . ")"; } } ?>