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

9
tools/.htaccess Executable file
View File

@@ -0,0 +1,9 @@
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ ../index.php [NC,L]
</IfModule>

35
tools/index.php Normal file
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;

View File

@@ -0,0 +1,10 @@
# Apache 2.2
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
# Apache 2.4
<IfModule mod_authz_core.c>
Require all denied
</IfModule>

49
tools/parser_sql/LICENSE Normal file
View File

@@ -0,0 +1,49 @@
Copyright (c) 2010-2014 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.
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.

View File

@@ -0,0 +1,143 @@
<?php
/**
* PHPSQLCreator.php
*
* A creator, which generates SQL from the output of PHPSQLParser.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 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 André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id: PHPSQLCreator.php 790 2013-12-17 12:16:48Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/exceptions/UnsupportedFeatureException.php';
require_once dirname(__FILE__) . '/builders/SelectStatementBuilder.php';
require_once dirname(__FILE__) . '/builders/DeleteStatementBuilder.php';
require_once dirname(__FILE__) . '/builders/UpdateStatementBuilder.php';
require_once dirname(__FILE__) . '/builders/InsertStatementBuilder.php';
require_once dirname(__FILE__) . '/builders/CreateStatementBuilder.php';
require_once dirname(__FILE__) . '/builders/ShowStatementBuilder.php';
/**
* This class generates SQL from the output of the PHPSQLParser.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class PHPSQLCreator {
public function __construct($parsed = false) {
if ($parsed) {
$this->create($parsed);
}
}
public function create($parsed) {
$k = key($parsed);
switch ($k) {
case "UNION":
case "UNION ALL":
throw new UnsupportedFeatureException($k);
break;
case "SELECT":
$builder = new SelectStatementBuilder($parsed);
$this->created = $builder->build($parsed);
break;
case "INSERT":
$builder = new InsertStatementBuilder($parsed);
$this->created = $builder->build($parsed);
break;
case "DELETE":
$builder = new DeleteStatementBuilder($parsed);
$this->created = $builder->build($parsed);
break;
case "UPDATE":
$builder = new UpdateStatementBuilder($parsed);
$this->created = $builder->build($parsed);
break;
case "RENAME":
$this->created = $this->processRenameTableStatement($parsed);
break;
case "SHOW":
$builder = new ShowStatementBuilder($parsed);
$this->created = $builder->build($parsed);
break;
case "CREATE":
$builder = new CreateStatementBuilder($parsed);
$this->created = $builder->build($parsed);
break;
default:
throw new UnsupportedFeatureException($k);
break;
}
return $this->created;
}
// TODO: we should change that, there are multiple "rename objects" as
// table, user, database
protected function processRenameTableStatement($parsed) {
$rename = $parsed['RENAME'];
$sql = "";
foreach ($rename as $k => $v) {
$len = strlen($sql);
$sql .= $this->processSourceAndDestTable($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('RENAME', $k, $v, 'expr_type');
}
$sql .= ",";
}
$sql = substr($sql, 0, -1);
return "RENAME TABLE " . $sql;
}
protected function processSourceAndDestTable($v) {
if (!isset($v['source']) || !isset($v['destination'])) {
return "";
}
return $v['source']['base_expr'] . " TO " . $v['destination']['base_expr'];
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* php-sql-parser.php
*
* A pure PHP SQL (non validating) parser w/ focus on MySQL dialect of SQL
*
* 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: PHPSQLParser.php 757 2013-12-16 09:54:05Z phosco@gmx.de $
*/
require_once dirname(__FILE__) . '/positions/PositionCalculator.php';
require_once dirname(__FILE__) . '/processors/DefaultProcessor.php';
/**
* This class implements the parser functionality.
*
* @author Justin Swanhart <greenlion@gmail.com>
* @author André Rothe <arothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*/
class PHPSQLParser {
public $parsed;
/**
* Constructor. It simply calls the parse() function.
* Use the public variable $parsed to get the output.
*
* @param String $sql The SQL statement.
* @param boolean $calcPositions True, if the output should contain [position], false otherwise.
*/
public function __construct($sql = false, $calcPositions = false) {
if ($sql) {
$this->parse($sql, $calcPositions);
}
}
/**
* It parses the given SQL statement and generates a detailled
* output array for every part of the statement. The method can
* also generate [position] fields within the output, which hold
* the character position for every statement part. The calculation
* of the positions needs some time, if you don't need positions in
* your application, set the parameter to false.
*
* @param String $sql The SQL statement.
* @param boolean $calcPositions True, if the output should contain [position], false otherwise.
*
* @return array An associative array with all meta information about the SQL statement.
*/
public function parse($sql, $calcPositions = false) {
$processor = new DefaultProcessor();
$queries = $processor->process($sql);
// calc the positions of some important tokens
if ($calcPositions) {
$calculator = new PositionCalculator();
$queries = $calculator->setPositionsWithinSQL($sql, $queries);
}
// store the parsed queries
$this->parsed = $queries;
return $this->parsed;
}
}

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;

View File

@@ -0,0 +1,52 @@
<?php
/**
* InvalidParameterException.php
*
* This file implements the InvalidParameterException class which is used within the
* PHPSQLParser package.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
/**
* This exception will occur in the parser, if the given SQL statement
* is not a String type.
*
* @author arothe
*
*/
class InvalidParameterException extends InvalidArgumentException {
protected $argument;
public function __construct($argument) {
$this->argument = $argument;
parent::__construct("no SQL string to parse: \n" . $argument, 10);
}
public function getArgument() {
return $this->argument;
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* UnableToCalculatePositionException.php
*
* This file implements the UnableToCalculatePositionException class which is used within the
* PHPSQLParser package.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
/**
* This exception will occur, if the PositionCalculator can not find the token
* defined by a base_expr field within the original SQL statement. Please create
* an issue in such a case, it is an application error.
*
* @author arothe
*
*/
class UnableToCalculatePositionException extends Exception {
protected $needle;
protected $haystack;
public function __construct($needle, $haystack) {
$this->needle = $needle;
$this->haystack = $haystack;
parent::__construct("cannot calculate position of " . $needle . " within " . $haystack, 5);
}
public function getNeedle() {
return $this->needle;
}
public function getHaystack() {
return $this->haystack;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* UnableToCreateSQLException.php
*
* This file implements the UnableToCreateSQLException class which is used within the
* PHPSQLParser package.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
/**
* This exception will occur within the PHPSQLCreator, if the creator can not find a
* method, which can handle the current expr_type field. It could be an error within the parser
* output or a special case has not been modelled within the creator. Please create an issue
* in such a case.
*
* @author arothe
*
*/
class UnableToCreateSQLException extends Exception {
protected $part;
protected $partkey;
protected $entry;
protected $entrykey;
public function __construct($part, $partkey, $entry, $entrykey) {
$this->part = $part;
$this->partkey = $partkey;
$this->entry = $entry;
$this->entrykey = $entrykey;
parent::__construct("unknown [" . $entrykey . "] = " .$entry[$entrykey] . " in \"" . $part . "\" [" . $partkey . "] ", 15);
}
public function getEntry() {
return $this->entry;
}
public function getEntryKey() {
return $this->entrykey;
}
public function getSQLPart() {
return $this->part;
}
public function getSQLPartKey() {
return $this->partkey;
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* UnsupportedFeatureException.php
*
* This file implements the UnsupportedFeatureException class which is used within the
* PHPSQLParser package.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
/**
* This exception will occur in the PHPSQLCreator, if the creator finds
* a field name, which is unknown. The developers have created some
* additional output of the parser, but the creator class has not been
* enhanced. Please open an issue in such a case.
*
* @author arothe
*
*/
class UnsupportedFeatureException extends Exception {
protected $key;
public function __construct($key) {
$this->key = $key;
parent::__construct($key . " not implemented.", 20);
}
public function getKey() {
return $this->key;
}
}

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;

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;

View File

@@ -0,0 +1,93 @@
<?php
/**
* LexerSplitter.php
*
* Defines the characters, which are used to split the given SQL string.
* Part of PHPSQLParser.
*
* 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: LexerSplitter.php 842 2013-12-30 08:57:53Z phosco@gmx.de $
*
*/
/**
* This class holds a sorted array of characters, which are used as stop token.
* On every part of the array the given SQL string will be split into single tokens.
* The array must be sorted by element size, longest first (3 chars -> 2 chars -> 1 char).
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class LexerSplitter {
protected static $splitters = array("<=>", "\r\n", "!=", ">=", "<=", "<>", "<<", ">>", ":=", "\\", "&&", "||", ":=",
"/*", "*/", "--", ">", "<", "|", "=", "^", "(", ")", "\t", "\n", "'", "\"", "`",
",", "@", " ", "+", "-", "*", "/", ";",
);
protected $tokenSize;
protected $hashSet;
/**
* Constructor.
*
* It initializes some fields.
*/
public function __construct() {
$this->tokenSize = strlen(self::$splitters[0]); // should be the largest one
$this->hashSet = array_flip(self::$splitters);
}
/**
* Get the maximum length of a split token.
*
* The largest element must be on position 0 of the internal $_splitters array,
* so the function returns the length of that token. It must be > 0.
*
* @return int The number of characters for the largest split token.
*/
public function getMaxLengthOfSplitter() {
return $this->tokenSize;
}
/**
* Looks into the internal split token array and compares the given token with
* the array content. It returns true, if the token will be found, false otherwise.
*
* @param String $token a string, which could be a split token.
*
* @return boolean true, if the given string will be a split token, false otherwise
*/
public function isSplitter($token) {
return isset($this->hashSet[$token]);
}
}

View File

@@ -0,0 +1,373 @@
<?php
/**
* PHPSQLLexer.php
*
* This file contains the lexer, which splits and recombines parts of the
* SQL statement just before parsing.
*
* 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: PHPSQLLexer.php 842 2013-12-30 08:57:53Z phosco@gmx.de $
*
*/
require_once dirname(__FILE__) . '/LexerSplitter.php';
require_once dirname(__FILE__) . '/../exceptions/InvalidParameterException.php';
/**
* This class splits the SQL string into little parts, which the parser can
* use to build the result array.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class PHPSQLLexer {
protected $splitters;
/**
* Constructor.
*
* It initializes some fields.
*/
public function __construct() {
$this->splitters = new LexerSplitter();
}
/**
* Ends the given string $haystack with the string $needle?
*
* @param string $haystack
* @param string $needle
*
* @return boolean true, if the parameter $haystack ends with the character sequences $needle, false otherwise
*/
protected function endsWith($haystack, $needle) {
$length = strlen($needle);
if ($length == 0) {
return true;
}
return substr($haystack, -$length) === $needle;
}
public function split($sql) {
if (!is_string($sql)) {
throw new InvalidParameterException($sql);
}
$tokens = array();
$token = "";
$splitLen = $this->splitters->getMaxLengthOfSplitter();
$found = false;
$len = strlen($sql);
$pos = 0;
while ($pos < $len) {
for ($i = $splitLen; $i > 0; $i--) {
$substr = substr($sql, $pos, $i);
if ($this->splitters->isSplitter($substr)) {
if ($token !== "") {
$tokens[] = $token;
}
$tokens[] = $substr;
$pos += $i;
$token = "";
continue 2;
}
}
$token .= $sql[$pos];
$pos++;
}
if ($token !== "") {
$tokens[] = $token;
}
$tokens = $this->concatEscapeSequences($tokens);
$tokens = $this->balanceBackticks($tokens);
$tokens = $this->concatColReferences($tokens);
$tokens = $this->balanceParenthesis($tokens);
$tokens = $this->concatComments($tokens);
$tokens = $this->concatUserDefinedVariables($tokens);
return $tokens;
}
protected function concatUserDefinedVariables($tokens) {
$i = 0;
$cnt = count($tokens);
$userdef = false;
while ($i < $cnt) {
if (!isset($tokens[$i])) {
$i++;
continue;
}
$token = $tokens[$i];
if ($userdef !== false) {
$tokens[$userdef] .= $token;
unset($tokens[$i]);
if ($token !== "@") {
$userdef = false;
}
}
if ($userdef === false && $token === "@") {
$userdef = $i;
}
$i++;
}
return array_values($tokens);
}
protected function concatComments($tokens) {
$i = 0;
$cnt = count($tokens);
$comment = false;
while ($i < $cnt) {
if (!isset($tokens[$i])) {
$i++;
continue;
}
$token = $tokens[$i];
if ($comment !== false) {
if ($inline === true && ($token === "\n" || $token === "\r\n")) {
$comment = false;
} else {
unset($tokens[$i]);
$tokens[$comment] .= $token;
}
if ($inline === false && ($token === "*/")) {
$comment = false;
}
}
if (($comment === false) && ($token === "--")) {
$comment = $i;
$inline = true;
}
if (($comment === false) && ($token === "/*")) {
$comment = $i;
$inline = false;
}
$i++;
}
return array_values($tokens);
}
protected function isBacktick($token) {
return $token === "'" || $token === "\"" || $token === "`";
}
protected function balanceBackticks($tokens) {
$i = 0;
$cnt = count($tokens);
while ($i < $cnt) {
if (!isset($tokens[$i])) {
$i++;
continue;
}
$token = $tokens[$i];
if ($this->isBacktick($token)) {
$tokens = $this->balanceCharacter($tokens, $i, $token);
}
$i++;
}
return $tokens;
}
// backticks are not balanced within one token, so we have
// to re-combine some tokens
protected function balanceCharacter($tokens, $idx, $char) {
$token_count = count($tokens);
$i = $idx + 1;
while ($i < $token_count) {
if (!isset($tokens[$i])) {
$i++;
continue;
}
$token = $tokens[$i];
$tokens[$idx] .= $token;
unset($tokens[$i]);
if ($token === $char) {
break;
}
$i++;
}
return array_values($tokens);
}
/**
* This function concats some tokens to a column reference.
* There are two different cases:
*
* 1. If the current token ends with a dot, we will add the next token
* 2. If the next token starts with a dot, we will add it to the previous token
*
*/
protected function concatColReferences($tokens) {
$cnt = count($tokens);
$i = 0;
while ($i < $cnt) {
if (!isset($tokens[$i])) {
$i++;
continue;
}
if ($tokens[$i][0] === ".") {
// concat the previous tokens, till the token has been changed
$k = $i - 1;
$len = strlen($tokens[$i]);
while (($k >= 0) && ($len == strlen($tokens[$i]))) {
if (!isset($tokens[$k])) { // FIXME: this can be wrong if we have schema . table . column
$k--;
continue;
}
$tokens[$i] = $tokens[$k] . $tokens[$i];
unset($tokens[$k]);
$k--;
}
}
if ($this->endsWith($tokens[$i], '.') && !is_numeric($tokens[$i])) {
// concat the next tokens, till the token has been changed
$k = $i + 1;
$len = strlen($tokens[$i]);
while (($k < $cnt) && ($len == strlen($tokens[$i]))) {
if (!isset($tokens[$k])) {
$k++;
continue;
}
$tokens[$i] .= $tokens[$k];
unset($tokens[$k]);
$k++;
}
}
$i++;
}
return array_values($tokens);
}
protected function concatEscapeSequences($tokens) {
$tokenCount = count($tokens);
$i = 0;
while ($i < $tokenCount) {
if ($this->endsWith($tokens[$i], "\\")) {
$i++;
if (isset($tokens[$i])) {
$tokens[$i - 1] .= $tokens[$i];
unset($tokens[$i]);
}
}
$i++;
}
return array_values($tokens);
}
protected function balanceParenthesis($tokens) {
$token_count = count($tokens);
$i = 0;
while ($i < $token_count) {
if ($tokens[$i] !== '(') {
$i++;
continue;
}
$count = 1;
for ($n = $i + 1; $n < $token_count; $n++) {
$token = $tokens[$n];
if ($token === '(') {
$count++;
}
if ($token === ')') {
$count--;
}
$tokens[$i] .= $token;
unset($tokens[$n]);
if ($count === 0) {
$n++;
break;
}
}
$i = $n;
}
return array_values($tokens);
}
}

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;

View File

@@ -0,0 +1,224 @@
<?php
/**
* position-calculator.php
*
* This file implements the calculator for the position elements of
* the output of the PHPSQLParser.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/../utils/PHPSQLParserConstants.php';
require_once dirname(__FILE__) . '/../exceptions/UnableToCalculatePositionException.php';
/**
* This class calculates the positions
* of base_expr within the original SQL statement.
*
* @author arothe <andre.rothe@phosco.info>
*
*/
class PositionCalculator {
private static $_allowedOnOperator = array("\t", "\n", "\r", " ", ",", "(", ")", "_", "'", "\"");
private static $_allowedOnOther = array("\t", "\n", "\r", " ", ",", "(", ")", "<", ">", "*", "+", "-", "/", "|",
"&", "=", "!", ";",
);
private function _printPos($text, $sql, $charPos, $key, $parsed, $backtracking) {
if (!isset($_ENV['DEBUG'])) {
return;
}
$spaces = "";
$caller = debug_backtrace();
$i = 1;
while ($caller[$i]['function'] === 'lookForBaseExpression') {
$spaces .= " ";
$i++;
}
$holdem = substr($sql, 0, $charPos) . "^" . substr($sql, $charPos);
echo $spaces . $text . " key:" . $key . " parsed:" . $parsed . " back:" . serialize($backtracking) . " "
. $holdem . "\n";
}
public function setPositionsWithinSQL($sql, $parsed) {
$charPos = 0;
$backtracking = array();
$this->lookForBaseExpression($sql, $charPos, $parsed, 0, $backtracking);
return $parsed;
}
private function findPositionWithinString($sql, $value, $expr_type) {
$offset = 0;
$ok = false;
while (true) {
$pos = strpos($sql, $value, $offset);
if ($pos === false) {
break;
}
$before = "";
if ($pos > 0) {
$before = $sql[$pos - 1];
}
$after = "";
if (isset($sql[$pos + strlen($value)])) {
$after = $sql[$pos + strlen($value)];
}
// if we have an operator, it should be surrounded by
// whitespace, comma, parenthesis, digit or letter, end_of_string
// an operator should not be surrounded by another operator
if ($expr_type === 'operator') {
$ok = ($before === "" || in_array($before, self::$_allowedOnOperator, true))
|| (strtolower($before) >= 'a' && strtolower($before) <= 'z') || ($before >= '0' && $before <= '9');
$ok = $ok
&& ($after === "" || in_array($after, self::$_allowedOnOperator, true)
|| (strtolower($after) >= 'a' && strtolower($after) <= 'z') || ($after >= '0' && $after <= '9')
|| ($after === '?') || ($after === '@'));
if (!$ok) {
$offset = $pos + 1;
continue;
}
break;
}
// in all other cases we accept
// whitespace, comma, operators, parenthesis and end_of_string
$ok = ($before === "" || in_array($before, self::$_allowedOnOther, true));
$ok = $ok && ($after === "" || in_array($after, self::$_allowedOnOther, true));
if ($ok) {
break;
}
$offset = $pos + 1;
}
return $pos;
}
private function lookForBaseExpression($sql, &$charPos, &$parsed, $key, &$backtracking) {
if (!is_numeric($key)) {
if (($key === 'UNION' || $key === 'UNION ALL')
|| ($key === 'expr_type' && $parsed === ExpressionType::EXPRESSION)
|| ($key === 'expr_type' && $parsed === ExpressionType::SUBQUERY)
|| ($key === 'expr_type' && $parsed === ExpressionType::BRACKET_EXPRESSION)
|| ($key === 'expr_type' && $parsed === ExpressionType::TABLE_EXPRESSION)
|| ($key === 'expr_type' && $parsed === ExpressionType::RECORD)
|| ($key === 'expr_type' && $parsed === ExpressionType::IN_LIST)
|| ($key === 'expr_type' && $parsed === ExpressionType::MATCH_ARGUMENTS)
|| ($key === 'expr_type' && $parsed === ExpressionType::TABLE)
|| ($key === 'expr_type' && $parsed === ExpressionType::TEMPORARY_TABLE)
|| ($key === 'expr_type' && $parsed === ExpressionType::COLUMN_TYPE)
|| ($key === 'expr_type' && $parsed === ExpressionType::COLDEF)
|| ($key === 'expr_type' && $parsed === ExpressionType::PRIMARY_KEY)
|| ($key === 'expr_type' && $parsed === ExpressionType::CONSTRAINT)
|| ($key === 'expr_type' && $parsed === ExpressionType::COLUMN_LIST)
|| ($key === 'expr_type' && $parsed === ExpressionType::CHECK)
|| ($key === 'expr_type' && $parsed === ExpressionType::COLLATE)
|| ($key === 'expr_type' && $parsed === ExpressionType::LIKE)
|| ($key === 'expr_type' && $parsed === ExpressionType::INDEX)
|| ($key === 'select-option' && $parsed !== false) || ($key === 'alias' && $parsed !== false)) {
// we hold the current position and come back after the next base_expr
// we do this, because the next base_expr contains the complete expression/subquery/record
// and we have to look into it too
$backtracking[] = $charPos;
} elseif (($key === 'ref_clause' || $key === 'columns') && $parsed !== false) {
// we hold the current position and come back after n base_expr(s)
// there is an array of sub-elements before (!) the base_expr clause of the current element
// so we go through the sub-elements and must come at the end
$backtracking[] = $charPos;
for ($i = 1; $i < count($parsed); $i++) {
$backtracking[] = false; // backtracking only after n base_expr!
}
} elseif (($key === 'sub_tree' && $parsed !== false) || ($key === 'options' && $parsed !== false)) {
// we prevent wrong backtracking on subtrees (too much array_pop())
// there is an array of sub-elements after(!) the base_expr clause of the current element
// so we go through the sub-elements and must not come back at the end
for ($i = 1; $i < count($parsed); $i++) {
$backtracking[] = false;
}
} elseif (($key === 'TABLE') || ($key === 'create-def' && $parsed !== false)) {
// do nothing
} else {
// move the current pos after the keyword
// SELECT, WHERE, INSERT etc.
if (PHPSQLParserConstants::isReserved($key)) {
$charPos = stripos($sql, $key, $charPos);
$charPos += strlen($key);
}
}
}
if (!is_array($parsed)) {
return;
}
foreach ($parsed as $key => $value) {
if ($key === 'base_expr') {
//$this->_printPos("0", $sql, $charPos, $key, $value, $backtracking);
$subject = substr($sql, $charPos);
$pos = $this->findPositionWithinString(
$subject,
$value,
isset($parsed['expr_type']) ? $parsed['expr_type'] : 'alias'
);
if ($pos === false) {
throw new UnableToCalculatePositionException($value, $subject);
}
$parsed['position'] = $charPos + $pos;
$charPos += $pos + strlen($value);
//$this->_printPos("1", $sql, $charPos, $key, $value, $backtracking);
$oldPos = array_pop($backtracking);
if (isset($oldPos) && $oldPos !== false) {
$charPos = $oldPos;
}
//$this->_printPos("2", $sql, $charPos, $key, $value, $backtracking);
} else {
$this->lookForBaseExpression($sql, $charPos, $parsed[$key], $key, $backtracking);
}
}
}
}

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;

View File

@@ -0,0 +1,223 @@
<?php
/**
* AbstractProcessor.php
*
* This file implements an abstract processor, which implements some helper functions.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/../lexer/PHPSQLLexer.php';
/**
*
* This class processes contains some general functions for a processor.
*
* @author arothe
*
*/
abstract class AbstractProcessor {
/**
* This function implements the main functionality of a processor class.
* Always use default valuses for additional parameters within overridden functions.
*/
abstract public function process($tokens);
/**
* this function splits up a SQL statement into easy to "parse"
* tokens for the SQL processor
*/
public function splitSQLIntoTokens($sql) {
$lexer = new PHPSQLLexer();
return $lexer->split($sql);
}
/**
* Revokes the quoting characters from an expression
*/
protected function revokeQuotation($sql) {
$result = trim($sql);
if (($result[0] === '`') && ($result[strlen($result) - 1] === '`')) {
$result = substr($result, 1, -1);
return trim(str_replace('``', '`', $result));
}
if (($result[0] === "'") && ($result[strlen($result) - 1] === "'")) {
$result = substr($result, 1, -1);
return trim(str_replace("''", "'", $result));
}
if (($result[0] === "\"") && ($result[strlen($result) - 1] === "\"")) {
$result = substr($result, 1, -1);
return trim(str_replace("\"\"", "\"", $result));
}
return $sql;
}
/**
* This method removes parenthesis from start of the given string.
* It removes also the associated closing parenthesis.
*/
protected function removeParenthesisFromStart($token) {
$parenthesisRemoved = 0;
$trim = trim($token);
if ($trim !== "" && $trim[0] === "(") { // remove only one parenthesis pair now!
$parenthesisRemoved++;
$trim[0] = " ";
$trim = trim($trim);
}
$parenthesis = $parenthesisRemoved;
$i = 0;
$string = 0;
while ($i < strlen($trim)) {
if ($trim[$i] === "\\") {
$i += 2; // an escape character, the next character is irrelevant
continue;
}
if ($trim[$i] === "'" || $trim[$i] === '"') {
$string++;
}
if (($string % 2 === 0) && ($trim[$i] === "(")) {
$parenthesis++;
}
if (($string % 2 === 0) && ($trim[$i] === ")")) {
if ($parenthesis == $parenthesisRemoved) {
$trim[$i] = " ";
$parenthesisRemoved--;
}
$parenthesis--;
}
$i++;
}
return trim($trim);
}
protected function getVariableType($expression) {
// $expression must contain only upper-case characters
if ($expression[1] !== "@") {
return ExpressionType::USER_VARIABLE;
}
$type = substr($expression, 2, strpos($expression, ".", 2));
switch ($type) {
case 'GLOBAL':
$type = ExpressionType::GLOBAL_VARIABLE;
break;
case 'LOCAL':
$type = ExpressionType::LOCAL_VARIABLE;
break;
case 'SESSION':
default:
$type = ExpressionType::SESSION_VARIABLE;
break;
}
return $type;
}
protected function isCommaToken($token) {
return trim($token) === ",";
}
protected function isWhitespaceToken($token) {
return trim($token) === "";
}
protected function isCommentToken($token) {
return isset($token[0], $token[1])
&& (($token[0] === '-' && $token[1] === '-') || ($token[0] === '/' && $token[1] === '*'));
}
protected function isColumnReference($out) {
return isset($out['expr_type']) && $out['expr_type'] === ExpressionType::COLREF;
}
protected function isReserved($out) {
return isset($out['expr_type']) && $out['expr_type'] === ExpressionType::RESERVED;
}
protected function isConstant($out) {
return isset($out['expr_type']) && $out['expr_type'] === ExpressionType::CONSTANT;
}
protected function isAggregateFunction($out) {
return isset($out['expr_type']) && $out['expr_type'] === ExpressionType::AGGREGATE_FUNCTION;
}
protected function isFunction($out) {
return isset($out['expr_type']) && $out['expr_type'] === ExpressionType::SIMPLE_FUNCTION;
}
protected function isExpression($out) {
return isset($out['expr_type']) && $out['expr_type'] === ExpressionType::EXPRESSION;
}
protected function isBracketExpression($out) {
return isset($out['expr_type']) && $out['expr_type'] === ExpressionType::BRACKET_EXPRESSION;
}
protected function isSubQuery($out) {
return isset($out['expr_type']) && $out['expr_type'] === ExpressionType::SUBQUERY;
}
/**
* translates an array of objects into an associative array
*/
public function toArray($tokenList) {
$expr = array();
foreach ($tokenList as $token) {
$expr[] = $token->toArray();
}
return empty($expr) ? false : $expr;
}
protected function array_insert_after($array, $key, $entry) {
$idx = array_search($key, array_keys($array));
$array = array_slice($array, 0, $idx + 1, true) + $entry
+ array_slice($array, $idx + 1, count($array) - 1, true);
return $array;
}
}

View File

@@ -0,0 +1,496 @@
<?php
/**
* ColumnDefinitionProcessor.php
*
* This file implements the processor for column definition part of a CREATE TABLE statement.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/AbstractProcessor.php';
require_once dirname(__FILE__) . '/ReferenceDefinitionProcessor.php';
require_once dirname(__FILE__) . '/ExpressionListProcessor.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
*
* This class processes the column definition part of a CREATE TABLE statement.
*
* @author arothe
*
*/
class ColumnDefinitionProcessor extends AbstractProcessor {
protected function processExpressionList($parsed) {
$processor = new ExpressionListProcessor();
return $processor->process($parsed);
}
protected function processReferenceDefinition($parsed) {
$processor = new ReferenceDefinitionProcessor();
return $processor->process($parsed);
}
protected function removeComma($tokens) {
$res = array();
foreach ($tokens as $token) {
if (trim($token) !== ',') {
$res[] = $token;
}
}
return $res;
}
protected function buildColDef($expr, $base_expr, $options, $refs, $key) {
$expr = array('expr_type' => ExpressionType::COLUMN_TYPE, 'base_expr' => $base_expr, 'sub_tree' => $expr);
// add options first
$expr['sub_tree'] = array_merge($expr['sub_tree'], $options['sub_tree']);
unset($options['sub_tree']);
$expr = array_merge($expr, $options);
// followed by references
if (count($refs) !== 0) {
$expr['sub_tree'] = array_merge($expr['sub_tree'], $refs);
}
$expr['till'] = $key;
return $expr;
}
public function process($tokens) {
$trim = '';
$base_expr = '';
$currCategory = '';
$expr = array();
$refs = array();
$options = array('unique' => false, 'nullable' => true, 'auto_inc' => false, 'primary' => false,
'sub_tree' => array(),
);
$skip = 0;
foreach ($tokens as $key => $token) {
$trim = trim($token);
$base_expr .= $token;
if ($skip > 0) {
$skip--;
continue;
}
if ($skip < 0) {
break;
}
if ($trim === '') {
continue;
}
$upper = strtoupper($trim);
switch ($upper) {
case ',':
// we stop on a single comma and return
// the $expr entry and the index $key
$expr = $this->buildColDef(
$expr,
trim(substr($base_expr, 0, -strlen($token))),
$options,
$refs,
$key - 1
);
break 2;
case 'VARCHAR':
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim, 'length' => false);
$prevCategory = 'TEXT';
$currCategory = 'SINGLE_PARAM_PARENTHESIS';
continue 2;
case 'VARBINARY':
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim, 'length' => false);
$prevCategory = $upper;
$currCategory = 'SINGLE_PARAM_PARENTHESIS';
continue 2;
case 'UNSIGNED':
$last = array_pop($expr);
$last['unsigned'] = true;
$expr[] = $last;
continue 2;
case 'ZEROFILL':
$last = array_pop($expr);
$last['zerofill'] = true;
$expr[] = $last;
continue 2;
case 'BIT':
case 'TINYBIT':
case 'SMALLINT':
case 'MEDIUMINT':
case 'INT':
case 'INTEGER':
case 'BIGINT':
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim, 'unsigned' => false,
'zerofill' => false, 'length' => false,
);
$currCategory = 'SINGLE_PARAM_PARENTHESIS';
$prevCategory = $upper;
continue 2;
case 'BINARY':
if ($currCategory === 'TEXT') {
$last = array_pop($expr);
$last['binary'] = true;
$last['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$expr[] = $last;
continue 2;
}
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim, 'length' => false);
$currCategory = 'SINGLE_PARAM_PARENTHESIS';
$prevCategory = $upper;
continue 2;
case 'CHAR':
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim, 'length' => false);
$currCategory = 'SINGLE_PARAM_PARENTHESIS';
$prevCategory = 'TEXT';
continue 2;
case 'REAL':
case 'DOUBLE':
case 'FLOAT':
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim, 'unsigned' => false,
'zerofill' => false,
);
$currCategory = 'TWO_PARAM_PARENTHESIS';
$prevCategory = $upper;
continue 2;
case 'DECIMAL':
case 'NUMERIC':
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim, 'unsigned' => false,
'zerofill' => false,
);
$currCategory = 'TWO_PARAM_PARENTHESIS';
$prevCategory = $upper;
continue 2;
case 'DATE':
case 'TIME':
case 'TIMESTAMP':
case 'DATETIME':
case 'YEAR':
case 'TINYBLOB':
case 'BLOB':
case 'MEDIUMBLOB':
case 'LONGBLOB':
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim);
$prevCategory = $currCategory = $upper;
continue 2;
// the next token can be BINARY
case 'TINYTEXT':
case 'TEXT':
case 'MEDIUMTEXT':
case 'LONGTEXT':
$prevCategory = $currCategory = 'TEXT';
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim, 'binary' => false);
continue 2;
case 'ENUM':
case 'SET':
$currCategory = 'MULTIPLE_PARAM_PARENTHESIS';
$prevCategory = 'TEXT';
$expr[] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim, 'sub_tree' => false);
continue 2;
case 'GEOMETRY':
case 'POINT':
case 'LINESTRING':
case 'POLYGON':
case 'MULTIPOINT':
case 'MULTILINESTRING':
case 'MULTIPOLYGON':
case 'GEOMETRYCOLLECTION':
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim);
$prevCategory = $currCategory = $upper;
// TODO: is it right?
// spatial types
continue 2;
case 'CHARACTER':
if ($prevCategory === 'TEXT') {
$parsed = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim);
$expr[] = array('expr_type' => ExpressionType::CHARSET, 'base_expr' => substr($base_expr, 0, -1),
'sub_tree' => $parsed,
);
$base_expr = $token;
$currCategory = 'CHARSET';
continue 2;
}
// else ?
break;
case 'SET':
if ($currCategory === 'CHARSET') {
// TODO: is it necessary to set special properties like the name or collation?
$parsed = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$last = array_pop($expr);
$last['sub_tree'][] = $parsed;
$expr[] = $last;
continue 2;
}
// else ?
break;
case 'COLLATE':
if ($prevCategory === 'TEXT') {
$parsed = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$expr[] = array('expr_type' => ExpressionType::COLLATE, 'base_expr' => substr($base_expr, 0, -1),
'sub_tree' => $parsed,
);
$base_expr = $token;
$currCategory = 'COLLATION';
continue 2;
}
// else ?
break;
case 'NOT':
case 'NULL':
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
if ($options['nullable']) {
$options['nullable'] = ($upper === 'NOT' ? false : true);
}
continue 2;
case 'DEFAULT':
case 'COMMENT':
$currCategory = $upper;
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
continue 2;
case 'AUTO_INCREMENT':
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$options['auto_inc'] = true;
continue 2;
case 'COLUMN_FORMAT':
case 'STORAGE':
$currCategory = $upper;
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
continue 2;
case 'UNIQUE':
// it can follow a KEY word
$currCategory = $upper;
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$options['unique'] = true;
continue 2;
case 'PRIMARY':
// it must follow a KEY word
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
continue 2;
case 'KEY':
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
if ($currCategory !== 'UNIQUE') {
$options['primary'] = true;
}
continue 2;
case 'REFERENCES':
$refs = $this->processReferenceDefinition(array_splice($tokens, $key - 1, null, true));
$skip = $refs['till'] - $key;
unset($refs['till']);
// TODO: check this, we need the last comma
continue 2;
default:
switch ($currCategory) {
case 'STORAGE':
if ($upper === 'DISK' || $upper === 'MEMORY' || $upper === 'DEFAULT') {
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$options['storage'] = $trim;
continue 3;
}
// else ?
break;
case 'COLUMN_FORMAT':
if ($upper === 'FIXED' || $upper === 'DYNAMIC' || $upper === 'DEFAULT') {
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$options['col_format'] = $trim;
continue 3;
}
// else ?
break;
case 'COMMENT':
// this is the comment string
$options['sub_tree'][] = array('expr_type' => ExpressionType::COMMENT, 'base_expr' => $trim);
$options['comment'] = $trim;
$currCategory = $prevCategory;
break;
case 'DEFAULT':
// this is the default value
$options['sub_tree'][] = array('expr_type' => ExpressionType::DEF_VALUE, 'base_expr' => $trim);
$options['default'] = $trim;
$currCategory = $prevCategory;
break;
case 'COLLATE':
// this is the collation name
$parsed = array('expr_type' => ExpressionType::CONSTANT, 'base_expr' => $trim);
$last = array_pop($expr);
$last['sub_tree'][] = $parsed;
$t = $base_expr;
$base_expr = $last['base_expr'] . $base_expr;
$last['base_expr'] = $t;
$currCategory = $prevCategory;
break;
case 'CHARSET':
// this is the character set name
$parsed = array('expr_type' => ExpressionType::CONSTANT, 'base_expr' => $trim);
$last = array_pop($expr);
$last['sub_tree'][] = $parsed;
$t = $base_expr;
$base_expr = $last['base_expr'] . $base_expr;
$last['base_expr'] = $t;
$currCategory = $prevCategory;
break;
case 'SINGLE_PARAM_PARENTHESIS':
$parsed = $this->removeParenthesisFromStart($trim);
$parsed = array('expr_type' => ExpressionType::CONSTANT, 'base_expr' => trim($parsed));
$last = array_pop($expr);
$last['length'] = $parsed['base_expr'];
$expr[] = $last;
$expr[] = array('expr_type' => ExpressionType::BRACKET_EXPRESSION, 'base_expr' => $trim,
'sub_tree' => array($parsed),
);
$currCategory = $prevCategory;
break;
case 'TWO_PARAM_PARENTHESIS':
// maximum of two parameters
$parsed = $this->removeParenthesisFromStart($trim);
$parsed = $this->splitSQLIntoTokens($parsed);
$parsed = $this->removeComma($parsed);
$parsed = $this->processExpressionList($parsed);
// TODO: check that
$last = array_pop($expr);
$last['length'] = $parsed[0]['base_expr'];
$last['decimals'] = isset($parsed[1]) ? $parsed[1]['base_expr'] : false;
$expr[] = $last;
$expr[] = array('expr_type' => ExpressionType::BRACKET_EXPRESSION, 'base_expr' => $trim,
'sub_tree' => $parsed,
);
$currCategory = $prevCategory;
break;
case 'MULTIPLE_PARAM_PARENTHESIS':
// some parameters
$parsed = $this->removeParenthesisFromStart($trim);
$parsed = $this->splitSQLIntoTokens($parsed);
$parsed = $this->removeComma($parsed);
$this->processExpressionList($parsed);
$last = array_pop($expr);
$last['sub_tree'] = array('expr_type' => ExpressionType::BRACKET_EXPRESSION, 'base_expr' => $trim,
'sub_tree' => $parsed,
);
$expr[] = $last;
$currCategory = $prevCategory;
break;
default:
break;
}
}
$prevCategory = $currCategory;
$currCategory = '';
}
if (!isset($expr['till'])) {
// end of $tokens array
$expr = $this->buildColDef($expr, trim($base_expr), $options, $refs, -1);
}
return $expr;
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* ColumnListProcessor.php
*
* This file implements the processor for column lists like in INSERT statements.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/AbstractProcessor.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
*
* This class processes column-lists.
*
* @author arothe
*
*/
class ColumnListProcessor extends AbstractProcessor {
public function process($tokens) {
$columns = explode(",", $tokens);
$cols = array();
foreach ($columns as $k => $v) {
$cols[] = array('expr_type' => ExpressionType::COLREF, 'base_expr' => trim($v),
'no_quotes' => $this->revokeQuotation($v),
);
}
return $cols;
}
}

View File

@@ -0,0 +1,449 @@
<?php
/**
* CreateDefinitionProcessor.php
*
* This file implements the processor for the create definition within the TABLE statements.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/AbstractProcessor.php';
require_once dirname(__FILE__) . '/ColumnDefinitionProcessor.php';
require_once dirname(__FILE__) . '/IndexColumnListProcessor.php';
require_once dirname(__FILE__) . '/ReferenceDefinitionProcessor.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
*
* This class processes the create definition of the TABLE statements.
*
* @author arothe
*
*/
class CreateDefinitionProcessor extends AbstractProcessor {
protected function correctExpressionType(&$expr) {
$type = ExpressionType::EXPRESSION;
if (!isset($expr[0]) || !isset($expr[0]['expr_type'])) {
return $type;
}
// replace the constraint type with a more descriptive one
switch ($expr[0]['expr_type']) {
case ExpressionType::CONSTRAINT:
$type = $expr[1]['expr_type'];
$expr[1]['expr_type'] = ExpressionType::RESERVED;
break;
case ExpressionType::COLREF:
$type = ExpressionType::COLDEF;
break;
default:
$type = $expr[0]['expr_type'];
$expr[0]['expr_type'] = ExpressionType::RESERVED;
break;
}
return $type;
}
public function process($tokens) {
$base_expr = "";
$prevCategory = "";
$currCategory = "";
$expr = array();
$result = array();
$skip = 0;
foreach ($tokens as $k => $token) {
$trim = trim($token);
$base_expr .= $token;
if ($skip !== 0) {
$skip--;
continue;
}
if ($trim === "") {
continue;
}
$upper = strtoupper($trim);
switch ($upper) {
case 'CONSTRAINT':
$expr[] = array('expr_type' => ExpressionType::CONSTRAINT, 'base_expr' => $trim, 'sub_tree' => false);
$currCategory = $prevCategory = $upper;
continue 2;
case 'LIKE':
$expr[] = array('expr_type' => ExpressionType::LIKE, 'base_expr' => $trim);
$currCategory = $prevCategory = $upper;
continue 2;
case 'FOREIGN':
if ($prevCategory === "" || $prevCategory === "CONSTRAINT") {
$expr[] = array('expr_type' => ExpressionType::FOREIGN_KEY, 'base_expr' => $trim);
$currCategory = $upper;
continue 2;
}
// else ?
break;
case 'PRIMARY':
if ($prevCategory === "" || $prevCategory === "CONSTRAINT") {
// next one is KEY
$expr[] = array('expr_type' => ExpressionType::PRIMARY_KEY, 'base_expr' => $trim);
$currCategory = $upper;
continue 2;
}
// else ?
break;
case 'UNIQUE':
if ($prevCategory === "" || $prevCategory === "CONSTRAINT") {
// next one is KEY
$expr[] = array('expr_type' => ExpressionType::UNIQUE_IDX, 'base_expr' => $trim);
$currCategory = $upper;
continue 2;
}
// else ?
break;
case 'KEY':
// the next one is an index name
if ($currCategory === 'PRIMARY' || $currCategory === 'FOREIGN' || $currCategory === 'UNIQUE') {
$expr[] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
continue 2;
}
$expr[] = array('expr_type' => ExpressionType::INDEX, 'base_expr' => $trim);
$currCategory = $upper;
continue 2;
case 'CHECK':
$expr[] = array('expr_type' => ExpressionType::CHECK, 'base_expr' => $trim);
$currCategory = $upper;
continue 2;
case 'INDEX':
if ($currCategory === 'UNIQUE' || $currCategory === 'FULLTEXT' || $currCategory === 'SPATIAL') {
$expr[] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
continue 2;
}
$expr[] = array('expr_type' => ExpressionType::INDEX, 'base_expr' => $trim);
$currCategory = $upper;
continue 2;
case 'FULLTEXT':
$expr[] = array('expr_type' => ExpressionType::FULLTEXT_IDX, 'base_expr' => $trim);
$currCategory = $prevCategory = $upper;
continue 2;
case 'SPATIAL':
$expr[] = array('expr_type' => ExpressionType::SPATIAL_IDX, 'base_expr' => $trim);
$currCategory = $prevCategory = $upper;
continue 2;
case 'WITH':
// starts an index option
if ($currCategory === 'INDEX_COL_LIST') {
$option = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$expr[] = array('expr_type' => ExpressionType::INDEX_PARSER,
'base_expr' => substr($base_expr, 0, -strlen($token)),
'sub_tree' => array($option),
);
$base_expr = $token;
$currCategory = 'INDEX_PARSER';
continue 2;
}
break;
case 'KEY_BLOCK_SIZE':
// starts an index option
if ($currCategory === 'INDEX_COL_LIST') {
$option = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$expr[] = array('expr_type' => ExpressionType::INDEX_SIZE,
'base_expr' => substr($base_expr, 0, -strlen($token)),
'sub_tree' => array($option),
);
$base_expr = $token;
$currCategory = 'INDEX_SIZE';
continue 2;
}
break;
case 'USING':
// starts an index option
if ($currCategory === 'INDEX_COL_LIST' || $currCategory === 'PRIMARY') {
$option = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$expr[] = array('base_expr' => substr($base_expr, 0, -strlen($token)), 'trim' => $trim,
'category' => $currCategory, 'sub_tree' => array($option),
);
$base_expr = $token;
$currCategory = 'INDEX_TYPE';
continue 2;
}
// else ?
break;
case 'REFERENCES':
if ($currCategory === 'INDEX_COL_LIST' && $prevCategory === 'FOREIGN') {
$processor = new ReferenceDefinitionProcessor();
$refs = $processor->process(array_slice($tokens, $k - 1, null, true));
$skip = $refs['till'] - $k;
unset($refs['till']);
$expr[] = $refs;
$currCategory = $upper;
}
break;
case 'BTREE':
case 'HASH':
if ($currCategory === 'INDEX_TYPE') {
$last = array_pop($expr);
$last['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$expr[] = array('expr_type' => ExpressionType::INDEX_TYPE, 'base_expr' => $base_expr,
'sub_tree' => $last['sub_tree'],
);
$base_expr = $last['base_expr'] . $base_expr;
// FIXME: it could be wrong for index_type within index_option
$currCategory = $last['category'];
continue 2;
}
//else
break;
case '=':
if ($currCategory === 'INDEX_SIZE') {
// the optional character between KEY_BLOCK_SIZE and the numeric constant
$last = array_pop($expr);
$last['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$expr[] = $last;
continue 2;
}
break;
case 'PARSER':
if ($currCategory === 'INDEX_PARSER') {
$last = array_pop($expr);
$last['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
$expr[] = $last;
continue 2;
}
// else?
break;
case ',':
// this starts the next definition
$type = $this->correctExpressionType($expr);
$result['create-def'][] = array('expr_type' => $type,
'base_expr' => trim(substr($base_expr, 0, -strlen($token))),
'sub_tree' => $expr,
);
$base_expr = "";
$expr = array();
break;
default:
switch ($currCategory) {
case 'LIKE':
// this is the tablename after LIKE
$expr[] = array('expr_type' => ExpressionType::TABLE, 'table' => $trim, 'base_expr' => $trim,
'no_quotes' => $this->revokeQuotation($trim),
);
break;
case 'PRIMARY':
if ($upper[0] === '(' && substr($upper, -1) === ')') {
// the column list
$processor = new IndexColumnListProcessor();
$cols = $processor->process($this->removeParenthesisFromStart($trim));
$expr[] = array('expr_type' => ExpressionType::COLUMN_LIST, 'base_expr' => $trim,
'sub_tree' => $cols,
);
$prevCategory = $currCategory;
$currCategory = "INDEX_COL_LIST";
continue 3;
}
// else?
break;
case 'FOREIGN':
if ($upper[0] === '(' && substr($upper, -1) === ')') {
$processor = new IndexColumnListProcessor();
$cols = $processor->process($this->removeParenthesisFromStart($trim));
$expr[] = array('expr_type' => ExpressionType::COLUMN_LIST, 'base_expr' => $trim,
'sub_tree' => $cols,
);
$prevCategory = $currCategory;
$currCategory = "INDEX_COL_LIST";
continue 3;
}
// index name
$expr[] = array('expr_type' => ExpressionType::CONSTANT, 'base_expr' => $trim);
continue 3;
case 'KEY':
case 'UNIQUE':
case 'INDEX':
if ($upper[0] === '(' && substr($upper, -1) === ')') {
$processor = new IndexColumnListProcessor();
$cols = $processor->process($this->removeParenthesisFromStart($trim));
$expr[] = array('expr_type' => ExpressionType::COLUMN_LIST, 'base_expr' => $trim,
'sub_tree' => $cols,
);
$prevCategory = $currCategory;
$currCategory = "INDEX_COL_LIST";
continue 3;
}
// index name
$expr[] = array('expr_type' => ExpressionType::CONSTANT, 'base_expr' => $trim);
continue 3;
case 'CONSTRAINT':
// constraint name
$last = array_pop($expr);
$last['base_expr'] = $base_expr;
$last['sub_tree'] = array('expr_type' => ExpressionType::CONSTANT, 'base_expr' => $trim);
$expr[] = $last;
continue 3;
case 'INDEX_PARSER':
// index parser name
$last = array_pop($expr);
$last['sub_tree'][] = array('expr_type' => ExpressionType::CONSTANT, 'base_expr' => $trim);
$expr[] = array('expr_type' => ExpressionType::INDEX_PARSER, 'base_expr' => $base_expr,
'sub_tree' => $last['sub_tree'],
);
$base_expr = $last['base_expr'] . $base_expr;
$currCategory = 'INDEX_COL_LIST';
continue 3;
case 'INDEX_SIZE':
// index key block size numeric constant
$last = array_pop($expr);
$last['sub_tree'][] = array('expr_type' => ExpressionType::CONSTANT, 'base_expr' => $trim);
$expr[] = array('expr_type' => ExpressionType::INDEX_SIZE, 'base_expr' => $base_expr,
'sub_tree' => $last['sub_tree'],
);
$base_expr = $last['base_expr'] . $base_expr;
$currCategory = 'INDEX_COL_LIST';
continue 3;
case 'CHECK':
if ($upper[0] === '(' && substr($upper, -1) === ')') {
$processor = new ExpressionListProcessor();
$unparsed = $this->splitSQLIntoTokens($this->removeParenthesisFromStart($trim));
$parsed = $processor->process($unparsed);
$expr[] = array('expr_type' => ExpressionType::BRACKET_EXPRESSION, 'base_expr' => $trim,
'sub_tree' => $parsed,
);
}
// else?
break;
case '':
// if the currCategory is empty, we have an unknown token,
// which is a column reference
$expr[] = array('expr_type' => ExpressionType::COLREF, 'base_expr' => $trim,
'no_quotes' => $this->revokeQuotation($trim),
);
$currCategory = 'COLUMN_NAME';
continue 3;
case 'COLUMN_NAME':
// the column-definition
// it stops on a comma or on a parenthesis
$processor = new ColumnDefinitionProcessor();
$parsed = $processor->process(array_slice($tokens, $k, null, true), $expr);
$skip = $parsed['till'] - $k;
unset($parsed['till']);
$expr[] = $parsed;
$currCategory = '';
break;
default:
// ?
break;
}
break;
}
$prevCategory = $currCategory;
$currCategory = '';
}
$type = $this->correctExpressionType($expr);
$result['create-def'][] = array('expr_type' => $type, 'base_expr' => trim($base_expr), 'sub_tree' => $expr);
return $result;
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* CreateProcessor.php
*
* This file implements the processor for the CREATE TABLE statements.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/AbstractProcessor.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
*
* This class processes the CREATE statements.
*
* @author arothe
*
*/
class CreateProcessor extends AbstractProcessor {
public function process($tokens) {
$result = array();
$base_expr = "";
foreach ($tokens as $token) {
$trim = strtoupper(trim($token));
$base_expr .= $token;
if ($trim === "") {
continue;
}
switch ($trim) {
case 'TEMPORARY':
$result['expr_type'] = ExpressionType::TEMPORARY_TABLE;
$result['not-exists'] = false;
$expr[] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
break;
case 'TABLE':
$result['expr_type'] = ExpressionType::TABLE;
$result['not-exists'] = false;
$expr[] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
break;
case 'IF':
$expr[] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
break;
case 'NOT':
$expr[] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
break;
case 'EXISTS':
$result['not-exists'] = true;
$expr[] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
break;
default:
break;
}
}
$result['base_expr'] = trim($base_expr);
$result['sub_tree'] = $expr;
return $result;
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* DefaultProcessor.php
*
* This file implements the processor the unparsed sql string given by the user.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/AbstractProcessor.php';
require_once dirname(__FILE__) . '/UnionProcessor.php';
require_once dirname(__FILE__) . '/SQLProcessor.php';
/**
*
* This class processes the incoming sql string.
*
* @author arothe
*
*/
class DefaultProcessor extends AbstractProcessor {
public function process($sql) {
$inputArray = $this->splitSQLIntoTokens($sql);
// this is the highest level lexical analysis. This is the part of the
// code which finds UNION and UNION ALL query parts
$processor = new UnionProcessor();
$queries = $processor->process($inputArray);
// If there was no UNION or UNION ALL in the query, then the query is
// stored at $queries[0].
if (!$processor->isUnion($queries)) {
$processor = new SQLProcessor();
$queries = $processor->process($queries[0]);
}
return $queries;
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* DeleteProcessor.php
*
* This file implements the processor for the DELETE statements.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/AbstractProcessor.php';
/**
*
* This class processes the DELETE statements.
*
* @author arothe
*
*/
class DeleteProcessor extends AbstractProcessor {
public function process($tokens) {
$tables = array();
$del = $tokens['DELETE'];
foreach ($tokens['DELETE'] as $expression) {
if ($expression !== 'DELETE' && trim($expression, ' .*') !== "" && !$this->isCommaToken($expression)) {
$tables[] = trim($expression, '.* ');
}
}
if (empty($tables)) {
foreach ($tokens['FROM'] as $table) {
$tables[] = $table['table'];
}
}
$tokens['DELETE'] = array('TABLES' => $tables);
return $tokens;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* DescProcessor.php
*
* This file implements the processor for the DESC statements, which is a short form of DESCRIBE.
*
* Copyright (c) 2010-2014, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/ExplainProcessor.php';
/**
*
* This class processes the DESC statement.
*
* @author arothe
*
*/
class DescProcessor extends ExplainProcessor {
protected function isStatement($keys, $needle = "DESC") {
return parent::isStatement($keys, $needle);
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* DescribeProcessor.php
*
* This file implements the processor for the DESCRIBE statements.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/ExplainProcessor.php';
/**
*
* This class processes the DESCRIBE statements.
*
* @author arothe
*
*/
class DescribeProcessor extends ExplainProcessor {
protected function isStatement($keys, $needle = "DESCRIBE") {
return parent::isStatement($keys, $needle);
}
}

View File

@@ -0,0 +1,112 @@
<?php
/**
* DropProcessor.php
*
* This file implements the processor for the DROP statements.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/../utils/ExpressionToken.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
require_once dirname(__FILE__) . '/AbstractProcessor.php';
/**
*
* This class processes the DROP statements.
*
* @author arothe
*
*/
class DropProcessor extends AbstractProcessor {
// TODO: we should enhance it to get the positions for the IF EXISTS keywords
// look into the CreateProcessor to get an idea.
public function process($tokenList) {
$skip = 0;
$warning = true;
$base_expr = "";
$expr_type = false;
$option = false;
$resultList = array();
foreach ($tokenList as $k => $v) {
$token = new ExpressionToken($k, $v);
if ($token->isWhitespaceToken()) {
continue;
}
if ($skip > 0) {
$skip--;
continue;
}
switch ($token->getUpper()) {
case 'VIEW':
case 'SCHEMA':
case 'DATABASE':
case 'TABLE':
$expr_type = strtolower($token->getTrim());
break;
case 'IF':
$warning = false;
$skip = 1;
break;
case 'TEMPORARY':
$expr_type = ExpressionType::TEMPORARY_TABLE;
$skip = 1;
break;
case 'RESTRICT':
case 'CASCADE':
$option = $token->getUpper();
break;
case ',':
$resultList[] = array('expr_type' => $expr_type, 'base_expr' => $base_expr);
$base_expr = "";
break;
default:
$base_expr .= $token->getToken();
}
}
if ($base_expr !== "") {
$resultList[] = array('expr_type' => $expr_type, 'base_expr' => $base_expr);
}
return array('option' => $option, 'warning' => $warning, 'object_list' => $resultList);
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* DuplicateProcessor.php
*
* This file implements the processor for the DUPLICATE statements.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/SetProcessor.php';
/**
*
* This class processes the DUPLICATE statements.
*
* @author arothe
*
*/
class DuplicateProcessor extends SetProcessor {
public function process($tokens) {
return parent::process($tokens, false);
}
}

View File

@@ -0,0 +1,145 @@
<?php
/**
* ExplainProcessor.php
*
* This file implements the processor for the EXPLAIN statements.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/AbstractProcessor.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
*
* This class processes the EXPLAIN statements.
*
* @author arothe
*
*/
class ExplainProcessor extends AbstractProcessor {
protected function isStatement($keys, $needle = "EXPLAIN") {
$pos = array_search($needle, $keys);
if (isset($keys[$pos + 1])) {
return in_array($keys[$pos + 1], array('SELECT', 'DELETE', 'INSERT', 'REPLACE', 'UPDATE'), true);
}
return false;
}
// TODO: refactor that function
public function process($tokens, $keys = array()) {
$base_expr = "";
$expr = array();
$currCategory = "";
if ($this->isStatement($keys)) {
foreach ($tokens as $token) {
$trim = trim($token);
$base_expr .= $token;
if ($trim === '') {
continue;
}
$upper = strtoupper($trim);
switch ($upper) {
case 'EXTENDED':
case 'PARTITIONS':
return array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $token);
break;
case 'FORMAT':
if ($currCategory === '') {
$currCategory = $upper;
$expr[] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
}
// else?
break;
case '=':
if ($currCategory === 'FORMAT') {
$expr[] = array('expr_type' => ExpressionType::OPERATOR, 'base_expr' => $trim);
}
// else?
break;
case 'TRADITIONAL':
case 'JSON':
if ($currCategory === 'FORMAT') {
$expr[] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
return array('expr_type' => ExpressionType::EXPRESSION, 'base_expr' => trim($base_expr),
'sub_tree' => $expr,
);
}
// else?
break;
default:
// ignore the other stuff
break;
}
}
return empty($expr) ? null : $expr;
}
foreach ($tokens as $token) {
$trim = trim($token);
if ($trim === '') {
continue;
}
switch ($currCategory) {
case 'TABLENAME':
$currCategory = 'WILD';
$expr[] = array('expr_type' => ExpressionType::COLREF, 'base_expr' => $trim);
break;
case '':
$currCategory = 'TABLENAME';
$expr[] = array('expr_type' => ExpressionType::TABLE, 'base_expr' => $trim);
break;
default:
break;
}
}
return empty($expr) ? null : $expr;
}
}

View File

@@ -0,0 +1,400 @@
<?php
/**
* ExpressionListProcessor.php
*
* This file implements the processor for expression lists.
*
* Copyright (c) 2010-2012, Justin Swanhart
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
require_once dirname(__FILE__) . '/AbstractProcessor.php';
require_once dirname(__FILE__) . '/DefaultProcessor.php';
require_once dirname(__FILE__) . '/../utils/ExpressionToken.php';
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
/**
*
* This class processes expression lists.
*
* @author arothe
*
*/
class ExpressionListProcessor extends AbstractProcessor {
public function process($tokens) {
$resultList = array();
$skip_next = false;
$prev = new ExpressionToken();
foreach ($tokens as $k => $v) {
$curr = new ExpressionToken($k, $v);
if ($curr->isWhitespaceToken()) {
continue;
}
if ($skip_next) {
// skip the next non-whitespace token
$skip_next = false;
continue;
}
/* is it a subquery? */
if ($curr->isSubQueryToken()) {
$processor = new DefaultProcessor();
$curr->setSubTree($processor->process($this->removeParenthesisFromStart($curr->getTrim())));
$curr->setTokenType(ExpressionType::SUBQUERY);
} elseif ($curr->isEnclosedWithinParenthesis()) {
/* is it an in-list? */
$localTokenList = $this->splitSQLIntoTokens($this->removeParenthesisFromStart($curr->getTrim()));
if ($prev->getUpper() === 'IN') {
foreach ($localTokenList as $k => $v) {
$tmpToken = new ExpressionToken($k, $v);
if ($tmpToken->isCommaToken()) {
unset($localTokenList[$k]);
}
}
$localTokenList = array_values($localTokenList);
$curr->setSubTree($this->process($localTokenList));
$curr->setTokenType(ExpressionType::IN_LIST);
} elseif ($prev->getUpper() === 'AGAINST') {
$match_mode = false;
foreach ($localTokenList as $k => $v) {
$tmpToken = new ExpressionToken($k, $v);
switch ($tmpToken->getUpper()) {
case 'WITH':
$match_mode = 'WITH QUERY EXPANSION';
break;
case 'IN':
$match_mode = 'IN BOOLEAN MODE';
break;
default:
}
if ($match_mode !== false) {
unset($localTokenList[$k]);
}
}
$tmpToken = $this->process($localTokenList);
if ($match_mode !== false) {
$match_mode = new ExpressionToken(0, $match_mode);
$match_mode->setTokenType(ExpressionType::MATCH_MODE);
$tmpToken[] = $match_mode->toArray();
}
$curr->setSubTree($tmpToken);
$curr->setTokenType(ExpressionType::MATCH_ARGUMENTS);
$prev->setTokenType(ExpressionType::SIMPLE_FUNCTION);
} elseif ($prev->isColumnReference() || $prev->isFunction() || $prev->isAggregateFunction()) {
// if we have a colref followed by a parenthesis pair,
// it isn't a colref, it is a user-function
// TODO: this should be a method, because we need the same code
// below for unspecified tokens (expressions).
$localExpr = new ExpressionToken();
$tmpExprList = array();
foreach ($localTokenList as $k => $v) {
$tmpToken = new ExpressionToken($k, $v);
if (!$tmpToken->isCommaToken()) {
$localExpr->addToken($v);
$tmpExprList[] = $v;
} else {
// an expression could have multiple parts split by operands
// if we have a comma, it is a split-point for expressions
$tmpExprList = array_values($tmpExprList);
$localExprList = $this->process($tmpExprList);
if (count($localExprList) > 1) {
$localExpr->setSubTree($localExprList);
$localExpr->setTokenType(ExpressionType::EXPRESSION);
$localExprList = $localExpr->toArray();
$localExprList['alias'] = false;
$localExprList = array($localExprList);
}
if (!$curr->getSubTree()) {
$curr->setSubTree($localExprList);
} else {
$tmpExprList = $curr->getSubTree();
$curr->setSubTree(array_merge($tmpExprList, $localExprList));
}
$tmpExprList = array();
$localExpr = new ExpressionToken();
}
}
$tmpExprList = array_values($tmpExprList);
$localExprList = $this->process($tmpExprList);
if (count($localExprList) > 1) {
$localExpr->setSubTree($localExprList);
$localExpr->setTokenType(ExpressionType::EXPRESSION);
$localExprList = $localExpr->toArray();
$localExprList['alias'] = false;
$localExprList = array($localExprList);
}
if (!$curr->getSubTree()) {
$curr->setSubTree($localExprList);
} else {
$tmpExprList = $curr->getSubTree();
$curr->setSubTree(array_merge($tmpExprList, $localExprList));
}
$prev->setSubTree($curr->getSubTree());
if ($prev->isColumnReference()) {
$prev->setTokenType(ExpressionType::SIMPLE_FUNCTION);
$prev->setNoQuotes(null);
}
array_pop($resultList);
$curr = $prev;
}
// we have parenthesis, but it seems to be an expression
if ($curr->isUnspecified()) {
// TODO: the localTokenList could contain commas and further expressions,
// we must handle that like function parameters (see above)!
// this should solve issue 51
$curr->setSubTree($this->process($localTokenList));
$curr->setTokenType(ExpressionType::BRACKET_EXPRESSION);
}
} elseif ($curr->isVariableToken()) {
// a variable
// it can be quoted
$curr->setTokenType($this->getVariableType($curr->getUpper()));
$curr->setSubTree(false);
$curr->setNoQuotes(trim(trim($curr->getToken()), '@'), "`'\"");
} else {
/* it is either an operator, a colref or a constant */
switch ($curr->getUpper()) {
case '*':
$curr->setSubTree(false); // o subtree
// single or first element of expression list -> all-column-alias
if (empty($resultList)) {
$curr->setTokenType(ExpressionType::COLREF);
break;
}
// if the last token is colref, const or expression
// then * is an operator
// but if the previous colref ends with a dot, the * is the all-columns-alias
if (!$prev->isColumnReference() && !$prev->isConstant() && !$prev->isExpression()
&& !$prev->isBracketExpression() && !$prev->isAggregateFunction() && !$prev->isVariable()) {
$curr->setTokenType(ExpressionType::COLREF);
break;
}
if ($prev->isColumnReference() && $prev->endsWith(".")) {
$prev->addToken('*'); // tablealias dot *
continue 2; // skip the current token
}
$curr->setTokenType(ExpressionType::OPERATOR);
break;
case ':=':
case 'AND':
case '&&':
case 'BETWEEN':
case 'AND':
case 'BINARY':
case '&':
case '~':
case '|':
case '^':
case 'DIV':
case '/':
case '<=>':
case '=':
case '>=':
case '>':
case 'IS':
case 'NOT':
case '<<':
case '<=':
case '<':
case 'LIKE':
case '%':
case '!=':
case '<>':
case 'REGEXP':
case '!':
case '||':
case 'OR':
case '>>':
case 'RLIKE':
case 'SOUNDS':
case 'XOR':
case 'IN':
$curr->setSubTree(false);
$curr->setTokenType(ExpressionType::OPERATOR);
break;
case 'NULL':
$curr->setSubTree(false);
$curr->setTokenType(ExpressionType::CONSTANT);
break;
case '-':
case '+':
// differ between preceding sign and operator
$curr->setSubTree(false);
if ($prev->isColumnReference() || $prev->isFunction() || $prev->isAggregateFunction()
|| $prev->isConstant() || $prev->isSubQuery() || $prev->isExpression()
|| $prev->isBracketExpression() || $prev->isVariable()) {
$curr->setTokenType(ExpressionType::OPERATOR);
} else {
$curr->setTokenType(ExpressionType::SIGN);
}
break;
default:
$curr->setSubTree(false);
switch ($curr->getToken(0)) {
case "'":
case '"':
// it is a string literal
$curr->setTokenType(ExpressionType::CONSTANT);
break;
case '`':
// it is an escaped colum name
$curr->setTokenType(ExpressionType::COLREF);
$curr->setNoQuotes($curr->getToken());
break;
default:
if (is_numeric($curr->getToken())) {
if ($prev->isSign()) {
$prev->addToken($curr->getToken()); // it is a negative numeric constant
$prev->setTokenType(ExpressionType::CONSTANT);
continue 3;
// skip current token
} else {
$curr->setTokenType(ExpressionType::CONSTANT);
}
} else {
$curr->setTokenType(ExpressionType::COLREF);
$curr->setNoQuotes($curr->getToken());
}
break;
}
}
}
/* is a reserved word? */
if (!$curr->isOperator() && !$curr->isInList() && !$curr->isFunction() && !$curr->isAggregateFunction()
&& PHPSQLParserConstants::isReserved($curr->getUpper())) {
if (PHPSQLParserConstants::isAggregateFunction($curr->getUpper())) {
$curr->setTokenType(ExpressionType::AGGREGATE_FUNCTION);
$curr->setNoQuotes(null);
} elseif ($curr->getUpper() === 'NULL') {
// it is a reserved word, but we would like to set it as constant
$curr->setTokenType(ExpressionType::CONSTANT);
} else {
if (PHPSQLParserConstants::isParameterizedFunction($curr->getUpper())) {
// issue 60: check functions with parameters
// -> colref (we check parameters later)
// -> if there is no parameter, we leave the colref
$curr->setTokenType(ExpressionType::COLREF);
} elseif (PHPSQLParserConstants::isFunction($curr->getUpper())) {
$curr->setTokenType(ExpressionType::SIMPLE_FUNCTION);
$curr->setNoQuotes(null);
} else {
$curr->setTokenType(ExpressionType::RESERVED);
$curr->setNoQuotes(null);
}
}
}
// issue 94, INTERVAL 1 MONTH
if ($curr->isConstant() && PHPSQLParserConstants::isParameterizedFunction($prev->getUpper())) {
$prev->setTokenType(ExpressionType::RESERVED);
$prev->setNoQuotes(null);
}
if ($prev->isConstant() && PHPSQLParserConstants::isParameterizedFunction($curr->getUpper())) {
$curr->setTokenType(ExpressionType::RESERVED);
$curr->setNoQuotes(null);
}
if ($curr->isUnspecified()) {
$curr->setTokenType(ExpressionType::EXPRESSION);
$curr->setNoQuotes(null);
$curr->setSubTree($this->process($this->splitSQLIntoTokens($curr->getTrim())));
}
$resultList[] = $curr;
$prev = $curr;
} // end of for-loop
return $this->toArray($resultList);
}
}

Some files were not shown because too many files have changed in this diff Show More