Forum > Databases
How can I find out if a table
Kalevi:
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:
With a simple SQL query like:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SELECT name FROM sqlite_master WHERE type='table' AND name='table_name_to_look'If the count = 0 than table does not exists.
wp:
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:
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:
Try this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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;
Navigation
[0] Message Index
[#] Next page