Incorrect parsing of WHERE LIKE with parameter
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start with the Parser tokenization path using the provided WHERE foo LIKE :bar sample and compare it with the backticked-column and = cases. Trace why the unquoted column, LIKE operator, and named parameter are combined, then add a regression test showing that foo, whitespace, LIKE, whitespace, and :bar are separate tokens.
Written by the indexing model from the issue text.
Description
When trying to parse a WHERE clause such as WHERE foo LIKE :bar it returns foo LIKE : as a single token, where as I would expect it to return foo LIKE :bar as individual tokens. It doesn't have this issue when using back ticks on the columns, or = instead of LIKE.
Sample script:
<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Token;
use PhpMyAdmin\SqlParser\TokensList;
$sql = 'SELECT * FROM test WHERE foo LIKE :bar';
echo 'sql: ' . $sql . PHP_EOL;
$parser = new Parser($sql);
foreach ($parser->list->tokens as $i => $token) {
echo 'token: ' . $token->token , PHP_EOL;
}
$sql = 'SELECT * FROM test WHERE `foo` LIKE :bar';
echo 'sql: ' . $sql . PHP_EOL;
$parser = new Parser($sql);
foreach ($parser->list->tokens as $i => $token) {
echo 'token: ' . $token->token , PHP_EOL;
}
$sql = 'SELECT * FROM test WHERE foo = :bar';
echo 'sql: ' . $sql . PHP_EOL;
$parser = new Parser($sql);
foreach ($parser->list->tokens as $i => $token) {
echo 'token: ' . $token->token , PHP_EOL;
}
Output:
sql: SELECT * FROM test WHERE foo LIKE :bar
token: SELECT
token:
token: *
token:
token: FROM
token:
token: test
token:
token: WHERE
token:
token: foo LIKE :
token: bar
token:
sql: SELECT * FROM test WHERE `foo` LIKE :bar
token: SELECT
token:
token: *
token:
token: FROM
token:
token: test
token:
token: WHERE
token:
token: `foo`
token:
token: LIKE
token:
token: :bar
token:
sql: SELECT * FROM test WHERE foo = :bar
token: SELECT
token:
token: *
token:
token: FROM
token:
token: test
token:
token: WHERE
token:
token: foo
token:
token: =
token:
token: :bar
token:
- Dominant language
- PHP
- Stars
- 485
- Forks
- 119
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phpmyadmin/sql-parser
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
phpmyadmin/sql-parser#655 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
phpmyadmin/sql-parser#666 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
phpmyadmin/sql-parser#662 · 2 reactions ·
-
kind/support
Difficulty 3/5 1-2 days Newbie friendliness 45/100
phpmyadmin/sql-parser#653 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 70/100
phpmyadmin/sql-parser#649 ·
All issues in phpmyadmin/sql-parser
Similar issues
-
a11y admissions.uiowa.edu needs grooming SiteImprove best practice
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Save States Menu Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
pluginsGLPI/datainjection#673 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
octobercms/october#6130 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
getgrav/grav-plugin-form#656 ·