Skip to content

Commit

Permalink
Fixes #11509, #11512, #11518.
Browse files Browse the repository at this point in the history
Updated sql-parser library to phpmyadmin/sql-parser@2f5d2da (v2.1.1).

Signed-off-by: Dan Ungureanu <udan1107@gmail.com>
  • Loading branch information
Dan Ungureanu committed Oct 1, 2015
1 parent b10a08e commit ce6c465
Show file tree
Hide file tree
Showing 39 changed files with 1,577 additions and 1,420 deletions.
132 changes: 58 additions & 74 deletions libraries/sql-parser/src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,89 +10,73 @@
*
* @package SqlParser
*/
namespace SqlParser;

namespace {
require_once 'common.php';

if (!function_exists('__')) {
/**
* A component (of a statement) is a part of a statement that is common to
* multiple query types.
*
* @category Components
* @package SqlParser
* @author Dan Ungureanu <udan1107@gmail.com>
* @license http://opensource.org/licenses/GPL-2.0 GNU Public License
*/
abstract class Component
{

/**
* Translates the given string.
*
* @param string $str String to be translated.
*
* @return string
*/
function __($str)
{
return $str;
}
/**
* Parses the tokens contained in the given list in the context of the given
* parser.
*
* @param Parser $parser The parser that serves as context.
* @param TokensList $list The list of tokens that are being parsed.
* @param array $options Parameters for parsing.
*
* @throws \Exception Not implemented yet.
*
* @return mixed
*/
public static function parse(
Parser $parser,
TokensList $list,
array $options = array()
) {
// This method should be abstract, but it can't be both static and
// abstract.
throw new \Exception(\__('Not implemented yet.'));
}
}

namespace SqlParser {

/**
* A component (of a statement) is a part of a statement that is common to
* multiple query types.
* Builds the string representation of a component of this type.
*
* In other words, this function represents the inverse function of
* `static::parse`.
*
* @category Components
* @package SqlParser
* @author Dan Ungureanu <udan1107@gmail.com>
* @license http://opensource.org/licenses/GPL-2.0 GNU Public License
* @param mixed $component The component to be built.
* @param array $options Parameters for building.
*
* @throws \Exception Not implemented yet.
*
* @return string
*/
abstract class Component
public static function build($component, array $options = array())
{
// This method should be abstract, but it can't be both static and
// abstract.
throw new \Exception(\__('Not implemented yet.'));
}

/**
* Parses the tokens contained in the given list in the context of the given
* parser.
*
* @param Parser $parser The parser that serves as context.
* @param TokensList $list The list of tokens that are being parsed.
* @param array $options Parameters for parsing.
*
* @throws \Exception Not implemented yet.
*
* @return mixed
*/
public static function parse(
Parser $parser, TokensList $list, array $options = array()
) {
// This method should be abstract, but it can't be both static and
// abstract.
throw new \Exception(\__('Not implemented yet.'));
}

/**
* Builds the string representation of a component of this type.
*
* In other words, this function represents the inverse function of
* `static::parse`.
*
* @param mixed $component The component to be built.
* @param array $options Parameters for building.
*
* @throws \Exception Not implemented yet.
*
* @return string
*/
public static function build($component, array $options = array())
{
// This method should be abstract, but it can't be both static and
// abstract.
throw new \Exception(\__('Not implemented yet.'));
}

/**
* Builds the string representation of a component of this type.
*
* @see static::build
*
* @return string
*/
public function __toString()
{
return static::build($this);
}
/**
* Builds the string representation of a component of this type.
*
* @see static::build
*
* @return string
*/
public function __toString()
{
return static::build($this);
}
}
1 change: 0 additions & 1 deletion libraries/sql-parser/src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
1 change: 0 additions & 1 deletion libraries/sql-parser/src/Components/Array2d.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
3 changes: 1 addition & 2 deletions libraries/sql-parser/src/Components/ArrayObj.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(array $raw = array(), array $values = array())
* @param TokensList $list The list of tokens that are being parsed.
* @param array $options Parameters for parsing.
*
* @return mixed
* @return ArrayObj|Component[]
*/
public static function parse(Parser $parser, TokensList $list, array $options = array())
{
Expand All @@ -79,7 +79,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
2 changes: 1 addition & 1 deletion libraries/sql-parser/src/Components/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Condition extends Component
'IN' => 1,
'IS' => 1,
'LIKE' => 1,
'NOT IN' => 1,
'NOT NULL' => 1,
'NULL' => 1,
'OR' => 1,
Expand Down Expand Up @@ -111,7 +112,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$betweenBefore = false;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
9 changes: 6 additions & 3 deletions libraries/sql-parser/src/Components/CreateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@ class CreateDefinition extends Component
* @param bool $isConstraint Whether this field is a constraint or not.
* @param Reference $references References.
*/
public function __construct($name = null, $options = null, $type = null,
$isConstraint = false, $references = null
public function __construct(
$name = null,
$options = null,
$type = null,
$isConstraint = false,
$references = null
) {
$this->name = $name;
$this->options = $options;
Expand Down Expand Up @@ -178,7 +182,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
5 changes: 3 additions & 2 deletions libraries/sql-parser/src/Components/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ class DataType extends Component
* @param array $parameters The parameters (size or possible values).
* @param OptionsArray $options The options of this data type.
*/
public function __construct($name = null, array $parameters = array(),
public function __construct(
$name = null,
array $parameters = array(),
$options = null
) {
$this->name = $name;
Expand Down Expand Up @@ -108,7 +110,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
2 changes: 0 additions & 2 deletions libraries/sql-parser/src/Components/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$prev = null;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down Expand Up @@ -274,7 +273,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
// field should be skipped; used to parse table names).
$field = (!empty($options['skipColumn'])) ? 'table' : 'column';
if (!empty($ret->$field)) {

// No alias is expected.
if (!empty($options['noAlias'])) {
break;
Expand Down
1 change: 0 additions & 1 deletion libraries/sql-parser/src/Components/ExpressionArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
1 change: 0 additions & 1 deletion libraries/sql-parser/src/Components/FunctionCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
1 change: 0 additions & 1 deletion libraries/sql-parser/src/Components/IntoKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
7 changes: 4 additions & 3 deletions libraries/sql-parser/src/Components/JoinKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class JoinKeyword extends Component
'INNER JOIN' => 'INNER',
'JOIN' => 'JOIN',
'LEFT JOIN' => 'LEFT',
'LEFT OUTER JOIN' => 'LEFT',
'RIGHT JOIN' => 'RIGHT',
'RIGHT OUTER JOIN' => 'RIGHT',
);

/**
Expand Down Expand Up @@ -98,7 +100,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down Expand Up @@ -132,7 +133,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
if (($token->type === Token::TYPE_KEYWORD) && ($token->value === 'ON')) {
$state = 3;
}
} else if ($state === 3) {
} elseif ($state === 3) {
$expr->on = Condition::parse($parser, $list);
$ret[] = $expr;
$expr = new JoinKeyword();
Expand Down Expand Up @@ -160,7 +161,7 @@ public static function build($component, array $options = array())
$ret = array();
foreach ($component as $c) {
$ret[] = (($c->type === 'JOIN') ? 'JOIN ' : ($c->type . ' JOIN '))
. $c->expr . ' ON ' . Condition::build($c->on);
. $c->expr . ' ON ' . Condition::build($c->on);
}
return implode(' ', $ret);
}
Expand Down
8 changes: 5 additions & 3 deletions libraries/sql-parser/src/Components/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ class Key extends Component
* @param string $type The type of this key.
* @param OptionsArray $options The options of this key.
*/
public function __construct($name = null, array $columns = array(),
$type = null, $options = null
public function __construct(
$name = null,
array $columns = array(),
$type = null,
$options = null
) {
$this->name = $name;
$this->columns = $columns;
Expand Down Expand Up @@ -119,7 +122,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
1 change: 0 additions & 1 deletion libraries/sql-parser/src/Components/Limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$offset = false;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
1 change: 0 additions & 1 deletion libraries/sql-parser/src/Components/OptionsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
1 change: 0 additions & 1 deletion libraries/sql-parser/src/Components/OrderKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {

/**
* Token parsed at this moment.
*
Expand Down
Loading

0 comments on commit ce6c465

Please sign in to comment.