sqlite static database connection over multiple instances

  • Thread starter Thread starter Digital Fart
  • Start date Start date
D

Digital Fart

hi

I want to wrap the access to a sqlite database in an object. So i can
create multiple instances of this wrapper with base code to get data
out of the sqlite database.

But i want to make the connection only onces when i create the first
instance. And when the program ends the connection should be removed.

ex.

wrapper objects

query wrapperQuery1 = new query(); // here the database should connect
query wrapperQuery2 = new query(); // connection should already exists
query wrapperQuery3 = new query(); // connection should already exists

wrapperQuery1.close(); // dbconnect stays open
wrapperQuery3.close(); // dbconnect stays open
wrapperQuery2.close(); // dbconnect should close now when.

How would i contruct this?
 
Digital Fart,

That's a REALLY bad way of handling this. Basically, when you perform
your query, you should open the connection, perform the operation, and close
it.

Database connections are the kind of resources that degrade over time,
and also are limited in use (if you have one being sucked up, that's one
less connection that can be made to the database).

My advise is to open the connection and close it when you are done with
the query.

Hope this helps.
 
Back
Top