Forum > Database

Straight forward sqlite database

(1/2) > >>

vdijken:
I want to use a simple pascal/lazarus program using an sqlite database without using an IDE, forms etc. One of the tables has so much entries that it does not fit into an array and I need to search into it. But I cannot find an example how to simply open a database, write and read to it and close it without using IDE elements. 

Handoko:
Maybe this can help:
https://wiki.freepascal.org/SqlDBHowto

Zvoni:
Place the sqlite3.dll in the Project-Folder

--- 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";}};} ---program project1; Uses sysutils, classes, sqldb, db, sqlite3conn; Var  SQLiteConn:TSQLite3Connection;  Transaction:TSQLTransaction;  SQLQuery:TSQLQuery; Const  SQLCreate:String='CREATE TABLE IF NOT EXISTS `tbl_data` (`ID` INTEGER NOT NULL UNIQUE, `StringData` TEXT, PRIMARY KEY(`ID`))';  SQLInsert:String='INSERT INTO tbl_data (StringData) VALUES (:ParamData);';  SQLSelect:String='SELECT * FROM tbl_data WHERE ID=1;'; begin  SQLiteConn:=TSQLite3Connection.Create(nil);  SQLiteConn.DatabaseName:=GetCurrentDir+'/test.db';  Transaction:=TSQLTransaction.Create(SQLiteConn);  Transaction.DataBase:=SQLiteConn;  SQLQuery:=TSQLQuery.Create(nil);  SQLQuery.DataBase:=SQLiteConn;  SQLQuery.Transaction:=Transaction;  SQLiteConn.Open;   SQLQuery.SQL.Text:=SQLCreate;  SQLQuery.ExecSQL;  Transaction.Commit;   SQLQuery.SQL.Text:=SQLInsert;  SQLQuery.ParamByName('ParamData').AsString := 'My TestString';  SQLQuery.ExecSQL;  Transaction.Commit;   SQLQuery.SQL.Text:=SQLSelect;  SQLQuery.Open;   Writeln('StringData for ID=',SQLQuery.FieldByName('ID').AsString,': ', SQLQuery.FieldByName('StringData').AsString);   SQLQuery.Close;  SQLQuery.Free;  Transaction.Free;  SQLiteConn.Free; end. 

ezlage:

--- Quote from: vdijken on November 09, 2021, 11:08:15 am ---I want to use a simple pascal/lazarus program using an sqlite database without using an IDE, forms etc. One of the tables has so much entries that it does not fit into an array and I need to search into it. But I cannot find an example how to simply open a database, write and read to it and close it without using IDE elements.

--- End quote ---

Try this https://sqlitebrowser.org/ or the SQLite official command line tool, available here https://www.sqlite.org/download.html. Using them you can open and search SQLite database files.

JanRoza:
Or study this demo project which I once wrote for a Dutch computer magazine.
There are some things in it I might do differently today but it shows you a lot of the possibilities in working with SQLite.

Navigation

[0] Message Index

[#] Next page

Go to full version