Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect parsing of WHERE LIKE with parameter #253

Open
Petah opened this issue Jul 10, 2019 · 1 comment
Open

Incorrect parsing of WHERE LIKE with parameter #253

Petah opened this issue Jul 10, 2019 · 1 comment
Labels
enhancement kind/support A request for adding support

Comments

@Petah
Copy link

Petah commented Jul 10, 2019

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:
@williamdes williamdes added the bug label Apr 21, 2023
@williamdes
Copy link
Member

williamdes commented Apr 21, 2023

This may be related to #425 (comment)
And to: #202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement kind/support A request for adding support
Projects
None yet
Development

No branches or pull requests

2 participants