ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject AW: Looping through a file contents and dynamically add <transaction> for each line in the file to <SQL> task
Date Mon, 10 Apr 2006 07:06:18 GMT
I thought, <import> statement would processed earlier ...
But I played a little bit and it seems that this would work:

1. The buildfile creates a second buildfile with your sql-oracle target
   - extract the static stuff into two files (prepend,append)
     BTW: I used properties in the sql-append.txt for Ant and Oracle...
   - generate the <transaction> lines from your sample.sql file using
regexp's
   - copy these three parts together
2. Import the just created buildfile
You call that (master)buildfile as used....


>Part of my requirement is to call the "SQL" task only once and 
>add as many "<transaction>" elements as the number of lines in 
>"sample.sql".
>
>Note: "Sample.sql" contains other sql file names as mentioned 
>in my first e-mail.


So here are my example files (I commented the <sql> statement and used
an <echo> instead)


build.xml
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<------
-8-<----
<project>

    <macrodef name="buildSQL">
        <sequential>
            <copy file="sample.sql" tofile="sql.txt" overwrite="true"/>
            <replaceregexp 
              file="sql.txt" 
              match="(.*)" 
              replace="      &lt;transaction src=&quot;\1&quot;/&gt;"  
              byline="true"
            />
            <move file="sql.txt" tofile="sql.xml">
                <filterchain>
                    <concatfilter prepend="sql-prepend.txt"
append="sql-append.txt"/>
                </filterchain>
            </move>
        </sequential>
    </macrodef>

    <buildSQL/>
    <import file="sql.xml"/>

</project>
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<------
-8-<----



sql-prepend.txt
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<------
-8-<----
<project name="callOracle">
  <target name="sql-oracle">
<echo>SQL-Oracle</echo>
<!--
    <sql
       driver="oracle.jdbc.driver.OracleDriver"
       delimiter="/"
       delimitertype="row"
       keepformat="true"
 
url="jdbc:oracle:thin:@${machine_name}:1521:${database_Instance_name}"
       userid="${user_name}"
       password="${password}"
    >
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<------
-8-<----


sql-append.txt
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<------
-8-<----

      <classpath>
        <pathelement location="${oracle.home}/jdbc/lib/classes12.jar"/>

        <fileset dir="${ant.home}/lib">
          <include name="**/*.jar"/>
        </fileset>
      </classpath>
    </sql>
-->
  </target>
</project>
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<------
-8-<----


sample.sql
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<------
-8-<----
release\Country.sql
release\State.sql
release\City.sql
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<------
-8-<----


Test run:
C:\tmp\ant-createProject>ant sql-oracle
Buildfile: build.xml
     [copy] Copying 1 file to C:\tmp\ant-createProject
     [move] Moving 1 file to C:\tmp\ant-createProject

sql-oracle:
     [echo] SQL-Oracle

BUILD SUCCESSFUL
Total time: 0 seconds





Jan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message