Re: DataObject Query
| From: | Ian Warner | Date: | Thu, 28 Sep 2006 16:57:58 +0000 |
| Subject: | Re: DataObject Query | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-25286@lists.php.net to get a copy of this message | ||
Justin
Nice one fix below i believe:
-------
I've patched joinAdd method to use additional conditions :
1 - Replaced function signature :
function joinAdd($obj = false, $joinType='INNER', $joinAs=false,
$joinCol=false, $additionalJoinsOn = NULL)
2 - Modified code in joinAdd
// $appendJoin = '';
$appendJoin = (isset($additionalJoinsOn)) ? 'AND ' . implode('AND ',
$additionalJoinsOn) : '';
-----------
If this is the code then I dont see why it could not have been included in the main DataObjects package, so small :)
Alan what was the issues with the above code please, can this be implemented into DO - I love your package, but this is an important fix, for me anyway :)
Regards
Ian Warner
Director
Triangle Solutions Ltd
Justin Patrin wrote:
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=3Justin Patrin wrote:On 9/28/06, Ian Warner <iwarner@triangle-solutions.com> wrote: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.sms_services.Hi I have the following query generated through DO -- SELECT sms_services.service_id, sms_services.service, sms_services.watershed, sms_services.free_msgs,type,total,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) ASsms_actions.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 (statusabove= '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 thePEARperforms the status condition on all the data and so retruns NULL as maybe there are no customers or actions with a service. Cant checksms_services.at the moment as the site is down. -- SELECT sms_services.service_id, sms_services.service, sms_services.watershed, sms_services.free_msgs,type,total,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) ASsms_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