Changeset - 11e4b90e697d
[Not reviewed]
0 1 0
HanzZ - 14 years ago 2011-08-13 14:40:58
hanzz.k@gmail.com
working MySQL results
1 file changed with 16 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/mysqlbackend.cpp
Show inline comments
 
@@ -172,12 +172,16 @@ MySQLBackend::Statement::Statement(MYSQL *conn, const std::string &format, const
 

	
 
MySQLBackend::Statement::~Statement() {
 
	for (int i = 0; i < m_params.size(); i++) {
 
		free(m_params[i].buffer);
 
		free(m_params[i].length);
 
	}
 
	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.
 
@@ -195,58 +199,58 @@ bool MySQLBackend::Statement::execute() {
 
bool MySQLBackend::Statement::fetch() {
 
	return mysql_stmt_fetch(m_stmt);
 
}
 

	
 
template <typename T>
 
MySQLBackend::Statement& MySQLBackend::Statement::operator << (const T& t) {
 
	if (m_offset >= m_resultOffset)
 
	if (m_offset >= m_params.size())
 
		return *this;
 
	T *data = (T *) m_params[m_offset].buffer;
 
	*data = t;
 

	
 
	LOG4CXX_INFO(logger, "adding " << m_offset << ":" << t);
 
	m_offset++;
 
	return *this;
 
}
 

	
 
MySQLBackend::Statement& MySQLBackend::Statement::operator << (const std::string& str) {
 
	if (m_offset >= m_resultOffset)
 
	if (m_offset >= m_params.size())
 
		return *this;
 
	LOG4CXX_INFO(logger, "adding " << m_offset << ":" << str << "(" << str.size() << ")");
 
	strncpy((char*) m_params[m_offset].buffer, str.c_str(), 4096);
 
	*m_params[m_offset].length = str.size();
 
	m_offset++;
 
	return *this;
 
}
 

	
 
template <typename T>
 
MySQLBackend::Statement& MySQLBackend::Statement::operator >> (T& t) {
 
	if (m_offset < m_resultOffset)
 
	if (m_resultOffset > m_results.size())
 
		return *this;
 

	
 
	if (!m_params[m_offset].is_null) {
 
		T *data = (T *) m_params[m_offset].buffer;
 
	if (!m_results[m_resultOffset].is_null) {
 
		T *data = (T *) m_results[m_resultOffset].buffer;
 
		t = *data;
 
	}
 

	
 
	if (++m_offset == m_params.size())
 
		m_offset = 0;
 
	if (++m_resultOffset == m_results.size())
 
		m_resultOffset = 0;
 
	return *this;
 
}
 

	
 
MySQLBackend::Statement& MySQLBackend::Statement::operator >> (std::string& t) {
 
	std::cout << "getting " << m_offset << " " << m_resultOffset << "\n";
 
	if (m_offset < m_resultOffset)
 
	if (m_resultOffset > m_results.size())
 
		return *this;
 

	
 
	if (!m_params[m_offset].is_null) {
 
		t = (char *) m_params[m_offset].buffer;
 
	if (!m_results[m_resultOffset].is_null) {
 
		t = (char *) m_results[m_resultOffset].buffer;
 
	}
 

	
 
	if (++m_offset == m_params.size())
 
		m_offset = 0;
 
	if (++m_resultOffset == m_results.size())
 
		m_resultOffset = 0;
 
	return *this;
 
}
 

	
 
MySQLBackend::MySQLBackend(Config *config) {
 
	m_config = config;
 
	mysql_init(&m_conn);
0 comments (0 inline, 0 general)