Re: DataObject Query

From: Date: Thu, 28 Sep 2006 16:47:58 +0000
Subject: Re: DataObject Query
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-25285@lists.php.net to get a copy of this message
On 9/28/06, Ian Warner <iwarner@triangle-solutions.com> wrote:
Justin I would love to apply the patch trouble is PEAR site is down can you send me the code please :) Yeah this was done quickly I usually write out then go through the optimisation later when the client pays :) Just a note, if you patched a bug then why was it not included in the DO script?
Alan has some problem or other with it, I don't remember for sure now. Ah, sorry, I've lost the patch. Server crash last year. Here's Google's cache of the bug: http://72.14.253.104/search?q=cache:WPTIDjwEx50J:pear.php.net/bugs/3734+site:pear.php.net+bug+DB_DataObject+joinAdd+%22on+clause%22&hl=en&gl=us&ct=clnk&cd=3
Justin Patrin wrote: On 9/28/06, Ian Warner <iwarner@triangle-solutions.com> wrote:
Hi I have the following query generated through DO -- SELECT sms_services.service_id, sms_services.service, sms_services.watershed, sms_services.free_msgs, sms_services.type, sms_services.multiple_signups, sms_keywords.keyword_id, sms_keywords.keyword, sms_shortcodes.shortcode_id, sms_shortcodes.shortcode, COUNT(DISTINCT sms_customers_services.customer_services_id) AS total, sms_actions.action_id FROM sms_services LEFT JOIN admin.sms_actions ON admin.sms_actions.service_id=sms_services.service_id LEFT JOIN admin.sms_keywords ON admin.sms_keywords.service_id=sms_services.service_id LEFT JOIN admin.sms_customers_services ON admin.sms_customers_services.keyword_id=sms_keywords.keyword_id LEFT JOIN admin.sms_shortcodes ON admin.sms_shortcodes.shortcode_id=sms_keywords.shortcode_id WHERE ( sms_services.user_id = '2' ) AND ( sms_services.status = 'Active' ) AND ( sms_keywords.status = 'Active' ) AND ( sms_shortcodes.status = 'Active' ) AND ( sms_customers_services.status = 'Active' ) AND ( sms_actions.status = 'Active' ) GROUP BY sms_services.service_id ASC, sms_keywords.keyword_id ASC -- Now I want it to be -- Notice that the AND statements for the status flag are now within the JOIN syntax - this provides the ability to perform a condition only if data is returned from this table the above performs the status condition on all the data and so retruns NULL as maybe there are no customers or actions with a service. Cant check PEAR at the moment as the site is down. -- SELECT sms_services.service_id, sms_services.service, sms_services.watershed, sms_services.free_msgs, sms_services.type, sms_services.multiple_signups, sms_keywords.keyword_id, sms_keywords.keyword, sms_shortcodes.shortcode_id, sms_shortcodes.shortcode, COUNT(DISTINCT sms_customers_services.customer_services_id) AS total, sms_actions.action_id FROM sms_services LEFT JOIN admin.sms_actions ON admin.sms_actions.service_id=sms_services.service_id AND ( sms_actions.status = 'Active' ) LEFT JOIN admin.sms_keywords ON admin.sms_keywords.service_id=sms_services.service_id AND ( sms_keywords.status = 'Active' ) LEFT JOIN admin.sms_customers_services ON admin.sms_customers_services.keyword_id=sms_keywords.keyword_id AND ( sms_customers_services.status = 'Active' ) LEFT JOIN admin.sms_shortcodes ON admin.sms_shortcodes.shortcode_id=sms_keywords.shortcode_id AND ( sms_shortcodes.status = 'Active' ) WHERE ( sms_services.user_id = '2' ) AND ( sms_services.status = 'Active' ) GROUP BY sms_services.service_id ASC, sms_keywords.keyword_id ASC
Yep, DB_DO doesn't support this. There is at least 1 open feature request for this but it has not been included yet. You can either apply my patch in the bug for this feature or use an extended DO which overrides joinAdd with the code in the patch or alter $do->_join manually (I used regular expressions). Also, just a quick note, you don't need to use whereAdd for such simple conditions. You could just set the status field in each of those DOs and the where clause would be added automatically.
-- Justin Patrin

« previous php.pear.general (#25285) next »