Or, if the info you're exporting maps to your Torque app's 
tables, you could probably just add "toSQL()" methods to
the record stubs that creates the INSERT statements.

E.g. if you have a User record object, modify the User.java
Torque created with something like:

Public String toSQL() {
   StringBuffer sql = new StringBuffer;
   
// Build SQL statement from current object contents

   return sql.toString();
}

Then just do a normal Torque query to get the data you're 
interested in and loop thru the results calling toSQL to 
create your output file.

Note that once the "stub" classes are built, Torque will not
replace them if your regenerate the code. So the toSQL() code 
is safe.

It would also be possible to create some generic Torque record to
SQL code by using the "map" information.  This lets you determine
the column info in a table.  So you could look up the table info 
for a record object, then create the sql by iterating over the 
column names and using the column type to determine the string 
format to use.

But for a few table objects, it might be easier to just do the 
manually created toSQL() methods.

-----Original Message-----
From: Thomas Vandahl [mailto:t...@apache.org] 
Sent: Thursday, January 19, 2012 12:51 PM
To: Apache Torque Users List
Subject: Re: get the SQL to be executed

On 19.01.12 18:38, Ivano Luberti wrote:
> Thanks all for your responses.
> Just to clarify, I need to generate sql commands inside my code to
> generate a file that can be used by another software (not written by me)
> to import data.
> 
> I would like not to execute commands but only write them (because this
> is what I need).
> If I cannot find alternatives, I can execute them and use one of the
> logging facilities that have been suggested.

Well, inserts are sort of tricky because the actual SQL generation
happens deep inside Village. If you have control over your class loader,
you may modify a copy of the com.workingdogs.village.Record class and
put that first in the chain. Look for the saveWithInsert() method. This
is probably the closest you can get, IMHO.

Bye, Thomas.

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscr...@db.apache.org
For additional commands, e-mail: torque-user-h...@db.apache.org

DukeCE Privacy Statement:
Please be advised that this e-mail and any files transmitted with
it are confidential communication or may otherwise be privileged or
confidential and are intended solely for the individual or entity
to whom they are addressed. If you are not the intended recipient
you may not rely on the contents of this email or any attachments,
and we ask that you please not read, copy or retransmit this
communication, but reply to the sender and destroy the email, its
contents, and all copies thereof immediately. Any unauthorized
dissemination, distribution or copying of this communication is
strictly prohibited.

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscr...@db.apache.org
For additional commands, e-mail: torque-user-h...@db.apache.org

Reply via email to