Skip to content

Commit

Permalink
[CBRD-24980] Fix wasNull () in ServerSideResultSet of server-side JDBC (
Browse files Browse the repository at this point in the history
#4651) (#4677)

http://jira.cubrid.org/browse/CBRD-24980

Fix wasNull() is not correctly implemented.
- add wasNull array in SUResultTuple was slipped

backport of #4651
  • Loading branch information
hgryoo authored Sep 12, 2023
1 parent 06180fc commit b3dcab9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
30 changes: 26 additions & 4 deletions src/jsp/com/cubrid/jsp/impl/SUResultTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,39 @@
import com.cubrid.jsp.data.CUBRIDUnpacker;
import com.cubrid.jsp.data.SOID;
import com.cubrid.jsp.exception.TypeMismatchException;
import com.cubrid.jsp.value.NullValue;
import com.cubrid.jsp.value.Value;

public class SUResultTuple {
private int index;
private SOID oid;

private Object attributes[];
private boolean wasNull[] = null;

public SUResultTuple(int tupleIndex, int attributeNumber) {
index = tupleIndex;
attributes = new Object[attributeNumber];
wasNull = new boolean[attributeNumber];
}

public SUResultTuple(CUBRIDUnpacker unpacker) throws TypeMismatchException {
index = unpacker.unpackInt();
int attributeLength = unpacker.unpackInt();

attributes = new Object[attributeLength];
wasNull = new boolean[attributeLength];

for (int i = 0; i < attributeLength; i++) {
int paramType = unpacker.unpackInt();
Value v = unpacker.unpackValue(paramType);
attributes[i] = v;

if (v instanceof NullValue) {
wasNull[i] = true;
} else {
wasNull[i] = false;
}
}

oid = unpacker.unpackOID();
Expand All @@ -38,10 +50,10 @@ public void close() {
}

public Object getAttribute(int tIndex) {
/*
* if (tIndex < 0 || attributes == null || tIndex >= attributes.length)
* return null;
*/
if (tIndex < 0 || attributes == null || tIndex >= attributes.length) {
return null;
}

return attributes[tIndex];
}

Expand All @@ -62,6 +74,12 @@ public void setAttribute(int tIndex, Object data) {
*/

attributes[tIndex] = data;

if (data instanceof NullValue) {
wasNull[tIndex] = true;
} else {
wasNull[tIndex] = false;
}
}

public void setOID(SOID o) {
Expand All @@ -71,4 +89,8 @@ public void setOID(SOID o) {
public int tupleNumber() {
return index;
}

public boolean getWasNull(int tIndex) {
return wasNull[tIndex];
}
}
17 changes: 11 additions & 6 deletions src/jsp/com/cubrid/jsp/impl/SUStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,22 @@ private Object beforeGetTuple(int index) throws SQLException {
// GET_BY_OID initialized 1 tuple at constructor
}

Object obj;
SUResultTuple tuple = null;
Object obj = null;

if ((tuples == null)
|| (tuples[cursorPosition - fetchedStartCursorPosition] == null)
|| ((obj = tuples[cursorPosition - fetchedStartCursorPosition].getAttribute(index))
== null)) {
if ((tuples == null) || (tuples[cursorPosition - fetchedStartCursorPosition] == null)) {
return null;
}

tuple = tuples[cursorPosition - fetchedStartCursorPosition];
if (tuple.getAttribute(index) == null) {
// it is error case... but for safe guard
wasNull = true;
return null;
}
wasNull = false;

obj = tuple.getAttribute(index);
wasNull = tuple.getWasNull(index);
return obj;
}

Expand Down
4 changes: 1 addition & 3 deletions src/jsp/com/cubrid/jsp/jdbc/CUBRIDServerSideResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ public class CUBRIDServerSideResultSet implements ResultSet {
/* For findColumn */
protected HashMap<String, Integer> colNameToIdx;

private boolean wasNullValue = false;

private boolean isInserting;
private int currentRowIndex = -1;

Expand Down Expand Up @@ -234,7 +232,7 @@ public void close() throws SQLException {

@Override
public boolean wasNull() throws SQLException {
return wasNullValue;
return statementHandler.getWasNull();
}

@Override
Expand Down

0 comments on commit b3dcab9

Please sign in to comment.