Bulk Copy cannot handle inserts with subset or differently ordered columns #1554
Labels
Backlog
The topic in question has been recognized and added to development backlog
Documentation
Pull requests that update documentation
Enhancement
An enhancement to the driver. Lower priority than bugs.
Projects
Driver version
9.2.1.jre15
SQL Server version
Microsoft SQL Server 2016 (SP2) (KB4052908) - 13.0.5026.0 (X64)
Client Operating System
Windows 10
JAVA/JVM version
openjdk-15.0.2
Table schema
Any table
Problem description
When using
useBulkCopyForBatchInsert=true
aSQLServerPreparedStatement
seems to expect any insert statements to contain all columns in the exact order returned fromsp_executesql N'SET FMTONLY ON SELECT * FROM "
(line 1990), as this is the order the column metadata is added.The problem with this is that any insert statement only specifying a subset of columns or columns in the wrong order can have the wrong column metadata mapped. The consequence of this seems to be that some columns will be set to null when inserted. Ideally the
executeBatch
will look at the column list and derive the right metadata from the colum name instead of the coumn index.Workaround is to make sure that the
SQLServerBulkBatchInsertRecord
has thecolumnList
,valueList
andcolumnMetadata
with the same number of elements in the same order.useBulkCopyForBatchInsert=false
Reproduction code
Have not tested this simplified version
The text was updated successfully, but these errors were encountered: