ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r675954 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/taskdefs/SQLExec.java src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java
Date Fri, 11 Jul 2008 13:58:38 GMT
Author: bodewig
Date: Fri Jul 11 06:58:38 2008
New Revision: 675954

URL: http://svn.apache.org/viewvc?rev=675954&view=rev
Log:
allow a more lenient matching mode when searching for delimiters in <sql>

Modified:
    ant/core/trunk/WHATSNEW
    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/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=675954&r1=675953&r2=675954&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Jul 11 06:58:38 2008
@@ -137,6 +137,12 @@
    database.
    Bugzilla Report 36712.
 
+ * A new attribute strictDelimiterMatching can be used to ignore case
+   or whitespace differences when <sql> searches for delimiters.
+   This is useful if you execute a SQL script that has contains "GO"
+   and "go" as delimiters.
+   Bugzilla Report 26459.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

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=675954&r1=675953&r2=675954&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:58:38
2008
@@ -853,12 +853,11 @@
 
     public int lastDelimiterPosition(StringBuffer buf, String currentLine) {
         if (strictDelimiterMatching) {
-            if (delimiterType.equals(DelimiterType.NORMAL)
-                && StringUtils.endsWith(buf, delimiter)) {
+            if ((delimiterType.equals(DelimiterType.NORMAL)
+                 && StringUtils.endsWith(buf, delimiter)) ||
+                (delimiterType.equals(DelimiterType.ROW)
+                 && currentLine.equals(delimiter))) {
                 return buf.length() - delimiter.length();
-            } else if (delimiterType.equals(DelimiterType.ROW)
-                       && currentLine.equals(delimiter)) {
-                return 0;
             }
             // no match
             return -1;
@@ -877,17 +876,18 @@
                     return -1;
                 }
                 while (endIndex >= 0) {
-                    if (buf.substring(bufferIndex, 1).toLowerCase(Locale.US)
-                        .charAt(0) != d.charAt(endIndex)) {
+                    if (buf.substring(bufferIndex, bufferIndex + 1)
+                        .toLowerCase(Locale.US).charAt(0)
+                        != d.charAt(endIndex)) {
                         return -1;
                     }
                     bufferIndex--;
                     endIndex--;
                 }
-                return bufferIndex;
+                return bufferIndex + 1;
             } else {
                 return currentLine.trim().toLowerCase(Locale.US).equals(d)
-                    ? 0 : -1;
+                    ? buf.length() - currentLine.length() : -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=675954&r1=675953&r2=675954&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:58:38 2008
@@ -252,4 +252,57 @@
         assertEquals(0,
                      s.lastDelimiterPosition(new StringBuffer("GO"), null));
     }
+
+    public void testLastDelimiterPositionNormalModeNonStrict() {
+        SQLExec s = new SQLExec();
+        s.setStrictDelimiterMatching(false);
+        assertEquals(-1,
+                     s.lastDelimiterPosition(new StringBuffer(), null));
+        assertEquals(-1,
+                     s.lastDelimiterPosition(new StringBuffer("GO"), null));
+        assertEquals(0,
+                     s.lastDelimiterPosition(new StringBuffer("; "), null));
+        assertEquals(2,
+                     s.lastDelimiterPosition(new StringBuffer("ab;"), null));
+        s.setDelimiter("GO");
+        assertEquals(0,
+                     s.lastDelimiterPosition(new StringBuffer("GO "), null));
+        assertEquals(0,
+                     s.lastDelimiterPosition(new StringBuffer("go"), null));
+        assertEquals(0,
+                     s.lastDelimiterPosition(new StringBuffer("GO"), null));
+    }
+
+    public void testLastDelimiterPositionRowModeStrict() {
+        SQLExec s = new SQLExec();
+        SQLExec.DelimiterType t = new SQLExec.DelimiterType();
+        t.setValue("row");
+        s.setDelimiterType(t);
+        assertEquals(-1, s.lastDelimiterPosition(null, ""));
+        assertEquals(-1, s.lastDelimiterPosition(null, "GO"));
+        assertEquals(-1, s.lastDelimiterPosition(null, "; "));
+        assertEquals(1, s.lastDelimiterPosition(new StringBuffer("ab"), ";"));
+        s.setDelimiter("GO");
+        assertEquals(-1, s.lastDelimiterPosition(null, "GO "));
+        assertEquals(-1, s.lastDelimiterPosition(null, "go"));
+        assertEquals(0, s.lastDelimiterPosition(new StringBuffer("ab"), "GO"));
+    }
+
+    public void testLastDelimiterPositionRowModeNonStrict() {
+        SQLExec s = new SQLExec();
+        SQLExec.DelimiterType t = new SQLExec.DelimiterType();
+        t.setValue("row");
+        s.setDelimiterType(t);
+        s.setStrictDelimiterMatching(false);
+        assertEquals(-1, s.lastDelimiterPosition(null, ""));
+        assertEquals(-1, s.lastDelimiterPosition(null, "GO"));
+        assertEquals(0, s.lastDelimiterPosition(new StringBuffer("; "), "; "));
+        assertEquals(1, s.lastDelimiterPosition(new StringBuffer("ab"), ";"));
+        s.setDelimiter("GO");
+        assertEquals(1,
+                     s.lastDelimiterPosition(new StringBuffer("abcd"), "GO "));
+        assertEquals(0, s.lastDelimiterPosition(new StringBuffer("go"), "go"));
+        assertEquals(0, s.lastDelimiterPosition(new StringBuffer("ab"), "GO"));
+    }
+
 }



Mime
View raw message