Author: stevel Date: Thu Jan 12 13:03:26 2006 New Revision: 368466 URL: http://svn.apache.org/viewcvs?rev=368466&view=rev Log: bug #38245; sql broken on Ant1.7; added expandProperties attribute to expand properties in SQL statements. Modified: ant/core/trunk/WHATSNEW ant/core/trunk/docs/manual/CoreTasks/sql.html ant/core/trunk/docs/manual/api/index.html ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java ant/core/trunk/src/main/org/apache/tools/ant/types/resources/FileResource.java Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewcvs/ant/core/trunk/WHATSNEW?rev=368466&r1=368465&r2=368466&view=diff ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Thu Jan 12 13:03:26 2006 @@ -334,19 +334,24 @@ * now accepts nested FileNameMappers e.g. . Bugzilla report 37604. -* New task loadresource that accompanies loadfile for non file resources. +* New task that accompanies for non file resources. * now supports an encoding when saving to a file. * new GreedyInputHandler added. -* add textfile attribute to the filesmatch condition. +* add textfile attribute to the condition. When true, the text + contents of the two files are compared, ignoring line ending differences. -* new resourcesmatch condition. +* new condition. * added the onmissingfiltersfile attribute to filterset. Bugzilla report 19845. * added the inline handler element to the input task. + +* supports property expansion if you set the expandProperties attribute. By default + it does not expand properties, something we dare not change for fear of breaking complex + SQL operations in existing files. Changes from Ant 1.6.4 to Ant 1.6.5 =================================== Modified: ant/core/trunk/docs/manual/CoreTasks/sql.html URL: http://svn.apache.org/viewcvs/ant/core/trunk/docs/manual/CoreTasks/sql.html?rev=368466&r1=368465&r2=368466&view=diff ============================================================================== --- ant/core/trunk/docs/manual/CoreTasks/sql.html (original) +++ ant/core/trunk/docs/manual/CoreTasks/sql.html Thu Jan 12 13:03:26 2006 @@ -146,10 +146,17 @@ object will perform escape substitution.
See Statement's - API docs for details. since Ant 1.6. + API docs for details. . No (default=true) + + expandproperties + Set to true to turn on property expansion in + nested SQL, inline in the task or nested transactions. Since Ant 1.7. + No (default=false) + +

Parameters specified as nested elements

@@ -220,7 +227,8 @@

Connects to the database given in url as the sa user using the org.database.jdbcDriver and executes the two SQL statements - inserting data into some_table and truncating some_other_table

+ inserting data into some_table and truncating some_other_table. Ant Properties + in the nested text will not be expanded.

Note that you may want to enclose your statements in <![CDATA[ ... ]]> sections so you don't @@ -238,6 +246,23 @@ ]]></sql> + +The following command turns property expansion in nested text on (it is off purely for backwards +compatibility), then creates a new user in the HSQLDB database using Ant properties. + +

<sql
+    driver="org.hsqldb.jdbcDriver";
+    url="jdbc:hsqldb:file:${database.dir}"
+    userid="sa"
+    password=""
+    expandProperties="true"
+    >
+  <transaction>
+    CREATE USER ${newuser} PASSWORD ${newpassword}
+  </transaction>
+</sql>
+
+

The following connects to the database given in url as the sa user using the org.database.jdbcDriver and executes the SQL statements contained within Modified: ant/core/trunk/docs/manual/api/index.html URL: http://svn.apache.org/viewcvs/ant/core/trunk/docs/manual/api/index.html?rev=368466&r1=368465&r2=368466&view=diff ============================================================================== --- ant/core/trunk/docs/manual/api/index.html (original) +++ ant/core/trunk/docs/manual/api/index.html Thu Jan 12 13:03:26 2006 @@ -1,12 +1,37 @@ - - - - -Apache Ant API - - -Redirecting to Apache Ant API ... - - - + + + + + + +Apache Ant API + + + + + + + + + + + +<H2> +Frame Alert</H2> +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. +<BR> +Link to<A HREF="overview-summary.html">Non-frame version.</A> + + + Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java?rev=368466&r1=368465&r2=368466&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java Thu Jan 12 13:03:26 2006 @@ -300,7 +300,7 @@ */ protected Connection getConnection() throws BuildException { if (userId == null) { - throw new BuildException("User Id attribute must be set!", getLocation()); + throw new BuildException("UserId attribute must be set!", getLocation()); } if (password == null) { throw new BuildException("Password attribute must be set!", getLocation()); @@ -378,14 +378,17 @@ } catch (ClassNotFoundException e) { throw new BuildException( "Class Not Found: JDBC driver " + driver + " could not be loaded", + e, getLocation()); } catch (IllegalAccessException e) { throw new BuildException( "Illegal Access: JDBC driver " + driver + " could not be loaded", + e, getLocation()); } catch (InstantiationException e) { throw new BuildException( "Instantiation Exception: JDBC driver " + driver + " could not be loaded", + e, getLocation()); } return driverInstance; Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java?rev=368466&r1=368465&r2=368466&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java Thu Jan 12 13:03:26 2006 @@ -181,6 +181,14 @@ private boolean escapeProcessing = true; /** + * should properties be expanded in text? + * false for backwards compatibility + * + * @since Ant 1.7 + */ + private boolean expandProperties = false; + + /** * Set the name of the SQL file to be run. * Required unless statements are enclosed in the build file * @param srcFile the file containing the SQL command. @@ -190,11 +198,34 @@ } /** + * Enable property expansion inside nested text + * + * @param expandProperties + * @since Ant 1.7 + */ + public void setExpandProperties(boolean expandProperties) { + this.expandProperties = expandProperties; + } + + /** + * is property expansion inside inline text enabled? + * + * @return true if properties are to be expanded. + * @since Ant 1.7 + */ + public boolean getExpandProperties() { + return expandProperties; + } + + /** * Set an inline SQL command to execute. - * NB: Properties are not expanded in this text. - * @param sql a inline string containing the SQL command. + * NB: Properties are not expanded in this text unless {@link #expandProperties} + * is set. + * @param sql an inline string containing the SQL command. */ public void addText(String sql) { + //there is no need to expand properties here as that happens when Transaction.addText is + //called; to do so here would be an error. this.sqlCommand += sql; } @@ -209,7 +240,7 @@ /** * Adds a collection of resources (nested element). - * @param set a collection of resources containing SQL commands, + * @param rc a collection of resources containing SQL commands, * each resource is run in a separate transaction. * @since Ant 1.7 */ @@ -664,11 +695,15 @@ * @param src the source file */ public void setSrc(File src) { - setSrcResource(new FileResource(src)); + //there are places (in this file, and perhaps elsewhere, where it is assumed + //that null is an acceptable parameter. + if(src!=null) { + setSrcResource(new FileResource(src)); + } } /** - * Set the source file attribute. + * Set the source resource attribute. * @param src the source file * @since Ant 1.7 */ @@ -684,7 +719,12 @@ * @param sql the inline text */ public void addText(String sql) { - this.tSqlCommand += sql; + if (sql != null) { + if (getExpandProperties()) { + sql = getProject().replaceProperties(sql); + } + this.tSqlCommand += sql; + } } /** Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/FileResource.java URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/FileResource.java?rev=368466&r1=368465&r2=368466&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/FileResource.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/FileResource.java Thu Jan 12 13:03:26 2006 @@ -277,8 +277,14 @@ * @return this FileResource formatted as a String. */ public String toString() { - return isReference() ? getCheckedRef().toString() - : FILE_UTILS.normalize(file.getAbsolutePath()).getAbsolutePath(); + if(isReference()) { + return getCheckedRef().toString(); + } + if(file==null) { + return "(unbound file resource)"; + } + String absolutePath = file.getAbsolutePath(); + return FILE_UTILS.normalize(absolutePath).getAbsolutePath(); } /** --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org