Depends of SGBD I think, but if not it's possible to, use Firedac macros
1- This zip contains a SQLite database not a MySQL one as indicated first !
2- The database contains a really poor lines for testing ! And nothing to do with directories
Suggestion for Button2.OnClick
uses System.IoUtils;
procedure TForm1.Button2Click(Sender: TObject);
var FileListe : TArray<String>;
i: integer;
begin
FileListe:=TDirectory.GetFiles(Edit1.Text);
for var s: String in FileListe
do i:=i+FDQuery1.ExecSQL('INSERT INTO Files(maindirectory) Values (:s)',[S]);
Showmessage(i.ToString+' records added');
end;
Suggestion for Query
procedure TForm1.Button1Click(Sender: TObject);
begin
FDQuery1.Close;
FDQuery1.SQL.Text:='SELECT Maindirectory from files WHERE Maindirectory LIKE &S';
FDQuery1.MacroByName('S').AsRaw:=Quotedstr(Edit1.Text+'%');
FDQuery1.Open;
end;
As you can see, this also include ability to use macro char % in the like clause value
so for MySQL INSTR function, you can set Edit1.Text to '%AEnvoyer'
TAKE CARE of SQL Injection with macro usage
Ah, yes 👍
so Button2.Onclick can be wrote on different ways
procedure TForm1.Button1Click(Sender: TObject);
begin
// FDQuery1.Close;
// By Macro Need FDQuery1.Close and FDQuery1.Open
// FDQuery1.SQL.Text:='SELECT Maindirectory from files WHERE Maindirectory LIKE &S';
// FDQuery1.MacroByName('S').AsRaw:=Quotedstr(Edit1.Text+'%');
// By Parameter Need FDQuery1.Close and FDQuery1.Open
// FDQuery1.SQL.Text:='SELECT Maindirectory from files WHERE Maindirectory LIKE :p';
// FDQuery1.ParamByName('P').AsString:=Edit1.Text+'%';
// FDQuery1.Open;
// By Parameter No Need of FDQuery1.Close and FDQuery1.Open, my preference
FDQuery1.Open('SELECT Maindirectory from files WHERE Maindirectory LIKE :p',
[Edit1.Text+'%']) ;
end;