@@ -64,50 +64,60 @@ public string ParameterName
6464 /// </summary>
6565 public SerializationType SerializationType { get ; set ; }
6666
67- public static FormatItem CreateForParameter ( AseParameter parameter , DbEnvironment env , CommandType commandType )
67+ public static FormatItem CreateForParameter ( AseParameter parameter , DbEnvironment env , AseCommand command )
6868 {
6969 parameter . AseDbType = TypeMap . InferType ( parameter ) ;
7070
7171 var dbType = parameter . DbType ;
72-
7372 var length = TypeMap . GetFormatLength ( dbType , parameter , env . Encoding ) ;
7473
75- var format = new FormatItem
74+ var format = command . FormatItem ;
75+ var parameterName = parameter . ParameterName ?? command . Parameters . IndexOf ( parameter ) . ToString ( ) ;
76+ if ( ! ( command . FormatItem != null && command . FormatItem . ParameterName == parameterName &&
77+ command . FormatItem . AseDbType == parameter . AseDbType ) )
7678 {
77- AseDbType = parameter . AseDbType ,
78- ParameterName = parameter . ParameterName ,
79- IsOutput = parameter . IsOutput ,
80- IsNullable = parameter . IsNullable ,
81- Length = length ,
82- DataType = TypeMap . GetTdsDataType ( dbType , parameter . SendableValue , length , parameter . ParameterName ) ,
83- UserType = TypeMap . GetUserType ( dbType , parameter . SendableValue , length )
84- } ;
79+ format = new FormatItem
80+ {
81+ AseDbType = parameter . AseDbType ,
82+ ParameterName = parameter . ParameterName ,
83+ IsOutput = parameter . IsOutput ,
84+ IsNullable = parameter . IsNullable ,
85+ Length = length ,
86+ DataType = TypeMap . GetTdsDataType ( dbType , parameter . SendableValue , length , parameter . ParameterName ) ,
87+ UserType = TypeMap . GetUserType ( dbType , parameter . SendableValue , length )
88+ } ;
8589
86- //fixup the FormatItem's BlobType for strings and byte arrays
87- if ( format . DataType == TdsDataType . TDS_BLOB )
88- {
89- switch ( parameter . DbType )
90+ //fixup the FormatItem's BlobType for strings and byte arrays
91+ if ( format . DataType == TdsDataType . TDS_BLOB )
9092 {
91- case DbType . AnsiString :
92- format . BlobType = BlobType . BLOB_LONGCHAR ;
93- break ;
94- case DbType . String :
95- format . BlobType = BlobType . BLOB_UNICHAR ;
96- // This is far less than ideal but at the time of addressing this issue whereby if the
97- // BlobType is a BLOB_UNICHAR then the UserType would need to be 36 when it
98- // is a stored proc otherwise it would need to be zero (0).
99- //
100- // In the future, we'd need to overhaul how TDS_BLOB is structured especially
101- // around BLOB_UNICHAR and the UserType that it should return in a more consistent way
102- if ( commandType != CommandType . StoredProcedure )
103- format . UserType = 0 ;
93+ switch ( parameter . DbType )
94+ {
95+ case DbType . AnsiString :
96+ format . BlobType = BlobType . BLOB_LONGCHAR ;
97+ break ;
98+ case DbType . String :
99+ format . BlobType = BlobType . BLOB_UNICHAR ;
100+ // This is far less than ideal but at the time of addressing this issue whereby if the
101+ // BlobType is a BLOB_UNICHAR then the UserType would need to be 36 when it
102+ // is a stored proc otherwise it would need to be zero (0).
103+ //
104+ // In the future, we'd need to overhaul how TDS_BLOB is structured especially
105+ // around BLOB_UNICHAR and the UserType that it should return in a more consistent way
106+ if ( command . CommandType != CommandType . StoredProcedure )
107+ format . UserType = 0 ;
104108
105- break ;
106- case DbType . Binary :
107- format . BlobType = BlobType . BLOB_LONGBINARY ;
108- break ;
109+ break ;
110+ case DbType . Binary :
111+ format . BlobType = BlobType . BLOB_LONGBINARY ;
112+ break ;
113+ }
109114 }
110115 }
116+ else
117+ {
118+ format . DataType = TypeMap . GetTdsDataType ( dbType , parameter . SendableValue , length , parameter . ParameterName ) ;
119+ format . UserType = TypeMap . GetUserType ( dbType , parameter . SendableValue , length ) ;
120+ }
111121
112122 //fixup the FormatItem's length,scale,precision for decimals
113123 if ( format . IsDecimalType )
0 commit comments