From: khartlage Date: Mon, 3 Mar 2003 20:07:10 +0000 (+0000) Subject: introduced IConstant.DEBUG flag X-Git-Url: http://git.phpeclipse.com introduced IConstant.DEBUG flag --- diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/IConstants.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/IConstants.java new file mode 100644 index 0000000..5902380 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/IConstants.java @@ -0,0 +1,9 @@ +package net.sourceforge.phpdt.sql; + +/** + * @author khartlage + *. + */ +public interface IConstants { + public boolean DEBUG = false; +} diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/PHPEclipseSQLPlugin.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/PHPEclipseSQLPlugin.java index 5b66482..c5bd07a 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/PHPEclipseSQLPlugin.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/PHPEclipseSQLPlugin.java @@ -26,7 +26,8 @@ import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider; /** * @author */ -public class PHPEclipseSQLPlugin extends AbstractUIPlugin { +public class PHPEclipseSQLPlugin extends AbstractUIPlugin implements IConstants { + private static final String BUNDLE_NAME = "net.sourceforge.phpdt.sql.PHPEclipseSQLResources"; private static final ResourceBundle RESOURCE_BUNDLE = @@ -114,7 +115,7 @@ public class PHPEclipseSQLPlugin extends AbstractUIPlugin { } } -class QuantumSaveParticipant implements ISaveParticipant { +class QuantumSaveParticipant implements ISaveParticipant, IConstants { /** * @see org.eclipse.core.resources.ISaveParticipant#doneSaving(ISaveContext) */ @@ -154,7 +155,9 @@ class QuantumSaveParticipant implements ISaveParticipant { context.map(new Path("save"), new Path(saveFileName)); context.needSaveNumber(); } else { + if (DEBUG) { System.out.println("Not saving unchanged bookmarks"); + } } break; case ISaveContext.PROJECT_SAVE : diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/EditBookmarkAction.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/EditBookmarkAction.java index daab5b6..7d204fe 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/EditBookmarkAction.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/EditBookmarkAction.java @@ -1,5 +1,10 @@ package net.sourceforge.phpdt.sql.actions; +import net.sourceforge.phpdt.sql.IConstants; +import net.sourceforge.phpdt.sql.view.BookmarkView; +import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode; +import net.sourceforge.phpdt.sql.wizards.BookmarkWizard; + import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; @@ -7,10 +12,6 @@ import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.ui.IViewActionDelegate; import org.eclipse.ui.IViewPart; -import net.sourceforge.phpdt.sql.view.BookmarkView; -import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode; -import net.sourceforge.phpdt.sql.wizards.BookmarkWizard; - /** * @author root * @@ -19,7 +20,7 @@ import net.sourceforge.phpdt.sql.wizards.BookmarkWizard; * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ -public class EditBookmarkAction extends Action implements IViewActionDelegate { +public class EditBookmarkAction extends Action implements IViewActionDelegate, IConstants { IViewPart view; /** * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart) @@ -36,7 +37,9 @@ public class EditBookmarkAction extends Action implements IViewActionDelegate { run(); } public void run() { + if (DEBUG) { System.out.println("Wizard.."); + } BookmarkWizard wizard = new BookmarkWizard(); BookmarkNode b = BookmarkView.getInstance().getCurrentBookmark(); diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/ExecuteAction.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/ExecuteAction.java index 9b1b0e2..cac0de1 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/ExecuteAction.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/ExecuteAction.java @@ -2,15 +2,8 @@ package net.sourceforge.phpdt.sql.actions; 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; @@ -19,73 +12,111 @@ import net.sourceforge.phpdt.sql.view.SQLQueryView; 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) { + } } diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/NewBookmarkAction.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/NewBookmarkAction.java index 3f4d936..7eb7294 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/NewBookmarkAction.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/NewBookmarkAction.java @@ -1,5 +1,8 @@ package net.sourceforge.phpdt.sql.actions; +import net.sourceforge.phpdt.sql.IConstants; +import net.sourceforge.phpdt.sql.wizards.BookmarkWizard; + import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; @@ -7,8 +10,6 @@ import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.ui.IViewActionDelegate; import org.eclipse.ui.IViewPart; -import net.sourceforge.phpdt.sql.wizards.BookmarkWizard; - /** * @author root * @@ -17,7 +18,7 @@ import net.sourceforge.phpdt.sql.wizards.BookmarkWizard; * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ -public class NewBookmarkAction extends Action implements IViewActionDelegate { +public class NewBookmarkAction extends Action implements IViewActionDelegate, IConstants { IViewPart view; /** * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart) @@ -34,7 +35,9 @@ public class NewBookmarkAction extends Action implements IViewActionDelegate { run(); } public void run() { + if (DEBUG) { System.out.println("Wizard.."); + } BookmarkWizard wizard = new BookmarkWizard(); wizard.init(); diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/sql/MultiSQLServer.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/sql/MultiSQLServer.java index f67f0f9..1a97c9f 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/sql/MultiSQLServer.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/sql/MultiSQLServer.java @@ -20,488 +20,513 @@ import java.util.Hashtable; import java.util.Properties; import java.util.Vector; +import net.sourceforge.phpdt.sql.IConstants; import net.sourceforge.phpdt.sql.adapters.AdapterFactory; import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter; import net.sourceforge.phpdt.sql.adapters.NoSuchAdapterException; import net.sourceforge.phpdt.sql.bookmarks.Bookmark; +import net.sourceforge.phpdt.sql.view.LogConstants; import net.sourceforge.phpdt.sql.view.LogProxy; -public class MultiSQLServer extends Thread { - private static final int STREAM = 1024 * 2; - public static final String USERNAME = "user"; - public static final String PASSWORD = "password"; - private static MultiSQLServer instance = null; - private Hashtable classLoaderCache = new Hashtable(); - private Connection con = null; - boolean running = true; - private Bookmark current = null; - private MultiSQLServer() { - //start(); - } - public synchronized static MultiSQLServer getInstance() { - if (instance == null) { - instance = new MultiSQLServer(); - } - return instance; - } - public Bookmark getConnected() { - return current; - } - - public void commit() { - LogProxy log = LogProxy.getInstance(); - try { - con.commit(); - } catch (SQLException e) { - log.addText(log.ERROR, "Error commiting: " + e); - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - log.addText( - log.ERROR, - writer.toString()); - } - } - - public void rollback() { - LogProxy log = LogProxy.getInstance(); - try { - con.rollback(); - } catch (SQLException e) { - log.addText(log.ERROR, "Error rolling back: " + e); - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - log.addText( - log.ERROR, - writer.toString()); - } - } +public class MultiSQLServer extends Thread implements IConstants, LogConstants { + private static final int STREAM = 1024 * 2; + public static final String USERNAME = "user"; + public static final String PASSWORD = "password"; + private static MultiSQLServer instance = null; + private Hashtable classLoaderCache = new Hashtable(); + private Connection con = null; + boolean running = true; + private Bookmark current = null; + private MultiSQLServer() { + //start(); + } + public synchronized static MultiSQLServer getInstance() { + if (instance == null) { + instance = new MultiSQLServer(); + } + return instance; + } + + public Bookmark getConnected() { + return current; + } - public void setAutoCommit(boolean enabled) { - LogProxy log = LogProxy.getInstance(); - try { - if (con != null) { - con.setAutoCommit(enabled); - } else { - log.addText(log.ERROR, "Please connect before setting autocommit"); - } - } catch (SQLException e) { - log.addText(log.ERROR, "Error setting autocommit: " + e); - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - log.addText( - log.ERROR, - writer.toString()); - } - } - - public DatabaseAdapter getCurrentAdapter() { - LogProxy log = LogProxy.getInstance(); - try { - AdapterFactory factory = AdapterFactory.getInstance(); - return factory.getAdapter(current.getType()); - } catch (NoSuchAdapterException e) { - log.addText(log.ERROR, "Invalid database type: ->" + current.getType() + "<-"); - } - return null; - } - public void disconnect(Bookmark b) { - current = null; - LogProxy log = LogProxy.getInstance(); + public void commit() { + LogProxy log = LogProxy.getInstance(); + try { + con.commit(); + } catch (SQLException e) { + log.addText(ERROR, "Error commiting: " + e); + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + log.addText(ERROR, writer.toString()); + } + } - try { - con.close(); - con = null; - log.addText(log.RESULTS, "Disconnected from: " + b.getName()); - } catch (Exception e) { - log.addText( - log.ERROR, - "Error Disonnecting to: " + b.getName() + ":" + e.toString()); - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - log.addText( - log.ERROR, - writer.toString()); - - } - } - public void shutdown() { - LogProxy log = LogProxy.getInstance(); - try { - if (con != null) { - con.close(); - } - con = null; - } catch (SQLException e) { - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - log.addText( - log.ERROR, - writer.toString()); - } - } - - public void dumpDatabaseData() { - LogProxy log = LogProxy.getInstance(); - try { - DatabaseMetaData metadata = con.getMetaData(); - log.addText(log.WARNING, "[METADATA] Database type: " + metadata.getDatabaseProductName()); - if (metadata.supportsCatalogsInDataManipulation()) { - log.addText(log.WARNING, "[METADATA] Database does support catalog in data manipulation"); - } else { - log.addText(log.WARNING, "[METADATA] Database does not support catalog in data manipulation"); - } - if (metadata.supportsSchemasInDataManipulation()) { - log.addText(log.WARNING, "[METADATA] Database does support schema in data manipulation"); - } else { - log.addText(log.WARNING, "[METADATA] Database does not support schema in data manipulation"); - } - if (metadata.supportsCatalogsInTableDefinitions()) { - log.addText(log.WARNING, "[METADATA] Database does support catalogs in table definitions"); - } else { - log.addText(log.WARNING, "[METADATA] Database does not support catalogs in table definitions"); - } - log.addText(log.WARNING, "[METADATA] Catalog Separator: " + metadata.getCatalogSeparator()); - log.addText(log.WARNING, "[METADATA] Catalog Term: " + metadata.getCatalogTerm()); - ResultSet set = metadata.getCatalogs(); - ArrayList catalogList = new ArrayList(); - catalogList.add(null); - while (set.next()) { - catalogList.add(set.getString(1)); - } - set.close(); - StringBuffer catalogOutput = new StringBuffer(); - catalogOutput.append("[CATALOG LIST] ["); - for (int i = 0; i < catalogList.size(); i++) { - String name = (String) catalogList.get(i); - catalogOutput.append(name + ", "); - } - catalogOutput.append("]"); - log.addText(log.WARNING, catalogOutput.toString()); - - set = metadata.getSchemas(); - ArrayList schemaList = new ArrayList(); - schemaList.add(""); - while (set.next()) { - schemaList.add(set.getString(1)); - } - set.close(); - StringBuffer schemaOutput = new StringBuffer(); - schemaOutput.append("[SCHEMA LIST] ["); - for (int i = 0; i < schemaList.size(); i++) { - String name = (String) schemaList.get(i); - schemaOutput.append(name + ", "); - } - schemaOutput.append("]"); - log.addText(log.WARNING, schemaOutput.toString()); + public void rollback() { + LogProxy log = LogProxy.getInstance(); + try { + con.rollback(); + } catch (SQLException e) { + log.addText(ERROR, "Error rolling back: " + e); + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + log.addText(ERROR, writer.toString()); + } + } - ArrayList tableTypes = new ArrayList(); - set = metadata.getTableTypes(); - while (set.next()) { - tableTypes.add(set.getString(1)); - } - set.close(); - - StringBuffer tableListOutput = new StringBuffer(); - tableListOutput.append("[TABLE LIST] ["); - for (int i = 0; i < tableTypes.size(); i++) { - String name = (String) tableTypes.get(i); - tableListOutput.append(name + ", "); - } - tableListOutput.append("]"); - log.addText(log.WARNING, tableListOutput.toString()); - - - } catch (Exception e) { - log.addText(log.ERROR, "Error occured: " + e); - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - log.addText( - log.ERROR, - writer.toString()); - } - } - /** - * type = "TABLE" "VIEW" "SEQUENCE" - */ - public Vector listTables(String schema, String type) { - LogProxy log = LogProxy.getInstance(); - Vector retVal = new Vector(); - log.addText(log.QUERY, "Retrieving list [" + type + "]"); - try { - DatabaseMetaData meta = con.getMetaData(); - ResultSet set = meta.getTableTypes(); - int columnCount = set.getMetaData().getColumnCount(); - for (int i = 1; i <= columnCount; i++) { - System.out.print(set.getMetaData().getColumnName(i) + "\t"); - } - System.out.println(); - while (set.next()) { - for (int i = 1; i <= columnCount; i++) { - System.out.print(set.getString(i) + "\t"); - } - System.out.println(); - } - Vector types = new Vector(); - set = meta.getTableTypes(); - while (set.next()) { - types.add(set.getString(1)); - } - set.close(); - if (types.contains(type)) { - set = meta.getTables(null, schema, "%", new String[] {type}); - while (set.next()) { - String name = set.getString("TABLE_NAME"); - String tableType = set.getString("TABLE_TYPE"); - //System.out.println(name + ":" + tableType); - retVal.addElement(name); - } - set.close(); - } - log.addText(log.RESULTS, "Success"); - } catch (SQLException e) { - log.addText(log.ERROR, "Error occured: " + e); - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - log.addText( - log.ERROR, - writer.toString()); - } - return retVal; - } - public boolean connect(Bookmark b) { - LogProxy log = LogProxy.getInstance(); - log.addText(log.QUERY, "Connecting to: " + b.getName()); - URL urls[] = new URL[1]; - try { - String driverFile = b.getDriverFile(); - URLClassLoader loader = (URLClassLoader) classLoaderCache.get(driverFile); - if (loader == null) { - urls[0] = new File(driverFile).toURL(); - loader = new URLClassLoader(urls); - classLoaderCache.put(driverFile, loader); - System.out.println("Creating new classloader"); - } else { - System.out.println("Using classloader in cache"); - } - Class driverClass = loader.loadClass(b.getDriver()); - Driver driver = (Driver) driverClass.newInstance(); - Properties props = new Properties(); - props.put(USERNAME, b.getUsername()); - props.put(PASSWORD, b.getPassword()); - con = driver.connect(b.getConnect(), props); - if (con == null) { - throw new Exception("Error: Driver returned a null connection: " + b.toString()); - } - current = b; - log.addText(log.RESULTS, "Connected to: " + b.getName()); - System.out.println("Connected"); - return true; - } catch (Exception e) { - log.addText( - log.ERROR, - "Error Connecting to: " + b.getName() + ":" + e.toString()); - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - log.addText( - log.ERROR, - writer.toString()); - } - return false; - } - public SQLResults execute(String s) { - return execute(s, -1, -1); - } - public SQLResults execute(String s, int startRow, int endRow) { - return execute(s, -1, -1, Integer.MAX_VALUE); - } - public SQLResults execute(String s, int startRow, int endRow, int maxLength) { - return execute(s, startRow, endRow, maxLength, ""); - } - public SQLResults execute(String s, int startRow, int endRow, int maxLength, String encoding) { - SQLResults results = new SQLResults(); + public void setAutoCommit(boolean enabled) { + LogProxy log = LogProxy.getInstance(); + try { + if (con != null) { + con.setAutoCommit(enabled); + } else { + log.addText(ERROR, "Please connect before setting autocommit"); + } + } catch (SQLException e) { + log.addText(ERROR, "Error setting autocommit: " + e); + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + log.addText(ERROR, writer.toString()); + } + } - System.out.println("Executing"); - LogProxy log = LogProxy.getInstance(); - log.addText(log.QUERY, "Executing Request [" + s + "]"); - boolean metadata = false; - if (s.startsWith("METADATA")) { - metadata = true; - } - if (metadata) { - results.setQuery(s); - String table = s.substring(s.indexOf(':') + 1); - String schema = current.getSchema(); - String query = "SELECT * FROM " + schema + "." + table; - if (schema.equals("")) { - query = "SELECT * FROM " + table; - } - s = query; - log.addText(log.QUERY, "Metadata Request [" + s + "]"); - } else { - results.setQuery(s); - } - try { - Statement stmt = con.createStatement(); - boolean flag = stmt.execute(s); - results.setResultSet(flag); - if (!flag) { - int updates = stmt.getUpdateCount(); - results.setUpdateCount(updates); - log.addText( - log.RESULTS, - "Success: " + updates + " records updated"); + public DatabaseAdapter getCurrentAdapter() { + LogProxy log = LogProxy.getInstance(); + try { + AdapterFactory factory = AdapterFactory.getInstance(); + return factory.getAdapter(current.getType()); + } catch (NoSuchAdapterException e) { + log.addText( + ERROR, + "Invalid database type: ->" + current.getType() + "<-"); + } + return null; + } + public void disconnect(Bookmark b) { + current = null; + LogProxy log = LogProxy.getInstance(); - } else { - if (metadata) { - ResultSet set = stmt.getResultSet(); - ResultSetMetaData metaData = set.getMetaData(); - int columnCount = metaData.getColumnCount(); - Vector columnNames = new Vector(); - columnNames.addElement("ColumnName"); - columnNames.addElement("Type"); - columnNames.addElement("Size"); - columnNames.addElement("Nullable"); - columnNames.addElement("AutoIncrement"); - results.setColumnNames(columnNames); - for (int i = 1; i <= columnCount; i++) { - Vector row = new Vector(); - row.addElement(metaData.getColumnName(i)); - row.addElement(metaData.getColumnTypeName(i)); - int textSize = metaData.getColumnDisplaySize(i); - int precision = metaData.getPrecision(i); - int scale = metaData.getScale(i); - if (scale == 0 && precision == 0) { - row.addElement(Integer.toString(precision)); - } else { - row.addElement(textSize + ", " + precision + ", " + scale); - } - int nullable = metaData.isNullable(i); - if (nullable == metaData.columnNoNulls) { - row.addElement("Not Null"); - } else if (nullable == metaData.columnNullable) { - row.addElement("Nullable"); - } else if (nullable == metaData.columnNullableUnknown) { - row.addElement("Nullable"); - } else { - row.addElement(""); - } - row.addElement(new Boolean(metaData.isAutoIncrement(i)).toString()); - results.addRow(row); - } - results.setHasMore(false); - } else { - ResultSet set = stmt.getResultSet(); - ResultSetMetaData metaData = set.getMetaData(); - int columnCount = metaData.getColumnCount(); - Vector columnNames = new Vector(); - for (int i = 1; i <= columnCount; i++) { - columnNames.addElement(metaData.getColumnName(i)); - } - results.setColumnNames(columnNames); - Vector columnTypes = new Vector(); - for (int i = 1; i <= columnCount; i++) { - columnTypes.addElement(metaData.getColumnTypeName(i)); - } - results.setColumnsTypes(columnTypes); - int columnSizes[] = new int[columnCount]; - for (int i = 1; i <= columnCount; i++) { - columnSizes[i - 1] = metaData.getColumnDisplaySize(i); - } - int rowCount = 1; - boolean exitEarly = false; - while (set.next()) { - boolean disable = startRow < 1 || endRow < 1; - boolean start = rowCount >= startRow; - boolean end = rowCount <= endRow; - if (disable || (start && end)) { - Vector row = new Vector(); - for (int i = 1; i <= columnCount; i++) { - String value; - if (columnSizes[i - 1] < STREAM && columnSizes[i - 1] < maxLength) { - if (encoding.equals("")) { - value = set.getString(i); - } else { - value = new String(set.getBytes(i), encoding); - } - } else { - try { - if (encoding.equals("")) { - Reader reader = set.getCharacterStream(i); - StringBuffer buffer = new StringBuffer(); - if (reader != null) { - int retVal = reader.read(); - int count = 0; - while (retVal >= 0) { - buffer.append((char) retVal); - retVal = reader.read(); - count++; - if (count > maxLength) { - buffer.append("...>>>"); - break; - } - } - reader.close(); - } - value = buffer.toString(); - } else { - InputStream binaryStream = set.getBinaryStream(i); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - if (binaryStream != null) { - int retVal = binaryStream.read(); - int count = 0; - while (retVal >= 0) { - baos.write(retVal); - retVal = binaryStream.read(); - count++; - if (count > maxLength) { - break; - } - } - binaryStream.close(); - } - value = new String(baos.toByteArray(), encoding); - } - } catch (Throwable e) { - // hack for mysql which doesn't implement - // character streams - value = set.getString(i); - } - } - if (set.wasNull()) { - row.addElement(""); - } else { - row.addElement(value); - } - } - results.addRow(row); - } - rowCount++; - if (!disable && (rowCount > endRow)) { - exitEarly = true; - break; - } - } - if (exitEarly) { - results.setHasMore(set.next()); - } else { - results.setMaxSize(rowCount); - results.setHasMore(false); - } - } - log.addText(log.RESULTS, "Success: result set displayed"); - } - stmt.close(); - System.out.println("Executed"); - System.out.println(); - } catch (Exception e) { - results.setIsError(true); - log.addText(log.ERROR, "Error occured: " + e); - StringWriter writer = new StringWriter(); - e.printStackTrace(new PrintWriter(writer)); - log.addText( - log.ERROR, - writer.toString()); - } - return results; - } + try { + con.close(); + con = null; + log.addText(RESULTS, "Disconnected from: " + b.getName()); + } catch (Exception e) { + log.addText( + ERROR, + "Error Disonnecting to: " + b.getName() + ":" + e.toString()); + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + log.addText(ERROR, writer.toString()); + + } + } + public void shutdown() { + LogProxy log = LogProxy.getInstance(); + try { + if (con != null) { + con.close(); + } + con = null; + } catch (SQLException e) { + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + log.addText(ERROR, writer.toString()); + } + } + + public void dumpDatabaseData() { + LogProxy log = LogProxy.getInstance(); + try { + DatabaseMetaData metadata = con.getMetaData(); + log.addText( + WARNING, + "[METADATA] Database type: " + metadata.getDatabaseProductName()); + if (metadata.supportsCatalogsInDataManipulation()) { + log.addText( + WARNING, + "[METADATA] Database does support catalog in data manipulation"); + } else { + log.addText( + WARNING, + "[METADATA] Database does not support catalog in data manipulation"); + } + if (metadata.supportsSchemasInDataManipulation()) { + log.addText( + WARNING, + "[METADATA] Database does support schema in data manipulation"); + } else { + log.addText( + WARNING, + "[METADATA] Database does not support schema in data manipulation"); + } + if (metadata.supportsCatalogsInTableDefinitions()) { + log.addText( + WARNING, + "[METADATA] Database does support catalogs in table definitions"); + } else { + log.addText( + WARNING, + "[METADATA] Database does not support catalogs in table definitions"); + } + log.addText( + WARNING, + "[METADATA] Catalog Separator: " + metadata.getCatalogSeparator()); + log.addText( + WARNING, + "[METADATA] Catalog Term: " + metadata.getCatalogTerm()); + ResultSet set = metadata.getCatalogs(); + ArrayList catalogList = new ArrayList(); + catalogList.add(null); + while (set.next()) { + catalogList.add(set.getString(1)); + } + set.close(); + StringBuffer catalogOutput = new StringBuffer(); + catalogOutput.append("[CATALOG LIST] ["); + for (int i = 0; i < catalogList.size(); i++) { + String name = (String) catalogList.get(i); + catalogOutput.append(name + ", "); + } + catalogOutput.append("]"); + log.addText(WARNING, catalogOutput.toString()); + + set = metadata.getSchemas(); + ArrayList schemaList = new ArrayList(); + schemaList.add(""); + while (set.next()) { + schemaList.add(set.getString(1)); + } + set.close(); + StringBuffer schemaOutput = new StringBuffer(); + schemaOutput.append("[SCHEMA LIST] ["); + for (int i = 0; i < schemaList.size(); i++) { + String name = (String) schemaList.get(i); + schemaOutput.append(name + ", "); + } + schemaOutput.append("]"); + log.addText(WARNING, schemaOutput.toString()); + + ArrayList tableTypes = new ArrayList(); + set = metadata.getTableTypes(); + while (set.next()) { + tableTypes.add(set.getString(1)); + } + set.close(); + + StringBuffer tableListOutput = new StringBuffer(); + tableListOutput.append("[TABLE LIST] ["); + for (int i = 0; i < tableTypes.size(); i++) { + String name = (String) tableTypes.get(i); + tableListOutput.append(name + ", "); + } + tableListOutput.append("]"); + log.addText(WARNING, tableListOutput.toString()); + + } catch (Exception e) { + log.addText(ERROR, "Error occured: " + e); + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + log.addText(ERROR, writer.toString()); + } + } + /** + * type = "TABLE" "VIEW" "SEQUENCE" + */ + public Vector listTables(String schema, String type) { + LogProxy log = LogProxy.getInstance(); + Vector retVal = new Vector(); + log.addText(QUERY, "Retrieving list [" + type + "]"); + try { + DatabaseMetaData meta = con.getMetaData(); + ResultSet set = meta.getTableTypes(); + int columnCount = set.getMetaData().getColumnCount(); + if (DEBUG) { + for (int i = 1; i <= columnCount; i++) { + System.out.print(set.getMetaData().getColumnName(i) + "\t"); + } + System.out.println(); + while (set.next()) { + for (int i = 1; i <= columnCount; i++) { + System.out.print(set.getString(i) + "\t"); + } + System.out.println(); + } + } + Vector types = new Vector(); + set = meta.getTableTypes(); + while (set.next()) { + types.add(set.getString(1)); + } + set.close(); + if (types.contains(type)) { + set = meta.getTables(null, schema, "%", new String[] { type }); + while (set.next()) { + String name = set.getString("TABLE_NAME"); + String tableType = set.getString("TABLE_TYPE"); + //System.out.println(name + ":" + tableType); + retVal.addElement(name); + } + set.close(); + } + log.addText(RESULTS, "Success"); + } catch (SQLException e) { + log.addText(ERROR, "Error occured: " + e); + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + log.addText(ERROR, writer.toString()); + } + return retVal; + } + public boolean connect(Bookmark b) { + LogProxy log = LogProxy.getInstance(); + log.addText(QUERY, "Connecting to: " + b.getName()); + URL urls[] = new URL[1]; + try { + String driverFile = b.getDriverFile(); + URLClassLoader loader = (URLClassLoader) classLoaderCache.get(driverFile); + if (loader == null) { + urls[0] = new File(driverFile).toURL(); + loader = new URLClassLoader(urls); + classLoaderCache.put(driverFile, loader); + if (DEBUG) { + System.out.println("Creating new classloader"); + } + } else { + if (DEBUG) { + System.out.println("Using classloader in cache"); + } + } + Class driverClass = loader.loadClass(b.getDriver()); + Driver driver = (Driver) driverClass.newInstance(); + Properties props = new Properties(); + props.put(USERNAME, b.getUsername()); + props.put(PASSWORD, b.getPassword()); + con = driver.connect(b.getConnect(), props); + if (con == null) { + throw new Exception( + "Error: Driver returned a null connection: " + b.toString()); + } + current = b; + log.addText(RESULTS, "Connected to: " + b.getName()); + if (DEBUG) { + System.out.println("Connected"); + } + return true; + } catch (Exception e) { + log.addText( + ERROR, + "Error Connecting to: " + b.getName() + ":" + e.toString()); + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + log.addText(ERROR, writer.toString()); + } + return false; + } + public SQLResults execute(String s) { + return execute(s, -1, -1); + } + public SQLResults execute(String s, int startRow, int endRow) { + return execute(s, -1, -1, Integer.MAX_VALUE); + } + public SQLResults execute( + String s, + int startRow, + int endRow, + int maxLength) { + return execute(s, startRow, endRow, maxLength, ""); + } + public SQLResults execute( + String s, + int startRow, + int endRow, + int maxLength, + String encoding) { + SQLResults results = new SQLResults(); + + if (DEBUG) { + System.out.println("Executing"); + } + LogProxy log = LogProxy.getInstance(); + log.addText(QUERY, "Executing Request [" + s + "]"); + boolean metadata = false; + if (s.startsWith("METADATA")) { + metadata = true; + } + if (metadata) { + results.setQuery(s); + String table = s.substring(s.indexOf(':') + 1); + String schema = current.getSchema(); + String query = "SELECT * FROM " + schema + "." + table; + if (schema.equals("")) { + query = "SELECT * FROM " + table; + } + s = query; + log.addText(QUERY, "Metadata Request [" + s + "]"); + } else { + results.setQuery(s); + } + try { + Statement stmt = con.createStatement(); + boolean flag = stmt.execute(s); + results.setResultSet(flag); + if (!flag) { + int updates = stmt.getUpdateCount(); + results.setUpdateCount(updates); + log.addText(RESULTS, "Success: " + updates + " records updated"); + + } else { + if (metadata) { + ResultSet set = stmt.getResultSet(); + ResultSetMetaData metaData = set.getMetaData(); + int columnCount = metaData.getColumnCount(); + Vector columnNames = new Vector(); + columnNames.addElement("ColumnName"); + columnNames.addElement("Type"); + columnNames.addElement("Size"); + columnNames.addElement("Nullable"); + columnNames.addElement("AutoIncrement"); + results.setColumnNames(columnNames); + for (int i = 1; i <= columnCount; i++) { + Vector row = new Vector(); + row.addElement(metaData.getColumnName(i)); + row.addElement(metaData.getColumnTypeName(i)); + int textSize = metaData.getColumnDisplaySize(i); + int precision = metaData.getPrecision(i); + int scale = metaData.getScale(i); + if (scale == 0 && precision == 0) { + row.addElement(Integer.toString(precision)); + } else { + row.addElement(textSize + ", " + precision + ", " + scale); + } + int nullable = metaData.isNullable(i); + if (nullable == metaData.columnNoNulls) { + row.addElement("Not Null"); + } else if (nullable == metaData.columnNullable) { + row.addElement("Nullable"); + } else if (nullable == metaData.columnNullableUnknown) { + row.addElement("Nullable"); + } else { + row.addElement(""); + } + row.addElement(new Boolean(metaData.isAutoIncrement(i)).toString()); + results.addRow(row); + } + results.setHasMore(false); + } else { + ResultSet set = stmt.getResultSet(); + ResultSetMetaData metaData = set.getMetaData(); + int columnCount = metaData.getColumnCount(); + Vector columnNames = new Vector(); + for (int i = 1; i <= columnCount; i++) { + columnNames.addElement(metaData.getColumnName(i)); + } + results.setColumnNames(columnNames); + Vector columnTypes = new Vector(); + for (int i = 1; i <= columnCount; i++) { + columnTypes.addElement(metaData.getColumnTypeName(i)); + } + results.setColumnsTypes(columnTypes); + int columnSizes[] = new int[columnCount]; + for (int i = 1; i <= columnCount; i++) { + columnSizes[i - 1] = metaData.getColumnDisplaySize(i); + } + int rowCount = 1; + boolean exitEarly = false; + while (set.next()) { + boolean disable = startRow < 1 || endRow < 1; + boolean start = rowCount >= startRow; + boolean end = rowCount <= endRow; + if (disable || (start && end)) { + Vector row = new Vector(); + for (int i = 1; i <= columnCount; i++) { + String value; + if (columnSizes[i - 1] < STREAM + && columnSizes[i - 1] < maxLength) { + if (encoding.equals("")) { + value = set.getString(i); + } else { + value = new String(set.getBytes(i), encoding); + } + } else { + try { + if (encoding.equals("")) { + Reader reader = set.getCharacterStream(i); + StringBuffer buffer = new StringBuffer(); + if (reader != null) { + int retVal = reader.read(); + int count = 0; + while (retVal >= 0) { + buffer.append((char) retVal); + retVal = reader.read(); + count++; + if (count > maxLength) { + buffer.append("...>>>"); + break; + } + } + reader.close(); + } + value = buffer.toString(); + } else { + InputStream binaryStream = set.getBinaryStream(i); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + if (binaryStream != null) { + int retVal = binaryStream.read(); + int count = 0; + while (retVal >= 0) { + baos.write(retVal); + retVal = binaryStream.read(); + count++; + if (count > maxLength) { + break; + } + } + binaryStream.close(); + } + value = new String(baos.toByteArray(), encoding); + } + } catch (Throwable e) { + // hack for mysql which doesn't implement + // character streams + value = set.getString(i); + } + } + if (set.wasNull()) { + row.addElement(""); + } else { + row.addElement(value); + } + } + results.addRow(row); + } + rowCount++; + if (!disable && (rowCount > endRow)) { + exitEarly = true; + break; + } + } + if (exitEarly) { + results.setHasMore(set.next()); + } else { + results.setMaxSize(rowCount); + results.setHasMore(false); + } + } + log.addText(RESULTS, "Success: result set displayed"); + } + stmt.close(); + if (DEBUG) { + System.out.println("Executed"); + System.out.println(); + } + } catch (Exception e) { + results.setIsError(true); + log.addText(ERROR, "Error occured: " + e); + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + log.addText(ERROR, writer.toString()); + } + return results; + } } diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/sql/SQLHelper.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/sql/SQLHelper.java index 1239620..06a6515 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/sql/SQLHelper.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/sql/SQLHelper.java @@ -2,6 +2,7 @@ package net.sourceforge.phpdt.sql.sql; import java.util.Vector; +import net.sourceforge.phpdt.sql.IConstants; import net.sourceforge.phpdt.sql.adapters.AdapterFactory; import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter; import net.sourceforge.phpdt.sql.adapters.DatabaseInfo; @@ -15,122 +16,137 @@ import net.sourceforge.phpdt.sql.view.bookmark.SequenceNode; import net.sourceforge.phpdt.sql.view.bookmark.TableNode; import net.sourceforge.phpdt.sql.view.bookmark.ViewNode; -public class SQLHelper { - MultiSQLServer server = MultiSQLServer.getInstance(); - public Vector getTableList(BookmarkNode current) throws NoSuchAdapterException, FeatureNotSupported { - DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(current.getType()); - Vector children = new Vector(); - DatabaseInfo info = DatabaseInfo.create(current); - if (adapter instanceof GenericAdapter) { - Vector tables = server.listTables(info.getSchema(), "TABLE"); - for (int i = 0; i < tables.size(); i++) { - String tableName = (String) tables.elementAt(i); - TableNode node = new TableNode(current, tableName); - children.addElement(node); - } - } else { - SQLResults results = server.execute(adapter.getShowTableQuery(info)); - String filter = adapter.getTableListFilter(); - int size = results.getRowCount(); - System.out.println("Found " + size + " tables"); - for (int i = 1; i <= size; i++) { - String tableName = results.getElement(1, i).toString(); - if (filter == null || filter.equals("") || tableName.indexOf(filter) < 0) { - TableNode node = new TableNode(current, tableName); - children.addElement(node); - } - } - } - return children; - } - public int getSize(String query) { - SQLResults results = server.execute("SELECT COUNT(*) FROM " + query); - return Integer.parseInt(results.getElement(1, 1).toString()); - } - public Vector getViewList(BookmarkNode current) - throws NoSuchAdapterException, FeatureNotSupported { - DatabaseAdapter adapter = - AdapterFactory.getInstance().getAdapter(current.getType()); - Vector children = new Vector(); - DatabaseInfo info = DatabaseInfo.create(current); - if (adapter instanceof GenericAdapter) { - Vector views = server.listTables(info.getSchema(), "VIEW"); - for (int i = 0; i < views.size(); i++) { - String viewName = (String) views.elementAt(i); - ViewNode node = new ViewNode(current, viewName); - children.addElement(node); - } - } else { - SQLResults results = - server.execute( - adapter.getShowViewQuery(info)); - String filter = adapter.getTableListFilter(); - int size = results.getRowCount(); - for (int i = 1; i <= size; i++) { - String viewName = results.getElement(1, i).toString(); - if (filter == null - || filter.equals("") - || viewName.indexOf(filter) < 0) { - ViewNode node = new ViewNode(current, viewName); - children.addElement(node); - } - } - } - return children; - } - public Vector getSequenceList(BookmarkNode current) throws NoSuchAdapterException, FeatureNotSupported { - DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(current.getType()); - MultiSQLServer server = MultiSQLServer.getInstance(); - Vector children = new Vector(); - if (!(adapter instanceof GenericAdapter)) { - SQLResults results = server.execute(adapter.getShowSequenceQuery(DatabaseInfo.create(current))); - String filter = adapter.getTableListFilter(); - int size = results.getRowCount(); - for (int i = 1; i <= size; i++) { - String seqName = results.getElement(1, i).toString(); - if (filter == null || filter.equals("") || seqName.indexOf(filter) < 0) { - SequenceNode node = new SequenceNode(current, seqName); - children.addElement(node); - } - } - } - return children; - } - public Vector getMetaData(TableNode parent, String entity) { - Vector columns = new Vector(); - String query = "SELECT * FROM " + entity; - SQLResults results = server.execute(query); - for (int i = 1; i <= results.getColumnCount(); i++) { - String name = results.getColumnName(i); - String type = results.getColumnType(i); - MetaDataNode node = new MetaDataNode(parent, name, type); - columns.addElement(node); - } - return columns; - } - public Vector getMetaData(ViewNode parent, String entity) { - Vector columns = new Vector(); - String query = "SELECT * FROM " + entity; - SQLResults results = server.execute(query); - for (int i = 1; i <= results.getColumnCount(); i++) { - String name = results.getColumnName(i); - String type = results.getColumnType(i); - MetaDataNode node = new MetaDataNode(parent, name, type); - columns.addElement(node); - } - return columns; - } - public SQLResults getResults(String query, int start, int end) { - return server.execute(query, start, end); - } - public SQLResults getResults(String query, int start, int end, int maxLength, String encoding) { - return server.execute(query, start, end, maxLength, encoding); - } - public static String getFullTableName(Bookmark current, String table) { - String schema = current.getSchema(); - if (schema == null || schema.equals("")) { - return table; - } - return schema + "." + table; - } +public class SQLHelper implements IConstants { + MultiSQLServer server = MultiSQLServer.getInstance(); + public Vector getTableList(BookmarkNode current) + throws NoSuchAdapterException, FeatureNotSupported { + DatabaseAdapter adapter = + AdapterFactory.getInstance().getAdapter(current.getType()); + Vector children = new Vector(); + DatabaseInfo info = DatabaseInfo.create(current); + if (adapter instanceof GenericAdapter) { + Vector tables = server.listTables(info.getSchema(), "TABLE"); + for (int i = 0; i < tables.size(); i++) { + String tableName = (String) tables.elementAt(i); + TableNode node = new TableNode(current, tableName); + children.addElement(node); + } + } else { + SQLResults results = server.execute(adapter.getShowTableQuery(info)); + String filter = adapter.getTableListFilter(); + int size = results.getRowCount(); + if (DEBUG) { + System.out.println("Found " + size + " tables"); + } + for (int i = 1; i <= size; i++) { + String tableName = results.getElement(1, i).toString(); + if (filter == null + || filter.equals("") + || tableName.indexOf(filter) < 0) { + TableNode node = new TableNode(current, tableName); + children.addElement(node); + } + } + } + return children; + } + public int getSize(String query) { + SQLResults results = server.execute("SELECT COUNT(*) FROM " + query); + return Integer.parseInt(results.getElement(1, 1).toString()); + } + public Vector getViewList(BookmarkNode current) + throws NoSuchAdapterException, FeatureNotSupported { + DatabaseAdapter adapter = + AdapterFactory.getInstance().getAdapter(current.getType()); + Vector children = new Vector(); + DatabaseInfo info = DatabaseInfo.create(current); + if (adapter instanceof GenericAdapter) { + Vector views = server.listTables(info.getSchema(), "VIEW"); + for (int i = 0; i < views.size(); i++) { + String viewName = (String) views.elementAt(i); + ViewNode node = new ViewNode(current, viewName); + children.addElement(node); + } + } else { + SQLResults results = server.execute(adapter.getShowViewQuery(info)); + String filter = adapter.getTableListFilter(); + int size = results.getRowCount(); + for (int i = 1; i <= size; i++) { + String viewName = results.getElement(1, i).toString(); + if (filter == null + || filter.equals("") + || viewName.indexOf(filter) < 0) { + ViewNode node = new ViewNode(current, viewName); + children.addElement(node); + } + } + } + return children; + } + public Vector getSequenceList(BookmarkNode current) + throws NoSuchAdapterException, FeatureNotSupported { + DatabaseAdapter adapter = + AdapterFactory.getInstance().getAdapter(current.getType()); + MultiSQLServer server = MultiSQLServer.getInstance(); + Vector children = new Vector(); + if (!(adapter instanceof GenericAdapter)) { + SQLResults results = + server.execute( + adapter.getShowSequenceQuery(DatabaseInfo.create(current))); + String filter = adapter.getTableListFilter(); + int size = results.getRowCount(); + for (int i = 1; i <= size; i++) { + String seqName = results.getElement(1, i).toString(); + if (filter == null + || filter.equals("") + || seqName.indexOf(filter) < 0) { + SequenceNode node = new SequenceNode(current, seqName); + children.addElement(node); + } + } + } + return children; + } + public Vector getMetaData(TableNode parent, String entity) { + Vector columns = new Vector(); + String query = "SELECT * FROM " + entity; + SQLResults results = server.execute(query); + for (int i = 1; i <= results.getColumnCount(); i++) { + String name = results.getColumnName(i); + String type = results.getColumnType(i); + MetaDataNode node = new MetaDataNode(parent, name, type); + columns.addElement(node); + } + return columns; + } + public Vector getMetaData(ViewNode parent, String entity) { + Vector columns = new Vector(); + String query = "SELECT * FROM " + entity; + SQLResults results = server.execute(query); + for (int i = 1; i <= results.getColumnCount(); i++) { + String name = results.getColumnName(i); + String type = results.getColumnType(i); + MetaDataNode node = new MetaDataNode(parent, name, type); + columns.addElement(node); + } + return columns; + } + public SQLResults getResults(String query, int start, int end) { + return server.execute(query, start, end); + } + public SQLResults getResults( + String query, + int start, + int end, + int maxLength, + String encoding) { + return server.execute(query, start, end, maxLength, encoding); + } + public static String getFullTableName(Bookmark current, String table) { + String schema = current.getSchema(); + if (schema == null || schema.equals("")) { + return table; + } + return schema + "." + table; + } } diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/sql/SQLParser.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/sql/SQLParser.java index 1f9a19b..fc31429 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/sql/SQLParser.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/sql/SQLParser.java @@ -2,42 +2,45 @@ package net.sourceforge.phpdt.sql.sql; import java.util.Vector; +import net.sourceforge.phpdt.sql.IConstants; import net.sourceforge.phpdt.sql.parser.SQLLexx; import net.sourceforge.phpdt.sql.parser.Token; -public class SQLParser { - public static final String COMMENT = "--"; - public static final String ENDLINE = ";"; - public static Vector parse(String query) { - Vector commands = new Vector(); - try { - //System.out.println("-------------------1"); - Vector tokens = SQLLexx.parse(query); - //System.out.println("-------------------2"); - StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < tokens.size(); i++) { - //System.out.println("-------------------3"); - Token t = (Token) tokens.elementAt(i); - if (t.getType() == t.COMMENT) { - // ignore comments - } else if (t.getType() == t.SEPARATOR) { - String newCommand = buffer.toString().trim(); - if (!newCommand.equals("")) { - commands.addElement(newCommand); - } - buffer = new StringBuffer(); - } else { - buffer.append(t.getValue()); - } - } - String newCommand = buffer.toString().trim(); - if (!newCommand.equals("")) { - commands.addElement(newCommand); - } - } catch (Throwable e) { - e.printStackTrace(); - } - System.out.println("Returning"); - return commands; - } +public class SQLParser implements IConstants { + public static final String COMMENT = "--"; + public static final String ENDLINE = ";"; + public static Vector parse(String query) { + Vector commands = new Vector(); + try { + //System.out.println("-------------------1"); + Vector tokens = SQLLexx.parse(query); + //System.out.println("-------------------2"); + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < tokens.size(); i++) { + //System.out.println("-------------------3"); + Token t = (Token) tokens.elementAt(i); + if (t.getType() == t.COMMENT) { + // ignore comments + } else if (t.getType() == t.SEPARATOR) { + String newCommand = buffer.toString().trim(); + if (!newCommand.equals("")) { + commands.addElement(newCommand); + } + buffer = new StringBuffer(); + } else { + buffer.append(t.getValue()); + } + } + String newCommand = buffer.toString().trim(); + if (!newCommand.equals("")) { + commands.addElement(newCommand); + } + } catch (Throwable e) { + e.printStackTrace(); + } + if (DEBUG) { + System.out.println("Returning"); + } + return commands; + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/SQLQueryView.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/SQLQueryView.java index 4756d02..24ae30d 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/SQLQueryView.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/SQLQueryView.java @@ -4,7 +4,14 @@ import java.util.LinkedList; import java.util.NoSuchElementException; import java.util.Vector; +import net.sourceforge.phpdt.sql.IConstants; import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin; +import net.sourceforge.phpdt.sql.actions.ExecuteAction; +import net.sourceforge.phpdt.sql.actions.ExportQueryAction; +import net.sourceforge.phpdt.sql.actions.ImportQueryAction; +import net.sourceforge.phpdt.sql.parser.SQLLexx; +import net.sourceforge.phpdt.sql.parser.Token; +import net.sourceforge.phpdt.sql.sql.MultiSQLServer; import org.eclipse.jface.action.Action; import org.eclipse.swt.SWT; @@ -28,14 +35,7 @@ import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.part.ViewPart; -import net.sourceforge.phpdt.sql.actions.ExecuteAction; -import net.sourceforge.phpdt.sql.actions.ExportQueryAction; -import net.sourceforge.phpdt.sql.actions.ImportQueryAction; -import net.sourceforge.phpdt.sql.sql.MultiSQLServer; -import net.sourceforge.phpdt.sql.parser.SQLLexx; -import net.sourceforge.phpdt.sql.parser.Token; - -public class SQLQueryView extends ViewPart { +public class SQLQueryView extends ViewPart implements IConstants { private ExecuteAction executeAction; private ImportQueryAction importQueryAction; private ExportQueryAction exportQueryAction; @@ -369,8 +369,10 @@ public class SQLQueryView extends ViewPart { widget.setStyleRange(styles[i]); } } catch (Throwable t) { + if (DEBUG) { System.out.println("Error with styles: " + t.getClass().toString()); // ignore any errors + } } } }); diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/bookmark/BookmarkContentProvider.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/bookmark/BookmarkContentProvider.java index ec997fa..efa2799 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/bookmark/BookmarkContentProvider.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/bookmark/BookmarkContentProvider.java @@ -6,188 +6,197 @@ import java.io.FileOutputStream; import java.util.Properties; import java.util.Vector; +import net.sourceforge.phpdt.sql.IConstants; +import net.sourceforge.phpdt.sql.bookmarks.Bookmark; + import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; -import net.sourceforge.phpdt.sql.bookmarks.Bookmark; +public class BookmarkContentProvider implements ITreeContentProvider, IConstants { + private Vector bookmarks = new Vector(); + private static BookmarkContentProvider instance = null; + private boolean hasChanged = false; -public class BookmarkContentProvider implements ITreeContentProvider { - private Vector bookmarks = new Vector(); - private static BookmarkContentProvider instance = null; - private boolean hasChanged = false; - - /** - * Singleton accessor - */ - public static synchronized BookmarkContentProvider getInstance() { - if (instance == null) { - instance = new BookmarkContentProvider(); - } - return instance; - } - - private BookmarkContentProvider() { - } - - public void importBookmarks(File file) { - hasChanged = true; - System.out.println("Importing Bookmarks: Loading from file: " + file); - try { - Properties props = new Properties(); - FileInputStream in = new FileInputStream(file); - props.load(in); - in.close(); - fromProperties(false, props); - } catch (Throwable e) { - e.printStackTrace(); - } - } - public void load(File file) { - System.out.println("Bookmarks: Loading from file: " + file); - try { - Properties props = new Properties(); - FileInputStream in = new FileInputStream(file); - props.load(in); - in.close(); - fromProperties(true, props); - } catch (Throwable e) { - e.printStackTrace(); - } - } - public void save(File file) { - System.out.println("Bookmarks: Saving to file: " + file); - try { - Properties props = getProperties(); - FileOutputStream out = new FileOutputStream(file); - props.store(out, ""); - out.close(); - } catch (Throwable e) { - e.printStackTrace(); - } - } - - public Object[] getChildren(Object parentElement) { - if (parentElement.equals(Root.ROOT)) { - return bookmarks.toArray(); - } else if (parentElement instanceof TreeNode) { - TreeNode node = (TreeNode) parentElement; - return node.getChildren(); - } - return Root.EMPTY_ARRAY; - } - - public Object[] getElements(Object inputElement) { - return getChildren(inputElement); - } - - public Object getParent(Object element) { - if (element.equals(Root.ROOT)) { - return null; - } else if (element instanceof TreeNode) { - TreeNode node = (TreeNode) element; - return node.getParent(); - } - return null; - } - - public boolean hasChildren(Object element) { - if (element.equals(Root.ROOT)) { - return true; - } else if (element instanceof TreeNode) { - TreeNode node = (TreeNode) element; - return node.hasChildren(); - } - return false; - } - - public void setChildren(BookmarkNode b, Vector tables) { - b.setChildren(tables); + /** + * Singleton accessor + */ + public static synchronized BookmarkContentProvider getInstance() { + if (instance == null) { + instance = new BookmarkContentProvider(); } + return instance; + } + + private BookmarkContentProvider() { + } - public void addBookmark(BookmarkNode b) { - hasChanged = true; - if (!bookmarks.contains(b)) { - bookmarks.addElement(b); - } - } - public void removeBookmark(BookmarkNode b) { - hasChanged = true; - if (bookmarks.contains(b)) { - bookmarks.removeElement(b); - } - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - public void dispose() { - } - - public boolean hasChanged() { - return hasChanged; - } - - public int getSize() { - return bookmarks.size(); - } - - public void fromProperties(boolean overwrite, Properties props) { - Vector newBookmarks = new Vector(); - int i = 0; - while (true) { - Bookmark bookmark = new BookmarkNode(); - String name = props.getProperty(i + ".name"); - if (name == null) { - break; - } - bookmark.setName(name); - bookmark.setUsername(props.getProperty(i + ".username")); - bookmark.setPassword(props.getProperty(i + ".password")); - bookmark.setConnect(props.getProperty(i + ".connect")); - bookmark.setDriver(props.getProperty(i + ".driver")); - String schema = props.getProperty(i + ".schema"); - if (schema != null) { - bookmark.setSchema(schema); - } else { - bookmark.setSchema(""); - } - String type = props.getProperty(i + ".type"); - if (type != null) { - bookmark.setType(type); - } else { - bookmark.setType(""); - } - String driverFile = props.getProperty(i + ".driverLocation"); - if (driverFile != null) { - bookmark.setDriverFile(driverFile); - } else { - bookmark.setDriverFile(""); - } - System.out.println(bookmark.toString()); - if (!bookmark.isEmpty()) { - newBookmarks.addElement(bookmark); - } - i++; - } - if (overwrite) { - bookmarks = newBookmarks; - } else { - bookmarks.addAll(newBookmarks); - } - } - public Properties getProperties() { - Properties props = new Properties(); - for (int i = 0; i < bookmarks.size(); i++) { - Bookmark b = (Bookmark) bookmarks.elementAt(i); - props.put(i + ".name", b.getName()); - props.put(i + ".username", b.getUsername()); - props.put(i + ".password", b.getPassword()); - props.put(i + ".schema", b.getSchema()); - props.put(i + ".connect", b.getConnect()); - props.put(i + ".driver", b.getDriver()); - props.put(i + ".type", b.getType()); - props.put(i + ".driverLocation", b.getDriverFile()); - } - return props; - } + public void importBookmarks(File file) { + hasChanged = true; + if (DEBUG) { + System.out.println("Importing Bookmarks: Loading from file: " + file); + } + try { + Properties props = new Properties(); + FileInputStream in = new FileInputStream(file); + props.load(in); + in.close(); + fromProperties(false, props); + } catch (Throwable e) { + e.printStackTrace(); + } + } + public void load(File file) { + if (DEBUG) { + System.out.println("Bookmarks: Loading from file: " + file); + } + try { + Properties props = new Properties(); + FileInputStream in = new FileInputStream(file); + props.load(in); + in.close(); + fromProperties(true, props); + } catch (Throwable e) { + e.printStackTrace(); + } + } + public void save(File file) { + if (DEBUG) { + System.out.println("Bookmarks: Saving to file: " + file); + } + try { + Properties props = getProperties(); + FileOutputStream out = new FileOutputStream(file); + props.store(out, ""); + out.close(); + } catch (Throwable e) { + e.printStackTrace(); + } + } + + public Object[] getChildren(Object parentElement) { + if (parentElement.equals(Root.ROOT)) { + return bookmarks.toArray(); + } else if (parentElement instanceof TreeNode) { + TreeNode node = (TreeNode) parentElement; + return node.getChildren(); + } + return Root.EMPTY_ARRAY; + } + + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + public Object getParent(Object element) { + if (element.equals(Root.ROOT)) { + return null; + } else if (element instanceof TreeNode) { + TreeNode node = (TreeNode) element; + return node.getParent(); + } + return null; + } + + public boolean hasChildren(Object element) { + if (element.equals(Root.ROOT)) { + return true; + } else if (element instanceof TreeNode) { + TreeNode node = (TreeNode) element; + return node.hasChildren(); + } + return false; + } + + public void setChildren(BookmarkNode b, Vector tables) { + b.setChildren(tables); + } + + public void addBookmark(BookmarkNode b) { + hasChanged = true; + if (!bookmarks.contains(b)) { + bookmarks.addElement(b); + } + } + public void removeBookmark(BookmarkNode b) { + hasChanged = true; + if (bookmarks.contains(b)) { + bookmarks.removeElement(b); + } + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public void dispose() { + } + + public boolean hasChanged() { + return hasChanged; + } + + public int getSize() { + return bookmarks.size(); + } + + public void fromProperties(boolean overwrite, Properties props) { + Vector newBookmarks = new Vector(); + int i = 0; + while (true) { + Bookmark bookmark = new BookmarkNode(); + String name = props.getProperty(i + ".name"); + if (name == null) { + break; + } + bookmark.setName(name); + bookmark.setUsername(props.getProperty(i + ".username")); + bookmark.setPassword(props.getProperty(i + ".password")); + bookmark.setConnect(props.getProperty(i + ".connect")); + bookmark.setDriver(props.getProperty(i + ".driver")); + String schema = props.getProperty(i + ".schema"); + if (schema != null) { + bookmark.setSchema(schema); + } else { + bookmark.setSchema(""); + } + String type = props.getProperty(i + ".type"); + if (type != null) { + bookmark.setType(type); + } else { + bookmark.setType(""); + } + String driverFile = props.getProperty(i + ".driverLocation"); + if (driverFile != null) { + bookmark.setDriverFile(driverFile); + } else { + bookmark.setDriverFile(""); + } + if (DEBUG) { + System.out.println(bookmark.toString()); + } + if (!bookmark.isEmpty()) { + newBookmarks.addElement(bookmark); + } + i++; + } + if (overwrite) { + bookmarks = newBookmarks; + } else { + bookmarks.addAll(newBookmarks); + } + } + public Properties getProperties() { + Properties props = new Properties(); + for (int i = 0; i < bookmarks.size(); i++) { + Bookmark b = (Bookmark) bookmarks.elementAt(i); + props.put(i + ".name", b.getName()); + props.put(i + ".username", b.getUsername()); + props.put(i + ".password", b.getPassword()); + props.put(i + ".schema", b.getSchema()); + props.put(i + ".connect", b.getConnect()); + props.put(i + ".driver", b.getDriver()); + props.put(i + ".type", b.getType()); + props.put(i + ".driverLocation", b.getDriverFile()); + } + return props; + } } diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/tableview/TableAdapter.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/tableview/TableAdapter.java index 2bf17cc..4752c37 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/tableview/TableAdapter.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/view/tableview/TableAdapter.java @@ -2,11 +2,7 @@ package net.sourceforge.phpdt.sql.view.tableview; import java.util.Vector; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.TableItem; - +import net.sourceforge.phpdt.sql.IConstants; import net.sourceforge.phpdt.sql.adapters.AdapterFactory; import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter; import net.sourceforge.phpdt.sql.adapters.DatabaseInfo; @@ -17,7 +13,12 @@ import net.sourceforge.phpdt.sql.sql.MultiSQLServer; import net.sourceforge.phpdt.sql.sql.SQLHelper; import net.sourceforge.phpdt.sql.sql.SQLResults; -public class TableAdapter { +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +public class TableAdapter implements IConstants { public static final String DEFAULT = ""; public static final String UTF_8 = "UTF-8"; public static final String UTF_16 = "UTF-16"; @@ -131,7 +132,9 @@ public class TableAdapter { } } String query = getQuery(); + if (DEBUG) { System.out.println(offset + " to " + (offset + pageSize - 1)); + } SQLResults results = helper.getResults(query, offset, offset + pageSize - 1, maxColumnSize, encoding); setData(results); } diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/BookmarkWizard.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/BookmarkWizard.java index 2b4a902..71d1112 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/BookmarkWizard.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/BookmarkWizard.java @@ -1,5 +1,11 @@ package net.sourceforge.phpdt.sql.wizards; +import net.sourceforge.phpdt.sql.IConstants; +import net.sourceforge.phpdt.sql.adapters.AdapterFactory; +import net.sourceforge.phpdt.sql.adapters.DriverInfo; +import net.sourceforge.phpdt.sql.view.BookmarkView; +import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode; + import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; @@ -14,242 +20,252 @@ import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; -import net.sourceforge.phpdt.sql.adapters.AdapterFactory; -import net.sourceforge.phpdt.sql.adapters.DriverInfo; -import net.sourceforge.phpdt.sql.view.BookmarkView; -import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode; +public class BookmarkWizard extends Wizard implements IConstants { + BookmarkPage mainPage; + + private BookmarkNode current; -public class BookmarkWizard extends Wizard { - BookmarkPage mainPage; - - private BookmarkNode current; - - public void init(BookmarkNode selection) { - System.out.println("Initing workbench"); - this.current = selection; - setWindowTitle("New Bookmark"); - } - public void init() { - System.out.println("Initing workbench"); - current = null; - setWindowTitle("New Bookmark"); - } - public boolean performFinish() { - System.out.println("perform finish workbench"); - mainPage.performFinish(); - return true; - } - public void addPages() { - System.out.println("adding pages"); - if (current != null) { - mainPage = new BookmarkPage("Testing...", current); - } else { - mainPage = new BookmarkPage("Testing..."); - } - addPage(mainPage); - System.out.println("adding pages"); - } + public void init(BookmarkNode selection) { + if (DEBUG) { + System.out.println("Initing workbench"); + } + this.current = selection; + setWindowTitle("New Bookmark"); + } + public void init() { + if (DEBUG) { + System.out.println("Initing workbench"); + } + current = null; + setWindowTitle("New Bookmark"); + } + public boolean performFinish() { + if (DEBUG) { + System.out.println("perform finish workbench"); + } + mainPage.performFinish(); + return true; + } + public void addPages() { + if (DEBUG) { + System.out.println("adding pages"); + } + if (current != null) { + mainPage = new BookmarkPage("Testing...", current); + } else { + mainPage = new BookmarkPage("Testing..."); + } + addPage(mainPage); + if (DEBUG) { + System.out.println("adding pages"); + } + } } -class BookmarkPage extends WizardPage { - public static final String ADD = "ADD"; - String action = ADD; - Text name; - Text username; - Text password; - Text schema; - Text connect; - Text driver; - //List driverList; - Combo type; - Text driverFile; - - BookmarkNode initialData = null; - - FileDialog dialog; - - DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList(); - /** - * Constructor for BookmarkPage. - * @param pageName - */ - public BookmarkPage(String pageName) { - super(pageName); - initialData = null; - } - /** - * Constructor for BookmarkPage. - * @param pageName - */ - public BookmarkPage(String pageName, BookmarkNode bookmark) { - super(pageName); - this.initialData = bookmark; - } - - public void createControl(Composite parent) { - System.out.println("page create control"); - dialog = new FileDialog(getContainer().getShell(), SWT.OPEN); - dialog.setFilterExtensions(new String[]{"*.jar", "*.zip","*.*"}); - dialog.setFilterNames(new String[]{"Jar Files (*.jar)","Zip Files (*.zip)", "All Files (*.*)"}); - Composite container = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - container.setLayout(layout); - layout.numColumns = 2; - layout.verticalSpacing = 9; - - - Label label = new Label(container, SWT.NULL); - label.setText("*Bookmark Name"); - name = new Text(container, SWT.BORDER | SWT.SINGLE); - GridData fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - name.setLayoutData(fullHorizontal); - - label = new Label(container, SWT.NULL); - label.setText("*Username"); - username = new Text(container, SWT.BORDER | SWT.SINGLE); - fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - username.setLayoutData(fullHorizontal); - - label = new Label(container, SWT.NULL); - label.setText("*Password"); - password = new Text(container, SWT.BORDER | SWT.SINGLE); - password.setEchoChar('*'); - fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - password.setLayoutData(fullHorizontal); - - label = new Label(container, SWT.NULL); - label.setText("Schema (optional)"); - schema = new Text(container, SWT.BORDER | SWT.SINGLE); - fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - schema.setLayoutData(fullHorizontal); - - label = new Label(container, SWT.NULL); - label.setText("*Connect"); - connect = new Text(container, SWT.BORDER | SWT.SINGLE); - fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - connect.setLayoutData(fullHorizontal); - - label = new Label(container, SWT.NULL); - label.setText("*Driver"); - driver = new Text(container, SWT.BORDER | SWT.SINGLE); - fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - driver.setLayoutData(fullHorizontal); - - //label = new Label(container, SWT.NULL); - //fullHorizontal = new GridData(); - //fullHorizontal.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; - //fullHorizontal.verticalSpan = 3; - //label.setLayoutData(fullHorizontal); - //label.setText("(Drivers Found in File)"); - /*driverList = new List(container, SWT.SINGLE); - fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - fullHorizontal.verticalAlignment = GridData.FILL; - fullHorizontal.verticalSpan = 3; - driverList.setLayoutData(fullHorizontal); - driverList.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - String[] selection = driverList.getSelection(); - if (selection != null && selection.length > 0) { - driver.setText(selection[0]); - } - } - });*/ - - label = new Label(container, SWT.NULL); - label.setText("*Type"); - type = new Combo(container, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY); - String driverNames[] = new String[drivers.length]; - for (int i = 0; i < drivers.length; i++) { - driverNames[i] = drivers[i].getDisplayName(); - } - type.setItems(driverNames); - type.select(0); - fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - type.setLayoutData(fullHorizontal); - - label = new Label(container, SWT.NULL); - label.setText("*Driver Filename"); - driverFile = new Text(container, SWT.BORDER | SWT.SINGLE); - fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - driverFile.setLayoutData(fullHorizontal); - - Button button = new Button(container, SWT.PUSH); - button.setText("Browse..."); - - button.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - String filename = dialog.open(); - if (filename != null) { - driverFile.setText(filename); - } - } - }); - if (initialData != null) { - name.setText(initialData.getName()); - username.setText(initialData.getUsername()); - password.setText(initialData.getPassword()); - schema.setText(initialData.getSchema()); - connect.setText(initialData.getConnect()); - driver.setText(initialData.getDriver()); - String typeData = initialData.getType(); - int selectedIndex = 0; - for (int i = 0; i < drivers.length; i++) { - if (typeData.equals(drivers[i].getDriverType())) { - selectedIndex = i; - } - } - type.select(selectedIndex); - driverFile.setText(initialData.getDriverFile()); - updateDriverList(); - } - setControl(container); - - setPageComplete(true); - } - public void updateDriverList() { - /*try { - JarFile file = new JarFile(driverFile.getText()); - Enumeration enum = file.entries(); - while (enum.hasMoreElements()) { - JarEntry entry = (JarEntry) enum.nextElement(); - String className = entry.getName().replace('/', '.'); - if (className.endsWith("Driver.class")) { - className = className.substring(0, className.lastIndexOf('.')); - //driverList.add(className); - } - } - } catch (IOException ex) { - //driverList.removeAll(); - }*/ - } - public void performFinish() { - if (initialData == null) { - initialData = new BookmarkNode(); - } - initialData.setName(name.getText()); - initialData.setUsername(username.getText()); - initialData.setPassword(password.getText()); - initialData.setSchema(schema.getText()); - initialData.setConnect(connect.getText()); - initialData.setDriver(driver.getText()); - int selection = type.getSelectionIndex(); - if (selection >= 0) { - initialData.setType(drivers[selection].getDriverType()); - } - initialData.setDriverFile(driverFile.getText()); - BookmarkView.getInstance().addNewBookmark(initialData); - } +class BookmarkPage extends WizardPage implements IConstants { + public static final String ADD = "ADD"; + String action = ADD; + Text name; + Text username; + Text password; + Text schema; + Text connect; + Text driver; + //List driverList; + Combo type; + Text driverFile; + + BookmarkNode initialData = null; + + FileDialog dialog; + + DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList(); + /** + * Constructor for BookmarkPage. + * @param pageName + */ + public BookmarkPage(String pageName) { + super(pageName); + initialData = null; + } + /** + * Constructor for BookmarkPage. + * @param pageName + */ + public BookmarkPage(String pageName, BookmarkNode bookmark) { + super(pageName); + this.initialData = bookmark; + } + + public void createControl(Composite parent) { + if (DEBUG) { + System.out.println("page create control"); + } + dialog = new FileDialog(getContainer().getShell(), SWT.OPEN); + dialog.setFilterExtensions(new String[] { "*.jar", "*.zip", "*.*" }); + dialog.setFilterNames( + new String[] { + "Jar Files (*.jar)", + "Zip Files (*.zip)", + "All Files (*.*)" }); + Composite container = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + layout.numColumns = 2; + layout.verticalSpacing = 9; + + Label label = new Label(container, SWT.NULL); + label.setText("*Bookmark Name"); + name = new Text(container, SWT.BORDER | SWT.SINGLE); + GridData fullHorizontal = new GridData(); + fullHorizontal.horizontalAlignment = GridData.FILL; + name.setLayoutData(fullHorizontal); + + label = new Label(container, SWT.NULL); + label.setText("*Username"); + username = new Text(container, SWT.BORDER | SWT.SINGLE); + fullHorizontal = new GridData(); + fullHorizontal.horizontalAlignment = GridData.FILL; + username.setLayoutData(fullHorizontal); + + label = new Label(container, SWT.NULL); + label.setText("*Password"); + password = new Text(container, SWT.BORDER | SWT.SINGLE); + password.setEchoChar('*'); + fullHorizontal = new GridData(); + fullHorizontal.horizontalAlignment = GridData.FILL; + password.setLayoutData(fullHorizontal); + + label = new Label(container, SWT.NULL); + label.setText("Schema (optional)"); + schema = new Text(container, SWT.BORDER | SWT.SINGLE); + fullHorizontal = new GridData(); + fullHorizontal.horizontalAlignment = GridData.FILL; + schema.setLayoutData(fullHorizontal); + + label = new Label(container, SWT.NULL); + label.setText("*Connect"); + connect = new Text(container, SWT.BORDER | SWT.SINGLE); + fullHorizontal = new GridData(); + fullHorizontal.horizontalAlignment = GridData.FILL; + connect.setLayoutData(fullHorizontal); + + label = new Label(container, SWT.NULL); + label.setText("*Driver"); + driver = new Text(container, SWT.BORDER | SWT.SINGLE); + fullHorizontal = new GridData(); + fullHorizontal.horizontalAlignment = GridData.FILL; + driver.setLayoutData(fullHorizontal); + + //label = new Label(container, SWT.NULL); + //fullHorizontal = new GridData(); + //fullHorizontal.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; + //fullHorizontal.verticalSpan = 3; + //label.setLayoutData(fullHorizontal); + //label.setText("(Drivers Found in File)"); + /*driverList = new List(container, SWT.SINGLE); + fullHorizontal = new GridData(); + fullHorizontal.horizontalAlignment = GridData.FILL; + fullHorizontal.verticalAlignment = GridData.FILL; + fullHorizontal.verticalSpan = 3; + driverList.setLayoutData(fullHorizontal); + driverList.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + String[] selection = driverList.getSelection(); + if (selection != null && selection.length > 0) { + driver.setText(selection[0]); + } + } + });*/ + + label = new Label(container, SWT.NULL); + label.setText("*Type"); + type = new Combo(container, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY); + String driverNames[] = new String[drivers.length]; + for (int i = 0; i < drivers.length; i++) { + driverNames[i] = drivers[i].getDisplayName(); + } + type.setItems(driverNames); + type.select(0); + fullHorizontal = new GridData(); + fullHorizontal.horizontalAlignment = GridData.FILL; + type.setLayoutData(fullHorizontal); + + label = new Label(container, SWT.NULL); + label.setText("*Driver Filename"); + driverFile = new Text(container, SWT.BORDER | SWT.SINGLE); + fullHorizontal = new GridData(); + fullHorizontal.horizontalAlignment = GridData.FILL; + driverFile.setLayoutData(fullHorizontal); + + Button button = new Button(container, SWT.PUSH); + button.setText("Browse..."); + + button.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + String filename = dialog.open(); + if (filename != null) { + driverFile.setText(filename); + } + } + }); + if (initialData != null) { + name.setText(initialData.getName()); + username.setText(initialData.getUsername()); + password.setText(initialData.getPassword()); + schema.setText(initialData.getSchema()); + connect.setText(initialData.getConnect()); + driver.setText(initialData.getDriver()); + String typeData = initialData.getType(); + int selectedIndex = 0; + for (int i = 0; i < drivers.length; i++) { + if (typeData.equals(drivers[i].getDriverType())) { + selectedIndex = i; + } + } + type.select(selectedIndex); + driverFile.setText(initialData.getDriverFile()); + updateDriverList(); + } + setControl(container); + + setPageComplete(true); + } + public void updateDriverList() { + /*try { + JarFile file = new JarFile(driverFile.getText()); + Enumeration enum = file.entries(); + while (enum.hasMoreElements()) { + JarEntry entry = (JarEntry) enum.nextElement(); + String className = entry.getName().replace('/', '.'); + if (className.endsWith("Driver.class")) { + className = className.substring(0, className.lastIndexOf('.')); + //driverList.add(className); + } + } + } catch (IOException ex) { + //driverList.removeAll(); + }*/ + } + public void performFinish() { + if (initialData == null) { + initialData = new BookmarkNode(); + } + initialData.setName(name.getText()); + initialData.setUsername(username.getText()); + initialData.setPassword(password.getText()); + initialData.setSchema(schema.getText()); + initialData.setConnect(connect.getText()); + initialData.setDriver(driver.getText()); + int selection = type.getSelectionIndex(); + if (selection >= 0) { + initialData.setType(drivers[selection].getDriverType()); + } + initialData.setDriverFile(driverFile.getText()); + BookmarkView.getInstance().addNewBookmark(initialData); + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/DeleteRowPage.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/DeleteRowPage.java index 2f8e6e6..c16e981 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/DeleteRowPage.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/DeleteRowPage.java @@ -18,122 +18,131 @@ import net.sourceforge.phpdt.sql.sql.TableRow; import net.sourceforge.phpdt.sql.view.tableview.TableAdapter; public class DeleteRowPage extends WizardPage implements SQLPage { - TableRow row; - String[] columnNames; - Text[] values; - Button[] whereValues; - Label query; + TableRow row; + String[] columnNames; + Text[] values; + Button[] whereValues; + Label query; - public DeleteRowPage(String pageName) { - super(pageName); - } - - public void init(TableRow row, TableAdapter adapter) { - this.row = row; - } + public DeleteRowPage(String pageName) { + super(pageName); + } - public void createControl(Composite parent) { - System.out.println("page create control"); - Composite container = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - container.setLayout(layout); - int layoutColumns = 3; - layout.numColumns = layoutColumns; + public void init(TableRow row, TableAdapter adapter) { + this.row = row; + } - if (row == null) { - System.out.println("Row is null"); - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); - } - if (row.getTableData() == null) { - System.out.println("Data is null"); - } - columnNames = row.getColumnNames(); - String[] data = row.getTableData(); - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); - System.out.println("column = " + i + "=" + columnNames[i]); - } - values = new Text[row.getColumnCount()]; - whereValues = new Button[row.getColumnCount()]; - Label temp = new Label(container, SWT.NULL); - temp.setText("Column Name"); - temp = new Label(container, SWT.NULL); - temp.setText("Value"); - temp = new Label(container, SWT.NULL); - temp.setText("Include in?"); - for (int i = 0; i < row.getColumnCount(); i++) { - Label label = new Label(container, SWT.NULL); - label.setText(columnNames[i]); - values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - GridData fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - values[i].setLayoutData(fullHorizontal); - values[i].setText(data[i]); + public void createControl(Composite parent) { + if (DEBUG) { + System.out.println("page create control"); + } + Composite container = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + int layoutColumns = 3; + layout.numColumns = layoutColumns; - values[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateQuery(); - } - }); - - whereValues[i] = new Button(container, SWT.CHECK); - whereValues[i].setText("Where clause"); - whereValues[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - } - query = new Label(container, SWT.WRAP); - GridData gridData = new GridData(); - gridData.horizontalSpan = layoutColumns; - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - query.setLayoutData(gridData); + if (DEBUG) { + if (row == null) { + System.out.println("Row is null"); + } - setControl(container); - updateQuery(); - - setPageComplete(true); - } - public void updateQuery() { - System.out.println("Updating query"); - StringBuffer whereClause = new StringBuffer(); - int numSelected = 0; - for (int i = 0; i < columnNames.length; i++) { - if (whereValues[i].getSelection()) { - numSelected++; - whereClause.append(columnNames[i]); - whereClause.append(" = "); - whereClause.append(values[i].getText()); - whereClause.append(", "); - } - } - if (whereClause.length() > 1) { - whereClause.deleteCharAt(whereClause.length() - 1); - whereClause.deleteCharAt(whereClause.length() - 1); - } - String query = "DELETE FROM " + row.getTable(); - if (numSelected > 0) { - query += " WHERE " + whereClause.toString(); - } - if (numSelected > 0) { - setMessage(""); - } else { - setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted"); - } - this.getControl().pack(); - this.query.setText(query); - } - public boolean performFinish() { - MultiSQLServer server = MultiSQLServer.getInstance(); - server.execute(query.getText()); - return true; - } + if (row.getColumnNames() == null) { + System.out.println("Columns are null"); + } + if (row.getTableData() == null) { + System.out.println("Data is null"); + } + } + columnNames = row.getColumnNames(); + String[] data = row.getTableData(); + if (DEBUG) { + for (int i = 0; i < row.getColumnCount(); i++) { + System.out.println("data = " + i + "=" + data[i]); + System.out.println("column = " + i + "=" + columnNames[i]); + } + } + values = new Text[row.getColumnCount()]; + whereValues = new Button[row.getColumnCount()]; + Label temp = new Label(container, SWT.NULL); + temp.setText("Column Name"); + temp = new Label(container, SWT.NULL); + temp.setText("Value"); + temp = new Label(container, SWT.NULL); + temp.setText("Include in?"); + for (int i = 0; i < row.getColumnCount(); i++) { + Label label = new Label(container, SWT.NULL); + label.setText(columnNames[i]); + values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); + GridData fullHorizontal = new GridData(); + fullHorizontal.horizontalAlignment = GridData.FILL; + values[i].setLayoutData(fullHorizontal); + values[i].setText(data[i]); + + values[i].addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateQuery(); + } + }); + + whereValues[i] = new Button(container, SWT.CHECK); + whereValues[i].setText("Where clause"); + whereValues[i].addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + updateQuery(); + } + }); + } + query = new Label(container, SWT.WRAP); + GridData gridData = new GridData(); + gridData.horizontalSpan = layoutColumns; + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + query.setLayoutData(gridData); + + setControl(container); + updateQuery(); + + setPageComplete(true); + } + public void updateQuery() { + if (DEBUG) { + System.out.println("Updating query"); + } + StringBuffer whereClause = new StringBuffer(); + int numSelected = 0; + for (int i = 0; i < columnNames.length; i++) { + if (whereValues[i].getSelection()) { + numSelected++; + whereClause.append(columnNames[i]); + whereClause.append(" = "); + whereClause.append(values[i].getText()); + whereClause.append(", "); + } + } + if (whereClause.length() > 1) { + whereClause.deleteCharAt(whereClause.length() - 1); + whereClause.deleteCharAt(whereClause.length() - 1); + } + String query = "DELETE FROM " + row.getTable(); + if (numSelected > 0) { + query += " WHERE " + whereClause.toString(); + } + if (numSelected > 0) { + setMessage(""); + } else { + setMessage("Warning: no \"where clause\" columns selected, all rows will be deleted"); + } + this.getControl().pack(); + this.query.setText(query); + } + public boolean performFinish() { + MultiSQLServer server = MultiSQLServer.getInstance(); + server.execute(query.getText()); + return true; + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/InsertRowPage.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/InsertRowPage.java index 3aa57e5..7098f46 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/InsertRowPage.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/InsertRowPage.java @@ -15,94 +15,102 @@ import net.sourceforge.phpdt.sql.sql.TableRow; import net.sourceforge.phpdt.sql.view.tableview.TableAdapter; public class InsertRowPage extends WizardPage implements SQLPage { - TableRow row; - String[] columnNames; - Text[] values; - Label query; - public InsertRowPage(String pageName) { - super(pageName); - } + TableRow row; + String[] columnNames; + Text[] values; + Label query; + public InsertRowPage(String pageName) { + super(pageName); + } - public void init(TableRow row, TableAdapter adapter) { - this.row = row; - } + public void init(TableRow row, TableAdapter adapter) { + this.row = row; + } - public void createControl(Composite parent) { - System.out.println("page create control"); - Composite container = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - container.setLayout(layout); - int layoutColumns = 2; - layout.numColumns = layoutColumns; + public void createControl(Composite parent) { + if (DEBUG) { + System.out.println("page create control"); + } + Composite container = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + int layoutColumns = 2; + layout.numColumns = layoutColumns; - if (row == null) { - System.out.println("Row is null"); - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); - } - if (row.getTableData() == null) { - System.out.println("Data is null"); - } - columnNames = row.getColumnNames(); - String[] data = row.getTableData(); - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); - System.out.println("column = " + i + "=" + columnNames[i]); - } - values = new Text[row.getColumnCount()]; - Label temp = new Label(container, SWT.NULL); - temp.setText("Column Name"); - temp = new Label(container, SWT.NULL); - temp.setText("Value"); - for (int i = 0; i < row.getColumnCount(); i++) { - Label label = new Label(container, SWT.NULL); - label.setText(columnNames[i]); - values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - GridData fullHorizontal = new GridData(); - fullHorizontal.horizontalAlignment = GridData.FILL; - values[i].setLayoutData(fullHorizontal); + if (DEBUG) { + if (row == null) { + System.out.println("Row is null"); + } + if (row.getColumnNames() == null) { + System.out.println("Columns are null"); + } + if (row.getTableData() == null) { + System.out.println("Data is null"); + } + } + columnNames = row.getColumnNames(); + String[] data = row.getTableData(); + if (DEBUG) { + for (int i = 0; i < row.getColumnCount(); i++) { + System.out.println("data = " + i + "=" + data[i]); + System.out.println("column = " + i + "=" + columnNames[i]); + } + } + values = new Text[row.getColumnCount()]; + Label temp = new Label(container, SWT.NULL); + temp.setText("Column Name"); + temp = new Label(container, SWT.NULL); + temp.setText("Value"); + for (int i = 0; i < row.getColumnCount(); i++) { + Label label = new Label(container, SWT.NULL); + label.setText(columnNames[i]); + values[i] = new Text(container, SWT.BORDER | SWT.SINGLE); + GridData fullHorizontal = new GridData(); + fullHorizontal.horizontalAlignment = GridData.FILL; + values[i].setLayoutData(fullHorizontal); - //values[i].setText(data[i]); - values[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateQuery(); - } - }); - } - query = new Label(container, SWT.WRAP); - GridData gridData = new GridData(); - gridData.horizontalSpan = layoutColumns; - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - query.setLayoutData(gridData); + //values[i].setText(data[i]); + values[i].addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateQuery(); + } + }); + } + query = new Label(container, SWT.WRAP); + GridData gridData = new GridData(); + gridData.horizontalSpan = layoutColumns; + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + query.setLayoutData(gridData); - setControl(container); - updateQuery(); - - setPageComplete(true); - } - public void updateQuery() { - System.out.println("Updating query"); - StringBuffer valuesClause = new StringBuffer(); - for (int i = 0; i < columnNames.length; i++) { - valuesClause.append(values[i].getText()); - valuesClause.append(", "); - } - if (valuesClause.length() > 1) { - valuesClause.deleteCharAt(valuesClause.length() - 1); - valuesClause.deleteCharAt(valuesClause.length() - 1); - } - String query = "INSERT INTO " + row.getTable(); - query += " VALUES (" + valuesClause.toString(); - query += " )"; - this.query.setText(query); - } - public boolean performFinish() { - MultiSQLServer server = MultiSQLServer.getInstance(); - server.execute(query.getText()); - return true; - } + setControl(container); + updateQuery(); + + setPageComplete(true); + } + public void updateQuery() { + if (DEBUG) { + System.out.println("Updating query"); + } + StringBuffer valuesClause = new StringBuffer(); + for (int i = 0; i < columnNames.length; i++) { + valuesClause.append(values[i].getText()); + valuesClause.append(", "); + } + if (valuesClause.length() > 1) { + valuesClause.deleteCharAt(valuesClause.length() - 1); + valuesClause.deleteCharAt(valuesClause.length() - 1); + } + String query = "INSERT INTO " + row.getTable(); + query += " VALUES (" + valuesClause.toString(); + query += " )"; + this.query.setText(query); + } + public boolean performFinish() { + MultiSQLServer server = MultiSQLServer.getInstance(); + server.execute(query.getText()); + return true; + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/PHPSelectRowPage.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/PHPSelectRowPage.java index c15581a..beef6fb 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/PHPSelectRowPage.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/PHPSelectRowPage.java @@ -35,27 +35,33 @@ public class PHPSelectRowPage extends WizardPage implements SQLPage { } public void createControl(Composite parent) { - System.out.println("page create control"); + if (DEBUG) { + System.out.println("page create control"); + } Composite container = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); container.setLayout(layout); int layoutColumns = 4; layout.numColumns = layoutColumns; - if (row == null) { - System.out.println("Row is null"); - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); - } - if (row.getTableData() == null) { - System.out.println("Data is null"); + if (DEBUG) { + if (row == null) { + System.out.println("Row is null"); + } + if (row.getColumnNames() == null) { + System.out.println("Columns are null"); + } + if (row.getTableData() == null) { + System.out.println("Data is null"); + } } columnNames = row.getColumnNames(); String[] data = row.getTableData(); - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); - System.out.println("column = " + i + "=" + columnNames[i]); + if (DEBUG) { + for (int i = 0; i < row.getColumnCount(); i++) { + System.out.println("data = " + i + "=" + data[i]); + System.out.println("column = " + i + "=" + columnNames[i]); + } } oldValues = new Text[row.getColumnCount()]; // newValues = new Text[row.getColumnCount()]; @@ -128,7 +134,9 @@ public class PHPSelectRowPage extends WizardPage implements SQLPage { } public void updateQuery() { - System.out.println("PHP SELECT"); + if (DEBUG) { + System.out.println("PHP SELECT"); + } StringBuffer setClause = new StringBuffer(); StringBuffer whereClause = new StringBuffer(); String temp; @@ -142,12 +150,11 @@ public class PHPSelectRowPage extends WizardPage implements SQLPage { whereClause.append(columnNames[i]); whereClause.append(" = "); temp = oldValues[i].getText(); -// if (temp.charAt(0) == '$') { -// whereClause.append(temp); -// } else { - whereClause.append("'"+temp+"'"); -// } - + // if (temp.charAt(0) == '$') { + // whereClause.append(temp); + // } else { + whereClause.append("'" + temp + "'"); + // } } if (setValues[i].getSelection()) { diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/SQLPage.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/SQLPage.java index bf53558..1972ccf 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/SQLPage.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/SQLPage.java @@ -1,11 +1,13 @@ package net.sourceforge.phpdt.sql.wizards; -import org.eclipse.jface.wizard.IWizardPage; - +import net.sourceforge.phpdt.sql.IConstants; import net.sourceforge.phpdt.sql.sql.TableRow; import net.sourceforge.phpdt.sql.view.tableview.TableAdapter; -public interface SQLPage extends IWizardPage { +import org.eclipse.jface.wizard.IWizardPage; + +public interface SQLPage extends IWizardPage, IConstants { public void init(TableRow row, TableAdapter adapter); public boolean performFinish(); } + \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/SortFilterPage.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/SortFilterPage.java index ff9d447..3fa7cc3 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/SortFilterPage.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/SortFilterPage.java @@ -20,142 +20,151 @@ import net.sourceforge.phpdt.sql.view.TableView; import net.sourceforge.phpdt.sql.view.tableview.TableAdapter; public class SortFilterPage extends WizardPage implements SQLPage { - TableRow row; - TableAdapter adapter; - Button[] filter; - Combo[] operator; - Text[] filterValues; - Button[] stringFlags; - Button[] sort; - - String columnNames[]; - Label query; - FilterSort filterSort = new FilterSort(); - public SortFilterPage(String pageName) { - super(pageName); - } - - public void init(TableRow row, TableAdapter adapter) { - this.row = row; - this.adapter = adapter; - } - - public void createControl(Composite parent) { - System.out.println("page create control"); - - Composite container = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - container.setLayout(layout); - int layoutColumns = 5; - layout.numColumns = layoutColumns; - - if (row == null) { - System.out.println("Row is null"); - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); - } - if (row.getTableData() == null) { - System.out.println("Data is null"); - } - - columnNames = row.getColumnNames(); - String[] data = row.getTableData(); - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); - System.out.println("column = " + i + "=" + columnNames[i]); - } - int size = row.getColumnCount(); - filter = new Button[size]; - operator = new Combo[size]; - filterValues = new Text[size]; - stringFlags = new Button[size]; - sort = new Button[size]; - for (int i = 0; i < row.getColumnCount(); i++) { - filter[i] = new Button(container, SWT.CHECK); - filter[i].setText(columnNames[i]); - filter[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - - operator[i] = new Combo(container, SWT.SINGLE | SWT.READ_ONLY); - operator[i].add("="); - operator[i].add("<>"); - operator[i].add("<"); - operator[i].add(">"); - operator[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - - filterValues[i] = new Text(container, SWT.BORDER); - filterValues[i].setText(data[i]); - filterValues[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateQuery(); - } - }); - - stringFlags[i] = new Button(container, SWT.CHECK); - stringFlags[i].setText("String"); - stringFlags[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - - final int index = i; - sort[i] = new Button(container, SWT.CHECK); - sort[i].setText(columnNames[i]); - sort[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - if (sort[index].getSelection()) { - filterSort.addSort(columnNames[index]); - } else { - filterSort.removeSort(columnNames[index]); - } - updateQuery(); - } - }); - } - query = new Label(container, SWT.WRAP); - GridData gridData = new GridData(); - gridData.horizontalSpan = layoutColumns; - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - query.setLayoutData(gridData); - - setControl(container); - - setPageComplete(true); - } - - public void updateQuery() { - filterSort.clearFilters(); - for (int i = 0; i < filter.length; i++) { - if (filter[i].getSelection()) { - filterSort.addFilter(filter[i].getText(), operator[i].getText(), filterValues[i].getText(), stringFlags[i].getSelection()); - } - } - query.setText(filterSort.toString()); - } - - public boolean performFinish() { - adapter.setFilterSort(filterSort); - TableView.getInstance().refreshCurrent(); - return true; - } + TableRow row; + TableAdapter adapter; + Button[] filter; + Combo[] operator; + Text[] filterValues; + Button[] stringFlags; + Button[] sort; + + String columnNames[]; + Label query; + FilterSort filterSort = new FilterSort(); + public SortFilterPage(String pageName) { + super(pageName); + } + + public void init(TableRow row, TableAdapter adapter) { + this.row = row; + this.adapter = adapter; + } + + public void createControl(Composite parent) { + if (DEBUG) { + System.out.println("page create control"); + } + Composite container = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + int layoutColumns = 5; + layout.numColumns = layoutColumns; + + if (DEBUG) { + if (row == null) { + System.out.println("Row is null"); + } + if (row.getColumnNames() == null) { + System.out.println("Columns are null"); + } + if (row.getTableData() == null) { + System.out.println("Data is null"); + } + } + + columnNames = row.getColumnNames(); + String[] data = row.getTableData(); + if (DEBUG) { + for (int i = 0; i < row.getColumnCount(); i++) { + System.out.println("data = " + i + "=" + data[i]); + System.out.println("column = " + i + "=" + columnNames[i]); + } + } + int size = row.getColumnCount(); + filter = new Button[size]; + operator = new Combo[size]; + filterValues = new Text[size]; + stringFlags = new Button[size]; + sort = new Button[size]; + for (int i = 0; i < row.getColumnCount(); i++) { + filter[i] = new Button(container, SWT.CHECK); + filter[i].setText(columnNames[i]); + filter[i].addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + updateQuery(); + } + }); + + operator[i] = new Combo(container, SWT.SINGLE | SWT.READ_ONLY); + operator[i].add("="); + operator[i].add("<>"); + operator[i].add("<"); + operator[i].add(">"); + operator[i].addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + updateQuery(); + } + }); + + filterValues[i] = new Text(container, SWT.BORDER); + filterValues[i].setText(data[i]); + filterValues[i].addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateQuery(); + } + }); + + stringFlags[i] = new Button(container, SWT.CHECK); + stringFlags[i].setText("String"); + stringFlags[i].addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + updateQuery(); + } + }); + + final int index = i; + sort[i] = new Button(container, SWT.CHECK); + sort[i].setText(columnNames[i]); + sort[i].addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + if (sort[index].getSelection()) { + filterSort.addSort(columnNames[index]); + } else { + filterSort.removeSort(columnNames[index]); + } + updateQuery(); + } + }); + } + query = new Label(container, SWT.WRAP); + GridData gridData = new GridData(); + gridData.horizontalSpan = layoutColumns; + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + query.setLayoutData(gridData); + + setControl(container); + + setPageComplete(true); + } + + public void updateQuery() { + filterSort.clearFilters(); + for (int i = 0; i < filter.length; i++) { + if (filter[i].getSelection()) { + filterSort.addFilter( + filter[i].getText(), + operator[i].getText(), + filterValues[i].getText(), + stringFlags[i].getSelection()); + } + } + query.setText(filterSort.toString()); + } + + public boolean performFinish() { + adapter.setFilterSort(filterSort); + TableView.getInstance().refreshCurrent(); + return true; + } } diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/UpdateRowPage.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/UpdateRowPage.java index d049615..35f3b0e 100644 --- a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/UpdateRowPage.java +++ b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/wizards/UpdateRowPage.java @@ -18,142 +18,151 @@ import net.sourceforge.phpdt.sql.sql.TableRow; import net.sourceforge.phpdt.sql.view.tableview.TableAdapter; public class UpdateRowPage extends WizardPage implements SQLPage { - TableRow row; - String[] columnNames; - Text[] oldValues; - Text[] newValues; - Button[] primaryKeys; - Button[] setValues; - Label query; - public UpdateRowPage(String pageName) { - super(pageName); - } + TableRow row; + String[] columnNames; + Text[] oldValues; + Text[] newValues; + Button[] primaryKeys; + Button[] setValues; + Label query; + public UpdateRowPage(String pageName) { + super(pageName); + } - public void init(TableRow row, TableAdapter adapter) { - this.row = row; - } - - public void createControl(Composite parent) { - System.out.println("page create control"); - Composite container = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - container.setLayout(layout); - int layoutColumns = 5; - layout.numColumns = layoutColumns; + public void init(TableRow row, TableAdapter adapter) { + this.row = row; + } - if (row == null) { - System.out.println("Row is null"); - } - if (row.getColumnNames() == null) { - System.out.println("Columns are null"); - } - if (row.getTableData() == null) { - System.out.println("Data is null"); - } - columnNames = row.getColumnNames(); - String[] data = row.getTableData(); - for (int i = 0; i < row.getColumnCount(); i++) { - System.out.println("data = " + i + "=" + data[i]); - System.out.println("column = " + i + "=" + columnNames[i]); - } - oldValues = new Text[row.getColumnCount()]; - newValues = new Text[row.getColumnCount()]; - primaryKeys = new Button[row.getColumnCount()]; - setValues = new Button[row.getColumnCount()]; - Label temp = new Label(container, SWT.NULL); - temp.setText("Column Name"); - temp = new Label(container, SWT.NULL); - temp.setText("Old Value"); - temp = new Label(container, SWT.NULL); - temp.setText(""); - temp = new Label(container, SWT.NULL); - temp.setText("New Value"); - temp = new Label(container, SWT.NULL); - temp.setText(""); - for (int i = 0; i < row.getColumnCount(); i++) { - Label label = new Label(container, SWT.NULL); - label.setText(columnNames[i]); - oldValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - oldValues[i].setText(data[i]); - oldValues[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateQuery(); - } - }); - primaryKeys[i] = new Button(container, SWT.CHECK); - primaryKeys[i].setText("Primary Key"); - primaryKeys[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); - newValues[i].setText(data[i]); - newValues[i].addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateQuery(); - } - }); - setValues[i] = new Button(container, SWT.CHECK); - setValues[i].setText("Set Value"); - setValues[i].addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - public void widgetSelected(SelectionEvent e) { - updateQuery(); - } - }); - } - query = new Label(container, SWT.WRAP); - GridData gridData = new GridData(); - gridData.horizontalSpan = layoutColumns; - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - query.setLayoutData(gridData); + public void createControl(Composite parent) { + if (DEBUG) { + System.out.println("page create control"); + } + Composite container = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + int layoutColumns = 5; + layout.numColumns = layoutColumns; - setControl(container); - updateQuery(); - - setPageComplete(true); - } - public void updateQuery() { - System.out.println("Updating query"); - StringBuffer setClause = new StringBuffer(); - StringBuffer whereClause = new StringBuffer(); - for (int i = 0; i < columnNames.length; i++) { - if (primaryKeys[i].getSelection()) { - whereClause.append(columnNames[i]); - whereClause.append(" = "); - whereClause.append(oldValues[i].getText()); - whereClause.append(", "); - } - if (setValues[i].getSelection()) { - setClause.append(columnNames[i]); - setClause.append(" = "); - setClause.append(newValues[i].getText()); - setClause.append(", "); - } - } - if (whereClause.length() > 1) { - whereClause.deleteCharAt(whereClause.length() - 1); - whereClause.deleteCharAt(whereClause.length() - 1); - } - if (setClause.length() > 1) { - setClause.deleteCharAt(setClause.length() - 1); - setClause.deleteCharAt(setClause.length() - 1); - } - String query = "UPDATE " + row.getTable(); - query += " SET " + setClause.toString(); - query += " WHERE " + whereClause.toString(); - this.query.setText(query); - } - public boolean performFinish() { - MultiSQLServer server = MultiSQLServer.getInstance(); - server.execute(query.getText()); - return true; - } + if (DEBUG) { + if (row == null) { + System.out.println("Row is null"); + } + if (row.getColumnNames() == null) { + System.out.println("Columns are null"); + } + if (row.getTableData() == null) { + System.out.println("Data is null"); + } + } + + columnNames = row.getColumnNames(); + String[] data = row.getTableData(); + if (DEBUG) { + for (int i = 0; i < row.getColumnCount(); i++) { + System.out.println("data = " + i + "=" + data[i]); + System.out.println("column = " + i + "=" + columnNames[i]); + } + } + oldValues = new Text[row.getColumnCount()]; + newValues = new Text[row.getColumnCount()]; + primaryKeys = new Button[row.getColumnCount()]; + setValues = new Button[row.getColumnCount()]; + Label temp = new Label(container, SWT.NULL); + temp.setText("Column Name"); + temp = new Label(container, SWT.NULL); + temp.setText("Old Value"); + temp = new Label(container, SWT.NULL); + temp.setText(""); + temp = new Label(container, SWT.NULL); + temp.setText("New Value"); + temp = new Label(container, SWT.NULL); + temp.setText(""); + for (int i = 0; i < row.getColumnCount(); i++) { + Label label = new Label(container, SWT.NULL); + label.setText(columnNames[i]); + oldValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); + oldValues[i].setText(data[i]); + oldValues[i].addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateQuery(); + } + }); + primaryKeys[i] = new Button(container, SWT.CHECK); + primaryKeys[i].setText("Primary Key"); + primaryKeys[i].addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + updateQuery(); + } + }); + newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE); + newValues[i].setText(data[i]); + newValues[i].addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateQuery(); + } + }); + setValues[i] = new Button(container, SWT.CHECK); + setValues[i].setText("Set Value"); + setValues[i].addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + updateQuery(); + } + }); + } + query = new Label(container, SWT.WRAP); + GridData gridData = new GridData(); + gridData.horizontalSpan = layoutColumns; + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + query.setLayoutData(gridData); + + setControl(container); + updateQuery(); + + setPageComplete(true); + } + public void updateQuery() { + if (DEBUG) { + System.out.println("Updating query"); + } + StringBuffer setClause = new StringBuffer(); + StringBuffer whereClause = new StringBuffer(); + for (int i = 0; i < columnNames.length; i++) { + if (primaryKeys[i].getSelection()) { + whereClause.append(columnNames[i]); + whereClause.append(" = "); + whereClause.append(oldValues[i].getText()); + whereClause.append(", "); + } + if (setValues[i].getSelection()) { + setClause.append(columnNames[i]); + setClause.append(" = "); + setClause.append(newValues[i].getText()); + setClause.append(", "); + } + } + if (whereClause.length() > 1) { + whereClause.deleteCharAt(whereClause.length() - 1); + whereClause.deleteCharAt(whereClause.length() - 1); + } + if (setClause.length() > 1) { + setClause.deleteCharAt(setClause.length() - 1); + setClause.deleteCharAt(setClause.length() - 1); + } + String query = "UPDATE " + row.getTable(); + query += " SET " + setClause.toString(); + query += " WHERE " + whereClause.toString(); + this.query.setText(query); + } + public boolean performFinish() { + MultiSQLServer server = MultiSQLServer.getInstance(); + server.execute(query.getText()); + return true; + } } \ No newline at end of file