Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup writeSQLVariant (removed unused parameter, remove duplicate code, spelling fixes) #2411

Merged
merged 5 commits into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
Loading