import com.quantum.Messages;
import com.quantum.adapters.DatabaseAdapter;
import com.quantum.model.Bookmark;
+import com.quantum.model.Column;
import com.quantum.model.Entity;
public class UpdateRowPage extends BaseSQLPage implements SQLPage {
Composite container = new Composite(parent, SWT.V_SCROLL);
GridLayout layout = new GridLayout();
container.setLayout(layout);
- Entity entity = row.getEntity();
+ Entity entity = this.results.getEntity();
int layoutColumns = 5;
layout.numColumns = layoutColumns;
- if (row == null) {
- System.out.println("Row is null"); //$NON-NLS-1$
- }
- if (row.getColumnNames() == null) {
- System.out.println("Columns are null"); //$NON-NLS-1$
- }
- if (row.getTableData() == null) {
- System.out.println("Data is null"); //$NON-NLS-1$
- }
- columnNames = row.getColumnNames();
- String[] data = row.getTableData();
- for (int i = 0; i < row.getColumnCount(); i++) {
- System.out.println("data = " + i + "=" + data[i]); //$NON-NLS-1$ //$NON-NLS-2$
- System.out.println("column = " + i + "=" + columnNames[i]); //$NON-NLS-1$ //$NON-NLS-2$
- }
- oldValues = new Text[row.getColumnCount()];
- newValues = new Text[row.getColumnCount()];
- primaryKeys = new Button[row.getColumnCount()];
- setValues = new Button[row.getColumnCount()];
+ columnNames = this.results.getColumnNames();
+ oldValues = new Text[columnNames.length];
+ newValues = new Text[columnNames.length];
+ primaryKeys = new Button[columnNames.length];
+ setValues = new Button[columnNames.length];
Label temp = new Label(container, SWT.NULL);
temp.setText(Messages.getString("UpdateRowPage.ColumnName")); //$NON-NLS-1$
temp = new Label(container, SWT.NULL);
temp.setText(Messages.getString("UpdateRowPage.NewValue")); //$NON-NLS-1$
temp = new Label(container, SWT.NULL);
temp.setText(Messages.getString("UpdateRowPage._13")); //$NON-NLS-1$
- for (int i = 0; i < row.getColumnCount(); i++) {
+ for (int i = 0; i < columnNames.length; i++) {
Label label = new Label(container, SWT.NULL);
label.setText(columnNames[i]);
oldValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
- oldValues[i].setText(data[i]);
+ GridData gridData = new GridData();
+ gridData.widthHint = 100;
+ oldValues[i].setLayoutData(gridData);
+ Object data = this.row == null ? null : this.row.get(i+1);
+ oldValues[i].setText(data == null ? "" : data.toString());
oldValues[i].addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
updateQuery();
});
primaryKeys[i] = new Button(container, SWT.CHECK);
primaryKeys[i].setText("Where"); //$NON-NLS-1$
- if (entity != null && getColumn(entity, columnNames[i]).isPrimaryKey())
+ Column column = (entity == null) ? null : getColumn(entity, columnNames[i]);
+ if (column != null && column.isPrimaryKey())
primaryKeys[i].setSelection(true);
primaryKeys[i].addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
});
newValues[i] = new Text(container, SWT.BORDER | SWT.SINGLE);
- newValues[i].setText(data[i]);
+ newValues[i].setText(data == null ? "" : data.toString());
+ gridData = new GridData();
+ gridData.widthHint = 100;
+ newValues[i].setLayoutData(gridData);
newValues[i].addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
updateQuery();
System.out.println("Updating query"); //$NON-NLS-1$
StringBuffer setClause = new StringBuffer();
StringBuffer whereClause = new StringBuffer();
- Bookmark bookmark = row.getBookmark();
- Entity entity = row.getEntity();
+ Bookmark bookmark = this.results.getBookmark();
+ Entity entity = this.results.getEntity();
DatabaseAdapter adapter = bookmark.getAdapter();
int numValuesSet = 0;
numValuesSet++;
}
}
- String query = "UPDATE " + row.getTable(); //$NON-NLS-1$
+ String query = "UPDATE " + this.results.getEntity().getQuotedTableName(); //$NON-NLS-1$
query += " SET " + setClause.toString(); //$NON-NLS-1$
query += " WHERE " + whereClause.toString(); //$NON-NLS-1$
this.query.setText(query);