Coding practice for director / sql lite?

Hello there,

I’ve started integrating directory (what a beautiful class!) in my project, deciding to scrap what was becoming a very complicated project in order to insert some order in the mess.

My little game doesn’t rely much on graphic, but it’s heavy on database writing/reading and interface-clicks (like a football manager, just way way simpler).

Now, what is the best practice for opening/interrogating/updating/closing the db?

  1. do I have to add the require sqllite3 at the top of every single module that uses the dbase?
    Or can I simply include the lua code for opening the dbase in an external module in a function?

So for example my main.lua would call menu.lua, and menu.lua would require dbase.lua, which already cointains the “require sqllite3” and the code to open the dbase: in this case I can call a function opendb().

If menu.lua decides to call say page1.lua, then again with one line I can open the db.

  1. regarding the following function:

[applescript]
function onSystemEvent( event )
if( event.type == “applicationExit” ) then
– Close DB Connection
conn:close()
end

if( event.type == “applicationSuspend” ) then
– Close DB Connection
conn:close()
end

end
Runtime:addEventListener( “system”, onSystemEvent )
[/applescript]

should it appear at the bottom of EVERY module that uses the dbase? Or once again, can I simply include it in dbase.lua and then call it in one line? (I’m trying to move as many identical functions as possible from the game module to an external library, to make everything more readable)

I’m trying to understand the possible performance issues here, but I’m still a bit confused.

I also have a multitude of functions to perform different interrogation and calculations in the dbase. For example I have to run a query in different pages that returns me certain values. Am I forced to do everything local or can I send my values to a function in dbase.lua (the external module) , run the query on the database, and return it to my page?

Thanks! [import]uid: 47871 topic_id: 9024 reply_id: 309024[/import]