Repository navigation
Closed
Labels
BugA problem or regression with an existing featureparserwaiting on upstreamIssues blocked by a third-party
Milestone
Description
Describe the bug
UDATING/DELETING/INSERTING with non back-ticked table names that start with an integer cause errors, though it is valid in MySQL. (Probably other query types too)
Works fine:
UPDATE `0searchhistoryx` SET complete = 1 WHERE id = 1;Causes error:
UPDATE 0searchhistoryx SET complete = 1 WHERE id = 1;To Reproduce
Steps to reproduce the behavior:
- Open database
- Create table named 0searchhistoryx
- Open SQL tab
- Enter SQL
"UPDATE 0searchhistoryx SET complete = 1 WHERE id = 1;" - Click "Go"
- See error
=====
Error in processing request
Error code: 500
Error text: Internal Server Error (rejected)
It seems that the connection to server has been lost. Please check your network connectivity and server status.
=====
> Fatal error</b>: Uncaught TypeError: Argument 1 passed to PhpMyAdmin\DatabaseInterface::escapeString() must be of the type string, null given, called in /var/www/html/ask/pmaask/libraries/classes/Tracker.php on line 149 and defined in /var/www/html/ask/pmaask/libraries/classes/DatabaseInterface.php:3000
> Stack trace:
> #0 /var/www/html/ask/pmaask/libraries/classes/Tracker.php(149): PhpMyAdmin\DatabaseInterface->escapeString()
> #1 /var/www/html/ask/pmaask/libraries/classes/Tracker.php(841): PhpMyAdmin\Tracker::isTracked()
> #2 /var/www/html/ask/pmaask/libraries/classes/DatabaseInterface.php(354): PhpMyAdmin\Tracker::handleQuery()
> #3 /var/www/html/ask/pmaask/libraries/classes/Sql.php(958): PhpMyAdmin\DatabaseInterface->tryQuery()
> #4 /var/www/html/ask/pmaask/libraries/classes/Sql.php(1177): PhpMyAdmin\Sql->executeQueryAndMeasureTime()
> #5 /var/www/html/ask/pmaask/libraries/classes/Sql.php(2225): PhpMyAdmin\Sql->executeTheQuery()
> #6 /var/www/html/ask/pmaask/import.php(760): PhpMyAdmin\Sql->executeQueryAndGetQueryResponse()
> #7 {main}
> t in <b>/var/www/html/ask/pmaask/libraries/classes/DatabaseInterface.php</b> on line <b>3000
=====
Expected behavior
Runs SQL happily
Screenshots
If applicable, add screenshots to help explain your problem.
Server configuration
- Operating system: Centos 8
- Web server: Apache/2.4.37 (centos)
- Database version: MySQL 8.0.17
- PHP version: 7.4.3 & 7.4.4
- phpMyAdmin version: 5.0.1 & 5.0.2
Client configuration
- Browser: Chrome
- Operating system: Windows 10
Additional context
Add any other context about the problem here.
Class \PhpMyAdmin\SqlParser\Lexer separates the 0 from the rest of the table name.
[0] => PhpMyAdmin\SqlParser\Token Object
(
[token] => UPDATE
[value] => UPDATE
[keyword] => UPDATE
[type] => 1
[flags] => 3
[position] => 0
[method] => parseKeyword
)
[1] => PhpMyAdmin\SqlParser\Token Object
(
[token] =>
[value] =>
[keyword] =>
[type] => 3
[flags] => 0
[position] => 6
[method] => parseWhitespace
)
[2] => PhpMyAdmin\SqlParser\Token Object
(
[token] => 0
[value] => 0
[keyword] =>
[type] => 6
[flags] => 0
[position] => 7
[method] => parseNumber
)
[3] => PhpMyAdmin\SqlParser\Token Object
(
[token] => searchhistoryx
[value] => searchhistoryx
[keyword] =>
[type] => 0
[flags] => 0
[position] => 8
[method] => parseUnknown
)
[4] => PhpMyAdmin\SqlParser\Token Object
(
[token] =>
[value] =>
[keyword] =>
[type] => 3
[flags] => 0
[position] => 22
[method] => parseWhitespace
)
[5] => PhpMyAdmin\SqlParser\Token Object
(
[token] => SET
[value] => SET
[keyword] => SET
[type] => 1
[flags] => 11
[position] => 23
[method] => parseKeyword
)
[6] => PhpMyAdmin\SqlParser\Token Object
(
[token] =>
[value] =>
[keyword] =>
[type] => 3
[flags] => 0
[position] => 26
[method] => parseWhitespace
)
[7] => PhpMyAdmin\SqlParser\Token Object
(
[token] => `complete`
[value] => complete
[keyword] =>
[type] => 8
[flags] => 2
[position] => 27
[method] => parseSymbol
)
My quick fixes for simple queries: (Not the best way I'm sure)
Statement.php - Add at line 263
// UPDATE 0table
// Fixes table names starting with a integer in updates
$lastIdx = $list->idx;
if ($this instanceof Statements\UpdateStatement) {
if ($token->value === 'UPDATE') {
++$list->idx; // Skip ON
$first = $list->getNext();
$second = $list->getNext();
if ($first->type == Token::TYPE_NUMBER && $second->type == Token::TYPE_NONE) {
$first->type = Token::TYPE_WHITESPACE;
$first->value = ' ';
$second->type = Token::TYPE_SYMBOL;
$second->value = $first->value . $second->value;
}
}
}
$list->idx = $lastIdx;DeleteStatement.php - Add at line 242
// DELETE 0table
// Fixes table names starting with a integer in updates
$lastIdx = $list->idx;
for (; $list->idx < $list->count; ++$list->idx) {
$token = $list->tokens[$list->idx];
if ($token->value === 'FROM') {
++$list->idx; // Skip ON
$first = $list->getNext();
$second = $list->getNext();
if ($first->type == Token::TYPE_NUMBER && $second->type == Token::TYPE_NONE) {
$first->type = Token::TYPE_WHITESPACE;
$first->value = ' ';
$second->type = Token::TYPE_SYMBOL;
$second->value = $first->value . $second->value;
}
break;
}
}
$list->idx = $lastIdx;
// END DELETE FIXPerhaps should be fixed in Lexer instead
Reacted by Chris Hewett
Metadata
Metadata
Assignees
Labels
BugA problem or regression with an existing featureparserwaiting on upstreamIssues blocked by a third-party
Activity
williamdes commentedon Mar 31, 2020
Thank you for the detailed report, I hope that it will be fixed soon :)
If you want you can open a pull-request on the https://github.com/phpmyadmin/sql-parser repository to branch QA
MatthewAsia commentedon Apr 4, 2020
Also appears to happen with INSERT INTO 0table
Tithugues commentedon Apr 14, 2020
@MattyTheMad , thanks for noticing it. With the changes, it seems to fix the
INSERTalso.Merge #300 - Don't allow numbers with letters
shucon commentedon Oct 8, 2020
Is it done?
williamdes commentedon Oct 8, 2020
Waiting for https://github.com/phpmyadmin/sql-parser/milestone/10 release
ibennetch commentedon Oct 8, 2020