ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Guttula, Mohan" <MGutt...@tiaa-cref.org>
Subject RE: Looping through a file contents and dynamically add <transaction> for each line in the file to <SQL> task
Date Tue, 11 Apr 2006 15:37:15 GMT
Hello Jon,

Thanks for all your help. Your solution resolved my issue.

Question: What is the industry standard for Database scripts?(i.e.,
either using "SQL" ANT task or using sqlplus.exe inside ant through
"Apply/Exec" tasks)?

Thanks,
Mohan

-----Original Message-----
From: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de] 
Sent: Monday, April 10, 2006 3:06 AM
To: user@ant.apache.org
Subject: AW: Looping through a file contents and dynamically add
<transaction> for each line in the file to <SQL> task

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



**************************************************************
This message, including any attachments, contains confidential information intended for a
specific individual and purpose, and is protected by law.  If you are not the intended recipient,
please contact sender immediately by reply e-mail and destroy all copies.  You are hereby
notified that any disclosure, copying, or distribution of this message, or the taking of any
action based on it, is strictly prohibited.
TIAA-CREF
**************************************************************


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


Mime
View raw message