[hg] main-silver: #232075: Total row count incorrect

  • From: Jaroslav Havlin < >
  • To:
  • Subject: [hg] main-silver: #232075: Total row count incorrect
  • Date: Tue, 02 Jul 2013 11:55:05 -0700

changeset 06f0fbe9e4ac in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/06f0fbe9e4ac
description:
        #232075: Total row count incorrect

diffstat:

 
db.dataview/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelper.java
               |  13 ++++++-
 
db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelperTest.java
 |  16 ++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)

diffs (61 lines):

diff --git 
a/db.dataview/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelper.java
 
b/db.dataview/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelper.java
--- 
a/db.dataview/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelper.java
+++ 
b/db.dataview/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelper.java
@@ -59,6 +59,7 @@
 import java.util.concurrent.Future;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import java.util.regex.Pattern;
 import javax.swing.SwingUtilities;
 import org.netbeans.api.db.explorer.DatabaseConnection;
 import org.netbeans.modules.db.dataview.meta.DBColumn;
@@ -88,6 +89,7 @@
     private final RequestProcessor rp = new 
RequestProcessor("SQLStatementExecution", 20, true); // NOI18N
     private static final String LIMIT_CLAUSE = "LIMIT ";               // 
NOI18N
     public static final String OFFSET_CLAUSE = "OFFSET ";              // 
NOI18N
+    private static Pattern GROUP_BY_IN_SELECT = null;
     private boolean limitSupported = false;
     private boolean useScrollableCursors = false;
     private int resultSetScrollType = ResultSet.TYPE_FORWARD_ONLY;
@@ -953,9 +955,14 @@
         return sql.toUpperCase().indexOf(LIMIT_CLAUSE) != -1;
     }
 
-    private boolean isGroupByUsedInSelect(String sql) {
-        return sql.toUpperCase().indexOf(" GROUP BY ") != -1 || 
sql.toUpperCase().indexOf(
-                " COUNT(*) ") != -1; // NOI18N
+    static boolean isGroupByUsedInSelect(String sql) {
+        if (GROUP_BY_IN_SELECT == null) {
+            GROUP_BY_IN_SELECT = Pattern.compile(
+                    "\\Wgroup\\s+by\\W" //NOI18N
+                    + "|\\Wcount\\s*\\(\\s*\\*\\s*\\)", //NOI18N
+                    Pattern.CASE_INSENSITIVE);
+        }
+        return GROUP_BY_IN_SELECT.matcher(sql).find();
     }
 
     void setTotalCount(ResultSet countresultSet, DataViewPageContext 
pageContext) {
diff --git 
a/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelperTest.java
 
b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelperTest.java
--- 
a/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelperTest.java
+++ 
b/db.dataview/test/unit/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelperTest.java
@@ -115,4 +115,20 @@
         instance.initialDataLoad();
         assertNotNull(instance);
     }
+
+    public void testIsGroupByUsedInSelect() {
+        assertGroupByInSelect(true, "SELECT a,b FROM c GROUP BY a");
+        assertGroupByInSelect(true, "SELECT a,b FROM c group by a");
+        assertGroupByInSelect(true, "SELECT count(*) FROM test");
+        assertGroupByInSelect(true, "SELECT COUNT(*) FROM test");
+        assertGroupByInSelect(true, "SELECT a,b FROM c\nGROUP  
BY\na");//#232075
+        assertGroupByInSelect(true, "SELECT\ncount  ( * )\n from test");
+
+        assertGroupByInSelect(false, "SELECT x FROM test;");
+        assertGroupByInSelect(false, "SELECT a as count FROM test;");
 }
+
+    private void assertGroupByInSelect(boolean expected, String sql) {
+        assertEquals(expected, 
SQLExecutionHelper.isGroupByUsedInSelect(sql));
+    }
+}

[hg] main-silver: #232075: Total row count incorrect

Jaroslav Havlin 07/02/2013

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 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close