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

Fix replace clause of select statement with FOR UPDATE #555

Merged

Conversation

MoonE
Copy link
Contributor

@MoonE MoonE commented Apr 28, 2024

Fixes phpmyadmin/phpmyadmin#17190

Replaces _END_OPTIONS with the actual names from here:

public static $END_OPTIONS = [
'FOR UPDATE' => 1,
'LOCK IN SHARE MODE' => 1,
];
/**
* The clauses of this statement, in order.
*
* @see Statement::$CLAUSES
*
* @var array<string, array<int, int|string>>
* @psalm-var array<string, array{non-empty-string, (1|2|3)}>
*/
public static $CLAUSES = [
'SELECT' => [
'SELECT',
2,
],
// Used for options.
'_OPTIONS' => [
'_OPTIONS',
1,
],
// Used for selected expressions.
'_SELECT' => [
'SELECT',
1,
],
'INTO' => [
'INTO',
3,
],
'FROM' => [
'FROM',
3,
],
'FORCE' => [
'FORCE',
1,
],
'USE' => [
'USE',
1,
],
'IGNORE' => [
'IGNORE',
3,
],
'PARTITION' => [
'PARTITION',
3,
],
'JOIN' => [
'JOIN',
1,
],
'FULL JOIN' => [
'FULL JOIN',
1,
],
'INNER JOIN' => [
'INNER JOIN',
1,
],
'LEFT JOIN' => [
'LEFT JOIN',
1,
],
'LEFT OUTER JOIN' => [
'LEFT OUTER JOIN',
1,
],
'RIGHT JOIN' => [
'RIGHT JOIN',
1,
],
'RIGHT OUTER JOIN' => [
'RIGHT OUTER JOIN',
1,
],
'NATURAL JOIN' => [
'NATURAL JOIN',
1,
],
'NATURAL LEFT JOIN' => [
'NATURAL LEFT JOIN',
1,
],
'NATURAL RIGHT JOIN' => [
'NATURAL RIGHT JOIN',
1,
],
'NATURAL LEFT OUTER JOIN' => [
'NATURAL LEFT OUTER JOIN',
1,
],
'NATURAL RIGHT OUTER JOIN' => [
'NATURAL RIGHT JOIN',
1,
],
'WHERE' => [
'WHERE',
3,
],
'GROUP BY' => [
'GROUP BY',
3,
],
'_GROUP_OPTIONS' => [
'_GROUP_OPTIONS',
1,
],
'HAVING' => [
'HAVING',
3,
],
'ORDER BY' => [
'ORDER BY',
3,
],
'LIMIT' => [
'LIMIT',
3,
],
'PROCEDURE' => [
'PROCEDURE',
3,
],
'UNION' => [
'UNION',
1,
],
'EXCEPT' => [
'EXCEPT',
1,
],
'INTERSECT' => [
'INTERSECT',
1,
],
'_END_OPTIONS' => [
'_END_OPTIONS',
1,
],

FOR UPDATE and LOCK IN SHARE MODE are not in the clauses array,
replace _END_OPTIONS with these values so they are found.

Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
Comment on lines +472 to +474
if (static::$END_OPTIONS !== []) {
array_push($clauses, ...array_keys(static::$END_OPTIONS));
}
Copy link
Contributor Author

@MoonE MoonE Apr 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When merging to master (PHP >= 7.3) the if is no long needed

Suggested change
if (static::$END_OPTIONS !== []) {
array_push($clauses, ...array_keys(static::$END_OPTIONS));
}
array_push($clauses, ...array_keys(static::$END_OPTIONS));

https://www.php.net/manual/en/function.array-push.php

{
$clauses = [];
foreach (array_keys($this->getClauses()) as $key) {
if ($key === '_END_OPTIONS') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When merging in master, this key changes name

@MauricioFauth MauricioFauth changed the base branch from 5.9.x to 5.10.x May 23, 2024 14:01
@MauricioFauth MauricioFauth merged commit b5b0f39 into phpmyadmin:5.10.x May 23, 2024
9 of 17 checks passed
@MauricioFauth MauricioFauth self-assigned this May 23, 2024
@MauricioFauth MauricioFauth added this to the 5.10.0 milestone May 23, 2024
@MoonE MoonE deleted the select-for-update-clause-order branch May 23, 2024 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants