From 357a0b5ccdcb35fc378f39464ecd3c6e67f21171 Mon Sep 17 00:00:00 2001 From: Jeff Wasty Date: Thu, 9 May 2024 10:21:29 -0700 Subject: [PATCH] Cleanup `writeSQLVariant` (removed unused parameter, remove duplicate code, spelling fixes) (#2411) * Changes to writeSQLVariant * Formatting * I forgot how switches work ... * Too much stuff, just keep the bulkScale change * Revert "Too much stuff, just keep the bulkScale change" This reverts commit 583679da2182dbad1365ec6dd7a56a170d0eebd3. --- .../sqlserver/jdbc/SQLServerBulkCopy.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java index e5fa8825e..b868ba5fd 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java @@ -2596,7 +2596,7 @@ else if (4 >= bulkScale) throw new SQLServerException(null, form.format(new Object[] {}), null, 0, false); } writeSqlVariant(tdsWriter, colValue, sourceResultSet, srcColOrdinal, destColOrdinal, bulkJdbcType, - bulkScale, isStreaming); + isStreaming); break; default: MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_BulkTypeNotSupported")); @@ -2622,9 +2622,10 @@ 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, int bulkScale, boolean isStreaming) throws SQLServerException { + int destColOrdinal, int bulkJdbcType, boolean isStreaming) throws SQLServerException { if (null == colValue) { writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming); return; @@ -2633,7 +2634,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 timestamp. so we have to retrieve it again once we are in bulkcopy + // bulkcopy we need it to be a 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); @@ -2671,6 +2672,7 @@ 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 @@ -2680,13 +2682,6 @@ 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)); @@ -2791,9 +2786,8 @@ 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, cause we are - // reading binary - // but in writing it we are using char, we need to get the collation. + // 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. SQLCollation collation = (null != destColumnMetadata.get(srcColOrdinal).collation) ? destColumnMetadata .get(srcColOrdinal).collation : connection.getDatabaseCollation(); variantType.setCollation(collation);