PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 1, 2022

[FIXED] Mismatched/wrong query parameters using notMatching and where

 January 01, 2022     cakephp, cakephp-3.0     No comments   

Issue

I got a strange behaviour using the notMatching function of the query builder in combination with a standard where. The parameters given in OR/AND arrays seems to be mismatched (more precisely it seems to take the last one and use it for the pre-last one).

Here is my query:

$myModel
->find('list')
->where(['column' => 'a value to match']) // If I remove the entire line it works
->notMatching('AnotherModel', function ($query) use ($value, $anotherValue) {
    return $query->where([
        'OR' => [
            ['secondColumn >=' => $value],
            ['secondColumn <=' => $value]
        ],
        'thirdColumn' => $anotherValue
    ]);
});

And here is the generated SQL (simplified):

`column` = `a value to match`
AND (
  `MyModel`.`id` NOT IN (
    SELECT 
      ...
    FROM 
      ... 
    WHERE 
      (
        (
          `secondColumn` >= $value 
          OR `secondColumn` <= $anotherValue /* The issue */
        ) 
        AND `thirdColumn` = $anotherValue
      )
  )
)

As you can see, $anotherValue is used instead of $value. If I remove the entire first where (after the find) it works as excepted. And interestingly I don't have the issue with matching or innerJoinWith.


Solution

This seems to be fixed in CakePHP version 3.8.12



Answered By - randomUserName
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing