SQLite3Backend::addBuddy
This commit is contained in:
parent
16d484457f
commit
ebebf04f69
3 changed files with 36 additions and 1 deletions
|
@ -79,7 +79,8 @@ class SQLite3Backend : public StorageBackend
|
|||
/// \return true if user has been found in database and roster has been fetched
|
||||
bool getBuddies(long id, std::list<std::string> &roster);
|
||||
|
||||
long addBuddy(long userId, const BuddyInfo &buddyInfo) { return 0; }
|
||||
long addBuddy(long userId, const BuddyInfo &buddyInfo);
|
||||
|
||||
void updateBuddy(long userId, const BuddyInfo &buddyInfo) {}
|
||||
void removeBuddy(long id) {}
|
||||
|
||||
|
@ -100,6 +101,7 @@ class SQLite3Backend : public StorageBackend
|
|||
sqlite3_stmt *m_removeUserBuddies;
|
||||
sqlite3_stmt *m_removeUserSettings;
|
||||
sqlite3_stmt *m_removeUserBuddiesSettings;
|
||||
sqlite3_stmt *m_addBuddy;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -88,6 +88,9 @@ void RosterManager::setBuddyCallback(Buddy *buddy) {
|
|||
m_RIETimer->start();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_rosterStorage)
|
||||
m_rosterStorage->storeBuddy(buddy);
|
||||
}
|
||||
|
||||
void RosterManager::unsetBuddy(Buddy *buddy) {
|
||||
|
|
|
@ -40,6 +40,15 @@
|
|||
if(prep != NULL) { \
|
||||
sqlite3_finalize(prep); \
|
||||
}
|
||||
|
||||
#define BEGIN(STATEMENT) sqlite3_reset(m_addBuddy);\
|
||||
int STATEMENT##_id = 1;
|
||||
|
||||
#define BIND_INT(STATEMENT, VARIABLE) sqlite3_bind_int(STATEMENT, STATEMENT##_id++, VARIABLE);
|
||||
#define BIND_STR(STATEMENT, VARIABLE) sqlite3_bind_text(STATEMENT, STATEMENT##_id++, VARIABLE.c_str(), -1, SQLITE_STATIC);
|
||||
#define EXECUTE_STATEMENT(STATEMENT, NAME) if(sqlite3_step(STATEMENT) != SQLITE_DONE) {\
|
||||
onStorageError(NAME, (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));\
|
||||
}
|
||||
|
||||
using namespace boost;
|
||||
|
||||
|
@ -84,6 +93,8 @@ bool SQLite3Backend::connect() {
|
|||
PREP_STMT(m_removeUserSettings, "DELETE FROM " + m_prefix + "users_settings WHERE user_id=?");
|
||||
PREP_STMT(m_removeUserBuddiesSettings, "DELETE FROM " + m_prefix + "buddies_settings WHERE user_id=?");
|
||||
|
||||
PREP_STMT(m_addBuddy, "INSERT INTO " + m_prefix + "buddies (user_id, uin, subscription, groups, nickname, flags) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -197,6 +208,25 @@ void SQLite3Backend::setUserOnline(long id, bool online) {
|
|||
|
||||
}
|
||||
|
||||
long SQLite3Backend::addBuddy(long userId, const BuddyInfo &buddyInfo) {
|
||||
// "INSERT INTO " + m_prefix + "buddies (user_id, uin, subscription, groups, nickname, flags) VALUES (?, ?, ?, ?, ?, ?)"
|
||||
BEGIN(m_addBuddy);
|
||||
BIND_INT(m_addBuddy, userId);
|
||||
BIND_STR(m_addBuddy, buddyInfo.legacyName);
|
||||
BIND_STR(m_addBuddy, buddyInfo.subscription);
|
||||
BIND_STR(m_addBuddy, buddyInfo.groups[0]); // TODO: serialize groups
|
||||
BIND_STR(m_addBuddy, buddyInfo.alias);
|
||||
BIND_INT(m_addBuddy, buddyInfo.flags);
|
||||
|
||||
EXECUTE_STATEMENT(m_addBuddy, "addBuddy query");
|
||||
|
||||
if(sqlite3_step(m_addBuddy) != SQLITE_DONE) {
|
||||
onStorageError("addBuddy query", (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
|
||||
return -1;
|
||||
}
|
||||
return (long) sqlite3_last_insert_rowid(m_db);
|
||||
}
|
||||
|
||||
bool SQLite3Backend::getBuddies(long id, std::list<std::string> &roster) {
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue