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