long SQLite3Backend::addBuddy(long userId, const BuddyInfo &buddyInfo) { // "INSERT INTO " + m_prefix + "buddies (user_id, uin, subscription, groups, nickname, flags) VALUES (?, ?, ?, ?, ?, ?)" std::string groups = StorageBackend::serializeGroups(buddyInfo.groups); BEGIN(m_addBuddy); BIND_INT(m_addBuddy, userId); BIND_STR(m_addBuddy, buddyInfo.legacyName); BIND_STR(m_addBuddy, buddyInfo.subscription); BIND_STR(m_addBuddy, groups); BIND_STR(m_addBuddy, buddyInfo.alias); BIND_INT(m_addBuddy, buddyInfo.flags); if(sqlite3_step(m_addBuddy) != SQLITE_DONE) { LOG4CXX_ERROR(logger, "addBuddy query"<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db))); return -1; } long id = (long) sqlite3_last_insert_rowid(m_db); // INSERT OR REPLACE INTO " + m_prefix + "buddies_settings (user_id, buddy_id, var, type, value) VALUES (?, ?, ?, ?, ?) BEGIN(m_updateBuddySetting); BIND_INT(m_updateBuddySetting, userId); BIND_INT(m_updateBuddySetting, id); BIND_STR(m_updateBuddySetting, buddyInfo.settings.find("icon_hash")->first); BIND_INT(m_updateBuddySetting, TYPE_STRING); BIND_STR(m_updateBuddySetting, buddyInfo.settings.find("icon_hash")->second.s); EXECUTE_STATEMENT(m_updateBuddySetting, "updateBuddySetting query"); return id; }
void SQLite3Backend::updateBuddySetting(long userId, long buddyId, const std::string &variable, int type, const std::string &value) { BEGIN(m_updateBuddySetting); BIND_INT(m_updateBuddySetting, userId); BIND_INT(m_updateBuddySetting, buddyId); BIND_STR(m_updateBuddySetting, variable); BIND_INT(m_updateBuddySetting, type); BIND_STR(m_updateBuddySetting, value); EXECUTE_STATEMENT(m_updateBuddySetting, "m_updateBuddySetting"); }
static int batter_accolades_t_delete_bindings( sqlite3_stmt *statement, const void *data ) { int rc; const batter_accolade_s *batter_accolade = (batter_accolade_s *)data; BIND_INT( statement, 1, batter_accolade->player_id ); BIND_INT( statement, 2, batter_accolade->season ); BIND_INT( statement, 3, batter_accolade->accolade ); return SQLITE_OK; }
static int player_defense_ratings_t_create_bindings( sqlite3_stmt *statement, const void *data ) { int rc; const player_defense_ratings_s *player_defense_ratings = (player_defense_ratings_s *)data; BIND_INT( statement, 1, player_defense_ratings->player_id ); BIND_INT( statement, 2, player_defense_ratings->interceptions ); BIND_INT( statement, 3, player_defense_ratings->quickness ); return SQLITE_OK; }
static int player_accolades_t_create_bindings( sqlite3_stmt *statement, const void *data ) { int rc; const player_accolade_s *player_accolade = (player_accolade_s *)data; BIND_INT( statement, 1, player_accolade->player_id ); BIND_INT( statement, 2, player_accolade->season ); BIND_INT( statement, 3, player_accolade->accolade ); return SQLITE_OK; }
// By Key: static int player_offense_stats_t_read_bindings( sqlite3_stmt *statement, const void *data ) { int rc; const player_offense_stats_s *player_offense_stats = (player_offense_stats_s *)data; BIND_INT( statement, 1, player_offense_stats->player_id ); BIND_INT( statement, 2, player_offense_stats->season ); BIND_INT( statement, 3, player_offense_stats->bowl_game ); return SQLITE_OK; }
// By Key: static int team_game_defense_stats_t_read_bindings( sqlite3_stmt *statement, const void *data ) { int rc; const team_game_defense_stats_s *team_game_defense_stats = (team_game_defense_stats_s *)data; BIND_INT( statement, 1, team_game_defense_stats->team_id ); BIND_INT( statement, 2, team_game_defense_stats->season ); BIND_INT( statement, 3, team_game_defense_stats->week ); BIND_INT( statement, 4, team_game_defense_stats->game ); return SQLITE_OK; }
static int player_game_defense_stats_t_delete_bindings( sqlite3_stmt *statement, const void *data ) { int rc; const player_game_defense_stats_s *player_game_defense_stats = (player_game_defense_stats_s *)data; BIND_INT( statement, 1, player_game_defense_stats->player_id ); BIND_INT( statement, 2, player_game_defense_stats->season ); BIND_INT( statement, 3, player_game_defense_stats->week ); BIND_INT( statement, 4, player_game_defense_stats->game ); return SQLITE_OK; }
void SQLite3Backend::getBuddySetting(long userId, long buddyId, const std::string &variable, int &type, std::string &value) { BEGIN(m_getBuddySetting); BIND_INT(m_getBuddySetting, userId); BIND_INT(m_getBuddySetting, buddyId); BIND_STR(m_getBuddySetting, variable); if(sqlite3_step(m_getBuddySetting) == SQLITE_ROW) { type = GET_INT(m_getBuddySetting); value = GET_STR(m_getBuddySetting); } int ret; while((ret = sqlite3_step(m_getBuddySetting)) == SQLITE_ROW) { } }
void SQLite3Backend::updateUserSetting(long id, const std::string &variable, const std::string &value) { BEGIN(m_updateUserSetting); BIND_STR(m_updateUserSetting, value); BIND_INT(m_updateUserSetting, id); BIND_STR(m_updateUserSetting, variable); EXECUTE_STATEMENT(m_updateUserSetting, "m_updateUserSetting"); }
void SQLite3Backend::getUserSetting(long id, const std::string &variable, int &type, std::string &value) { BEGIN(m_getUserSetting); BIND_INT(m_getUserSetting, id); BIND_STR(m_getUserSetting, variable); if(sqlite3_step(m_getUserSetting) != SQLITE_ROW) { BEGIN(m_setUserSetting); BIND_INT(m_setUserSetting, id); BIND_STR(m_setUserSetting, variable); BIND_INT(m_setUserSetting, type); BIND_STR(m_setUserSetting, value); EXECUTE_STATEMENT(m_setUserSetting, "m_setUserSetting"); } else { type = GET_INT(m_getUserSetting); value = GET_STR(m_getUserSetting); } int ret; while((ret = sqlite3_step(m_getUserSetting)) == SQLITE_ROW) { } }
void SQLite3Backend::updateBuddy(long userId, const BuddyInfo &buddyInfo) { // UPDATE " + m_prefix + "buddies SET groups=?, nickname=?, flags=?, subscription=? WHERE user_id=? AND uin=? std::string groups = StorageBackend::serializeGroups(buddyInfo.groups); BEGIN(m_updateBuddy); BIND_STR(m_updateBuddy, groups); BIND_STR(m_updateBuddy, buddyInfo.alias); BIND_INT(m_updateBuddy, buddyInfo.flags); BIND_STR(m_updateBuddy, buddyInfo.subscription); BIND_INT(m_updateBuddy, userId); BIND_STR(m_updateBuddy, buddyInfo.legacyName); EXECUTE_STATEMENT(m_updateBuddy, "updateBuddy query"); // INSERT OR REPLACE INTO " + m_prefix + "buddies_settings (user_id, buddy_id, var, type, value) VALUES (?, ?, ?, ?, ?) BEGIN(m_updateBuddySetting); BIND_INT(m_updateBuddySetting, userId); BIND_INT(m_updateBuddySetting, buddyInfo.id); BIND_STR(m_updateBuddySetting, buddyInfo.settings.find("icon_hash")->first); BIND_INT(m_updateBuddySetting, TYPE_STRING); BIND_STR(m_updateBuddySetting, buddyInfo.settings.find("icon_hash")->second.s); EXECUTE_STATEMENT(m_updateBuddySetting, "updateBuddySetting query"); }
static int player_game_defense_stats_t_create_bindings( sqlite3_stmt *statement, const void *data ) { int rc; const player_game_defense_stats_s *player_game_defense_stats = (player_game_defense_stats_s *)data; BIND_INT( statement, 1, player_game_defense_stats->player_id ); BIND_INT( statement, 2, player_game_defense_stats->season ); BIND_INT( statement, 3, player_game_defense_stats->week ); BIND_INT( statement, 4, player_game_defense_stats->game ); BIND_INT( statement, 5, player_game_defense_stats->sacks ); BIND_INT( statement, 6, player_game_defense_stats->interceptions ); BIND_INT( statement, 7, player_game_defense_stats->return_yards ); BIND_INT( statement, 8, player_game_defense_stats->return_touchdowns ); return SQLITE_OK; }
static int team_game_defense_stats_t_update_bindings( sqlite3_stmt *statement, const void *data ) { int rc; const team_game_defense_stats_s *team_game_defense_stats = (team_game_defense_stats_s *)data; BIND_INT( statement, 1, team_game_defense_stats->sacks ); BIND_INT( statement, 2, team_game_defense_stats->interceptions ); BIND_INT( statement, 3, team_game_defense_stats->return_yards ); BIND_INT( statement, 4, team_game_defense_stats->return_touchdowns ); BIND_INT( statement, 5, team_game_defense_stats->team_id ); BIND_INT( statement, 6, team_game_defense_stats->season ); BIND_INT( statement, 7, team_game_defense_stats->week ); BIND_INT( statement, 8, team_game_defense_stats->game ); return SQLITE_OK; }
void SQLite3Backend::setUserOnline(long id, bool online) { BEGIN(m_setUserOnline); BIND_INT(m_setUserOnline, (int)online); BIND_INT(m_setUserOnline, id); EXECUTE_STATEMENT(m_setUserOnline, "setUserOnline query"); }
bool SQLite3Backend::getBuddies(long id, std::list<BuddyInfo> &roster) { // SELECT id, uin, subscription, nickname, groups, flags FROM " + m_prefix + "buddies WHERE user_id=? ORDER BY id ASC BEGIN(m_getBuddies); BIND_INT(m_getBuddies, id); // "SELECT buddy_id, type, var, value FROM " + m_prefix + "buddies_settings WHERE user_id=? ORDER BY buddy_id ASC" BEGIN(m_getBuddiesSettings); BIND_INT(m_getBuddiesSettings, id); SettingVariableInfo var; long buddy_id = -1; std::string key; int ret; int ret2 = -10; while((ret = sqlite3_step(m_getBuddies)) == SQLITE_ROW) { BuddyInfo b; RESET_GET_COUNTER(m_getBuddies); b.id = GET_INT(m_getBuddies); b.legacyName = GET_STR(m_getBuddies); b.subscription = GET_STR(m_getBuddies); b.alias = GET_STR(m_getBuddies); std::string groups = GET_STR(m_getBuddies); b.groups = StorageBackend::deserializeGroups(groups); b.flags = GET_INT(m_getBuddies); if (buddy_id == b.id) { std::cout << "Adding buddy info " << key << "\n"; b.settings[key] = var; buddy_id = -1; } while(buddy_id == -1 && ret2 != SQLITE_DONE && ret2 != SQLITE_ERROR && (ret2 = sqlite3_step(m_getBuddiesSettings)) == SQLITE_ROW) { RESET_GET_COUNTER(m_getBuddiesSettings); buddy_id = GET_INT(m_getBuddiesSettings); var.type = GET_INT(m_getBuddiesSettings); key = GET_STR(m_getBuddiesSettings); std::string val = GET_STR(m_getBuddiesSettings); switch (var.type) { case TYPE_BOOLEAN: var.b = atoi(val.c_str()); break; case TYPE_STRING: var.s = val; break; default: if (buddy_id == b.id) { buddy_id = -1; } continue; break; } if (buddy_id == b.id) { std::cout << "Adding buddy info " << key << "=" << val << "\n"; b.settings[key] = var; buddy_id = -1; } } // if (ret != SQLITE_DONE) { // LOG4CXX_ERROR(logger, "getBuddiesSettings query"<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db))); // return false; // } roster.push_back(b); } if (ret != SQLITE_DONE) { LOG4CXX_ERROR(logger, "getBuddies query "<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db))); return false; } if (ret2 != SQLITE_DONE) { if (ret2 == SQLITE_ERROR) { LOG4CXX_ERROR(logger, "getBuddiesSettings query "<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db))); return false; } while((ret2 = sqlite3_step(m_getBuddiesSettings)) == SQLITE_ROW) { } if (ret2 != SQLITE_DONE) { LOG4CXX_ERROR(logger, "getBuddiesSettings query "<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db))); return false; } } return true; }
static int player_game_offense_stats_t_create_bindings( sqlite3_stmt *statement, const void *data ) { int rc; const player_game_offense_stats_s *player_game_offense_stats = (player_game_offense_stats_s *)data; BIND_INT( statement, 1, player_game_offense_stats->player_id ); BIND_INT( statement, 2, player_game_offense_stats->season ); BIND_INT( statement, 3, player_game_offense_stats->week ); BIND_INT( statement, 4, player_game_offense_stats->game ); BIND_INT( statement, 5, player_game_offense_stats->pass_attempts ); BIND_INT( statement, 6, player_game_offense_stats->completions ); BIND_INT( statement, 7, player_game_offense_stats->interceptions ); BIND_INT( statement, 8, player_game_offense_stats->pass_yards ); BIND_INT( statement, 9, player_game_offense_stats->pass_touchdowns ); BIND_INT( statement, 10, player_game_offense_stats->rush_attempts ); BIND_INT( statement, 11, player_game_offense_stats->rush_yards ); BIND_INT( statement, 12, player_game_offense_stats->rush_touchdowns ); BIND_INT( statement, 13, player_game_offense_stats->receptions ); BIND_INT( statement, 14, player_game_offense_stats->receiving_yards ); BIND_INT( statement, 15, player_game_offense_stats->receiving_touchdowns ); return SQLITE_OK; }