Libs changes for php 8.x
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user