SQLite efficiency questions.
#1


Two simple questions..

Firstly Question.

Which would be more efficient?

Opening all databases under OnGameModeInit, to be written into and updated when needed while the server is online.

or

Opening each database when required, for example the user database being opened and closed when a player connects and logs in.

I'm just wondering because, it seems quite silly to be opening and closing the databases constantly, rather than keeping it open and updating it throughout the servers online time...

Obviously there would be db_close under OnGameModeExit

But... What if the server crashes and the database wasn't closed beforehand?


Second question.

Is it possible to write the same information into two sepperate tables without re-writing the same query, but only changing the name of the table to be written to?

So if i have two tables inside one database file. I'd like to have one which would log an event, and another used to log the same event exactly the same way.


Reply
#2

Ok nevermind the first question I've decided to open all databases when the gamemode starts.

Personally I think that would be far more efficient.

Is anyone able to answer my second question?
Reply
#3

Well, I use MySQL and I Have something like:

Код:
format(query,sizeof(query),"UPDATE useri, players SET useri.parola='%s', players.Password='%s' WHERE useri.nick='%s' AND players.Name = '%s'",encrypt_newp,encrypt_newp,myusername,myusername);
for update..

I don't know how can you build inserts but I guess that you can create a MYSQL procedure to do 2 separate queries from the same parameters, and enter the same data into two or more tables at once. And when you need to store data, you just call that procedure with data as parameters ..or a trigger if some action has been made to first table, then an defined action will be taken.

More details about mysql procedures and triggers http://dev.mysql.com/doc/refman/5.1/...-routines.html

But my advice is.. keep it simple! Use 2 queries for insert and one for update if you wish so.

Good luck!
PS: don't forget to escape your query if user has access to the data that you will build the query from.
Reply
#4

Perhaps use a trigger.

[code=sql]
CREATE TRIGGER IF NOT EXISTS trg_logstuff AFTER INSERT ON `table1`
BEGIN
INSERT INTO `table2` ( `col1` , `col2` ) VALUES ( new.`col1` , new.`col2` );
END
[/code]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)