Skip to content

Commit

Permalink
0004929: Fixed SQL explorer row editor when table has no PK (#156)
Browse files Browse the repository at this point in the history
* 0004929: Fixed SQL explorer row editor

* 0004929: Fixed SQL explorer row editor when table has no PK
  • Loading branch information
evan-miller-jumpmind committed Apr 5, 2021
1 parent d27c832 commit afa00dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Expand Up @@ -257,22 +257,15 @@ public static Grid<List<Object>> putResultsInGrid(final ResultSet rs, int maxRes
case Types.REAL:
case Types.NUMERIC:
case Types.DECIMAL:
if (o == null) {
o = new BigDecimal(-1);
}
if (!(o instanceof BigDecimal)) {
if (o != null && !(o instanceof BigDecimal)) {
o = new BigDecimal(castToNumber(o.toString()));
}
break;
case Types.TINYINT:
case Types.SMALLINT:
case Types.BIGINT:
case Types.INTEGER:
if (o == null) {
o = new Long(-1);
}

if (!(o instanceof Long)) {
if (o != null && !(o instanceof Long)) {
o = new Long(castToNumber(o.toString()));
}
break;
Expand Down
Expand Up @@ -281,7 +281,7 @@ public void menuSelected(MenuItem selectedItem) {
types.add(resultTable.getColumnWithName(colName).getMappedTypeCode());
}
}
String sql = buildUpdate(resultTable, colNames, resultTable.getPrimaryKeyColumnNames());
String sql = buildUpdate(resultTable, colNames, unchangedValue[0], resultTable.getPrimaryKeyColumnNames());
log.warn(sql);
Object[] allParams;
int[] allTypes;
Expand All @@ -300,9 +300,11 @@ public void menuSelected(MenuItem selectedItem) {
for (int k = 0; k < unchangedValue[0].size(); k++) {
Object val = unchangedValue[0].get(k);
Column col = resultTable.getColumn(k);
if (col.isRequired() && db.getPlatform().canColumnBeUsedInWhereClause(col)) {
requiredColParams.add(val);
requiredColTypes.add(col.getMappedTypeCode());
if (db.getPlatform().canColumnBeUsedInWhereClause(col)) {
if (!val.equals("<null>")) {
requiredColParams.add(val);
requiredColTypes.add(col.getMappedTypeCode());
}
}
}
allParams = ArrayUtils.addAll(params.toArray(), requiredColParams.toArray());
Expand Down Expand Up @@ -800,7 +802,7 @@ protected String[] getColumnsToExclude() {
return new String[0];
}

protected String buildUpdate(Table table, List<String> columnNames, String[] pkColumnNames) {
protected String buildUpdate(Table table, List<String> columnNames, List<Object> originalValues, String[] pkColumnNames) {
StringBuilder sql = new StringBuilder("update ");
IDatabasePlatform platform = db.getPlatform();
DatabaseInfo dbInfo = platform.getDatabaseInfo();
Expand All @@ -823,12 +825,18 @@ protected String buildUpdate(Table table, List<String> columnNames, String[] pkC
sql.append("=? and ");
}
} else {
for (Column col : table.getColumns()) {
if (col.isRequired() && platform.canColumnBeUsedInWhereClause(col)) {
Column[] cols = table.getColumns();
for (int i = 0; i < originalValues.size(); i++) {
Column col = cols[i];
if (platform.canColumnBeUsedInWhereClause(col)) {
sql.append(quote);
sql.append(col.getName());
sql.append(quote);
sql.append("=? and ");
if (!originalValues.get(i).equals("<null>")) {
sql.append("=? and ");
} else {
sql.append(" is null and ");
}
}
}
}
Expand Down

0 comments on commit afa00dc

Please sign in to comment.