1 package net.sourceforge.phpdt.sql.wizards;
3 import net.sourceforge.phpdt.sql.sql.TableRow;
4 import net.sourceforge.phpdt.sql.view.PHPSourceConsole;
5 import net.sourceforge.phpdt.sql.view.tableview.TableAdapter;
7 import org.eclipse.jface.wizard.WizardPage;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.events.ModifyEvent;
10 import org.eclipse.swt.events.ModifyListener;
11 import org.eclipse.swt.events.SelectionEvent;
12 import org.eclipse.swt.events.SelectionListener;
13 import org.eclipse.swt.layout.GridData;
14 import org.eclipse.swt.layout.GridLayout;
15 import org.eclipse.swt.widgets.Button;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Label;
18 import org.eclipse.swt.widgets.Text;
20 public class PHPSelectRowPage extends WizardPage implements SQLPage {
29 public PHPSelectRowPage(String pageName) {
33 public void init(TableRow row, TableAdapter adapter) {
37 public void createControl(Composite parent) {
39 System.out.println("page create control");
41 Composite container = new Composite(parent, SWT.NULL);
42 GridLayout layout = new GridLayout();
43 container.setLayout(layout);
44 int layoutColumns = 4;
45 layout.numColumns = layoutColumns;
49 System.out.println("Row is null");
51 if (row.getColumnNames() == null) {
52 System.out.println("Columns are null");
54 if (row.getTableData() == null) {
55 System.out.println("Data is null");
58 columnNames = row.getColumnNames();
59 String[] data = row.getTableData();
61 for (int i = 0; i < row.getColumnCount(); i++) {
62 System.out.println("data = " + i + "=" + data[i]);
63 System.out.println("column = " + i + "=" + columnNames[i]);
66 oldValues = new Text[row.getColumnCount()];
67 // newValues = new Text[row.getColumnCount()];
68 primaryKeys = new Button[row.getColumnCount()];
69 setValues = new Button[row.getColumnCount()];
70 Label temp = new Label(container, SWT.NULL);
71 temp.setText("Column Name");
72 temp = new Label(container, SWT.NULL);
73 temp.setText("Old Value");
74 temp = new Label(container, SWT.NULL);
76 // temp = new Label(container, SWT.NULL);
77 // temp.setText("New Value");
78 temp = new Label(container, SWT.NULL);
80 for (int i = 0; i < row.getColumnCount(); i++) {
81 Label label = new Label(container, SWT.NULL);
82 label.setText(columnNames[i]);
83 oldValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
84 if (data[i] == null || data[i].equals("")) {
85 oldValues[i].setText('$' + columnNames[i]);
87 oldValues[i].setText(data[i]);
89 oldValues[i].addModifyListener(new ModifyListener() {
90 public void modifyText(ModifyEvent e) {
95 primaryKeys[i] = new Button(container, SWT.CHECK);
96 primaryKeys[i].setText("Where Clause");
97 primaryKeys[i].addSelectionListener(new SelectionListener() {
98 public void widgetDefaultSelected(SelectionEvent e) {
100 public void widgetSelected(SelectionEvent e) {
104 // newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
105 // newValues[i].setText(data[i]);
106 // newValues[i].addModifyListener(new ModifyListener() {
107 // public void modifyText(ModifyEvent e) {
111 setValues[i] = new Button(container, SWT.CHECK);
112 setValues[i].setText("Select Value");
113 setValues[i].addSelectionListener(new SelectionListener() {
114 public void widgetDefaultSelected(SelectionEvent e) {
116 public void widgetSelected(SelectionEvent e) {
121 query = new Label(container, SWT.WRAP);
122 GridData gridData = new GridData();
123 gridData.horizontalSpan = layoutColumns;
124 gridData.horizontalAlignment = GridData.FILL;
125 gridData.verticalAlignment = GridData.FILL;
126 gridData.grabExcessHorizontalSpace = true;
127 gridData.grabExcessVerticalSpace = true;
128 query.setLayoutData(gridData);
130 setControl(container);
133 setPageComplete(true);
136 public void updateQuery() {
138 System.out.println("PHP SELECT");
140 StringBuffer setClause = new StringBuffer();
141 StringBuffer whereClause = new StringBuffer();
143 boolean firstClause = false;
144 for (int i = 0; i < columnNames.length; i++) {
145 if (primaryKeys[i].getSelection()) {
147 whereClause.append(" AND ");
150 whereClause.append(columnNames[i]);
151 whereClause.append(" = ");
152 temp = oldValues[i].getText();
153 // if (temp.charAt(0) == '$') {
154 // whereClause.append(temp);
156 whereClause.append("'" + temp + "'");
160 if (setValues[i].getSelection()) {
161 setClause.append(columnNames[i]);
162 // setClause.append(" = ");
163 // setClause.append(newValues[i].getText());
164 setClause.append(", ");
167 // if (whereClause.length() > 1) {
168 // whereClause.deleteCharAt(whereClause.length() - 1);
169 // whereClause.deleteCharAt(whereClause.length() - 1);
171 if (setClause.length() > 1) {
172 setClause.deleteCharAt(setClause.length() - 1);
173 setClause.deleteCharAt(setClause.length() - 1);
175 String query = "$results = mysql_query(\"SELECT " + setClause.toString();
176 query += " FROM " + row.getTable();
177 query += " WHERE " + whereClause.toString() + "\");";
178 this.query.setText(query);
181 public boolean performFinish() {
182 PHPSourceConsole console = PHPSourceConsole.getInstance();
184 console.print(query.getText());