#include "SymbolsToDatabase.h" #include void SymbolsToDatabase::sendSymbols(int userId, int listId, const StringList &symbols, const std::string name) { bool first = true; _database.tryQueryUntilSuccess("BEGIN"); std::stringstream ss; ss << "DELETE FROM symbols_in_lists where user_id = " << userId << " AND list_id = " << listId; _database.tryQueryUntilSuccess(ss.str()); ss.str(""); ss << "REPLACE INTO symbol_lists (name, user_id, id) VALUES ( \"" << mysqlEscapeString(name) << "\","<< userId << ',' << listId << ')'; _database.tryQueryUntilSuccess(ss.str()); if (!symbols.empty()) { ss.str(""); ss << "REPLACE INTO symbols_in_lists (user_id, list_id, symbol) VALUES "; for(StringList::const_iterator it = symbols.begin(); it != symbols.end(); it++) { /* std::cout << *it; ... */ if (!first) ss << ','; else first = false; ss << '(' << userId << "," << listId << ",\"" << mysqlEscapeString(*it) << "\")"; } _database.tryQueryUntilSuccess(ss.str()); } _database.tryQueryUntilSuccess("COMMIT"); }