import java.text.MessageFormat;
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-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.preference.IPreferenceStore;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.sql.TableRow;
+import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
+import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
+
public class PHPUpdateRowPage extends WizardPage implements SQLPage {
TableRow row;
String[] columnNames;
Button[] setValues;
Label query;
IPreferenceStore fStore;
-
+
public PHPUpdateRowPage(String pageName) {
super(pageName);
}
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()];
}
});
primaryKeys[i] = new Button(container, SWT.CHECK);
- // primaryKeys[i].setText("Where");
+ // primaryKeys[i].setText("Where");
primaryKeys[i].addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
}
});
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) {
}
setPageComplete(true);
}
+
public void updateQuery() {
if (DEBUG) {
System.out.println("Updating update 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("'" + 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[] arguments = { setClause.toString(), row.getTable(), whereClause.toString() };
+ String[] arguments = { row.getTable(), setClause.toString(), whereClause.toString()};
MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.update.template"));
String query = form.format(arguments);
-//
-// String query = "$results = mysql_query(\"UPDATE " + row.getTable();
-// query += " SET " + setClause.toString();
-// query += " WHERE " + whereClause.toString() + "\");";
+ //
+ // String query = "$results = mysql_query(\"UPDATE " + row.getTable();
+ // query += " SET " + setClause.toString();
+ // query += " WHERE " + whereClause.toString() + "\");";
this.query.setText(query);
}
public boolean performFinish() {