first version
This commit is contained in:
162
tools/parser_sql/utils/ExpressionToken.php
Normal file
162
tools/parser_sql/utils/ExpressionToken.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
require_once dirname(__FILE__) . '/ExpressionType.php';
|
||||
|
||||
class ExpressionToken {
|
||||
|
||||
private $subTree;
|
||||
private $expression;
|
||||
private $key;
|
||||
private $token;
|
||||
private $tokenType;
|
||||
private $trim;
|
||||
private $upper;
|
||||
private $noQuotes;
|
||||
|
||||
public function __construct($key = "", $token = "") {
|
||||
$this->subTree = false;
|
||||
$this->expression = "";
|
||||
$this->key = $key;
|
||||
$this->token = $token;
|
||||
$this->tokenType = false;
|
||||
$this->trim = trim($token);
|
||||
$this->upper = strtoupper($this->trim);
|
||||
$this->noQuotes = null;
|
||||
}
|
||||
|
||||
# TODO: we could replace it with a constructor new ExpressionToken(this, "*")
|
||||
public function addToken($string) {
|
||||
$this->token .= $string;
|
||||
}
|
||||
|
||||
public function isEnclosedWithinParenthesis() {
|
||||
return ($this->upper[0] === '(' && substr($this->upper, -1) === ')');
|
||||
}
|
||||
|
||||
public function setSubTree($tree) {
|
||||
$this->subTree = $tree;
|
||||
}
|
||||
|
||||
public function getSubTree() {
|
||||
return $this->subTree;
|
||||
}
|
||||
|
||||
public function getUpper($idx = false) {
|
||||
return $idx !== false ? $this->upper[$idx] : $this->upper;
|
||||
}
|
||||
|
||||
public function getTrim($idx = false) {
|
||||
return $idx !== false ? $this->trim[$idx] : $this->trim;
|
||||
}
|
||||
|
||||
public function getToken($idx = false) {
|
||||
return $idx !== false ? $this->token[$idx] : $this->token;
|
||||
}
|
||||
|
||||
public function setNoQuotes($token, $qchars = '`') {
|
||||
$this->noQuotes = ($token === null) ? null : $this->revokeQuotation($token, $qchars);
|
||||
}
|
||||
|
||||
public function setTokenType($type) {
|
||||
$this->tokenType = $type;
|
||||
}
|
||||
|
||||
public function endsWith($needle) {
|
||||
$length = strlen($needle);
|
||||
if ($length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$start = $length * -1;
|
||||
return (substr($this->token, $start) === $needle);
|
||||
}
|
||||
|
||||
public function isWhitespaceToken() {
|
||||
return ($this->trim === "");
|
||||
}
|
||||
|
||||
public function isCommaToken() {
|
||||
return ($this->trim === ",");
|
||||
}
|
||||
|
||||
public function isVariableToken() {
|
||||
return $this->upper[0] === '@';
|
||||
}
|
||||
|
||||
public function isSubQueryToken() {
|
||||
return preg_match("/^\\(\\s*SELECT/i", $this->trim);
|
||||
}
|
||||
|
||||
public function isExpression() {
|
||||
return $this->tokenType === ExpressionType::EXPRESSION;
|
||||
}
|
||||
|
||||
public function isBracketExpression() {
|
||||
return $this->tokenType === ExpressionType::BRACKET_EXPRESSION;
|
||||
}
|
||||
|
||||
public function isOperator() {
|
||||
return $this->tokenType === ExpressionType::OPERATOR;
|
||||
}
|
||||
|
||||
public function isInList() {
|
||||
return $this->tokenType === ExpressionType::IN_LIST;
|
||||
}
|
||||
|
||||
public function isFunction() {
|
||||
return $this->tokenType === ExpressionType::SIMPLE_FUNCTION;
|
||||
}
|
||||
|
||||
public function isUnspecified() {
|
||||
return ($this->tokenType === false);
|
||||
}
|
||||
|
||||
public function isVariable() {
|
||||
return $this->tokenType === ExpressionType::GLOBAL_VARIABLE || $this->tokenType === ExpressionType::LOCAL_VARIABLE || $this->tokenType === ExpressionType::USER_VARIABLE;
|
||||
}
|
||||
|
||||
public function isAggregateFunction() {
|
||||
return $this->tokenType === ExpressionType::AGGREGATE_FUNCTION;
|
||||
}
|
||||
|
||||
public function isColumnReference() {
|
||||
return $this->tokenType === ExpressionType::COLREF;
|
||||
}
|
||||
|
||||
public function isConstant() {
|
||||
return $this->tokenType === ExpressionType::CONSTANT;
|
||||
}
|
||||
|
||||
public function isSign() {
|
||||
return $this->tokenType === ExpressionType::SIGN;
|
||||
}
|
||||
|
||||
public function isSubQuery() {
|
||||
return $this->tokenType === ExpressionType::SUBQUERY;
|
||||
}
|
||||
|
||||
private function revokeQuotation($token, $qchars = '`') {
|
||||
$result = trim($token);
|
||||
for ($i = 0; $i < strlen($qchars); $i++) {
|
||||
$quote = $qchars[$i];
|
||||
if (($result[0] === $quote) && ($result[strlen($result) - 1] === $quote)) {
|
||||
$result = substr($result, 1, -1);
|
||||
return trim(str_replace($quote.$quote, $quote, $result));
|
||||
}
|
||||
}
|
||||
return $token;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
$result = array();
|
||||
$result['expr_type'] = $this->tokenType;
|
||||
$result['base_expr'] = $this->token;
|
||||
if (!empty($this->noQuotes)) {
|
||||
$result['no_quotes'] = $this->noQuotes;
|
||||
}
|
||||
$result['sub_tree'] = $this->subTree;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
116
tools/parser_sql/utils/ExpressionType.php
Normal file
116
tools/parser_sql/utils/ExpressionType.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* ExpressionType.php
|
||||
*
|
||||
* Defines all values, which are possible for the [expr_type] field
|
||||
* within the parser output.
|
||||
*
|
||||
* 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: ExpressionType.php 836 2013-12-20 05:31:55Z phosco@gmx.de $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class defines all values, which are possible for the [expr_type] field
|
||||
* within the parser output.
|
||||
*
|
||||
* @author André Rothe <andre.rothe@phosco.info>
|
||||
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
|
||||
*
|
||||
*/
|
||||
class ExpressionType {
|
||||
|
||||
const USER_VARIABLE = "user_variable";
|
||||
const SESSION_VARIABLE = "session_variable";
|
||||
const GLOBAL_VARIABLE = "global_variable";
|
||||
const LOCAL_VARIABLE = "local_variable";
|
||||
|
||||
const COLDEF = "column-def";
|
||||
const COLREF = "colref";
|
||||
const RESERVED = "reserved";
|
||||
const CONSTANT = "const";
|
||||
|
||||
const AGGREGATE_FUNCTION = "aggregate_function";
|
||||
const SIMPLE_FUNCTION = "function";
|
||||
|
||||
const EXPRESSION = "expression";
|
||||
const BRACKET_EXPRESSION = "bracket_expression";
|
||||
const TABLE_EXPRESSION = "table_expression";
|
||||
|
||||
const SUBQUERY = "subquery";
|
||||
const IN_LIST = "in-list";
|
||||
const OPERATOR = "operator";
|
||||
const SIGN = "sign";
|
||||
const RECORD = "record";
|
||||
|
||||
const MATCH_ARGUMENTS = "match-arguments";
|
||||
const MATCH_MODE = "match-mode";
|
||||
|
||||
const ALIAS = "alias";
|
||||
const POSITION = "pos";
|
||||
|
||||
const TEMPORARY_TABLE = "temporary-table";
|
||||
const TABLE = "table";
|
||||
const VIEW = "view";
|
||||
const DATABASE = "database";
|
||||
const SCHEMA = "schema";
|
||||
|
||||
const PROCEDURE = "procedure";
|
||||
const ENGINE = "engine";
|
||||
const USER = "user";
|
||||
const DIRECTORY = "directory";
|
||||
const UNION = "union";
|
||||
const CHARSET = "character-set";
|
||||
const COLLATE = "collation";
|
||||
|
||||
const LIKE = "like";
|
||||
const CONSTRAINT = "constraint";
|
||||
const PRIMARY_KEY = "primary-key";
|
||||
const FOREIGN_KEY = "foreign-key";
|
||||
const UNIQUE_IDX = "unique-index";
|
||||
const INDEX = "index";
|
||||
const FULLTEXT_IDX = "fulltext-index";
|
||||
const SPATIAL_IDX = "spatial-index";
|
||||
const INDEX_TYPE = "index-type";
|
||||
const CHECK = "check";
|
||||
const COLUMN_LIST = "column-list";
|
||||
const INDEX_COLUMN = "index-column";
|
||||
const INDEX_SIZE = "index-size";
|
||||
const INDEX_PARSER = "index-parser";
|
||||
const REFERENCE = "foreign-ref";
|
||||
|
||||
const DATA_TYPE = "data-type";
|
||||
const COLUMN_TYPE = "column-type";
|
||||
const DEF_VALUE = "default-value";
|
||||
}
|
||||
?>
|
||||
184
tools/parser_sql/utils/PHPSQLParserConstants.php
Normal file
184
tools/parser_sql/utils/PHPSQLParserConstants.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* constants.php
|
||||
*
|
||||
* Some constants for the PHPSQLParser.
|
||||
*
|
||||
* Copyright (c) 2010-2012, Justin Swanhart
|
||||
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*/
|
||||
|
||||
class PHPSQLParserConstants {
|
||||
|
||||
protected static $reserved = array('ABS', 'ACOS', 'ADDDATE', 'ADDTIME', 'AES_ENCRYPT', 'AES_DECRYPT', 'AGAINST',
|
||||
'ASCII', 'ASIN', 'ATAN', 'AVG', 'BENCHMARK', 'BIN', 'BIT_AND', 'BIT_OR',
|
||||
'BITCOUNT', 'BITLENGTH', 'CAST', 'CEILING', 'CHAR', 'CHAR_LENGTH',
|
||||
'CHARACTER_LENGTH', 'CHARSET', 'COALESCE', 'COERCIBILITY', 'COLLATION',
|
||||
'COMPRESS', 'CONCAT', 'CONCAT_WS', 'CONNECTION_ID', 'CONV', 'CONVERT',
|
||||
'CONVERT_TZ', 'COS', 'COT', 'COUNT', 'CRC32', 'CURDATE', 'CURRENT_USER',
|
||||
'CURRVAL', 'CURTIME', 'DATABASE', 'DATETIME', 'DATE_ADD', 'DATE_DIFF',
|
||||
'DATE_FORMAT', 'DATE_SUB', 'DAY', 'DAYNAME', 'DAYOFMONTH', 'DAYOFWEEK',
|
||||
'DAYOFYEAR', 'DECODE', 'DEFAULT', 'DEGREES', 'DES_DECRYPT', 'DES_ENCRYPT',
|
||||
'ELT', 'ENCODE', 'ENCRYPT', 'EXISTS', 'EXP', 'EXPORT_SET', 'EXTRACT', 'FIELD',
|
||||
'FIND_IN_SET', 'FLOOR', 'FORMAT', 'FOUND_ROWS', 'FROM_DAYS', 'FROM_UNIXTIME',
|
||||
'GET_FORMAT', 'GET_LOCK', 'GROUP_CONCAT', 'GREATEST', 'HEX', 'HOUR', 'IF',
|
||||
'IFNULL', 'IN', 'INET_ATON', 'INET_NTOA', 'INSERT', 'INSTR', 'INTERVAL',
|
||||
'IS_FREE_LOCK', 'IS_USED_LOCK', 'LAST_DAY', 'LAST_INSERT_ID', 'LCASE', 'LEAST',
|
||||
'LEFT', 'LENGTH', 'LN', 'LOAD_FILE', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCATE',
|
||||
'LOG', 'LOG2', 'LOG10', 'LOWER', 'LPAD', 'LTRIM', 'MAKE_SET', 'MAKEDATE',
|
||||
'MAKETIME', 'MASTER_POS_WAIT', 'MATCH', 'MAX', 'MD5', 'MICROSECOND', 'MID',
|
||||
'MIN', 'MINUTE', 'MOD', 'MONTH', 'MONTHNAME', 'NEXTVAL', 'NOW', 'NULLIF', 'OCT',
|
||||
'OCTET_LENGTH', 'OLD_PASSWORD', 'ORD', 'PASSWORD', 'PERIOD_ADD', 'PERIOD_DIFF',
|
||||
'PI', 'POSITION', 'POW', 'POWER', 'QUARTER', 'QUOTE', 'RADIANS', 'RAND',
|
||||
'RELEASE_LOCK', 'REPEAT', 'REPLACE', 'REVERSE', 'RIGHT', 'ROUND', 'ROW_COUNT',
|
||||
'RPAD', 'RTRIM', 'SEC_TO_TIME', 'SECOND', 'SESSION_USER', 'SHA', 'SHA1', 'SIGN',
|
||||
'SOUNDEX', 'SPACE', 'SQRT', 'STD', 'STDDEV', 'STDDEV_POP', 'STDDEV_SAMP',
|
||||
'STRCMP', 'STR_TO_DATE', 'SUBDATE', 'SUBSTRING', 'SUBSTRING_INDEX', 'SUBTIME',
|
||||
'SUM', 'SYSDATE', 'SYSTEM_USER', 'TAN', 'TIME', 'TIMEDIFF', 'TIMESTAMP',
|
||||
'TIMESTAMPADD', 'TIMESTAMPDIFF', 'TIME_FORMAT', 'TIME_TO_SEC', 'TO_DAYS',
|
||||
'TRIM', 'TRUNCATE', 'UCASE', 'UNCOMPRESS', 'UNCOMPRESSED_LENGTH', 'UNHEX',
|
||||
'UNIX_TIMESTAMP', 'UPPER', 'USER', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP',
|
||||
'UUID', 'VAR_POP', 'VAR_SAMP', 'VARIANCE', 'VERSION', 'WEEK', 'WEEKDAY',
|
||||
'WEEKOFYEAR', 'YEAR', 'YEARWEEK', 'ADD', 'ALL', 'ALTER', 'ANALYZE', 'AND', 'AS',
|
||||
'ASC', 'ASENSITIVE', 'AUTO_INCREMENT', 'BDB', 'BEFORE', 'BERKELEYDB', 'BETWEEN',
|
||||
'BIGINT', 'BINARY', 'BLOB', 'BOTH', 'BY', 'CALL', 'CASCADE', 'CASE', 'CHANGE',
|
||||
'CHAR', 'CHARACTER', 'CHECK', 'COLLATE', 'COLUMN', 'COLUMNS', 'CONDITION',
|
||||
'CONNECTION', 'CONSTRAINT', 'CONTINUE', 'CREATE', 'CROSS', 'CURRENT_DATE',
|
||||
'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURSOR', 'DATABASE', 'DATABASES',
|
||||
'DAY_HOUR', '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', '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', 'INTEGER', 'INTERVAL', 'INTO',
|
||||
'IO_THREAD', 'IS', 'ITERATE', 'JOIN', 'KEY', 'KEYS', 'KILL', 'LEADING', 'LEAVE',
|
||||
'LEFT', 'LIKE', 'LIMIT', 'LINES', 'LOAD', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCK',
|
||||
'LONG', 'LONGBLOB', 'LONGTEXT', 'LOOP', 'LOW_PRIORITY', 'MASTER_SERVER_ID',
|
||||
'MATCH', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT',
|
||||
'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MOD', 'NATURAL', 'NOT',
|
||||
'NO_WRITE_TO_BINLOG', 'NULL', 'NUMERIC', 'ON', 'OPTIMIZE', 'OPTION',
|
||||
'OPTIONALLY', 'OR', 'ORDER', 'OUT', 'OUTER', 'OUTFILE', 'PRECISION', 'PRIMARY',
|
||||
'PRIVILEGES', 'PROCEDURE', 'PURGE', 'READ', 'REAL', 'REFERENCES', 'REGEXP',
|
||||
'RENAME', 'REPEAT', 'REPLACE', 'REQUIRE', 'RESTRICT', 'RETURN', 'REVOKE',
|
||||
'RIGHT', 'RLIKE', 'SECOND_MICROSECOND', 'SELECT', 'SENSITIVE', 'SEPARATOR',
|
||||
'SET', 'SHOW', 'SMALLINT', 'SOME', 'SONAME', 'SPATIAL', 'SPECIFIC', 'SQL',
|
||||
'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SQL_BIG_RESULT',
|
||||
'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT', 'SQL_TSI_DAY', 'SQL_TSI_FRAC_SECOND',
|
||||
'SQL_TSI_HOUR', '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', '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');
|
||||
|
||||
protected static $parameterizedFunctions = array('ABS', 'ACOS', 'ADDDATE', 'ADDTIME', 'AES_ENCRYPT', 'AES_DECRYPT',
|
||||
'AGAINST', 'ASCII', 'ASIN', 'ATAN', 'AVG', 'BENCHMARK', 'BIN',
|
||||
'BIT_AND', 'BIT_OR', 'BITCOUNT', 'BITLENGTH', 'CAST', 'CEILING',
|
||||
'CHAR', 'CHAR_LENGTH', 'CHARACTER_LENGTH', 'CHARSET', 'COALESCE',
|
||||
'COERCIBILITY', 'COLLATION', 'COMPRESS', 'CONCAT', 'CONCAT_WS',
|
||||
'CONV', 'CONVERT', 'CONVERT_TZ', 'COS', 'COT', 'COUNT', 'CRC32',
|
||||
'CURRVAL', 'DATE_ADD', 'DATE_DIFF', 'DATE_FORMAT', 'DATE_SUB',
|
||||
'DAY', 'DAYNAME', 'DAYOFMONTH', 'DAYOFWEEK', 'DAYOFYEAR',
|
||||
'DECODE', 'DEFAULT', 'DEGREES', 'DES_DECRYPT', 'DES_ENCRYPT',
|
||||
'ELT', 'ENCODE', 'ENCRYPT', 'EXP', 'EXPORT_SET', 'EXTRACT',
|
||||
'FIELD', 'FIND_IN_SET', 'FLOOR', 'FORMAT', 'FROM_DAYS',
|
||||
'FROM_UNIXTIME', 'GET_FORMAT', 'GET_LOCK', 'GROUP_CONCAT',
|
||||
'GREATEST', 'HEX', 'HOUR', 'IF', 'IFNULL', 'IN', 'INET_ATON',
|
||||
'INET_NTOA', 'INSERT', 'INSTR', 'INTERVAL', 'IS_FREE_LOCK',
|
||||
'IS_USED_LOCK', 'LAST_DAY', 'LCASE', 'LEAST', 'LEFT', 'LENGTH',
|
||||
'LN', 'LOAD_FILE', 'LOCATE', 'LOG', 'LOG2', 'LOG10', 'LOWER',
|
||||
'LPAD', 'LTRIM', 'MAKE_SET', 'MAKEDATE', 'MAKETIME',
|
||||
'MASTER_POS_WAIT', 'MATCH', 'MAX', 'MD5', 'MICROSECOND', 'MID',
|
||||
'MIN', 'MINUTE', 'MOD', 'MONTH', 'MONTHNAME', 'NEXTVAL', 'NULLIF',
|
||||
'OCT', 'OCTET_LENGTH', 'OLD_PASSWORD', 'ORD', 'PASSWORD',
|
||||
'PERIOD_ADD', 'PERIOD_DIFF', 'PI', 'POSITION', 'POW', 'POWER',
|
||||
'QUARTER', 'QUOTE', 'RADIANS', 'RELEASE_LOCK', 'REPEAT',
|
||||
'REPLACE', 'REVERSE', 'RIGHT', 'ROUND', 'RPAD', 'RTRIM',
|
||||
'SEC_TO_TIME', 'SECOND', 'SHA', 'SHA1', 'SIGN', 'SOUNDEX',
|
||||
'SPACE', 'SQRT', 'STD', 'STDDEV', 'STDDEV_POP', 'STDDEV_SAMP',
|
||||
'STRCMP', 'STR_TO_DATE', 'SUBDATE', 'SUBSTRING',
|
||||
'SUBSTRING_INDEX', 'SUBTIME', 'SUM', 'TAN', 'TIME', 'TIMEDIFF',
|
||||
'TIMESTAMP', 'TIMESTAMPADD', 'TIMESTAMPDIFF', 'TIME_FORMAT',
|
||||
'TIME_TO_SEC', 'TO_DAYS', 'TRIM', 'TRUNCATE', 'UCASE',
|
||||
'UNCOMPRESS', 'UNCOMPRESSED_LENGTH', 'UNHEX', 'UPPER', 'VAR_POP',
|
||||
'VAR_SAMP', 'VARIANCE', 'WEEK', 'WEEKDAY', 'WEEKOFYEAR', 'YEAR',
|
||||
'YEARWEEK');
|
||||
|
||||
protected static $functions = array('ABS', 'ACOS', 'ADDDATE', 'ADDTIME', 'AES_ENCRYPT', 'AES_DECRYPT', 'AGAINST',
|
||||
'ASCII', 'ASIN', 'ATAN', 'AVG', 'BENCHMARK', 'BIN', 'BIT_AND', 'BIT_OR',
|
||||
'BITCOUNT', 'BITLENGTH', 'CAST', 'CEILING', 'CHAR', 'CHAR_LENGTH',
|
||||
'CHARACTER_LENGTH', 'CHARSET', 'COALESCE', 'COERCIBILITY', 'COLLATION',
|
||||
'COMPRESS', 'CONCAT', 'CONCAT_WS', 'CONNECTION_ID', 'CONV', 'CONVERT',
|
||||
'CONVERT_TZ', 'COS', 'COT', 'COUNT', 'CRC32', 'CURDATE', 'CURRENT_USER',
|
||||
'CURRVAL', 'CURTIME', 'DATABASE', 'DATE_ADD', 'DATE_DIFF', 'DATE_FORMAT',
|
||||
'DATE_SUB', 'DAY', 'DAYNAME', 'DAYOFMONTH', 'DAYOFWEEK', 'DAYOFYEAR', 'DECODE',
|
||||
'DEFAULT', 'DEGREES', 'DES_DECRYPT', 'DES_ENCRYPT', 'ELT', 'ENCODE', 'ENCRYPT',
|
||||
'EXP', 'EXPORT_SET', 'EXTRACT', 'FIELD', 'FIND_IN_SET', 'FLOOR', 'FORMAT',
|
||||
'FOUND_ROWS', 'FROM_DAYS', 'FROM_UNIXTIME', 'GET_FORMAT', 'GET_LOCK',
|
||||
'GROUP_CONCAT', 'GREATEST', 'HEX', 'HOUR', 'IF', 'IFNULL', 'IN', 'INET_ATON',
|
||||
'INET_NTOA', 'INSERT', 'INSTR', 'INTERVAL', 'IS_FREE_LOCK', 'IS_USED_LOCK',
|
||||
'LAST_DAY', 'LAST_INSERT_ID', 'LCASE', 'LEAST', 'LEFT', 'LENGTH', 'LN',
|
||||
'LOAD_FILE', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCATE', 'LOG', 'LOG2', 'LOG10',
|
||||
'LOWER', 'LPAD', 'LTRIM', 'MAKE_SET', 'MAKEDATE', 'MAKETIME',
|
||||
'MASTER_POS_WAIT', 'MATCH', 'MAX', 'MD5', 'MICROSECOND', 'MID', 'MIN',
|
||||
'MINUTE', 'MOD', 'MONTH', 'MONTHNAME', 'NEXTVAL', 'NOW', 'NULLIF', 'OCT',
|
||||
'OCTET_LENGTH', 'OLD_PASSWORD', 'ORD', 'PASSWORD', 'PERIOD_ADD', 'PERIOD_DIFF',
|
||||
'PI', 'POSITION', 'POW', 'POWER', 'QUARTER', 'QUOTE', 'RADIANS', 'RAND',
|
||||
'RELEASE_LOCK', 'REPEAT', 'REPLACE', 'REVERSE', 'RIGHT', 'ROUND', 'ROW_COUNT',
|
||||
'RPAD', 'RTRIM', 'SEC_TO_TIME', 'SECOND', 'SESSION_USER', 'SHA', 'SHA1',
|
||||
'SIGN', 'SOUNDEX', 'SPACE', 'SQRT', 'STD', 'STDDEV', 'STDDEV_POP',
|
||||
'STDDEV_SAMP', 'STRCMP', 'STR_TO_DATE', 'SUBDATE', 'SUBSTRING',
|
||||
'SUBSTRING_INDEX', 'SUBTIME', 'SUM', 'SYSDATE', 'SYSTEM_USER', 'TAN', 'TIME',
|
||||
'TIMEDIFF', 'TIMESTAMP', 'TIMESTAMPADD', 'TIMESTAMPDIFF', 'TIME_FORMAT',
|
||||
'TIME_TO_SEC', 'TO_DAYS', 'TRIM', 'TRUNCATE', 'UCASE', 'UNCOMPRESS',
|
||||
'UNCOMPRESSED_LENGTH', 'UNHEX', 'UNIX_TIMESTAMP', 'UPPER', 'USER', 'UTC_DATE',
|
||||
'UTC_TIME', 'UTC_TIMESTAMP', 'UUID', 'VAR_POP', 'VAR_SAMP', 'VARIANCE',
|
||||
'VERSION', 'WEEK', 'WEEKDAY', 'WEEKOFYEAR', 'YEAR', 'YEARWEEK');
|
||||
|
||||
protected static $aggregateFunctions = array('AVG', 'SUM', 'COUNT', 'MIN', 'MAX', 'STDDEV', 'STDDEV_SAMP',
|
||||
'STDDEV_POP', 'VARIANCE', 'VAR_SAMP', 'VAR_POP', 'GROUP_CONCAT',
|
||||
'BIT_AND', 'BIT_OR', 'BIT_XOR');
|
||||
|
||||
public static function isAggregateFunction($token) {
|
||||
return in_array($token, PHPSQLParserConstants::$aggregateFunctions);
|
||||
}
|
||||
|
||||
public static function isReserved($token) {
|
||||
return in_array($token, PHPSQLParserConstants::$reserved);
|
||||
}
|
||||
|
||||
public static function isFunction($token) {
|
||||
return in_array($token, PHPSQLParserConstants::$functions);
|
||||
}
|
||||
|
||||
public static function isParameterizedFunction($token) {
|
||||
return in_array($token, PHPSQLParserConstants::$parameterizedFunctions);
|
||||
}
|
||||
}
|
||||
?>
|
||||
150
tools/parser_sql/utils/PHPSQLParserUtils.php
Normal file
150
tools/parser_sql/utils/PHPSQLParserUtils.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPSQLParserUtils.php
|
||||
*
|
||||
* These are utility functions for the PHPSQLParser.
|
||||
*
|
||||
* Copyright (c) 2010-2012, Justin Swanhart
|
||||
* with contributions by André Rothe <arothe@phosco.info, phosco@gmx.de>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements some helper functions.
|
||||
*
|
||||
* @author arothe
|
||||
* @deprecated
|
||||
*/
|
||||
class PHPSQLParserUtils {
|
||||
|
||||
/**
|
||||
* Prints an array only if debug mode is on.
|
||||
*
|
||||
* @param array $s
|
||||
* @param boolean $return, if true, the formatted array is returned via return parameter
|
||||
*/
|
||||
protected function preprint($arr, $return = false) {
|
||||
$x = "<pre>";
|
||||
$x .= print_r($arr, 1);
|
||||
$x .= "</pre>";
|
||||
if ($return) {
|
||||
return $x;
|
||||
} else {
|
||||
if (isset($_ENV['DEBUG'])) {
|
||||
print $x . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the given string $haystack with the string $needle?
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string $needle
|
||||
*/
|
||||
protected function endsWith($haystack, $needle) {
|
||||
$length = strlen($needle);
|
||||
if ($length == 0) {
|
||||
return true;
|
||||
}
|
||||
return (substr($haystack, -$length) === $needle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revokes the quoting characters from an expression
|
||||
*/
|
||||
protected function revokeQuotation($sql) {
|
||||
$result = trim($sql);
|
||||
if (($result[0] === '`') && ($result[strlen($result) - 1] === '`')) {
|
||||
$result = substr($result, 1, -1);
|
||||
return trim(str_replace('``', '`', $result));
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method removes parenthesis from start of the given string.
|
||||
* It removes also the associated closing parenthesis.
|
||||
*/
|
||||
protected function removeParenthesisFromStart($token) {
|
||||
|
||||
$parenthesisRemoved = 0;
|
||||
|
||||
$trim = trim($token);
|
||||
if ($trim !== "" && $trim[0] === "(") { // remove only one parenthesis pair now!
|
||||
$parenthesisRemoved++;
|
||||
$trim[0] = " ";
|
||||
$trim = trim($trim);
|
||||
}
|
||||
|
||||
$parenthesis = $parenthesisRemoved;
|
||||
$i = 0;
|
||||
$string = 0;
|
||||
while ($i < strlen($trim)) {
|
||||
|
||||
if ($trim[$i] === "\\") {
|
||||
$i += 2; # an escape character, the next character is irrelevant
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($trim[$i] === "'" || $trim[$i] === '"') {
|
||||
$string++;
|
||||
}
|
||||
|
||||
if (($string % 2 === 0) && ($trim[$i] === "(")) {
|
||||
$parenthesis++;
|
||||
}
|
||||
|
||||
if (($string % 2 === 0) && ($trim[$i] === ")")) {
|
||||
if ($parenthesis == $parenthesisRemoved) {
|
||||
$trim[$i] = " ";
|
||||
$parenthesisRemoved--;
|
||||
}
|
||||
$parenthesis--;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
return trim($trim);
|
||||
}
|
||||
|
||||
public function getLastOf($array) {
|
||||
// $array is a copy of the original array, so we can change it without sideeffects
|
||||
if (!is_array($array)) {
|
||||
return false;
|
||||
}
|
||||
return array_pop($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* translates an array of objects into an associative array
|
||||
*/
|
||||
public function toArray($tokenList) {
|
||||
$expr = array();
|
||||
foreach ($tokenList as $token) {
|
||||
$expr[] = $token->toArray();
|
||||
}
|
||||
return (empty($expr) ? false : $expr);
|
||||
}
|
||||
}
|
||||
?>
|
||||
35
tools/parser_sql/utils/index.php
Normal file
35
tools/parser_sql/utils/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2015 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2015 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
Reference in New Issue
Block a user