Return-Path: Delivered-To: apmail-incubator-ibatis-user-java-archive@www.apache.org Received: (qmail 19464 invoked from network); 24 Apr 2005 02:26:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 24 Apr 2005 02:26:22 -0000 Received: (qmail 10057 invoked by uid 500); 24 Apr 2005 02:26:50 -0000 Delivered-To: apmail-incubator-ibatis-user-java-archive@incubator.apache.org Received: (qmail 9805 invoked by uid 500); 24 Apr 2005 02:26:49 -0000 Mailing-List: contact ibatis-user-java-help@incubator.apache.org; run by ezmlm Precedence: bulk Reply-To: ibatis-user-java@incubator.apache.org List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list ibatis-user-java@incubator.apache.org Received: (qmail 9783 invoked by uid 99); 24 Apr 2005 02:26:49 -0000 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=HTML_30_40,HTML_MESSAGE,RCVD_BY_IP X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of jasonpunzalan@gmail.com designates 64.233.162.198 as permitted sender) Received: from zproxy.gmail.com (HELO zproxy.gmail.com) (64.233.162.198) by apache.org (qpsmtpd/0.28) with ESMTP; Sat, 23 Apr 2005 19:26:48 -0700 Received: by zproxy.gmail.com with SMTP id 16so1713991nzp for ; Sat, 23 Apr 2005 19:26:15 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:references; b=JxB4HAeyQYGveNZvYWtWeub/cfOwryrLWbLdPcmo7Ym+D6mRYfXZf208BW3Bsk1YGLdpdXeEZwv6u8U/NsqRPDnCdaEbLw4f7CN0qOU7/59QCxD+gPfYwN9dCN3ec+AqFOs9n3GDF8iiyxLHVhbC8+qtsRZ8QcAozVSwGXm47TA= Received: by 10.36.88.3 with SMTP id l3mr395340nzb; Sat, 23 Apr 2005 19:26:15 -0700 (PDT) Received: by 10.36.48.1 with HTTP; Sat, 23 Apr 2005 19:26:15 -0700 (PDT) Message-ID: <971c0e950504231926701cf97c@mail.gmail.com> Date: Sat, 23 Apr 2005 22:26:15 -0400 From: Jason Punzalan Reply-To: Jason Punzalan To: ibatis-user-java@incubator.apache.org Subject: Re: select with iterate In-Reply-To: <20050424004240.60872.qmail@web32205.mail.mud.yahoo.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_3732_14272065.1114309575252" References: <20050424004240.60872.qmail@web32205.mail.mud.yahoo.com> X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_3732_14272065.1114309575252 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Ahh...very helpful. thank you. what about inserts? can you use iterate to= =20 execute multiple inserts or updates? or do i have to make separate calls in= =20 my dao class? On 4/23/05, Ron Grabowski wrote: >=20 > I believe your code would incorrectly generate the following sql > statements (all on one line): >=20 > select * from content where id =3D 1 > select * from content where id =3D 2 > select * from content where id =3D 3 > ... >=20 > Take a look at the these test cases: >=20 > http://tinyurl.com/dadn5 >=20 > http://svn.apache.org/repos/asf/incubator/ibatis/trunk/java/mapper/mapper= 2/test/com/ibatis/sqlmap/maps/DynamicAccount.xml >=20 > You probably want to do something like this: >=20 > SELECT * FROM content WHERE id IN > > #idList[]# > >=20 > That would generate this sql: >=20 > SELECT * FROM content WHERE id IN (1,2,3) >=20 > If you want three seperate queries, your dao class would need to make > three seperate calls to the database. >=20 > --- Jason Punzalan wrote: > > Can someone show me an example of doing a select with iterate? Is it > > possible to do the following.... > > > > > parameterClass=3D"Content" > > resultMap=3D"content-result" > > > > > > > select * from content where > > id =3D #idList[]# > > > > > > > > > > I'm currently getting an java.sql.SQLException...running mysql. > > > > Thanks > > > ------=_Part_3732_14272065.1114309575252 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Ahh...very helpful. thank you. what about inserts? can you use iterate to execute multiple inserts or updates? or do i have to make separate calls in my dao class?



On 4/23/05, Ron Grabowski <rongrab= owski@yahoo.com> wrote:
I believe your code would incorrectly generate the following sql
stateme= nts (all on one line):

select * from content where id =3D 1
selec= t * from content where id =3D 2
select * from content where id =3D 3
= ...

Take a look at the these test cases:

http://tinyurl.com/dadn5
http://svn.apache.org/repos/asf/incubator/ibatis/trunk/java/mapper/mapper2/= test/com/ibatis/sqlmap/maps/DynamicAccount.xml

You probably want= to do something like this:

SELECT * FROM content WHERE id IN
<iterate property=3D"idList" open=3D"(" close=3D&qu= ot;)"  conjunction=3D",">
  #idLis= t[]#
</iterate>

That would generate this sql:

SELEC= T * FROM content WHERE id IN (1,2,3)

If you want three seperate queries, your dao class would need to ma= ke
three seperate calls to the database.

--- Jason Punzalan <<= a href=3D"mailto:jasonpunzalan@gmail.com">jasonpunzalan@gmail.com> w= rote:
> Can someone show me an example of doing a select with iterate? Is = it
> possible to do the following....
>
> <statement i= d=3D"getAllByList" resultClass=3D"Content"
> para= meterClass=3D"Content"
> resultMap=3D"content-result" >
> <dynamic>= ;
> <iterate property=3D"idList">
> select * fr= om content where
> id =3D #idList[]#
> </iterate>
>= </dynamic>
> </statement>
>
> I'm currently getting an java.s= ql.SQLException...running mysql.
>
> Thanks
>

------=_Part_3732_14272065.1114309575252--