B4J Question How to handle multiple SQLite databases?

jtare

Active Member
Licensed User
Longtime User
I always create a class module where I initialize the sql object and query the database (like most tutorials show), but this time I have many .db files that I want to read (45 and increasing). One solution would be to create 45+ sql objects (or inside a list) and a huge "if" condition to select the right object to do the queries, I'm not an expert but does not seem to be the best solution.

What are the memory consequences of having this amount sqlite databases opened?
The class is initialized in the "AppStart" of a non-ui application.

Beside the fact that the amount of databases is huge and could decrease by using more tables inside of a few .db files, what are other possible solutions?

Is it efficient to initialize and open a .db file each time I want to query it?

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
One solution would be to create 45+ sql objects (or inside a list) and a huge "if" condition to select the right object to do the queries, I'm not an expert but does not seem to be the best solution.
How do you know which database to use? I guess that you should use a Map for this with SQL objects as values.

What are the memory consequences of having this amount sqlite databases opened?
I don't think that you will encounter any special issues. Test it.

Is it efficient to initialize and open a .db file each time I want to query it?
How frequent are the calls? Every millisecond, second or minute+?
 
Upvote 0

jtare

Active Member
Licensed User
Longtime User
How do you know which database to use? I guess that you should use a Map for this with SQL objects as values
By the name of the file. Will try using a map.
How frequent are the calls? Every millisecond, second or minute+?
At least at 10 seconds, which is the calling rate of a bot, the rest will be users, which are very low right now.

Thanks!
 
Upvote 0

jtare

Active Member
Licensed User
Longtime User
I left the connections opened with all the sql objects in a map object, seems to be working fine. Thanks for the suggestion.
 
Upvote 0
Top