The attached patches allow creating a <connection> within the build file and referencing it from the <sql> task rather than having to define all of the connection information each time. Also, it adds a <database> condition that can be used to query the database for the existence of a schema, a catalog, a table or view within a schema/catalog, or a column/index on a table. There are three attachments. One is a patch file, the other two are new sources.
Created attachment 3824 [details] Patch as described.
Created attachment 3825 [details] Java source file - place in org/apache/tools/ant/types
Created attachment 3826 [details] Java source file - place in org/apache/tools/ant/taskdefs/condition
Here is an example build file (based upon the one I used to test this) that demonstrates some of the syntax. Note: I ran ant with -debug to see what properties were set as a result of the conditions, so there is no explicit use of the "xxxxx.is.present" property values. (Their use is left as an exercise to the reader ;-) <?xml version="2.0"?> <project default="main" basedir="."> <path id="classes12"> <pathelement location="c:/software/jdbc/classes12.jar"/> </path> <!-- Make sure the connection works properly with a classpath --> <connection id="connection1" driver="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:ORCL" userid="lacht" password="none_of_your_business" classpath="c:/software/jdbc/classes12.jar"/> <!-- Make sure the connection works properly with a classpathref --> <connection id="connection2" driver="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:ORCL" userid="lacht" password="none_of_your_business" classpathref="classes12"/> <target name="main"> <!-- Make sure it still works the old way --> <sql driver="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:ORCL" userid="lacht" password="none_of_your_business" classpathref="classes12"> <transaction> select * from dual </transaction> </sql> <!-- The same thing with a connectionref --> <sql connectionref="connection1"> <transaction> select * from dual </transaction> </sql> <condition property="schema.is.present"> <database connectionref="connection2" type="schema" name="LACHT"/> </condition> <condition property="table.is.present"> <database connectionref="connection2" catalog="" type="table" schema="LACHT" name="TURBINE_USER"/> </condition> <condition property="column.is.present"> <or> <database connectionref="connection1" catalog="" type="column" schema="LACHT" table="TURBINE_USER" name="OBJECT_DATA"/> <database connectionref="connection2" catalog="" type="column" schema="LACHT" table="TURBINE_USER" name="OBJECTDATA"/> </or> </condition> </target> </project>