ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ninju Bohra <ninju_bo...@yahoo.com>
Subject Re: Conditional antcall
Date Mon, 20 Feb 2006 17:38:02 GMT
Within the constraints of default ANT components it may be a bit klugely (but then you're probably
used doing ANT kluges :-)
 
A way that I found to get data into ANT from the database is to execute SQL whose result (when
successful) looks like a standard JAVA property file.  I then use the <sql> task with
the output property set to send the results to a temp file (also showheaders=false helps).
 I execute the SQL (with onerror=continue) and then load the property file (via the <property
file="..."> task)  
 
If the task executed properly, a property would have been loaded into the ANT property space.
 I use that property in my if/unless checks.
 
In your case, the follow SQL will result in a property being set only if you are able to reach
a table in the database:
 
    SELECT DISTINCT('found.database=true') from ANY_TABLE;
 
(note replace ANY_TABLE with the name of a table that you expect to be in the schema)
 
Now if you redirect the output to a file and load that file, you can now conditionally check
the property ${found.database} to tell you whether the database is there or not...
 
Of course, at our project site we ended up modifying the <sql> task to support an onerrorproperty
which allows us to have a property to be set if we ecounter an error while executing a SQL.
 
You can also use the <try>/<catch> task from the ant-contrib project to tell you
that there was an error executing SQL.
Hope that makes sense,
 
Ninju
 



----- Original Message ----
From: ar <armaillist@free.fr>
To: user@ant.apache.org
Sent: Monday, February 20, 2006 10:41:35 AM
Subject: Conditional antcall


Hi,

I'd like to access to a database, and, if it fails, create the database  
otherwise update it.
To access the database, I intend to use a sql task. If the sql request  
fails, I want to call the create-database target. If it successes, I want  
to call the update-database target.
Any idea on how to do this conditional call ?

Regards
-- 
A. ROY

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message