/** * Retrieve data from db and store it in the provided data structure. * Doesn't actually retrieve data yet: escapes and checks userid, then transforms it to accid for fetching. * Filled data structure is done by delegation to account_db_sql_load_num. * @param self: pointer to db * @param acc: pointer of mmo_account to fill * @param userid: name of user account * @return true if successful, false if something has failed */ static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, const char* userid) { AccountDB_SQL* db = (AccountDB_SQL*)self; Sql* sql_handle = db->accounts; char esc_userid[2*NAME_LENGTH+1]; uint32 account_id; char* data; Sql_EscapeString(sql_handle, esc_userid, userid); // get the list of account IDs for this user ID if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `userid`= %s '%s'", db->account_db, (db->case_sensitive ? "BINARY" : ""), esc_userid) ) { Sql_ShowDebug(sql_handle); return false; } if( Sql_NumRows(sql_handle) > 1 ) {// serious problem - duplicit account ShowError("account_db_sql_load_str: multiple accounts found when retrieving data for account '%s'!\n", userid); Sql_FreeResult(sql_handle); return false; } if( SQL_SUCCESS != Sql_NextRow(sql_handle) ) {// no such entry Sql_FreeResult(sql_handle); return false; } Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); return account_db_sql_load_num(self, acc, account_id); }
/// retrieve data from db and store it in the provided data structure static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, const char* userid) { AccountDB_SQL* db = (AccountDB_SQL*)self; Sql* sql_handle; char esc_userid[2*NAME_LENGTH+1]; int account_id; char* data; nullpo_ret(db); nullpo_ret(acc); sql_handle = db->accounts; SQL->EscapeString(sql_handle, esc_userid, userid); // get the list of account IDs for this user ID if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `userid`= %s '%s'", db->account_db, (db->case_sensitive ? "BINARY" : ""), esc_userid) ) { Sql_ShowDebug(sql_handle); return false; } if( SQL->NumRows(sql_handle) > 1 ) {// serious problem - duplicate account ShowError("account_db_sql_load_str: Varias contas relacionadas ao usuario '%s'!\n", userid); SQL->FreeResult(sql_handle); return false; } if( SQL_SUCCESS != SQL->NextRow(sql_handle) ) {// no such entry SQL->FreeResult(sql_handle); return false; } SQL->GetData(sql_handle, 0, &data, NULL); account_id = atoi(data); return account_db_sql_load_num(self, acc, account_id); }