You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Daniel Pitts <Da...@cnet.com> on 2006/08/23 20:17:08 UTC
dynamic script's
Is there a way to run an SQL "script" from iBATIS?
Such as:
INSERT INTO foo (#bar#, #baz#);
INSERT INTO ho (#hum#);
Also, if there is, is it possible to dynamically generate the SQL to do
so?
Eg:
INSERT INTO foo (#bar#, #baz#);
<iterate property="hos">INSERT INTO ho (#bar#, #hos[]#);</iterate>
Thanks.
Re: dynamic script's
Posted by Larry Meadors <lm...@apache.org>.
Agreed.
IMO this is one of those areas where you have to balance portability
and functionality. From what I have seen, bundling stuff together like
this can provide a significant performance boost, but on the down
side, it's Oracle-specific.
In my case, I don't care that it's Oracle-specific, because I am
writing an application that will only ever run on Oracle.
Larry
On 8/24/06, Michael Campbell <mi...@gmail.com> wrote:
> Does this not depend on how Prepared Statements are implemented? As I
> recall, one of the big db's does them as a stored proc. In that
> light, multiple statements seems reasonable, but this sort of behavior
> (like most things) might not valid across all the dbs that one might
> consider.
>
> I guess the answer is, "try it". =)
>
> On 8/24/06, Larry Meadors <lm...@apache.org> wrote:
> > This works perfectly in Oracle:
> >
> > <delete id="delete">
> > BEGIN
> > DELETE FROM Child WHERE childId = #parentId#;
> > DELETE FROM Parent WHERE parentId = #parentId#;
> > END;
> > </delete>
> >
> > It is a single prepared statement, and performs great.
> >
> > Larry
> >
> >
> > On 8/23/06, Daniel Pitts <Da...@cnet.com> wrote:
> > > Is there a way to run an SQL "script" from iBATIS?
> > > Such as:
> > > INSERT INTO foo (#bar#, #baz#);
> > > INSERT INTO ho (#hum#);
> > >
> > >
> > > Also, if there is, is it possible to dynamically generate the SQL to do
> > > so?
> > > Eg:
> > > INSERT INTO foo (#bar#, #baz#);
> > > <iterate property="hos">INSERT INTO ho (#bar#, #hos[]#);</iterate>
> > >
> > > Thanks.
> > >
> > >
> > >
> > >
> >
>
>
> --
> If you're as clever as you can be when you write it, how will you ever
> debug it? -- Brian Kernighan
>
Re: dynamic script's
Posted by Michael Campbell <mi...@gmail.com>.
Does this not depend on how Prepared Statements are implemented? As I
recall, one of the big db's does them as a stored proc. In that
light, multiple statements seems reasonable, but this sort of behavior
(like most things) might not valid across all the dbs that one might
consider.
I guess the answer is, "try it". =)
On 8/24/06, Larry Meadors <lm...@apache.org> wrote:
> This works perfectly in Oracle:
>
> <delete id="delete">
> BEGIN
> DELETE FROM Child WHERE childId = #parentId#;
> DELETE FROM Parent WHERE parentId = #parentId#;
> END;
> </delete>
>
> It is a single prepared statement, and performs great.
>
> Larry
>
>
> On 8/23/06, Daniel Pitts <Da...@cnet.com> wrote:
> > Is there a way to run an SQL "script" from iBATIS?
> > Such as:
> > INSERT INTO foo (#bar#, #baz#);
> > INSERT INTO ho (#hum#);
> >
> >
> > Also, if there is, is it possible to dynamically generate the SQL to do
> > so?
> > Eg:
> > INSERT INTO foo (#bar#, #baz#);
> > <iterate property="hos">INSERT INTO ho (#bar#, #hos[]#);</iterate>
> >
> > Thanks.
> >
> >
> >
> >
>
--
If you're as clever as you can be when you write it, how will you ever
debug it? -- Brian Kernighan
Re: dynamic script's
Posted by Larry Meadors <lm...@apache.org>.
This works perfectly in Oracle:
<delete id="delete">
BEGIN
DELETE FROM Child WHERE childId = #parentId#;
DELETE FROM Parent WHERE parentId = #parentId#;
END;
</delete>
It is a single prepared statement, and performs great.
Larry
On 8/23/06, Daniel Pitts <Da...@cnet.com> wrote:
> Is there a way to run an SQL "script" from iBATIS?
> Such as:
> INSERT INTO foo (#bar#, #baz#);
> INSERT INTO ho (#hum#);
>
>
> Also, if there is, is it possible to dynamically generate the SQL to do
> so?
> Eg:
> INSERT INTO foo (#bar#, #baz#);
> <iterate property="hos">INSERT INTO ho (#bar#, #hos[]#);</iterate>
>
> Thanks.
>
>
>
>
Re: dynamic script's
Posted by Jeff Butler <je...@gmail.com>.
The answer is yes - if the driver supports it. If your driver supports
multiple SQL statements in a single prepared statement, then you can do it.
iBATIS doesn't to anything to support or deny this function - it's totally
dependant on the driver support. iBATIS will only prepare one statement.
In my opinion, this is a bad idea even if the driver supports it. I think
it's better to start a transaction and make multiple calls to the different
insert statements. More portable, and probably more maintainable.
Jeff Butler
On 8/23/06, Daniel Pitts <Da...@cnet.com> wrote:
>
> Is there a way to run an SQL "script" from iBATIS?
> Such as:
> INSERT INTO foo (#bar#, #baz#);
> INSERT INTO ho (#hum#);
>
>
> Also, if there is, is it possible to dynamically generate the SQL to do
> so?
> Eg:
> INSERT INTO foo (#bar#, #baz#);
> <iterate property="hos">INSERT INTO ho (#bar#, #hos[]#);</iterate>
>
> Thanks.
>
>
>
>