Even though Lazarus is not just for database development, I guess the problem of
tan is that SQLite3 connectivity is not enabled by default in Lazarus. Python's standard libraries comes with lots of extras.
Here is another trivial example using the Chinook database which compares Python & Lazarus manipulation of an SQLite database.
A)Here is Python code for retrieving all the system tables from the Chinook database
import sqlite3
con = sqlite3.connect('chinook.db')
cursor = con.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';")
print(cursor.fetchall())
B)Here is the same code in Lazarus but which puts the tablenames in a combobox
// Set the type of database we are trying to connect to
SQLConnector1.ConnectorType := 'SQLite3';
// Set the name and path of the database
// If the database is in the same directory as the program, the
// path can be omitted; just the name of the database will suffice
SQLConnector1.DatabaseName := 'chinook.db';
// Now connect to the database
SQLConnector1.Connected := True;
// Set the transaction to active
SQLTransaction1.Active := True;
// Run the query that gets the names of the non-system tables in the database
SQLQuery1.SQL.Text := 'SELECT tbl_name FROM sqlite_master WHERE type = ''table'' AND tbl_name NOT LIKE ''sqlite_%''';
SQLQuery1.Open;
//
while not SQLQuery1.EOF do
begin
ComboBox1.Items.Add(SQLQuery1.FieldByName('tbl_name').AsString);
SQLQuery1.Next;
end;
As you can see, it is not that difficult to do.
NOTE:One just needs to add SQLConnector, SQLTransaction and SQLQuery to the project, connect the 3 components and then put the sqlite3 dll in the same directory as the project. The Chinook database is here
http://www.sqlitetutorial.net/wp-content/uploads/2018/03/chinook.zip. The sqlite3 32-bit dll is here
https://www.sqlite.org/2018/sqlite-dll-win32-x86-3240000.zipThe complete example (without the database and the sqlite 32 bit dll) is in the attachment. After connection, the database tables names are loaded into the combobox; selecting a table and then clicking on the search button will display the contents of the table in the DBGrid.
I hope this helps the newcomers.
Cheers,
JD