package net.sourceforge.phpdt.sql.wizards;
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
-import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
-import net.sourceforge.phpdt.sql.sql.TableRow;
-import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
-
public class PHPUpdateRowPage extends WizardPage implements SQLPage {
TableRow row;
String[] columnNames;
Label temp = new Label(container, SWT.NULL);
temp.setText("Column Name");
temp = new Label(container, SWT.NULL);
- temp.setText("Old Value");
+ temp.setText("Where Value");
temp = new Label(container, SWT.NULL);
- temp.setText("");
+ temp.setText("Where");
temp = new Label(container, SWT.NULL);
- temp.setText("New Value");
+ temp.setText("Set Value");
temp = new Label(container, SWT.NULL);
- temp.setText("");
+ temp.setText("Set");
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]);
+ if (data[i] == null || data[i].equals("")) {
+ oldValues[i].setText('$' + columnNames[i]);
+ } else {
+ 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].setText("Where");
primaryKeys[i].addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
}
});
newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
- newValues[i].setText(data[i]);
+
+ if (data[i] == null || data[i].equals("")) {
+ newValues[i].setText('$' + columnNames[i]);
+ } else {
+ 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].setText("Set Value");
setValues[i].addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
}
public void updateQuery() {
if (DEBUG) {
- System.out.println("Updating query");
+ System.out.println("Updating update query");
}
StringBuffer setClause = new StringBuffer();
StringBuffer whereClause = new StringBuffer();
if (primaryKeys[i].getSelection()) {
whereClause.append(columnNames[i]);
whereClause.append(" = ");
- whereClause.append(oldValues[i].getText());
+ whereClause.append("'"+oldValues[i].getText()+"'");
whereClause.append(", ");
}
if (setValues[i].getSelection()) {
setClause.append(columnNames[i]);
setClause.append(" = ");
- setClause.append(newValues[i].getText());
+ setClause.append("'"+newValues[i].getText()+"'");
setClause.append(", ");
}
}
setClause.deleteCharAt(setClause.length() - 1);
setClause.deleteCharAt(setClause.length() - 1);
}
- String query = "UPDATE " + row.getTable();
+ String query = "$results = mysql_query(\"UPDATE " + row.getTable();
query += " SET " + setClause.toString();
- query += " WHERE " + whereClause.toString();
+ query += " WHERE " + whereClause.toString() + "\");";
this.query.setText(query);
}
public boolean performFinish() {
- MultiSQLServer server = MultiSQLServer.getInstance();
- server.execute(query.getText());
+ PHPSourceConsole console = PHPSourceConsole.getInstance();
+ console.clear();
+ console.print(query.getText());
return true;
}
}
\ No newline at end of file