Forum > Database

SQLite open and close database connection

(1/1)

pmralbuquerque:
Hello,

Please forgive the dumbness of the question, but I never worked with databases before.
I am trying to understand the process of using SQLite in a GUI application.

So far, I managed to establish the connection, create a logon form, and create a new database reading SQL code from a file. Next comes the new data, refresh, update, delete, etc.

But there is something I'm not sure of. Reading https://forum.lazarus.freepascal.org/index.php?topic=57083.0, I can see an ending group:

--- 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";}};} ---SQLQuery.Close;  SQLQuery.Free;  Transaction.Free;  SQLiteConn.Free;
So, my question is, when should I terminate/close the connection, and where in the application?

* Open at startup and close at exit?
* Open and close wherever it is used locally?
* Is that group everything needed?
Thank you in advance for your answers.

Zvoni:
3) If you use the "native" Classes/Controls/Objects of FPC/Lazarus, you need the "Trinity": Connection, Transaction, Query, interconnected as documented. That's all you need. There is some "other" stuff (DataMadoule etc. resp. ZEOS instead) you could use additionally, though
1+2) Open/Closing: It depends.
If it's a single-user accessing hat DB (only one user will use your program), then open at startup, close on exit. If it's multi-user, then it also depends, how many users want to write to the DB at the same time. If you have more than one, open before needing, close after done. If multi-user, id'd use journal_mode=WAL (add as a connection-param).

EDIT: If it's a "real" Multi-user-environment, then SQLite is IMO the wrong DBMS (despite loving SQLite myself, i do know its limits). Then I'd rather go for a server-based DBMS (MySQL et al)

pmralbuquerque:
Hello @Zvoni, and thank you for your answer.

This is a single user environment, a learning project, something I'm trying to adapt from an old ZX Spectrum BASIC code.

So, opening at startup and close at shutdown it is.

Thanks a lot. :D

Navigation

[0] Message Index

Go to full version