@@ -112,14 +112,6 @@ internal object[] CreateRowBuffer()
112
112
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/SqlBulkCopy/*'/>
113
113
public sealed class SqlBulkCopy : IDisposable
114
114
{
115
- private enum TableNameComponents
116
- {
117
- Server = 0 ,
118
- Catalog ,
119
- Owner ,
120
- TableName ,
121
- }
122
-
123
115
private enum ValueSourceType
124
116
{
125
117
Unspecified = 0 ,
@@ -161,10 +153,6 @@ public SourceColumnMetadata(ValueMethod method, bool isSqlType, bool isDataFeed)
161
153
// MetaData has n columns but no rows
162
154
// Collation has 4 columns and n rows
163
155
164
- private const int TranCountResultId = 0 ;
165
- private const int TranCountRowId = 0 ;
166
- private const int TranCountValueId = 0 ;
167
-
168
156
private const int MetaDataResultId = 1 ;
169
157
170
158
private const int CollationResultId = 2 ;
@@ -439,66 +427,60 @@ private string CreateInitialQuery()
439
427
string TDSCommand ;
440
428
441
429
TDSCommand = "select @@trancount; SET FMTONLY ON select * from " + ADP . BuildMultiPartName ( parts ) + " SET FMTONLY OFF " ;
442
- if ( _connection . Is2000 )
443
- {
444
- // If its a temp DB then try to connect
445
430
446
- string TableCollationsStoredProc ;
447
- if ( _connection . Is2008OrNewer )
448
- {
449
- TableCollationsStoredProc = "sp_tablecollations_100" ;
450
- }
451
- else if ( _connection . Is2005OrNewer )
452
- {
453
- TableCollationsStoredProc = "sp_tablecollations_90" ;
454
- }
455
- else
456
- {
457
- TableCollationsStoredProc = "sp_tablecollations" ;
458
- }
431
+ // If its a temp DB then try to connect
459
432
460
- string TableName = parts [ MultipartIdentifier . TableIndex ] ;
461
- bool isTempTable = TableName . Length > 0 && '#' == TableName [ 0 ] ;
462
- if ( ! ADP . IsEmpty ( TableName ) )
463
- {
464
- // Escape table name to be put inside TSQL literal block (within N'').
465
- TableName = SqlServerEscapeHelper . EscapeStringAsLiteral ( TableName ) ;
466
- // VSDD 581951 - escape the table name
467
- TableName = SqlServerEscapeHelper . EscapeIdentifier ( TableName ) ;
468
- }
433
+ string TableCollationsStoredProc ;
434
+ if ( _connection . Is2008OrNewer )
435
+ {
436
+ TableCollationsStoredProc = "sp_tablecollations_100" ;
437
+ }
438
+ else
439
+ {
440
+ TableCollationsStoredProc = "sp_tablecollations_90" ;
441
+ }
469
442
470
- string SchemaName = parts [ MultipartIdentifier . SchemaIndex ] ;
471
- if ( ! ADP . IsEmpty ( SchemaName ) )
472
- {
473
- // Escape schema name to be put inside TSQL literal block (within N'').
474
- SchemaName = SqlServerEscapeHelper . EscapeStringAsLiteral ( SchemaName ) ;
475
- // VSDD 581951 - escape the schema name
476
- SchemaName = SqlServerEscapeHelper . EscapeIdentifier ( SchemaName ) ;
477
- }
443
+ string TableName = parts [ MultipartIdentifier . TableIndex ] ;
444
+ bool isTempTable = TableName . Length > 0 && '#' == TableName [ 0 ] ;
445
+ if ( ! ADP . IsEmpty ( TableName ) )
446
+ {
447
+ // Escape table name to be put inside TSQL literal block (within N'').
448
+ TableName = SqlServerEscapeHelper . EscapeStringAsLiteral ( TableName ) ;
449
+ // VSDD 581951 - escape the table name
450
+ TableName = SqlServerEscapeHelper . EscapeIdentifier ( TableName ) ;
451
+ }
478
452
479
- string CatalogName = parts [ MultipartIdentifier . CatalogIndex ] ;
480
- if ( isTempTable && ADP . IsEmpty ( CatalogName ) )
481
- {
482
- TDSCommand += string . Format ( "exec tempdb..{0} N'{1}.{2}'" ,
483
- TableCollationsStoredProc ,
484
- SchemaName ,
485
- TableName
486
- ) ;
487
- }
488
- else
453
+ string SchemaName = parts [ MultipartIdentifier . SchemaIndex ] ;
454
+ if ( ! ADP . IsEmpty ( SchemaName ) )
455
+ {
456
+ // Escape schema name to be put inside TSQL literal block (within N'').
457
+ SchemaName = SqlServerEscapeHelper . EscapeStringAsLiteral ( SchemaName ) ;
458
+ // VSDD 581951 - escape the schema name
459
+ SchemaName = SqlServerEscapeHelper . EscapeIdentifier ( SchemaName ) ;
460
+ }
461
+
462
+ string CatalogName = parts [ MultipartIdentifier . CatalogIndex ] ;
463
+ if ( isTempTable && ADP . IsEmpty ( CatalogName ) )
464
+ {
465
+ TDSCommand += string . Format ( "exec tempdb..{0} N'{1}.{2}'" ,
466
+ TableCollationsStoredProc ,
467
+ SchemaName ,
468
+ TableName
469
+ ) ;
470
+ }
471
+ else
472
+ {
473
+ // VSDD 581951 - escape the catalog name
474
+ if ( ! ADP . IsEmpty ( CatalogName ) )
489
475
{
490
- // VSDD 581951 - escape the catalog name
491
- if ( ! ADP . IsEmpty ( CatalogName ) )
492
- {
493
- CatalogName = SqlServerEscapeHelper . EscapeIdentifier ( CatalogName ) ;
494
- }
495
- TDSCommand += string . Format ( "exec {0}..{1} N'{2}.{3}'" ,
496
- CatalogName ,
497
- TableCollationsStoredProc ,
498
- SchemaName ,
499
- TableName
500
- ) ;
476
+ CatalogName = SqlServerEscapeHelper . EscapeIdentifier ( CatalogName ) ;
501
477
}
478
+ TDSCommand += string . Format ( "exec {0}..{1} N'{2}.{3}'" ,
479
+ CatalogName ,
480
+ TableCollationsStoredProc ,
481
+ SchemaName ,
482
+ TableName
483
+ ) ;
502
484
}
503
485
return TDSCommand ;
504
486
}
@@ -549,7 +531,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
549
531
550
532
StringBuilder updateBulkCommandText = new StringBuilder ( ) ;
551
533
552
- if ( _connection . Is2000 && 0 == internalResults [ CollationResultId ] . Count )
534
+ if ( 0 == internalResults [ CollationResultId ] . Count )
553
535
{
554
536
throw SQL . BulkLoadNoCollation ( ) ;
555
537
}
@@ -562,15 +544,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
562
544
563
545
bool isInTransaction ;
564
546
565
- if ( _parser . Is2005OrNewer )
566
- {
567
- isInTransaction = _connection . HasLocalTransaction ;
568
- }
569
- else
570
- {
571
- isInTransaction = ( bool ) ( 0 < ( SqlInt32 ) ( internalResults [ TranCountResultId ] [ TranCountRowId ] [ TranCountValueId ] ) ) ;
572
- }
573
-
547
+ isInTransaction = _connection . HasLocalTransaction ;
574
548
// Throw if there is a transaction but no flag is set
575
549
if ( isInTransaction &&
576
550
_externalTransaction == null &&
@@ -701,50 +675,45 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
701
675
}
702
676
}
703
677
704
- if ( _connection . Is2000 )
705
- {
706
- // 2000 or above!
707
- // get collation for column i
678
+ // Get collation for column i
679
+ Result rowset = internalResults [ CollationResultId ] ;
680
+ object rowvalue = rowset [ i ] [ CollationId ] ;
708
681
709
- Result rowset = internalResults [ CollationResultId ] ;
710
- object rowvalue = rowset [ i ] [ CollationId ] ;
682
+ bool shouldSendCollation ;
683
+ switch ( metadata . type )
684
+ {
685
+ case SqlDbType . Char :
686
+ case SqlDbType . NChar :
687
+ case SqlDbType . VarChar :
688
+ case SqlDbType . NVarChar :
689
+ case SqlDbType . Text :
690
+ case SqlDbType . NText :
691
+ shouldSendCollation = true ;
692
+ break ;
711
693
712
- bool shouldSendCollation ;
713
- switch ( metadata . type )
714
- {
715
- case SqlDbType . Char :
716
- case SqlDbType . NChar :
717
- case SqlDbType . VarChar :
718
- case SqlDbType . NVarChar :
719
- case SqlDbType . Text :
720
- case SqlDbType . NText :
721
- shouldSendCollation = true ;
722
- break ;
694
+ default :
695
+ shouldSendCollation = false ;
696
+ break ;
697
+ }
723
698
724
- default :
725
- shouldSendCollation = false ;
726
- break ;
727
- }
699
+ if ( rowvalue != null && shouldSendCollation )
700
+ {
701
+ Debug . Assert ( rowvalue is SqlString ) ;
702
+ SqlString collation_name = ( SqlString ) rowvalue ;
728
703
729
- if ( rowvalue != null && shouldSendCollation )
704
+ if ( ! collation_name . IsNull )
730
705
{
731
- Debug . Assert ( rowvalue is SqlString ) ;
732
- SqlString collation_name = ( SqlString ) rowvalue ;
733
-
734
- if ( ! collation_name . IsNull )
706
+ updateBulkCommandText . Append ( " COLLATE " + collation_name . Value ) ;
707
+ // VSTFDEVDIV 461426: compare collations only if the collation value was set on the metadata
708
+ if ( _sqlDataReaderRowSource != null && metadata . collation != null )
735
709
{
736
- updateBulkCommandText . Append ( " COLLATE " + collation_name . Value ) ;
737
- // VSTFDEVDIV 461426: compare collations only if the collation value was set on the metadata
738
- if ( _sqlDataReaderRowSource != null && metadata . collation != null )
710
+ // On SqlDataReader we can verify the sourcecolumn collation!
711
+ int sourceColumnId = _localColumnMappings [ assocId ] . _internalSourceColumnOrdinal ;
712
+ int destinationLcid = metadata . collation . LCID ;
713
+ int sourceLcid = _sqlDataReaderRowSource . GetLocaleId ( sourceColumnId ) ;
714
+ if ( sourceLcid != destinationLcid )
739
715
{
740
- // On SqlDataReader we can verify the sourcecolumn collation!
741
- int sourceColumnId = _localColumnMappings [ assocId ] . _internalSourceColumnOrdinal ;
742
- int destinationLcid = metadata . collation . LCID ;
743
- int sourceLcid = _sqlDataReaderRowSource . GetLocaleId ( sourceColumnId ) ;
744
- if ( sourceLcid != destinationLcid )
745
- {
746
- throw SQL . BulkLoadLcidMismatch ( sourceLcid , _sqlDataReaderRowSource . GetName ( sourceColumnId ) , destinationLcid , metadata . column ) ;
747
- }
716
+ throw SQL . BulkLoadLcidMismatch ( sourceLcid , _sqlDataReaderRowSource . GetName ( sourceColumnId ) , destinationLcid , metadata . column ) ;
748
717
}
749
718
}
750
719
}
0 commit comments