From afa00dcd7abe9f97c43762df64104f1af262ef1c Mon Sep 17 00:00:00 2001 From: evan-miller-jumpmind <70151986+evan-miller-jumpmind@users.noreply.github.com> Date: Mon, 5 Apr 2021 15:56:22 -0400 Subject: [PATCH] 0004929: Fixed SQL explorer row editor when table has no PK (#156) * 0004929: Fixed SQL explorer row editor * 0004929: Fixed SQL explorer row editor when table has no PK --- .../vaadin/ui/common/CommonUiUtils.java | 11 ++------- .../ui/sqlexplorer/TabularResultLayout.java | 24 ++++++++++++------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/CommonUiUtils.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/CommonUiUtils.java index 5eee1a27f9..14efefc27b 100644 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/CommonUiUtils.java +++ b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/common/CommonUiUtils.java @@ -257,10 +257,7 @@ public static Grid> 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; @@ -268,11 +265,7 @@ public static Grid> putResultsInGrid(final ResultSet rs, int maxRes 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; diff --git a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/TabularResultLayout.java b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/TabularResultLayout.java index 94317d2588..39302cb035 100644 --- a/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/TabularResultLayout.java +++ b/symmetric-sqlexplorer/src/main/java/org/jumpmind/vaadin/ui/sqlexplorer/TabularResultLayout.java @@ -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; @@ -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("")) { + requiredColParams.add(val); + requiredColTypes.add(col.getMappedTypeCode()); + } } } allParams = ArrayUtils.addAll(params.toArray(), requiredColParams.toArray()); @@ -800,7 +802,7 @@ protected String[] getColumnsToExclude() { return new String[0]; } - protected String buildUpdate(Table table, List columnNames, String[] pkColumnNames) { + protected String buildUpdate(Table table, List columnNames, List originalValues, String[] pkColumnNames) { StringBuilder sql = new StringBuilder("update "); IDatabasePlatform platform = db.getPlatform(); DatabaseInfo dbInfo = platform.getDatabaseInfo(); @@ -823,12 +825,18 @@ protected String buildUpdate(Table table, List 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("")) { + sql.append("=? and "); + } else { + sql.append(" is null and "); + } } } }