by date
Async (non-blocking) Postgres Database Handler
Async (non-blocking) Postgres Database Handler
| Name: | Danni | |
|---|---|---|
| Date Posted: | Jun 01, 2008 | |
| Rating: | 5.0 out of 5 | |
| Public: | YES | |
| Comments: | YES | |
| RSS Feed: | or Subscribe with . | |
| Profile Page: | View profile page for Danni |
Blog post
This post is out of date, check the completed resource here.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1497...
After looking at how wonderfully C looking the async API would be I figured a better solution would be threading with a pool handler. So here it is! Basically the way this works is one can create a pool of threads each with their own connection into the PGSQL database. You execute a query to the pool and one of the threads picks it up then processes it returning to a callback (C++ or TS). In the callback you have full access to the result for the run of the callback.
Here is how i set mine up.
The Database connection arguments are now in the prefs.cs files;
In TS you can query anywhere with the following;
C++ is almost identical.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1497...
After looking at how wonderfully C looking the async API would be I figured a better solution would be threading with a pool handler. So here it is! Basically the way this works is one can create a pool of threads each with their own connection into the PGSQL database. You execute a query to the pool and one of the threads picks it up then processes it returning to a callback (C++ or TS). In the callback you have full access to the result for the run of the callback.
Here is how i set mine up.
function createServer(%serverType, %mission)
{
.....
PGSQLPool::createPool();
.....
}
The Database connection arguments are now in the prefs.cs files;
$pref::Server::Database::Database = "TGEA";
$pref::Server::Database::Host = "localhost";
$pref::Server::Database::Password = "test";
$pref::Server::Database::Port = "5432";
$pref::Server::Database::Threads = "2";
$pref::Server::Database::Username = "tgeauser";
In TS you can query anywhere with the following;
function getResult(%r)
{
%db = PGSQLPool::getPool();
%val = %db.getValue(%r, 0, 1);
echo("DATABASE GOT " @ %val);
}
function otherFunction()
{
%db = PGSQLPool::getPool();
%db.Exec("getResult", "SELECT * FROM tgea_test WHERE first = %s;", "something");
}
C++ is almost identical.
void getResult(PGQuery* r,const void *user)
{
const char* val = r->getValue(0,1);
}
void function()
{
PGSQLPool* db = PGSQLPool::getPool();
int userval = 1;
db->Exec(&getResult, &userval, "SELECT * FROM tgea_test WHERE first = %s;", "something");
}
Recent Blog Posts
| List: | 07/17/08 - AFX Selected Objects, AutoAttack AI and Jerkiness. 06/01/08 - Async (non-blocking) Postgres Database Handler 05/18/08 - Postgres as a database solution? 05/04/08 - Step sounds, recoil and hit scans. 01/27/08 - Torque prediction hack for hitscans |
|---|
Submit your own resources!| Tony Richards (Jun 02, 2008 at 00:04 GMT) |
| Brian Jones (Jun 02, 2008 at 00:42 GMT) Resource Rating: 5 |
| Ronald V Rieger (Jun 09, 2008 at 20:15 GMT) Resource Rating: 5 |
Thank you.
| Danni (Jun 09, 2008 at 23:26 GMT) Resource Rating: 5 |
You must be a member and be logged in to either append comments or rate this resource.


5.0 out of 5


