Implement removeBuddy/removeBuddySettings/getBuddySetting for mysql
This commit is contained in:
parent
b3f59f9bb6
commit
fcdddf9da4
3 changed files with 44 additions and 5 deletions
|
@ -87,10 +87,10 @@ class MySQLBackend : public StorageBackend
|
|||
long addBuddy(long userId, const BuddyInfo &buddyInfo);
|
||||
|
||||
void updateBuddy(long userId, const BuddyInfo &buddyInfo);
|
||||
void removeBuddy(long id) {}
|
||||
void removeBuddy(long id);
|
||||
|
||||
void getBuddySetting(long userId, long buddyId, const std::string &variable, int &type, std::string &value) {}
|
||||
void updateBuddySetting(long userId, long buddyId, const std::string &variable, int type, const std::string &value) {}
|
||||
void getBuddySetting(long userId, long buddyId, const std::string &variable, int &type, std::string &value);
|
||||
void updateBuddySetting(long userId, long buddyId, const std::string &variable, int type, const std::string &value);
|
||||
|
||||
void getUserSetting(long userId, const std::string &variable, int &type, std::string &value);
|
||||
void updateUserSetting(long userId, const std::string &variable, const std::string &value);
|
||||
|
@ -148,8 +148,11 @@ class MySQLBackend : public StorageBackend
|
|||
Statement *m_removeUserSettings;
|
||||
Statement *m_removeUserBuddiesSettings;
|
||||
Statement *m_addBuddy;
|
||||
Statement *m_removeBuddy;
|
||||
Statement *m_removeBuddySettings;
|
||||
Statement *m_updateBuddy;
|
||||
Statement *m_updateBuddySetting;
|
||||
Statement *m_getBuddySetting;
|
||||
Statement *m_getBuddies;
|
||||
Statement *m_getBuddiesSettings;
|
||||
Statement *m_setUserOnline;
|
||||
|
|
|
@ -13,8 +13,8 @@ admin_password=test
|
|||
#cert=server.pfx #patch to PKCS#12 certificate
|
||||
#cert_password=test #password to that certificate if any
|
||||
users_per_backend=10
|
||||
#backend=../..//backends/libpurple/spectrum2_libpurple_backend
|
||||
backend=../../backends/twitter/spectrum_twitter_backend
|
||||
backend=../..//backends/swiften/spectrum2_swiften_backend
|
||||
#backend=../../backends/twitter/spectrum_twitter_backend
|
||||
protocol=prpl-jabber
|
||||
#protocol=prpl-msn
|
||||
#protocol=any
|
||||
|
|
|
@ -289,6 +289,8 @@ void MySQLBackend::disconnect() {
|
|||
delete m_removeUserSettings;
|
||||
delete m_removeUserBuddiesSettings;
|
||||
delete m_addBuddy;
|
||||
delete m_removeBuddy;
|
||||
delete m_removeBuddySettings;
|
||||
delete m_updateBuddy;
|
||||
delete m_getBuddies;
|
||||
delete m_getBuddiesSettings;
|
||||
|
@ -296,6 +298,7 @@ void MySQLBackend::disconnect() {
|
|||
delete m_setUserSetting;
|
||||
delete m_updateUserSetting;
|
||||
delete m_updateBuddySetting;
|
||||
delete m_getBuddySetting;
|
||||
delete m_setUserOnline;
|
||||
delete m_getOnlineUsers;
|
||||
mysql_close(&m_conn);
|
||||
|
@ -331,10 +334,13 @@ bool MySQLBackend::connect() {
|
|||
m_removeUserBuddiesSettings = new Statement(&m_conn, "i", "DELETE FROM " + m_prefix + "buddies_settings WHERE user_id=?");
|
||||
|
||||
m_addBuddy = new Statement(&m_conn, "issssi", "INSERT INTO " + m_prefix + "buddies (user_id, uin, subscription, groups, nickname, flags) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
m_removeBuddy = new Statement(&m_conn, "i", "DELETE FROM " + m_prefix + "buddies WHERE id=?");
|
||||
m_removeBuddySettings = new Statement(&m_conn, "i", "DELETE FROM " + m_prefix + "buddies_settings WHERE buddy_id=?");
|
||||
m_updateBuddy = new Statement(&m_conn, "ssisis", "UPDATE " + m_prefix + "buddies SET groups=?, nickname=?, flags=?, subscription=? WHERE user_id=? AND uin=?");
|
||||
m_getBuddies = new Statement(&m_conn, "i|issssi", "SELECT id, uin, subscription, nickname, groups, flags FROM " + m_prefix + "buddies WHERE user_id=? ORDER BY id ASC");
|
||||
m_getBuddiesSettings = new Statement(&m_conn, "i|iiss", "SELECT buddy_id, type, var, value FROM " + m_prefix + "buddies_settings WHERE user_id=? ORDER BY buddy_id ASC");
|
||||
m_updateBuddySetting = new Statement(&m_conn, "iisiss", "INSERT INTO " + m_prefix + "buddies_settings (user_id, buddy_id, var, type, value) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE value=?");
|
||||
m_getBuddySetting = new Statement(&m_conn, "is|is", "SELECT type, value FROM " + m_prefix + "buddies_settings WHERE user_id=? AND buddy_id=? AND var=?");
|
||||
|
||||
m_getUserSetting = new Statement(&m_conn, "is|is", "SELECT type, value FROM " + m_prefix + "users_settings WHERE user_id=? AND var=?");
|
||||
m_setUserSetting = new Statement(&m_conn, "isis", "INSERT INTO " + m_prefix + "users_settings (user_id, var, type, value) VALUES (?,?,?,?)");
|
||||
|
@ -479,6 +485,36 @@ long MySQLBackend::addBuddy(long userId, const BuddyInfo &buddyInfo) {
|
|||
return id;
|
||||
}
|
||||
|
||||
void MySQLBackend::updateBuddySetting(long userId, long buddyId, const std::string &variable, int type, const std::string &value) {
|
||||
*m_updateBuddySetting << userId << buddyId << variable << type << value << value;
|
||||
EXEC(m_updateBuddySetting, updateBuddySetting(userId, buddyId, variable, type, value));
|
||||
}
|
||||
|
||||
void MySQLBackend::getBuddySetting(long userId, long buddyId, const std::string &variable, int &type, std::string &value) {
|
||||
// "SELECT type, value FROM " + m_prefix + "users_settings WHERE user_id=? AND var=?"
|
||||
*m_getBuddySetting << userId << buddyId << variable;
|
||||
EXEC(m_getBuddySetting, getBuddySetting(userId, buddyId, variable, type, value));
|
||||
if (m_getBuddySetting->fetch() == 0) {
|
||||
*m_getBuddySetting >> type >> value;
|
||||
}
|
||||
|
||||
while (m_getBuddySetting->fetch() == 0) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MySQLBackend::removeBuddy(long id) {
|
||||
*m_removeBuddy << (int) id;
|
||||
EXEC(m_removeBuddy, removeBuddy(id));
|
||||
if (!exec_ok)
|
||||
return;
|
||||
|
||||
*m_removeBuddySettings << (int) id;
|
||||
EXEC(m_removeBuddySettings, removeBuddy(id));
|
||||
if (!exec_ok)
|
||||
return;
|
||||
}
|
||||
|
||||
void MySQLBackend::updateBuddy(long userId, const BuddyInfo &buddyInfo) {
|
||||
// "UPDATE " + m_prefix + "buddies SET groups=?, nickname=?, flags=?, subscription=? WHERE user_id=? AND uin=?"
|
||||
std::string groups = Util::serializeGroups(buddyInfo.groups);
|
||||
|
|
Loading…
Add table
Reference in a new issue