From 041839480e012c4481dbc8ed0b78db581adbb682 Mon Sep 17 00:00:00 2001 From: Suraiya Hameed Date: Thu, 16 Feb 2017 16:56:43 -0800 Subject: [PATCH] use source metadata to send if destination column is not encrypted --- .../sqlserver/jdbc/SQLServerBulkCopy.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java index 0a8adae96..2be5d0a37 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java @@ -799,11 +799,15 @@ private void writeColumnMetaDataColumnData(TDSWriter tdsWriter, isStreaming = (DataTypes.SHORT_VARTYPE_MAX_BYTES < bulkPrecision) || (DataTypes.SHORT_VARTYPE_MAX_BYTES < destPrecision); } + CryptoMetadata destCryptoMeta = destColumnMetadata.get(destColumnIndex).cryptoMeta; + /* - * if source is encrypted and destination is unenecrypted use destination sql type to send since there is no way of finding if source is - * encrypted without accessing the resultset, send destination type if source resultset set is of type SQLServer and encryption is enabled + * if source is encrypted and destination is unenecrypted, use destination's sql type to send since there is no way of finding if source is + * encrypted without accessing the resultset. + * + * Send destination type if source resultset set is of type SQLServer, encryption is enabled and destination column is not encrypted */ - if ((sourceResultSet instanceof SQLServerResultSet) && (connection.isColumnEncryptionSettingEnabled())) { + if ((sourceResultSet instanceof SQLServerResultSet) && (connection.isColumnEncryptionSettingEnabled()) && (null != destCryptoMeta)) { bulkJdbcType = destColumnMetadata.get(destColumnIndex).jdbcType; bulkPrecision = destPrecision; bulkScale = destColumnMetadata.get(destColumnIndex).scale; @@ -839,8 +843,7 @@ else if (((java.sql.Types.CHAR == bulkJdbcType) || (java.sql.Types.VARCHAR == bu writeTypeInfo(tdsWriter, bulkJdbcType, bulkScale, bulkPrecision, destSSType, collation, isStreaming, srcNullable, false); } - CryptoMetadata destCryptoMeta = null; - if ((null != (destCryptoMeta = destColumnMetadata.get(destColumnIndex).cryptoMeta))) { + if (null != destCryptoMeta) { int baseDestJDBCType = destCryptoMeta.baseTypeInfo.getSSType().getJDBCType().asJavaSqlType(); int baseDestPrecision = destCryptoMeta.baseTypeInfo.getPrecision(); @@ -1268,8 +1271,13 @@ private String getDestTypeFromSrcType(int srcColIndx, } bulkPrecision = validateSourcePrecision(srcPrecision, bulkJdbcType, destPrecision); - // if encrypted source and unencrypted destination combination - if ((sourceResultSet instanceof SQLServerResultSet) && (connection.isColumnEncryptionSettingEnabled())) { + /* + * if source is encrypted and destination is unenecrypted, use destination's sql type to send since there is no way of finding if source is + * encrypted without accessing the resultset. + * + * Send destination type if source resultset set is of type SQLServer, encryption is enabled and destination column is not encrypted + */ + if ((sourceResultSet instanceof SQLServerResultSet) && (connection.isColumnEncryptionSettingEnabled()) && (null != destCryptoMeta)) { bulkJdbcType = destColumnMetadata.get(destColIndx).jdbcType; bulkPrecision = destPrecision; bulkScale = destColumnMetadata.get(destColIndx).scale;