Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/phpmyadmin/phpmyadmin
Browse files Browse the repository at this point in the history
  • Loading branch information
Tithugues committed Jul 19, 2015
2 parents 9a9b390 + 47ad60d commit 5aff600
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 54 deletions.
14 changes: 12 additions & 2 deletions js/console.js
Expand Up @@ -553,7 +553,12 @@ var PMA_consoleInput = {
mode: 'text/x-sql',
lineWrapping: true,
extraKeys: {"Ctrl-Space": "autocomplete"},
hintOptions: {"completeSingle": false, "completeOnSingleClick": true}
hintOptions: {"completeSingle": false, "completeOnSingleClick": true},
gutters: ["CodeMirror-lint-markers"],
lint: {
"getAnnotations": CodeMirror.sqlLint,
"async": true,
}
});
PMA_consoleInput._inputs.console.on("inputRead", codemirrorAutocompleteOnInputRead);
PMA_consoleInput._inputs.console.on("keydown", function(instance, event) {
Expand All @@ -565,7 +570,12 @@ var PMA_consoleInput = {
mode: 'text/x-sql',
lineWrapping: true,
extraKeys: {"Ctrl-Space": "autocomplete"},
hintOptions: {"completeSingle": false, "completeOnSingleClick": true}
hintOptions: {"completeSingle": false, "completeOnSingleClick": true},
gutters: ["CodeMirror-lint-markers"],
lint: {
"getAnnotations": CodeMirror.sqlLint,
"async": true,
}
});
PMA_consoleInput._inputs.bookmark.on("inputRead", codemirrorAutocompleteOnInputRead);
}
Expand Down
11 changes: 1 addition & 10 deletions libraries/sql-parser/src/Components/Array2d.php
Expand Up @@ -36,13 +36,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
{
$ret = array();

/**
* Whether an array was parsed or not. To be a valid parsing, at least
* one array must be parsed after each comma.
* @var bool $parsed
*/
$parsed = false;

/**
* The number of values in each set.
* @var int
Expand Down Expand Up @@ -95,22 +88,20 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$parser->error("{$count} values were expected, but found {$arrCount}.", $token);
}
$ret[] = $arr;
$parsed = true;
$state = 1;
} else {
break;
}
} elseif ($state === 1) {
if ($token->value === ',') {
$parsed = false;
$state = 0;
} else {
break;
}
}
}

if (!$parsed) {
if ($state === 0) {
$parser->error(
'An opening bracket followed by a set of values was expected.',
$list->tokens[$list->idx]
Expand Down
18 changes: 16 additions & 2 deletions libraries/sql-parser/src/Components/Expression.php
Expand Up @@ -239,6 +239,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =

if ($alias) {
// An alias is expected (the keyword `AS` was previously found).
if (!empty($ret->alias)) {
$parser->error('An alias was previously found.', $token);
}
$ret->alias = $token->value;
$alias = 0;
} else {
Expand All @@ -265,12 +268,18 @@ public static function parse(Parser $parser, TokensList $list, array $options =
break;
}

// Parsing aliases without `AS` keyword and any whitespace.
// Parsing aliases without `AS` keyword and any
// whitespace.
// Example: SELECT 1`foo`
if (($token->type === Token::TYPE_STRING)
|| (($token->type === Token::TYPE_SYMBOL)
&& ($token->flags & Token::FLAG_SYMBOL_BACKTICK))
) {
if (!empty($ret->alias)) {
$parser->error(
'An alias was previously found.', $token
);
}
$ret->alias = $token->value;
}
} else {
Expand All @@ -285,6 +294,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
if (($token->type === Token::TYPE_NONE) || ($token->type === Token::TYPE_STRING)
|| (($token->type === Token::TYPE_SYMBOL) && ($token->flags & Token::FLAG_SYMBOL_BACKTICK))
) {
if (!empty($ret->alias)) {
$parser->error(
'An alias was previously found.', $token
);
}
$ret->alias = $token->value;
continue;
}
Expand All @@ -301,8 +315,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =
} else {
$prev = null;
}

}

if ($alias === 2) {
$parser->error('An alias was expected.', $list->tokens[$list->idx - 1]);
}
Expand Down
35 changes: 28 additions & 7 deletions libraries/sql-parser/src/Components/ExpressionArray.php
Expand Up @@ -38,6 +38,20 @@ public static function parse(Parser $parser, TokensList $list, array $options =

$expr = null;

/**
* The state of the parser.
*
* Below are the states of the parser.
*
* 0 ----------------------[ array ]---------------------> 1
*
* 1 ------------------------[ , ]------------------------> 0
* 1 -----------------------[ else ]----------------------> -1
*
* @var int
*/
$state = 0;

for (; $list->idx < $list->count; ++$list->idx) {
/**
* Token parsed at this moment.
Expand All @@ -60,20 +74,27 @@ public static function parse(Parser $parser, TokensList $list, array $options =
break;
}

if (($token->type === Token::TYPE_OPERATOR) && ($token->value === ',')) {
$ret[] = $expr;
} else {
if ($state === 0) {
$expr = Expression::parse($parser, $list, $options);
if ($expr === null) {
break;
}
$ret[] = $expr;
$state = 1;
} elseif ($state === 1) {
if ($token->value === ',') {
$state = 0;
} else {
break;
}
}

}

// Last iteration was not processed.
if ($expr !== null) {
$ret[] = $expr;
if ($state === 0) {
$parser->error(
'An expression was expected.',
$list->tokens[$list->idx]
);
}

--$list->idx;
Expand Down
12 changes: 1 addition & 11 deletions libraries/sql-parser/src/Components/RenameOperation.php
Expand Up @@ -52,13 +52,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =

$expr = new RenameOperation();

/**
* Whether an operation was parsed or not. To be a valid parsing, at
* least one operation must be parsed after each comma.
* @var bool $parsed
*/
$parsed = false;

/**
* The state of the parser.
*
Expand Down Expand Up @@ -129,21 +122,18 @@ public static function parse(Parser $parser, TokensList $list, array $options =
$parser->error('The new name of the table was expected.', $token);
}
$state = 3;
$parsed = true;
} elseif ($state === 3) {
if (($token->type === Token::TYPE_OPERATOR) && ($token->value === ',')) {
$ret[] = $expr;
$expr = new RenameOperation();
$state = 0;
// Found a comma, looking for another operation.
$parsed = false;
} else {
break;
}
}
}

if (!$parsed) {
if ($state !== 3) {
$parser->error('A rename operation was expected.', $list->tokens[$list->idx - 1]);
}

Expand Down
28 changes: 16 additions & 12 deletions libraries/sql-parser/src/Parser.php
Expand Up @@ -327,6 +327,13 @@ public function parse()
// Statements can start with keywords only.
// Comments, whitespaces, etc. are ignored.
if ($token->type !== Token::TYPE_KEYWORD) {
if (($token->type !== TOKEN::TYPE_COMMENT)
&& ($token->type !== Token::TYPE_WHITESPACE)
&& ($token->type !== Token::TYPE_OPERATOR) // `(` and `)`
&& ($token->type !== Token::TYPE_DELIMITER)
) {
$this->error('Unexpected beginning of statement.', $token);
}
continue;
}

Expand All @@ -337,10 +344,7 @@ public function parse()

// Checking if it is a known statement that can be parsed.
if (empty(static::$STATEMENT_PARSERS[$token->value])) {
$this->error(
'Unrecognized statement type.',
$token
);
$this->error('Unrecognized statement type.', $token);
// Skipping to the end of this statement.
$list->getNextOfType(Token::TYPE_DELIMITER);
//
Expand All @@ -356,35 +360,35 @@ public function parse()

/**
* Processed statement.
* @var Statement $stmt
* @var Statement $statement
*/
$stmt = new $class($this, $this->list);
$statement = new $class($this, $this->list);

// The first token that is a part of this token is the next token
// unprocessed by the previous statement.
// There might be brackets around statements and this shouldn't
// affect the parser
$stmt->first = $prevLastIdx + 1;
$statement->first = $prevLastIdx + 1;

// Storing the index of the last token parsed and updating the old
// index.
$stmt->last = $list->idx;
$statement->last = $list->idx;
$prevLastIdx = $list->idx;

// Finally, storing the statement.
if (($inUnion)
&& ($lastStatement instanceof SelectStatement)
&& ($stmt instanceof SelectStatement)
&& ($statement instanceof SelectStatement)
) {
/**
* Last SELECT statement.
* @var SelectStatement $lastStatement
*/
$lastStatement->union[] = $stmt;
$lastStatement->union[] = $statement;
$inUnion = false;
} else {
$this->statements[] = $stmt;
$lastStatement = $stmt;
$this->statements[] = $statement;
$lastStatement = $statement;
}

}
Expand Down
5 changes: 5 additions & 0 deletions libraries/sql-parser/src/Statement.php
Expand Up @@ -195,6 +195,11 @@ public function parse(Parser $parser, TokensList $list)
// Only keywords are relevant here. Other parts of the query are
// processed in the functions below.
if ($token->type !== Token::TYPE_KEYWORD) {
if (($token->type !== TOKEN::TYPE_COMMENT)
&& ($token->type !== Token::TYPE_WHITESPACE)
) {
$parser->error('Unexpected token.', $token);
}
continue;
}

Expand Down
1 change: 1 addition & 0 deletions libraries/sql.lib.php
Expand Up @@ -665,6 +665,7 @@ function PMA_isJustBrowsing($analyzed_sql_results, $find_real_end)
&& ! $analyzed_sql_results['is_func']
&& empty($analyzed_sql_results['union'])
&& empty($analyzed_sql_results['distinct'])
&& $analyzed_sql_results['select_from']
&& count($analyzed_sql_results['select_tables'] <= 1)
&& (empty($analyzed_sql_results['statement']->where)
|| (count($analyzed_sql_results['statement']->where) == 1
Expand Down
19 changes: 9 additions & 10 deletions po/sl.po
Expand Up @@ -4,16 +4,16 @@ msgstr ""
"Project-Id-Version: phpMyAdmin 4.5.0-dev\n"
"Report-Msgid-Bugs-To: phpmyadmin-devel@lists.sourceforge.net\n"
"POT-Creation-Date: 2015-07-19 05:31-0400\n"
"PO-Revision-Date: 2015-07-12 20:53+0200\n"
"PO-Revision-Date: 2015-07-19 14:17+0200\n"
"Last-Translator: Domen <mitenem@outlook.com>\n"
"Language-Team: Slovenian <https://hosted.weblate.org/projects/phpmyadmin/"
"master/sl/>\n"
"Language-Team: Slovenian "
"<https://hosted.weblate.org/projects/phpmyadmin/master/sl/>\n"
"Language: sl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=4; plural=n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n"
"%100==4 ? 2 : 3;\n"
"Plural-Forms: nplurals=4; plural=n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || "
"n%100==4 ? 2 : 3;\n"
"X-Generator: Weblate 2.4-dev\n"

#: changelog.php:37 license.php:28
Expand Down Expand Up @@ -5643,12 +5643,12 @@ msgid ""
"Find any errors in the query before executing it. Requires CodeMirror to be "
"enabled."
msgstr ""
"Pred izvedbo poizvedbe najdi napake v njej. CodeMirror mora biti omogočen."

#: libraries/config/messages.inc.php:62
#, fuzzy
#| msgid "Enable SQL Validator"
msgid "Enable linter"
msgstr "Omogoči Preverjalnik SQL"
msgstr "Omogoči linter"

#: libraries/config/messages.inc.php:64
msgid ""
Expand Down Expand Up @@ -14701,10 +14701,9 @@ msgid "Pick from Central Columns"
msgstr "Izberite iz osrednjih stolpcev"

#: templates/columns_definitions/column_virtuality.phtml:46
#, fuzzy
#| msgid "Compression"
msgid "Expression"
msgstr "Stiskanje"
msgstr "Izraz"

#: templates/columns_definitions/move_column.phtml:7
msgid "first"
Expand Down Expand Up @@ -14732,7 +14731,7 @@ msgstr ""

#: templates/columns_definitions/table_fields_definitions.phtml:70
msgid "Virtuality"
msgstr ""
msgstr "Navideznost"

#: templates/columns_definitions/table_fields_definitions.phtml:76
msgid "Move column"
Expand Down

0 comments on commit 5aff600

Please sign in to comment.