Re: DataObject Query
| From: | Justin Patrin | Date: | Thu, 28 Sep 2006 15:19:14 +0000 |
| Subject: | Re: DataObject Query | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-25281@lists.php.net to get a copy of this message | ||
On 9/28/06, Ian Warner <iwarner@triangle-solutions.com> wrote:
Hi I have the following query generated through DO -- SELECT sms_services.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 Patrinservice_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_idFROM 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_idASC, sms_keywords.keyword_idASC -- 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_idFROM 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_idASC, sms_keywords.keyword_idASC