Posts: 4,510
Threads: 163
Joined: Mar 2008
Reputation:
0
Which way is it better? Open a database on OnGameModeInit, write/read data and close it on OnGameModeExit
or just simply open, write/read, close each time I want to write/read?
I need a good explanation, as I don't want memory leaks or anything, I just want the best option.
Posts: 622
Threads: 5
Joined: Feb 2009
Reputation:
0
You mean, persistent connection to database ?
Of course creating a persistent connection to database in OnGameModeInit would be better because connecting to sql server each time you perform a query would add additional delay/overhead.
There will be no memory leak as long as you use a stable plugin without any leak-related-issues and if you free the result each time after storing a result that is no longer needed.
Posts: 622
Threads: 5
Joined: Feb 2009
Reputation:
0
Oh, you're talking about built-in SQLite. I've thought that you're using mySQL with 3rd party plugin.
Db_free_result (from sqllite) must have as a parameter the result to free.
Can you post a snip of code that causes the server to crash?
Posts: 622
Threads: 5
Joined: Feb 2009
Reputation:
0
Always keep in mind freeing the result as soon as you don't need it anymore. And always free it before performing aditional query.
I haven't "played" with SQLite but I'am also a mysql/php programmer and in mysql if you use another query before freeing the result you get "Commands out of sync" error. So I guess you don't get any error here in SQLite but instead it just ends up in a crash.