Return-Path: X-Original-To: apmail-db-torque-user-archive@www.apache.org Delivered-To: apmail-db-torque-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 490ACE7D4 for ; Tue, 25 Jun 2013 00:45:43 +0000 (UTC) Received: (qmail 77412 invoked by uid 500); 25 Jun 2013 00:45:43 -0000 Delivered-To: apmail-db-torque-user-archive@db.apache.org Received: (qmail 77247 invoked by uid 500); 25 Jun 2013 00:45:42 -0000 Mailing-List: contact torque-user-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Apache Torque Users List" Reply-To: "Apache Torque Users List" Delivered-To: mailing list torque-user@db.apache.org Received: (qmail 77239 invoked by uid 99); 25 Jun 2013 00:45:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Jun 2013 00:45:42 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of jay.bourland@gmail.com designates 209.85.223.170 as permitted sender) Received: from [209.85.223.170] (HELO mail-ie0-f170.google.com) (209.85.223.170) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Jun 2013 00:45:35 +0000 Received: by mail-ie0-f170.google.com with SMTP id e11so26642856iej.15 for ; Mon, 24 Jun 2013 17:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; bh=zsFEOpsAmREORd8MHpooAy1rftwv0vDijI3d9PY5qsI=; b=Y7M+MTYblOnzkEuXeAyEbmWOsCE2srCMlbzeHFYGtFef0zS2UPK0A7uNMbx9otc1iG QeFxtqpkRpBoXpJ/hNoeJH1wlM/sZPzjTc+UR5PbhEemUxoBKUf3xT+nKNlFb/dtVTHy hVJGFHel9vghJkdPRDHz5QXzCBWRo04/er+pbKx0QJlturwHZB6CX6318kzKK5coPlHx E81MEqAndYjxT06metJ3CEtr4i5hNfkyU+AbN/uZK+kxcHbP0lFQmf3QJXwJjaW+pfIX NRz3dcpoZB40owAI4EFgj5cYJe4PIe0/vV4vJjY94avixxfpxvXUcBf/uWeIPcpMJQ4i BREg== X-Received: by 10.50.72.40 with SMTP id a8mr7233121igv.15.1372121115073; Mon, 24 Jun 2013 17:45:15 -0700 (PDT) Received: from [192.168.0.154] (bourland.dsl.frii.net. [216.17.156.211]) by mx.google.com with ESMTPSA id l9sm931532igt.5.2013.06.24.17.45.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Jun 2013 17:45:14 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) Subject: Re: SummaryHelper not setting replacements From: Jay Bourland In-Reply-To: Date: Mon, 24 Jun 2013 18:45:10 -0600 Content-Transfer-Encoding: quoted-printable Message-Id: References: <53D7A1AD-3700-4399-9684-A7729EFAFB81@gmail.com> To: "Apache Torque Users List" X-Mailer: Apple Mail (2.1508) X-Virus-Checked: Checked by ClamAV on apache.org Thomas - I have verified that the code now runs clean. Thank you for = fixing it. And thank you for reviving this project. I looked at = migrating to Hibernate or one of the other ORM's but I really like = Torque much better. Jay On Jun 24, 2013, at 1:30 AM, Thomas Fox = wrote: >> Hi Thomas - Here's the problem code. The plain select works fine, >> but asking for the count causes an error to be thrown if I use the >> non-hack method. >=20 > I think I have found and fixed the problem. If you want you can try = the > current trunk. > Thanks for reporting the error ! >=20 > Thomas >=20 >>=20 >> /** >> * Get a List of the dogs that earned all of a list of titles in >> a given year >> * @param titles array of titles to be searched. >> * @param year four digit year to be searched >> * @return a List of dogs that earned the titles >> * @throws TorqueException if something goes wrong >> */ >> public static List doFindDogsWithAllTitles( String[] titles, >> String year ) throws TorqueException { >> Criteria crit =3D getCriteriaDogsWithAllTitles( titles, year ); >> crit.addAscendingOrderByColumn( REG_NAME ); >>=20 >> return doSelect( crit ); >> } >>=20 >> /** >> * Get a count of the dogs that earned all of a list of titles in >> a given year >> * @param titles array of titles to be searched. >> * @param year four digit year to be searched >> * @return number of dogs that earned the titles >> * @throws TorqueException if something goes wrong >> */ >> public static int doFindCountWithAllTitles( String[] titles, >> String year ) throws TorqueException { >> //TODO: Remove Hack once issue fixed >> Criteria crit =3D getCriteriaDogsWithAllTitlesHack( titles, year = ); >>=20 >> SummaryHelper summary =3D new SummaryHelper(); >>=20 >> summary.addAggregate( "count", new Count( DogPeer.DOG_ID ) ); >> List results =3D summary.summarize( crit ); >> return Integer.parseInt( results.get( 0 ).get( "count" = ).toString > () ); >> } >>=20 >> /** >> * Create a criteria to search for the dogs that earned all of an >> array of titles in a given year >> * @param titles array of titles to be searched. >> * @param year four digit year to be searched >> * @return the Criteria to be used for the request >> */ >> private static Criteria getCriteriaDogsWithAllTitles( String[] >> titles, String year ) { >> String startDate =3D null, endDate =3D null; >> try{ >> int yr =3D Integer.parseInt( year )+1; >> //They year is valid if we get here. >> startDate =3D year+"-01-01"; >> endDate =3D Integer.toString( yr ) + "-01-01"; >> } catch( NumberFormatException nfe ) { >> //ignore >> } >>=20 >> Criteria crit =3D new Criteria(); >> int idx =3D 1; >> for( String str : titles ) { >> String alias =3D "t"+Integer.toString( idx ); >> crit.addAlias( alias, "title" ); >> crit.addJoin( DogPeer.DOG_ID, new ColumnImpl( alias + "." + >> TitlePeer.DOG_ID.getColumnName() ) ); >> crit.where( new ColumnImpl( alias + "." + >> TitlePeer.TITLE.getColumnName() ), str ); >> if( startDate !=3D null ) { >> Column aliasDate =3D new ColumnImpl( alias + "." + >> TitlePeer.TITLE_DATE.getColumnName() ); >> crit.where( aliasDate, startDate, Criteria.GREATER_EQUAL = ); >> crit.where( aliasDate, endDate, Criteria.LESS_THAN ); >> } >> ++idx; >> } >> return crit; >> } >>=20 >> /** >> * forces a non-prepared statement to get around SummaryHelper bug >> * @param titles array of titles that the dog must have >> * @param year year to be searched >> * @return a Criteria object with the appropriate query >> */ >> private static Criteria getCriteriaDogsWithAllTitlesHack( String >> [] titles, String year ) { >> String startDate =3D null, endDate =3D null; >> try{ >> int yr =3D Integer.parseInt( year )+1; >> //They year is valid if we get here. >> startDate =3D year+"-01-01"; >> endDate =3D Integer.toString( yr ) + "-01-01"; >> } catch( NumberFormatException nfe ) { >> //ignore >> } >>=20 >> Criteria crit =3D new Criteria(); >> int idx =3D 1; >> for( String str : titles ) { >> String alias =3D "t"+Integer.toString( idx ); >> crit.addAlias( alias, "title" ); >> crit.addJoin( DogPeer.DOG_ID, new ColumnImpl( alias + "." + >> TitlePeer.DOG_ID.getColumnName() ) ); >> crit.whereVerbatimSql( alias + "." + >> TitlePeer.TITLE.getColumnName() + "=3D'" + str + "'", null ); >> if( startDate !=3D null ) { >> Column aliasDate =3D new ColumnImpl( alias + "." + >> TitlePeer.TITLE_DATE.getColumnName() ); >> crit.whereVerbatimSql( alias + "." + >> TitlePeer.TITLE_DATE.getColumnName() + ">=3D'" + startDate + "'", = null ); >> crit.whereVerbatimSql( alias + "." + >> TitlePeer.TITLE_DATE.getColumnName() + "<'" + endDate + "'", null ); >> } >> ++idx; >> } >> return crit; >> } >>=20 >>=20 >> On Jun 12, 2013, at 12:59 AM, Thomas Fox > wrote: >>=20 >>>=20 >>=20 > = |-------------------------------------------------------------------------= --------------------------------------------------------------------------= -> >=20 >>> |Jay Bourland wrote: > | >>>=20 >>=20 > = |-------------------------------------------------------------------------= --------------------------------------------------------------------------= -> >=20 >>>> ---------------------------| >>> | An: | >>>> ---------------------------| >>>=20 >>>=20 >>>=20 >>>> I'm trying to convert an old Torque site to version 4. I'm running >>>> into a problem with using a count() function. The code looks like > this: >>>>=20 >>>> Criteria crit =3D getCriteriaDogsWithAllTitles( titles, year ); >>>>=20 >>>> SummaryHelper summary =3D new SummaryHelper(); >>>>=20 >>>> summary.addAggregate( "count", new Count( DogPeer.DOG_ID ) ); >>>> List results =3D summary.summarize( crit ); >>>>=20 >>>> When summarize() is executed, I get a >>>> "jdbc4.MySQLSyntaxErrorException: You have an error in your SQL >>>> syntax" exception. The Criteria is good and works fine with a >>>> doSelect(). It appears that the summarize converts the Criteria to = a >>>> string without adding in the replacements for the parameters in the >>>> prepared statement. >>>=20 >>> Can you please provide an example how you construct a crit which > fails ? >>>=20 >>>> Also, if I take the string from the >>>> queryStatement and replace the '?' with values, the statement runs >>>> fine from an interactive MySQL session. When I compare the code in >>>> SummaryHelper.summarize() to BasePeerImpl.doSelect() the code to = set >>>> the replacements is present in doSelect but not in summarize. >>>>=20 >>>> What's the best way to report this? >>>=20 >>> Please file a jira issue at >>>=20 >>> https://issues.apache.org/jira/browse/TORQUE/ >>>=20 >>> As a workaround, you can try >>> crit.addSelectColumn(new org.apache.torque.util.functions.Count >>> ("*")); >>> int count =3D SomePeer.doSelectSingleRecord(crit, new >>> org.apache.torque.om.mapper.IntegerMapper()); >>>=20 >>> instead of >>> summary.addAggregate( "count", new Count( DogPeer.DOG_ID ) ); >>> List results =3D summary.summarize( crit ); >>>=20 >>> Thomas >>>=20 >>>=20 >>> = --------------------------------------------------------------------- >>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org >>> For additional commands, e-mail: torque-user-help@db.apache.org >>>=20 >>=20 >>=20 >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org >> For additional commands, e-mail: torque-user-help@db.apache.org >>=20 >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org > For additional commands, e-mail: torque-user-help@db.apache.org >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org For additional commands, e-mail: torque-user-help@db.apache.org