How to programmatically connect to SQLite ? lazarus / 16-Databases ---------------------------------------------------------------------- engine32 · 2022-11-15 01:35 Hello,   I am working on an application with four worker threads that needs access to the SQLite database. I read online that I should not use a single connection established with visual component in the main thread but use one connection per thread. I am looking for some advice of how to establish the connection to the database and then read / write   to it from individual threads.   Thank you. ---------------------------------------------------------------------- Leledumbo · 2022-11-15 01:45 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  db, sqldb, sqlite3conn;var  Conn: TSQLConnector;  Query: TSQLQuery;  F: TField;begin  Conn := TSQLConnector.Create(nil);  with Conn do begin  ConnectorType := 'SQLite3';    HostName := ''; // unread by underlying TSQLite3Connection    DatabaseName := '/path/to/sqlite/db/file.sqlite';    UserName := ''; // unread by underlying TSQLite3Connection    Password := ''; // this is still read, if you use the encrypted db feature    Transaction := TSQLTransaction.Create(Conn);  end;   Query := TSQLQuery.Create(nil);  Query.DataBase := Conn;   Query.SQL.Text := 'select * from tables'; // make your own query  Query.Open;  while not Query.EOF do begin    for F in Query.Fields do begin      Write(F.FieldName,' = ');      if F.IsNull then WriteLn('NULL') else WriteLn(F.Value);    end;    WriteLn;    Query.Next;  end;  Query.Close;  Query.Free;  Conn.Free;end. ---------------------------------------------------------------------- Zvoni · 2022-11-15 07:05 Quote from: Leledumbo on November 15, 2022, 02:45:54 amuses   db, sqldb, mysql56conn; *snipp*   with Conn do begin     ConnectorType := 'SQLite3'; *snipp* ?!?!???!??!??! Especially for SQLite don't forget to set the proper OpenFlags, and, IIRC, to set Journal_mode-Pragma to WAL ---------------------------------------------------------------------- Leledumbo · 2022-11-15 08:55 Quote from: Zvoni on November 15, 2022, 08:05:54 amQuote from: Leledumbo on November 15, 2022, 02:45:54 amuses   db, sqldb, mysql56conn; *snipp*   with Conn do begin     ConnectorType := 'SQLite3'; *snipp* ?!?!???!??!??! Especially for SQLite don't forget to set the proper OpenFlags, and, IIRC, to set Journal_mode-Pragma to WAL Oops, forgot to change that. My original example code was indeed to connect with MySQL 5.6 or MariaDB 10.0 equivalent.