简体   繁体   中英

Why Zend Framework is adding parentheses in where clause?

I have the following query:

$tagCordQuery = $this->freqDb->select()
                    ->from("rr_amplifiers", "*")
                    ->join("amplifiers_coordinate", "amplifiers_coordinate.name = TRIM(TRAILING '0' FROM  rr_amplifiers.name)", array())
                    ->where("amplifiers_coordinate.name IN(?)", $apsName);

Where $apsName it's an array.

The problem is when this array has only one element the query had extra parenthesis like this:

SELECT `rr_amplifiers`.* FROM `rr_amplifiers`
 INNER JOIN `amplifiers_coordinate` ON amplifiers_coordinate.name = TRIM(TRAILING '0' FROM  rr_amplifiers.name) WHERE (amplifiers_coordinate.name IN('xpto'))

Why this it's happen?

It's in case you did something like this:

->where("amplifiers_coordinate.name IN(?) OR something = 1", $apsName);

(ie include an OR condition in the WHERE). Without the parentheses, the query wouldn't work as you'd expect.

Zend Framework allows you to add more than one where statement. Always wrapping the clause in parentheses prevents unintended logic from occuring.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM