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;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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;
To escape ' use ", and the other way around. The following should work:
Filter := 'FIELD1="VALUE1''"';
That's work !
thank's
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
Fix for the FPC version of TDBF here:
http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&revision=26253