@@ -391,7 +391,7 @@ internal void Generate(in GenerateState ctx)
391
391
392
392
if ( flags . HasAny ( OperationFlags . GetRowParser ) )
393
393
{
394
- WriteGetRowParser ( sb , resultType , readers , grp . Key . AdditionalCommandState ? . StrictBind ?? default ) ;
394
+ WriteGetRowParser ( sb , resultType , readers , grp . Key . AdditionalCommandState ? . QueryColumns ?? default ) ;
395
395
}
396
396
else if ( ! TryWriteMultiExecImplementation ( sb , flags , commandTypeMode , parameterType , grp . Key . ParameterMap , grp . Key . UniqueLocation is not null , methodParameters , factories , fixedSql , additionalCommandState ) )
397
397
{
@@ -451,7 +451,7 @@ internal void Generate(in GenerateState ctx)
451
451
452
452
foreach ( var tuple in readers )
453
453
{
454
- WriteRowFactory ( ctx , sb , tuple . Type , tuple . Index , tuple . StrictBind , null /* TODO */ ) ;
454
+ WriteRowFactory ( ctx , sb , tuple . Type , tuple . Index , tuple . QueryColumns , null /* TODO */ ) ;
455
455
}
456
456
457
457
foreach ( var tuple in factories )
@@ -468,9 +468,9 @@ internal void Generate(in GenerateState ctx)
468
468
ctx . ReportDiagnostic ( Diagnostic . Create ( Diagnostics . InterceptorsGenerated , null , callSiteCount , ctx . Nodes . Length , methodIndex , factories . Count ( ) , readers . Count ( ) ) ) ;
469
469
}
470
470
471
- private static void WriteGetRowParser ( CodeWriter sb , ITypeSymbol ? resultType , in RowReaderState readers , ImmutableArray < string > strictBind )
471
+ private static void WriteGetRowParser ( CodeWriter sb , ITypeSymbol ? resultType , in RowReaderState readers , ImmutableArray < string > queryColumns )
472
472
{
473
- sb . Append ( "return " ) . AppendReader ( resultType , readers , strictBind )
473
+ sb . Append ( "return " ) . AppendReader ( resultType , readers , queryColumns )
474
474
. Append ( ".GetRowParser(reader, startIndex, length, returnNullIfFirstMissing);" ) . NewLine ( ) ;
475
475
}
476
476
@@ -732,7 +732,7 @@ static bool IsReserved(string name)
732
732
}
733
733
}
734
734
735
- private static void WriteRowFactory ( in GenerateState context , CodeWriter sb , ITypeSymbol type , int index , ImmutableArray < string > strictBind , Location ? location )
735
+ private static void WriteRowFactory ( in GenerateState context , CodeWriter sb , ITypeSymbol type , int index , ImmutableArray < string > queryColumns , Location ? location )
736
736
{
737
737
var map = MemberMap . CreateForResults ( type ) ;
738
738
if ( map is null ) return ;
@@ -780,7 +780,7 @@ void WriteRowFactoryFooter()
780
780
void WriteTokenizeMethod ( )
781
781
{
782
782
sb . Append ( "public override object? Tokenize(global::System.Data.Common.DbDataReader reader, global::System.Span<int> tokens, int columnOffset)" ) . Indent ( ) . NewLine ( ) ;
783
- if ( strictBind . IsDefault ) // don't emit any tokens for strict binding
783
+ if ( queryColumns . IsDefault ) // don't emit any tokens for strict binding
784
784
{
785
785
sb . Append ( "for (int i = 0; i < tokens.Length; i++)" ) . Indent ( ) . NewLine ( )
786
786
. Append ( "int token = -1;" ) . NewLine ( )
@@ -808,11 +808,11 @@ void WriteTokenizeMethod()
808
808
}
809
809
else
810
810
{
811
- sb . Append ( "// strict-bind : " ) ;
812
- for ( int i = 0 ; i < strictBind . Length ; i ++ )
811
+ sb . Append ( "// query columns : " ) ;
812
+ for ( int i = 0 ; i < queryColumns . Length ; i ++ )
813
813
{
814
814
if ( i != 0 ) sb . Append ( ", " ) ;
815
- var name = strictBind [ i ] ;
815
+ var name = queryColumns [ i ] ;
816
816
if ( string . IsNullOrWhiteSpace ( name ) )
817
817
{
818
818
sb . Append ( "(n/a)" ) ;
@@ -826,7 +826,7 @@ void WriteTokenizeMethod()
826
826
sb . Append ( "'" ) . Append ( name ) . Append ( "'" ) ;
827
827
}
828
828
}
829
- sb . NewLine ( ) . Append ( "global::System.Diagnostics.Debug.Assert(tokens.Length == " ) . Append ( strictBind . Length ) . Append ( """, "Strict-bind column count mismatch");""" ) . NewLine ( ) ;
829
+ sb . NewLine ( ) . Append ( "global::System.Diagnostics.Debug.Assert(tokens.Length >= " ) . Append ( queryColumns . Length ) . Append ( """, "Query columns count mismatch");""" ) . NewLine ( ) ;
830
830
}
831
831
sb . Append ( "return null;" ) . Outdent ( ) . NewLine ( ) ;
832
832
}
@@ -879,15 +879,16 @@ void WriteReadMethod(in GenerateState context)
879
879
}
880
880
881
881
ImmutableArray < ElementMember > readMembers ;
882
- if ( strictBind . IsDefault )
882
+ if ( queryColumns . IsDefault )
883
883
{
884
884
readMembers = members ; // try to parse everything
885
885
sb . Append ( "foreach (var token in tokens)" ) ;
886
886
}
887
887
else
888
888
{
889
- readMembers = MapStrictBind ( context , members , strictBind , location ) ;
890
- sb . Append ( "for (int token = 0; token < tokens.Length; token++) // strict-bind" ) ;
889
+ readMembers = MapQueryColumns ( context , members , queryColumns , location ) ;
890
+ sb . Append ( "int lim = global::System.Math.Min(tokens.Length, " ) . Append ( queryColumns . Length ) . Append ( ");" ) . NewLine ( )
891
+ . Append ( "for (int token = 0; token < lim; token++) // query-columns predefined" ) ;
891
892
}
892
893
sb . Indent ( ) . NewLine ( ) . Append ( "switch (token)" ) . Indent ( ) . NewLine ( ) ;
893
894
@@ -920,7 +921,7 @@ void WriteReadMethod(in GenerateState context)
920
921
921
922
sb . NewLine ( ) . Append ( "break;" ) . NewLine ( ) . Outdent ( false ) ;
922
923
923
- if ( strictBind . IsDefault ) // type-forgiving version; only emitted when not using strict-bind
924
+ if ( queryColumns . IsDefault ) // type-forgiving version; only emitted when not using strict-bind
924
925
{
925
926
sb . Append ( "case " ) . Append ( token + map . Members . Length ) . Append ( ":" ) . NewLine ( ) . Indent ( false ) ;
926
927
@@ -1020,27 +1021,27 @@ void WriteDeferredMethodArgs()
1020
1021
}
1021
1022
}
1022
1023
1023
- private static ImmutableArray < ElementMember > MapStrictBind ( in GenerateState state , ImmutableArray < ElementMember > members , ImmutableArray < string > strictBind , Location ? location )
1024
+ private static ImmutableArray < ElementMember > MapQueryColumns ( in GenerateState state , ImmutableArray < ElementMember > members , ImmutableArray < string > queryColumns , Location ? location )
1024
1025
{
1025
- if ( strictBind . IsDefault ) return members ; // not bound
1026
+ if ( queryColumns . IsDefault ) return members ; // not bound
1026
1027
1027
- var result = ImmutableArray . CreateBuilder < ElementMember > ( strictBind . Length ) ;
1028
- foreach ( var seek in strictBind )
1028
+ var result = ImmutableArray . CreateBuilder < ElementMember > ( queryColumns . Length ) ;
1029
+ foreach ( var seek in queryColumns )
1029
1030
{
1030
1031
ElementMember found = default ;
1031
1032
if ( ! string . IsNullOrWhiteSpace ( seek ) )
1032
1033
{
1033
- foreach ( var member in members )
1034
+ foreach ( var member in members ) // look for direct match
1034
1035
{
1035
- if ( member . CodeName == seek )
1036
+ if ( string . Equals ( member . CodeName , seek , StringComparison . InvariantCultureIgnoreCase ) )
1036
1037
{
1037
1038
found = member ;
1038
1039
break ;
1039
1040
}
1040
1041
}
1041
- if ( found . Member is null )
1042
+ if ( found . Member is null ) // additional underscore-etc deviation
1042
1043
{
1043
- var normalizedSeek = StringHashing . Normalize ( seek ) ;
1044
+ var normalizedSeek = StringHashing . Normalize ( seek ) ; // note: should already *be* normalized, but: be sure
1044
1045
foreach ( var member in members )
1045
1046
{
1046
1047
if ( StringHashing . NormalizedEquals ( member . CodeName , normalizedSeek ) )
0 commit comments