Do not pass char * which won't survive till sqlite3 statement execution.
This commit is contained in:
parent
79fd6782fb
commit
1fa8a9d975
2 changed files with 26 additions and 2 deletions
|
@ -283,11 +283,12 @@ bool SQLite3Backend::getOnlineUsers(std::vector<std::string> &users) {
|
|||
|
||||
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, StorageBackend::serializeGroups(buddyInfo.groups));
|
||||
BIND_STR(m_addBuddy, groups);
|
||||
BIND_STR(m_addBuddy, buddyInfo.alias);
|
||||
BIND_INT(m_addBuddy, buddyInfo.flags);
|
||||
|
||||
|
@ -312,8 +313,9 @@ long SQLite3Backend::addBuddy(long userId, const BuddyInfo &buddyInfo) {
|
|||
|
||||
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, StorageBackend::serializeGroups(buddyInfo.groups));
|
||||
BIND_STR(m_updateBuddy, groups);
|
||||
BIND_STR(m_updateBuddy, buddyInfo.alias);
|
||||
BIND_INT(m_updateBuddy, buddyInfo.flags);
|
||||
BIND_STR(m_updateBuddy, buddyInfo.subscription);
|
||||
|
|
|
@ -26,6 +26,7 @@ using namespace Transport;
|
|||
class UtilTest : public CPPUNIT_NS :: TestFixture{
|
||||
CPPUNIT_TEST_SUITE(UtilTest);
|
||||
CPPUNIT_TEST(encryptDecryptPassword);
|
||||
CPPUNIT_TEST(serializeGroups);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
@ -41,6 +42,27 @@ class UtilTest : public CPPUNIT_NS :: TestFixture{
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("password"), StorageBackend::decryptPassword(encrypted, "key"));
|
||||
}
|
||||
|
||||
void serializeGroups() {
|
||||
std::vector<std::string> groups;
|
||||
std::string g = "";
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(g, StorageBackend::serializeGroups(groups));
|
||||
CPPUNIT_ASSERT_EQUAL(0, (int) StorageBackend::deserializeGroups(g).size());
|
||||
|
||||
groups.push_back("Buddies");
|
||||
g = "Buddies";
|
||||
CPPUNIT_ASSERT_EQUAL(g, StorageBackend::serializeGroups(groups));
|
||||
CPPUNIT_ASSERT_EQUAL(1, (int) StorageBackend::deserializeGroups(g).size());
|
||||
CPPUNIT_ASSERT_EQUAL(g, StorageBackend::deserializeGroups(g)[0]);
|
||||
|
||||
groups.push_back("Buddies2");
|
||||
g = "Buddies\nBuddies2";
|
||||
CPPUNIT_ASSERT_EQUAL(g, StorageBackend::serializeGroups(groups));
|
||||
CPPUNIT_ASSERT_EQUAL(2, (int) StorageBackend::deserializeGroups(g).size());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("Buddies"), StorageBackend::deserializeGroups(g)[0]);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("Buddies2"), StorageBackend::deserializeGroups(g)[1]);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION (UtilTest);
|
||||
|
|
Loading…
Add table
Reference in a new issue