cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Fagerstrom <dani...@nada.kth.se>
Subject Re: SQL and CTemplate (was Re: [RT] Rules for adding blocks and functionality?)
Date Thu, 03 Nov 2005 15:38:39 GMT
Upayavira wrote:

>Daniel Fagerstrom wrote:
>  
>
...

>>Anyway, for the time beeing I think it is better to focus on making it
>>as easy as possible to use SQL from flowscripts and present the result
>>sets in CTemplate. Then if we don't get it easy enough we can start to
>>think about doing part of ESQL in CTemplate.
>>    
>>
>
>Whilst I'm not going to be the person implementing it, having seen the
>distinction made between SELECT and UPDATE in ESQL/SQLTransformer, I'd
>happily see tags added to CTemplate to allow for SQL querying, without
>the ability to update/insert.
>
>Surely the main thing about a template is that it is side-effect free,
>and that would be.
>
>Maybe better would be some way to separate the SQL from the template.
>Imagine:
>
><esql:select name="my-query" idEmployee="#{request.getParameters('id')}/>
>
>And queries.sql:
>
>my-query: SELECT * FROM Employee WHERE idEmployee = ${idEmployee}
>my-other-query: SELECT * FROM Employers
>
>I guess you'd define your queries.sql file in the <map:generators>
>section of your sitemap.
>
>The worst thing about ESQL/SQLTransformer in my view is the embedded
>SQL. Horrible.
>  
>
That require a small string template language for the queries. While it 
wouldn't be such a big deal to implement a such labuage I'm not to happy 
with having several different template languages with different properties.

I'd rather have a script action that reuse the flow script mechanisms 
except for the web continuation, (as Torsten discussed in another 
thread). Then we could have some utility functions for making it easy to 
create (lazy) query result sets that are embed in some suitable data 
structure that make it easy to iterate over it from JXTG.

The script could look like:

// Query script
myResult = executeSelect("SELECT * FROM Employee WHERE idEmployee = ?", 
{request.parameter.id});
myOtherResult = executeSelect("SELECT * FROM Employers");

return {"myResult": myResult, "myOtherResult": myOtherResult};

The return map from the script is supposed to be used with the ordinary 
flow attribute mechanism from JXTG.

The template would do an ordinary for each:

<jx:for-each select="#{myOtherResult/row}">
  <tr>
    <td>#{name}</td>
    <!-- ... -->
  </tr>
</jx:for-each>

Simple and respects SoC, IMO.

/Daniel


Mime
View raw message