Submitted by: Michael McCallum <michael@spinsoftware.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268906 13f79535-47bb-0310-9956-ffa450edef68master
@@ -29,6 +29,11 @@ Other changes: | |||||
* <fail> supports nested text | * <fail> supports nested text | ||||
* <fixcrlf> won't override files that are already in the correct | |||||
format. | |||||
* <sql> now supports REM comments as well as // and -- | |||||
Fixed bugs: | Fixed bugs: | ||||
----------- | ----------- | ||||
@@ -9,7 +9,7 @@ | |||||
<h3>Description</h3> | <h3>Description</h3> | ||||
<p>Executes a series of sql statement via JDBC to a database. Statements can either be read in from a text file using the src attribute or from between the enclosing sql tags.</p> | <p>Executes a series of sql statement via JDBC to a database. Statements can either be read in from a text file using the src attribute or from between the enclosing sql tags.</p> | ||||
<p>Multiple statements can be set and each statement is delimited from the next use a semi-colon. Individual lines within the statements can be commented using either -- or // at the start of the line.</p> | |||||
<p>Multiple statements can be set and each statement is delimited from the next use a semi-colon. Individual lines within the statements can be commented using either --, // or REM at the start of the line.</p> | |||||
<p>The auto-commit attribute specifies whether auto commit should be turned on or off whilst executing the statements. If auto-commit is turned on each statement will be executed and committed. If it is turned off the statements will all be executed as one transaction.</p> | <p>The auto-commit attribute specifies whether auto commit should be turned on or off whilst executing the statements. If auto-commit is turned on each statement will be executed and committed. If it is turned off the statements will all be executed as one transaction.</p> | ||||
@@ -68,9 +68,10 @@ import java.sql.*; | |||||
/** | /** | ||||
* Reads in a text file containing SQL statements seperated with semicolons | * Reads in a text file containing SQL statements seperated with semicolons | ||||
* and executes it in a given db. | * and executes it in a given db. | ||||
* Both -- and // maybe used as comments. | |||||
* Comments may be created with REM -- or //. | |||||
* | * | ||||
* @author <a href="mailto:jeff@custommonkey.org">Jeff Martin</a> | * @author <a href="mailto:jeff@custommonkey.org">Jeff Martin</a> | ||||
* @author <A href="gholam@xtra.co.nz">Michael McCallum</A> | |||||
*/ | */ | ||||
public class SQLExec extends Task { | public class SQLExec extends Task { | ||||
@@ -425,8 +426,12 @@ public class SQLExec extends Task { | |||||
try{ | try{ | ||||
while ((line=in.readLine()) != null){ | while ((line=in.readLine()) != null){ | ||||
if (line.trim().startsWith("//")) continue; | |||||
if (line.trim().startsWith("--")) continue; | |||||
line = line.trim(); | |||||
if (line.startsWith("//")) continue; | |||||
if (line.startsWith("--")) continue; | |||||
if ( line.length() > 2 ) { | |||||
if (line.substring(0,3).equalsIgnoreCase("REM")) continue; | |||||
} | |||||
sql += " " + line; | sql += " " + line; | ||||
sql = sql.trim(); | sql = sql.trim(); | ||||
@@ -535,7 +540,7 @@ public class SQLExec extends Task { | |||||
do { | do { | ||||
rs = statement.getResultSet(); | rs = statement.getResultSet(); | ||||
if (rs != null) { | if (rs != null) { | ||||
log("Processing new result set.", Project.MSG_VERBOSE); | |||||
log("Processing new result set.", Project.MSG_VERBOSE); | |||||
ResultSetMetaData md = rs.getMetaData(); | ResultSetMetaData md = rs.getMetaData(); | ||||
int columnCount = md.getColumnCount(); | int columnCount = md.getColumnCount(); | ||||
StringBuffer line = new StringBuffer(); | StringBuffer line = new StringBuffer(); | ||||