[SOLVED] SQLite insert multiple record lazarus / 16-Databases ---------------------------------------------------------------------- Pe3s · 2023-08-27 08:20 Hello, I use sqlite database and I want to make a playlist and here the question arises, how can I add and delete many files? Regards Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.AddFile(AName: String);begin  ZQuery1.Close;  ZQuery1.SQL.Clear;  ZQuery1.SQL.Text := 'INSERT INTO lista(File) values(:File)';  ZQuery1.ParamByName('File').AsString := AName;  ZQuery1.ExecSQL;   ZQuery1.Close;  ZQuery1.SQL.Clear;  ZQuery1.SQL.Text := 'SELECT * FROM lista';  ZQuery1.Open;end;                           Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  if OpenDialog1.Execute then  begin    AddFile(OpenDialog1.FileName);  end;end; ---------------------------------------------------------------------- Чебурашка · 2023-08-27 08:32 You could modify addfile to addfiles, and make it receive a files:tstrings, where you put the list of files you want store in db (repeat insert query for each item in tstrings). Then see how to make open file dialog to get a selection of multiple files. ---------------------------------------------------------------------- cdbc · 2023-08-27 08:43 Hi To explain @Чебурашка's idea...  It goes something like this:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.AddFiles(aFiles: TStrings);var  S: string;begin  ZQuery1.Close;  ZQuery1.SQL.Clear;  ZQuery1.SQL.Text := 'INSERT INTO lista(File) values(:File)';  for S in aFiles do begin    ZQuery1.ParamByName('File').AsString := S;    ZQuery1.ExecSQL;  end;  ZQuery1.Close;  ZQuery1.SQL.Clear;  ZQuery1.SQL.Text := 'SELECT * FROM lista';  ZQuery1.Open;end;                             And then you have to feed it:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  if OpenDialog1.Execute then  begin    AddFiles(OpenDialog1.Files);  end;end; Of course, you have to set OpenDialog1.Options to include "doMultiSelect", in the Object Inspector... (...or something like that, can't remember exactly). HTH  Regards Benny ---------------------------------------------------------------------- Pe3s · 2023-08-27 09:32 What do I need to fix to make dropping files on the form work? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);var  i: Integer;begin  for i := Low(FileNames) to High(FileNames) do  begin    AddFile(FileNames[i]);  end;end; ---------------------------------------------------------------------- TRon · 2023-08-27 16:05 Quote from: Pe3s on August 27, 2023, 11:32:38 amWhat do I need to fix to make dropping files on the form work? Convert your FIleNames (array of string) to a TStringList and feed that to your AddFiles() routine. Something like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);var  sl: tstringlist;begin  sl := TStringlsit.Create;  sl.Addstrings(Filenames)  AddFiles(sl);  sl.Free;end; ---------------------------------------------------------------------- Pe3s · 2023-08-27 16:50 Thank you for your help Regards ---------------------------------------------------------------------- Zvoni · 2023-08-28 07:02 Or if there is no "direct" User-Input (like a TEdit) you can forgo Parameters and the Loop Untested Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Uses SysUtils; //For TypeHelperprocedure TForm1.AddFiles(AFiles: String);begin  ZQuery1.Close;  ZQuery1.SQL.Clear;  ZQuery1.SQL.Text := 'INSERT INTO lista(File) values'+AFiles;  //This results in something like INSERT INTO Lista(File) VALUES('Song0'),('Song1'),('Song2'),('Son g3'),('Song4'),('Song5'),('Song6'),('Song7'),('Song8'),('Song9')  ZQuery1.ExecSQL;   ZQuery1.Close;  ZQuery1.SQL.Clear;  ZQuery1.SQL.Text := 'SELECT * FROM lista';  ZQuery1.Open;end;      procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);var  i:Integer;  s:String;  a:Array Of String;begin  SetLength(a,Length(FileNames));  For i:=Low(FileNames) To High(FileNames) Do    a[i]:='('+QuotedStr(FileNames[i])+')';  //This results in Something like ('Song0'),('Song1'),('Song2'),('Song3'),('So ng4'),('Song5'),('Song6'),('Song7'),('Song8'),('Song9')  s:=s.Join(',',a);          AddFiles(s);  end;