You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Ryan Clifton <ry...@weiderinet.com> on 2003/01/24 22:57:30 UTC

Using PreparedStatments with Torque

Hi,

I noticed that by default Torque wants to use regular statements with the values in-lined into the queries.  Ex:  select user.name from user where user.id = '1'

The better way to do this is with prepared statements so the query looks like:

select user.name from user where user.id = ?

then you pass a typed '1' to the prepared statement.  This doesn't have much of an effect in my example, but it has big implications in a real system/schema.

So I've been trying to figure out how Torque handles prepared statements.  I tried the obvious thing of changing my doSelect statements to doPSSelect statements.  The problem is that Torque doesn't auto-populate the columns that are being selected.  In my example the query looks like:

select  from user where user.id = ?

I looked in BasePeer.java and the reason is pretty obvious, you have to explicitly define the columns you want to select by using the Criteria.addSelectColumn(String columnname) method.  This seems like a huge waste of time to me.  Isn't there a way to get Torque to run a prepared statement on all of the columns in a table without having to manually set them?  If not, is there a way to somewhat easily set the columns into the Criteria?

I have tables with 25 columns and if I have to explicitly set each Criteria up, it's going to take forever..

Thanks,

Ryan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>