You should really get rid of the exec task and use the Ant sql task instead. It just requires a JDBC driver.
Suitable parameters exist for all your args.

Robert.

Le 8/11/2010 16:19, Java Jboss a écrit :
Hi,

Thank you to all for the suggestions.  I have now got an ANT script that
checks the current database version and then runs a set of mysql scripts to
upgrade the database to the next version.  What I am struggling with is when
it goes through the list="${db.upgrade.path.list}.  On the first run the
folder exists and runs the scripts then on the second run it checks for the
next folder(it doesn't exist at the moment) and it should drop out echoing
the new current version but in my case it tries to run every occurrence as
per the  list="${db.upgrade.path.list}. I want it to stop when it can't meet
the next condition.  The output I am getting is as below:

<!-- ***************************************
   Restore MySQL database
   **************************************** -->
<target name="restore-db">
     <!-- Clean up the database by deleting and then creating it. -->
     <antcall target="delete_db"/>
     <antcall target="create_db"/>
<!-- Import data from the backup file. -->
     <exec executable="${my.sql}" input="db_dumps/db1.sql">
       <arg value="--user=root"/>
       <arg value="--password=<password>"/>
       <arg value="--host=localhost" />
       <arg value="--port=3306" />
       <arg value="<newschema1>"/>
     </exec>
    <exec executable="${my.sql}" input="db_dumps/db2.sql">
       <arg value="--user=root"/>
       <arg value="--password=<password>"/>
       <arg value="--host=localhost" />
       <arg value="--port=3306" />
       <arg value="<newschema2>"/>
     </exec>
   <exec executable="${my.sql}" input="db_dumps/db3.sql">
       <arg value="--user=root"/>
       <arg value="--password=<password>"/>
       <arg value="--host=localhost" />
       <arg value="--port=3306" />
       <arg value="<newschema3>"/>
     </exec>
   <exec executable="${my.sql}" input="db_dumps/db4.sql">
       <arg value="--user=root"/>
       <arg value="--password=<password>"/>
       <arg value="--host=localhost" />
       <arg value="--port=3306" />
       <arg value="<newschema4>"/>
     </exec>
</target>

   <target name="delete_db">
     <exec executable="${my.sql}">
       <arg value="--user=root"/>
       <arg value="--password=<password>"/>
       <arg value="--host=localhost" />
       <arg value="--port=3306" />
       <arg value="--force"/>
       <arg value="drop"/>
       <arg value="<newschema1>"/>
       <arg value="<newschema2>"/>
       <arg value="<newschema3>"/>
       <arg value="<newschema4>"/>
     </exec>
   </target>

   <target name="create_db">
     <exec executable="${my.sql}">
       <arg value="--user=root"/>
       <arg value="--password=<password>"/>
       <arg value="--host=localhost" />
       <arg value="--port=3306" />
       <arg value="--force"/>
       <arg value="create"/>
       <arg value="<newschema1>"/>
       <arg value="<newschema2>"/>
       <arg value="<newschema3>"/>
       <arg value="<newschema4>"/>
     </exec>
   </target>

<!-- ***************************************
   Get database version
   **************************************** -->
<target name="get-db-version">
        <exec executable="${my.sql}" outputproperty="get-db-version.out"
input="getdbver.sql">
            <arg line="--host=${server.ip}"/>
            <arg line="--user=root"/>
            <arg line="--password=<password>"/>
            <arg line="-D${newschema1}"/>
      </exec>
    <echo>Is at ${get-db-version.out}</echo>
</target>

<!-- ************************************************
            Check database upgrade scripts exists
   *********************************************** -->
<target name="db-version" if="get-db-version.out" depends="get-db-version">
    <echo>Running upgrade from ${get-db-version.out}</echo>

  <condition property="script1.exists">
            <available filepath="<directory>" file="script1.sql"/>
         </condition>
          <antcall target="run-script1"/>
        <condition property="script2.exists">
            <available filepath="<directory>" file="script2.sql"/>
         </condition>
    <antcall target="run-script2"/>
  <condition property="script3.exists">
            <available filepath="<directory>" file="script3.sql"/>
         </condition>
    <antcall target="run-script3"/>
  <condition property="script4.exists">
            <available filepath="<directory>" file="script4.sql"/>
         </condition>
    <antcall target="run-script4"/>
</target>

<!-- ***************************************
               Run database upgrade scripts
   **************************************** -->
<target name="run-script1" if="script1.exists">
       <echo>Running sql in dir<directory></echo>
       <exec executable="${my.sql}" input="<directory>/script1.sql"
failonerror="true">
       <arg value="--user=<username>"/>
       <arg value="--password=<password>"/>
       <arg value="--host=localhost" />
       <arg value="--port=3306" />
       <arg value="<newschema1>"/>
       </exec>
</target>
<target name="run-script2" if="script2.exists">
       <echo>Running sql in dir<directory></echo>
       <exec executable="${my.sql}" input="<directory>/script2.sql"
failonerror="true">
       <arg value="--user=<username>"/>
       <arg value="--password=<password>"/>
       <arg value="--host=localhost" />
       <arg value="--port=3306" />
       <arg value="<newschema1>"/>
       </exec>
</target>
<target name="run-script3" if="script3.exists">
       <echo>Running sql in dir<directory></echo>
       <exec executable="${my.sql}" input="<directory>/script3.sql"
failonerror="true">
       <arg value="--user=<username>"/>
       <arg value="--password=<password>"/>
       <arg value="--host=localhost" />
       <arg value="--port=3306" />
       <arg value="<newschema1>"/>
       </exec>
</target>
<target name="run-script4" if="script4.exists">
       <echo>Running sql in dir<directory></echo>
       <exec executable="${my.sql}" input="<directory>/script4.sql"
failonerror="true">
       <arg value="--user=<username>"/>
       <arg value="--password=<password>"/>
       <arg value="--host=localhost" />
       <arg value="--port=3306" />
       <arg value="<newschema1>"/>
       </exec>
</target>


OUTPUT

get-db-version:
      [echo] Current database version: 1.00

db-upgrade:
      [echo] Current Version: 1.00
      [echo] Upgrade path : 1.0-2.0
      [echo] database......... mysql
      [echo] tx............... standalone
      [echo] mail.smtp.host... localhost

get-db-version:
      [echo] Current database version: 1.01

db-upgrade:
      [echo] Current Version: 1.01
      [echo] Upgrade path : 2.0-3.0
      [exec] Failed to open
../build/dir-upgrade-2.0-3.0/Upgrade-1.01-1-Pre.sql
      [exec] Failed to open
../build/dir-upgrade-2.0-3.0/Upgrade-1.01-2-Data.sql
      [exec] Failed to open
../build/dir-upgrade-2.0-3.0/Upgrade-1.01-3-Post.sql
      [exec] Failed to open
../build/dir-upgrade-2.0-3.0/Upgrade-1.01-4-Version.sql
      [echo] database......... mysql
      [echo] tx............... standalone
      [echo] mail.smtp.host... localhost

get-db-version:
      [echo] Current database version: 1.01

db-upgrade:
      [echo] Current Version: 1.01
      [echo] Upgrade path : 3.0-4.0
      [exec] Failed to open
../build/dir-upgrade-3.0-4.0/Upgrade-1.01-1-Pre.sql
      [exec] Failed to open
../build/dir-upgrade-3.0-4.0/Upgrade-1.01-2-Data.sql
      [exec] Failed to open
../build/dir-upgrade-3.0-4.0/Upgrade-1.01-3-Post.sql
      [exec] Failed to open
../build/dir-upgrade-3.0-4.0/Upgrade-1.01-4-Version.sql

BUILD SUCCESSFUL




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

Reply via email to