db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anthony Kay <awka...@yahoo.com>
Subject Enhancement (w/patch)
Date Wed, 27 Aug 2003 22:40:05 GMT
Hi,

I tried to get into the Scarab system to post this...I could get into
the Source module, but not the source one, so I thought I might try
making my suggestion here anyway.

I find that sometimes on complex databases that I would like to write a
complex SQL query (on a table with lots of columns, joining to multiple
tables, with complex conditions), but have the results put into
objects. The Peer already supports this with resultSet2Objects.

My problem was that there is no way to easily get the list of fields in
the format I often desire. That is to say that if I have a table that
has 15 columns, and I want to alias it in the SQL to ease my typing in
the rest of the query, the resulting code is hideous. 

I have made my own patch to the Torque system velocity template
(Peer.vm) that adds a nice method and public variable for this purpose,
and includes documentation that has an example to show the use of the
thing.

Example:
Connection con = Torque.getConnection();
Statement stmt = con.createStatement();
// the "l" parameter is the alias to use for the table
ResultSet rs = stmt.executeQuery("select " +
LocationPeer.getQueryFields("l") + " from location l,
locationcategories lcs, locationcategory lc where COMPLEX STUFF");
                                                                       
        
List locations = LocationPeer.resultSet2Objects(rs);

You are welcome to include it in the main distro if you think it a
useful addition; otherwise, ignore at will :)

- Tony

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Mime
View raw message