Libs changes for php 8.x

This commit is contained in:
Sumit Panwar
2025-05-23 10:46:00 +05:30
parent 178e8fa28a
commit fa0a498733
1185 changed files with 92175 additions and 58962 deletions

View File

@@ -65,6 +65,8 @@ use PHPSQLParser\builders\AlterStatementBuilder;
*/
class PHPSQLCreator {
public $created;
public function __construct($parsed = false) {
if ($parsed) {
$this->create($parsed);

View File

@@ -80,6 +80,20 @@ class ColumnTypeBuilder implements Builder {
return $parsed['base_expr'];
}
protected function buildCollation($parsed) {
if ($parsed['expr_type'] !== ExpressionType::COLLATE) {
return "";
}
return $parsed['base_expr'];
}
protected function buildComment($parsed) {
if ($parsed['expr_type'] !== ExpressionType::COMMENT) {
return "";
}
return $parsed['base_expr'];
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::COLUMN_TYPE) {
return "";
@@ -92,6 +106,8 @@ class ColumnTypeBuilder implements Builder {
$sql .= $this->buildReserved($v);
$sql .= $this->buildDefaultValue($v);
$sql .= $this->buildCharacterSet($v);
$sql .= $this->buildCollation($v);
$sql .= $this->buildComment($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE column-type subtree', $k, $v, 'expr_type');

View File

@@ -0,0 +1,99 @@
<?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 FulltextIndexBuilder 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 buildIndexKey($parsed) {
if ($parsed['expr_type'] !== ExpressionType::INDEX) {
return "";
}
return $parsed['base_expr'];
}
protected function buildColumnList($parsed) {
$builder = new ColumnListBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::FULLTEXT_IDX) {
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->buildIndexKey($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE fulltext-index key subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -92,7 +92,12 @@ class FunctionBuilder implements Builder {
$builder = new SubQueryBuilder();
return $builder->build($parsed);
}
protected function buildUserVariableExpression($parsed) {
$builder = new UserVariableBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if (($parsed['expr_type'] !== ExpressionType::AGGREGATE_FUNCTION)
&& ($parsed['expr_type'] !== ExpressionType::SIMPLE_FUNCTION)
@@ -114,6 +119,7 @@ class FunctionBuilder implements Builder {
$sql .= $this->buildReserved($v);
$sql .= $this->buildSelectBracketExpression($v);
$sql .= $this->buildSelectExpression($v);
$sql .= $this->buildUserVariableExpression($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('function subtree', $k, $v, 'expr_type');

View File

@@ -84,7 +84,7 @@ class OrderByBuilder implements Builder {
}
protected function buildPosition($parsed) {
$builder = new PositionBuilder();
$builder = new OrderByPositionBuilder();
return $builder->build($parsed);
}

View File

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

View File

@@ -84,6 +84,16 @@ class TableBracketExpressionBuilder implements Builder {
return $builder->build($parsed);
}
protected function buildUniqueIndex($parsed) {
$builder = new UniqueIndexBuilder();
return $builder->build($parsed);
}
protected function buildFulltextIndex($parsed) {
$builder = new FulltextIndexBuilder();
return $builder->build($parsed);
}
public function build(array $parsed) {
if ($parsed['expr_type'] !== ExpressionType::BRACKET_EXPRESSION) {
return "";
@@ -97,6 +107,8 @@ class TableBracketExpressionBuilder implements Builder {
$sql .= $this->buildLikeExpression($v);
$sql .= $this->buildForeignKey($v);
$sql .= $this->buildIndexKey($v);
$sql .= $this->buildUniqueIndex($v);
$sql .= $this->buildFulltextIndex($v);
if ($len == strlen($sql)) {
throw new UnableToCreateSQLException('CREATE TABLE create-def expression subtree', $k, $v, 'expr_type');

View 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 UniqueIndexBuilder 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::UNIQUE_IDX) {
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 unique-index key subtree', $k, $v, 'expr_type');
}
$sql .= " ";
}
return substr($sql, 0, -1);
}
}
?>

View File

@@ -1,29 +0,0 @@
<?php
/**
* 2010-2021 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2021 Webkul IN
* @license https://store.webkul.com/license.html
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;

View File

@@ -1,29 +0,0 @@
<?php
/**
* 2010-2021 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2021 Webkul IN
* @license https://store.webkul.com/license.html
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;

View File

@@ -1,29 +0,0 @@
<?php
/**
* 2010-2021 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2021 Webkul IN
* @license https://store.webkul.com/license.html
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;

View File

@@ -84,7 +84,7 @@ class PHPSQLLexer {
if (!is_string($sql)) {
throw new InvalidParameterException($sql);
}
$tokens = preg_split($this->splitters->getSplittersRegexPattern(), $sql, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$tokens = preg_split($this->splitters->getSplittersRegexPattern(), $sql, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$tokens = $this->concatComments($tokens);
$tokens = $this->concatEscapeSequences($tokens);
$tokens = $this->balanceBackticks($tokens);

View File

@@ -1,29 +0,0 @@
<?php
/**
* 2010-2021 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2021 Webkul IN
* @license https://store.webkul.com/license.html
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;

View File

@@ -90,7 +90,8 @@ class PositionCalculator {
ExpressionType::SUBPARTITION_HASH, ExpressionType::SUBPARTITION_COUNT,
ExpressionType::CHARSET, ExpressionType::ENGINE, ExpressionType::QUERY,
ExpressionType::INDEX_ALGORITHM, ExpressionType::INDEX_LOCK,
ExpressionType::SUBQUERY_FACTORING, ExpressionType::CUSTOM_FUNCTION
ExpressionType::SUBQUERY_FACTORING, ExpressionType::CUSTOM_FUNCTION,
ExpressionType::SIMPLE_FUNCTION
);
/**
@@ -127,6 +128,9 @@ class PositionCalculator {
}
protected function findPositionWithinString($sql, $value, $expr_type) {
if ($value === '') {
return false;
}
$offset = 0;
$ok = false;
@@ -145,8 +149,9 @@ class PositionCalculator {
}
// if we have a quoted string, we every character is allowed after it
// see issue 137
$quoted = ($sql[$pos + strlen($value) - 1] === '`');
// see issues 137 and 361
$quotedBefore = in_array($sql[$pos], array('`', '('), true);
$quotedAfter = in_array($sql[$pos + strlen($value) - 1], array('`', ')'), true);
$after = "";
if (isset($sql[$pos + strlen($value)])) {
$after = $sql[$pos + strlen($value)];
@@ -175,10 +180,11 @@ class PositionCalculator {
// in all other cases we accept
// whitespace, comma, operators, parenthesis and end_of_string
$ok = ($before === "" || in_array($before, self::$allowedOnOther, true));
$ok = ($before === "" || in_array($before, self::$allowedOnOther, true)
|| ($quotedBefore && (strtolower($before) >= 'a' && strtolower($before) <= 'z')));
$ok = $ok
&& ($after === "" || in_array($after, self::$allowedOnOther, true)
|| ($quoted && (strtolower($after) >= 'a' && strtolower($after) <= 'z')));
|| ($quotedAfter && (strtolower($after) >= 'a' && strtolower($after) <= 'z')));
if ($ok) {
break;

View File

@@ -1,29 +0,0 @@
<?php
/**
* 2010-2021 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2021 Webkul IN
* @license https://store.webkul.com/license.html
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;

View File

@@ -64,7 +64,7 @@ abstract class AbstractProcessor {
*
* @param Options $options
*/
public function __construct(Options $options = null)
public function __construct(?Options $options = null)
{
$this->options = $options;
}

View File

@@ -82,6 +82,19 @@ class ColumnDefinitionProcessor extends AbstractProcessor {
return $expr;
}
protected function peekAtNextToken($tokens, $index)
{
$offset = $index + 1;
while (isset($tokens[$offset])) {
$token = trim($tokens[$offset]);
if ($token !== '') {
return strtoupper($token);
}
$offset++;
}
return '';
}
public function process($tokens) {
$trim = '';
@@ -123,6 +136,7 @@ class ColumnDefinitionProcessor extends AbstractProcessor {
break 2;
case 'VARCHAR':
case 'VARCHARACTER': // Alias for VARCHAR
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim, 'length' => false);
$prevCategory = 'TEXT';
$currCategory = 'SINGLE_PARAM_PARENTHESIS';
@@ -155,10 +169,15 @@ class ColumnDefinitionProcessor extends AbstractProcessor {
case 'TINYBIT':
case 'TINYINT':
case 'SMALLINT':
case 'INT2': // Alias of SMALLINT
case 'MEDIUMINT':
case 'INT3': // Alias of MEDIUMINT
case 'MIDDLEINT': // Alias of MEDIUMINT
case 'INT':
case 'INTEGER':
case 'INT4': // Alias of INT
case 'BIGINT':
case 'INT8': // Alias of BIGINT
case 'BOOL':
case 'BOOLEAN':
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim, 'unsigned' => false,
@@ -188,7 +207,9 @@ class ColumnDefinitionProcessor extends AbstractProcessor {
case 'REAL':
case 'DOUBLE':
case 'FLOAT8': // Alias for DOUBLE
case 'FLOAT':
case 'FLOAT4': // Alias for FLOAT
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim, 'unsigned' => false,
'zerofill' => false);
$currCategory = 'TWO_PARAM_PARENTHESIS';
@@ -250,11 +271,25 @@ class ColumnDefinitionProcessor extends AbstractProcessor {
// spatial types
continue 2;
case 'CHARACTER':
case 'CHARSET':
$currCategory = 'CHARSET';
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
continue 2;
case 'CHARACTER':
// Alias of CHAR as well as pre-running for CHARACTER SET
// To determine which we peek at the next token to see if it's a SET or not.
if ($this->peekAtNextToken($tokens, $key) == 'SET') {
$currCategory = 'CHARSET';
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);
// If it's not a SET we assume that it is a CHARACTER type definition
} else {
$expr[] = array('expr_type' => ExpressionType::DATA_TYPE, 'base_expr' => $trim, 'length' => false);
$currCategory = 'SINGLE_PARAM_PARENTHESIS';
$prevCategory = 'TEXT';
}
continue 2;
case 'SET':
if ($currCategory == 'CHARSET') {
$options['sub_tree'][] = array('expr_type' => ExpressionType::RESERVED, 'base_expr' => $trim);

View File

@@ -256,8 +256,15 @@ class ExpressionListProcessor extends AbstractProcessor {
// if the last token is colref, const or expression
// then * is an operator
// but if the previous colref ends with a dot, the * is the all-columns-alias
if (!$prev->isColumnReference() && !$prev->isConstant() && !$prev->isExpression()
&& !$prev->isBracketExpression() && !$prev->isAggregateFunction() && !$prev->isVariable()) {
if (
!$prev->isColumnReference()
&& !$prev->isConstant()
&& !$prev->isExpression()
&& !$prev->isBracketExpression()
&& !$prev->isAggregateFunction()
&& !$prev->isVariable()
&& !$prev->isFunction()
) {
$curr->setTokenType(ExpressionType::COLREF);
break;
}

View File

@@ -76,7 +76,7 @@ class FromProcessor extends AbstractProcessor {
}
// loop init
return array('expression' => "", 'token_count' => 0, 'table' => "", 'no_quotes' => "", 'alias' => false,
'hints' => false, 'join_type' => "", 'next_join_type' => "",
'hints' => array(), 'join_type' => "", 'next_join_type' => "",
'saved_join_type' => $parseInfo['saved_join_type'], 'ref_type' => false, 'ref_expr' => false,
'base_expr' => false, 'sub_tree' => false, 'subquery' => "");
}
@@ -84,13 +84,17 @@ class FromProcessor extends AbstractProcessor {
protected function processFromExpression(&$parseInfo) {
$res = array();
if ($parseInfo['hints'] === array()) {
$parseInfo['hints'] = false;
}
// exchange the join types (join_type is save now, saved_join_type holds the next one)
$parseInfo['join_type'] = $parseInfo['saved_join_type']; // initialized with JOIN
$parseInfo['saved_join_type'] = ($parseInfo['next_join_type'] ? $parseInfo['next_join_type'] : 'JOIN');
// we have a reg_expr, so we have to parse it
if ($parseInfo['ref_expr'] !== false) {
$unparsed = $this->splitSQLIntoTokens($parseInfo['ref_expr']);
$unparsed = $this->splitSQLIntoTokens(trim($parseInfo['ref_expr']));
// here we can get a comma separated list
foreach ($unparsed as $k => $v) {
@@ -186,6 +190,11 @@ class FromProcessor extends AbstractProcessor {
if ($token_category === 'LEFT' || $token_category === 'RIGHT' || $token_category === 'NATURAL') {
$token_category = '';
$parseInfo['next_join_type'] = strtoupper(trim($prevToken)); // it seems to be a join
} elseif ($token_category === 'IDX_HINT') {
$parseInfo['expression'] .= $token;
if ($parseInfo['ref_type'] !== false) { // all after ON / USING
$parseInfo['ref_expr'] .= $token;
}
}
break;
@@ -272,6 +281,12 @@ class FromProcessor extends AbstractProcessor {
break;
case 'FOR':
if ($token_category === 'IDX_HINT') {
$cur_hint = (count($parseInfo['hints']) - 1);
$parseInfo['hints'][$cur_hint]['hint_type'] .= " " . $upper;
continue 2;
}
$parseInfo['token_count']++;
$skip_next = true;
break;
@@ -291,6 +306,12 @@ class FromProcessor extends AbstractProcessor {
$parseInfo['next_join_type'] = 'CROSS';
case 'JOIN':
if ($token_category === 'IDX_HINT') {
$cur_hint = (count($parseInfo['hints']) - 1);
$parseInfo['hints'][$cur_hint]['hint_type'] .= " " . $upper;
continue 2;
}
if ($parseInfo['subquery']) {
$parseInfo['sub_tree'] = $this->parse($this->removeParenthesisFromStart($parseInfo['subquery']));
$parseInfo['expression'] = $parseInfo['subquery'];
@@ -300,6 +321,13 @@ class FromProcessor extends AbstractProcessor {
$parseInfo = $this->initParseInfo($parseInfo);
break;
case 'GROUP BY':
if ($token_category === 'IDX_HINT') {
$cur_hint = (count($parseInfo['hints']) - 1);
$parseInfo['hints'][$cur_hint]['hint_type'] .= " " . $upper;
continue 2;
}
default:
// TODO: enhance it, so we can have base_expr to calculate the position of the keywords
// build a subtree under "hints"

View File

@@ -72,7 +72,7 @@ class IndexProcessor extends AbstractProcessor {
$currCategory = 'INDEX_NAME';
$result = array('base_expr' => false, 'name' => false, 'no_quotes' => false, 'index-type' => false, 'on' => false,
'options' => false);
'options' => array());
$expr = array();
$base_expr = '';
$skip = 0;
@@ -300,6 +300,9 @@ class IndexProcessor extends AbstractProcessor {
$currCategory = '';
}
if ($result['options'] === array()) {
$result['options'] = false;
}
return $result;
}
}

View File

@@ -59,7 +59,7 @@ class SQLProcessor extends SQLChunkProcessor {
$prev_category = "";
$token_category = "";
$skip_next = 0;
$out = false;
$out = array();
// $tokens may come as a numeric indexed array starting with an index greater than 0 (or as a boolean)
$tokenCount = count($tokens);
@@ -242,7 +242,6 @@ class SQLProcessor extends SQLChunkProcessor {
case 'DELETE':
case 'ALTER':
case 'INSERT':
case 'TRUNCATE':
case 'OPTIMIZE':
case 'GRANT':
case 'REVOKE':
@@ -264,6 +263,17 @@ class SQLProcessor extends SQLChunkProcessor {
$out[$upper][0] = $trim;
continue 2;
case 'TRUNCATE':
if ($prev_category === '') {
// set the category in case these get subclauses in a future version of MySQL
$token_category = $upper;
$out[$upper][0] = $trim;
continue 2;
}
// part of the CREATE TABLE statement or a function
$out[$prev_category][] = $trim;
continue 2;
case 'REPLACE':
if ($prev_category === '') {
// set the category in case these get subclauses in a future version of MySQL
@@ -400,7 +410,7 @@ class SQLProcessor extends SQLChunkProcessor {
break;
case 'FOR':
if ($prev_category === 'SHOW') {
if ($prev_category === 'SHOW' || $token_category === 'FROM') {
break;
}
$skip_next = 1;
@@ -509,6 +519,10 @@ class SQLProcessor extends SQLChunkProcessor {
$prev_category = $token_category;
}
if (count($out) === 0) {
return false;
}
return parent::process($out);
}
}

View File

@@ -83,7 +83,7 @@ class TableProcessor extends AbstractProcessor {
$currCategory = 'TABLE_NAME';
$result = array('base_expr' => false, 'name' => false, 'no_quotes' => false, 'create-def' => false,
'options' => false, 'like' => false, 'select-option' => false);
'options' => array(), 'like' => false, 'select-option' => false);
$expr = array();
$base_expr = '';
$skip = 0;
@@ -366,6 +366,9 @@ class TableProcessor extends AbstractProcessor {
if ($result['select-option'] === false) {
unset($result['select-option']);
}
if ($result['options'] === array()) {
$result['options'] = false;
}
return $result;
}

View File

@@ -1,29 +0,0 @@
<?php
/**
* 2010-2021 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2021 Webkul IN
* @license https://store.webkul.com/license.html
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;

View File

@@ -71,7 +71,7 @@ class PHPSQLParserConstants {
'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DEC', 'DECIMAL', 'DECLARE', 'DEFAULT',
'DELAYED', 'DELETE', 'DESC', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCT', 'DISTINCTROW',
'DIV', 'DOUBLE', 'DROP', 'ELSE', 'ELSEIF', 'END', 'ENCLOSED', 'ESCAPED', 'EXISTS',
'EXIT', 'EXPLAIN', 'FALSE', 'FETCH', 'FIELDS', 'FLOAT', 'FOR', 'FORCE', 'FOREIGN',
'EXIT', 'EXPLAIN', 'FETCH', 'FIELDS', 'FLOAT', 'FOR', 'FORCE', 'FOREIGN',
'FOUND', 'FRAC_SECOND', 'FROM', 'FULLTEXT', 'GRANT', 'GROUP', 'HAVING',
'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', 'IF', 'IGNORE',
'IN', 'INDEX', 'INFILE', 'INNER', 'INNODB', 'INOUT', 'INSENSITIVE', 'INSERT', 'INT',
@@ -90,7 +90,7 @@ class PHPSQLParserConstants {
'SQL_TSI_MINUTE', 'SQL_TSI_MONTH', 'SQL_TSI_QUARTER', 'SQL_TSI_SECOND', 'SQL_TSI_WEEK',
'SQL_TSI_YEAR', 'SSL', 'STARTING', 'STRAIGHT_JOIN', 'STRIPED', 'TABLE', 'TABLES',
'TEMPORARY', 'TERMINATED', 'THEN', 'TIMESTAMPADD', 'TIMESTAMPDIFF', 'TINYBLOB',
'TINYINT', 'TINYTEXT', 'TO', 'TRAILING', 'TRUE', 'UNDO', 'UNION', 'UNIQUE', 'UNLOCK',
'TINYINT', 'TINYTEXT', 'TO', 'TRAILING', 'UNDO', 'UNION', 'UNIQUE', 'UNLOCK',
'UNSIGNED', 'UPDATE', 'USAGE', 'USE', 'USER_RESOURCES', 'USING', 'UTC_DATE',
'UTC_TIME', 'UTC_TIMESTAMP', 'VALUES', 'VARBINARY', 'VARCHAR', 'VARCHARACTER',
'VARYING', 'WHEN', 'WHERE', 'WHILE', 'WITH', 'WRITE', 'XOR', 'YEAR_MONTH', 'ZEROFILL');

View File

@@ -1,29 +0,0 @@
<?php
/**
* 2010-2021 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright 2010-2021 Webkul IN
* @license https://store.webkul.com/license.html
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;