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) {
38 System.out.println("page create control");
39 Composite container = new Composite(parent, SWT.NULL);
40 GridLayout layout = new GridLayout();
41 container.setLayout(layout);
42 int layoutColumns = 4;
43 layout.numColumns = layoutColumns;
46 System.out.println("Row is null");
48 if (row.getColumnNames() == null) {
49 System.out.println("Columns are null");
51 if (row.getTableData() == null) {
52 System.out.println("Data is null");
54 columnNames = row.getColumnNames();
55 String[] data = row.getTableData();
56 for (int i = 0; i < row.getColumnCount(); i++) {
57 System.out.println("data = " + i + "=" + data[i]);
58 System.out.println("column = " + i + "=" + columnNames[i]);
60 oldValues = new Text[row.getColumnCount()];
61 // newValues = new Text[row.getColumnCount()];
62 primaryKeys = new Button[row.getColumnCount()];
63 setValues = new Button[row.getColumnCount()];
64 Label temp = new Label(container, SWT.NULL);
65 temp.setText("Column Name");
66 temp = new Label(container, SWT.NULL);
67 temp.setText("Old Value");
68 temp = new Label(container, SWT.NULL);
70 // temp = new Label(container, SWT.NULL);
71 // temp.setText("New Value");
72 temp = new Label(container, SWT.NULL);
74 for (int i = 0; i < row.getColumnCount(); i++) {
75 Label label = new Label(container, SWT.NULL);
76 label.setText(columnNames[i]);
77 oldValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
78 if (data[i] == null || data[i].equals("")) {
79 oldValues[i].setText('$' + columnNames[i]);
81 oldValues[i].setText(data[i]);
83 oldValues[i].addModifyListener(new ModifyListener() {
84 public void modifyText(ModifyEvent e) {
89 primaryKeys[i] = new Button(container, SWT.CHECK);
90 primaryKeys[i].setText("Where Clause");
91 primaryKeys[i].addSelectionListener(new SelectionListener() {
92 public void widgetDefaultSelected(SelectionEvent e) {
94 public void widgetSelected(SelectionEvent e) {
98 // newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
99 // newValues[i].setText(data[i]);
100 // newValues[i].addModifyListener(new ModifyListener() {
101 // public void modifyText(ModifyEvent e) {
105 setValues[i] = new Button(container, SWT.CHECK);
106 setValues[i].setText("Select Value");
107 setValues[i].addSelectionListener(new SelectionListener() {
108 public void widgetDefaultSelected(SelectionEvent e) {
110 public void widgetSelected(SelectionEvent e) {
115 query = new Label(container, SWT.WRAP);
116 GridData gridData = new GridData();
117 gridData.horizontalSpan = layoutColumns;
118 gridData.horizontalAlignment = GridData.FILL;
119 gridData.verticalAlignment = GridData.FILL;
120 gridData.grabExcessHorizontalSpace = true;
121 gridData.grabExcessVerticalSpace = true;
122 query.setLayoutData(gridData);
124 setControl(container);
127 setPageComplete(true);
130 public void updateQuery() {
131 System.out.println("PHP SELECT");
132 StringBuffer setClause = new StringBuffer();
133 StringBuffer whereClause = new StringBuffer();
135 boolean firstClause = false;
136 for (int i = 0; i < columnNames.length; i++) {
137 if (primaryKeys[i].getSelection()) {
139 whereClause.append(" AND ");
142 whereClause.append(columnNames[i]);
143 whereClause.append(" = ");
144 temp = oldValues[i].getText();
145 // if (temp.charAt(0) == '$') {
146 // whereClause.append(temp);
148 whereClause.append("'"+temp+"'");
153 if (setValues[i].getSelection()) {
154 setClause.append(columnNames[i]);
155 // setClause.append(" = ");
156 // setClause.append(newValues[i].getText());
157 setClause.append(", ");
160 // if (whereClause.length() > 1) {
161 // whereClause.deleteCharAt(whereClause.length() - 1);
162 // whereClause.deleteCharAt(whereClause.length() - 1);
164 if (setClause.length() > 1) {
165 setClause.deleteCharAt(setClause.length() - 1);
166 setClause.deleteCharAt(setClause.length() - 1);
168 String query = "$results = mysql_query(\"SELECT " + setClause.toString();
169 query += " FROM " + row.getTable();
170 query += " WHERE " + whereClause.toString() + "\");";
171 this.query.setText(query);
174 public boolean performFinish() {
175 PHPSourceConsole console = PHPSourceConsole.getInstance();
177 console.print(query.getText());