Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)

## [7.4.1] HotFix & Stable Release
### Fixed Issues
- Reverted [#1025](https://github.com/Microsoft/mssql-jdbc/pull/1025) as it contains breaking changes. This removes `hashCode()` and `equals()` APIs from `SQLServerDataTable` and `SQLServerDataColumn`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted #1025 as it changes API definition for SQLServerDataTable.getIterator() that causes breaking change. This change also removes hashCode() and equals() APIs from SQLServerDataTable and SQLServerDataColumn.


## [7.4.0] Stable Release
### Fixed Issues
- Fixed issues reported by Static Analysis Tool - SonarQube [#1077](https://github.com/Microsoft/mssql-jdbc/pull/1077) [#1103](https://github.com/Microsoft/mssql-jdbc/pull/1103)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ We're now on the Maven Central Repository. Add the following to your POM file to
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.4.0.jre12</version>
<version>7.4.1.jre12</version>
</dependency>
```
The driver can be downloaded from the [Microsoft Download Center](https://go.microsoft.com/fwlink/?linkid=868287).
Expand Down Expand Up @@ -127,7 +127,7 @@ Projects that require either of the two features need to explicitly declare the
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.4.0.jre12</version>
<version>7.4.1.jre12</version>
<scope>compile</scope>
</dependency>

Expand All @@ -150,7 +150,7 @@ Projects that require either of the two features need to explicitly declare the
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.4.0.jre12</version>
<version>7.4.1.jre12</version>
<scope>compile</scope>
</dependency>

Expand Down Expand Up @@ -183,7 +183,7 @@ When setting 'useFmtOnly' property to 'true' for establishing a connection or cr
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.4.0.jre12</version>
<version>7.4.1.jre12</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

apply plugin: 'java'

version = '7.4.0'
version = '7.4.1'
def jreVersion = ""
def testOutputDir = file("build/classes/java/test")
def archivesBaseName = 'mssql-jdbc'
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.4.0</version>
<version>7.4.1</version>
<packaging>jar</packaging>

<name>Microsoft JDBC Driver for SQL Server</name>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4596,7 +4596,7 @@ void writeTVPRows(TVP value) throws SQLServerException {
writeBytes(cachedTVPHeaders.array(), 0, ((Buffer) cachedTVPHeaders).position());
}

List<Object> rowData = value.getRowData();
Object[] rowData = value.getRowData();

// ROW
writeByte((byte) TDS.TVP_ROW);
Expand All @@ -4618,8 +4618,8 @@ void writeTVPRows(TVP value) throws SQLServerException {
if (null != rowData) {
// if rowData has value for the current column, retrieve it. If not, current column will stay
// null.
if (rowData.size() > currentColumn) {
currentObject = rowData.get(currentColumn);
if (rowData.length > currentColumn) {
currentObject = rowData[currentColumn];
if (null != currentObject) {
currentColumnStringValue = String.valueOf(currentObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package com.microsoft.sqlserver.jdbc;

import java.util.List;

/**
* Provides an interface to create classes that read in data from any source (such as a file) and allow a structured
* type to be sent to SQL Server tables.
Expand Down Expand Up @@ -36,7 +34,7 @@ public interface ISQLServerDataRecord {
*
* @return The data for the row.
*/
public List<Object> getRowData();
public Object[] getRowData();

/**
* Advances to the next data row.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
final class SQLJdbcVersion {
static final int major = 7;
static final int minor = 4;
static final int patch = 0;
static final int patch = 1;
static final int build = 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,4 @@ public String getColumnName() {
public int getColumnType() {
return javaSqlType;
}

@Override
public int hashCode() {
int hash = 7;
hash = 31 * hash + javaSqlType;
hash = 31 * hash + precision;
hash = 31 * hash + scale;
hash = 31 * hash + numberOfDigitsIntegerPart;
hash = 31 * hash + (null != columnName ? columnName.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}

if (null != object && object.getClass() == SQLServerDataColumn.class) {
SQLServerDataColumn aSQLServerDataColumn = (SQLServerDataColumn) object;
if (hashCode() == aSQLServerDataColumn.hashCode()) {
// Compare objects to avoid collision
return ((null == columnName && null == aSQLServerDataColumn.columnName
|| columnName.equals(aSQLServerDataColumn.columnName))
&& javaSqlType == aSQLServerDataColumn.javaSqlType
&& numberOfDigitsIntegerPart == aSQLServerDataColumn.numberOfDigitsIntegerPart
&& precision == aSQLServerDataColumn.precision && scale == aSQLServerDataColumn.scale);
}
}
return false;
}
}
72 changes: 17 additions & 55 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
Expand All @@ -30,7 +28,7 @@ public final class SQLServerDataTable {
int columnCount = 0;
Map<Integer, SQLServerDataColumn> columnMetadata = null;
Set<String> columnNames = null;
Map<Integer, List<Object>> rows = null;
Map<Integer, Object[]> rows = null;
private String tvpName = null;

/**
Expand Down Expand Up @@ -63,7 +61,7 @@ public synchronized void clear() {
*
* @return an iterator on the rows of the data table.
*/
public synchronized Iterator<Entry<Integer, List<Object>>> getIterator() {
public synchronized Iterator<Entry<Integer, Object[]>> getIterator() {
if ((null != rows) && (null != rows.entrySet())) {
return rows.entrySet().iterator();
}
Expand Down Expand Up @@ -120,7 +118,7 @@ public synchronized void addRow(Object... values) throws SQLServerException {
}

Iterator<Entry<Integer, SQLServerDataColumn>> columnsIterator = columnMetadata.entrySet().iterator();
List<Object> rowValues = new LinkedList<>();
Object[] rowValues = new Object[columnCount];
int currentColumn = 0;
while (columnsIterator.hasNext()) {
Object val = null;
Expand Down Expand Up @@ -155,30 +153,29 @@ public synchronized void addRow(Object... values) throws SQLServerException {
* @throws SQLServerException
* when an error occurs
*/
private void internalAddrow(JDBCType jdbcType, Object val, List<Object> rowValues,
private void internalAddrow(JDBCType jdbcType, Object val, Object[] rowValues,
Map.Entry<Integer, SQLServerDataColumn> pair) throws SQLServerException {
int key = pair.getKey();
rowValues.add(key, val);

if (null != val) {
SQLServerDataColumn currentColumnMetadata = pair.getValue();
int nValueLen;

switch (jdbcType) {
case BIGINT:
rowValues.set(key, (val instanceof Long) ? val : Long.parseLong(val.toString()));
rowValues[key] = (val instanceof Long) ? val : Long.parseLong(val.toString());
break;

case BIT:
if (val instanceof Boolean) {
rowValues.set(key, val);
rowValues[key] = val;
} else {
String valString = val.toString();

if ("0".equals(valString) || valString.equalsIgnoreCase(Boolean.FALSE.toString())) {
rowValues.set(key, Boolean.FALSE);
rowValues[key] = Boolean.FALSE;
} else if ("1".equals(valString) || valString.equalsIgnoreCase(Boolean.TRUE.toString())) {
rowValues.set(key, Boolean.TRUE);
rowValues[key] = Boolean.TRUE;
} else {
MessageFormat form = new MessageFormat(
SQLServerException.getErrString("R_TVPInvalidColumnValue"));
Expand All @@ -189,12 +186,12 @@ private void internalAddrow(JDBCType jdbcType, Object val, List<Object> rowValue
break;

case INTEGER:
rowValues.set(key, (val instanceof Integer) ? val : Integer.parseInt(val.toString()));
rowValues[key] = (val instanceof Integer) ? val : Integer.parseInt(val.toString());
break;

case SMALLINT:
case TINYINT:
rowValues.set(key, (val instanceof Short) ? val : Short.parseShort(val.toString()));
rowValues[key] = (val instanceof Short) ? val : Short.parseShort(val.toString());
break;

case DECIMAL:
Expand Down Expand Up @@ -226,16 +223,16 @@ private void internalAddrow(JDBCType jdbcType, Object val, List<Object> rowValue
+ currentColumnMetadata.numberOfDigitsIntegerPart;
columnMetadata.put(pair.getKey(), currentColumnMetadata);
}
rowValues.set(key, bd);
rowValues[key] = bd;
break;

case DOUBLE:
rowValues.set(key, (val instanceof Double) ? val : Double.parseDouble(val.toString()));
rowValues[key] = (val instanceof Double) ? val : Double.parseDouble(val.toString());
break;

case FLOAT:
case REAL:
rowValues.set(key, (val instanceof Float) ? val : Float.parseFloat(val.toString()));
rowValues[key] = (val instanceof Float) ? val : Float.parseFloat(val.toString());
break;

case TIMESTAMP_WITH_TIMEZONE:
Expand All @@ -253,9 +250,9 @@ private void internalAddrow(JDBCType jdbcType, Object val, List<Object> rowValue
// java.sql.Date, java.sql.Time and java.sql.Timestamp are subclass of java.util.Date
if (val instanceof java.util.Date || val instanceof microsoft.sql.DateTimeOffset
|| val instanceof OffsetDateTime || val instanceof OffsetTime)
rowValues.set(key, val.toString());
rowValues[key] = val.toString();
else
rowValues.set(key, val);
rowValues[key] = val;
break;

case BINARY:
Expand All @@ -267,7 +264,7 @@ private void internalAddrow(JDBCType jdbcType, Object val, List<Object> rowValue
currentColumnMetadata.precision = nValueLen;
columnMetadata.put(pair.getKey(), currentColumnMetadata);
}
rowValues.set(key, val);
rowValues[key] = val;
break;

case CHAR:
Expand All @@ -285,7 +282,7 @@ private void internalAddrow(JDBCType jdbcType, Object val, List<Object> rowValue
currentColumnMetadata.precision = nValueLen;
columnMetadata.put(pair.getKey(), currentColumnMetadata);
}
rowValues.set(key, val);
rowValues[key] = val;
break;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At Line 301, in the else block before the condition, you need to assign rowValues[key] = null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that needed to happen. rowValues[key] would have already been null since nothing else would have set it.

case SQL_VARIANT:
Expand Down Expand Up @@ -336,39 +333,4 @@ public String getTvpName() {
public void setTvpName(String tvpName) {
this.tvpName = tvpName;
}

@Override
public int hashCode() {
int hash = 7;
hash = 31 * hash + rowCount;
hash = 31 * hash + columnCount;
hash = 31 * hash + (null != columnMetadata ? columnMetadata.hashCode() : 0);
hash = 31 * hash + (null != columnNames ? columnNames.hashCode() : 0);
hash = 31 * hash + (null != rows ? rows.hashCode() : 0);
hash = 31 * hash + (null != tvpName ? tvpName.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}

if (null != object && object.getClass() == SQLServerDataTable.class) {
SQLServerDataTable aSQLServerDataTable = (SQLServerDataTable) object;
if (hashCode() == aSQLServerDataTable.hashCode()) {

// Compare objects to avoid collision
boolean equalColumnMetadata = columnMetadata.equals(aSQLServerDataTable.columnMetadata);
boolean equalColumnNames = columnNames.equals(aSQLServerDataTable.columnNames);
boolean equalRowData = rows.equals(aSQLServerDataTable.rows);

return (rowCount == aSQLServerDataTable.rowCount && columnCount == aSQLServerDataTable.columnCount
&& tvpName == aSQLServerDataTable.tvpName && equalColumnMetadata && equalColumnNames
&& equalRowData);
}
}
return false;
}
}
14 changes: 6 additions & 8 deletions src/main/java/com/microsoft/sqlserver/jdbc/TVP.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
Expand Down Expand Up @@ -52,7 +50,7 @@ class TVP {
ResultSet sourceResultSet = null;
SQLServerDataTable sourceDataTable = null;
Map<Integer, SQLServerMetaData> columnMetadata = null;
Iterator<Entry<Integer, List<Object>>> sourceDataTableRowIterator = null;
Iterator<Entry<Integer, Object[]>> sourceDataTableRowIterator = null;
ISQLServerDataRecord sourceRecord = null;
TVPType tvpType = null;
Set<String> columnNames = null;
Expand Down Expand Up @@ -111,28 +109,28 @@ boolean isNull() {
return (TVPType.Null == tvpType);
}

List<Object> getRowData() throws SQLServerException {
Object[] getRowData() throws SQLServerException {
if (TVPType.ResultSet == tvpType) {
int colCount = columnMetadata.size();
List<Object> rowData = new ArrayList<>();
Object[] rowData = new Object[colCount];
for (int i = 0; i < colCount; i++) {
try {
/*
* for Time types, getting TimeStamp instead of Time, because this value will be converted to String
* later on. If the value is a time object, the millisecond would be removed.
*/
if (java.sql.Types.TIME == sourceResultSet.getMetaData().getColumnType(i + 1)) {
rowData.add(i,sourceResultSet.getTimestamp(i + 1));
rowData[i] = sourceResultSet.getTimestamp(i + 1);
} else {
rowData.add(i,sourceResultSet.getObject(i + 1));
rowData[i] = sourceResultSet.getObject(i + 1);
}
} catch (SQLException e) {
throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), e);
}
}
return rowData;
} else if (TVPType.SQLServerDataTable == tvpType) {
Map.Entry<Integer, List<Object>> rowPair = sourceDataTableRowIterator.next();
Map.Entry<Integer, Object[]> rowPair = sourceDataTableRowIterator.next();
return rowPair.getValue();
} else
return sourceRecord.getRowData();
Expand Down
Loading