How can I find out if a table lazarus / 16-Databases ---------------------------------------------------------------------- Kalevi · 2022-11-03 09:55 How can I find out if a table (table name) is already ready in the database when I start the node?Using SQLite Database and  TSQLite3Connection  TSQLTransaction; ---------------------------------------------------------------------- KodeZwerg · 2022-11-03 10:35 With a simple SQL query 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 SELECT name FROM sqlite_master WHERE type='table' AND name='table_name_to_look'If the count = 0 than table does not exists. ---------------------------------------------------------------------- wp · 2022-11-03 11:11 Every descendant of TSQLConnection - TSqlite3Connection is one - has a method GetTableNames which exports the names of the existing tables into a TStrings (e.g. TStringList): https://www.freepascal.org/docs- html/fcl/sqldb/tsqlconnection.gettablenames.html ---------------------------------------------------------------------- Kalevi · 2022-11-03 12:09 I did this procedure, but it doesn't work ! function LookTableName(tablename: String): Boolean; var   lista: TStringList;       I: Integer; begin   Result := False;   lista := TStringList.Create;    SQLite3Connection1.GetFieldNames(tablename,Lista);   I := 0;   while (not Result) and (I < lista.Count) do begin      Result := tablename = lista;      Inc(I);      end;   lista.Free; end; ---------------------------------------------------------------------- wp · 2022-11-03 12:51 Try 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 function LookTableName(tablename: String): Boolean;var  lista: TStringList;begin  Result := False;  lista := TStringList.Create;  try    SQLite3Connection1.GetFieldNames(tablename,Lista);    Result := lista.IndexOf(tablename) > -1;  finally    lista.Free;  end;end; ---------------------------------------------------------------------- Kalevi · 2022-11-03 13:14 Kiitos wp , mutta en saanut tuotakaan toimimaan ! The program is running normally, but I would like to add one table to the database, and for this purpose I want to check if the table has been added.There's a datamodule in the program that connects to the database and I've tried that function since the connection to the database exists. ---------------------------------------------------------------------- Kalevi · 2022-11-03 13:15 Sorry for Finnish Thanks for the wp, but I couldn't make that work either. ---------------------------------------------------------------------- Zvoni · 2022-11-03 13:16 In Germany, we have a "fun" Game. It's called "spot the Mistake" Quote from: wp on November 03, 2022, 12:11:19 pmEvery descendant of TSQLConnection - TSqlite3Connection is one - has a method GetTableNames which exports the names of the existing tables into a TStrings (e.g. TStringList): https://www.freepascal.org/docs- html/fcl/sqldb/tsqlconnection.gettablenames.html     function LookTableName(tablename: String): Boolean;     var       lista: TStringList;     begin       Result := False;       lista := TStringList.Create;       try         SQLite3Connection1.GetFieldNames(tablename,Lista);         Result := lista.IndexOf(tablename) > -1;       finally         lista.Free;       end;     end; ---------------------------------------------------------------------- Kalevi · 2022-11-03 13:36 Great, I should just get my own code wrong, thank you very much, Zvoni.Have a nice autumn follow-up for everyone! ---------------------------------------------------------------------- Zvoni · 2022-11-03 17:19 Quote from: Kalevi on November 03, 2022, 02:36:31 pmGreat, I should just get my own code wrong, thank you very much, Zvoni.Have a nice autumn follow-up for everyone! Btw: i just saw that you want to add a table, and check if it exists beforehand. Why? Sqlite supports CREATE TABLE IF NOT EXISTS If the table exists, nothing happens, if it doesn’t exist it gets created. No need to look it up. ---------------------------------------------------------------------- Kalevi · 2022-11-03 17:56 I'm stuffed with patterns and old habits.I've used other databases like Firebird before.Thank you for the guidance, Zvoni, I tried and that sentence worked very well, thus simplifying the code.