Bonjour
je souhaite retrouver dans une base SQlite toutes les valeurs avec ET sans accents et autres diacritiques
je cherche "Jérémy", je souhaiterais qu'un LIKE '%JEREMY%' me ramène jeremy, jérémy, JÉRÉMY...
Mauvaise solution :
Je le faisais précédemment avec Delphi 7 et les composants Zeos comme ceci :
Cela fonctionnait... lentement! Je le mets dans le message pour servir éventuellement.Citation:
WHERE ((REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(author,'à','a'),'á','a'),'å','a'),'â','a'),'ä','a'),'ã','a'),'é','e'),'è','e'),'ë','e'),'ê','e'),'ì','i'),'í','i'),'î','i'),'ï','i'),'ò','o'),'ø','o'),'ô','o'),'ö','o'),'õ','o'),'ú','u'),'ù','u'),'ü','u'),'û','u'),'ý','y'),'ÿ','y') LIKE '%JEREMY%')
OR (REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(author,'Á','A'),'Â','A'),'Ã','A'),'Ä','A'),'Å','A'),'È','E'),'É','E'),'É','E'),'Ê','E'),'Ë','E'),'Ì','I'),'Í','I'),'Î','I'),'Ï','I'),'Ì','I'),'Ò','O'),'Ó','O'),'Ô','O'),'Õ','O'),'Ö','O'),'Ù','U'),'Ú','U'),'Û','U'),'Ü','U') LIKE '%JEREMY%'))
Problème actuelCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 //////////////////////////////////////////////////////////////////////////////// // Pour créer les chaînes, avec la recherche en "aValue" function SqlReplace1(aValue: string): string; Var S1,S2,S3 : string; i : integer; begin S1 :='àáåâäãéèëêìíîïòøôöõúùüûýÿ'; S2 :='aaaaaaeeeeiiiiooooouuuuyy'; S3 :='' ; for i:= 1 to length(S1) do S3:=S3+'REPLACE('; S3:=S3+aValue; for i:= 1 to length(S1) do S3:=S3+','+quotedstr(S1[i])+','+quotedstr(S2[i])+')'; result := S3+' '; end; //////////////////////////////////////////////////////////////////////////////// function SqlReplace2(aValue: string): string; Var S1,S2,S3 : string; i : integer; begin S1 :='ÁÂÃÄÅÈÉÉÊËÌÍÎÏÌÒÓÔÕÖÙÚÛÜ'; S2 :='AAAAAEEEEEIIIIIOOOOOUUUU'; S3 :='' ; for i:= 1 to length(S1) do S3:=S3+'REPLACE('; S3:=S3+aValue; for i:= 1 to length(S1) do S3:=S3+','+quotedstr(S1[i])+','+quotedstr(S2[i])+')'; result := S3+' '; end;
J'ai implémenté le code préconisé par RAD STUDIO et FireDAC
(exemple : FireDAC.Phys.SQLite.TFDSQLiteCollation)
et modifié le code en tenant compte de ce message (Epées et FireDac SQLite), mais ça ne fonctionne pas.
J'ai modifié certains paramètres du composant sans succès.
Voila le résultat, je voudrais avec les 3 recherches avec le mot "PERE"
https://i.imgur.com/pObVpiM.jpg
Merci de votre aide, ou de me dire si je suis dans la bonne direction au moins.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 procedure TForm1.FormCreate(Sender: TObject); begin with FDConnection do if Connected then Connected := False; SQLitePhysDriverLink:= TFDPhysSQLiteDriverLink.Create(nil); SQLiteCollation:= TFDSQLiteCollation.Create(nil); With SQLiteCollation do begin Active := False; DriverLink := SQLitePhysDriverLink; CollationName := 'UTF16NoCase'; Flags := [sfLingIgnoreCase,sfLingIgnoreDiacritic,sfIgnoreCase]; Active := True; end; {Ouverture de FDConnection après activation de SQLiteCollation } with FDConnection do begin Params.Add ('DriverID = SQLite'); {Inutile ici} Params.Add ('OpenMode = CreateUTF8'); {Idem} Connected := True; end; end; procedure TForm1.btnFindClick(Sender: TObject); begin sSql.Clear; sSql.add('SELECT CAST(AUTHOR_SORT AS varchar(255)) AS AUTEUR,'); sSql.add('CAST(TITLE AS varchar(255)) AS TITRE'); sSql.add('FROM "BOOKS" '); sSql.add('WHERE'); sSql.Add('BOOKS.AUTHOR_SORT LIKE '+quotedstr('%'+edAuteur.Text+'%')); sSql.Add('ORDER BY AUTHOR_SORT, TITLE'); memoOut.Lines.Assign(sSql); qryBooks.Open(sSql.Text); caption := inttostr(DSBooks.DataSet.recordcount); end;