diff --git a/plugins/org.jkiss.dbeaver.core/plugin.properties b/plugins/org.jkiss.dbeaver.core/plugin.properties
index eaa20066ceadc402c9fe704bbc03b8df954a1576..d5f7f5c5d9abe9f5890459eb7332ac8d5ec1a1d2 100644
--- a/plugins/org.jkiss.dbeaver.core/plugin.properties
+++ b/plugins/org.jkiss.dbeaver.core/plugin.properties
@@ -97,6 +97,8 @@ command.org.jkiss.dbeaver.ui.editors.sql.run.script.name=Execute SQL Script
command.org.jkiss.dbeaver.ui.editors.sql.run.script.description=Execute script
command.org.jkiss.dbeaver.ui.editors.sql.run.scriptNew.name=Execute Script In Separate Tabs
command.org.jkiss.dbeaver.ui.editors.sql.run.scriptNew.description=Execute script's statements in separate results tabs
+command.org.jkiss.dbeaver.ui.editors.sql.run.count.name=Select row count for query
+command.org.jkiss.dbeaver.ui.editors.sql.run.count.description=Select row count for query under cursor
command.org.jkiss.dbeaver.ui.editors.sql.run.explain.name=Explain Execution Plan
command.org.jkiss.dbeaver.ui.editors.sql.run.explain.description=Explain execution plan
command.org.jkiss.dbeaver.ui.editors.sql.run.validate.name=Validate Query
diff --git a/plugins/org.jkiss.dbeaver.core/plugin.xml b/plugins/org.jkiss.dbeaver.core/plugin.xml
index bdc95af0fc9510d13913e26fb1d6ab1b72d2889a..79c8a285bf58ae1ebcf25735ae9f3b02fbb5514d 100644
--- a/plugins/org.jkiss.dbeaver.core/plugin.xml
+++ b/plugins/org.jkiss.dbeaver.core/plugin.xml
@@ -203,6 +203,7 @@
+
@@ -772,6 +773,15 @@
+
+
+
+
+
+
+
+
+
@@ -1516,6 +1526,13 @@
+
+
+
+
+
+
+
@@ -1576,6 +1593,7 @@
+
@@ -1649,6 +1667,11 @@
contextId="org.jkiss.dbeaver.ui.editors.sql"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="CTRL+ALT+X"/>
+
statementInfos;
+ List queries;
ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
if (selection.getLength() > 1) {
- statementInfos = extractScriptQueries(selection.getOffset(), selection.getLength());
+ queries = extractScriptQueries(selection.getOffset(), selection.getLength());
} else {
- statementInfos = extractScriptQueries(0, document.getLength());
+ queries = extractScriptQueries(0, document.getLength());
+ }
+ if (transformer != null) {
+ for (SQLQuery query : queries) {
+ transformer.transformQuery(query);
+ }
}
- processQueries(statementInfos, newTab, false);
+ processQueries(queries, newTab, false);
} else {
// Execute statement under cursor or selected text (if selection present)
SQLQuery sqlQuery = extractActiveQuery();
if (sqlQuery == null) {
setStatus(CoreMessages.editors_sql_status_empty_query_string, true);
} else {
+ if (transformer != null) {
+ transformer.transformQuery(sqlQuery);
+ }
+
processQueries(Collections.singletonList(sqlQuery), newTab, false);
}
}
diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/handlers/ExecuteStatementCountHandler.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/handlers/ExecuteStatementCountHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..ae47ac43b89f7e5b996d7ebe97d04eb814824b1c
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/handlers/ExecuteStatementCountHandler.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2010-2014 Serge Rieder
+ * serge@jkiss.org
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.jkiss.dbeaver.ui.editors.sql.handlers;
+
+import net.sf.jsqlparser.expression.Expression;
+import net.sf.jsqlparser.expression.Function;
+import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
+import net.sf.jsqlparser.parser.CCJSqlParserUtil;
+import net.sf.jsqlparser.schema.Column;
+import net.sf.jsqlparser.statement.Statement;
+import net.sf.jsqlparser.statement.select.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.jkiss.dbeaver.DBException;
+import org.jkiss.dbeaver.model.sql.SQLQuery;
+import org.jkiss.dbeaver.model.sql.SQLQueryTransformer;
+import org.jkiss.dbeaver.runtime.RuntimeUtils;
+import org.jkiss.dbeaver.ui.editors.sql.SQLEditor;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class ExecuteStatementCountHandler extends AbstractHandler implements SQLQueryTransformer {
+
+ static final Log log = LogFactory.getLog(ExecuteStatementCountHandler.class);
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActiveEditor(event), SQLEditor.class);
+ if (editor != null) {
+ editor.processSQL(false, false, this);
+ }
+ return null;
+ }
+
+ @Override
+ public void transformQuery(SQLQuery query) {
+ try {
+ Statement statement = CCJSqlParserUtil.parse(query.getQuery());
+ if (statement instanceof Select && ((Select) statement).getSelectBody() instanceof PlainSelect) {
+ PlainSelect select = (PlainSelect) ((Select) statement).getSelectBody();
+ List selectItems = new ArrayList();
+ Function countFunc = new Function();
+ countFunc.setName("count");
+ countFunc.setParameters(new ExpressionList(Collections.singletonList(new Column("*"))));
+ SelectItem countItem = new SelectExpressionItem(countFunc);
+ selectItems.add(countItem);
+ select.setSelectItems(selectItems);
+ query.setQuery(select.toString());
+ } else {
+ throw new DBException("Query [" + query.getQuery() + "] can't be modified");
+ }
+ } catch (Exception e) {
+ log.error(e);
+ }
+
+ System.out.println(query);
+ }
+
+}
\ No newline at end of file