You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Leszek Gawron <ou...@vip.net.pl> on 2003/03/04 22:26:44 UTC

ESQL and prepared statements

Am I right that even though I can use prepared statement I cannot rerun the
query several times without recreating the statement every time? I have a lot
of cases when I have to make a lot of same inserts basing on xml data from
request body.
	ouzo
-- 
            __
         | /  \ |        Leszek Gawron            //  \\
        \_\\  //_/      ouzo@vip.net.pl          _\\()//_
         .'/()\'.     Phone: +48(600)341118     / //  \\ \
          \\  //  recursive: adj; see recursive  | \__/ |


Re: ESQL and prepared statements

Posted by Leszek Gawron <ou...@vip.net.pl>.
On śro, mar 05, 2003 at 07:47:19 -0500, Geoff Howard wrote:
> At 07:37 AM 3/5/2003, you wrote:
> >On 05.Mar.2003 -- 11:42 AM, Leszek Gawron wrote:
> >> you may do something like:
> 
> <snip-proposal/>
> 
> 
> >Sounds reasonable. Although I fear changes to esql.xsl and helper
> >classes might be cosiderable to achieve this.
> >
> >This would lead to the question: Is it worth it? I mean, in my book
> >ESQL should be used to generate content only, not for update,
> >insert or delete. And for that it's probably less often useful to
> >repeat a query a number of times. Would be different of course, if the
> >statement would be kept over different invocations of the page (the
> >driver or the DBMS might do it for prepared statements).
> >
> >        Chris.
> 
> I thought JDBC3 drivers were supposed to automatically pool and reuse 
> prepared statements "for free".  No?
even if, both pervasive and ms sql server driver are JDBC 2.0 only and M$ does
not plan to release JDBC 3.0 compliant version
	ouzo
-- 
            __
         | /  \ |        Leszek Gawron            //  \\
        \_\\  //_/      ouzo@vip.net.pl          _\\()//_
         .'/()\'.     Phone: +48(600)341118     / //  \\ \
          \\  //  recursive: adj; see recursive  | \__/ |


Re: ESQL and prepared statements

Posted by Geoff Howard <co...@leverageweb.com>.
At 07:37 AM 3/5/2003, you wrote:
>On 05.Mar.2003 -- 11:42 AM, Leszek Gawron wrote:
> > you may do something like:

<snip-proposal/>


>Sounds reasonable. Although I fear changes to esql.xsl and helper
>classes might be cosiderable to achieve this.
>
>This would lead to the question: Is it worth it? I mean, in my book
>ESQL should be used to generate content only, not for update,
>insert or delete. And for that it's probably less often useful to
>repeat a query a number of times. Would be different of course, if the
>statement would be kept over different invocations of the page (the
>driver or the DBMS might do it for prepared statements).
>
>         Chris.

I thought JDBC3 drivers were supposed to automatically pool and reuse 
prepared statements "for free".  No?

Geoff 


Re: ESQL and prepared statements

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 05.Mar.2003 -- 01:59 PM, Leszek Gawron wrote:
> On ??ro, mar 05, 2003 at 01:37:57 +0100, Christian Haul wrote:
> > This would lead to the question: Is it worth it? I mean, in my book
> > ESQL should be used to generate content only, not for update,
> why is that?

> as a request body . The xsp action parses the document, valiates data against
> the database (checks if contractor, goods exist), then performs several insert
> (order header, repeated inserts into order positions table). ESQL is a great

Of course! I tend to forget about XSP-actions. That is differnt, I agree.

	Chris.
-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

Re: ESQL and prepared statements

Posted by Leszek Gawron <ou...@vip.net.pl>.
On śro, mar 05, 2003 at 01:37:57 +0100, Christian Haul wrote:
> On 05.Mar.2003 -- 11:42 AM, Leszek Gawron wrote:
> > you may do something like:
> > 
> > <esql:declare-prepared-query id="prepared-no1">
> > 	select foo from bar where blah = <esql:parameter name="firstparam"/>
> > </esql:declare-prepared-query>
> > 
> > <xsp:logic>
> > int i;
> > for ( i = 0; i < count; ++i ) {
> > 	<esql:set-param query="prepared-no1" name="firstparam">
> > 		<xsp:expr>somearray[ i ]</xsp:expr>
> > 	</esql:set-param>
> > 
> > 	<esql:run-prepared-query id="prepared-no1">
> > 		<esql:results>
> > 			<!-- standard stuff goes here -->
> > 		</esql:results>
> > 	</esql:run-prepared-query>
> > }
> > </xsp:logic>
> > 
> > What do you think ? 
> 
> Sounds reasonable. Although I fear changes to esql.xsl and helper
> classes might be cosiderable to achieve this.
> 
> This would lead to the question: Is it worth it? I mean, in my book
> ESQL should be used to generate content only, not for update,
why is that?

for example you want to place an order. The way I do it (using client app
instead of browser) is to send an xmlfile
<root>
	<contractor-id>10<contractor-id>
	<positions>
		<position>
			<good-id>2</good-id>
			<amount>10</amount>
		</position>
		<position>
			<good-id>5</good-id>
			<amount>22</amount>
		</position>
	</positions>
</root>

as a request body . The xsp action parses the document, valiates data against
the database (checks if contractor, goods exist), then performs several insert
(order header, repeated inserts into order positions table). ESQL is a great
help in that and there is really no other way to achieve this (modular
database actions rather wouldn't help and even if they did a massive amount of
logic would end up in the sitemap which in my case is not small even now).

What you say is maybe true when cocoon serves content for web browsers but I
find cocoon a great tool acting as a application server layer - I do not know
EJBs and stuff and from what I saw the development time would be much bigger.
I have:
1. xsp as data providers
2. xsp actions as logic performers 
3. authentication framework as .. authentication frameork
4. siteap - lets me create any application folder hierarchy I want.

There's an apache in front of this all which compresses all output data (using
mod_gzip) to 5% of its original size. Got all what is needed to be happy
forever :)

And reusing the same pipelines I can build web administrator application very
fast.
	ouzo
-- 
            __
         | /  \ |        Leszek Gawron            //  \\
        \_\\  //_/      ouzo@vip.net.pl          _\\()//_
         .'/()\'.     Phone: +48(600)341118     / //  \\ \
          \\  //  recursive: adj; see recursive  | \__/ |


Re: ESQL and prepared statements

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 05.Mar.2003 -- 11:42 AM, Leszek Gawron wrote:
> you may do something like:
> 
> <esql:declare-prepared-query id="prepared-no1">
> 	select foo from bar where blah = <esql:parameter name="firstparam"/>
> </esql:declare-prepared-query>
> 
> <xsp:logic>
> int i;
> for ( i = 0; i < count; ++i ) {
> 	<esql:set-param query="prepared-no1" name="firstparam">
> 		<xsp:expr>somearray[ i ]</xsp:expr>
> 	</esql:set-param>
> 
> 	<esql:run-prepared-query id="prepared-no1">
> 		<esql:results>
> 			<!-- standard stuff goes here -->
> 		</esql:results>
> 	</esql:run-prepared-query>
> }
> </xsp:logic>
> 
> What do you think ? 

Sounds reasonable. Although I fear changes to esql.xsl and helper
classes might be cosiderable to achieve this.

This would lead to the question: Is it worth it? I mean, in my book
ESQL should be used to generate content only, not for update,
insert or delete. And for that it's probably less often useful to
repeat a query a number of times. Would be different of course, if the
statement would be kept over different invocations of the page (the
driver or the DBMS might do it for prepared statements).

	Chris.
-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

Re: ESQL and prepared statements

Posted by Leszek Gawron <ou...@vip.net.pl>.
On śro, mar 05, 2003 at 09:33:50 +0100, Torsten Curdt wrote:
> >>>Am I right that even though I can use prepared statement I cannot rerun 
> >>>the
> >>>query several times without recreating the statement every time? I have 
> >>>a lot
> >>>of cases when I have to make a lot of same inserts basing on xml data 
> >>>from
> >>>request body.
> >>
> >>http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
> >
> >Yeah nice. That's obvious. I know how to do it in JDBC. Just asking if ESQL
> >supports it.
> 
> Ah.. sorry.
> 
> No, not yet. Care enough for a patch? :)
Sure, at least I can try. Please comment my idea. 

Instead of in-place execution:

<xsp:logic>
int i;
for ( i = 0; i < count; ++i ) {
	somevar = somearray[ i ];
	
	<esql:execute-query>
		<esql:query>select foo from bar where blah =
		<esql:parameter><xsp:expr>somevar</xsp:expr></esql:parameter></esql:query>
	<esql:results>
		<!-- standard stuff -->
	</esql:results>
	</esql:execute-query>

}
</xsp:logic>
you may do something like:

<esql:declare-prepared-query id="prepared-no1">
	select foo from bar where blah = <esql:parameter name="firstparam"/>
</esql:declare-prepared-query>

<xsp:logic>
int i;
for ( i = 0; i < count; ++i ) {
	<esql:set-param query="prepared-no1" name="firstparam">
		<xsp:expr>somearray[ i ]</xsp:expr>
	</esql:set-param>

	<esql:run-prepared-query id="prepared-no1">
		<esql:results>
			<!-- standard stuff goes here -->
		</esql:results>
	</esql:run-prepared-query>
}
</xsp:logic>

What do you think ? 
	ouzo
-- 
            __
         | /  \ |        Leszek Gawron            //  \\
        \_\\  //_/      ouzo@vip.net.pl          _\\()//_
         .'/()\'.     Phone: +48(600)341118     / //  \\ \
          \\  //  recursive: adj; see recursive  | \__/ |


Re: ESQL and prepared statements

Posted by Torsten Curdt <tc...@dff.st>.
>>>Am I right that even though I can use prepared statement I cannot rerun the
>>>query several times without recreating the statement every time? I have a lot
>>>of cases when I have to make a lot of same inserts basing on xml data from
>>>request body.
>>
>>http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
> 
> Yeah nice. That's obvious. I know how to do it in JDBC. Just asking if ESQL
> supports it.

Ah.. sorry.

No, not yet. Care enough for a patch? :)
--
Torsten


Re: ESQL and prepared statements

Posted by Leszek Gawron <ou...@vip.net.pl>.
On śro, mar 05, 2003 at 01:21:17 +0100, Torsten Curdt wrote:
> > Am I right that even though I can use prepared statement I cannot rerun the
> > query several times without recreating the statement every time? I have a lot
> > of cases when I have to make a lot of same inserts basing on xml data from
> > request body.
> 
> http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
Yeah nice. That's obvious. I know how to do it in JDBC. Just asking if ESQL
supports it.
	ouzo
-- 
            __
         | /  \ |        Leszek Gawron            //  \\
        \_\\  //_/      ouzo@vip.net.pl          _\\()//_
         .'/()\'.     Phone: +48(600)341118     / //  \\ \
          \\  //  recursive: adj; see recursive  | \__/ |


Re: ESQL and prepared statements

Posted by Torsten Curdt <tc...@dff.st>.
> Am I right that even though I can use prepared statement I cannot rerun the
> query several times without recreating the statement every time? I have a lot
> of cases when I have to make a lot of same inserts basing on xml data from
> request body.

http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html

regards
--
Torsten