Skip to content

Commit

Permalink
Too much stuff, just keep the bulkScale change
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffery-Wasty committed May 8, 2024
1 parent d4954b6 commit 583679d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2622,7 +2622,6 @@ else if (4 >= bulkScale)
* Writes sql_variant data based on the baseType for bulkcopy
*
* @throws SQLServerException
* an exception
*/
private void writeSqlVariant(TDSWriter tdsWriter, Object colValue, ResultSet sourceResultSet, int srcColOrdinal,
int destColOrdinal, int bulkJdbcType, boolean isStreaming) throws SQLServerException {
Expand All @@ -2634,7 +2633,7 @@ private void writeSqlVariant(TDSWriter tdsWriter, Object colValue, ResultSet sou
int baseType = variantType.getBaseType();
byte[] srcBytes;
// for sql variant we normally should return the colvalue for time as time string. but for
// bulkcopy we need it to be a timestamp. so we have to retrieve it again once we are in bulkcopy
// bulkcopy we need it to be timestamp. so we have to retrieve it again once we are in bulkcopy
// and make sure that the base type is time.
if (TDSType.TIMEN == TDSType.valueOf(baseType)) {
variantType.setIsBaseTypeTimeValue(true);
Expand Down Expand Up @@ -2672,7 +2671,6 @@ private void writeSqlVariant(TDSWriter tdsWriter, Object colValue, ResultSet sou
tdsWriter.writeReal(Float.valueOf(colValue.toString()));
break;

case MONEY4:
case MONEY8:
// For decimalN we right TDSWriter.BIGDECIMAL_MAX_LENGTH as maximum length = 17
// 17 + 2 for basetype and probBytes + 2 for precision and length = 21 the length of data in header
Expand All @@ -2682,6 +2680,13 @@ private void writeSqlVariant(TDSWriter tdsWriter, Object colValue, ResultSet sou
tdsWriter.writeSqlVariantInternalBigDecimal((BigDecimal) colValue, bulkJdbcType);
break;

case MONEY4:
writeBulkCopySqlVariantHeader(21, TDSType.DECIMALN.byteValue(), (byte) 2, tdsWriter);
tdsWriter.writeByte((byte) 38);
tdsWriter.writeByte((byte) 4);
tdsWriter.writeSqlVariantInternalBigDecimal((BigDecimal) colValue, bulkJdbcType);
break;

case BIT1:
writeBulkCopySqlVariantHeader(3, TDSType.BIT1.byteValue(), (byte) 0, tdsWriter);
tdsWriter.writeByte((byte) (((Boolean) colValue).booleanValue() ? 1 : 0));
Expand Down Expand Up @@ -2786,8 +2791,9 @@ private void writeSqlVariant(TDSWriter tdsWriter, Object colValue, ResultSet sou
case GUID:
length = colValue.toString().length();
writeBulkCopySqlVariantHeader(9 + length, TDSType.BIGCHAR.byteValue(), (byte) 7, tdsWriter);
// since while reading collation from sourceMetaData in GUID we don't read collation, because we are
// reading binary, but in writing it we are using char, so we need to get the collation.
// since while reading collation from sourceMetaData in guid we don't read collation, cause we are
// reading binary
// but in writing it we are using char, we need to get the collation.
SQLCollation collation = (null != destColumnMetadata.get(srcColOrdinal).collation) ? destColumnMetadata
.get(srcColOrdinal).collation : connection.getDatabaseCollation();
variantType.setCollation(collation);
Expand Down

0 comments on commit 583679d

Please sign in to comment.