Author: bodewig
Date: Fri Jul 11 06:35:50 2008
New Revision: 675949
URL: http://svn.apache.org/viewvc?rev=675949&view=rev
Log:
work on PR 26459 - in progress (fighting with the tests and my environment)
Modified:
ant/core/trunk/docs/manual/CoreTasks/sql.html
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java
Modified: ant/core/trunk/docs/manual/CoreTasks/sql.html
URL:
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/sql.html?rev=675949&r1=675948&r2=675949&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/sql.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/sql.html Fri Jul 11 06:35:50 2008
@@ -204,6 +204,16 @@
</tr>
</table>
+<tr>
+ <td width="12%" valign="top">strictDelimiterMatching</td>
+ <td width="78%" valign="top">If false, delimiters will be searched
+ for in a case-insesitive manner (i.e. delimer="go" matches "GO")
+ and surrounding whitespace will be ignored (delimter="go" matches
+ "GO "). <em>Since Ant 1.8.0</em>.</td>
+ <td width="10%" valign="top">No, default <em>true</em></td>
+</tr>
+</table>
+
<h3>Parameters specified as nested elements</h3>
<h4>transaction</h4>
<p>Use nested <code><transaction></code>
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SQLExec.java?rev=675949&r1=675948&r2=675949&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 Fri Jul
11 06:35:50 2008
@@ -40,6 +40,7 @@
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.Iterator;
+import java.util.Locale;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -199,6 +200,12 @@
private boolean rawBlobs;
/**
+ * delimers must match in case and whitespace is significant.
+ * @since Ant 1.8.0
+ */
+ private boolean strictDelimiterMatching = true;
+
+ /**
* 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.
@@ -397,6 +404,16 @@
}
/**
+ * If false, delimiters will be searched for in a case-insesitive
+ * manner (i.e. delimer="go" matches "GO") and surrounding
+ * whitespace will be ignored (delimter="go" matches "GO ").
+ * @since Ant 1.8.0
+ */
+ public void setStrictDelimiterMatching(boolean b) {
+ strictDelimiterMatching = b;
+ }
+
+ /**
* Load the sql file and then execute it
* @throws BuildException on error.
*/
@@ -542,9 +559,9 @@
if (!keepformat && line.indexOf("--") >= 0) {
sql.append("\n");
}
- if ((delimiterType.equals(DelimiterType.NORMAL) &&
StringUtils.endsWith(sql, delimiter))
- || (delimiterType.equals(DelimiterType.ROW) &&
line.equals(delimiter))) {
- execSQL(sql.substring(0, sql.length() - delimiter.length()),
out);
+ int lastDelimPos = lastDelimiterPosition(sql, line);
+ if (lastDelimPos > -1) {
+ execSQL(sql.substring(0, lastDelimPos), out);
sql.replace(0, sql.length(), "");
}
}
@@ -833,4 +850,45 @@
}
}
}
+
+ public int lastDelimiterPosition(StringBuffer buf, String currentLine) {
+ if (strictDelimiterMatching) {
+ if (delimiterType.equals(DelimiterType.NORMAL)
+ && StringUtils.endsWith(buf, delimiter)) {
+ return buf.length() - delimiter.length();
+ } else if (delimiterType.equals(DelimiterType.ROW)
+ && currentLine.equals(delimiter)) {
+ return 0;
+ }
+ // no match
+ return -1;
+ } else {
+ String d = delimiter.trim().toLowerCase(Locale.US);
+ if (delimiterType.equals(DelimiterType.NORMAL)) {
+ // still trying to avoid wasteful copying, see
+ // StringUtils.endsWith
+ int endIndex = delimiter.length() - 1;
+ int bufferIndex = buf.length() - 1;
+ while (bufferIndex >= 0
+ && Character.isWhitespace(buf.charAt(bufferIndex))) {
+ --bufferIndex;
+ }
+ if (bufferIndex < endIndex) {
+ return -1;
+ }
+ while (endIndex >= 0) {
+ if (buf.substring(bufferIndex, 1).toLowerCase(Locale.US)
+ .charAt(0) != d.charAt(endIndex)) {
+ return -1;
+ }
+ bufferIndex--;
+ endIndex--;
+ }
+ return bufferIndex;
+ } else {
+ return currentLine.trim().toLowerCase(Locale.US).equals(d)
+ ? 0 : -1;
+ }
+ }
+ }
}
Modified:
ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java?rev=675949&r1=675948&r2=675949&view=diff
==============================================================================
---
ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java
(original)
+++
ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java
Fri Jul 11 06:35:50 2008
@@ -234,4 +234,22 @@
}
}
+ public void testLastDelimiterPositionNormalModeStrict() {
+ SQLExec s = new SQLExec();
+ assertEquals(-1,
+ s.lastDelimiterPosition(new StringBuffer(), null));
+ assertEquals(-1,
+ s.lastDelimiterPosition(new StringBuffer("GO"), null));
+ assertEquals(-1,
+ s.lastDelimiterPosition(new StringBuffer("; "), null));
+ assertEquals(2,
+ s.lastDelimiterPosition(new StringBuffer("ab;"), null));
+ s.setDelimiter("GO");
+ assertEquals(-1,
+ s.lastDelimiterPosition(new StringBuffer("GO "), null));
+ assertEquals(-1,
+ s.lastDelimiterPosition(new StringBuffer("go"), null));
+ assertEquals(0,
+ s.lastDelimiterPosition(new StringBuffer("GO"), null));
+ }
}