-
Notifications
You must be signed in to change notification settings - Fork 48
Better support for SET
statements and MySQL variables
#214
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
Conversation
This traversal produces a natural ordering that corresponds to the original parsed input. It also aligns with CSS selector behavior. This is useful in situations when we need to reconstract or retrieve a fragment of the original input with tokens in the correct order.
…cient at the moment
&& WP_MySQL_Lexer::NAMES_SYMBOL === $part->id | ||
) { | ||
// "SET NAMES ..." is a no-op for now. | ||
// TODO: Validate charset compatibility with UTF-8. |
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.
should we call _doing_it_wrong to log a warning?
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.
@adamziel We'll need to validate it somehow, but I think that should be part of #192. If we do it properly (getting a list of all commonly supported charsets and, for each one of them evaluating whether they are UTF-8 compatible or not), then maybe we can even throw an error. Or at least a warning.
We can't use directly _doing_it_wrong
as that's WP-specific, but we want the driver to be more universal.
$value = str_replace( "''", "'", $value ); | ||
$value = substr( $value, 1, -1 ); | ||
/* | ||
* Some MySQL system variables values can be set using an unquoted pure |
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.
tricky! TIL
/* | ||
* Handle ON/OFF values. They are accepted as both strings and keywords. | ||
* | ||
* @TODO: This is actually variable-specific and depends on the its type. |
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.
tricky! oh, MySQL 🤦
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.
@adamziel Yeah... So to support the system variables better in the future, we'll need a list of them, their types, etc. And for some of them, we should implement whatever behavior they modify.
$name = $this->unquote_sqlite_identifier( | ||
$this->translate( $user_variable->get_first_child() ) | ||
); | ||
$name = strtolower( substr( $name, 1 ) ); // Remove '@', normalize case. |
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.
any chance we get a double @@
here?
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.
@adamziel I think that should be excluded by the grammar — single @
is user variable, double @
is system variable.
* @return mixed The value of the expression. | ||
*/ | ||
public function evaluate_expression( WP_Parser_Node $node ) { | ||
// To support expressions, we'll use a SQLite query. |
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.
smart!
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.
Great work, as always @JanJakes – thank you!
Co-authored-by: Adam Zieliński <[email protected]>
This pull request implements better support for MySQL
SET
statements.It also implements additional related functionality and resolves some related issues:
CONCAT('a', 'b')
to('a' || 'b')
, we need to use the originalCONCAT('a', 'b')
string as the column name. In other words,SELECT CONCAT('a', 'b')
will be translated toSELECT ('a' || 'b') AS ’CONCAT('a', 'b')’
. This is also needed when selecting user and system variables (see the items below).SET NAMES
,SET CHARSET
, andSET CHARACTER SET
are a no-op now, with aTODO
to implement some validation logic in Charset and collation support #192.SET @my_var = ...
,SELECT @my_var
).SET time_zone = ...
,SET @@time_zone = ...
, ,SET @@session.time_zone = ...
,SELECT @@time_zone
,SELECT @@session.time_zone
, etc.). The variables are not yet interpreted in any way, and they are not merged with global system variables at the moment.