1 package net.sourceforge.phpdt.sql.actions;
3 import java.util.Vector;
5 import net.sourceforge.phpdt.sql.IConstants;
6 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
7 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
8 import net.sourceforge.phpdt.sql.sql.SQLParser;
9 import net.sourceforge.phpdt.sql.sql.SQLResults;
10 import net.sourceforge.phpdt.sql.view.QueryHistoryView;
11 import net.sourceforge.phpdt.sql.view.SQLQueryView;
12 import net.sourceforge.phpdt.sql.view.TableView;
13 import net.sourceforge.phpdt.sql.view.tableview.DefaultSizes;
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.swt.graphics.Image;
19 import org.eclipse.ui.IViewActionDelegate;
20 import org.eclipse.ui.IViewPart;
22 public class ExecuteAction
24 implements IViewActionDelegate, IConstants {
27 String execute1 = "Executing Query...";
28 String execute2 = "Executing Query..";
29 public void init(IViewPart view) {
30 this.view = (SQLQueryView) view;
33 public void run(IAction action) {
38 view.setStatus(execute1);
39 MultiSQLServer server = MultiSQLServer.getInstance();
40 view.setStatus("Parsing sql script...");
41 Vector queries = new Vector();
42 String viewQuery = view.getQuery();
43 queries = SQLParser.parse(viewQuery);
44 for (int i = 0; i < queries.size(); i++) {
45 String query = (String) queries.elementAt(i);
47 System.out.println(query);
51 int resultUpdateCount = 0;
53 int resultsDisplayed = 0;
54 for (int i = 0; i < queries.size(); i++) {
56 view.setStatus(execute1);
58 view.setStatus(execute2);
60 String query = (String) queries.elementAt(i);
62 System.out.println(">" + query + "<");
64 if (!query.equals("")) {
69 DefaultSizes.PAGE_SIZE,
70 DefaultSizes.MAX_COLUMN_SIZE);
72 if (results.isResultSet()) {
73 TableView.getInstance().loadQuery(results);
76 int count = results.getUpdateCount();
78 resultUpdateCount += results.getUpdateCount();
81 if (results.isError()) {
86 view.setProgress(i + 1, queries.size());
89 Image error = PHPEclipseSQLPlugin.getImage("stop.gif");
94 + " queries executed, "
98 + " results displayed, "
102 Image success = PHPEclipseSQLPlugin.getImage("success.gif");
107 + " queries executed, "
111 + " results displayed, "
115 view.setProgress(0, 1);
116 QueryHistoryView history = QueryHistoryView.getInstance();
117 history.addQuery(viewQuery);
120 public void selectionChanged(IAction action, ISelection selection) {