Return-Path: Delivered-To: apmail-ofbiz-commits-archive@www.apache.org Received: (qmail 63869 invoked from network); 4 Mar 2010 09:25:03 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 4 Mar 2010 09:25:03 -0000 Received: (qmail 94183 invoked by uid 500); 4 Mar 2010 09:24:53 -0000 Delivered-To: apmail-ofbiz-commits-archive@ofbiz.apache.org Received: (qmail 94150 invoked by uid 500); 4 Mar 2010 09:24:53 -0000 Mailing-List: contact commits-help@ofbiz.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ofbiz.apache.org Delivered-To: mailing list commits@ofbiz.apache.org Received: (qmail 94143 invoked by uid 99); 4 Mar 2010 09:24:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Mar 2010 09:24:53 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Mar 2010 09:24:52 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0DBD7238890A; Thu, 4 Mar 2010 09:24:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r918910 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Date: Thu, 04 Mar 2010 09:24:31 -0000 To: commits@ofbiz.apache.org From: jonesde@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100304092431.0DBD7238890A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jonesde Date: Thu Mar 4 09:24:30 2010 New Revision: 918910 URL: http://svn.apache.org/viewvc?rev=918910&view=rev Log: A better approach for this condition, it isn't just the COUNT function we want to look for, it is ANY function; a reminder for those using this: put the unique field first Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=918910&r1=918909&r2=918910&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Thu Mar 4 09:24:30 2010 @@ -1012,15 +1012,15 @@ * cause the "COUNT(DISTINCT " to appear twice, causing an attempt to try to count a count (function="count-distinct", distinct=true in find options) */ if (selectFields != null && selectFields.size() > 0) { - String fullColName = selectFields.get(0).getColName(); - - if (fullColName.indexOf("COUNT") >= 0) { - // already has a COUNT in the name (generally from a function=count-distinct), so do it the old style + ModelField firstSelectField = selectFields.get(0); + ModelViewEntity.ModelAlias firstModelAlias = modelViewEntity != null ? modelViewEntity.getAlias(firstSelectField.getName()) : null; + if (firstModelAlias != null && UtilValidate.isNotEmpty(firstModelAlias.getFunction())) { + // if the field has a function already we don't want to count just it, would be meaningless sqlBuffer.append("COUNT(DISTINCT *) "); } else { sqlBuffer.append("COUNT(DISTINCT "); // this only seems to support a single column, which is not desirable but seems a lot better than no columns or in certain cases all columns - sqlBuffer.append(selectFields.get(0).getColName()); + sqlBuffer.append(firstSelectField.getColName()); // sqlBuffer.append(modelEntity.colNameString(selectFields, ", ", "", datasourceInfo.aliasViews)); sqlBuffer.append(")"); }