Skip to content

Commit

Permalink
[APIS-976] JDBC receives the oracle_compat_number_behavior system par…
Browse files Browse the repository at this point in the history
…ameter and removes trailing zeros of double and float types. (#42)

http://jira.cubrid.org/browse/APIS-976

to eliminate user confusion, 2-way expression is unified with the oracle_compat_number_behavior system parameter.
in order for the broker to deliver the value of the system parameters including oracle_compat_number_behavior to the client, the broker extends the broker info that the client receives using the RESERVED field.
Change the CAS Protocol version from PROTOCOL_V11 to PROTOCOL_V12 to express the extension of the above protocol
  • Loading branch information
airnet73 committed Aug 30, 2023
1 parent 365c694 commit 5895f35
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
7 changes: 0 additions & 7 deletions src/jdbc/cubrid/jdbc/driver/ConnectionProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,6 @@ private int getDefaultConnectTimeout() {
IntegerConnectionProperty preparedStmtCacheSqlLimit =
new IntegerConnectionProperty("preparedStmtCacheSqlLimit", 256, 1, Integer.MAX_VALUE);

BooleanConnectionProperty oracleStyleNumberReturn =
new BooleanConnectionProperty("oracleStyleNumberReturn", false);

public boolean getLogOnException() {
return logOnException.getValueAsBoolean();
}
Expand Down Expand Up @@ -494,8 +491,4 @@ public int getPrepStmtCacheSize() {
public int getPrepStmtCacheSqlLimit() {
return preparedStmtCacheSqlLimit.getValueAsInteger();
}

public boolean getOracleStyleNumberReturn() {
return oracleStyleNumberReturn.getValueAsBoolean();
}
}
23 changes: 16 additions & 7 deletions src/jdbc/cubrid/jdbc/jci/UConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,19 @@ public abstract class UConnection {
public static final int PROTOCOL_V9 = 9;

public static final int PROTOCOL_V11 = 11;
public static final int PROTOCOL_V12 = 12;

/* Current protocol version */
protected static final byte CAS_PROTOCOL_VERSION = PROTOCOL_V11;
protected static final byte CAS_PROTOCOL_VERSION = PROTOCOL_V12;
protected static final byte CAS_PROTO_INDICATOR = 0x40;
protected static final byte CAS_PROTO_VER_MASK = 0x3F;
protected static final byte CAS_RENEWED_ERROR_CODE = (byte) 0x80;
protected static final byte CAS_SUPPORT_HOLDABLE_RESULT = (byte) 0x40;
/* Do not remove and rename CAS_RECONNECT_WHEN_SERVER_DOWN */
protected static final byte CAS_RECONNECT_WHEN_SERVER_DOWN = (byte) 0x20;

protected static final byte CAS_ORACLE_COMPAT_NUMBER_BEHAVIOR = (byte) 0x01;

@SuppressWarnings("unused")
private static final byte GET_COLLECTION_VALUE = 1,
GET_SIZE_OF_COLLECTION = 2,
Expand Down Expand Up @@ -159,13 +162,13 @@ public abstract class UConnection {
protected static final int BROKER_INFO_CCI_PCONNECT = 3;
protected static final int BROKER_INFO_PROTO_VERSION = 4;
protected static final int BROKER_INFO_FUNCTION_FLAG = 5;
protected static final int BROKER_INFO_RESERVED2 = 6;
protected static final int BROKER_INFO_SYSTEM_PARAM = 6;
protected static final int BROKER_INFO_RESERVED3 = 7;

/* For backward compatibility */
protected static final int BROKER_INFO_MAJOR_VERSION = BROKER_INFO_PROTO_VERSION;
protected static final int BROKER_INFO_MINOR_VERSION = BROKER_INFO_FUNCTION_FLAG;
protected static final int BROKER_INFO_PATCH_VERSION = BROKER_INFO_RESERVED2;
protected static final int BROKER_INFO_PATCH_VERSION = BROKER_INFO_SYSTEM_PARAM;

public static final String ZERO_DATETIME_BEHAVIOR_CONVERT_TO_NULL = "convertToNull";
public static final String ZERO_DATETIME_BEHAVIOR_EXCEPTION = "exception";
Expand Down Expand Up @@ -1513,10 +1516,6 @@ public boolean isPrepStmtCache(String sql) {
return isCacheable;
}

public boolean getOracleStyleNumberReturn() {
return connectionProperties.getOracleStyleNumberReturn();
}

public void setCasIp(String casIp) {
this.casIp = casIp;
}
Expand Down Expand Up @@ -1713,6 +1712,16 @@ public boolean supportHoldableResult() {
return false;
}

public boolean isOracleCompatNumberBehavior() {
if (protoVersionIsAbove(PROTOCOL_V12)) {
if (brokerInfo == null) return false;
return (brokerInfo[BROKER_INFO_SYSTEM_PARAM] & CAS_ORACLE_COMPAT_NUMBER_BEHAVIOR)
== CAS_ORACLE_COMPAT_NUMBER_BEHAVIOR;
} else {
return false;
}
}

public void setCUBRIDConnection(CUBRIDConnection con) {
cubridcon = con;
lastIsolationLevel = CUBRIDIsolationLevel.TRAN_UNKNOWN_ISOLATION;
Expand Down
9 changes: 5 additions & 4 deletions src/jdbc/cubrid/jdbc/jci/UStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -1510,10 +1510,11 @@ else if (obj instanceof Timestamp) {
} catch (Exception e) {
retValue = null;
}
} else if (relatedConnection.getOracleStyleNumberReturn() && (obj instanceof Double)) {
} else if (relatedConnection.isOracleCompatNumberBehavior()
&& (obj instanceof Double)) {
String numString = obj.toString();
retValue = new BigDecimal(numString).stripTrailingZeros().toPlainString();
} else if (relatedConnection.getOracleStyleNumberReturn() && (obj instanceof Float)) {
} else if (relatedConnection.isOracleCompatNumberBehavior() && (obj instanceof Float)) {
String numString = obj.toString();
retValue = new BigDecimal(numString).stripTrailingZeros().toPlainString();
} else retValue = obj;
Expand Down Expand Up @@ -1584,10 +1585,10 @@ public synchronized String getString(int index) {
if (obj == null) return null;

try {
if (relatedConnection.getOracleStyleNumberReturn() && (obj instanceof Double)) {
if (relatedConnection.isOracleCompatNumberBehavior() && (obj instanceof Double)) {
numString = obj.toString();
return new BigDecimal(numString).stripTrailingZeros().toPlainString();
} else if (relatedConnection.getOracleStyleNumberReturn() && (obj instanceof Float)) {
} else if (relatedConnection.isOracleCompatNumberBehavior() && (obj instanceof Float)) {
numString = obj.toString();
return new BigDecimal(numString).stripTrailingZeros().toPlainString();
} else {
Expand Down

0 comments on commit 5895f35

Please sign in to comment.