@@ -23,7 +23,7 @@ namespace FreeSql.Internal
2323 public abstract class CommonUtils
2424 {
2525
26- public abstract string GetNoneParamaterSqlValue ( List < DbParameter > specialParams , string specialParamFlag , Type type , object value ) ;
26+ public abstract string GetNoneParamaterSqlValue ( List < DbParameter > specialParams , string specialParamFlag , ColumnInfo col , Type type , object value ) ;
2727 public abstract DbParameter AppendParamter ( List < DbParameter > _params , string parameterName , ColumnInfo col , Type type , object value ) ;
2828 public abstract DbParameter [ ] GetDbParamtersByObject ( string sql , object obj ) ;
2929 public abstract string FormatSql ( string sql , params object [ ] args ) ;
@@ -267,7 +267,7 @@ public string WhereObject(TableInfo table, string aliasAndDot, object dywhere)
267267 var pk1 = primarys . FirstOrDefault ( ) ;
268268 if ( primarys . Length == 1 && ( type == pk1 . CsType || type . IsNumberType ( ) && pk1 . CsType . IsNumberType ( ) ) )
269269 {
270- return $ "{ aliasAndDot } { this . QuoteSqlName ( pk1 . Attribute . Name ) } = { this . FormatSql ( "{0}" , Utils . GetDataReaderValue ( pk1 . Attribute . MapType , dywhere ) ) } ";
270+ return $ "{ aliasAndDot } { this . QuoteSqlName ( pk1 . Attribute . Name ) } = { GetNoneParamaterSqlValue ( null , null , pk1 , pk1 . Attribute . MapType , Utils . GetDataReaderValue ( pk1 . Attribute . MapType , dywhere ) ) } ";
271271 }
272272 else if ( primarys . Length > 0 && ( type == table . Type || type . BaseType == table . Type ) )
273273 {
@@ -276,15 +276,15 @@ public string WhereObject(TableInfo table, string aliasAndDot, object dywhere)
276276 foreach ( var pk in primarys )
277277 {
278278 if ( pkidx > 0 ) sb . Append ( " AND " ) ;
279- sb . Append ( aliasAndDot ) . Append ( this . QuoteSqlName ( pk . Attribute . Name ) ) ;
280- sb . Append ( this . FormatSql ( " = {0}" , pk . GetDbValue ( dywhere ) ) ) ;
279+ sb . Append ( aliasAndDot ) . Append ( this . QuoteSqlName ( pk . Attribute . Name ) ) . Append ( " = " ) ;
280+ sb . Append ( GetNoneParamaterSqlValue ( null , null , pk , pk . Attribute . MapType , pk . GetDbValue ( dywhere ) ) ) ;
281281 ++ pkidx ;
282282 }
283283 return sb . ToString ( ) ;
284284 }
285285 else if ( primarys . Length == 1 && type == typeof ( string ) )
286286 {
287- return $ "{ aliasAndDot } { this . QuoteSqlName ( pk1 . Attribute . Name ) } = { this . FormatSql ( "{0}" , Utils . GetDataReaderValue ( pk1 . Attribute . MapType , dywhere ) ) } ";
287+ return $ "{ aliasAndDot } { this . QuoteSqlName ( pk1 . Attribute . Name ) } = { GetNoneParamaterSqlValue ( null , null , pk1 , pk1 . Attribute . MapType , Utils . GetDataReaderValue ( pk1 . Attribute . MapType , dywhere ) ) } ";
288288 }
289289 else if ( primarys . Length == 1 && dywhere is IEnumerable )
290290 {
@@ -303,8 +303,8 @@ public string WhereObject(TableInfo table, string aliasAndDot, object dywhere)
303303 var itype = i . GetType ( ) ;
304304 isEntityType = ( itype == table . Type || itype . BaseType == table . Type ) ;
305305 }
306- if ( isEntityType ) sb . Append ( this . FormatSql ( "{0}" , primarys [ 0 ] . GetDbValue ( i ) ) ) ;
307- else sb . Append ( this . FormatSql ( "{0}" , Utils . GetDataReaderValue ( pk1 . Attribute . MapType , i ) ) ) ;
306+ if ( isEntityType ) sb . Append ( GetNoneParamaterSqlValue ( null , null , primarys [ 0 ] , primarys [ 0 ] . Attribute . MapType , primarys [ 0 ] . GetDbValue ( i ) ) ) ;
307+ else sb . Append ( GetNoneParamaterSqlValue ( null , null , pk1 , pk1 . Attribute . MapType , Utils . GetDataReaderValue ( pk1 . Attribute . MapType , i ) ) ) ;
308308 ++ ieidx ;
309309 }
310310 if ( isAny == false ) return "" ;
@@ -338,8 +338,8 @@ public string WhereObject(TableInfo table, string aliasAndDot, object dywhere)
338338 if ( trycol == null ) continue ;
339339
340340 if ( psidx > 0 ) sb . Append ( " AND " ) ;
341- sb . Append ( aliasAndDot ) . Append ( this . QuoteSqlName ( trycol . Attribute . Name ) ) ;
342- sb . Append ( this . FormatSql ( " = {0}" , Utils . GetDataReaderValue ( trycol . Attribute . MapType , p . GetValue ( dywhere , null ) ) ) ) ;
341+ sb . Append ( aliasAndDot ) . Append ( this . QuoteSqlName ( trycol . Attribute . Name ) ) . Append ( " = " ) ;
342+ sb . Append ( GetNoneParamaterSqlValue ( null , null , trycol , trycol . Attribute . MapType , Utils . GetDataReaderValue ( trycol . Attribute . MapType , p . GetValue ( dywhere , null ) ) ) ) ;
343343 ++ psidx ;
344344 }
345345 if ( psidx == 0 ) return "" ;
@@ -360,8 +360,8 @@ public string WhereItems<TEntity>(TableInfo table, string aliasAndDot, IEnumerab
360360 sbin . Append ( aliasAndDot ) . Append ( this . QuoteSqlName ( pk1 . Attribute . Name ) ) ;
361361 var indt = its . Select ( a => pk1 . GetDbValue ( a ) ) . Where ( a => a != null ) . ToArray ( ) ;
362362 if ( indt . Any ( ) == false ) return null ;
363- if ( indt . Length == 1 ) sbin . Append ( " = " ) . Append ( this . FormatSql ( "{0}" , indt . First ( ) ) ) ;
364- else sbin . Append ( " IN (" ) . Append ( string . Join ( "," , indt . Select ( a => this . FormatSql ( "{0}" , a ) ) ) ) . Append ( ")" ) ;
363+ if ( indt . Length == 1 ) sbin . Append ( " = " ) . Append ( GetNoneParamaterSqlValue ( null , null , pk1 , pk1 . Attribute . MapType , indt . First ( ) ) ) ;
364+ else sbin . Append ( " IN (" ) . Append ( string . Join ( "," , indt . Select ( a => GetNoneParamaterSqlValue ( null , null , pk1 , pk1 . Attribute . MapType , a ) ) ) ) . Append ( ")" ) ;
365365 return sbin . ToString ( ) ;
366366 }
367367 var dicpk = its . Length > 5 ? new Dictionary < string , bool > ( ) : null ;
@@ -371,7 +371,7 @@ public string WhereItems<TEntity>(TableInfo table, string aliasAndDot, IEnumerab
371371 {
372372 var filter = "" ;
373373 foreach ( var pk in table . Primarys )
374- filter += $ " AND { aliasAndDot } { this . QuoteSqlName ( pk . Attribute . Name ) } = { this . FormatSql ( "{0}" , pk . GetDbValue ( item ) ) } ";
374+ filter += $ " AND { aliasAndDot } { this . QuoteSqlName ( pk . Attribute . Name ) } = { GetNoneParamaterSqlValue ( null , null , pk , pk . Attribute . MapType , pk . GetDbValue ( item ) ) } ";
375375 if ( string . IsNullOrEmpty ( filter ) ) continue ;
376376 if ( sb != null )
377377 {
0 commit comments