Skip to content

Commit 0418394

Browse files
author
Suraiya Hameed
committed
use source metadata to send if destination column is not encrypted
1 parent ca59185 commit 0418394

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -799,11 +799,15 @@ private void writeColumnMetaDataColumnData(TDSWriter tdsWriter,
799799
isStreaming = (DataTypes.SHORT_VARTYPE_MAX_BYTES < bulkPrecision) || (DataTypes.SHORT_VARTYPE_MAX_BYTES < destPrecision);
800800
}
801801

802+
CryptoMetadata destCryptoMeta = destColumnMetadata.get(destColumnIndex).cryptoMeta;
803+
802804
/*
803-
* if source is encrypted and destination is unenecrypted use destination sql type to send since there is no way of finding if source is
804-
* encrypted without accessing the resultset, send destination type if source resultset set is of type SQLServer and encryption is enabled
805+
* 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
806+
* encrypted without accessing the resultset.
807+
*
808+
* Send destination type if source resultset set is of type SQLServer, encryption is enabled and destination column is not encrypted
805809
*/
806-
if ((sourceResultSet instanceof SQLServerResultSet) && (connection.isColumnEncryptionSettingEnabled())) {
810+
if ((sourceResultSet instanceof SQLServerResultSet) && (connection.isColumnEncryptionSettingEnabled()) && (null != destCryptoMeta)) {
807811
bulkJdbcType = destColumnMetadata.get(destColumnIndex).jdbcType;
808812
bulkPrecision = destPrecision;
809813
bulkScale = destColumnMetadata.get(destColumnIndex).scale;
@@ -839,8 +843,7 @@ else if (((java.sql.Types.CHAR == bulkJdbcType) || (java.sql.Types.VARCHAR == bu
839843
writeTypeInfo(tdsWriter, bulkJdbcType, bulkScale, bulkPrecision, destSSType, collation, isStreaming, srcNullable, false);
840844
}
841845

842-
CryptoMetadata destCryptoMeta = null;
843-
if ((null != (destCryptoMeta = destColumnMetadata.get(destColumnIndex).cryptoMeta))) {
846+
if (null != destCryptoMeta) {
844847
int baseDestJDBCType = destCryptoMeta.baseTypeInfo.getSSType().getJDBCType().asJavaSqlType();
845848
int baseDestPrecision = destCryptoMeta.baseTypeInfo.getPrecision();
846849

@@ -1268,8 +1271,13 @@ private String getDestTypeFromSrcType(int srcColIndx,
12681271
}
12691272
bulkPrecision = validateSourcePrecision(srcPrecision, bulkJdbcType, destPrecision);
12701273

1271-
// if encrypted source and unencrypted destination combination
1272-
if ((sourceResultSet instanceof SQLServerResultSet) && (connection.isColumnEncryptionSettingEnabled())) {
1274+
/*
1275+
* 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
1276+
* encrypted without accessing the resultset.
1277+
*
1278+
* Send destination type if source resultset set is of type SQLServer, encryption is enabled and destination column is not encrypted
1279+
*/
1280+
if ((sourceResultSet instanceof SQLServerResultSet) && (connection.isColumnEncryptionSettingEnabled()) && (null != destCryptoMeta)) {
12731281
bulkJdbcType = destColumnMetadata.get(destColIndx).jdbcType;
12741282
bulkPrecision = destPrecision;
12751283
bulkScale = destColumnMetadata.get(destColIndx).scale;

0 commit comments

Comments
 (0)