I'm currenctly working on SQLite support for libcod. MySQL is nice but might be too heavy and/or hard for some people. SQLite is a lightweight and compact local database engine, and it's also quite easy to use.
The basic support has been added, there are no async support yet, but i'm working on it.
On Arch Linux, SQLite is preinstalled. On ubuntu proably apt-get install sqlite or something like that. It won't be compiled if you don't have the library though.
Unlike MySQL, SQLite is VERY simple, and doesn't need any wrappers, here's a little how to:
Open your database:
Execute your query:PHP Code:level.ranksdb = sqlite_open("databases/ranks.db");
Where the first argument is the database pointer and second is your query.PHP Code:rows = sqlite_query(level.ranksdb, "SELECT id, rank FROM ranks");
The returned result of rows is the sqlite fields and rows of each field.
So for our query, the result will be like: rows[0][0] where the first number is the FIELD number and second is ROW number.
If you do:
The result will be:PHP Code:for (i = 0; i < rows.size; i++)
printf("% - %\n", rows[i][0], rows[i][1]);
Close your database:Code:1 - Idiot 2 - Noob 3 - Sergant Slaughter 4 - Lowak 5 - Loler 6 - Private 7 - OVER 9000 8 - JERKASS 9 - Crap 10 - Faggot 11 - Maggot 12 - Nanny's boyfriend 13 - Leader of gay-parade 14 - Captain Obvious 15 - Ass 16 - Cock of Duty 2
You can close your database on endmap for example, but that's not neccecary, a new sqlite_open will just return the previous database pointer on new map/restart.PHP Code:sqlite_close(level.ranksdb);
Also made some nice error messages if you f*ck up your query for example:
Code:******* script runtime error ******* gsc_sqlite_query() failed to fetch query data: near "FRM": syntax error: (file 'novoselscripts/zom.gsc', line 126) rows = sqlite_query(db, "SELECT * FRM ranks"); * called from: (file 'maps/mp/gametypes/_callbacksetup.gsc', line 15) [[level.callbackStartGameType]](); * started from: (file 'maps/mp/gametypes/_callbacksetup.gsc', line 10) CodeCallback_StartGameType() * ************************************ Sys_Error: Error during initialization: script runtime error (see console for details) gsc_sqlite_query() failed to fetch query data: near "FRM": syntax error

 
			
			 
					
					
					
						 Reply With Quote
Reply With Quote