SQLite, code only, no TSQLite3Connection lazarus / 16-Databases ---------------------------------------------------------------------- jbmckim · 2018-02-03 00:55 I like the DB connectors and I'll use the SQLite connector if need be but I was wondering if there was a "code only" solution.  I'm starting what will likely be a rather large project and I'd like to have my DB access all run through one unit.  This unit will be a worker bee and won't have a UI.  I've looked and maybe my Google skills aren't that sharp but everything I find uses the connectors dropped on a UI. Thanks. ---------------------------------------------------------------------- valdir.marcos · 2018-02-03 02:14 Take a look here: [Solved]How can I create TSQLite3 components in a unit at run time. http://forum.lazarus.freepascal.org/index.php/topic,30398.msg193409.ht ml#msg193409 ---------------------------------------------------------------------- GAN · 2018-02-03 02:27 I use this unit in my projects. I use ZeosLib but it will serve as a guide. 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 unit dbfunctions; {$mode objfpc}{$H+} interface uses    Classes, SysUtils, db, ZConnection, ZDataset, FileUtil    ; function DB_Exists (sDBase, sTable, sField, sValue: String) : Integer; implementation  function DB_Exists (sDBase, sTable, sField, sValue: String) : Integer;    //-1 Database does not existvar                                                                     // 0 Database not Found  ZConn:TZConnection;                                                     // >0 Number of records found  ZQry:TZQuery;  DSource:TDataSource;  iRet:Integer=0;begin  if not(FileExists(sDBase)) then Exit(-1);  ZConn:=TZConnection.Create(nil);  ZQry:=TZQuery.Create(nil);  DSource:=TDataSource.Create(nil);  ZConn.Protocol:='sqlite-3';  ZConn.Database:=sDBase;  ZConn.Connect;  ZQry.Connection:=ZConn;  DSource.DataSet:=ZQry;  DSource.Enabled:=True;  ZQry.SQL.Text:='SELECT '+sField+' FROM '+sTable+' WHERE '+sField+'='+QuotedStr(sValue)+' ;';  ZQry.Open;  iRet:=ZQry.RecordCount;  ZQry.Close;  DSource.Enabled:=False;  ZConn.Disconnect;  FreeAndNil(ZConn);  FreeAndNil(ZQry);  FreeAndNil(DSource);  DB_Exists:=iRet;end; end. ---------------------------------------------------------------------- Thaddy · 2018-02-03 10:09 Quote from: valdir.marcos on February 03, 2018, 03:14:44 amTake a look here: [Solved]How can I create TSQLite3 components in a unit at run time. http://forum.lazarus.freepascal.org/index.php/topic,30398.msg193409.ht ml#msg193409 Indeed. Actually I never use the visual component, I always do it like that. ---------------------------------------------------------------------- jbmckim · 2018-02-03 21:36 Thanks all, Just to put things (mostly) all in one place: You do need some things in "uses" 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,...; Then this - I put this in the global vars for the unit: 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 var  DBconnection: TSQLite3Connection; Then 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 DBconnection := TSQLite3Connection.Create(nil);   Mostly putting this here so I can google it later to remind myself ---------------------------------------------------------------------- jbmckim · 2018-02-03 21:43 And here's a good example of how to use after things are defined: http://wiki.freepascal.org/TSQLite3Connection