Changeset - 9bc058ae376f
[Not reviewed]
0 1 0
HanzZ - 14 years ago 2011-12-23 13:37:17
hanzz.k@gmail.com
setUserONline, getOnlineUsers
1 file changed with 19 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/pqxxbackend.cpp
Show inline comments
 
@@ -176,7 +176,7 @@ bool PQXXBackend::getUser(const std::string &barejid, UserInfo &user) {
 
		user.password = r[0][3].as<std::string>();
 
		user.encoding = r[0][4].as<std::string>();
 
		user.language = r[0][5].as<std::string>();
 
		// user.vip = r[0][6].as<int>();
 
		user.vip = r[0][6].as<bool>();
 
	}
 
	catch (std::exception& e) {
 
		LOG4CXX_ERROR(logger, e.what());
 
@@ -187,20 +187,28 @@ bool PQXXBackend::getUser(const std::string &barejid, UserInfo &user) {
 
}
 

	
 
void PQXXBackend::setUserOnline(long id, bool online) {
 
//	*m_setUserOnline << online << id;
 
//	EXEC(m_setUserOnline, setUserOnline(id, online));
 
	try {
 
		pqxx::work txn(*m_conn);
 
		exec(txn, "UPDATE " + m_prefix + "users SET online=" + txn.quote(online) + ", last_login=NOW() WHERE id=" + txn.quote(id));
 
	}
 
	catch (std::exception& e) {
 
		LOG4CXX_ERROR(logger, e.what());
 
	}
 
}
 

	
 
bool PQXXBackend::getOnlineUsers(std::vector<std::string> &users) {
 
//	EXEC(m_getOnlineUsers, getOnlineUsers(users));
 
//	if (!exec_ok)
 
//		return false;
 
	try {
 
		pqxx::work txn(*m_conn);
 
		pqxx::result r = txn.exec("SELECT jid FROM " + m_prefix + "users WHERE online=1");
 

	
 
//	std::string jid;
 
//	while (m_getOnlineUsers->fetch() == 0) {
 
//		*m_getOnlineUsers >> jid;
 
//		users.push_back(jid);
 
//	}
 
		for (pqxx::result::const_iterator it = r.begin(); it != r.end(); it++)  {
 
			users.push_back((*it)[0].as<std::string>());
 
		}
 
	}
 
	catch (std::exception& e) {
 
		LOG4CXX_ERROR(logger, e.what());
 
		return false;
 
	}
 

	
 
	return true;
 
}
0 comments (0 inline, 0 general)