@@ -3001,17 +3001,53 @@ private CompileResult CompileExpr (Expression expr, List<object> queryArgs)
30013001 }
30023002 else if ( call . Method . Name == "Contains" && args . Length == 1 ) {
30033003 if ( call . Object != null && call . Object . Type == typeof ( string ) ) {
3004- sqlCall = "(" + obj . CommandText + " like ('%' || " + args [ 0 ] . CommandText + " || '%') )" ;
3004+ sqlCall = "( instr( " + obj . CommandText + ", " + args [ 0 ] . CommandText + ") >0 )" ;
30053005 }
30063006 else {
30073007 sqlCall = "(" + args [ 0 ] . CommandText + " in " + obj . CommandText + ")" ;
30083008 }
30093009 }
3010- else if ( call . Method . Name == "StartsWith" && args . Length == 1 ) {
3011- sqlCall = "(" + obj . CommandText + " like (" + args [ 0 ] . CommandText + " || '%'))" ;
3012- }
3013- else if ( call . Method . Name == "EndsWith" && args . Length == 1 ) {
3014- sqlCall = "(" + obj . CommandText + " like ('%' || " + args [ 0 ] . CommandText + "))" ;
3010+ else if ( call . Method . Name == "StartsWith" && args . Length >= 1 )
3011+ {
3012+ var startsWithCmpOp = StringComparison . CurrentCulture ;
3013+ if ( args . Length == 2 )
3014+ {
3015+ startsWithCmpOp = ( StringComparison ) args [ 1 ] . Value ;
3016+ }
3017+ switch ( startsWithCmpOp )
3018+ {
3019+ case StringComparison . Ordinal :
3020+ case StringComparison . CurrentCulture :
3021+ case StringComparison . InvariantCulture :
3022+ sqlCall = "( substr(" + obj . CommandText + ", 1, " + args [ 0 ] . Value . ToString ( ) . Length + ") = " + args [ 0 ] . CommandText + ")" ;
3023+ break ;
3024+ case StringComparison . OrdinalIgnoreCase :
3025+ case StringComparison . CurrentCultureIgnoreCase :
3026+ case StringComparison . InvariantCultureIgnoreCase :
3027+ sqlCall = "(" + obj . CommandText + " like (" + args [ 0 ] . CommandText + " || '%'))" ;
3028+ break ;
3029+ }
3030+
3031+ }
3032+ else if ( call . Method . Name == "EndsWith" && args . Length >= 1 ) {
3033+ var endsWithCmpOp = StringComparison . CurrentCulture ;
3034+ if ( args . Length == 2 )
3035+ {
3036+ endsWithCmpOp = ( StringComparison ) args [ 1 ] . Value ;
3037+ }
3038+ switch ( endsWithCmpOp )
3039+ {
3040+ case StringComparison . Ordinal :
3041+ case StringComparison . CurrentCulture :
3042+ case StringComparison . InvariantCulture :
3043+ sqlCall = "( substr(" + obj . CommandText + ", length(" + obj . CommandText + ") - " + args [ 0 ] . Value . ToString ( ) . Length + "+1, " + args [ 0 ] . Value . ToString ( ) . Length + ") = " + args [ 0 ] . CommandText + ")" ;
3044+ break ;
3045+ case StringComparison . OrdinalIgnoreCase :
3046+ case StringComparison . CurrentCultureIgnoreCase :
3047+ case StringComparison . InvariantCultureIgnoreCase :
3048+ sqlCall = "(" + obj . CommandText + " like ('%' || " + args [ 0 ] . CommandText + "))" ;
3049+ break ;
3050+ }
30153051 }
30163052 else if ( call . Method . Name == "Equals" && args . Length == 1 ) {
30173053 sqlCall = "(" + obj . CommandText + " = (" + args [ 0 ] . CommandText + "))" ;
0 commit comments