Changeset - 13979eacdd27
[Not reviewed]
0 1 0
HanzZ - 14 years ago 2011-08-13 17:52:04
hanzz.k@gmail.com
fetch all results from mysql
1 file changed with 10 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/mysqlbackend.cpp
Show inline comments
 
@@ -178,27 +178,28 @@ MySQLBackend::Statement::~Statement() {
 
	for (int i = 0; i < m_results.size(); i++) {
 
		free(m_results[i].buffer);
 
		free(m_results[i].length);
 
	}
 
	FINALIZE_STMT(m_stmt);
 
}
 

	
 
bool MySQLBackend::Statement::execute() {
 
	// If statement has some input and doesn't have any output, we have
 
	// to clear the offset now, because operator>> will not be called.
 
	m_offset = 0;
 
	m_resultOffset = 0;
 
	int ret;
 

	
 
	if (mysql_stmt_execute(m_stmt)) {
 
		LOG4CXX_ERROR(logger, m_string << " " << mysql_error(m_conn));
 
	if ((ret = mysql_stmt_execute(m_stmt)) != 0) {
 
		LOG4CXX_ERROR(logger, m_string << " " << mysql_stmt_error(m_stmt) << "; " << mysql_error(m_conn));
 
		return false;
 
	}
 
	return true;
 
}
 

	
 
int MySQLBackend::Statement::fetch() {
 
	return mysql_stmt_fetch(m_stmt);
 
}
 

	
 
template <typename T>
 
MySQLBackend::Statement& MySQLBackend::Statement::operator << (const T& t) {
 
	if (m_offset >= m_params.size())
 
@@ -377,35 +378,36 @@ bool MySQLBackend::exec(const std::string &query) {
 
		LOG4CXX_ERROR(logger, query << " " << mysql_error(&m_conn));
 
		return false;
 
	}
 
	return true;
 
}
 

	
 
void MySQLBackend::setUser(const UserInfo &user) {
 
	*m_setUser << user.jid << user.uin << user.password << user.language << user.encoding << user.vip;
 
	m_setUser->execute();
 
}
 

	
 
bool MySQLBackend::getUser(const std::string &barejid, UserInfo &user) {
 
	user.id = -1;
 
	*m_getUser << barejid;
 
	if (!m_getUser->execute())
 
		return false;
 

	
 
	if (m_getUser->fetch() == MYSQL_NO_DATA)
 
		return false;
 
	int ret = false;
 
	while (m_getUser->fetch() == 0) {
 
		ret = true;
 
		*m_getUser >> user.id >> user.jid >> user.uin >> user.password >> user.encoding >> user.language >> user.vip;
 
		std::cout << user.id << " " << user.jid << " " <<  user.uin << " " <<  user.password << " " <<  user.encoding << " " <<  user.language << " " <<  user.vip << "\n";
 
	}
 

	
 
	*m_getUser >> user.id >> user.jid >> user.uin >> user.password >> user.encoding >> user.language >> user.vip;
 
	std::cout << user.id << " " << user.jid << " " <<  user.uin << " " <<  user.password << " " <<  user.encoding << " " <<  user.language << " " <<  user.vip << "\n";
 
	return true;
 
	return ret;
 
}
 

	
 
void MySQLBackend::setUserOnline(long id, bool online) {
 
	
 
}
 

	
 
long MySQLBackend::addBuddy(long userId, const BuddyInfo &buddyInfo) {
 
// 	"INSERT INTO " + m_prefix + "buddies (user_id, uin, subscription, groups, nickname, flags) VALUES (?, ?, ?, ?, ?, ?)"
 
	*m_addBuddy << userId << buddyInfo.legacyName << buddyInfo.subscription;
 
	*m_addBuddy << (buddyInfo.groups.size() == 0 ? "" : buddyInfo.groups[0]);
 
	*m_addBuddy << buddyInfo.alias << buddyInfo.flags;
 

	
0 comments (0 inline, 0 general)