Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-519] Updatable result-set possible NPE when same field is repea…
…ted.
  • Loading branch information
rusher committed Aug 30, 2017
1 parent 0932c58 commit 60cf61d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Expand Up @@ -204,7 +204,6 @@ private void checkIfUpdatable(Results results) throws SQLException {
updatableColumns[index] = new UpdatableColumnInformation(
columnInformation, canBeNull, hasDefault, generated, primary, autoIncrement);
found = true;
break;
}
}

Expand Down Expand Up @@ -239,15 +238,16 @@ private void checkIfUpdatable(Results results) throws SQLException {
canBeRefresh = true;
}

boolean ensureAllColumnHaveMeta = true;
for (int index = 0; index < columnInformationLength; index++) {
if (updatableColumns[index] == null) {
//abnormal error : some field in META are not listed in SHOW COLUMNS
cannotUpdateInsertRow("Metadata information not available for table `"
+ database + "`.`" + table + "`, field `" + columnsInformation[index].getOriginalName() + "`");
ensureAllColumnHaveMeta = false;
}
}

columnsInformation = updatableColumns;
if (ensureAllColumnHaveMeta) columnsInformation = updatableColumns;
} else {
throw new SQLException("abnormal error : connection is null");
}
Expand Down Expand Up @@ -312,8 +312,6 @@ public void updateNull(String columnLabel) throws SQLException {
*/
public void updateBoolean(int columnIndex, boolean bool) throws SQLException {
checkUpdatable(columnIndex);


parameterHolders[columnIndex - 1] = new ByteParameter(bool ? (byte) 1 : (byte) 0);
}

Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/mariadb/jdbc/UpdateResultSetTest.java
Expand Up @@ -890,4 +890,22 @@ public void updatePosTest() throws SQLException {

}
}

/**
* CONJ-519 : Updatable result-set possible NPE when same field is repeated.
* @throws SQLException
*/
@Test
public void repeatedFieldUpdatable() throws SQLException {
createTable("repeatedFieldUpdatable", "t1 varchar(50) NOT NULL, t2 varchar(50), PRIMARY KEY (t1)");

Statement stmt = sharedConnection.createStatement();
stmt.execute("insert into repeatedFieldUpdatable values ('gg', 'hh'), ('jj', 'll')");

PreparedStatement preparedStatement = sharedConnection.prepareStatement("SELECT t1, t2, t1 as t3 FROM repeatedFieldUpdatable", ResultSet.FETCH_FORWARD, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
rs.getObject(3);
}
}
}

0 comments on commit 60cf61d

Please sign in to comment.