fix: simulate query matched rows wrong count#18536
fix: simulate query matched rows wrong count#18536MauricioFauth merged 6 commits intophpmyadmin:QA_5_2from
Conversation
Signed-off-by: kamioon <kamran.azari@gmail.com>
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## QA_5_2 #18536 +/- ##
============================================
- Coverage 48.02% 47.76% -0.27%
+ Complexity 17011 17010 -1
============================================
Files 607 607
Lines 72342 72339 -3
============================================
- Hits 34741 34550 -191
- Misses 37601 37789 +188
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
| $notEqualOperator = ' IS NOT '; | ||
| $diff[] = $set->column . ' IS NOT ' . $set->value; | ||
| }else{ | ||
| $diff[] = '(' . $set->column . ' <> ' . $set->value . ' OR ' . $set->column . ' IS NULL)'; |
There was a problem hiding this comment.
I would get rid of both parentheses here, since aren't need. Examples of generated queries with and without parentheses.
SELECT `b` FROM `test` WHERE `a` = 2 AND ((`b` <> 'test' OR `b` IS NULL))
SELECT `b` FROM `test` WHERE `a` = 2 AND (`b` <> 'test' OR `b` IS NULL)
SELECT `b`, `c` FROM `test` WHERE `a` = 1 AND ((`b` <> 'test' OR `b` IS NULL) OR (`c` <> 'test' OR `c` IS NULL))
SELECT `b`, `c` FROM `test` WHERE `a` = 1 AND (`b` <> 'test' OR `b` IS NULL OR `c` <> 'test' OR `c` IS NULL)
SELECT `b`, `c` FROM `test` WHERE `a` = 2 AND (`b` IS NOT NULL OR (`c` <> 'test' OR `c` IS NULL))
SELECT `b`, `c` FROM `test` WHERE `a` = 2 AND (`b` IS NOT NULL OR `c` <> 'test' OR `c` IS NULL)There was a problem hiding this comment.
It makes sense. considering that they are all OR, it is not really necessary. I've removed them.
add space before and after the else keyword Signed-off-by: kamioon <kamran.azari@gmail.com>
| if (strtoupper($set->value) === 'NULL') { | ||
| $notEqualOperator = ' IS NOT '; | ||
| $diff[] = $set->column . ' IS NOT ' . $set->value; | ||
| } else { | ||
| $diff[] = $set->column . ' <> ' . $set->value . ' OR ' . $set->column . ' IS NULL'; | ||
| } |
There was a problem hiding this comment.
Some love for the MySQL <=> operator?
| if (strtoupper($set->value) === 'NULL') { | |
| $notEqualOperator = ' IS NOT '; | |
| $diff[] = $set->column . ' IS NOT ' . $set->value; | |
| } else { | |
| $diff[] = $set->column . ' <> ' . $set->value . ' OR ' . $set->column . ' IS NULL'; | |
| } | |
| $diff[] = 'NOT ' . $set->column . ' <=> (' . $set->value . ')'; |
There was a problem hiding this comment.
It broke my brain 😂
Thanks for sharing it
There was a problem hiding this comment.
Thank you @MoonE ! I kept the additional parentheses that you have added it seems to keep the value safe. but are there any special conditions without them that ruin the query?
There was a problem hiding this comment.
This can happen with an update query like
UPDATE a SET b = c OR d WHERE e OR fIt would generate NOT b <=> c OR d instead of NOT b <=> (c OR d)
With that in mind the original condition should also be set in parenthesis:
if (! empty($diff)) {
- $where .= ' AND (' . implode(' OR ', $diff) . ')';
+ $where = '(' . $where . ') AND (' . implode(' OR ', $diff) . ')';
}to generate the condition
WHERE (e OR f) AND (NOT b <=> (c OR d)) instead of
WHERE e OR f AND (NOT b <=> (c OR d))
Signed-off-by: kamioon <kamran.azari@gmail.com>
|
@kamioon You also need to adjust the test here phpmyadmin/test/classes/Import/SimulateDmlTest.php Lines 51 to 54 in dd5d340 and also modify the same query here phpmyadmin/test/classes/Stubs/DbiDummy.php Lines 2231 to 2235 in dd5d340 @williamdes @MauricioFauth Unit tests still pass because the test is marked incomplete here phpmyadmin/test/classes/Stubs/DbiDummy.php Line 135 in dd5d340 and PHPUnit is not run with --fail-on-incomplete / failOnIncomplete="true"
|
Signed-off-by: kamioon <kamran.azari@gmail.com>
Signed-off-by: kamioon <kamran.azari@gmail.com>
MoonE
left a comment
There was a problem hiding this comment.
For what it's woth, I think this is ready.
This is a bug fix for #18533
The
<>operator excludesNULLvalues. read moreFixes: #18533