Menu

Problem with ' character in filter string

2006-04-08
2013-12-19
  • xxxxxxxxxxxxxxxxx

    Hello, i use this function to filter my dbf tables but i've one problem. When the string cFilter contain a ' character the program crashe because '  seem's not escaped in filter. I try to replace ' with '' in CFilter to escape it but the result is the same.
    What can i do to have filter working with a ' character in a value to filter ?
    Thank's
    -------------------------------------
    Function TFDbf_Func.Set_Filter_01 ( F_Name, CFilter: String; Dbf:TDbf; nFilter:Integer ):Boolean;
    Begin
      with Dbf do begin
        Filtered:=False;
        FilterOptions:=[foCaseInsensitive,foNoPartialCompare];
        Case nFilter Of
          0:Filter:=''+F_Name+'='''+CFilter+'''';     // 0 Egal à
          1:Filter:=''+F_Name+'>'''+CFilter+'''';     // 1 Plus grand que
          2:Filter:=''+F_Name+'>='''+CFilter+'''';    // 2 Egal ou plus grand que
          3:Filter:=''+F_Name+'<'''+CFilter+'''';     // 3 Plus petit qu
          4:Filter:=''+F_Name+'<='''+CFilter+'''';    // 4 Egal ou plusz petit que
          5:Filter:=''+F_Name+'<>'''+CFilter+'''';    // 5 Différent de
        end;
    ///showmessage (filter);
        Filtered:=True;
        First;
        Result:=Not EOF;
      end;
    End;     

     
    • Micha Nelissen

      Micha Nelissen - 2006-04-08

      To escape ' use ", and the other way around. The following should work:

      Filter := 'FIELD1="VALUE1''"';

       
    • xxxxxxxxxxxxxxxxx

      That's work !

      thank's

       
  • Reinier Olislagers

    The problem is of course the case where you want to filter on both ' and ". Seems like dbf_prscore does not allow for this.

    I'll have a look to see how the DBase products dealt with this - I'd normally expect to use something like
    Filter := 'FIELD1="Value with double ""quotes"" in it"; //i.e. escape using a doubled delimiter

     

Log in to post a comment.