BUGFIX: Found an error in SQL save statements

The character's positions are now persistent between logins.
This commit is contained in:
Kayne Ruse
2014-05-13 04:33:38 +10:00
parent c5e8f1b3af
commit 14b330009b
2 changed files with 7 additions and 9 deletions
+3 -4
View File
@@ -31,7 +31,7 @@
static const char* CREATE_USER_ACCOUNT = "INSERT INTO UserAccounts (username) VALUES (?);"; static const char* CREATE_USER_ACCOUNT = "INSERT INTO UserAccounts (username) VALUES (?);";
static const char* LOAD_USER_ACCOUNT = "SELECT * FROM UserAccounts WHERE username = ?;"; static const char* LOAD_USER_ACCOUNT = "SELECT * FROM UserAccounts WHERE username = ?;";
static const char* SAVE_USER_ACCOUNT = "INSERT OR REPLACE INTO UserAccounts VALUES (?, ?, ?, ?);"; static const char* SAVE_USER_ACCOUNT = "UPDATE OR FAIL UserAccounts SET blacklisted = ?2, whitelisted = ?3 WHERE uid = ?1;";
static const char* DELETE_USER_ACCOUNT = "DELETE FROM UserAccounts WHERE uid = ?;"; static const char* DELETE_USER_ACCOUNT = "DELETE FROM UserAccounts WHERE uid = ?;";
//------------------------- //-------------------------
@@ -135,9 +135,8 @@ int ServerApplication::SaveUserAccount(int uid) {
//parameters //parameters
bool ret = false; bool ret = false;
ret |= sqlite3_bind_int(statement, 1, uid) != SQLITE_OK; ret |= sqlite3_bind_int(statement, 1, uid) != SQLITE_OK;
ret |= sqlite3_bind_text(statement, 2, account.username.c_str(), account.username.size() + 1, SQLITE_STATIC) != SQLITE_OK; ret |= sqlite3_bind_int(statement, 2, account.blackListed) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 3, account.blackListed) != SQLITE_OK; ret |= sqlite3_bind_int(statement, 3, account.whiteListed) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 4, account.whiteListed) != SQLITE_OK;
//check for binding errors //check for binding errors
if (ret) { if (ret) {
+4 -5
View File
@@ -31,7 +31,7 @@
static const char* CREATE_CHARACTER = "INSERT INTO PlayerCharacters (owner, handle, avatar) VALUES (?, ?, ?);"; static const char* CREATE_CHARACTER = "INSERT INTO PlayerCharacters (owner, handle, avatar) VALUES (?, ?, ?);";
static const char* LOAD_CHARACTER = "SELECT * FROM PlayerCharacters WHERE handle = ?;"; static const char* LOAD_CHARACTER = "SELECT * FROM PlayerCharacters WHERE handle = ?;";
static const char* SAVE_CHARACTER = "INSERT OR REPLACE INTO PlayerCharacters (uid, owner, mapIndex, positionX, positionY) VALUES (?, ?, ?, ?, ?);"; static const char* SAVE_CHARACTER = "UPDATE OR FAIL PlayerCharacters SET mapIndex = ?2, positionX = ?3, positionY = ?4 WHERE uid = ?1;";
static const char* DELETE_CHARACTER = "DELETE FROM PlayerCharacters WHERE uid = ?;"; static const char* DELETE_CHARACTER = "DELETE FROM PlayerCharacters WHERE uid = ?;";
//------------------------- //-------------------------
@@ -172,10 +172,9 @@ int ServerApplication::SaveCharacter(int uid) {
//parameters //parameters
bool ret = false; bool ret = false;
ret |= sqlite3_bind_int(statement, 1, uid) != SQLITE_OK; ret |= sqlite3_bind_int(statement, 1, uid) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 2, character.owner) != SQLITE_OK; ret |= sqlite3_bind_int(statement, 2, character.mapIndex) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 3, character.mapIndex) != SQLITE_OK; ret |= sqlite3_bind_int(statement, 3, (int)character.position.x) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 4, (int)character.position.x) != SQLITE_OK; ret |= sqlite3_bind_int(statement, 4, (int)character.position.y) != SQLITE_OK;
ret |= sqlite3_bind_int(statement, 5, (int)character.position.y) != SQLITE_OK;
//TODO: stats, etc. //TODO: stats, etc.
//check for binding errors //check for binding errors