diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index 926ebccbe..2ae393ccf 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -4865,7 +4865,7 @@ void writeRPCStringUnicode(String sValue) throws SQLServerException { } void writeRPCJSON(String sValue) throws SQLServerException { - writeRPCJSON(null, sValue, false, null); + writeRPCJSON(null, sValue, true, null); } /** * Writes a string value as Unicode for RPC @@ -4933,50 +4933,22 @@ void writeRPCJSON(String sName, String sValue, boolean bOut, SQLCollation collation) throws SQLServerException { boolean bValueNull = (sValue == null); int nValueLen = bValueNull ? 0 : (2 * sValue.length()); - // Textual RPC requires a collation. If none is provided, as is the case when - // the SSType is non-textual, then use the database collation by default. - // if (null == collation) - // collation = con.getDatabaseCollation(); - - /* - * Use PLP encoding if either OUT params were specified or if the user query exceeds - * DataTypes.SHORT_VARTYPE_MAX_BYTES - */ - if (nValueLen > DataTypes.SHORT_VARTYPE_MAX_BYTES || bOut) { - writeRPCNameValType(sName, bOut, TDSType.JSON); - - writeVMaxHeader(nValueLen, // Length - bValueNull, // Is null? - collation); - - // Send the data. - if (!bValueNull) { - if (nValueLen > 0) { - writeInt(nValueLen); - writeString(sValue); - } - - // Send the terminator PLP chunk. - writeInt(0); - } - } else { // non-PLP type - // Write maximum length of data - writeRPCNameValType(sName, bOut, TDSType.JSON); - writeShort((short) DataTypes.UNKNOWN_STREAM_LENGTH); - - // collation.writeCollation(this); - - // Data and length - if (bValueNull) { - writeShort((short) -1); // actual len - } else { - // Write actual length of data - writeShort((short) nValueLen); - - // If length is zero, we're done. - if (0 != nValueLen) - writeString(sValue); // data + + writeRPCNameValType(sName, bOut, TDSType.JSON); + + writeVMaxHeader(nValueLen, // Length + bValueNull, // Is null? + null); // For JSON test code POC, JSON does not have collation value + + // Send the data. + if (!bValueNull) { + if (nValueLen > 0) { + writeInt(nValueLen); + writeString(sValue); } + + // Send the terminator PLP chunk. + writeInt(0); } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java index 8e18f6199..ecbc188f9 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java @@ -919,7 +919,7 @@ private void buildExecSQLParams(TDSWriter tdsWriter) throws SQLServerException { // IN if (preparedTypeDefinitions.length() > 0) - tdsWriter.writeRPCStringUnicode(preparedTypeDefinitions); + tdsWriter.writeRPCStringUnicode(preparedTypeDefinitions); } private void buildServerCursorExecParams(TDSWriter tdsWriter) throws SQLServerException { diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java b/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java index ece51d16a..959436863 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/dtv.java @@ -298,10 +298,22 @@ void execute(DTV dtv, String strValue) throws SQLServerException { if (dtv.getJdbcType() == JDBCType.GUID) { tdsWriter.writeRPCUUID(name, UUID.fromString(strValue), isOutParam); } - else if (dtv.getJdbcType() == JDBCType.JSON) { - tdsWriter.writeRPCJSON(name, strValue, isOutParam, collation); - } + // else if (dtv.getJdbcType() == JDBCType.JSON) { + // /* If you enble the following code, you will get the following exception: + // * FINE: *** SQLException: com.microsoft.sqlserver.jdbc.SQLServerException: The incoming + // * tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. + // * Parameter 3 (""): JSON data type is not supported in TDS on the server side. + // */ + // tdsWriter.writeRPCJSON(name, strValue, isOutParam, collation); + // } else { + /* + * For JSON type, if we use below method then we get the below error: + * FINE: *** SQLException: com.microsoft.sqlserver.jdbc.SQLServerException: Implicit conversion + * from data type json to nvarchar(max) is not allowed. Use the CONVERT function to run this query. + * Msg 257, Level 16, State 3, Implicit conversion from data type + * json to nvarchar(max) is not allowed. + */ tdsWriter.writeRPCStringUnicode(name, strValue, isOutParam, collation); } } @@ -1531,8 +1543,8 @@ final void executeOp(DTVExecuteOp op) throws SQLServerException { case LONGVARCHAR: case CLOB: //case JSON: - op.execute(this, (byte[]) null); - break; + // op.execute(this, (byte[]) null); + // break; case GUID: if (null != cryptoMeta) @@ -1613,6 +1625,7 @@ final void executeOp(DTVExecuteOp op) throws SQLServerException { switch (javaType) { case STRING: + case JSON: if (JDBCType.GUID == jdbcType) { if (null != cryptoMeta) { if (value instanceof String) { @@ -1900,9 +1913,9 @@ else if ((JDBCType.VARCHAR == jdbcTypeSetByUser) || (JDBCType.CHAR == jdbcTypeSe op.execute(this, (SQLServerSQLXML) value); break; - case JSON: - op.execute(this, (SQLServerSQLJSON) value); - break; + // case JSON: + // op.execute(this, (SQLServerSQLJSON) value); + // break; default: assert false : "Unexpected JavaType: " + javaType;