Initial commit

This commit is contained in:
2020-10-07 10:37:15 +02:00
commit ce5f440392
28157 changed files with 4429172 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
<?php
/**
* AliasBuilder.php
*
* Builds aliases.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: AliasBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
/**
* This class implements the builder for aliases.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class AliasBuilder {
public function hasAlias($parsed) {
return isset($parsed['alias']);
}
public function build($parsed) {
if (!isset($parsed['alias']) || $parsed['alias'] === false) {
return "";
}
$sql = "";
if ($parsed['alias']['as']) {
$sql .= " as";
}
$sql .= " " . $parsed['alias']['name'];
return $sql;
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* CharacterSetBuilder.php
*
* Builds the CHARACTER SET part of a CREATE TABLE statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: CharacterSetBuilder.php 914 2014-01-08 11:33:25Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ColumnListBuilder.php';
require_once dirname(__FILE__) . '/ConstraintBuilder.php';
require_once dirname(__FILE__) . '/ReservedBuilder.php';
require_once dirname(__FILE__) . '/IndexTypeBuilder.php';
/**
* This class implements the builder for the CHARACTER SET statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CharacterSetBuilder {
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::CHARSET) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildOperator($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildConstant($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE options CHARACTER SET subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* CheckBuilder.php
*
* Builds the CHECK statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @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 <andre.rothe@phosco.info>
* @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);
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* CollationBuilder.php
*
* Builds the collation expression part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: CollationBuilder.php 922 2014-01-08 12:19:35Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ConstantBuilder.php';
require_once dirname(__FILE__) . '/OperatorBuilder.php';
require_once dirname(__FILE__) . '/ReservedBuilder.php';
/**
* This class implements the builder for the collation statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CollationBuilder {
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::COLLATE) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildOperator($v);
$sql .= $this->buildConstant($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE options collation subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* ColumnDefinitionBuilder.php
*
* Builds the column definition statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ColumnDefinitionBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
require_once dirname(__FILE__) . '/ColumnTypeBuilder.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for the columndefinition statement part
* of CREATE TABLE. You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ColumnDefinitionBuilder {
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildColumnType($parsed) {
$builder = new ColumnTypeBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::COLDEF) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildColumnType($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE primary key subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* ColumnListBuilder.php
*
* Builds column-list parts of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @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 <andre.rothe@phosco.info>
* @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) . ")";
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* ColumnReferenceBuilder.php
*
* Builds Column references.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ColumnReferenceBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/AliasBuilder.php';
require_once dirname(__FILE__) . '/DirectionBuilder.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for column references.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ColumnReferenceBuilder {
protected function buildDirection($parsed) {
$builder = new DirectionBuilder();
return $builder->build($parsed);
}
protected function buildAlias($parsed) {
$builder = new AliasBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::COLREF) {
return "";
}
$sql = $parsed['base_expr'];
$sql .= $this->buildAlias($parsed);
$sql .= $this->buildDirection($parsed);
return $sql;
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* ColumnTypeExpressionBuilder.php
*
* Builds the bracket expressions within a column type.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ColumnTypeBracketExpressionBuilder.php 934 2014-01-08 13:57:16Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/SubTreeBuilder.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for bracket expressions within a column type.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ColumnTypeBracketExpressionBuilder {
protected function buildSubTree($parsed, $delim) {
$builder = new SubTreeBuilder();
return $builder->build($parsed, $delim);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::BRACKET_EXPRESSION) {
return "";
}
$sql = $this->buildSubTree($parsed, ",");
$sql = "(" . $sql . ")";
return $sql;
}
}

View File

@@ -0,0 +1,94 @@
<?php
/**
* ColumnTypeBuilder.php
*
* Builds the column type statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ColumnTypeBuilder.php 935 2014-01-08 13:58:11Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ReservedBuilder.php';
require_once dirname(__FILE__) . '/ColumnTypeBracketExpressionBuilder.php';
require_once dirname(__FILE__) . '/DataTypeBuilder.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for the column type statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ColumnTypeBuilder {
protected function buildColumnTypeBracketExpression($parsed) {
$builder = new ColumnTypeBracketExpressionBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildDataType($parsed) {
$builder = new DataTypeBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::COLUMN_TYPE) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildDataType($v);
$sql .= $this->buildColumnTypeBracketExpression($v);
$sql .= $this->buildReserved($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE column-type subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* ConstantBuilder.php
*
* Builds constant (String, Integer, etc.) parts.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ConstantBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/AliasBuilder.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for constants.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ConstantBuilder {
protected function buildAlias($parsed) {
$builder = new AliasBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::CONSTANT) {
return "";
}
$sql = $parsed['base_expr'];
$sql .= $this->buildAlias($parsed);
return $sql;
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* ConstraintBuilder.php
*
* Builds the constraint statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ConstraintBuilder.php 891 2013-12-31 00:20:19Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/ConstantBuilder.php';
/**
* This class implements the builder for the constraint statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ConstraintBuilder {
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::CONSTRAINT) {
return "";
}
$sql = $this->buildConstant($parsed['sub_tree']);
return "CONSTRAINT" . (empty($sql) ? '' : (' ' . $sql));
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* CreateBuilder.php
*
* Builds the CREATE statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: CreateBuilder.php 833 2013-12-18 10:13:59Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/CreateTableBuilder.php';
require_once dirname(__FILE__) . '/SubTreeBuilder.php';
/**
* This class implements the builder for the [CREATE] part. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateBuilder {
protected function buildCreateTable($parsed) {
$builder = new CreateTableBuilder();
return $builder->build($parsed);
}
protected function buildSubTree($parsed) {
$builder = new SubTreeBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
$create = $parsed['CREATE'];
$sql = $this->buildSubTree($create);
if (($create['expr_type'] === ExpressionType::TABLE)
|| ($create['expr_type'] === ExpressionType::TEMPORARY_TABLE)) {
$sql .= " " . $this->buildCreateTable($parsed['TABLE']);
}
// TODO: add more expr_types here (like VIEW), if available
return "CREATE " . $sql;
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* CreateStatement.php
*
* Builds the CREATE statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: CreateStatementBuilder.php 930 2014-01-08 13:07:55Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/LikeBuilder.php';
require_once dirname(__FILE__) . '/SelectStatementBuilder.php';
require_once dirname(__FILE__) . '/CreateBuilder.php';
/**
* This class implements the builder for the whole Create statement. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateStatementBuilder {
protected function buildLIKE($parsed) {
$builder = new LikeBuilder();
return $builder->build($parsed);
}
protected function buildSelectStatement($parsed) {
$builder = new SelectStatementBuilder();
return $builder->build($parsed);
}
protected function buildCREATE($parsed) {
$builder = new CreateBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
$sql = $this->buildCREATE($parsed);
if (isset($parsed['LIKE'])) {
$sql .= " " . $this->buildLIKE($parsed['LIKE']);
}
if (isset($parsed['SELECT'])) {
$sql .= " " . $this->buildSelectStatement($parsed);
}
return $sql;
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* CreateTable.php
*
* Builds the CREATE TABLE statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: CreateTableBuilder.php 892 2013-12-31 00:21:33Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/CreateTableDefinitionBuilder.php';
require_once dirname(__FILE__) . '/CreateTableSelectOptionBuilder.php';
require_once dirname(__FILE__) . '/CreateTableOptionsBuilder.php';
/**
* This class implements the builder for the CREATE TABLE statement. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateTableBuilder {
protected function buildCreateTableDefinition($parsed) {
$builder = new CreateTableDefinitionBuilder();
return $builder->build($parsed);
}
protected function buildCreateTableOptions($parsed) {
$builder = new CreateTableOptionsBuilder();
return $builder->build($parsed);
}
protected function buildCreateTableSelectOption($parsed) {
$builder = new CreateTableSelectOptionBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
$sql = $parsed['name'];
$sql .= $this->buildCreateTableDefinition($parsed);
$sql .= $this->buildCreateTableOptions($parsed);
$sql .= $this->buildCreateTableSelectOption($parsed);
return $sql;
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* CreateTableDefinitionBuilder.php
*
* Builds the create definitions of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: CreateTableDefinitionBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/TableBracketExpressionBuilder.php';
/**
* This class implements the builder for the create definitions of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateTableDefinitionBuilder {
protected function buildTableBracketExpression($parsed) {
$builder = new TableBracketExpressionBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if (!isset($parsed) || $parsed['create-def'] === false) {
return "";
}
return $this->buildTableBracketExpression($parsed['create-def']);
}
}

View File

@@ -0,0 +1,106 @@
<?php
/**
* CreateTableOptionsBuilder.php
*
* Builds the table-options statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: CreateTableOptionsBuilder.php 923 2014-01-08 12:20:30Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/SelectExpressionBuilder.php';
require_once dirname(__FILE__) . '/CharacterSetBuilder.php';
require_once dirname(__FILE__) . '/CollationBuilder.php';
/**
* This class implements the builder for the table-options statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateTableOptionsBuilder {
protected function buildExpression($parsed) {
$builder = new SelectExpressionBuilder();
return $builder->build($parsed);
}
protected function buildCharacterSet($parsed) {
$builder = new CharacterSetBuilder();
return $builder->build($parsed);
}
protected function buildCollation($parsed) {
$builder = new CollationBuilder();
return $builder->build($parsed);
}
/**
* Returns a well-formatted delimiter string. If you don't need nice SQL,
* you could simply return $parsed['delim'].
*
* @param array $parsed The part of the output array, which contains the current expression.
* @return a string, which is added right after the expression
*/
protected function getDelimiter($parsed) {
return $parsed['delim'] === false ? '' : (trim($parsed['delim']) . ' ');
}
public function build($parsed) {
if (!isset($parsed['options']) || $parsed['options'] === false) {
return "";
}
$options = $parsed['options'];
$sql = "";
foreach ($options as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildExpression($v);
$sql .= $this->buildCharacterSet($v);
$sql .= $this->buildCollation($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE options', $k, $v, 'expr_type');
}
$sql .= $this->getDelimiter($v);
}
return " " . substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* CreateTableSelectOptionBuilder.php
*
* Builds the select-options statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: CreateTableSelectOptionBuilder.php 932 2014-01-08 13:15:26Z phosco@gmx.de $
*
*/
/**
* This class implements the builder for the select-options statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class CreateTableSelectOptionBuilder {
public function build($parsed) {
if (!isset($parsed['select-option']) || $parsed['select-option'] === false) {
return "";
}
$option = $parsed['select-option'];
$sql = ($option['duplicates'] === false ? '' : (' ' . $option['duplicates']));
$sql .= ($option['as'] === false ? '' : ' AS');
return $sql;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* DataTypeBuilder.php
*
* Builds the data-type statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: DataTypeBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for the data-type statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DataTypeBuilder {
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::DATA_TYPE) {
return "";
}
return $parsed['base_expr'];
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* DatabaseBuilder.php
*
* Builds the database within the SHOW statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: DatabaseBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for a database within SHOW statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DatabaseBuilder {
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::DATABASE) {
return "";
}
return $parsed['base_expr'];
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* DeleteBuilder.php
*
* Builds the DELETE statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: DeleteBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
/**
* This class implements the builder for the [DELETE] part. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DeleteBuilder {
public function build($parsed) {
$sql = "DELETE";
foreach ($parsed['TABLES'] as $k => $v) {
$sql .= $v . ",";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* DeleteStatementBuilder.php
*
* Builds the DELETE statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: DeleteStatementBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/WhereBuilder.php';
require_once dirname(__FILE__) . '/FromBuilder.php';
require_once dirname(__FILE__) . '/DeleteBuilder.php';
/**
* This class implements the builder for the whole Delete statement. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DeleteStatementBuilder {
protected function buildWHERE($parsed) {
$builder = new WhereBuilder();
return $builder->build($parsed);
}
protected function buildFROM($parsed) {
$builder = new FromBuilder();
return $builder->build($parsed);
}
protected function buildDELETE($parsed) {
$builder = new DeleteBuilder();
return $builder->build($parsed);
}
public function processDeleteStatement($parsed) {
$sql = $this->buildDELETE($parsed['DELETE']) . " " . $this->processFROM($parsed['FROM']);
if (isset($parsed['WHERE'])) {
$sql .= " " . $this->processWHERE($parsed['WHERE']);
}
return $sql;
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* DirectionBuilder.php
*
* Builds direction (e.g. of the order-by clause).
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: DirectionBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
/**
* This class implements the builder for directions (e.g. of the order-by clause).
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class DirectionBuilder {
public function build($parsed) {
if (!isset($parsed['direction']) || $parsed['direction'] === false) {
return "";
}
return " " . $parsed['direction'];
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* DatabaseBuilder.php
*
* Builds the database within the SHOW statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: EngineBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for a database within SHOW statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class EngineBuilder {
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::ENGINE) {
return "";
}
return $parsed['base_expr'];
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* ForeignKeyBuilder.php
*
* Builds the FOREIGN KEY statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ForeignKeyBuilder.php 927 2014-01-08 13:01:17Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ConstantBuilder.php';
require_once dirname(__FILE__) . '/ReservedBuilder.php';
require_once dirname(__FILE__) . '/ColumnListBuilder.php';
require_once dirname(__FILE__) . '/ForeignRefBuilder.php';
/**
* This class implements the builder for the FOREIGN KEY statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ForeignKeyBuilder {
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildColumnList($parsed) {
$builder = new ColumnListBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildForeignRef($parsed) {
$builder = new ForeignRefBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::FOREIGN_KEY) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildConstant($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildColumnList($v);
$sql .= $this->buildForeignRef($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE foreign key subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* ForeignRefBuilder.php
*
* Builds the FOREIGN KEY REFERENCES statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ForeignRefBuilder.php 927 2014-01-08 13:01:17Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/TableBuilder.php';
require_once dirname(__FILE__) . '/ReservedBuilder.php';
require_once dirname(__FILE__) . '/ColumnListBuilder.php';
/**
* This class implements the builder for the FOREIGN KEY REFERENCES statement
* part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ForeignRefBuilder {
protected function buildTable($parsed) {
$builder = new TableBuilder();
return $builder->build($parsed, 0);
}
protected function buildColumnList($parsed) {
$builder = new ColumnListBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::REFERENCE) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildTable($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildColumnList($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE foreign ref subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* FromBuilder.php
*
* Builds the FROM statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @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 <andre.rothe@phosco.info>
* @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;
}
}

View File

@@ -0,0 +1,139 @@
<?php
/**
* FunctionBuilder.php
*
* Builds function statements.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: FunctionBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/AliasBuilder.php';
require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
require_once dirname(__FILE__) . '/ConstantBuilder.php';
require_once dirname(__FILE__) . '/FunctionBuilder.php';
require_once dirname(__FILE__) . '/ReservedBuilder.php';
require_once dirname(__FILE__) . '/SelectExpressionBuilder.php';
require_once dirname(__FILE__) . '/SelectBracketExpressionBuilder.php';
require_once dirname(__FILE__) . '/DirectionBuilder.php';
/**
* This class implements the builder for function calls.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class FunctionBuilder {
protected function buildDirection($parsed) {
$builder = new DirectionBuilder();
return $builder->build($parsed);
}
protected function buildAlias($parsed) {
$builder = new AliasBuilder();
return $builder->build($parsed);
}
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function isReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->isReserved($parsed);
}
protected function buildSelectExpression($parsed) {
$builder = new SelectExpressionBuilder();
return $builder->build($parsed);
}
protected function buildSelectBracketExpression($parsed) {
$builder = new SelectBracketExpressionBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if (($parsed['expr_type'] !== ExpressionType::AGGREGATE_FUNCTION)
&& ($parsed['expr_type'] !== ExpressionType::SIMPLE_FUNCTION)) {
return "";
}
if ($parsed['sub_tree'] === false) {
return $parsed['base_expr'] . "()";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->build($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildColRef($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildSelectBracketExpression($v);
$sql .= $this->buildSelectExpression($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('function subtree', $k, $v, 'expr_type');
}
$sql .= ($this->isReserved($v) ? " " : ",");
}
return $parsed['base_expr'] . "(" . substr($sql, 0, -1) . ")" . $this->buildAlias($parsed) . $this->buildDirection($parsed);
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* GroupByBuilder.php
*
* Builds the GROUP-BY clause.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: GroupByBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/PositionBuilder.php';
require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
require_once dirname(__FILE__) . '/FunctionBuilder.php';
/**
* This class implements the builder for the GROUP-BY clause.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class GroupByBuilder {
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildPosition($parsed) {
$builder = new PositionBuilder();
return $builder->build($parsed);
}
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
$sql = "";
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildPosition($v);
$sql .= $this->buildFunction($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('GROUP', $k, $v, 'expr_type');
}
$sql .= ", ";
}
$sql = substr($sql, 0, -2);
return "GROUP BY " . $sql;
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* InListBuilder.php
*
* Builds lists of values for the IN statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: InListBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/SubTreeBuilder.php';
/**
* This class implements the builder list of values for the IN statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class InListBuilder {
protected function buildSubTree($parsed, $delim) {
$builder = new SubTreeBuilder();
return $builder->build($parsed, $delim);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::IN_LIST) {
return "";
}
$sql = $this->buildSubTree($parsed, ", ");
return "(" . $sql . ")";
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* IndexColumnBuilder.php
*
* Builds the column entries of the column-list parts of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: IndexColumnBuilder.php 917 2014-01-08 11:47:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnsupportedFeatureException.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for index column entries of the column-list
* parts of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexColumnBuilder {
protected function buildLength($parsed) {
return $parsed === false ? '' : ('(' . $parsed . ')');
}
protected function buildDirection($parsed) {
return $parsed === false ? '' : (' ' . $parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::INDEX_COLUMN) {
return "";
}
$sql = $parsed['name'];
$sql .= $this->buildLength($parsed['length']);
$sql .= $this->buildDirection($parsed['dir']);
return $sql;
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* IndexParserBuilder.php
*
* Builds index parser part of a PRIMARY KEY statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: IndexParserBuilder.php 918 2014-01-08 11:48:30Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ColumnListBuilder.php';
require_once dirname(__FILE__) . '/ConstraintBuilder.php';
require_once dirname(__FILE__) . '/ReservedBuilder.php';
require_once dirname(__FILE__) . '/IndexTypeBuilder.php';
/**
* This class implements the builder for the index parser of a PRIMARY KEY
* statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexParserBuilder {
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::INDEX_PARSER) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildConstant($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE primary key index parser subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* IndexSizeBuilder.php
*
* Builds index size part of a PRIMARY KEY statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: IndexSizeBuilder.php 918 2014-01-08 11:48:30Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ColumnListBuilder.php';
require_once dirname(__FILE__) . '/ConstraintBuilder.php';
require_once dirname(__FILE__) . '/ReservedBuilder.php';
require_once dirname(__FILE__) . '/IndexTypeBuilder.php';
/**
* This class implements the builder for the index size of a PRIMARY KEY
* statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexSizeBuilder {
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::INDEX_SIZE) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildConstant($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE primary key index size subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* IndexTypeBuilder.php
*
* Builds index type part of a PRIMARY KEY statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: IndexTypeBuilder.php 910 2014-01-08 10:46:12Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ColumnListBuilder.php';
require_once dirname(__FILE__) . '/ConstraintBuilder.php';
require_once dirname(__FILE__) . '/ReservedBuilder.php';
require_once dirname(__FILE__) . '/IndexTypeBuilder.php';
/**
* This class implements the builder for the index type of a PRIMARY KEY
* statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class IndexTypeBuilder {
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::INDEX_TYPE) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE primary key index type subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* InsertBuilder.php
*
* Builds the [INSERT] statement part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @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 <andre.rothe@phosco.info>
* @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;
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* InsertStatement.php
*
* Builds the INSERT statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: InsertStatementBuilder.php 834 2013-12-18 10:14:26Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/InsertBuilder.php';
require_once dirname(__FILE__) . '/ValuesBuilder.php';
/**
* This class implements the builder for the whole Insert statement. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class InsertStatementBuilder {
protected function buildVALUES($parsed) {
$builder = new ValuesBuilder();
return $builder->build($parsed);
}
protected function buildINSERT($parsed) {
$builder = new InsertBuilder($parsed);
return $builder->build($parsed);
}
public function build($parsed) {
// TODO: are there more than one tables possible (like [INSERT][1])
return $this->buildINSERT($parsed['INSERT'][0]) . " " . $this->buildVALUES($parsed['VALUES']);
// TODO: subquery?
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* JoinBuilder.php
*
* Builds the JOIN statement parts (within FROM).
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: JoinBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnsupportedFeatureException.php';
/**
* This class implements the builder for the JOIN statement parts (within FROM).
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class JoinBuilder {
public function build($parsed) {
if ($parsed === 'CROSS') {
return ", ";
}
if ($parsed === 'JOIN') {
return " INNER JOIN ";
}
if ($parsed === 'LEFT') {
return " LEFT JOIN ";
}
if ($parsed === 'RIGHT') {
return " RIGHT JOIN ";
}
// TODO: add more
throw new UnsupportedFeatureException($parsed);
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* LikeBuilder.php
*
* Builds the LIKE statement part of a CREATE TABLE statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: LikeBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/TableBuilder.php';
/**
* This class implements the builder for the LIKE statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class LikeBuilder {
protected function buildTable($parsed, $index) {
$builder = new TableBuilder();
return $builder->build($parsed, $index);
}
public function build($parsed) {
$sql = $this->buildTable($parsed, 0);
if (strlen($sql) === 0) {
throw new UnableToCreateSQLException('LIKE', "", $like, 'table');
}
return "LIKE " . $sql;
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* LikeExpressionBuilder.php
*
* Builds the LIKE keyword within parenthesis.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: LikeExpressionBuilder.php 906 2014-01-07 14:38:08Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/TableBuilder.php';
require_once dirname(__FILE__) . '/ReservedBuilder.php';
/**
* This class implements the builder for the (LIKE) keyword within a
* CREATE TABLE statement. There are difference to LIKE (without parenthesis),
* the latter is a top-level element of the output array.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class LikeExpressionBuilder {
protected function buildTable($parsed, $index) {
$builder = new TableBuilder();
return $builder->build($parsed, $index);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::LIKE) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildTable($v, 0);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE create-def (like) subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* LimitBuilder.php
*
* Builds the LIMIT statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: LimitBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
/**
* This class implements the builder LIMIT statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class LimitBuilder {
public function build($parsed) {
$sql = ($parsed['offset'] ? $parsed['offset'] . ", " : "") . $parsed['rowcount'];
if ($sql === "") {
throw new UnableToCreateSQLException('LIMIT', 'rowcount', $parsed, 'rowcount');
}
return "LIMIT " . $sql;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* OperatorBuilder.php
*
* Builds operators.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: OperatorBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for operators.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class OperatorBuilder {
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::OPERATOR) {
return "";
}
return $parsed['base_expr'];
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* OrderByAliasBuilder.php
*
* Builds an alias within an ORDER-BY clause.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: OrderByAliasBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/DirectionBuilder.php';
/**
* This class implements the builder for an alias within the ORDER-BY clause.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class OrderByAliasBuilder {
protected function buildDirection($parsed) {
$builder = new DirectionBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::ALIAS) {
return "";
}
return $parsed['base_expr'] . $this->buildDirection($parsed);
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* OrderByBuilder.php
*
* Builds the ORDERBY clause.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: OrderByBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/OrderByAliasBuilder.php';
require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
/**
* This class implements the builder for the ORDER-BY clause.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class OrderByBuilder {
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildOrderByAlias($parsed) {
$builder = new OrderByAliasBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
$sql = "";
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildOrderByAlias($v);
$sql .= $this->buildColRef($v);
$sql .= $this->buildFunction($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('ORDER', $k, $v, 'expr_type');
}
$sql .= ", ";
}
$sql = substr($sql, 0, -2);
return "ORDER BY " . $sql;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* PositionBuilder.php
*
* Builds positions of the GROUP BY clause.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: PositionBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for positions of the GROUP-BY clause.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class PositionBuilder {
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::POSITION) {
return "";
}
return $parsed['base_expr'];
}
}

View File

@@ -0,0 +1,119 @@
<?php
/**
* PrimaryKeyBuilder.php
*
* Builds the PRIMARY KEY statement part of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: PrimaryKeyBuilder.php 919 2014-01-08 11:49:02Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ColumnListBuilder.php';
require_once dirname(__FILE__) . '/ConstraintBuilder.php';
require_once dirname(__FILE__) . '/ReservedBuilder.php';
require_once dirname(__FILE__) . '/IndexTypeBuilder.php';
require_once dirname(__FILE__) . '/IndexSizeBuilder.php';
require_once dirname(__FILE__) . '/IndexParserBuilder.php';
/**
* This class implements the builder for the PRIMARY KEY statement part of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class PrimaryKeyBuilder {
protected function buildColumnList($parsed) {
$builder = new ColumnListBuilder();
return $builder->build($parsed);
}
protected function buildConstraint($parsed) {
$builder = new ConstraintBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildIndexType($parsed) {
$builder = new IndexTypeBuilder();
return $builder->build($parsed);
}
protected function buildIndexSize($parsed) {
$builder = new IndexSizeBuilder();
return $builder->build($parsed);
}
protected function buildIndexParser($parsed) {
$builder = new IndexParserBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::PRIMARY_KEY) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildConstraint($v);
$sql .= $this->buildReserved($v);
$sql .= $this->buildColumnList($v);
$sql .= $this->buildIndexType($v);
$sql .= $this->buildIndexSize($v);
$sql .= $this->buildIndexParser($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE primary key subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* Procedureuilder.php
*
* Builds the procedures within the SHOW statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ProcedureBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for a procedure within SHOW statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ProcedureBuilder {
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::PROCEDURE) {
return "";
}
return $parsed['base_expr'];
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* RecordBuilder.php
*
* Builds the records within the INSERT statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: RecordBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/OperatorBuilder.php';
require_once dirname(__FILE__) . '/ConstantBuilder.php';
require_once dirname(__FILE__) . '/FunctionBuilder.php';
/**
* This class implements the builder for the records within INSERT statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class RecordBuilder {
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::RECORD) {
return "";
}
$sql = "";
foreach ($parsed['data'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildConstant($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildOperator($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException(ExpressionType::RECORD, $k, $v, 'expr_type');
}
$sql .= ",";
}
$sql = substr($sql, 0, -1);
return "(" . $sql . ")";
}
}

View File

@@ -0,0 +1,94 @@
<?php
/**
* RefClauseBuilder.php
*
* Builds reference clauses within a JOIN.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: RefClauseBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
require_once dirname(__FILE__) . '/OperatorBuilder.php';
require_once dirname(__FILE__) . '/ConstantBuilder.php';
/**
* This class implements the references clause within a JOIN.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class RefClauseBuilder {
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed === false) {
return "";
}
$sql = "";
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildOperator($v);
$sql .= $this->buildConstant($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('expression ref_clause', $k, $v, 'expr_type');
}
$sql .= " ";
}
return "(" . substr($sql, 0, -1) . ")";
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* RefTypeBuilder.php
*
* Builds reference type within a JOIN.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: RefTypeBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnsupportedFeatureException.php';
/**
* This class implements the references type within a JOIN.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class RefTypeBuilder {
public function build($parsed) {
if ($parsed === false) {
return "";
}
if ($parsed === 'ON') {
return " ON ";
}
if ($parsed === 'USING') {
return " USING ";
}
// TODO: add more
throw new UnsupportedFeatureException($parsed);
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* ReservedBuilder.php
*
* Builds reserved keywords.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ReservedBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for reserved keywords.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ReservedBuilder {
public function isReserved($parsed) {
return $parsed['expr_type'] === ExpressionType::RESERVED;
}
public function build($parsed) {
if (!$this->isReserved($parsed)) {
return "";
}
return $parsed['base_expr'];
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* SelectBracketExpressionBuilder.php
*
* Builds the bracket expressions within a SELECT statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: SelectBracketExpressionBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/SubTreeBuilder.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for bracket expressions within a SELECT statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class SelectBracketExpressionBuilder {
protected function buildSubTree($parsed, $delim) {
$builder = new SubTreeBuilder();
return $builder->build($parsed, $delim);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::BRACKET_EXPRESSION) {
return "";
}
$sql = $this->buildSubTree($parsed, " ");
$sql = "(" . $sql . ")";
return $sql;
}
}

View File

@@ -0,0 +1,124 @@
<?php
/**
* SelectBuilder.php
*
* Builds the SELECT statement from the [SELECT] field.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: SelectBuilder.php 903 2014-01-06 11:29:19Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ConstantBuilder.php';
require_once dirname(__FILE__) . '/FunctionBuilder.php';
require_once dirname(__FILE__) . '/SelectExpressionBuilder.php';
require_once dirname(__FILE__) . '/SelectBracketExpressionBuilder.php';
require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
/**
* This class implements the builder for the [SELECT] field. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class SelectBuilder {
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
protected function buildSelectExpression($parsed) {
$builder = new SelectExpressionBuilder();
return $builder->build($parsed);
}
protected function buildSelectBracketExpression($parsed) {
$builder = new SelectBracketExpressionBuilder();
return $builder->build($parsed);
}
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
/**
* Returns a well-formatted delimiter string. If you don't need nice SQL,
* you could simply return $parsed['delim'].
*
* @param array $parsed The part of the output array, which contains the current expression.
* @return a string, which is added right after the expression
*/
protected function getDelimiter($parsed) {
return $parsed['delim'] === false ? '' : (trim($parsed['delim']) . ' ');
}
public function build($parsed) {
$sql = "";
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildSelectBracketExpression($v);
$sql .= $this->buildSelectExpression($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildReserved($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('SELECT', $k, $v, 'expr_type');
}
$sql .= $this->getDelimiter($v);
}
return "SELECT " . $sql;
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* SelectExpressionBuilder.php
*
* Builds simple expressions within a SELECT statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: SelectExpressionBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/SubTreeBuilder.php';
require_once dirname(__FILE__) . '/AliasBuilder.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for simple expressions within a SELECT statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class SelectExpressionBuilder {
protected function buildSubTree($parsed, $delim) {
$builder = new SubTreeBuilder();
return $builder->build($parsed, $delim);
}
protected function buildAlias($parsed) {
$builder = new AliasBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::EXPRESSION) {
return "";
}
$sql = $this->buildSubTree($parsed, " ");
$sql .= $this->buildAlias($parsed);
return $sql;
}
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* SelectStatement.php
*
* Builds the SELECT statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: SelectStatementBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/LimitBuilder.php';
require_once dirname(__FILE__) . '/SelectBuilder.php';
require_once dirname(__FILE__) . '/FromBuilder.php';
require_once dirname(__FILE__) . '/WhereBuilder.php';
require_once dirname(__FILE__) . '/GroupByBuilder.php';
require_once dirname(__FILE__) . '/OrderByBuilder.php';
/**
* This class implements the builder for the whole Select statement. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class SelectStatementBuilder {
protected function buildSELECT($parsed) {
$builder = new SelectBuilder();
return $builder->build($parsed);
}
protected function buildFROM($parsed) {
$builder = new FromBuilder();
return $builder->build($parsed);
}
protected function buildWHERE($parsed) {
$builder = new WhereBuilder();
return $builder->build($parsed);
}
protected function buildGROUP($parsed) {
$builder = new GroupByBuilder();
return $builder->build($parsed);
}
protected function buildORDER($parsed) {
$builder = new OrderByBuilder();
return $builder->build($parsed);
}
protected function buildLIMIT($parsed) {
$builder = new LimitBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
$sql = $this->buildSELECT($parsed['SELECT']);
if (isset($parsed['FROM'])) {
$sql .= " " . $this->buildFROM($parsed['FROM']);
}
if (isset($parsed['WHERE'])) {
$sql .= " " . $this->buildWHERE($parsed['WHERE']);
}
if (isset($parsed['GROUP'])) {
$sql .= " " . $this->buildGROUP($parsed['GROUP']);
}
if (isset($parsed['ORDER'])) {
$sql .= " " . $this->buildORDER($parsed['ORDER']);
}
if (isset($parsed['LIMIT'])) {
$sql .= " " . $this->buildLIMIT($parsed['LIMIT']);
}
return $sql;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* SetBuilder.php
*
* Builds the SET part of the INSERT statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: SetBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/SetExpressionBuilder.php';
/**
* This class implements the builder for the SET part of INSERT statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class SetBuilder {
protected function buildSetExpression($parsed) {
$builder = new SetExpressionBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
$sql = "";
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildSetExpression($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('SET', $k, $v, 'expr_type');
}
$sql .= ",";
}
return "SET " . substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,104 @@
<?php
/**
* SetExpressionBuilder.php
*
* Builds the SET part of the INSERT statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: SetExpressionBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
require_once dirname(__FILE__) . '/ConstantBuilder.php';
require_once dirname(__FILE__) . '/OperatorBuilder.php';
require_once dirname(__FILE__) . '/FunctionBuilder.php';
/**
* This class implements the builder for the SET part of INSERT statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class SetExpressionBuilder {
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::EXPRESSION) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildOperator($v);
$sql .= $this->buildFunction($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('SET expression subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
$sql = substr($sql, 0, -1);
return $sql;
}
}

View File

@@ -0,0 +1,126 @@
<?php
/**
* ShowBuilder.php
*
* Builds the SHOW statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ShowBuilder.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__) . '/ConstantBuilder.php';
require_once dirname(__FILE__) . '/EngineBuilder.php';
require_once dirname(__FILE__) . '/FunctionBuilder.php';
require_once dirname(__FILE__) . '/ProcedureBuilder.php';
require_once dirname(__FILE__) . '/DatabaseBuilder.php';
require_once dirname(__FILE__) . '/TableBuilder.php';
/**
* This class implements the builder for the SHOW statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ShowBuilder {
protected function buildTable($parsed, $delim) {
$builder = new TableBuilder();
return $builder->build($parsed, $delim);
}
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
protected function buildProcedure($parsed) {
$builder = new ProcedureBuilder();
return $builder->build($parsed);
}
protected function buildDatabase($parsed) {
$builder = new DatabaseBuilder();
return $builder->build($parsed);
}
protected function buildEngine($parsed) {
$builder = new EngineBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
$show = $parsed['SHOW'];
$sql = "";
foreach ($show as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildReserved($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildEngine($v);
$sql .= $this->buildDatabase($v);
$sql .= $this->buildProcedure($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildTable($v, 0);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('SHOW', $k, $v, 'expr_type');
}
$sql .= " ";
}
$sql = substr($sql, 0, -1);
return "SHOW " . $sql;
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* ShowStatementBuilder.php
*
* Builds the SHOW statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ShowStatementBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/ShowBuilder.php';
require_once dirname(__FILE__) . '/WhereBuilder.php';
/**
* This class implements the builder for the SHOW statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ShowStatementBuilder {
protected function buildWHERE($parsed) {
$builder = new WhereBuilder();
return $builder->build($parsed);
}
protected function buildSHOW($parsed) {
$builder = new ShowBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
$sql = $this->buildSHOW($parsed);
if (isset($parsed['WHERE'])) {
$sql .= " " . $this->buildWHERE($parsed['WHERE']);
}
return $sql;
}
}

View File

@@ -0,0 +1,105 @@
<?php
/**
* SubQueryBuilder.php
*
* Builds the statements for sub-queries.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: SubQueryBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/RefClauseBuilder.php';
require_once dirname(__FILE__) . '/RefTypeBuilder.php';
require_once dirname(__FILE__) . '/JoinBuilder.php';
require_once dirname(__FILE__) . '/AliasBuilder.php';
require_once dirname(__FILE__) . '/AliasBuilder.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for sub-queries.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class SubQueryBuilder {
protected function buildRefClause($parsed) {
$builder = new RefClauseBuilder();
return $builder->build($parsed);
}
protected function buildRefType($parsed) {
$builder = new RefTypeBuilder();
return $builder->build($parsed);
}
protected function buildJoin($parsed) {
$builder = new JoinBuilder();
return $builder->build($parsed);
}
protected function buildAlias($parsed) {
$builder = new AliasBuilder();
return $builder->build($parsed);
}
protected function buildSelectStatement($parsed) {
$builder = new SelectStatementBuilder();
return $builder->build($parsed);
}
public function build($parsed, $index = 0) {
if ($parsed['expr_type'] !== ExpressionType::SUBQUERY) {
return "";
}
$sql = $this->buildSelectStatement($parsed['sub_tree']);
$sql = "(" . $sql . ")";
$sql .= $this->buildAlias($parsed);
if ($index !== 0) {
$sql = $this->buildJoin($parsed['join_type']) . $sql;
$sql .= $this - buildRefType($parsed['ref_type']);
$sql .= $this->buildRefClause($parsed['ref_clause']);
}
return $sql;
}
}

View File

@@ -0,0 +1,127 @@
<?php
/**
* SubTreeBuilder.php
*
* Builds the statements for [sub_tree] fields.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: SubTreeBuilder.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__) . '/ColumnReferenceBuilder.php';
require_once dirname(__FILE__) . '/FunctionBuilder.php';
require_once dirname(__FILE__) . '/OperatorBuilder.php';
require_once dirname(__FILE__) . '/ConstantBuilder.php';
require_once dirname(__FILE__) . '/SubQueryBuilder.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for [sub_tree] fields.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class SubTreeBuilder {
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildReserved($parsed) {
$builder = new ReservedBuilder();
return $builder->build($parsed);
}
protected function buildSubQuery($parsed) {
$builder = new SubQueryBuilder();
return $builder->build($parsed);
}
protected function buildSelectBracketExpression($parsed) {
$builder = new SelectBracketExpressionBuilder();
return $builder->build($parsed);
}
public function build($parsed, $delim = " ") {
if ($parsed['sub_tree'] === '') {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildOperator($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildSubQuery($v);
$sql .= $this->buildSelectBracketExpression($v);
$sql .= $this->buildReserved($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('expression subtree', $k, $v, 'expr_type');
}
$sql .= $delim;
}
return substr($sql, 0, -strlen($delim));
}
}

View File

@@ -0,0 +1,113 @@
<?php
/**
* TableBracketExpressionBuilder.php
*
* Builds the table expressions within the create definitions of CREATE TABLE.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: TableBracketExpressionBuilder.php 928 2014-01-08 13:01:57Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ColumnDefinitionBuilder.php';
require_once dirname(__FILE__) . '/PrimaryKeyBuilder.php';
require_once dirname(__FILE__) . '/ForeignKeyBuilder.php';
require_once dirname(__FILE__) . '/CheckBuilder.php';
require_once dirname(__FILE__) . '/LikeExpressionBuilder.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for the table expressions
* within the create definitions of CREATE TABLE.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class TableBracketExpressionBuilder {
protected function buildColDef($parsed) {
$builder = new ColumnDefinitionBuilder();
return $builder->build($parsed);
}
protected function buildPrimaryKey($parsed) {
$builder = new PrimaryKeyBuilder();
return $builder->build($parsed);
}
protected function buildForeignKey($parsed) {
$builder = new ForeignKeyBuilder();
return $builder->build($parsed);
}
protected function buildCheck($parsed) {
$builder = new CheckBuilder();
return $builder->build($parsed);
}
protected function buildLikeExpression($parsed) {
$builder = new LikeExpressionBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::BRACKET_EXPRESSION) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColDef($v);
$sql .= $this->buildPrimaryKey($v);
$sql .= $this->buildCheck($v);
$sql .= $this->buildLikeExpression($v);
$sql .= $this->buildForeignKey($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE create-def expression subtree', $k, $v, 'expr_type');
}
$sql .= ", ";
}
$sql = " (" . substr($sql, 0, -2) . ")";
return $sql;
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* TableBuilder.php
*
* Builds the table name/join options.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: TableBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/AliasBuilder.php';
require_once dirname(__FILE__) . '/JoinBuilder.php';
require_once dirname(__FILE__) . '/RefTypeBuilder.php';
require_once dirname(__FILE__) . '/RefClauseBuilder.php';
/**
* This class implements the builder for the table name and join options.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class TableBuilder {
protected function buildAlias($parsed) {
$builder = new AliasBuilder();
return $builder->build($parsed);
}
protected function buildJoin($parsed) {
$builder = new JoinBuilder();
return $builder->build($parsed);
}
protected function buildRefType($parsed) {
$builder = new RefTypeBuilder();
return $builder->build($parsed);
}
protected function buildRefClause($parsed) {
$builder = new RefClauseBuilder();
return $builder->build($parsed);
}
public function build($parsed, $index) {
if ($parsed['expr_type'] !== ExpressionType::TABLE) {
return "";
}
$sql = $parsed['table'];
$sql .= $this->buildAlias($parsed);
if ($index !== 0) {
$sql = $this->buildJoin($parsed['join_type']) . $sql;
$sql .= $this->buildRefType($parsed['ref_type']);
$sql .= $this->buildRefClause($parsed['ref_clause']);
}
return $sql;
}
}

View File

@@ -0,0 +1,104 @@
<?php
/**
* TableExpressionBuilder.php
*
* Builds the table name/join options.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: TableExpressionBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/AliasBuilder.php';
require_once dirname(__FILE__) . '/JoinBuilder.php';
require_once dirname(__FILE__) . '/RefTypeBuilder.php';
require_once dirname(__FILE__) . '/RefClauseBuilder.php';
require_once dirname(__FILE__) . '/FromBuilder.php';
/**
* This class implements the builder for the table name and join options.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class TableExpressionBuilder {
protected function buildFROM($parsed) {
$builder = new FromBuilder();
return $builder->build($parsed);
}
protected function buildAlias($parsed) {
$builder = new AliasBuilder();
return $builder->build($parsed);
}
protected function buildJoin($parsed) {
$builder = new JoinBuilder();
return $builder->build($parsed);
}
protected function buildRefType($parsed) {
$builder = new RefTypeBuilder();
return $builder->build($parsed);
}
protected function buildRefClause($parsed) {
$builder = new RefClauseBuilder();
return $builder->build($parsed);
}
public function build($parsed, $index) {
if ($parsed['expr_type'] !== ExpressionType::TABLE_EXPRESSION) {
return "";
}
$sql = substr($this->buildFROM($parsed['sub_tree']), 5); // remove FROM keyword
$sql = "(" . $sql . ")";
$sql .= $this->buildAlias($parsed);
if ($index !== 0) {
$sql = $this->buildJoin($parsed['join_type']) . $sql;
$sql .= $this->buildRefType($parsed['ref_type']);
$sql .= $this->buildRefClause($parsed['ref_clause']);
}
return $sql;
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* UpdateBuilder.php
*
* Builds the UPDATE statement parts.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: UpdateBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
/**
* This class implements the builder for the UPDATE statement parts.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class UpdateBuilder {
public function build($parsed) {
return "UPDATE " . $parsed[0]['table'];
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* UpdateStatement.php
*
* Builds the UPDATE statement
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: UpdateStatementBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/WhereBuilder.php';
require_once dirname(__FILE__) . '/SetBuilder.php';
require_once dirname(__FILE__) . '/UpdateBuilder.php';
/**
* This class implements the builder for the whole Update statement. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class UpdateStatementBuilder {
protected function buildWHERE($parsed) {
$builder = new WhereBuilder();
return $builder->build($parsed);
}
protected function buildSET($parsed) {
$builder = new SetBuilder();
return $builder->build($parsed);
}
protected function buildUPDATE($parsed) {
$builder = new UpdateBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
$sql = $this->buildUPDATE($parsed['UPDATE']) . " " . $this->buildSET($parsed['SET']);
if (isset($parsed['WHERE'])) {
$sql .= " " . $this->buildWHERE($parsed['WHERE']);
}
return $sql;
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* UserVariableBuilder.php
*
* Builds an user variable.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: UserVariableBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
* This class implements the builder for an user variable.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class UserVariableBuilder {
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::USER_VARIABLE) {
return "";
}
return $parsed['base_expr'];
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* ValuesBuilder.php
*
* Builds the VALUES part of the INSERT statement.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: ValuesBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/RecordBuilder.php';
/**
* This class implements the builder for the VALUES part of INSERT statement.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class ValuesBuilder {
protected function buildRecord($parsed) {
$builder = new RecordBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
$sql = "";
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildRecord($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('VALUES', $k, $v, 'expr_type');
}
$sql .= ",";
}
$sql = substr($sql, 0, -1);
return "VALUES " . $sql;
}
}

View File

@@ -0,0 +1,131 @@
<?php
/**
* WhereBracketExpressionBuilder.php
*
* Builds bracket expressions within the WHERE part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: WhereBracketExpressionBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
require_once dirname(__FILE__) . '/ConstantBuilder.php';
require_once dirname(__FILE__) . '/OperatorBuilder.php';
require_once dirname(__FILE__) . '/FunctionBuilder.php';
require_once dirname(__FILE__) . '/InListBuilder.php';
require_once dirname(__FILE__) . '/WhereExpressionBuilder.php';
require_once dirname(__FILE__) . '/WhereBracketExpressionBuilder.php';
require_once dirname(__FILE__) . '/UserVariableBuilder.php';
/**
* This class implements the builder for bracket expressions within the WHERE part.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class WhereBracketExpressionBuilder {
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
protected function buildInList($parsed) {
$builder = new InListBuilder();
return $builder->build($parsed);
}
protected function buildWhereExpression($parsed) {
$builder = new WhereExpressionBuilder();
return $builder->build($parsed);
}
protected function buildUserVariable($parsed) {
$builder = new UserVariableBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::BRACKET_EXPRESSION) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildOperator($v);
$sql .= $this->buildInList($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildWhereExpression($v);
$sql .= $this->build($v);
$sql .= $this->buildUserVariable($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('WHERE expression subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
$sql = "(" . substr($sql, 0, -1) . ")";
return $sql;
}
}

View File

@@ -0,0 +1,141 @@
<?php
/**
* WhereBuilder.php
*
* Builds the WHERE part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: WhereBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
require_once dirname(__FILE__) . '/ConstantBuilder.php';
require_once dirname(__FILE__) . '/OperatorBuilder.php';
require_once dirname(__FILE__) . '/FunctionBuilder.php';
require_once dirname(__FILE__) . '/InListBuilder.php';
require_once dirname(__FILE__) . '/WhereExpressionBuilder.php';
require_once dirname(__FILE__) . '/WhereBracketExpressionBuilder.php';
require_once dirname(__FILE__) . '/UserVariableBuilder.php';
require_once dirname(__FILE__) . '/SubQueryBuilder.php';
/**
* This class implements the builder for the WHERE part.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class WhereBuilder {
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
protected function buildSubQuery($parsed) {
$builder = new SubQueryBuilder();
return $builder->build($parsed);
}
protected function buildInList($parsed) {
$builder = new InListBuilder();
return $builder->build($parsed);
}
protected function buildWhereExpression($parsed) {
$builder = new WhereExpressionBuilder();
return $builder->build($parsed);
}
protected function buildWhereBracketExpression($parsed) {
$builder = new WhereBracketExpressionBuilder();
return $builder->build($parsed);
}
protected function buildUserVariable($parsed) {
$builder = new UserVariableBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
$sql = "WHERE ";
foreach ($parsed as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildOperator($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildColRef($v);
$sql .= $this->buildSubQuery($v);
$sql .= $this->buildInList($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildWhereExpression($v);
$sql .= $this->buildWhereBracketExpression($v);
$sql .= $this->buildUserVariable($v);
if (strlen($sql) == $len) {
throw new UnableToCreateSQLException('WHERE', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}

View File

@@ -0,0 +1,137 @@
<?php
/**
* WhereExpressionBuilder.php
*
* Builds expressions within the WHERE part.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: WhereExpressionBuilder.php 830 2013-12-18 09:35:42Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
require_once dirname(__FILE__) . '/ConstantBuilder.php';
require_once dirname(__FILE__) . '/OperatorBuilder.php';
require_once dirname(__FILE__) . '/FunctionBuilder.php';
require_once dirname(__FILE__) . '/InListBuilder.php';
require_once dirname(__FILE__) . '/WhereExpressionBuilder.php';
require_once dirname(__FILE__) . '/WhereBracketExpressionBuilder.php';
require_once dirname(__FILE__) . '/UserVariableBuilder.php';
/**
* This class implements the builder for expressions within the WHERE part.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class WhereExpressionBuilder {
protected function buildColRef($parsed) {
$builder = new ColumnReferenceBuilder();
return $builder->build($parsed);
}
protected function buildConstant($parsed) {
$builder = new ConstantBuilder();
return $builder->build($parsed);
}
protected function buildOperator($parsed) {
$builder = new OperatorBuilder();
return $builder->build($parsed);
}
protected function buildFunction($parsed) {
$builder = new FunctionBuilder();
return $builder->build($parsed);
}
protected function buildInList($parsed) {
$builder = new InListBuilder();
return $builder->build($parsed);
}
protected function buildWhereExpression($parsed) {
$builder = new static();
return $builder->build($parsed);
}
protected function buildWhereBracketExpression($parsed) {
$builder = new WhereBracketExpressionBuilder();
return $builder->build($parsed);
}
protected function buildUserVariable($parsed) {
$builder = new UserVariableBuilder();
return $builder->build($parsed);
}
public function build($parsed) {
if ($parsed['expr_type'] !== ExpressionType::EXPRESSION) {
return "";
}
$sql = "";
foreach ($parsed['sub_tree'] as $k => $v) {
$len = strlen($sql);
$sql .= $this->buildColRef($v);
$sql .= $this->buildConstant($v);
$sql .= $this->buildOperator($v);
$sql .= $this->buildInList($v);
$sql .= $this->buildFunction($v);
$sql .= $this->buildWhereExpression($v);
$sql .= $this->buildWhereBracketExpression($v);
$sql .= $this->buildUserVariable($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('WHERE expression subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
$sql = substr($sql, 0, -1);
return $sql;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;