Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-24980] Fix wasNull () in ServerSideResultSet of server-side JDBC (#4651) #4677

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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