-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Feature ansi mode, partial solution to #284 #294
Conversation
Thank you for the PR @smarek |
Codecov Report
@@ Coverage Diff @@
## QA #294 +/- ##
==========================================
- Coverage 100% 99.67% -0.33%
- Complexity 1874 1883 +9
==========================================
Files 63 63
Lines 4540 4557 +17
==========================================
+ Hits 4540 4542 +2
- Misses 0 15 +15 |
@williamdes thank you, also because I'm dumb, could you put up some guide, how to create new test? I can certainly provide SQL input data (such as |
Maybe you could be searching for https://github.com/phpmyadmin/sql-parser/blob/master/CONTRIBUTING.md#testsuite ? |
geez, yes, thank you very much |
Ok, I'm still not sure what I'm doing, but i've added ANSI_QUOTES generator and tests logic, and single case for lexer and parser (same test data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch looks good to me
Can you rebase all the commits onto QA branch or do you want me to do it ?
Please do the rebase and updates you mentioned in code review, it will be faster and easier for both of us |
2e18e60
to
ab89cc5
Compare
It should be okay now |
ab89cc5
to
bd519e4
Compare
Thank you @smarek for your contribution ! |
Cheers, however did you test it ? I mean standalone parsing / re-assembling seemed to work for me, but there were more places in code that I did not touch, is merging this complete solution ? |
I did not make a real-world test but the code and tests looked good to me |
Ok, do you want me to provide test environment? I can and i gladly will But me fixing the tests to work, does not mean it works and is complete solution As i wrote in phpmyadmin/phpmyadmin#15821 (comment) there is a great number of issues with phpmyadmin (suddenly) when using this patched version against ANSI sql_mode DB-server, and I'd expect phpmyadmin to be kind-of agnostic to sql_mode given that this should handle sql-parser library, but hey, I expect you to at least test the changes, once we get to fix the phpmyadmin in ANSI mode, am I right? |
Yes of course, go ahead ;) |
Signed-off-by: William Desportes <williamdes@wdes.fr>
// Using appropriate quotes.
if (($compat === 'MSSQL') || ($sql_backquotes === '"')) {
Context::$MODE |= Context::SQL_MODE_ANSI_QUOTES;
} On the main repo |
diff --git a/src/Context.php b/src/Context.php
index 8792117d..0124d88d 100644
--- a/src/Context.php
+++ b/src/Context.php
@@ -417,7 +417,7 @@ abstract class Context
}
if ($str[0] === '@') {
return Token::FLAG_SYMBOL_VARIABLE;
- } elseif ($str[0] === self::getIdentifierQuote()) {
+ } elseif ($str[0] === '`') {
return Token::FLAG_SYMBOL_BACKTICK;
} elseif ($str[0] === ':' || $str[0] === '?') {
return Token::FLAG_SYMBOL_PARAMETER;
diff --git a/src/Lexer.php b/src/Lexer.php
index a56641e8..3cf0d187 100644
--- a/src/Lexer.php
+++ b/src/Lexer.php
@@ -935,7 +935,7 @@ class Lexer extends Core
$str = null;
if ($this->last < $this->len) {
- if (($str = $this->parseString(Context::getIdentifierQuote())) === null) {
+ if (($str = $this->parseString('`')) === null) {
if (($str = $this->parseUnknown()) === null) {
$this->error(
'Variable name was expected.',
Fixes the test |
https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_ansi_quotes
So both are now identifiers |
This reverts commit bd519e4. Signed-off-by: William Desportes <williamdes@wdes.fr>
@williamdes how's it going with re-reverting the changes? |
It was reverted partially, would you agree to work on implementing another time the reverted part of the feature? |
This is very trivial, and I have no idea, what might have been broken by these changes, but phpunit does not complain about anything, so you definitely haven't written enough tests 😆
/s
It allows you to retrieve current identifiers quoting char from
Context::getIdentifierQuote()
based on current SQL Mode set and seems to work well with CLI tools such as lint and highlight-queryThere are still few places, where the backtick is hard-coded, and I'm not sure if I should update these pieces of code with new context-aware solution, but that I probably leave to someone who knows this code-base better.
I've tested this with sample SQL query from: phpmyadmin/phpmyadmin#15821 (comment)
Fixes: #284