changeset 1115:fdb8d3772440

DbUtils.extractStatementType improvements
author Devel 2
date Thu, 21 May 2020 14:10:56 +0200
parents 776dcb7c749e
children f8522f874d0f
files stress-tester/src/main/java/com/passus/st/utils/DbUtils.java stress-tester/src/test/java/com/passus/st/utils/DbUtilsTest.java
diffstat 2 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/utils/DbUtils.java	Thu May 21 12:30:07 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/utils/DbUtils.java	Thu May 21 14:10:56 2020 +0200
@@ -16,10 +16,19 @@
             return -1;
         }
 
+        while (pos < sql.length()) {
+            char ch = sql.charAt(pos);
+            if (AsciiUtils.isWhitespace((byte) ch)) {
+                pos++;
+            } else {
+                break;
+            }
+        }
+
         int startLen = out.length();
         while (pos < sql.length()) {
             char ch = sql.charAt(pos++);
-            if (ch == ' ') {
+            if (AsciiUtils.isWhitespace((byte) ch)) {
                 break;
             } else if (!AsciiUtils.isCharacter(ch)) {
                 out.setLength(startLen);
--- a/stress-tester/src/test/java/com/passus/st/utils/DbUtilsTest.java	Thu May 21 12:30:07 2020 +0200
+++ b/stress-tester/src/test/java/com/passus/st/utils/DbUtilsTest.java	Thu May 21 14:10:56 2020 +0200
@@ -19,6 +19,9 @@
     @Test
     public void testExtractStatementType() {
         assertEquals("SELECT", extractStatementType("SELECT * FROM test"));
+        assertEquals("SELECT", extractStatementType("  SELECT * FROM test"));
+        assertEquals("SELECT", extractStatementType("\nSELECT * FROM test"));
+        assertEquals("SELECT", extractStatementType("SELECT\n * FROM test"));
         assertEquals("select", extractStatementType("select * FROM test"));
         assertEquals("select", extractStatementType("select"));
         assertEquals("select", extractStatementType(" select", 1));