SQLite: when to open the database

I’m using SQLite as the data store for my app and I’m wondering what the best practice is for when/where to open/close the database.

For example, can I do something like the following in main.lua:

globalDB = sqlite3.open(myDB)  

And then access globalDB from anywhere in main and any other Lua files (which will be brought into play using Director). And I’d close the DB on application exit. Or is it better to open and close the DB as and when required?

I’ve done a lot of DB work in the past (web development, client apps, etc) and usually it’s a case of opening and closing on demand. However, just wondered what the best practice was in the Corona world.

Thoughts anyone? [import]uid: 26769 topic_id: 7470 reply_id: 307470[/import]