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 java.text.MessageFormat;
+import org.eclipse.jface.preference.IPreferenceStore;
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.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 PHPSelectRowPage extends WizardPage implements SQLPage {
TableRow row;
String[] columnNames;
- Text[] oldValues;
+ Text[] whereValues;
// Text[] newValues;
Button[] primaryKeys;
Button[] setValues;
Label query;
+ IPreferenceStore fStore;
public PHPSelectRowPage(String pageName) {
super(pageName);
System.out.println("page create control");
}
Composite container = new Composite(parent, SWT.NULL);
+ fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
+
GridLayout layout = new GridLayout();
container.setLayout(layout);
int layoutColumns = 4;
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]);
- }
+
+ 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()];
+
+ whereValues = 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.setText("Value");
temp = new Label(container, SWT.NULL);
- temp.setText("");
+ temp.setText("Where");
// temp = new Label(container, SWT.NULL);
// temp.setText("New Value");
temp = new Label(container, SWT.NULL);
- temp.setText("");
+ temp.setText("Select");
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);
+ whereValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
if (data[i] == null || data[i].equals("")) {
- oldValues[i].setText('$' + columnNames[i]);
+ whereValues[i].setText('$' + columnNames[i]);
} else {
- oldValues[i].setText(data[i]);
+ whereValues[i].setText(data[i]);
}
- oldValues[i].addModifyListener(new ModifyListener() {
+
+ whereValues[i].addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
updateQuery();
}
});
primaryKeys[i] = new Button(container, SWT.CHECK);
- primaryKeys[i].setText("Where Clause");
+ //primaryKeys[i].setText("Where Clause");
primaryKeys[i].addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
// }
// });
setValues[i] = new Button(container, SWT.CHECK);
- setValues[i].setText("Select Value");
+ //setValues[i].setText("Select Value");
setValues[i].addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
firstClause = true;
whereClause.append(columnNames[i]);
whereClause.append(" = ");
- temp = oldValues[i].getText();
+ temp = whereValues[i].getText();
// if (temp.charAt(0) == '$') {
// whereClause.append(temp);
// } else {
setClause.deleteCharAt(setClause.length() - 1);
setClause.deleteCharAt(setClause.length() - 1);
}
- String query = "$results = mysql_query(\"SELECT " + setClause.toString();
- query += " FROM " + row.getTable();
- query += " WHERE " + whereClause.toString() + "\");";
+
+ String[] arguments = { setClause.toString(), row.getTable(), whereClause.toString()};
+ MessageFormat form = new MessageFormat(fStore.getString("phpeclipse.sql.select.template"));
+
+ String query = form.format(arguments);
+ // String query = "$results = mysql_query(\"SELECT " + setClause.toString();
+ // query += " FROM " + row.getTable();
+ // query += " WHERE " + whereClause.toString() + "\");";
this.query.setText(query);
}