ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject RE: problem in executing sql statements under foreach task
Date Wed, 13 Aug 2003 06:22:16 GMT
> Hai Friends,
> I need a help from you all.
> I have two questions.
> 
> 1. I am trying to execute set of sql files present in a 
> directory one by one
> using foreach task. my test code is like this. How can I pass
> (properties)variables defined in the other targets.
> i.e ${driver}, ${durl}.... or is there any way to acheieve that?

<foreach inheritall="true" inheritrefs="true"/>






> <interactive verbose="off">
> <input property ="driver" text="Database Driver" type="string"
> value="oracle.jdbc.driver.OracleDriver"/>
> <input property="durl" text="Driver URL" type="string"
> value="jdbc:oracle:thin:@localhost:1521:orcl"/>
> <input property="dbuname" text="User Name" type="string" value="cdm"/>
> <input property="dbupass" text="PassWord" type="string" value="cdm"/>
> </interactive>


FYI: Ant contains an <input> task (1.5.3-1, maybe earlier, too).


> <taskdef resource="net/sf/antcontrib/antcontrib.properties" />
> <target name="test">
>    <foreach param="myparam" target="sqlrun">
>          <path>
>          <fileset dir="D:\orac" includes="*.sql"/>
>          </path>   
>    </foreach>      
> </target>
> 	
> <target name="sqlrun">
> 	<echo>Called with ${myparam}</echo>
> 	<sql onerror="continue" driver="${driver}" url="${durl}"
> userid="${dbuname}" password="${dbupass}" >
>   	<transaction  src="${myparam}"/>
> 	</sql>
> </target>


Maybe faster, maybe easier (maybe wrong :-)

<concat destfile="tmp.sql">
    <fileset dir="D:\orac" includes="*.sql"/>
</concat>
<sql ... src="tmp.sql"/>
<delete file="tmp.sql"/>


> The echo command gives correct result, but when its trying to 
> execute sql
> file it throws
> Class Not Found: JDBC driver ${driver} could not be loaded 
> error. ( I am
> sure, I have added neccessary jar files in the
> class path)

For faster tests: print all these values.


> 2. My second question is can we control the order of execution, i.e by
> alphatical or parent directoty 
> first then sub directoy and so any attributes for that is available?

AFAIK you can´t.
(I´m sure, I had read a hint somewhere ... I think in DirectoryScanner ...
sorry, not found).


In your case you use <foreach>. Why you don´t use a file containing all the
sql-file-names?

sql.files
----------
test-1.sql
another-test.sql
subdir/foo.sql


<loadfile property="sql.files" srcFile="sql.files"/>
<foreach ... list="${sql.files}" delimiter="${line.separator}"/>





Or you write the result of the fileset into a file and call an external sort
program. Then
read and use that.

<fileset id="fs" dir="D:\orac" includes="*.sql"/>
<pathconvert property="fs.value" refid="fs" pathsep="${line.separator}"/>
<echo file="sql.files" message="${fs.value}"/>
<exec ....  />   <!-- sort here -->
<loadfile property="sql.files" srcFile="sql.files"/>
<foreach ... list="${sql.files}" delimiter="${line.separator}"/>



Nothing tested, just thoughts 


Jan

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message