[hg] main-silver: #222617: The '#' character used for temporary ...

  • From: Jaroslav Havlin < >
  • To:
  • Subject: [hg] main-silver: #222617: The '#' character used for temporary ...
  • Date: Fri, 23 Nov 2012 16:01:57 -0800

changeset aeec33367fb4 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/aeec33367fb4
description:
        #222617: The '#' character used for temporary tables creates an error 
for MS SQL Server

diffstat:

 db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java        
       |  25 +++++++--
 
db.core/test/unit/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelperTest.java
 |  12 ++++-
 2 files changed, 29 insertions(+), 8 deletions(-)

diffs (109 lines):

diff --git 
a/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java 
b/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java
--- a/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java
+++ b/db.core/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelper.java
@@ -91,7 +91,8 @@
         
         boolean cancelled = false;
         
-        List<StatementInfo> statements = getStatements(sqlScript, 
startOffset, endOffset);
+        List<StatementInfo> statements = getStatements(sqlScript, 
startOffset, endOffset,
+                conn.getDriverClass().contains("mysql"));               
//NOI18N
         
         List<SQLExecutionResult> results = new 
ArrayList<SQLExecutionResult>();
         long totalExecutionTime = 0;
@@ -159,10 +160,11 @@
         }
     }
     
-    private static List<StatementInfo> getStatements(String script, int 
startOffset, int endOffset) {
+    private static List<StatementInfo> getStatements(String script, int 
startOffset, int endOffset,
+            boolean useHashComments) {
         if ((startOffset == 0 && endOffset == script.length()) || 
(startOffset == endOffset)) {
             // Either the whole script, or the statement at offset 
startOffset.
-            List<StatementInfo> allStatements = split(script);
+            List<StatementInfo> allStatements = split(script, 
useHashComments);
             if (startOffset == 0 && endOffset == script.length()) {
                 return allStatements;
             }
@@ -175,12 +177,17 @@
             return Collections.emptyList();
         } else {
             // Just execute the selected subscript.
-            return split(script.substring(startOffset, endOffset));
+            return split(script.substring(startOffset, endOffset), 
useHashComments);
         }
     }
         
     public static List<StatementInfo> split(String script) {
-        return new SQLSplitter(script).getStatements();
+        return split(script, true);
+    }
+    
+    static List<StatementInfo> split(String script,
+            boolean useHashComments) {
+        return new SQLSplitter(script, useHashComments).getStatements();
     }
     
     private static final class SQLSplitter {
@@ -195,6 +202,7 @@
         
         private String sql;
         private int sqlLength;
+        private boolean useHashComments;
         
         private StringBuffer statement = new StringBuffer();
         private List<StatementInfo> statements = new 
ArrayList<StatementInfo>();
@@ -219,11 +227,14 @@
         /**
          * @param sql the SQL string to parse. If it contains multiple lines
          * they have to be delimited by '\n' characters.
+         * @param useHashComments True if hash symbol (#) should be used as
+         * start of line comment (MySQL supports it).
          */
-        public SQLSplitter(String sql) {
+        public SQLSplitter(String sql, boolean useHashComments) {
             assert sql != null;
             this.sql = sql;
             sqlLength = sql.length();
+            this.useHashComments = useHashComments;
             parse();
         }
 
@@ -256,7 +267,7 @@
                             state = STATE_MAYBE_LINE_COMMENT;
                         } else if (ch == '/') {
                             state = STATE_MAYBE_BLOCK_COMMENT;
-                        } else if (ch == '#') {
+                        } else if (ch == '#' && useHashComments) {
                             if (statement.length() == 0 || 
!Character.isLetterOrDigit(statement.charAt(statement.length() - 1))) {
                                 state = STATE_LINE_COMMENT;
                             }
diff --git 
a/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelperTest.java
 
b/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelperTest.java
--- 
a/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelperTest.java
+++ 
b/db.core/test/unit/src/org/netbeans/modules/db/sql/execute/SQLExecuteHelperTest.java
@@ -67,6 +67,10 @@
         assertSplit("select ##line\n from dual", "select \n from dual");
         assertSplit("select #line from dual", "select");
         assertSplit("# This should be ignored \nselect from dual", "select 
from dual");
+        assertSplit("select #line\n from dual", false, "select #line\n from 
dual");
+        assertSplit("select ##line\n from dual", false, "select ##line\n 
from dual");
+        assertSplit("select #line from dual", false, "select #line from 
dual");
+        assertSplit("# This should not valid", false, "# This should not 
valid");
 
         // removing block comments
         assertSplit("select /* block */ from dual", "select  from dual");
@@ -136,7 +140,13 @@
     }
     
     private static void assertSplit(String script, String... expected) {
-        List<StatementInfo> stmts = SQLExecuteHelper.split(script);
+        assertSplit(script, true, expected);
+    }
+
+    private static void assertSplit(String script, boolean useHashComments,
+            String... expected) {
+        List<StatementInfo> stmts = SQLExecuteHelper.split(script,
+                useHashComments);
         assertEquals(expected.length, stmts.size());
         for (int i = 0; i < expected.length; i++) {
             assertEquals(expected[i], stmts.get(i).getSQL());

[hg] main-silver: #222617: The '#' character used for temporary ...

Jaroslav Havlin 11/24/2012

Project Features

About this Project

DB was started in November 2009, is owned by Antonin Nebuzelsky, and has 113 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close