import java.util.Vector;
+import net.sourceforge.phpdt.sql.IConstants;
import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.IViewActionDelegate;
-import org.eclipse.ui.IViewPart;
-
import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
import net.sourceforge.phpdt.sql.sql.SQLParser;
import net.sourceforge.phpdt.sql.sql.SQLResults;
import net.sourceforge.phpdt.sql.view.TableView;
import net.sourceforge.phpdt.sql.view.tableview.DefaultSizes;
-public class ExecuteAction extends Action implements IViewActionDelegate {
- SQLQueryView view;
- boolean flag = false;
- String execute1 = "Executing Query...";
- String execute2 = "Executing Query..";
- public void init(IViewPart view) {
- this.view = (SQLQueryView) view;
- }
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+public class ExecuteAction
+ extends Action
+ implements IViewActionDelegate, IConstants {
+ SQLQueryView view;
+ boolean flag = false;
+ String execute1 = "Executing Query...";
+ String execute2 = "Executing Query..";
+ public void init(IViewPart view) {
+ this.view = (SQLQueryView) view;
+ }
- public void run(IAction action) {
- run();
- }
+ public void run(IAction action) {
+ run();
+ }
- public void run() {
- view.setStatus(execute1);
- MultiSQLServer server = MultiSQLServer.getInstance();
- view.setStatus("Parsing sql script...");
- Vector queries = new Vector();
- String viewQuery = view.getQuery();
- queries = SQLParser.parse(viewQuery);
- for (int i = 0; i < queries.size(); i++) {
- String query = (String) queries.elementAt(i);
- System.out.println(query);
- }
- int resultCount = 0;
- int resultUpdateCount = 0;
- int errorCount = 0;
- int resultsDisplayed = 0;
- for (int i = 0; i < queries.size(); i++) {
- if (flag) {
- view.setStatus(execute1);
- } else {
- view.setStatus(execute2);
- }
- String query = (String) queries.elementAt(i);
- System.out.println(">" + query + "<");
- if (!query.equals("")) {
- SQLResults results = server.execute(query, 1, DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE);
- resultCount++;
- if (results.isResultSet()) {
- TableView.getInstance().loadQuery(results);
- resultsDisplayed++;
- } else {
- int count = results.getUpdateCount();
- if (count > 0) {
- resultUpdateCount += results.getUpdateCount();
- }
- }
- if (results.isError()) {
- errorCount++;
- }
- }
- flag = !flag;
- view.setProgress(i + 1, queries.size());
- }
- if (errorCount > 0) {
- Image error = PHPEclipseSQLPlugin.getImage("stop.gif");
- view.setStatus(error, "Done (" + resultCount + " queries executed, " + resultUpdateCount + " rows updated, " + resultsDisplayed + " results displayed, " + errorCount + " errors)");
- } else {
- Image success = PHPEclipseSQLPlugin.getImage("success.gif");
- view.setStatus(success, "Done (" + resultCount + " queries executed, " + resultUpdateCount + " rows updated, " + resultsDisplayed + " results displayed, " + errorCount + " errors)");
- }
- view.setProgress(0, 1);
- QueryHistoryView history = QueryHistoryView.getInstance();
- history.addQuery(viewQuery);
- }
+ public void run() {
+ view.setStatus(execute1);
+ MultiSQLServer server = MultiSQLServer.getInstance();
+ view.setStatus("Parsing sql script...");
+ Vector queries = new Vector();
+ String viewQuery = view.getQuery();
+ queries = SQLParser.parse(viewQuery);
+ for (int i = 0; i < queries.size(); i++) {
+ String query = (String) queries.elementAt(i);
+ if (DEBUG) {
+ System.out.println(query);
+ }
+ }
+ int resultCount = 0;
+ int resultUpdateCount = 0;
+ int errorCount = 0;
+ int resultsDisplayed = 0;
+ for (int i = 0; i < queries.size(); i++) {
+ if (flag) {
+ view.setStatus(execute1);
+ } else {
+ view.setStatus(execute2);
+ }
+ String query = (String) queries.elementAt(i);
+ if (DEBUG) {
+ System.out.println(">" + query + "<");
+ }
+ if (!query.equals("")) {
+ SQLResults results =
+ server.execute(
+ query,
+ 1,
+ DefaultSizes.PAGE_SIZE,
+ DefaultSizes.MAX_COLUMN_SIZE);
+ resultCount++;
+ if (results.isResultSet()) {
+ TableView.getInstance().loadQuery(results);
+ resultsDisplayed++;
+ } else {
+ int count = results.getUpdateCount();
+ if (count > 0) {
+ resultUpdateCount += results.getUpdateCount();
+ }
+ }
+ if (results.isError()) {
+ errorCount++;
+ }
+ }
+ flag = !flag;
+ view.setProgress(i + 1, queries.size());
+ }
+ if (errorCount > 0) {
+ Image error = PHPEclipseSQLPlugin.getImage("stop.gif");
+ view.setStatus(
+ error,
+ "Done ("
+ + resultCount
+ + " queries executed, "
+ + resultUpdateCount
+ + " rows updated, "
+ + resultsDisplayed
+ + " results displayed, "
+ + errorCount
+ + " errors)");
+ } else {
+ Image success = PHPEclipseSQLPlugin.getImage("success.gif");
+ view.setStatus(
+ success,
+ "Done ("
+ + resultCount
+ + " queries executed, "
+ + resultUpdateCount
+ + " rows updated, "
+ + resultsDisplayed
+ + " results displayed, "
+ + errorCount
+ + " errors)");
+ }
+ view.setProgress(0, 1);
+ QueryHistoryView history = QueryHistoryView.getInstance();
+ history.addQuery(viewQuery);
+ }
- public void selectionChanged(IAction action, ISelection selection) {
- }
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
}