Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c97b863
Fix AEv2 tests exclude for reqExternalSetup and cleanup (#1247)
lilgreenbird Feb 5, 2020
54b5a19
Fix | Add null check for getObject() with LocalTime and LocalDate (#1…
peterbae Feb 8, 2020
672b7d6
added all AKV tests to use reqExternalSetup tag so they will be skipp…
lilgreenbird Feb 10, 2020
3c3331b
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Mar 25, 2020
e2c5640
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Mar 26, 2020
aad6966
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Mar 28, 2020
92bf04c
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Mar 31, 2020
3ba5ab7
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Apr 4, 2020
d20823d
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Apr 7, 2020
4cc959f
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Apr 29, 2020
7b301f8
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Apr 30, 2020
56bcf13
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird May 7, 2020
744e0ca
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird May 12, 2020
df8fd41
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird May 19, 2020
652e68b
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird May 26, 2020
53736db
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird May 26, 2020
9ba6a42
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 2, 2020
6d156f7
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 5, 2020
e08ffe5
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 10, 2020
6b6cab2
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 18, 2020
c202590
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 24, 2020
0515d4b
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 24, 2020
2c63b58
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jun 25, 2020
78aa941
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jul 2, 2020
90e99cd
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jul 2, 2020
da1004b
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jul 6, 2020
9ca1284
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Jul 28, 2020
c67d8ed
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Aug 1, 2020
1d0a4ad
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Aug 5, 2020
f1b1dfb
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Aug 26, 2020
d9bad87
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Sep 2, 2020
a2e50b9
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Sep 9, 2020
7ff97de
enable ADintegrated tests for non-windows
lilgreenbird Sep 9, 2020
7cae3b4
fixed user test for kerberos
lilgreenbird Sep 11, 2020
c8c5a29
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Sep 16, 2020
d76368a
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Sep 22, 2020
e5aafd3
Merge branch 'dev' of https://github.com/lilgreenbird/mssql-jdbc into…
lilgreenbird Sep 22, 2020
7800824
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Oct 5, 2020
a8199bb
merged
lilgreenbird Oct 14, 2020
3a91ea1
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Oct 16, 2020
3e39be1
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Oct 28, 2020
16d2bbd
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Nov 28, 2020
f9d22e9
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Dec 2, 2020
8eeb9a6
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Dec 8, 2020
e950394
removed trim
lilgreenbird Dec 8, 2020
70a8cb9
Merge remote-tracking branch 'upstream/dev' into bulkcopy
lilgreenbird Jan 5, 2021
f5e2616
add test
lilgreenbird Jan 6, 2021
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
54 changes: 24 additions & 30 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void addColumnMapping(int sourceColumn, String destinationColumn) throws
} else if (null == destinationColumn || destinationColumn.isEmpty()) {
throwInvalidArgument("destinationColumn");
}
columnMappings.add(new ColumnMapping(sourceColumn, destinationColumn.trim()));
columnMappings.add(new ColumnMapping(sourceColumn, destinationColumn));

loggerExternal.exiting(loggerClassName, "addColumnMapping");
}
Expand All @@ -396,7 +396,7 @@ public void addColumnMapping(String sourceColumn, int destinationColumn) throws
} else if (null == sourceColumn || sourceColumn.isEmpty()) {
throwInvalidArgument("sourceColumn");
}
columnMappings.add(new ColumnMapping(sourceColumn.trim(), destinationColumn));
columnMappings.add(new ColumnMapping(sourceColumn, destinationColumn));

loggerExternal.exiting(loggerClassName, "addColumnMapping");
}
Expand All @@ -422,7 +422,7 @@ public void addColumnMapping(String sourceColumn, String destinationColumn) thro
} else if (null == destinationColumn || destinationColumn.isEmpty()) {
throwInvalidArgument("destinationColumn");
}
columnMappings.add(new ColumnMapping(sourceColumn.trim(), destinationColumn.trim()));
columnMappings.add(new ColumnMapping(sourceColumn, destinationColumn));

loggerExternal.exiting(loggerClassName, "addColumnMapping");
}
Expand Down Expand Up @@ -929,11 +929,10 @@ private void writeTypeInfo(TDSWriter tdsWriter, int srcJdbcType, int srcScale, i
case java.sql.Types.NUMERIC:
case java.sql.Types.DECIMAL:
/*
* SQL Server allows the insertion of decimal and numeric into a money (and smallmoney) column,
* but Azure DW only accepts money types for money column.
* To make the code compatible against both SQL Server and Azure DW, always send decimal and
* numeric as money/smallmoney if the destination column is money/smallmoney
* and the source is decimal/numeric.
* SQL Server allows the insertion of decimal and numeric into a money (and smallmoney) column, but
* Azure DW only accepts money types for money column. To make the code compatible against both SQL
* Server and Azure DW, always send decimal and numeric as money/smallmoney if the destination column is
* money/smallmoney and the source is decimal/numeric.
*/
if (destSSType == SSType.MONEY) {
tdsWriter.writeByte(TDSType.MONEYN.byteValue());
Expand All @@ -944,7 +943,8 @@ private void writeTypeInfo(TDSWriter tdsWriter, int srcJdbcType, int srcScale, i
tdsWriter.writeByte((byte) 4);
break;
}
byte byteType = (java.sql.Types.DECIMAL == srcJdbcType) ? TDSType.DECIMALN.byteValue() : TDSType.NUMERICN.byteValue();
byte byteType = (java.sql.Types.DECIMAL == srcJdbcType) ? TDSType.DECIMALN.byteValue()
: TDSType.NUMERICN.byteValue();
tdsWriter.writeByte(byteType);
tdsWriter.writeByte((byte) TDSWriter.BIGDECIMAL_MAX_LENGTH); // maximum length
tdsWriter.writeByte((byte) srcPrecision); // unsigned byte
Expand Down Expand Up @@ -1296,11 +1296,10 @@ private String getDestTypeFromSrcType(int srcColIndx, int destColIndx,
return "smallmoney";
case java.sql.Types.DECIMAL:
/*
* SQL Server allows the insertion of decimal and numeric into a money (and smallmoney) column,
* but Azure DW only accepts money types for money column.
* To make the code compatible against both SQL Server and Azure DW, always send decimal and
* numeric as money/smallmoney if the destination column is money/smallmoney
* and the source is decimal/numeric.
* SQL Server allows the insertion of decimal and numeric into a money (and smallmoney) column, but
* Azure DW only accepts money types for money column. To make the code compatible against both SQL
* Server and Azure DW, always send decimal and numeric as money/smallmoney if the destination column is
* money/smallmoney and the source is decimal/numeric.
*/
if (destSSType == SSType.MONEY) {
return "money";
Expand Down Expand Up @@ -1842,8 +1841,7 @@ private void validateColumnMappings() throws SQLServerException {
Set<Integer> columnOrdinals = serverBulkData.getColumnOrdinals();
Iterator<Integer> columnsIterator = columnOrdinals.iterator();
int j = 1;
outerWhileLoop:
while (columnsIterator.hasNext()) {
outerWhileLoop : while (columnsIterator.hasNext()) {
int currentOrdinal = columnsIterator.next();
if (j != currentOrdinal) {
/*
Expand Down Expand Up @@ -2067,8 +2065,7 @@ else if (null != sourceCryptoMeta) {
} else if (null != serverBulkData && connection.getSendTemporalDataTypesAsStringForBulkCopy()) {
/*
* Bulk copy from CSV and destination is not encrypted. In this case, we send the temporal types as varchar
* and
* SQL Server does the conversion. If destination is encrypted, then temporal types can not be sent as
* and SQL Server does the conversion. If destination is encrypted, then temporal types can not be sent as
* varchar.
*/
switch (bulkJdbcType) {
Expand Down Expand Up @@ -2219,10 +2216,9 @@ else if (null != sourceCryptoMeta) {
}
/*
* SQL Server allows the insertion of decimal and numeric into a money (and smallmoney) column,
* but Azure DW only accepts money types for money column.
* To make the code compatible against both SQL Server and Azure DW, always send decimal and
* numeric as money/smallmoney if the destination column is money/smallmoney
* and the source is decimal/numeric.
* but Azure DW only accepts money types for money column. To make the code compatible against
* both SQL Server and Azure DW, always send decimal and numeric as money/smallmoney if the
* destination column is money/smallmoney and the source is decimal/numeric.
*/
if (destSSType == SSType.MONEY) {
tdsWriter.writeMoney((BigDecimal) colValue, microsoft.sql.Types.MONEY);
Expand Down Expand Up @@ -2490,14 +2486,12 @@ else if (4 >= bulkScale)
tdsWriter.writeByte((byte) 0x05);
if (colValue instanceof String) {
/*
* if colValue is an instance of String, this means the data is coming from a CSV file.
* Time string is expected to come in with this pattern: hh:mm:ss[.nnnnnnn]
* First, look for the '.' character to determine if the String has the optional nanoseconds
* component.
* Next, create a java.sql.Time instance with the hh:mm:ss part we extracted, then set that
* time as the timestamp's time.
* Then, add the nanoseconds (optional, 0 if not provided) to the timestamp value.
* Finally, provide the timestamp value to writeTime method.
* if colValue is an instance of String, this means the data is coming from a CSV file. Time
* string is expected to come in with this pattern: hh:mm:ss[.nnnnnnn] First, look for the
* '.' character to determine if the String has the optional nanoseconds component. Next,
* create a java.sql.Time instance with the hh:mm:ss part we extracted, then set that time
* as the timestamp's time. Then, add the nanoseconds (optional, 0 if not provided) to the
* timestamp value. Finally, provide the timestamp value to writeTime method.
*/
java.sql.Timestamp ts = new java.sql.Timestamp(0);
int nanos = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.microsoft.sqlserver.jdbc.ComparisonUtil;
import com.microsoft.sqlserver.jdbc.RandomUtil;
import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy;
import com.microsoft.sqlserver.jdbc.SQLServerBulkCopyOptions;
import com.microsoft.sqlserver.jdbc.TestResource;
import com.microsoft.sqlserver.jdbc.TestUtils;
import com.microsoft.sqlserver.testframework.AbstractSQLGenerator;
Expand Down Expand Up @@ -377,6 +378,44 @@ public void testUnicodeCharToNchar() throws SQLException, ClassNotFoundException
validateMapping("VARCHAR(5)", "NVARCHAR(max)", "фщыab");
}

@Tag(Constants.xAzureSQLDW)
@Test
@DisplayName("BulkCopy:test column name with trailing space")
public void testTrailingSpace() throws SQLException, ClassNotFoundException {
String sourceTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("sourceTable")));
String destTable = TestUtils
.escapeSingleQuotes(AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("destTable")));

try (Connection conn = DriverManager.getConnection(connectionString);) {
try (Statement sourceStmt = conn.createStatement(); Statement destStmt = conn.createStatement();
SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(conn)) {

sourceStmt.executeUpdate("CREATE TABLE " + sourceTable + " ([colTrailingSpace ] char(5) null);");
sourceStmt.executeUpdate("INSERT INTO " + sourceTable + " VALUES('" + "data" + "');");
destStmt.executeUpdate("CREATE TABLE " + destTable + " ([colTrailingSpace ] char(5) null);");
ResultSet sourceRs = sourceStmt.executeQuery("SELECT * FROM " + sourceTable);

ResultSet destRs = destStmt.executeQuery("SELECT * FROM " + destTable);
destRs.next();

ResultSetMetaData rsmd = sourceRs.getMetaData();
String name = rsmd.getColumnName(1);
bulkCopy.addColumnMapping(name, name);

bulkCopy.setDestinationTableName(destTable);
bulkCopy.writeToServer(sourceRs);
} catch (Exception e) {
fail(e.getMessage());
} finally {
try (Statement stmt = conn.createStatement();) {
TestUtils.dropTableIfExists(destTable, stmt);
TestUtils.dropTableIfExists(sourceTable, stmt);
}
}
}
}

/**
* Validate if same values are in both source and destination table taking into account 1 extra column in
* destination which should be a copy of first column of source.
Expand Down