package net.sourceforge.phpdt.sql.actions;
+import java.sql.Connection;
import java.util.Vector;
-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.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
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.BookmarkView;
import net.sourceforge.phpdt.sql.view.QueryHistoryView;
import net.sourceforge.phpdt.sql.view.SQLQueryView;
import net.sourceforge.phpdt.sql.view.TableView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
import net.sourceforge.phpdt.sql.view.tableview.DefaultSizes;
+/**
+ * @author panic
+ *
+ * Executes a query from the QueryView
+ */
public class ExecuteAction extends Action implements IViewActionDelegate {
SQLQueryView view;
boolean flag = false;
- String execute1 = "Executing Query...";
- String execute2 = "Executing Query..";
+ String execute1 = Messages.getString("ExecuteAction.Executing_Query3"); //$NON-NLS-1$
+ String execute2 = Messages.getString("ExecuteAction.Executing_Query2"); //$NON-NLS-1$
public void init(IViewPart view) {
this.view = (SQLQueryView) view;
}
public void run() {
view.setStatus(execute1);
MultiSQLServer server = MultiSQLServer.getInstance();
- view.setStatus("Parsing sql script...");
+ view.setStatus(Messages.getString("ExecuteAction.Parsing_sql_script3")); //$NON-NLS-1$
Vector queries = new Vector();
String viewQuery = view.getQuery();
queries = SQLParser.parse(viewQuery);
} else {
view.setStatus(execute2);
}
+ BookmarkNode current = BookmarkView.getInstance().getCurrentBookmark();
+ Connection con = current.getConnection();
+
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);
+ System.out.println(">" + query + "<"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (con != null && !query.equals("")) { //$NON-NLS-1$
+ SQLResults results = server.execute(con, query, 1, DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE);
resultCount++;
if (results.isResultSet()) {
- TableView.getInstance().loadQuery(results);
+ PHPEclipseSQLPlugin phpesqlPluginInstance = PHPEclipseSQLPlugin.getDefault();
+ phpesqlPluginInstance.showView("net.sourceforge.phpdt.sql.view.tableview"); //$NON-NLS-1$
+ TableView.getInstance().loadQuery(current, results);
resultsDisplayed++;
} else {
int count = results.getUpdateCount();
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)");
- }
+ Image statImage = PHPEclipseSQLPlugin.getImage((errorCount > 0) ? "stop.gif" : "success.gif"); //$NON-NLS-1$ //$NON-NLS-2$
+ view.setStatus(statImage, Messages.getString("ExecuteAction.Done") + "(" + //$NON-NLS-1$ //$NON-NLS-2$
+ resultCount + Messages.getString("ExecuteAction.QueriesExecuted") + //$NON-NLS-1$
+ resultUpdateCount + Messages.getString("ExecuteAction.RowsUpdated") + //$NON-NLS-1$
+ resultsDisplayed + Messages.getString("ExecuteAction.ResultsDisplayed") + //$NON-NLS-1$
+ errorCount + Messages.getString("ExecuteAction.Errors") + ")"); //$NON-NLS-1$ //$NON-NLS-2$
view.setProgress(0, 1);
QueryHistoryView history = QueryHistoryView.getInstance();
- history.addQuery(viewQuery);
+ if (history != null) history.addQuery(viewQuery);
}
public void selectionChanged(IAction action, ISelection selection) {