1 package net.sourceforge.phpdt.sql.actions;
3 import java.util.Vector;
5 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
7 import org.eclipse.jface.action.Action;
8 import org.eclipse.jface.action.IAction;
9 import org.eclipse.jface.viewers.ISelection;
10 import org.eclipse.swt.graphics.Image;
11 import org.eclipse.ui.IViewActionDelegate;
12 import org.eclipse.ui.IViewPart;
14 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
15 import net.sourceforge.phpdt.sql.sql.SQLParser;
16 import net.sourceforge.phpdt.sql.sql.SQLResults;
17 import net.sourceforge.phpdt.sql.view.QueryHistoryView;
18 import net.sourceforge.phpdt.sql.view.SQLQueryView;
19 import net.sourceforge.phpdt.sql.view.TableView;
20 import net.sourceforge.phpdt.sql.view.tableview.DefaultSizes;
22 public class ExecuteAction extends Action implements IViewActionDelegate {
25 String execute1 = "Executing Query...";
26 String execute2 = "Executing Query..";
27 public void init(IViewPart view) {
28 this.view = (SQLQueryView) view;
31 public void run(IAction action) {
36 view.setStatus(execute1);
37 MultiSQLServer server = MultiSQLServer.getInstance();
38 view.setStatus("Parsing sql script...");
39 Vector queries = new Vector();
40 String viewQuery = view.getQuery();
41 queries = SQLParser.parse(viewQuery);
42 for (int i = 0; i < queries.size(); i++) {
43 String query = (String) queries.elementAt(i);
44 System.out.println(query);
47 int resultUpdateCount = 0;
49 int resultsDisplayed = 0;
50 for (int i = 0; i < queries.size(); i++) {
52 view.setStatus(execute1);
54 view.setStatus(execute2);
56 String query = (String) queries.elementAt(i);
57 System.out.println(">" + query + "<");
58 if (!query.equals("")) {
59 SQLResults results = server.execute(query, 1, DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE);
61 if (results.isResultSet()) {
62 TableView.getInstance().loadQuery(results);
65 int count = results.getUpdateCount();
67 resultUpdateCount += results.getUpdateCount();
70 if (results.isError()) {
75 view.setProgress(i + 1, queries.size());
78 Image error = PHPEclipseSQLPlugin.getImage("stop.gif");
79 view.setStatus(error, "Done (" + resultCount + " queries executed, " + resultUpdateCount + " rows updated, " + resultsDisplayed + " results displayed, " + errorCount + " errors)");
81 Image success = PHPEclipseSQLPlugin.getImage("success.gif");
82 view.setStatus(success, "Done (" + resultCount + " queries executed, " + resultUpdateCount + " rows updated, " + resultsDisplayed + " results displayed, " + errorCount + " errors)");
84 view.setProgress(0, 1);
85 QueryHistoryView history = QueryHistoryView.getInstance();
86 history.addQuery(viewQuery);
89 public void selectionChanged(IAction action, ISelection selection) {