@@ -28,8 +28,6 @@ public abstract partial class SqlExpression<T> : ISqlExpression, IHasUntypedSqlE
28
28
protected bool useFieldName = false ;
29
29
protected bool selectDistinct = false ;
30
30
protected bool CustomSelect { get ; set ; }
31
- protected bool SkipParameterizationForThisExpression { get ; set ; }
32
- private bool visitedExpressionIsTableColumn = false ;
33
31
private ModelDefinition modelDef ;
34
32
public bool PrefixFieldWithTableName { get ; set ; }
35
33
public bool WhereStatementWithoutWhereString { get ; set ; }
@@ -46,7 +44,6 @@ public SqlExpression(IOrmLiteDialectProvider dialectProvider)
46
44
modelDef = typeof ( T ) . GetModelDefinition ( ) ;
47
45
PrefixFieldWithTableName = false ;
48
46
WhereStatementWithoutWhereString = false ;
49
- SkipParameterizationForThisExpression = false ;
50
47
DialectProvider = dialectProvider ;
51
48
Params = new List < IDbDataParameter > ( ) ;
52
49
tableDefs . Add ( modelDef ) ;
@@ -930,8 +927,6 @@ protected internal bool UseFieldName
930
927
931
928
protected internal virtual object Visit ( Expression exp )
932
929
{
933
- visitedExpressionIsTableColumn = false ;
934
-
935
930
if ( exp == null ) return string . Empty ;
936
931
switch ( exp . NodeType )
937
932
{
@@ -993,10 +988,7 @@ protected internal virtual object Visit(Expression exp)
993
988
994
989
protected internal virtual object VisitJoin ( Expression exp )
995
990
{
996
- SkipParameterizationForThisExpression = true ;
997
- var visitedExpression = Visit ( exp ) ;
998
- SkipParameterizationForThisExpression = false ;
999
- return visitedExpression ;
991
+ return Visit ( exp ) ;
1000
992
}
1001
993
1002
994
protected virtual object VisitLambda ( LambdaExpression lambda )
@@ -1015,11 +1007,14 @@ protected virtual object VisitLambda(LambdaExpression lambda)
1015
1007
return Visit ( lambda . Body ) ;
1016
1008
}
1017
1009
1018
- protected virtual object VisitBinary ( BinaryExpression b )
1010
+ public virtual object GetValue ( object value , Type type )
1019
1011
{
1020
- var skipParameterizationForThisVisit = false ;
1012
+ return DialectProvider . GetQuotedValue ( value , type ) ;
1013
+ }
1021
1014
1022
- object left , right ;
1015
+ protected virtual object VisitBinary ( BinaryExpression b )
1016
+ {
1017
+ object originalLeft = null , originalRight = null , left , right ;
1023
1018
var operand = BindOperant ( b . NodeType ) ; //sep= " " ??
1024
1019
if ( operand == "AND" || operand == "OR" )
1025
1020
{
@@ -1050,18 +1045,12 @@ protected virtual object VisitBinary(BinaryExpression b)
1050
1045
}
1051
1046
else
1052
1047
{
1053
- left = Visit ( b . Left ) ;
1054
- right = Visit ( b . Right ) ;
1055
-
1056
- if ( visitedExpressionIsTableColumn || ( right is DateTimeOffset ) )
1057
- skipParameterizationForThisVisit = true ;
1048
+ originalLeft = left = Visit ( b . Left ) ;
1049
+ originalRight = right = Visit ( b . Right ) ;
1058
1050
1059
1051
var leftEnum = left as EnumMemberAccess ;
1060
1052
var rightEnum = right as EnumMemberAccess ;
1061
1053
1062
- if ( leftEnum != null && rightEnum != null )
1063
- skipParameterizationForThisVisit = true ;
1064
-
1065
1054
var rightNeedsCoercing = leftEnum != null && rightEnum == null ;
1066
1055
var leftNeedsCoercing = rightEnum != null && leftEnum == null ;
1067
1056
@@ -1070,9 +1059,7 @@ protected virtual object VisitBinary(BinaryExpression b)
1070
1059
var rightPartialSql = right as PartialSqlString ;
1071
1060
if ( rightPartialSql == null )
1072
1061
{
1073
- right = SkipParameterizationForThisExpression
1074
- ? DialectProvider . GetQuotedValue ( right , leftEnum . EnumType )
1075
- : DialectProvider . GetValue ( right , leftEnum . EnumType ) ;
1062
+ right = GetValue ( right , leftEnum . EnumType ) ;
1076
1063
}
1077
1064
}
1078
1065
else if ( leftNeedsCoercing )
@@ -1092,19 +1079,14 @@ protected virtual object VisitBinary(BinaryExpression b)
1092
1079
left = DialectProvider . GetQuotedValue ( left , left != null ? left . GetType ( ) : null ) ;
1093
1080
else if ( right as PartialSqlString == null )
1094
1081
{
1095
- right = SkipParameterizationForThisExpression
1096
- ? DialectProvider . GetQuotedValue ( right , right != null ? right . GetType ( ) : null )
1097
- : DialectProvider . GetValue ( right , right != null ? right . GetType ( ) : null ) ;
1082
+ right = GetValue ( right , right != null ? right . GetType ( ) : null ) ;
1098
1083
}
1099
1084
}
1100
1085
1101
1086
if ( operand == "=" && right . ToString ( ) . Equals ( "null" , StringComparison . OrdinalIgnoreCase ) ) operand = "is" ;
1102
1087
else if ( operand == "<>" && right . ToString ( ) . Equals ( "null" , StringComparison . OrdinalIgnoreCase ) ) operand = "is not" ;
1103
1088
1104
- if ( operand == "AND" || operand == "OR" || operand == "is" || operand == "is not" )
1105
- skipParameterizationForThisVisit = true ;
1106
-
1107
- DoParameterization ( skipParameterizationForThisVisit , ref right ) ;
1089
+ VisitFilter ( operand , originalLeft , originalRight , ref left , ref right ) ;
1108
1090
1109
1091
switch ( operand )
1110
1092
{
@@ -1116,16 +1098,7 @@ protected virtual object VisitBinary(BinaryExpression b)
1116
1098
}
1117
1099
}
1118
1100
1119
- private void DoParameterization ( bool skipParameterizationForThisVisit , ref object right )
1120
- {
1121
- if ( skipParameterizationForThisVisit )
1122
- return ;
1123
-
1124
- if ( SkipParameterizationForThisExpression )
1125
- return ;
1126
-
1127
- ConvertToPlaceholderAndParameter ( ref right ) ;
1128
- }
1101
+ protected virtual void VisitFilter ( string operand , object originalLeft , object originalRight , ref object left , ref object right ) { }
1129
1102
1130
1103
protected virtual object VisitMemberAccess ( MemberExpression m )
1131
1104
{
@@ -1144,9 +1117,9 @@ protected virtual object VisitMemberAccess(MemberExpression m)
1144
1117
}
1145
1118
}
1146
1119
1120
+ OnVisitMemberType ( modelType ) ;
1121
+
1147
1122
var tableDef = modelType . GetModelDefinition ( ) ;
1148
- if ( tableDef != null )
1149
- visitedExpressionIsTableColumn = true ;
1150
1123
1151
1124
if ( propertyInfo . PropertyType . IsEnum )
1152
1125
return new EnumMemberAccess (
@@ -1161,6 +1134,8 @@ protected virtual object VisitMemberAccess(MemberExpression m)
1161
1134
return getter ( ) ;
1162
1135
}
1163
1136
1137
+ protected virtual void OnVisitMemberType ( Type modelType ) { }
1138
+
1164
1139
protected virtual object VisitMemberInit ( MemberInitExpression exp )
1165
1140
{
1166
1141
return Expression . Lambda ( exp ) . Compile ( ) . DynamicInvoke ( ) ;
@@ -1189,7 +1164,6 @@ protected virtual object VisitNew(NewExpression nex)
1189
1164
}
1190
1165
return r . ToString ( ) ;
1191
1166
}
1192
-
1193
1167
}
1194
1168
1195
1169
protected virtual object VisitParameter ( ParameterExpression p )
@@ -1654,10 +1628,6 @@ protected virtual object VisitColumnAccessMethod(MethodCallExpression m)
1654
1628
return new PartialSqlString ( statement ) ;
1655
1629
}
1656
1630
1657
- protected virtual void ConvertToPlaceholderAndParameter ( ref object right )
1658
- {
1659
- }
1660
-
1661
1631
public IDbDataParameter CreateParam ( string name ,
1662
1632
object value = null ,
1663
1633
ParameterDirection direction = ParameterDirection . Input ,
0 commit comments