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();
62 for (int i = 0; i < row.getColumnCount(); i++) {
63 System.out.println("data = " + i + "=" + data[i]);
64 System.out.println("column = " + i + "=" + columnNames[i]);
68 whereValues = new Text[row.getColumnCount()];
69 // newValues = new Text[row.getColumnCount()];
70 primaryKeys = new Button[row.getColumnCount()];
71 setValues = new Button[row.getColumnCount()];
72 Label temp = new Label(container, SWT.NULL);
73 temp.setText("Column Name");
74 temp = new Label(container, SWT.NULL);
75 temp.setText("Value");
76 temp = new Label(container, SWT.NULL);
77 temp.setText("Where");
78 // temp = new Label(container, SWT.NULL);
79 // temp.setText("New Value");
80 temp = new Label(container, SWT.NULL);
81 temp.setText("Select");
82 for (int i = 0; i < row.getColumnCount(); i++) {
83 Label label = new Label(container, SWT.NULL);
84 label.setText(columnNames[i]);
85 whereValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
86 if (data[i] == null || data[i].equals("")) {
87 whereValues[i].setText('$' + columnNames[i]);
89 whereValues[i].setText(data[i]);
91 whereValues[i].addModifyListener(new ModifyListener() {
92 public void modifyText(ModifyEvent e) {
97 primaryKeys[i] = new Button(container, SWT.CHECK);
98 //primaryKeys[i].setText("Where Clause");
99 primaryKeys[i].addSelectionListener(new SelectionListener() {
100 public void widgetDefaultSelected(SelectionEvent e) {
102 public void widgetSelected(SelectionEvent e) {
106 // newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
107 // newValues[i].setText(data[i]);
108 // newValues[i].addModifyListener(new ModifyListener() {
109 // public void modifyText(ModifyEvent e) {
113 setValues[i] = new Button(container, SWT.CHECK);
114 //setValues[i].setText("Select Value");
115 setValues[i].addSelectionListener(new SelectionListener() {
116 public void widgetDefaultSelected(SelectionEvent e) {
118 public void widgetSelected(SelectionEvent e) {
123 query = new Label(container, SWT.WRAP);
124 GridData gridData = new GridData();
125 gridData.horizontalSpan = layoutColumns;
126 gridData.horizontalAlignment = GridData.FILL;
127 gridData.verticalAlignment = GridData.FILL;
128 gridData.grabExcessHorizontalSpace = true;
129 gridData.grabExcessVerticalSpace = true;
130 query.setLayoutData(gridData);
132 setControl(container);
135 setPageComplete(true);
138 public void updateQuery() {
140 System.out.println("PHP SELECT");
142 StringBuffer setClause = new StringBuffer();
143 StringBuffer whereClause = new StringBuffer();
145 boolean firstClause = false;
146 for (int i = 0; i < columnNames.length; i++) {
147 if (primaryKeys[i].getSelection()) {
149 whereClause.append(" AND ");
152 whereClause.append(columnNames[i]);
153 whereClause.append(" = ");
154 temp = whereValues[i].getText();
155 // if (temp.charAt(0) == '$') {
156 // whereClause.append(temp);
158 whereClause.append("'" + temp + "'");
162 if (setValues[i].getSelection()) {
163 setClause.append(columnNames[i]);
164 // setClause.append(" = ");
165 // setClause.append(newValues[i].getText());
166 setClause.append(", ");
169 // if (whereClause.length() > 1) {
170 // whereClause.deleteCharAt(whereClause.length() - 1);
171 // whereClause.deleteCharAt(whereClause.length() - 1);
173 if (setClause.length() > 1) {
174 setClause.deleteCharAt(setClause.length() - 1);
175 setClause.deleteCharAt(setClause.length() - 1);
177 String query = "$results = mysql_query(\"SELECT " + setClause.toString();
178 query += " FROM " + row.getTable();
179 query += " WHERE " + whereClause.toString() + "\");";
180 this.query.setText(query);
183 public boolean performFinish() {
184 PHPSourceConsole console = PHPSourceConsole.getInstance();
186 console.print(query.getText());