conor 01/07/07 03:22:24
Modified: src/main/org/apache/tools/ant/taskdefs SQLExec.java
Log:
Add support for delimiter type. Base don the ideas contained in
the bugzilla report suggested by [EMAIL PROTECTED] (Johan Adelow)
PR: 273
Revision Changes Path
1.19 +30 -5
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
Index: SQLExec.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- SQLExec.java 2001/07/07 00:11:18 1.18
+++ SQLExec.java 2001/07/07 10:22:23 1.19
@@ -74,7 +74,16 @@
* @author <A href="[EMAIL PROTECTED]">Michael McCallum</A>
*/
public class SQLExec extends Task {
+
+ static public class DelimiterType extends EnumeratedAttribute {
+ static public final String NORMAL = "normal";
+ static public final String ROW = "row";
+ public String[] getValues() {
+ return new String[] {NORMAL, ROW};
+ }
+ }
+
private int goodSql = 0, totalSql = 0;
private Path classpath;
@@ -137,6 +146,12 @@
private String delimiter = ";";
/**
+ * The delimiter type indicating whether the delimiter will
+ * only be recognized on a line by itself
+ */
+ private String delimiterType = DelimiterType.NORMAL;
+
+ /**
* Print SQL results.
*/
private boolean print = false;
@@ -260,6 +275,16 @@
}
/**
+ * Set the Delimiter type for this sql task. The delimiter type takes
+ * two values - normal and row. Normal means that any occurence of the
delimiter
+ * terminate the SQL command whereas with row, only a line containing
just the
+ * delimiter is recognized as the end of the command.
+ */
+ public void setDelimiterType(DelimiterType delimiterType) {
+ this.delimiterType = delimiterType.getValue();
+ }
+
+ /**
* Set the print flag.
*/
public void setPrint(boolean print) {
@@ -441,9 +466,8 @@
line = line.trim();
if (line.startsWith("//")) continue;
if (line.startsWith("--")) continue;
- if ( line.length() > 2 ) {
- if (line.substring(0,3).equalsIgnoreCase("REM")) continue;
- }
+ if (line.length() > 2 &&
+ line.substring(0,3).equalsIgnoreCase("REM")) continue;
sql += " " + line;
sql = sql.trim();
@@ -453,9 +477,10 @@
// so we cannot just remove it, instead we must end it
if (line.indexOf("--") >= 0) sql += "\n";
- if (sql.endsWith(delimiter)){
+ if (delimiterType.equals(DelimiterType.NORMAL) &&
sql.endsWith(delimiter) ||
+ delimiterType.equals(DelimiterType.ROW) &&
line.equals(delimiter)) {
log("SQL: " + sql, Project.MSG_VERBOSE);
- execSQL(sql.substring(0, sql.length()-1), out);
+ execSQL(sql.substring(0, sql.length() -
delimiter.length()), out);
sql = "";
}
}