getBuddiesSettings sqlite3 statement
This commit is contained in:
parent
e58ede7d51
commit
125264c226
3 changed files with 78 additions and 1 deletions
|
@ -104,6 +104,7 @@ class SQLite3Backend : public StorageBackend
|
|||
sqlite3_stmt *m_addBuddy;
|
||||
sqlite3_stmt *m_updateBuddy;
|
||||
sqlite3_stmt *m_getBuddies;
|
||||
sqlite3_stmt *m_getBuddiesSettings;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -36,12 +36,43 @@ struct UserInfo {
|
|||
bool vip; ///< true if user is VIP
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TYPE_UNKNOWN = 0, /**< Unknown type. */
|
||||
TYPE_SUBTYPE, /**< Subtype. */
|
||||
TYPE_CHAR, /**< Character. */
|
||||
TYPE_UCHAR, /**< Unsigned character. */
|
||||
TYPE_BOOLEAN, /**< Boolean. */
|
||||
TYPE_SHORT, /**< Short integer. */
|
||||
TYPE_USHORT, /**< Unsigned short integer. */
|
||||
TYPE_INT, /**< Integer. */
|
||||
TYPE_UINT, /**< Unsigned integer. */
|
||||
TYPE_LONG, /**< Long integer. */
|
||||
TYPE_ULONG, /**< Unsigned long integer. */
|
||||
TYPE_INT64, /**< 64-bit integer. */
|
||||
TYPE_UINT64, /**< 64-bit unsigned integer. */
|
||||
TYPE_STRING, /**< String. */
|
||||
TYPE_OBJECT, /**< Object pointer. */
|
||||
TYPE_POINTER, /**< Generic pointer. */
|
||||
TYPE_ENUM, /**< Enum. */
|
||||
TYPE_BOXED /**< Boxed pointer with specific type. */
|
||||
|
||||
} SettingType;
|
||||
|
||||
struct SettingVariableInfo {
|
||||
int type;
|
||||
std::string s;
|
||||
int i;
|
||||
bool b;
|
||||
};
|
||||
|
||||
struct BuddyInfo {
|
||||
long id;
|
||||
std::string alias;
|
||||
std::string legacyName;
|
||||
std::string subscription;
|
||||
std::vector<std::string> groups;
|
||||
std::map<std::string, SettingVariableInfo> settings;
|
||||
int flags;
|
||||
};
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ bool SQLite3Backend::connect() {
|
|||
PREP_STMT(m_addBuddy, "INSERT INTO " + m_prefix + "buddies (user_id, uin, subscription, groups, nickname, flags) VALUES (?, ?, ?, ?, ?, ?)");
|
||||
PREP_STMT(m_updateBuddy, "UPDATE " + m_prefix + "buddies SET groups=?, nickname=?, flags=?, subscription=? WHERE user_id=? AND uin=?");
|
||||
PREP_STMT(m_getBuddies, "SELECT id uin, subscription, nickname, groups, flags FROM " + m_prefix + "buddies WHERE user_id=? ORDER BY id ASC");
|
||||
PREP_STMT(m_getBuddiesSettings, "SELECT buddy_id, type, var, value FROM " + m_prefix + "buddies_settings WHERE user_id=? ORDER BY buddy_id ASC");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -249,8 +250,16 @@ bool SQLite3Backend::getBuddies(long id, std::list<BuddyInfo> &roster) {
|
|||
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;
|
||||
while((ret = sqlite3_step(m_getUser)) == SQLITE_ROW) {
|
||||
while((ret = sqlite3_step(m_getBuddies)) == SQLITE_ROW) {
|
||||
BuddyInfo b;
|
||||
b.id = GET_INT(m_getBuddies);
|
||||
b.legacyName = GET_STR(m_getBuddies);
|
||||
|
@ -258,6 +267,42 @@ bool SQLite3Backend::getBuddies(long id, std::list<BuddyInfo> &roster) {
|
|||
b.alias = GET_STR(m_getBuddies);
|
||||
b.groups.push_back(GET_STR(m_getBuddies));
|
||||
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 && (ret = sqlite3_step(m_getBuddiesSettings)) == SQLITE_ROW) {
|
||||
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:
|
||||
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) {
|
||||
onStorageError("getBuddiesSettings query", (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
|
||||
return false;
|
||||
}
|
||||
|
||||
roster.push_back(b);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue