rename cookie->room in db; reposition columns.

This commit is contained in:
Andy2 2010-09-16 03:30:24 -07:00
parent b25579b893
commit d1a9c3962a
2 changed files with 8 additions and 7 deletions

View file

@ -82,7 +82,7 @@ DBMgr::AddNew( const char* cookie, const char* connName, CookieID cid,
if ( !connName ) connName = "";
const char* fmt = "INSERT INTO " TABLE_NAME
"(cid, cookie, connName, nTotal, nJoined, lang, ispublic, ctime) "
"(cid, room, connName, nTotal, nJoined, lang, ispublic, ctime) "
"VALUES( %d, '%s', '%s', %d, %d, %d, %s, 'now' )";
char buf[256];
snprintf( buf, sizeof(buf), fmt, cid/*m_nextCID++*/, cookie, connName,
@ -118,7 +118,8 @@ DBMgr::FindGame( const char* connName, char* cookieBuf, int bufLen,
{
CookieID cid = 0;
const char* fmt = "SELECT cid, cookie, lang, nTotal from " TABLE_NAME " where connName = '%s' "
const char* fmt = "SELECT cid, room, lang, nTotal from " TABLE_NAME
" where connName = '%s' "
"LIMIT 1";
char query[256];
snprintf( query, sizeof(query), fmt, connName );
@ -144,7 +145,7 @@ DBMgr::FindOpen( const char* cookie, int lang, int nPlayersT, int nPlayersH,
CookieID cid = 0;
const char* fmt = "SELECT cid, connName FROM " TABLE_NAME " "
"WHERE cookie = '%s' "
"WHERE room = '%s' "
"AND lang = %d "
"AND nTotal = %d "
"AND %d <= nTotal-nJoined "
@ -212,7 +213,7 @@ DBMgr::execSql( const char* query )
Schema:
CREATE TABLE games (
cid integer,
cookie VARCHAR(32),
room VARCHAR(32),
connName VARCHAR(64) UNIQUE PRIMARY KEY,
nTotal INTEGER,
nJoined INTEGER,

View file

@ -21,12 +21,12 @@ make_db() {
cat | psql xwgames --file - <<EOF
CREATE TABLE games (
cid integer,
cookie VARCHAR(32),
room VARCHAR(32),
lang INTEGER,
isPublic BOOLEAN,
connName VARCHAR(64) UNIQUE PRIMARY KEY,
nTotal INTEGER,
nJoined INTEGER,
lang INTEGER,
isPublic BOOLEAN,
ctime TIMESTAMP,
mtime TIMESTAMP
);