Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
Trivial
-
Resolution: Won't Fix
-
Affects Version/s: 1.7.2
-
Fix Version/s: 1.9.3
-
Component/s: Zend_Db_Adapter_Mysqli
-
Labels:None
Description
When creating a query, and then checking the actual query using __toString(), it seems backtick usage is inconsistent. Given the following code:
$select = $db->select()
->from(array('iv' => 'indicator_version'))
->columns(array('type' => new Zend_Db_Expr("'".self::TYPE_VERSION_DATA."'")))
->join(array('ivc' => 'country_indicator_version'), 'iv.id = ivc.indicator_version_id', array('value' => 'ivc.value', 'show_footnote' => 'ivc.show_footnote', 'footnote_desc' => 'ivc.footnote_desc'))
->join(array('c' => 'country'), 'ivc.country_id = c.id', array('country' => 'c.name', 'country_id' => 'c.id' ,'fips_code'=>'c.fips_code'))
->join(array('i' => 'indicator'), 'iv.indicator_id = i.id', array('sort' => 'i.sort'))
->where('iv.id = ?', (int) $version_id)
->where('ivc.value IS NOT NULL')
->order('ivc.value desc');
I currently get the following query:
SELECT `iv`.*, 'versiondata' AS `type`, `ivc`.`value`, `ivc`.`show_footnote`, `ivc`.`footnote_desc`, `c`.`name` AS `country`, `c`.`id` AS `country_id`, `c`.`fips_code`, `i`.`sort` FROM `indicator_version` AS `iv` INNER JOIN `country_indicator_version` AS `ivc` ON iv.id = ivc.indicator_version_id INNER JOIN `country` AS `c` ON ivc.country_id = c.id INNER JOIN `indicator` AS `i` ON iv.indicator_id = i.id WHERE (iv.id = 2) AND (ivc.value IS NOT NULL) ORDER BY `ivc`.`value` desc
As you can notice WHERE clauses and the ON clauses for joins do not have backticks. At first, I thought this to be related to the fact that those strings are literally added in our code, but then I noticed that the value of the ORDER clause does have backticks (even though we didn't add backticks in our code). So it seems in some situations, backticks are added, but in others they aren't. This seems inconsistent and may result in problems when using specific field names.
This issue also happens on 1.8.0 ?