Browse Source

* fcl-db: test filter using double delimiters inside string to test syntax as presented in issue #25432
allow escaping delimiters by doubling them e.g.
Filter:='(NAME=''O''''Malley''''s "Magic" Hammer'')';
which gives
(NAME='O''Malley''s "Magic" Hammer')
which will match
O'Malley's "Magic" Hammer

git-svn-id: trunk@26249 -

reiniero 11 years ago
parent
commit
f27d3baccc
1 changed files with 44 additions and 0 deletions
  1. 44 0
      packages/fcl-db/tests/testdbbasics.pas

+ 44 - 0
packages/fcl-db/tests/testdbbasics.pas

@@ -1368,6 +1368,7 @@ begin
     next;
     CheckTrue(EOF);
 
+    // Valid data with partial compare
     Filter := '(name=''*name*'')';
     first;
     CheckFalse(EOF);
@@ -1378,10 +1379,53 @@ begin
     CheckEquals(2,FieldByName('ID').asinteger);
     CheckEquals('TestName2',FieldByName('NAME').asstring);
 
+    // Invalid data with partial compare
     Filter := '(name=''*neme*'')';
     first;
     CheckTrue(EOF);
 
+    // Modify so we can use some tricky data
+    Filter := ''; //show all records again and allow edits
+    First;
+    Edit;
+    // Record 1=O'Malley
+    FieldByName('NAME').AsString := 'O''Malley';
+    Post;
+
+    Next;
+    Edit;
+    // Record 2="Magic" Mushroom
+    FieldByName('NAME').AsString := '"Magic" Mushroom';
+    Post;
+
+    Next;
+    Edit;
+    // Record 3=O'Malley's "Magic" Mushroom
+    FieldByName('NAME').AsString := 'O''Malley''s "Magic" Mushroom';
+    Post;
+
+    // Test searching on " which can be a delimiter
+    Filter := '(name=''*"Magic"*'')'; //should give record 2 and 3
+    first;
+    CheckFalse(EOF);
+    CheckEquals(2,FieldByName('ID').asinteger,'Search for strings with ", partial compare');
+    CheckEquals('"Magic" Mushroom',FieldByName('NAME').asstring,'Search for strings with ", partial compare');
+    next;
+    CheckFalse(EOF);
+    CheckEquals(3,FieldByName('ID').asinteger,'Search for strings with ", partial compare');
+    CheckEquals('O''Malley''s "Magic" Mushroom',FieldByName('NAME').asstring,'Search for strings with ", partial compare');
+
+    // Search for strings with ' escaped, partial compare delimited by '
+    Filter := '(name=''O''''Malley*'')'; //should give record 1 and 3
+    first;
+    CheckFalse(EOF);
+    CheckEquals(1,FieldByName('ID').asinteger,'Search for strings with '' escaped, partial compare delimited by ''');
+    CheckEquals('O''Malley',FieldByName('NAME').asstring,'Search for strings with '' escaped, partial compare delimited by ''');
+    next;
+    CheckFalse(EOF);
+    CheckEquals(3,FieldByName('ID').asinteger,'Search for strings with '' escaped, partial compare delimited by ''');
+    CheckEquals('O''Malley''s "Magic" Mushroom',FieldByName('NAME').asstring,'Search for strings with '' escaped, partial compare delimited by ''');
+
     Close;
     end;
 end;