1 package net.sourceforge.phpdt.sql.actions;
3 import java.sql.Connection;
4 import java.util.Vector;
6 import org.eclipse.jface.action.Action;
7 import org.eclipse.jface.action.IAction;
8 import org.eclipse.jface.viewers.ISelection;
9 import org.eclipse.swt.graphics.Image;
10 import org.eclipse.ui.IViewActionDelegate;
11 import org.eclipse.ui.IViewPart;
13 import net.sourceforge.phpdt.sql.Messages;
14 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
15 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
16 import net.sourceforge.phpdt.sql.sql.SQLParser;
17 import net.sourceforge.phpdt.sql.sql.SQLResults;
18 import net.sourceforge.phpdt.sql.view.BookmarkView;
19 import net.sourceforge.phpdt.sql.view.QueryHistoryView;
20 import net.sourceforge.phpdt.sql.view.SQLQueryView;
21 import net.sourceforge.phpdt.sql.view.TableView;
22 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
23 import net.sourceforge.phpdt.sql.view.tableview.DefaultSizes;
28 * Executes a query from the QueryView
30 public class ExecuteAction extends Action implements IViewActionDelegate {
33 String execute1 = Messages.getString("ExecuteAction.Executing_Query3"); //$NON-NLS-1$
34 String execute2 = Messages.getString("ExecuteAction.Executing_Query2"); //$NON-NLS-1$
35 public void init(IViewPart view) {
36 this.view = (SQLQueryView) view;
39 public void run(IAction action) {
44 view.setStatus(execute1);
45 MultiSQLServer server = MultiSQLServer.getInstance();
46 view.setStatus(Messages.getString("ExecuteAction.Parsing_sql_script3")); //$NON-NLS-1$
47 Vector queries = new Vector();
48 String viewQuery = view.getQuery();
49 queries = SQLParser.parse(viewQuery);
50 for (int i = 0; i < queries.size(); i++) {
51 String query = (String) queries.elementAt(i);
52 System.out.println(query);
55 int resultUpdateCount = 0;
57 int resultsDisplayed = 0;
58 for (int i = 0; i < queries.size(); i++) {
60 view.setStatus(execute1);
62 view.setStatus(execute2);
64 BookmarkNode current = BookmarkView.getInstance().getCurrentBookmark();
65 Connection con = current.getConnection();
67 String query = (String) queries.elementAt(i);
68 System.out.println(">" + query + "<"); //$NON-NLS-1$ //$NON-NLS-2$
69 if (con != null && !query.equals("")) { //$NON-NLS-1$
70 SQLResults results = server.execute(con, query, 1, DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE);
72 if (results.isResultSet()) {
73 PHPEclipseSQLPlugin phpesqlPluginInstance = PHPEclipseSQLPlugin.getDefault();
74 phpesqlPluginInstance.showView("net.sourceforge.phpdt.sql.view.tableview"); //$NON-NLS-1$
75 TableView.getInstance().loadQuery(current, results);
78 int count = results.getUpdateCount();
80 resultUpdateCount += results.getUpdateCount();
83 if (results.isError()) {
88 view.setProgress(i + 1, queries.size());
90 Image statImage = PHPEclipseSQLPlugin.getImage((errorCount > 0) ? "stop.gif" : "success.gif"); //$NON-NLS-1$ //$NON-NLS-2$
91 view.setStatus(statImage, Messages.getString("ExecuteAction.Done") + "(" + //$NON-NLS-1$ //$NON-NLS-2$
92 resultCount + Messages.getString("ExecuteAction.QueriesExecuted") + //$NON-NLS-1$
93 resultUpdateCount + Messages.getString("ExecuteAction.RowsUpdated") + //$NON-NLS-1$
94 resultsDisplayed + Messages.getString("ExecuteAction.ResultsDisplayed") + //$NON-NLS-1$
95 errorCount + Messages.getString("ExecuteAction.Errors") + ")"); //$NON-NLS-1$ //$NON-NLS-2$
96 view.setProgress(0, 1);
97 QueryHistoryView history = QueryHistoryView.getInstance();
98 if (history != null) history.addQuery(viewQuery);
101 public void selectionChanged(IAction action, ISelection selection) {