Merge pull request #249 from shreesh-webkul/qlo-parser-sql
Updated Sql Parser Library
This commit is contained in:
@@ -2169,8 +2169,8 @@ class ToolsCore
|
||||
public static function parserSQL($sql)
|
||||
{
|
||||
if (strlen($sql) > 0) {
|
||||
require_once(_PS_TOOL_DIR_.'parser_sql/PHPSQLParser.php');
|
||||
$parser = new PHPSQLParser($sql);
|
||||
require_once _PS_TOOL_DIR_.'parser_sql/php_sql_parser_autoload.php';
|
||||
$parser = new PHPSQLParser\PHPSQLParser($sql);
|
||||
return $parser->parsed;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,49 +1,27 @@
|
||||
Copyright (c) 2010-2014 André Rothe
|
||||
Copyright (c) 2014, Justin Swanhart <greenlion@gmail.com> and André Rothe <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:
|
||||
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.
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
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.
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
Copyright (c) 2010-2014 Justin Swanhart and André Rothe
|
||||
All rights reserved.
|
||||
* 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.
|
||||
|
||||
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.
|
||||
* Neither the name of the {organization} nor the names of its
|
||||
contributors may 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.
|
||||
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.
|
||||
|
||||
57
tools/parser_sql/Options.php
Normal file
57
tools/parser_sql/Options.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @author mfris
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author mfris
|
||||
* @package PHPSQLParser
|
||||
*/
|
||||
final class Options
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* @const string
|
||||
*/
|
||||
const CONSISTENT_SUB_TREES = 'consistent_sub_trees';
|
||||
|
||||
/**
|
||||
* @const string
|
||||
*/
|
||||
const ANSI_QUOTES = 'ansi_quotes';
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $options)
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getConsistentSubtrees()
|
||||
{
|
||||
return (isset($this->options[self::CONSISTENT_SUB_TREES]) && $this->options[self::CONSISTENT_SUB_TREES]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getANSIQuotes()
|
||||
{
|
||||
return (isset($this->options[self::ANSI_QUOTES]) && $this->options[self::ANSI_QUOTES]);
|
||||
}
|
||||
}
|
||||
@@ -35,17 +35,26 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser;
|
||||
use PHPSQLParser\exceptions\UnsupportedFeatureException;
|
||||
use PHPSQLParser\builders\SelectStatementBuilder;
|
||||
use PHPSQLParser\builders\DeleteStatementBuilder;
|
||||
use PHPSQLParser\builders\TruncateStatementBuilder;
|
||||
use PHPSQLParser\builders\UpdateStatementBuilder;
|
||||
use PHPSQLParser\builders\InsertStatementBuilder;
|
||||
use PHPSQLParser\builders\CreateStatementBuilder;
|
||||
use PHPSQLParser\builders\DropStatementBuilder;
|
||||
use PHPSQLParser\builders\RenameStatementBuilder;
|
||||
use PHPSQLParser\builders\ReplaceStatementBuilder;
|
||||
use PHPSQLParser\builders\ShowStatementBuilder;
|
||||
use PHPSQLParser\builders\BracketStatementBuilder;
|
||||
use PHPSQLParser\builders\UnionStatementBuilder;
|
||||
use PHPSQLParser\builders\UnionAllStatementBuilder;
|
||||
use PHPSQLParser\builders\AlterStatementBuilder;
|
||||
|
||||
/**
|
||||
* This class generates SQL from the output of the PHPSQLParser.
|
||||
@@ -66,35 +75,60 @@ class PHPSQLCreator {
|
||||
$k = key($parsed);
|
||||
switch ($k) {
|
||||
|
||||
case "UNION":
|
||||
case "UNION ALL":
|
||||
throw new UnsupportedFeatureException($k);
|
||||
break;
|
||||
case "SELECT":
|
||||
$builder = new SelectStatementBuilder($parsed);
|
||||
case 'UNION':
|
||||
$builder = new UnionStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case 'UNION ALL':
|
||||
$builder = new UnionAllStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case "INSERT":
|
||||
$builder = new InsertStatementBuilder($parsed);
|
||||
case 'SELECT':
|
||||
$builder = new SelectStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case "DELETE":
|
||||
$builder = new DeleteStatementBuilder($parsed);
|
||||
case 'INSERT':
|
||||
$builder = new InsertStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case "UPDATE":
|
||||
$builder = new UpdateStatementBuilder($parsed);
|
||||
case 'REPLACE':
|
||||
$builder = new ReplaceStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case "RENAME":
|
||||
$this->created = $this->processRenameTableStatement($parsed);
|
||||
break;
|
||||
case "SHOW":
|
||||
$builder = new ShowStatementBuilder($parsed);
|
||||
case 'DELETE':
|
||||
$builder = new DeleteStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case "CREATE":
|
||||
$builder = new CreateStatementBuilder($parsed);
|
||||
case 'TRUNCATE':
|
||||
$builder = new TruncateStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case 'UPDATE':
|
||||
$builder = new UpdateStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case 'RENAME':
|
||||
$builder = new RenameStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case 'SHOW':
|
||||
$builder = new ShowStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case 'CREATE':
|
||||
$builder = new CreateStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case 'BRACKET':
|
||||
$builder = new BracketStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case 'DROP':
|
||||
$builder = new DropStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
case 'ALTER':
|
||||
$builder = new AlterStatementBuilder();
|
||||
$this->created = $builder->build($parsed);
|
||||
break;
|
||||
default:
|
||||
@@ -103,31 +137,6 @@ class PHPSQLCreator {
|
||||
}
|
||||
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'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* php-sql-parser.php
|
||||
* PHPSQLParser.php
|
||||
*
|
||||
* A pure PHP SQL (non validating) parser w/ focus on MySQL dialect of SQL
|
||||
*
|
||||
@@ -32,15 +32,17 @@
|
||||
* 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 $
|
||||
* @version SVN: $Id$
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/positions/PositionCalculator.php';
|
||||
require_once dirname(__FILE__) . '/processors/DefaultProcessor.php';
|
||||
namespace PHPSQLParser;
|
||||
use PHPSQLParser\positions\PositionCalculator;
|
||||
use PHPSQLParser\processors\DefaultProcessor;
|
||||
use PHPSQLParser\utils\PHPSQLParserConstants;
|
||||
|
||||
/**
|
||||
* This class implements the parser functionality.
|
||||
@@ -54,34 +56,42 @@ 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.
|
||||
* @var Options
|
||||
*/
|
||||
public function __construct($sql = false, $calcPositions = false) {
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Constructor. It simply calls the parse() function.
|
||||
* Use the public variable $parsed to get the output.
|
||||
*
|
||||
* @param String|bool $sql The SQL statement.
|
||||
* @param bool $calcPositions True, if the output should contain [position], false otherwise.
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($sql = false, $calcPositions = false, array $options = array()) {
|
||||
$this->options = new Options($options);
|
||||
|
||||
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
|
||||
* 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();
|
||||
$processor = new DefaultProcessor($this->options);
|
||||
$queries = $processor->process($sql);
|
||||
|
||||
// calc the positions of some important tokens
|
||||
@@ -94,5 +104,36 @@ class PHPSQLParser {
|
||||
$this->parsed = $queries;
|
||||
return $this->parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a custom function to the parser. no return value
|
||||
*
|
||||
* @param String $token The name of the function to add
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function addCustomFunction($token) {
|
||||
PHPSQLParserConstants::getInstance()->addCustomFunction($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a custom function from the parser. no return value
|
||||
*
|
||||
* @param String $token The name of the function to remove
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function removeCustomFunction($token) {
|
||||
PHPSQLParserConstants::getInstance()->removeCustomFunction($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of custom functions
|
||||
*
|
||||
* @return array Returns an array of all custom functions
|
||||
*/
|
||||
public function getCustomFunctions() {
|
||||
return PHPSQLParserConstants::getInstance()->getCustomFunctions();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -35,10 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for aliases.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
@@ -47,19 +49,19 @@
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class AliasBuilder {
|
||||
class AliasBuilder implements Builder {
|
||||
|
||||
public function hasAlias($parsed) {
|
||||
return isset($parsed['alias']);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if (!isset($parsed['alias']) || $parsed['alias'] === false) {
|
||||
return "";
|
||||
}
|
||||
$sql = "";
|
||||
if ($parsed['alias']['as']) {
|
||||
$sql .= " as";
|
||||
$sql .= " AS";
|
||||
}
|
||||
$sql .= " " . $parsed['alias']['name'];
|
||||
return $sql;
|
||||
|
||||
63
tools/parser_sql/builders/AliasReferenceBuilder.php
Normal file
63
tools/parser_sql/builders/AliasReferenceBuilder.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* AliasReferenceBuilder.php
|
||||
*
|
||||
* Builds Alias 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for alias 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 AliasReferenceBuilder implements Builder {
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::ALIAS) {
|
||||
return "";
|
||||
}
|
||||
$sql = $parsed['base_expr'];
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
?>
|
||||
35
tools/parser_sql/builders/AlterBuilder.php
Normal file
35
tools/parser_sql/builders/AlterBuilder.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* 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 AlterBuilder implements Builder
|
||||
{
|
||||
public function build(array $parsed)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
foreach ($parsed as $term) {
|
||||
if ($term === ' ') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (substr($term, 0, 1) === '(' ||
|
||||
strpos($term, "\n") !== false) {
|
||||
$sql = rtrim($sql);
|
||||
}
|
||||
|
||||
$sql .= $term . ' ';
|
||||
}
|
||||
|
||||
$sql = rtrim($sql);
|
||||
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
24
tools/parser_sql/builders/AlterStatementBuilder.php
Normal file
24
tools/parser_sql/builders/AlterStatementBuilder.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
class AlterStatementBuilder implements Builder
|
||||
{
|
||||
protected function buildSubTree($parsed) {
|
||||
$builder = new SubTreeBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
private function buildAlter($parsed)
|
||||
{
|
||||
$builder = new AlterBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed)
|
||||
{
|
||||
$alter = $parsed['ALTER'];
|
||||
$sql = $this->buildAlter($alter);
|
||||
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
78
tools/parser_sql/builders/BracketStatementBuilder.php
Normal file
78
tools/parser_sql/builders/BracketStatementBuilder.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* BracketStatementBuilder.php
|
||||
*
|
||||
* Builds the parentheses around a 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the parentheses around a 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 BracketStatementBuilder implements Builder {
|
||||
|
||||
protected function buildSelectBracketExpression($parsed) {
|
||||
$builder = new SelectBracketExpressionBuilder();
|
||||
return $builder->build($parsed, " ");
|
||||
}
|
||||
|
||||
protected function buildSelectStatement($parsed) {
|
||||
$builder = new SelectStatementBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = "";
|
||||
foreach ($parsed['BRACKET'] as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildSelectBracketExpression($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('BRACKET', $k, $v, 'expr_type');
|
||||
}
|
||||
}
|
||||
return trim($sql . " " . trim($this->buildSelectStatement($parsed)));
|
||||
}
|
||||
}
|
||||
?>
|
||||
63
tools/parser_sql/builders/Builder.php
Normal file
63
tools/parser_sql/builders/Builder.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Builder.php
|
||||
*
|
||||
* Interface declaration for all builder classes.
|
||||
*
|
||||
* 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* A builder can create a part of an SQL statement. The necessary information
|
||||
* are provided by the function parameter as array. This array is a subtree
|
||||
* of the PHPSQLParser output.
|
||||
*
|
||||
* @author André Rothe <andre.rothe@phosco.info>
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*/
|
||||
interface Builder {
|
||||
/**
|
||||
* Builds a part of an SQL statement.
|
||||
*
|
||||
* @param array $parsed a subtree of the PHPSQLParser output array
|
||||
*
|
||||
* @return A string, which contains a part of an SQL statement.
|
||||
*/
|
||||
public function build(array $parsed);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -35,16 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the CHARACTER SET statement part of CREATE TABLE.
|
||||
@@ -54,7 +51,7 @@ require_once dirname(__FILE__) . '/IndexTypeBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class CharacterSetBuilder {
|
||||
class CharacterSetBuilder implements Builder {
|
||||
|
||||
protected function buildConstant($parsed) {
|
||||
$builder = new ConstantBuilder();
|
||||
@@ -71,7 +68,7 @@ class CharacterSetBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::CHARSET) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,14 +35,14 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the CHECK statement part of CREATE TABLE.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
@@ -51,7 +51,7 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class CheckBuilder {
|
||||
class CheckBuilder implements Builder {
|
||||
|
||||
protected function buildSelectBracketExpression($parsed) {
|
||||
$builder = new SelectBracketExpressionBuilder();
|
||||
@@ -63,7 +63,7 @@ class CheckBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::CHECK) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,15 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the collation statement part of CREATE TABLE.
|
||||
@@ -53,7 +51,7 @@ require_once dirname(__FILE__) . '/ReservedBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class CollationBuilder {
|
||||
class CollationBuilder implements Builder {
|
||||
|
||||
protected function buildOperator($parsed) {
|
||||
$builder = new OperatorBuilder();
|
||||
@@ -70,7 +68,7 @@ class CollationBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::COLLATE) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,14 +35,14 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the columndefinition statement part
|
||||
* of CREATE TABLE. You can overwrite all functions to achieve another handling.
|
||||
@@ -51,7 +51,7 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ColumnDefinitionBuilder {
|
||||
class ColumnDefinitionBuilder implements Builder {
|
||||
|
||||
protected function buildColRef($parsed) {
|
||||
$builder = new ColumnReferenceBuilder();
|
||||
@@ -63,7 +63,7 @@ class ColumnDefinitionBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::COLDEF) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,13 +35,14 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
|
||||
require_once dirname(__FILE__) . '/IndexColumnBuilder.php';
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for column-list parts of CREATE TABLE.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
@@ -50,29 +51,35 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ColumnListBuilder {
|
||||
class ColumnListBuilder implements Builder {
|
||||
|
||||
protected function buildIndexColumn($parsed) {
|
||||
$builder = new IndexColumnBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
protected function buildColumnReference($parsed) {
|
||||
$builder = new ColumnReferenceBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed, $delim = ', ') {
|
||||
if ($parsed['expr_type'] !== ExpressionType::COLUMN_LIST) {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
$sql = "";
|
||||
$sql = '';
|
||||
foreach ($parsed['sub_tree'] as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildIndexColumn($v);
|
||||
$sql .= $this->buildColumnReference($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('CREATE TABLE column-list subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= " ";
|
||||
}
|
||||
return "(" . substr($sql, 0, -1) . ")";
|
||||
$sql .= $delim;
|
||||
}
|
||||
return '(' . substr($sql, 0, -strlen($delim)) . ')';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/AliasBuilder.php';
|
||||
require_once dirname(__FILE__) . '/DirectionBuilder.php';
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for column references.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
@@ -50,25 +50,19 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @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);
|
||||
}
|
||||
class ColumnReferenceBuilder implements Builder {
|
||||
|
||||
protected function buildAlias($parsed) {
|
||||
$builder = new AliasBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::COLREF) {
|
||||
return "";
|
||||
}
|
||||
$sql = $parsed['base_expr'];
|
||||
$sql .= $this->buildAlias($parsed);
|
||||
$sql .= $this->buildDirection($parsed);
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,12 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/SubTreeBuilder.php';
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for bracket expressions within a column type.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
@@ -49,14 +50,14 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ColumnTypeBracketExpressionBuilder {
|
||||
class ColumnTypeBracketExpressionBuilder implements Builder {
|
||||
|
||||
protected function buildSubTree($parsed, $delim) {
|
||||
$builder = new SubTreeBuilder();
|
||||
return $builder->build($parsed, $delim);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::BRACKET_EXPRESSION) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,15 +35,14 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the column type statement part of CREATE TABLE.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
@@ -52,7 +51,7 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ColumnTypeBuilder {
|
||||
class ColumnTypeBuilder implements Builder {
|
||||
|
||||
protected function buildColumnTypeBracketExpression($parsed) {
|
||||
$builder = new ColumnTypeBracketExpressionBuilder();
|
||||
@@ -69,7 +68,19 @@ class ColumnTypeBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
protected function buildDefaultValue($parsed) {
|
||||
$builder = new DefaultValueBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildCharacterSet($parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::CHARSET) {
|
||||
return "";
|
||||
}
|
||||
return $parsed['base_expr'];
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::COLUMN_TYPE) {
|
||||
return "";
|
||||
}
|
||||
@@ -79,7 +90,9 @@ class ColumnTypeBuilder {
|
||||
$sql .= $this->buildDataType($v);
|
||||
$sql .= $this->buildColumnTypeBracketExpression($v);
|
||||
$sql .= $this->buildReserved($v);
|
||||
|
||||
$sql .= $this->buildDefaultValue($v);
|
||||
$sql .= $this->buildCharacterSet($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('CREATE TABLE column-type subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/AliasBuilder.php';
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for constants.
|
||||
@@ -50,14 +50,14 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ConstantBuilder {
|
||||
class ConstantBuilder implements Builder {
|
||||
|
||||
protected function buildAlias($parsed) {
|
||||
$builder = new AliasBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::CONSTANT) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
require_once dirname(__FILE__) . '/ConstantBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the constraint statement part of CREATE TABLE.
|
||||
@@ -50,18 +50,18 @@ require_once dirname(__FILE__) . '/ConstantBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ConstraintBuilder {
|
||||
class ConstraintBuilder implements Builder {
|
||||
|
||||
protected function buildConstant($parsed) {
|
||||
$builder = new ConstantBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::CONSTRAINT) {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
$sql = $this->buildConstant($parsed['sub_tree']);
|
||||
$sql = $parsed['sub_tree'] === false ? '' : $this->buildConstant($parsed['sub_tree']);
|
||||
return "CONSTRAINT" . (empty($sql) ? '' : (' ' . $sql));
|
||||
}
|
||||
|
||||
|
||||
@@ -35,13 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
require_once dirname(__FILE__) . '/CreateTableBuilder.php';
|
||||
require_once dirname(__FILE__) . '/SubTreeBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the [CREATE] part. You can overwrite
|
||||
@@ -51,27 +50,36 @@ require_once dirname(__FILE__) . '/SubTreeBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class CreateBuilder {
|
||||
class CreateBuilder implements Builder {
|
||||
|
||||
protected function buildCreateTable($parsed) {
|
||||
$builder = new CreateTableBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildCreateIndex($parsed) {
|
||||
$builder = new CreateIndexBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildSubTree($parsed) {
|
||||
$builder = new SubTreeBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $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']);
|
||||
$sql .= ' ' . $this->buildCreateTable($parsed['TABLE']);
|
||||
}
|
||||
// TODO: add more expr_types here (like VIEW), if available
|
||||
if ($create['expr_type'] === ExpressionType::INDEX) {
|
||||
$sql .= ' ' . $this->buildCreateIndex($parsed['INDEX']);
|
||||
}
|
||||
|
||||
// TODO: add more expr_types here (like VIEW), if available in parser output
|
||||
return "CREATE " . $sql;
|
||||
}
|
||||
|
||||
|
||||
80
tools/parser_sql/builders/CreateIndexBuilder.php
Normal file
80
tools/parser_sql/builders/CreateIndexBuilder.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* CreateIndex.php
|
||||
*
|
||||
* Builds the CREATE INDEX 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the CREATE INDEX 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 CreateIndexBuilder implements Builder {
|
||||
|
||||
protected function buildIndexType($parsed) {
|
||||
$builder = new CreateIndexTypeBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildIndexTable($parsed) {
|
||||
$builder = new CreateIndexTableBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildIndexOptions($parsed) {
|
||||
$builder = new CreateIndexOptionsBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = $parsed['name'];
|
||||
$sql .= ' ' . $this->buildIndexType($parsed);
|
||||
$sql = trim($sql);
|
||||
$sql .= ' ' . $this->buildIndexTable($parsed);
|
||||
$sql = trim($sql);
|
||||
$sql .= $this->buildIndexOptions($parsed);
|
||||
return trim($sql);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
109
tools/parser_sql/builders/CreateIndexOptionsBuilder.php
Normal file
109
tools/parser_sql/builders/CreateIndexOptionsBuilder.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* CreateIndexOptionsBuilder.php
|
||||
*
|
||||
* Builds index options part of a CREATE INDEX 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the index options of a CREATE INDEX
|
||||
* 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 CreateIndexOptionsBuilder implements Builder {
|
||||
|
||||
protected function buildIndexParser($parsed) {
|
||||
$builder = new IndexParserBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildIndexSize($parsed) {
|
||||
$builder = new IndexSizeBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildIndexType($parsed) {
|
||||
$builder = new IndexTypeBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildIndexComment($parsed) {
|
||||
$builder = new IndexCommentBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildIndexAlgorithm($parsed) {
|
||||
$builder = new IndexAlgorithmBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildIndexLock($parsed) {
|
||||
$builder = new IndexLockBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['options'] === false) {
|
||||
return '';
|
||||
}
|
||||
$sql = '';
|
||||
foreach ($parsed['options'] as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildIndexAlgorithm($v);
|
||||
$sql .= $this->buildIndexLock($v);
|
||||
$sql .= $this->buildIndexComment($v);
|
||||
$sql .= $this->buildIndexParser($v);
|
||||
$sql .= $this->buildIndexSize($v);
|
||||
$sql .= $this->buildIndexType($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('CREATE INDEX options', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= ' ';
|
||||
}
|
||||
return ' ' . substr($sql, 0, -1);
|
||||
}
|
||||
}
|
||||
?>
|
||||
72
tools/parser_sql/builders/CreateIndexTableBuilder.php
Normal file
72
tools/parser_sql/builders/CreateIndexTableBuilder.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* CreateIndexTable.php
|
||||
*
|
||||
* Builds the table part of a CREATE INDEX 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the table part of a CREATE INDEX 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 CreateIndexTableBuilder implements Builder {
|
||||
|
||||
protected function buildColumnList($parsed) {
|
||||
$builder = new ColumnListBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if (!isset($parsed['on']) || $parsed['on'] === false) {
|
||||
return '';
|
||||
}
|
||||
$table = $parsed['on'];
|
||||
if ($table['expr_type'] !== ExpressionType::TABLE) {
|
||||
return '';
|
||||
}
|
||||
return 'ON ' . $table['name'] . ' ' . $this->buildColumnList($table['sub_tree']);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
62
tools/parser_sql/builders/CreateIndexTypeBuilder.php
Normal file
62
tools/parser_sql/builders/CreateIndexTypeBuilder.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* CreateIndexTypeBuilder.php
|
||||
*
|
||||
* Builds index type part of a CREATE INDEX 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the index type of a CREATE INDEX
|
||||
* 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 CreateIndexTypeBuilder extends IndexTypeBuilder {
|
||||
|
||||
public function build(array $parsed) {
|
||||
if (!isset($parsed['index-type']) || $parsed['index-type'] === false) {
|
||||
return '';
|
||||
}
|
||||
return parent::build($parsed['index-type']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -35,13 +35,11 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/LikeBuilder.php';
|
||||
require_once dirname(__FILE__) . '/SelectStatementBuilder.php';
|
||||
require_once dirname(__FILE__) . '/CreateBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the whole Create statement. You can overwrite
|
||||
@@ -51,7 +49,7 @@ require_once dirname(__FILE__) . '/CreateBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class CreateStatementBuilder {
|
||||
class CreateStatementBuilder implements Builder {
|
||||
|
||||
protected function buildLIKE($parsed) {
|
||||
$builder = new LikeBuilder();
|
||||
@@ -67,8 +65,8 @@ class CreateStatementBuilder {
|
||||
$builder = new CreateBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = $this->buildCREATE($parsed);
|
||||
if (isset($parsed['LIKE'])) {
|
||||
$sql .= " " . $this->buildLIKE($parsed['LIKE']);
|
||||
|
||||
@@ -35,14 +35,11 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the CREATE TABLE statement. You can overwrite
|
||||
@@ -52,7 +49,7 @@ require_once dirname(__FILE__) . '/CreateTableOptionsBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class CreateTableBuilder {
|
||||
class CreateTableBuilder implements Builder {
|
||||
|
||||
protected function buildCreateTableDefinition($parsed) {
|
||||
$builder = new CreateTableDefinitionBuilder();
|
||||
@@ -63,19 +60,19 @@ class CreateTableBuilder {
|
||||
$builder = new CreateTableOptionsBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
|
||||
protected function buildCreateTableSelectOption($parsed) {
|
||||
$builder = new CreateTableSelectOptionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = $parsed['name'];
|
||||
$sql .= $this->buildCreateTableDefinition($parsed);
|
||||
$sql .= $this->buildCreateTableOptions($parsed);
|
||||
$sql .= $this->buildCreateTableSelectOption($parsed);
|
||||
return $sql;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -35,11 +35,11 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/TableBracketExpressionBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the create definitions of CREATE TABLE.
|
||||
@@ -49,14 +49,14 @@ require_once dirname(__FILE__) . '/TableBracketExpressionBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class CreateTableDefinitionBuilder {
|
||||
class CreateTableDefinitionBuilder implements Builder {
|
||||
|
||||
protected function buildTableBracketExpression($parsed) {
|
||||
$builder = new TableBracketExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if (!isset($parsed) || $parsed['create-def'] === false) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,14 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the table-options statement part of CREATE TABLE.
|
||||
@@ -52,23 +50,23 @@ require_once dirname(__FILE__) . '/CollationBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class CreateTableOptionsBuilder {
|
||||
class CreateTableOptionsBuilder implements Builder {
|
||||
|
||||
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'].
|
||||
@@ -79,8 +77,8 @@ class CreateTableOptionsBuilder {
|
||||
protected function getDelimiter($parsed) {
|
||||
return ($parsed['delim'] === false ? '' : (trim($parsed['delim']) . ' '));
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
|
||||
public function build(array $parsed) {
|
||||
if (!isset($parsed['options']) || $parsed['options'] === false) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,10 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the select-options statement part of CREATE TABLE.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
@@ -47,9 +49,9 @@
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class CreateTableSelectOptionBuilder {
|
||||
class CreateTableSelectOptionBuilder implements Builder {
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if (!isset($parsed['select-option']) || $parsed['select-option'] === false) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,11 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the data-type statement part of CREATE TABLE.
|
||||
@@ -49,9 +50,9 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class DataTypeBuilder {
|
||||
class DataTypeBuilder implements Builder {
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::DATA_TYPE) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,11 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for a database within SHOW statement.
|
||||
@@ -49,9 +50,9 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class DatabaseBuilder {
|
||||
class DatabaseBuilder implements Builder {
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::DATABASE) {
|
||||
return "";
|
||||
}
|
||||
|
||||
62
tools/parser_sql/builders/DefaultValueBuilder.php
Normal file
62
tools/parser_sql/builders/DefaultValueBuilder.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* DefaultValueBuilder.php
|
||||
*
|
||||
* Builds the default value statement part of a column of a 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the default value 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 DefaultValueBuilder implements Builder {
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::DEF_VALUE) {
|
||||
return "";
|
||||
}
|
||||
return $parsed['base_expr'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -35,10 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the [DELETE] part. You can overwrite
|
||||
* all functions to achieve another handling.
|
||||
@@ -47,14 +49,26 @@
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class DeleteBuilder {
|
||||
class DeleteBuilder implements Builder {
|
||||
|
||||
public function build($parsed) {
|
||||
$sql = "DELETE";
|
||||
foreach ($parsed['TABLES'] as $k => $v) {
|
||||
$sql .= $v . ",";
|
||||
public function build(array $parsed) {
|
||||
$sql = "DELETE ";
|
||||
$right = -1;
|
||||
|
||||
if ($parsed['options'] !== false) {
|
||||
foreach ($parsed['options'] as $k => $v) {
|
||||
$sql .= $v . " ";
|
||||
}
|
||||
}
|
||||
return substr($sql, 0, -1);
|
||||
|
||||
if ($parsed['tables'] !== false) {
|
||||
foreach ($parsed['tables'] as $k => $v) {
|
||||
$sql .= $v . ", ";
|
||||
$right = -2;
|
||||
}
|
||||
}
|
||||
|
||||
return substr($sql, 0, $right);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -35,13 +35,11 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/WhereBuilder.php';
|
||||
require_once dirname(__FILE__) . '/FromBuilder.php';
|
||||
require_once dirname(__FILE__) . '/DeleteBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the whole Delete statement. You can overwrite
|
||||
@@ -51,7 +49,7 @@ require_once dirname(__FILE__) . '/DeleteBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class DeleteStatementBuilder {
|
||||
class DeleteStatementBuilder implements Builder {
|
||||
|
||||
protected function buildWHERE($parsed) {
|
||||
$builder = new WhereBuilder();
|
||||
@@ -67,14 +65,14 @@ class DeleteStatementBuilder {
|
||||
$builder = new DeleteBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function processDeleteStatement($parsed) {
|
||||
$sql = $this->buildDELETE($parsed['DELETE']) . " " . $this->processFROM($parsed['FROM']);
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = $this->buildDELETE($parsed['DELETE']) . " " . $this->buildFROM($parsed['FROM']);
|
||||
if (isset($parsed['WHERE'])) {
|
||||
$sql .= " " . $this->processWHERE($parsed['WHERE']);
|
||||
$sql .= " " . $this->buildWHERE($parsed['WHERE']);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -35,10 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for directions (e.g. of the order-by clause).
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
@@ -47,9 +49,9 @@
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class DirectionBuilder {
|
||||
class DirectionBuilder implements Builder {
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if (!isset($parsed['direction']) || $parsed['direction'] === false) {
|
||||
return "";
|
||||
}
|
||||
|
||||
100
tools/parser_sql/builders/DropBuilder.php
Normal file
100
tools/parser_sql/builders/DropBuilder.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* DropBuilder.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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the [DROP] part. You can overwrite
|
||||
* all functions to achieve another handling.
|
||||
*/
|
||||
class DropBuilder implements Builder {
|
||||
|
||||
protected function buildDropIndex( $parsed ) {
|
||||
$builder = new DropIndexBuilder();
|
||||
|
||||
return $builder->build( $parsed );
|
||||
}
|
||||
|
||||
protected function buildReserved( $parsed ) {
|
||||
$builder = new ReservedBuilder();
|
||||
|
||||
return $builder->build( $parsed );
|
||||
}
|
||||
|
||||
protected function buildExpression( $parsed ) {
|
||||
$builder = new DropExpressionBuilder();
|
||||
|
||||
return $builder->build( $parsed );
|
||||
}
|
||||
|
||||
protected function buildSubTree( $parsed ) {
|
||||
$sql = '';
|
||||
foreach ( $parsed['sub_tree'] as $k => $v ) {
|
||||
$len = strlen( $sql );
|
||||
$sql .= $this->buildReserved( $v );
|
||||
$sql .= $this->buildExpression( $v );
|
||||
|
||||
if ( $len == strlen( $sql ) ) {
|
||||
throw new UnableToCreateSQLException( 'DROP subtree', $k, $v, 'expr_type' );
|
||||
}
|
||||
|
||||
$sql .= ' ';
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
public function build( array $parsed ) {
|
||||
$drop = $parsed['DROP'];
|
||||
$sql = $this->buildSubTree( $drop );
|
||||
|
||||
if ( $drop['expr_type'] === ExpressionType::INDEX ) {
|
||||
$sql .= '' . $this->buildDropIndex( $parsed['INDEX'] ) . ' ';
|
||||
}
|
||||
|
||||
return 'DROP ' . substr( $sql, 0, -1 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
103
tools/parser_sql/builders/DropExpressionBuilder.php
Normal file
103
tools/parser_sql/builders/DropExpressionBuilder.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* DropExpressionBuilder.php
|
||||
*
|
||||
* Builds the object list of a DROP 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the object list of a DROP 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 DropExpressionBuilder implements Builder {
|
||||
|
||||
protected function buildTable($parsed, $index) {
|
||||
$builder = new TableBuilder();
|
||||
return $builder->build($parsed, $index);
|
||||
}
|
||||
|
||||
protected function buildDatabase($parsed) {
|
||||
$builder = new DatabaseBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildSchema($parsed) {
|
||||
$builder = new SchemaBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildTemporaryTable($parsed) {
|
||||
$builder = new TempTableBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildView($parsed) {
|
||||
$builder = new ViewBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::EXPRESSION) {
|
||||
return "";
|
||||
}
|
||||
$sql = '';
|
||||
foreach ($parsed['sub_tree'] as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildTable($v, 0);
|
||||
$sql .= $this->buildView($v);
|
||||
$sql .= $this->buildSchema($v);
|
||||
$sql .= $this->buildDatabase($v);
|
||||
$sql .= $this->buildTemporaryTable($v, 0);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('DROP object-list subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= ', ';
|
||||
}
|
||||
return substr($sql, 0, -2);
|
||||
}
|
||||
}
|
||||
?>
|
||||
63
tools/parser_sql/builders/DropIndexBuilder.php
Normal file
63
tools/parser_sql/builders/DropIndexBuilder.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* DropIndexBuilder.php
|
||||
*
|
||||
* Builds the CREATE INDEX 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the DROP INDEX statement. You can overwrite
|
||||
* all functions to achieve another handling.
|
||||
*/
|
||||
class DropIndexBuilder implements Builder {
|
||||
|
||||
protected function buildIndexTable($parsed) {
|
||||
$builder = new DropIndexTableBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = $parsed['name'];
|
||||
$sql = trim($sql);
|
||||
$sql .= ' ' . $this->buildIndexTable($parsed);
|
||||
return trim($sql);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
67
tools/parser_sql/builders/DropIndexTableBuilder.php
Normal file
67
tools/parser_sql/builders/DropIndexTableBuilder.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* DropIndexTable.php
|
||||
*
|
||||
* Builds the table part of a CREATE INDEX 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the table part of a DROP INDEX 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 DropIndexTableBuilder implements Builder {
|
||||
|
||||
public function build(array $parsed) {
|
||||
if (!isset($parsed['on']) || $parsed['on'] === false) {
|
||||
return '';
|
||||
}
|
||||
$table = $parsed['on'];
|
||||
if ($table['expr_type'] !== ExpressionType::TABLE) {
|
||||
return '';
|
||||
}
|
||||
return 'ON ' . $table['name'];
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
63
tools/parser_sql/builders/DropStatementBuilder.php
Normal file
63
tools/parser_sql/builders/DropStatementBuilder.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* DropStatement.php
|
||||
*
|
||||
* Builds the DROP 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the whole DROP 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 DropStatementBuilder implements Builder {
|
||||
|
||||
protected function buildDROP( $parsed ) {
|
||||
$builder = new DropBuilder();
|
||||
return $builder->build( $parsed );
|
||||
}
|
||||
|
||||
public function build( array $parsed ) {
|
||||
return $this->buildDROP( $parsed );
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -35,11 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for a database within SHOW statement.
|
||||
@@ -49,9 +50,9 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class EngineBuilder {
|
||||
class EngineBuilder implements Builder {
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::ENGINE) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,16 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the FOREIGN KEY statement part of CREATE TABLE.
|
||||
@@ -54,7 +51,7 @@ require_once dirname(__FILE__) . '/ForeignRefBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ForeignKeyBuilder {
|
||||
class ForeignKeyBuilder implements Builder {
|
||||
|
||||
protected function buildConstant($parsed) {
|
||||
$builder = new ConstantBuilder();
|
||||
@@ -76,7 +73,7 @@ class ForeignKeyBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::FOREIGN_KEY) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,15 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the FOREIGN KEY REFERENCES statement
|
||||
@@ -54,7 +52,7 @@ require_once dirname(__FILE__) . '/ColumnListBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ForeignRefBuilder {
|
||||
class ForeignRefBuilder implements Builder {
|
||||
|
||||
protected function buildTable($parsed) {
|
||||
$builder = new TableBuilder();
|
||||
@@ -71,7 +69,7 @@ class ForeignRefBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::REFERENCE) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -31,18 +31,16 @@
|
||||
* 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 $
|
||||
*
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the [FROM] part. You can overwrite
|
||||
@@ -50,9 +48,9 @@ require_once dirname(__FILE__) . '/SubQueryBuilder.php';
|
||||
*
|
||||
* @author André Rothe <andre.rothe@phosco.info>
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*
|
||||
*/
|
||||
class FromBuilder {
|
||||
class FromBuilder implements Builder {
|
||||
|
||||
protected function buildTable($parsed, $key) {
|
||||
$builder = new TableBuilder();
|
||||
@@ -69,16 +67,41 @@ class FromBuilder {
|
||||
return $builder->build($parsed, $key);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $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 (array_key_exists("UNION ALL", $parsed) || array_key_exists("UNION", $parsed)) {
|
||||
foreach ($parsed as $union_type => $outer_v) {
|
||||
$first = true;
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('FROM', $k, $v, 'expr_type');
|
||||
foreach ($outer_v as $item) {
|
||||
if (!$first) {
|
||||
$sql .= " $union_type ";
|
||||
}
|
||||
else {
|
||||
$first = false;
|
||||
}
|
||||
|
||||
$select_builder = new SelectStatementBuilder();
|
||||
|
||||
$len = strlen($sql);
|
||||
$sql .= $select_builder->build($item);
|
||||
|
||||
if ($len === strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('FROM', $union_type, $outer_v, 'expr_type');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
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;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
|
||||
* Copyright (c) 2010-2015 Justin Swanhart and André Rothe
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,22 +33,15 @@
|
||||
* 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
|
||||
* @copyright 2010-2015 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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for function calls.
|
||||
@@ -58,13 +51,8 @@ require_once dirname(__FILE__) . '/DirectionBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class FunctionBuilder {
|
||||
class FunctionBuilder implements Builder {
|
||||
|
||||
protected function buildDirection($parsed) {
|
||||
$builder = new DirectionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildAlias($parsed) {
|
||||
$builder = new AliasBuilder();
|
||||
return $builder->build($parsed);
|
||||
@@ -99,15 +87,21 @@ class FunctionBuilder {
|
||||
$builder = new SelectBracketExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
|
||||
protected function buildSubQuery($parsed) {
|
||||
$builder = new SubQueryBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if (($parsed['expr_type'] !== ExpressionType::AGGREGATE_FUNCTION)
|
||||
&& ($parsed['expr_type'] !== ExpressionType::SIMPLE_FUNCTION)) {
|
||||
&& ($parsed['expr_type'] !== ExpressionType::SIMPLE_FUNCTION)
|
||||
&& ($parsed['expr_type'] !== ExpressionType::CUSTOM_FUNCTION)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if ($parsed['sub_tree'] === false) {
|
||||
return $parsed['base_expr'] . "()";
|
||||
return $parsed['base_expr'] . "()" . $this->buildAlias($parsed);
|
||||
}
|
||||
|
||||
$sql = "";
|
||||
@@ -115,6 +109,7 @@ class FunctionBuilder {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->build($v);
|
||||
$sql .= $this->buildConstant($v);
|
||||
$sql .= $this->buildSubQuery($v);
|
||||
$sql .= $this->buildColRef($v);
|
||||
$sql .= $this->buildReserved($v);
|
||||
$sql .= $this->buildSelectBracketExpression($v);
|
||||
@@ -126,7 +121,7 @@ class FunctionBuilder {
|
||||
|
||||
$sql .= ($this->isReserved($v) ? " " : ",");
|
||||
}
|
||||
return $parsed['base_expr'] . "(" . substr($sql, 0, -1) . ")" . $this->buildAlias($parsed) . $this->buildDirection($parsed);
|
||||
return $parsed['base_expr'] . "(" . substr($sql, 0, -1) . ")" . $this->buildAlias($parsed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
62
tools/parser_sql/builders/GroupByAliasBuilder.php
Normal file
62
tools/parser_sql/builders/GroupByAliasBuilder.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* GroupByAliasBuilder.php
|
||||
*
|
||||
* Builds an alias within a 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for an alias within 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 GroupByAliasBuilder implements Builder {
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::ALIAS) {
|
||||
return "";
|
||||
}
|
||||
return $parsed['base_expr'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -35,14 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the GROUP-BY clause.
|
||||
@@ -52,7 +50,7 @@ require_once dirname(__FILE__) . '/FunctionBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class GroupByBuilder {
|
||||
class GroupByBuilder implements Builder {
|
||||
|
||||
protected function buildColRef($parsed) {
|
||||
$builder = new ColumnReferenceBuilder();
|
||||
@@ -68,15 +66,27 @@ class GroupByBuilder {
|
||||
$builder = new FunctionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
|
||||
protected function buildGroupByAlias($parsed) {
|
||||
$builder = new GroupByAliasBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildGroupByExpression($parsed) {
|
||||
$builder = new GroupByExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = "";
|
||||
foreach ($parsed as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildColRef($v);
|
||||
$sql .= $this->buildPosition($v);
|
||||
$sql .= $this->buildFunction($v);
|
||||
|
||||
$sql .= $this->buildGroupByExpression($v);
|
||||
$sql .= $this->buildGroupByAlias($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('GROUP', $k, $v, 'expr_type');
|
||||
}
|
||||
@@ -86,6 +96,6 @@ class GroupByBuilder {
|
||||
$sql = substr($sql, 0, -2);
|
||||
return "GROUP BY " . $sql;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
89
tools/parser_sql/builders/GroupByExpressionBuilder.php
Normal file
89
tools/parser_sql/builders/GroupByExpressionBuilder.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* GroupByExpressionBuilder.php
|
||||
*
|
||||
* Builds an expression within a 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 oohook <oohook@163.com>
|
||||
* @copyright 2010-2016 Justin Swanhart and André Rothe
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
* @version SVN: $Id$
|
||||
* @example group by id desc
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for an alias within the GROUP-BY clause.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
*
|
||||
* @author oohook <oohook@163.com>
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class GroupByExpressionBuilder implements Builder {
|
||||
|
||||
protected function buildColRef($parsed) {
|
||||
$builder = new ColumnReferenceBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildReserved($parsed) {
|
||||
$builder = new ReservedBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $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->buildReserved($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('GROUP expression subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= " ";
|
||||
}
|
||||
|
||||
$sql = substr($sql, 0, -1);
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
?>
|
||||
90
tools/parser_sql/builders/HavingBracketExpressionBuilder.php
Normal file
90
tools/parser_sql/builders/HavingBracketExpressionBuilder.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* HavingBracketExpressionBuilder.php
|
||||
*
|
||||
* Builds bracket expressions within the HAVING 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for bracket expressions within the HAVING part.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
*
|
||||
* @author Ian Barker <ian@theorganicagency.com>
|
||||
* @author André Rothe <andre.rothe@phosco.info>
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class HavingBracketExpressionBuilder extends WhereBracketExpressionBuilder {
|
||||
|
||||
protected function buildHavingExpression($parsed) {
|
||||
$builder = new HavingExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $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->buildHavingExpression($v);
|
||||
$sql .= $this->build($v);
|
||||
$sql .= $this->buildUserVariable($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('HAVING expression subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= " ";
|
||||
}
|
||||
|
||||
$sql = "(" . substr($sql, 0, -1) . ")";
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
97
tools/parser_sql/builders/HavingBuilder.php
Normal file
97
tools/parser_sql/builders/HavingBuilder.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* HavingBuilder.php
|
||||
*
|
||||
* Builds the HAVING 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the HAVING part.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
*
|
||||
* @author Ian Barker <ian@theorganicagency.com>
|
||||
* @author André Rothe <andre.rothe@phosco.info>
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class HavingBuilder extends WhereBuilder {
|
||||
|
||||
protected function buildAliasReference($parsed) {
|
||||
$builder = new AliasReferenceBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildHavingExpression($parsed) {
|
||||
$builder = new HavingExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildHavingBracketExpression($parsed) {
|
||||
$builder = new HavingBracketExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = "HAVING ";
|
||||
foreach ($parsed as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
|
||||
$sql .= $this->buildAliasReference($v);
|
||||
$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->buildHavingExpression($v);
|
||||
$sql .= $this->buildHavingBracketExpression($v);
|
||||
$sql .= $this->buildUserVariable($v);
|
||||
|
||||
if (strlen($sql) == $len) {
|
||||
throw new UnableToCreateSQLException('HAVING', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= " ";
|
||||
}
|
||||
return substr($sql, 0, -1);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
94
tools/parser_sql/builders/HavingExpressionBuilder.php
Normal file
94
tools/parser_sql/builders/HavingExpressionBuilder.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* HavingExpressionBuilder.php
|
||||
*
|
||||
* Builds expressions within the HAVING 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for expressions within the HAVING part.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
*
|
||||
* @author Ian Barker <ian@theorganicagency.com>
|
||||
* @author André Rothe <andre.rothe@phosco.info>
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class HavingExpressionBuilder extends WhereExpressionBuilder {
|
||||
|
||||
protected function buildHavingExpression($parsed) {
|
||||
return $this->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildHavingBracketExpression($parsed) {
|
||||
$builder = new HavingBracketExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $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->buildHavingExpression($v);
|
||||
$sql .= $this->buildHavingBracketExpression($v);
|
||||
$sql .= $this->buildUserVariable($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('HAVING expression subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= " ";
|
||||
}
|
||||
|
||||
$sql = substr($sql, 0, -1);
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -35,12 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
require_once dirname(__FILE__) . '/SubTreeBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder list of values for the IN statement.
|
||||
@@ -50,14 +50,14 @@ require_once dirname(__FILE__) . '/SubTreeBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class InListBuilder {
|
||||
class InListBuilder implements Builder {
|
||||
|
||||
protected function buildSubTree($parsed, $delim) {
|
||||
$builder = new SubTreeBuilder();
|
||||
return $builder->build($parsed, $delim);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::IN_LIST) {
|
||||
return "";
|
||||
}
|
||||
|
||||
91
tools/parser_sql/builders/IndexAlgorithmBuilder.php
Normal file
91
tools/parser_sql/builders/IndexAlgorithmBuilder.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* IndexAlgorithmBuilder.php
|
||||
*
|
||||
* Builds index algorithm part of a CREATE INDEX 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the index algorithm of CREATE INDEX 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 IndexAlgorithmBuilder implements Builder {
|
||||
|
||||
protected function buildReserved($parsed) {
|
||||
$builder = new ReservedBuilder();
|
||||
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);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::INDEX_ALGORITHM) {
|
||||
return '';
|
||||
}
|
||||
$sql = '';
|
||||
foreach ($parsed['sub_tree'] as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildReserved($v);
|
||||
$sql .= $this->buildConstant($v);
|
||||
$sql .= $this->buildOperator($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('CREATE INDEX algorithm subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= ' ';
|
||||
}
|
||||
return substr($sql, 0, -1);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -35,12 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../exceptions/UnsupportedFeatureException.php';
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for index column entries of the column-list
|
||||
* parts of CREATE TABLE.
|
||||
@@ -50,7 +51,7 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class IndexColumnBuilder {
|
||||
class IndexColumnBuilder implements Builder {
|
||||
|
||||
protected function buildLength($parsed) {
|
||||
return ($parsed === false ? '' : ('(' . $parsed . ')'));
|
||||
@@ -59,8 +60,8 @@ class IndexColumnBuilder {
|
||||
protected function buildDirection($parsed) {
|
||||
return ($parsed === false ? '' : (' ' . $parsed));
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::INDEX_COLUMN) {
|
||||
return "";
|
||||
}
|
||||
|
||||
85
tools/parser_sql/builders/IndexCommentBuilder.php
Normal file
85
tools/parser_sql/builders/IndexCommentBuilder.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* IndexCommentBuilder.php
|
||||
*
|
||||
* Builds index comment part of a CREATE INDEX 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the index comment of CREATE INDEX 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 IndexCommentBuilder implements Builder {
|
||||
|
||||
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(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::COMMENT) {
|
||||
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 INDEX comment subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= ' ';
|
||||
}
|
||||
return substr($sql, 0, -1);
|
||||
}
|
||||
}
|
||||
?>
|
||||
70
tools/parser_sql/builders/IndexHintListBuilder.php
Normal file
70
tools/parser_sql/builders/IndexHintListBuilder.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* IndexHintListBuilder.php
|
||||
*
|
||||
* Builds the index hint list of a 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for index hint lists.
|
||||
* 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 IndexHintListBuilder implements Builder {
|
||||
|
||||
public function hasHint($parsed) {
|
||||
return isset($parsed['hints']);
|
||||
}
|
||||
|
||||
// TODO: the hint list should be enhanced to get base_expr fro position calculation
|
||||
public function build(array $parsed) {
|
||||
if (!isset($parsed['hints']) || $parsed['hints'] === false) {
|
||||
return "";
|
||||
}
|
||||
$sql = "";
|
||||
foreach ($parsed['hints'] as $k => $v) {
|
||||
$sql .= $v['hint_type'] . " " . $v['hint_list'] . " ";
|
||||
}
|
||||
return " " . substr($sql, 0, -1);
|
||||
}
|
||||
}
|
||||
?>
|
||||
97
tools/parser_sql/builders/IndexKeyBuilder.php
Normal file
97
tools/parser_sql/builders/IndexKeyBuilder.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* IndexKeyBuilder.php
|
||||
*
|
||||
* Builds index key 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the index key part of a 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 IndexKeyBuilder implements Builder {
|
||||
|
||||
protected function buildReserved($parsed) {
|
||||
$builder = new ReservedBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildConstant($parsed) {
|
||||
$builder = new ConstantBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildIndexType($parsed) {
|
||||
$builder = new IndexTypeBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildColumnList($parsed) {
|
||||
$builder = new ColumnListBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::INDEX) {
|
||||
return "";
|
||||
}
|
||||
$sql = "";
|
||||
foreach ($parsed['sub_tree'] as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildReserved($v);
|
||||
$sql .= $this->buildColumnList($v);
|
||||
$sql .= $this->buildConstant($v);
|
||||
$sql .= $this->buildIndexType($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('CREATE TABLE index key subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= " ";
|
||||
}
|
||||
return substr($sql, 0, -1);
|
||||
}
|
||||
}
|
||||
?>
|
||||
91
tools/parser_sql/builders/IndexLockBuilder.php
Normal file
91
tools/parser_sql/builders/IndexLockBuilder.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* IndexLockBuilder.php
|
||||
*
|
||||
* Builds index lock part of a CREATE INDEX 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the index lock of CREATE INDEX 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 IndexLockBuilder implements Builder {
|
||||
|
||||
protected function buildReserved($parsed) {
|
||||
$builder = new ReservedBuilder();
|
||||
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);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::INDEX_LOCK) {
|
||||
return "";
|
||||
}
|
||||
$sql = "";
|
||||
foreach ($parsed['sub_tree'] as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildReserved($v);
|
||||
$sql .= $this->buildConstant($v);
|
||||
$sql .= $this->buildOperator($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('CREATE INDEX lock subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= ' ';
|
||||
}
|
||||
return substr($sql, 0, -1);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -35,16 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the index parser of a PRIMARY KEY
|
||||
@@ -55,7 +52,7 @@ require_once dirname(__FILE__) . '/IndexTypeBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class IndexParserBuilder {
|
||||
class IndexParserBuilder implements Builder {
|
||||
|
||||
protected function buildReserved($parsed) {
|
||||
$builder = new ReservedBuilder();
|
||||
@@ -67,7 +64,7 @@ class IndexParserBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::INDEX_PARSER) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,16 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the index size of a PRIMARY KEY
|
||||
@@ -55,7 +52,7 @@ require_once dirname(__FILE__) . '/IndexTypeBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class IndexSizeBuilder {
|
||||
class IndexSizeBuilder implements Builder {
|
||||
|
||||
protected function buildReserved($parsed) {
|
||||
$builder = new ReservedBuilder();
|
||||
@@ -67,7 +64,7 @@ class IndexSizeBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::INDEX_SIZE) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,16 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the index type of a PRIMARY KEY
|
||||
@@ -55,14 +52,14 @@ require_once dirname(__FILE__) . '/IndexTypeBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class IndexTypeBuilder {
|
||||
class IndexTypeBuilder implements Builder {
|
||||
|
||||
protected function buildReserved($parsed) {
|
||||
$builder = new ReservedBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::INDEX_TYPE) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
|
||||
require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the [INSERT] statement parts.
|
||||
@@ -50,39 +50,51 @@ require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class InsertBuilder {
|
||||
class InsertBuilder implements Builder {
|
||||
|
||||
protected function buildColRef($parsed) {
|
||||
$builder = new ColumnReferenceBuilder();
|
||||
protected function buildTable($parsed) {
|
||||
$builder = new TableBuilder();
|
||||
return $builder->build($parsed, 0);
|
||||
}
|
||||
|
||||
protected function buildSubQuery($parsed) {
|
||||
$builder = new SubQueryBuilder();
|
||||
return $builder->build($parsed, 0);
|
||||
}
|
||||
|
||||
protected function buildReserved($parsed) {
|
||||
$builder = new ReservedBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
$sql = "INSERT INTO " . $parsed['table'];
|
||||
protected function buildBracketExpression($parsed) {
|
||||
$builder = new SelectBracketExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
if ($parsed['columns'] === false) {
|
||||
return $sql;
|
||||
}
|
||||
protected function buildColumnList($parsed) {
|
||||
$builder = new InsertColumnListBuilder();
|
||||
return $builder->build($parsed, 0);
|
||||
}
|
||||
|
||||
$columns = "";
|
||||
foreach ($parsed['columns'] as $k => $v) {
|
||||
$len = strlen($columns);
|
||||
$columns .= $this->buildColRef($v);
|
||||
public function build(array $parsed) {
|
||||
$sql = '';
|
||||
foreach ($parsed as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildTable($v);
|
||||
$sql .= $this->buildSubQuery($v);
|
||||
$sql .= $this->buildColumnList($v);
|
||||
$sql .= $this->buildReserved($v);
|
||||
$sql .= $this->buildBracketExpression($v);
|
||||
|
||||
if ($len == strlen($columns)) {
|
||||
throw new UnableToCreateSQLException('INSERT[columns]', $k, $v, 'expr_type');
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('INSERT', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$columns .= ",";
|
||||
$sql .= " ";
|
||||
}
|
||||
|
||||
if ($columns !== "") {
|
||||
$columns = " (" . substr($columns, 0, -1) . ")";
|
||||
}
|
||||
|
||||
$sql .= $columns;
|
||||
return $sql;
|
||||
return 'INSERT ' . substr($sql, 0, -1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
80
tools/parser_sql/builders/InsertColumnListBuilder.php
Normal file
80
tools/parser_sql/builders/InsertColumnListBuilder.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* InsertColumnListBuilder.php
|
||||
*
|
||||
* Builds column-list parts of INSERT 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for column-list parts of INSERT statements.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
*
|
||||
* @author André Rothe <andre.rothe@phosco.info>
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class InsertColumnListBuilder implements Builder {
|
||||
|
||||
protected function buildColumn($parsed) {
|
||||
$builder = new ColumnReferenceBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::COLUMN_LIST) {
|
||||
return "";
|
||||
}
|
||||
$sql = "";
|
||||
foreach ($parsed['sub_tree'] as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildColumn($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('INSERT column-list subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= ", ";
|
||||
}
|
||||
return "(" . substr($sql, 0, -2) . ")";
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -35,12 +35,11 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/InsertBuilder.php';
|
||||
require_once dirname(__FILE__) . '/ValuesBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the whole Insert statement. You can overwrite
|
||||
@@ -50,7 +49,7 @@ require_once dirname(__FILE__) . '/ValuesBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class InsertStatementBuilder {
|
||||
class InsertStatementBuilder implements Builder {
|
||||
|
||||
protected function buildVALUES($parsed) {
|
||||
$builder = new ValuesBuilder();
|
||||
@@ -58,14 +57,33 @@ class InsertStatementBuilder {
|
||||
}
|
||||
|
||||
protected function buildINSERT($parsed) {
|
||||
$builder = new InsertBuilder($parsed);
|
||||
$builder = new InsertBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
protected function buildSELECT($parsed) {
|
||||
$builder = new SelectStatementBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildSET($parsed) {
|
||||
$builder = new SetBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
// TODO: are there more than one tables possible (like [INSERT][1])
|
||||
return $this->buildINSERT($parsed['INSERT'][0]) . " " . $this->buildVALUES($parsed['VALUES']);
|
||||
// TODO: subquery?
|
||||
$sql = $this->buildINSERT($parsed['INSERT']);
|
||||
if (isset($parsed['VALUES'])) {
|
||||
$sql .= ' ' . $this->buildVALUES($parsed['VALUES']);
|
||||
}
|
||||
if (isset($parsed['SET'])) {
|
||||
$sql .= ' ' . $this->buildSET($parsed['SET']);
|
||||
}
|
||||
if (isset($parsed['SELECT'])) {
|
||||
$sql .= ' ' . $this->buildSELECT($parsed);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -33,19 +33,21 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @author André Rothe <andre.rothe@phosco.info>
|
||||
* @author George Schneeloch <noisecapella@gmail.com>
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../exceptions/UnsupportedFeatureException.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
* @author George Schneeloch <noisecapella@gmail.com>
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
@@ -64,6 +66,9 @@ class JoinBuilder {
|
||||
if ($parsed === 'RIGHT') {
|
||||
return " RIGHT JOIN ";
|
||||
}
|
||||
if ($parsed === 'STRAIGHT_JOIN') {
|
||||
return " STRAIGHT_JOIN ";
|
||||
}
|
||||
// TODO: add more
|
||||
throw new UnsupportedFeatureException($parsed);
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
|
||||
require_once dirname(__FILE__) . '/TableBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the LIKE statement part of CREATE TABLE.
|
||||
@@ -50,17 +50,17 @@ require_once dirname(__FILE__) . '/TableBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class LikeBuilder {
|
||||
class LikeBuilder implements Builder {
|
||||
|
||||
protected function buildTable($parsed, $index) {
|
||||
$builder = new TableBuilder();
|
||||
return $builder->build($parsed, $index);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = $this->buildTable($parsed, 0);
|
||||
if (strlen($sql) === 0) {
|
||||
throw new UnableToCreateSQLException('LIKE', "", $like, 'table');
|
||||
throw new UnableToCreateSQLException('LIKE', "", $parsed, 'table');
|
||||
}
|
||||
return "LIKE " . $sql;
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
require_once dirname(__FILE__) . '/TableBuilder.php';
|
||||
require_once dirname(__FILE__) . '/ReservedBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the (LIKE) keyword within a
|
||||
@@ -53,7 +53,7 @@ require_once dirname(__FILE__) . '/ReservedBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class LikeExpressionBuilder {
|
||||
class LikeExpressionBuilder implements Builder {
|
||||
|
||||
protected function buildTable($parsed, $index) {
|
||||
$builder = new TableBuilder();
|
||||
@@ -65,7 +65,7 @@ class LikeExpressionBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::LIKE) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,11 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder LIMIT statement.
|
||||
@@ -49,10 +50,10 @@ require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php'
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class LimitBuilder {
|
||||
class LimitBuilder implements Builder {
|
||||
|
||||
public function build($parsed) {
|
||||
$sql = ($parsed['offset'] ? $parsed['offset'] . ", " : "") . $parsed['rowcount'];
|
||||
public function build(array $parsed) {
|
||||
$sql = ($parsed['rowcount']) . ($parsed['offset'] ? " OFFSET " . $parsed['offset'] : "");
|
||||
if ($sql === "") {
|
||||
throw new UnableToCreateSQLException('LIMIT', 'rowcount', $parsed, 'rowcount');
|
||||
}
|
||||
|
||||
@@ -35,11 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for operators.
|
||||
@@ -49,9 +50,9 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class OperatorBuilder {
|
||||
class OperatorBuilder implements Builder {
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::OPERATOR) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
require_once dirname(__FILE__) . '/DirectionBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for an alias within the ORDER-BY clause.
|
||||
@@ -50,14 +50,14 @@ require_once dirname(__FILE__) . '/DirectionBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class OrderByAliasBuilder {
|
||||
class OrderByAliasBuilder implements Builder {
|
||||
|
||||
protected function buildDirection($parsed) {
|
||||
$builder = new DirectionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::ALIAS) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* OrderByBracketExpressionBuilder.php
|
||||
*
|
||||
* Builds bracket-expressions within the ORDER-BY 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for bracket-expressions within the ORDER-BY part.
|
||||
* It must contain the direction.
|
||||
* 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 OrderByBracketExpressionBuilder extends WhereBracketExpressionBuilder {
|
||||
|
||||
protected function buildDirection($parsed) {
|
||||
$builder = new DirectionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = parent::build($parsed);
|
||||
if ($sql !== '') {
|
||||
$sql .= $this->buildDirection($parsed);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -35,13 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
|
||||
require_once dirname(__FILE__) . '/OrderByAliasBuilder.php';
|
||||
require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the ORDER-BY clause.
|
||||
@@ -51,31 +51,55 @@ require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class OrderByBuilder {
|
||||
class OrderByBuilder implements Builder {
|
||||
|
||||
protected function buildFunction($parsed) {
|
||||
$builder = new FunctionBuilder();
|
||||
$builder = new OrderByFunctionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildReserved($parsed) {
|
||||
$builder = new OrderByReservedBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildColRef($parsed) {
|
||||
$builder = new ColumnReferenceBuilder();
|
||||
$builder = new OrderByColumnReferenceBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildOrderByAlias($parsed) {
|
||||
protected function buildAlias($parsed) {
|
||||
$builder = new OrderByAliasBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
protected function buildExpression($parsed) {
|
||||
$builder = new OrderByExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildBracketExpression($parsed) {
|
||||
$builder = new OrderByBracketExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildPosition($parsed) {
|
||||
$builder = new PositionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = "";
|
||||
foreach ($parsed as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildOrderByAlias($v);
|
||||
$sql .= $this->buildAlias($v);
|
||||
$sql .= $this->buildColRef($v);
|
||||
$sql .= $this->buildFunction($v);
|
||||
|
||||
$sql .= $this->buildExpression($v);
|
||||
$sql .= $this->buildBracketExpression($v);
|
||||
$sql .= $this->buildReserved($v);
|
||||
$sql .= $this->buildPosition($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('ORDER', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
69
tools/parser_sql/builders/OrderByColumnReferenceBuilder.php
Normal file
69
tools/parser_sql/builders/OrderByColumnReferenceBuilder.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* OrderByColumnReferenceBuilder.php
|
||||
*
|
||||
* Builds column references within the ORDER-BY 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for column references within the ORDER-BY part.
|
||||
* It must contain the direction.
|
||||
* 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 OrderByColumnReferenceBuilder extends ColumnReferenceBuilder {
|
||||
|
||||
protected function buildDirection($parsed) {
|
||||
$builder = new DirectionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = parent::build($parsed);
|
||||
if ($sql !== '') {
|
||||
$sql .= $this->buildDirection($parsed);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
69
tools/parser_sql/builders/OrderByExpressionBuilder.php
Normal file
69
tools/parser_sql/builders/OrderByExpressionBuilder.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* OrderByExpressionBuilder.php
|
||||
*
|
||||
* Builds expressions within the ORDER-BY 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for expressions within the ORDER-BY part.
|
||||
* It must contain the direction.
|
||||
* 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 OrderByExpressionBuilder extends WhereExpressionBuilder {
|
||||
|
||||
protected function buildDirection($parsed) {
|
||||
$builder = new DirectionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = parent::build($parsed);
|
||||
if ($sql !== '') {
|
||||
$sql .= $this->buildDirection($parsed);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
69
tools/parser_sql/builders/OrderByFunctionBuilder.php
Normal file
69
tools/parser_sql/builders/OrderByFunctionBuilder.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* OrderByFunctionBuilder.php
|
||||
*
|
||||
* Builds functions within the ORDER-BY 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for functions within the ORDER-BY part.
|
||||
* It must contain the direction.
|
||||
* 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 OrderByFunctionBuilder extends FunctionBuilder {
|
||||
|
||||
protected function buildDirection($parsed) {
|
||||
$builder = new DirectionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = parent::build($parsed);
|
||||
if ($sql !== '') {
|
||||
$sql .= $this->buildDirection($parsed);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
69
tools/parser_sql/builders/OrderByReservedBuilder.php
Normal file
69
tools/parser_sql/builders/OrderByReservedBuilder.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* OrderByReservedBuilder.php
|
||||
*
|
||||
* Builds reserved keywords within the ORDER-BY 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for reserved keywords within the ORDER-BY part.
|
||||
* It must contain the direction.
|
||||
* 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 OrderByReservedBuilder extends ReservedBuilder {
|
||||
|
||||
protected function buildDirection($parsed) {
|
||||
$builder = new DirectionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = parent::build($parsed);
|
||||
if ($sql !== '') {
|
||||
$sql .= $this->buildDirection($parsed);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -35,11 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for positions of the GROUP-BY clause.
|
||||
@@ -49,9 +50,9 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class PositionBuilder {
|
||||
class PositionBuilder implements Builder {
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::POSITION) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,18 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the PRIMARY KEY statement part of CREATE TABLE.
|
||||
@@ -56,7 +51,7 @@ require_once dirname(__FILE__) . '/IndexParserBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class PrimaryKeyBuilder {
|
||||
class PrimaryKeyBuilder implements Builder {
|
||||
|
||||
protected function buildColumnList($parsed) {
|
||||
$builder = new ColumnListBuilder();
|
||||
@@ -77,18 +72,18 @@ class PrimaryKeyBuilder {
|
||||
$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) {
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::PRIMARY_KEY) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,11 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for a procedure within SHOW statement.
|
||||
@@ -49,9 +50,9 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ProcedureBuilder {
|
||||
class ProcedureBuilder implements Builder {
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::PROCEDURE) {
|
||||
return "";
|
||||
}
|
||||
|
||||
97
tools/parser_sql/builders/QueryBuilder.php
Normal file
97
tools/parser_sql/builders/QueryBuilder.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* QueryBuilder.php
|
||||
*
|
||||
* Builds the SELECT statements within parentheses.
|
||||
*
|
||||
* 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for queries within parentheses (no subqueries).
|
||||
* 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 QueryBuilder implements Builder {
|
||||
|
||||
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(array $parsed, $index = 0) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::QUERY) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// TODO: should we add a numeric level (0) between sub_tree and SELECT?
|
||||
$sql = $this->buildSelectStatement($parsed['sub_tree']);
|
||||
$sql .= $this->buildAlias($parsed);
|
||||
|
||||
if ($index !== 0) {
|
||||
$sql = $this->buildJoin($parsed['join_type']) . $sql;
|
||||
$sql .= $this->buildRefType($parsed['ref_type']);
|
||||
$sql .= $parsed['ref_clause'] === false ? '' : $this->buildRefClause($parsed['ref_clause']);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -35,15 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the records within INSERT statement.
|
||||
@@ -53,7 +51,7 @@ require_once dirname(__FILE__) . '/FunctionBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class RecordBuilder {
|
||||
class RecordBuilder implements Builder {
|
||||
|
||||
protected function buildOperator($parsed) {
|
||||
$builder = new OperatorBuilder();
|
||||
@@ -70,9 +68,14 @@ class RecordBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
protected function buildColRef($parsed) {
|
||||
$builder = new ColumnReferenceBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::RECORD) {
|
||||
return "";
|
||||
return isset($parsed['base_expr']) ? $parsed['base_expr'] : '';
|
||||
}
|
||||
$sql = "";
|
||||
foreach ($parsed['data'] as $k => $v) {
|
||||
@@ -80,14 +83,15 @@ class RecordBuilder {
|
||||
$sql .= $this->buildConstant($v);
|
||||
$sql .= $this->buildFunction($v);
|
||||
$sql .= $this->buildOperator($v);
|
||||
$sql .= $this->buildColRef($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException(ExpressionType::RECORD, $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= ",";
|
||||
$sql .= ", ";
|
||||
}
|
||||
$sql = substr($sql, 0, -1);
|
||||
$sql = substr($sql, 0, -2);
|
||||
return "(" . $sql . ")";
|
||||
}
|
||||
|
||||
|
||||
@@ -31,28 +31,31 @@
|
||||
* 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 $
|
||||
*
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the references clause within a JOIN.
|
||||
* 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 {
|
||||
class RefClauseBuilder implements Builder {
|
||||
|
||||
protected function buildInList($parsed) {
|
||||
$builder = new InListBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildColRef($parsed) {
|
||||
$builder = new ColumnReferenceBuilder();
|
||||
@@ -64,29 +67,54 @@ class RefClauseBuilder {
|
||||
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) {
|
||||
protected function buildBracketExpression($parsed) {
|
||||
$builder = new SelectBracketExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildColumnList($parsed) {
|
||||
$builder = new ColumnListBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildSubQuery($parsed) {
|
||||
$builder = new SubQueryBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed === false) {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
$sql = "";
|
||||
$sql = '';
|
||||
foreach ($parsed as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildColRef($v);
|
||||
$sql .= $this->buildOperator($v);
|
||||
$sql .= $this->buildConstant($v);
|
||||
$sql .= $this->buildFunction($v);
|
||||
$sql .= $this->buildBracketExpression($v);
|
||||
$sql .= $this->buildInList($v);
|
||||
$sql .= $this->buildColumnList($v);
|
||||
$sql .= $this->buildSubQuery($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('expression ref_clause', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= " ";
|
||||
$sql .= ' ';
|
||||
}
|
||||
return "(" . substr($sql, 0, -1) . ")";
|
||||
return substr($sql, 0, -1);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -35,11 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../exceptions/UnsupportedFeatureException.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnsupportedFeatureException;
|
||||
|
||||
/**
|
||||
* This class implements the references type within a JOIN.
|
||||
|
||||
86
tools/parser_sql/builders/RenameStatementBuilder.php
Normal file
86
tools/parser_sql/builders/RenameStatementBuilder.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* RenameStatement.php
|
||||
*
|
||||
* Builds the RENAME 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the RENAME 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 RenameStatementBuilder implements Builder {
|
||||
|
||||
protected function buildReserved($parsed) {
|
||||
$builder = new ReservedBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function processSourceAndDestTable($v) {
|
||||
if (!isset($v['source']) || !isset($v['destination'])) {
|
||||
return '';
|
||||
}
|
||||
return $v['source']['base_expr'] . ' TO ' . $v['destination']['base_expr'] . ',';
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$rename = $parsed['RENAME'];
|
||||
$sql = '';
|
||||
foreach ($rename['sub_tree'] as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildReserved($v);
|
||||
$sql .= $this->processSourceAndDestTable($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('RENAME subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= ' ';
|
||||
}
|
||||
$sql = trim('RENAME ' . $sql);
|
||||
return (substr($sql, -1) === ',' ? substr($sql, 0, -1) : $sql);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
100
tools/parser_sql/builders/ReplaceBuilder.php
Normal file
100
tools/parser_sql/builders/ReplaceBuilder.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* ReplaceBuilder.php
|
||||
*
|
||||
* Builds the [REPLACE] 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the [REPLACE] 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 ReplaceBuilder implements Builder {
|
||||
|
||||
protected function buildTable($parsed) {
|
||||
$builder = new TableBuilder();
|
||||
return $builder->build($parsed, 0);
|
||||
}
|
||||
|
||||
protected function buildSubQuery($parsed) {
|
||||
$builder = new SubQueryBuilder();
|
||||
return $builder->build($parsed, 0);
|
||||
}
|
||||
|
||||
protected function buildReserved($parsed) {
|
||||
$builder = new ReservedBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildBracketExpression($parsed) {
|
||||
$builder = new SelectBracketExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildColumnList($parsed) {
|
||||
$builder = new ReplaceColumnListBuilder();
|
||||
return $builder->build($parsed, 0);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = '';
|
||||
foreach ($parsed as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildTable($v);
|
||||
$sql .= $this->buildSubQuery($v);
|
||||
$sql .= $this->buildColumnList($v);
|
||||
$sql .= $this->buildReserved($v);
|
||||
$sql .= $this->buildBracketExpression($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('REPLACE', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= " ";
|
||||
}
|
||||
return 'REPLACE ' . substr($sql, 0, -1);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
80
tools/parser_sql/builders/ReplaceColumnListBuilder.php
Normal file
80
tools/parser_sql/builders/ReplaceColumnListBuilder.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* ReplaceColumnListBuilder.php
|
||||
*
|
||||
* Builds column-list parts of REPLACE 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for column-list parts of REPLACE statements.
|
||||
* 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 ReplaceColumnListBuilder implements Builder {
|
||||
|
||||
protected function buildColumn($parsed) {
|
||||
$builder = new ColumnReferenceBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::COLUMN_LIST) {
|
||||
return "";
|
||||
}
|
||||
$sql = "";
|
||||
foreach ($parsed['sub_tree'] as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildColumn($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('REPLACE column-list subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= ", ";
|
||||
}
|
||||
return "(" . substr($sql, 0, -2) . ")";
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
89
tools/parser_sql/builders/ReplaceStatementBuilder.php
Normal file
89
tools/parser_sql/builders/ReplaceStatementBuilder.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* ReplaceStatement.php
|
||||
*
|
||||
* Builds the REPLACE 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the whole Replace 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 ReplaceStatementBuilder implements Builder {
|
||||
|
||||
protected function buildVALUES($parsed) {
|
||||
$builder = new ValuesBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildREPLACE($parsed) {
|
||||
$builder = new ReplaceBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildSELECT($parsed) {
|
||||
$builder = new SelectStatementBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildSET($parsed) {
|
||||
$builder = new SetBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
// TODO: are there more than one tables possible (like [REPLACE][1])
|
||||
$sql = $this->buildREPLACE($parsed['REPLACE']);
|
||||
if (isset($parsed['VALUES'])) {
|
||||
$sql .= ' ' . $this->buildVALUES($parsed['VALUES']);
|
||||
}
|
||||
if (isset($parsed['SET'])) {
|
||||
$sql .= ' ' . $this->buildSET($parsed['SET']);
|
||||
}
|
||||
if (isset($parsed['SELECT'])) {
|
||||
$sql .= ' ' . $this->buildSELECT($parsed);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -35,11 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for reserved keywords.
|
||||
@@ -49,13 +50,13 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ReservedBuilder {
|
||||
class ReservedBuilder implements Builder {
|
||||
|
||||
public function isReserved($parsed) {
|
||||
return ($parsed['expr_type'] === ExpressionType::RESERVED);
|
||||
return (isset($parsed['expr_type']) && $parsed['expr_type'] === ExpressionType::RESERVED);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
|
||||
public function build(array $parsed) {
|
||||
if (!$this->isReserved($parsed)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
62
tools/parser_sql/builders/SchemaBuilder.php
Normal file
62
tools/parser_sql/builders/SchemaBuilder.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* SchemaBuilder.php
|
||||
*
|
||||
* Builds the schema within the DROP 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for a schema within DROP 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 SchemaBuilder implements Builder {
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::SCHEMA) {
|
||||
return "";
|
||||
}
|
||||
return $parsed['base_expr'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -35,12 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/SubTreeBuilder.php';
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for bracket expressions within a SELECT statement.
|
||||
* You can overwrite all functions to achieve another handling.
|
||||
@@ -49,20 +50,24 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class SelectBracketExpressionBuilder {
|
||||
class SelectBracketExpressionBuilder implements Builder {
|
||||
|
||||
protected function buildSubTree($parsed, $delim) {
|
||||
$builder = new SubTreeBuilder();
|
||||
return $builder->build($parsed, $delim);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
protected function buildAlias($parsed) {
|
||||
$builder = new AliasBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::BRACKET_EXPRESSION) {
|
||||
return "";
|
||||
}
|
||||
$sql = $this->buildSubTree($parsed, " ");
|
||||
$sql = "(" . $sql . ")";
|
||||
return $sql;
|
||||
return '(' . $this->buildSubTree($parsed, ' ') . ')'
|
||||
. $this->buildAlias($parsed);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -35,15 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
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';
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the [SELECT] field. You can overwrite
|
||||
@@ -53,7 +50,7 @@ require_once dirname(__FILE__) . '/ColumnReferenceBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class SelectBuilder {
|
||||
class SelectBuilder implements Builder {
|
||||
|
||||
protected function buildConstant($parsed) {
|
||||
$builder = new ConstantBuilder();
|
||||
@@ -92,10 +89,10 @@ class SelectBuilder {
|
||||
* @return a string, which is added right after the expression
|
||||
*/
|
||||
protected function getDelimiter($parsed) {
|
||||
return ($parsed['delim'] === false ? '' : (trim($parsed['delim']) . ' '));
|
||||
return (!isset($parsed['delim']) || $parsed['delim'] === false ? '' : (trim($parsed['delim']) . ' '));
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
$sql = "";
|
||||
foreach ($parsed as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
|
||||
@@ -35,13 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/SubTreeBuilder.php';
|
||||
require_once dirname(__FILE__) . '/AliasBuilder.php';
|
||||
require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for simple expressions within a SELECT statement.
|
||||
@@ -51,7 +50,7 @@ require_once dirname(__FILE__) . '/../utils/ExpressionType.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class SelectExpressionBuilder {
|
||||
class SelectExpressionBuilder implements Builder {
|
||||
|
||||
protected function buildSubTree($parsed, $delim) {
|
||||
$builder = new SubTreeBuilder();
|
||||
@@ -63,7 +62,7 @@ class SelectExpressionBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::EXPRESSION) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -35,16 +35,11 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the whole Select statement. You can overwrite
|
||||
@@ -54,7 +49,7 @@ require_once dirname(__FILE__) . '/OrderByBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class SelectStatementBuilder {
|
||||
class SelectStatementBuilder implements Builder {
|
||||
|
||||
protected function buildSELECT($parsed) {
|
||||
$builder = new SelectBuilder();
|
||||
@@ -76,6 +71,11 @@ class SelectStatementBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildHAVING($parsed) {
|
||||
$builder = new HavingBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildORDER($parsed) {
|
||||
$builder = new OrderByBuilder();
|
||||
return $builder->build($parsed);
|
||||
@@ -85,9 +85,22 @@ class SelectStatementBuilder {
|
||||
$builder = new LimitBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildUNION($parsed) {
|
||||
$builder = new UnionStatementBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildUNIONALL($parsed) {
|
||||
$builder = new UnionAllStatementBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
$sql = $this->buildSELECT($parsed['SELECT']);
|
||||
public function build(array $parsed) {
|
||||
$sql = "";
|
||||
if (isset($parsed['SELECT'])) {
|
||||
$sql .= $this->buildSELECT($parsed['SELECT']);
|
||||
}
|
||||
if (isset($parsed['FROM'])) {
|
||||
$sql .= " " . $this->buildFROM($parsed['FROM']);
|
||||
}
|
||||
@@ -97,11 +110,20 @@ class SelectStatementBuilder {
|
||||
if (isset($parsed['GROUP'])) {
|
||||
$sql .= " " . $this->buildGROUP($parsed['GROUP']);
|
||||
}
|
||||
if (isset($parsed['HAVING'])) {
|
||||
$sql .= " " . $this->buildHAVING($parsed['HAVING']);
|
||||
}
|
||||
if (isset($parsed['ORDER'])) {
|
||||
$sql .= " " . $this->buildORDER($parsed['ORDER']);
|
||||
}
|
||||
if (isset($parsed['LIMIT'])) {
|
||||
$sql .= " " . $this->buildLIMIT($parsed['LIMIT']);
|
||||
}
|
||||
if (isset($parsed['UNION'])) {
|
||||
$sql .= " " . $this->buildUNION($parsed);
|
||||
}
|
||||
if (isset($parsed['UNION ALL'])) {
|
||||
$sql .= " " . $this->buildUNIONALL($parsed);
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../exceptions/UnableToCreateSQLException.php';
|
||||
require_once dirname(__FILE__) . '/SetExpressionBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the SET part of INSERT statement.
|
||||
@@ -50,14 +50,14 @@ require_once dirname(__FILE__) . '/SetExpressionBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class SetBuilder {
|
||||
class SetBuilder implements Builder {
|
||||
|
||||
protected function buildSetExpression($parsed) {
|
||||
$builder = new SetExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
public function build(array $parsed) {
|
||||
$sql = "";
|
||||
foreach ($parsed as $k => $v) {
|
||||
$len = strlen($sql);
|
||||
|
||||
@@ -35,16 +35,13 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the SET part of INSERT statement.
|
||||
@@ -54,7 +51,7 @@ require_once dirname(__FILE__) . '/FunctionBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class SetExpressionBuilder {
|
||||
class SetExpressionBuilder implements Builder {
|
||||
|
||||
protected function buildColRef($parsed) {
|
||||
$builder = new ColumnReferenceBuilder();
|
||||
@@ -76,23 +73,42 @@ class SetExpressionBuilder {
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build($parsed) {
|
||||
protected function buildBracketExpression($parsed) {
|
||||
$builder = new SelectBracketExpressionBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
protected function buildSign($parsed) {
|
||||
$builder = new SignBuilder();
|
||||
return $builder->build($parsed);
|
||||
}
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::EXPRESSION) {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
$sql = "";
|
||||
$sql = '';
|
||||
foreach ($parsed['sub_tree'] as $k => $v) {
|
||||
$delim = ' ';
|
||||
$len = strlen($sql);
|
||||
$sql .= $this->buildColRef($v);
|
||||
$sql .= $this->buildConstant($v);
|
||||
$sql .= $this->buildOperator($v);
|
||||
$sql .= $this->buildFunction($v);
|
||||
|
||||
$sql .= $this->buildBracketExpression($v);
|
||||
|
||||
// we don't need whitespace between the sign and
|
||||
// the following part
|
||||
if ($this->buildSign($v) !== '') {
|
||||
$delim = '';
|
||||
}
|
||||
$sql .= $this->buildSign($v);
|
||||
|
||||
if ($len == strlen($sql)) {
|
||||
throw new UnableToCreateSQLException('SET expression subtree', $k, $v, 'expr_type');
|
||||
}
|
||||
|
||||
$sql .= " ";
|
||||
$sql .= $delim;
|
||||
}
|
||||
$sql = substr($sql, 0, -1);
|
||||
return $sql;
|
||||
|
||||
@@ -35,18 +35,12 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
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';
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\exceptions\UnableToCreateSQLException;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the SHOW statement.
|
||||
@@ -56,44 +50,44 @@ require_once dirname(__FILE__) . '/TableBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ShowBuilder {
|
||||
class ShowBuilder implements Builder {
|
||||
|
||||
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) {
|
||||
|
||||
public function build(array $parsed) {
|
||||
$show = $parsed['SHOW'];
|
||||
$sql = "";
|
||||
foreach ($show as $k => $v) {
|
||||
@@ -115,6 +109,6 @@ class ShowBuilder {
|
||||
|
||||
$sql = substr($sql, 0, -1);
|
||||
return "SHOW " . $sql;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -35,12 +35,11 @@
|
||||
* @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 $
|
||||
* @version SVN: $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/ShowBuilder.php';
|
||||
require_once dirname(__FILE__) . '/WhereBuilder.php';
|
||||
namespace PHPSQLParser\builders;
|
||||
|
||||
/**
|
||||
* This class implements the builder for the SHOW statement.
|
||||
@@ -50,19 +49,19 @@ require_once dirname(__FILE__) . '/WhereBuilder.php';
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ShowStatementBuilder {
|
||||
class ShowStatementBuilder implements Builder {
|
||||
|
||||
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) {
|
||||
|
||||
public function build(array $parsed) {
|
||||
$sql = $this->buildSHOW($parsed);
|
||||
if (isset($parsed['WHERE'])) {
|
||||
$sql .= " " . $this->buildWHERE($parsed['WHERE']);
|
||||
|
||||
62
tools/parser_sql/builders/SignBuilder.php
Normal file
62
tools/parser_sql/builders/SignBuilder.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* SignBuilder.php
|
||||
*
|
||||
* Builds unary 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$
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PHPSQLParser\builders;
|
||||
use PHPSQLParser\utils\ExpressionType;
|
||||
|
||||
/**
|
||||
* This class implements the builder for unary 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 SignBuilder implements Builder {
|
||||
|
||||
public function build(array $parsed) {
|
||||
if ($parsed['expr_type'] !== ExpressionType::SIGN) {
|
||||
return "";
|
||||
}
|
||||
return $parsed['base_expr'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user