tags:

views:

844

answers:

2

I would like to feed the result of a simple sql query (something like: select SP_NUMBER from SERVICE_PACK) which I run inside my ant script (using the sql task) back into an ant property (e.g. service.pack.number).

The sql task can output to a file, but is there a more direct way?

A: 

Perhaps the Ant exec task is more useful here ? You can execute a standalone and get the result in a property via outputproperty. You'll have to execute your SQL in some standalone fashion, unfortunately.

Alternatively is it worth looking at the code to the Ant Sql task and modify it to accept an outputproperty ? It sounds a bit of a pain, but I think it could well be a very simple modification if you can't find anything more direct.

Brian Agnew
Thanks for the suggestions, Brian. I'm a bit weary of doing too much outside of my ant script, so I'm going with the approach described in my answer.
zakvdm
Thx for the feedback. Sounds like the most pragmatic solution for your requirements
Brian Agnew
A: 

Although I would have preferred not creating a file, I eventually went with the following solution:

The sql task is called as follows

<sql ... print="yes" output="temp.properties"
        expandProperties="true" showheaders="false" showtrailers="false" >
        <![CDATA[
        select 'current.sp.version=' || NAME from SERVICE_PACK;
        select 'current.major.version=' || NAME from VERSION;
        ]]>
</sql>

The generated properties file will contain:

current.sp.version=03

current.major.version=5

Then you just load the properties file and delete it:

<property file="temp.properties" />
<delete file="temp.properties" />

<echo message="Current service pack version: ${current.sp.version}" />
<echo message="Current major version: ${current.major.version}" />

This works, and everything is right there in the ant script (even if it's not the prettiest thing in the world!).

zakvdm