diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 60f1d236..0f5bd0e4 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -344,6 +344,7 @@ type procedure ParseRoutineStructure(Obj: TDBObject; Parameters: TRoutineParamList); function GetDatatypeByName(Datatype: String): TDBDatatype; function ApplyLimitClause(QueryType, QueryBody: String; Limit, Offset: Cardinal): String; + function LikeClauseTail: String; property Parameters: TConnectionParameters read FParameters write FParameters; property ThreadId: Cardinal read GetThreadId; property ConnectionUptime: Integer read GetConnectionUptime; @@ -2264,17 +2265,16 @@ begin EscChar := ''''; Result := escChars(Text, EscChar, c1, c2, c3, c4); - { // TODO: escape joker chars % and _ in conjunction with a specified escape char after the WHERE clause. - // Did not work on MSSQL 2008 here. - // http://www.techtamasha.com/escape-single-quotes-and-wild-cards-_-in-ms-sql/20 + // Escape joker chars % and _ in conjunction with a specified escape char after the WHERE clause. + // See http://www.heidisql.com/forum.php?t=12747 if ProcessJokerChars then begin c1 := '%'; c2 := '_'; c4 := '_'; c3 := '_'; EscChar := '\'; - Result := escChars(Text, EscChar, c1, c2, c3, c4); - end; } + Result := escChars(Result, EscChar, c1, c2, c3, c4); + end; end; end; @@ -3654,6 +3654,15 @@ begin end; +function TDBConnection.LikeClauseTail: String; +begin + case FParameters.NetTypeGroup of + ngMSSQL: Result := ' ESCAPE ' + EscapeString('\'); + ngMySQL: Result := ''; + end; +end; + + { TMySQLQuery } diff --git a/source/main.pas b/source/main.pas index 2b446b25..01410097 100644 --- a/source/main.pas +++ b/source/main.pas @@ -5352,6 +5352,9 @@ begin end else Filter := Item.Hint; + if ExecRegExpr('\s+LIKE\s+''', Filter) then + Filter := Filter + ActiveConnection.LikeClauseTail; + if Filter <> '' then begin SynMemoFilter.UndoList.AddGroupBreak; SynMemoFilter.SelectAll; @@ -7629,6 +7632,7 @@ begin Line := ''; end; end; + Clause := Clause + Conn.LikeClauseTail; end; SynMemoFilter.UndoList.AddGroupBreak; SynMemoFilter.SelectAll;