Changeset - 1309637a5843
[Not reviewed]
0 1 0
Jan Kaluza - 10 years ago 2015-11-25 16:23:13
jkaluza@redhat.com
SQLite3Backend::setUser - use null for the 'id' when user.id is 0
1 file changed with 6 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/SQLite3Backend.cpp
Show inline comments
 
@@ -202,49 +202,54 @@ bool SQLite3Backend::createDatabase() {
 
			"  ver INTEGER NOT NULL DEFAULT '3'"
 
			");");
 
		exec("REPLACE INTO " + m_prefix + "db_version (ver) values(3)");
 
	}
 
	return true;
 
}
 

	
 
bool SQLite3Backend::exec(const std::string &query) {
 
	char *errMsg = 0;
 
	int rc = sqlite3_exec(m_db, query.c_str(), NULL, 0, &errMsg);
 
	if (rc != SQLITE_OK) {
 
		// This error is OK, because we try to create buddies table every time
 
		// to detect if DB is created properly.
 
		if (errMsg && std::string(errMsg).find("table buddies already exists") == std::string::npos) {
 
			LOG4CXX_ERROR(logger, errMsg << " during statement " << query);
 
		}
 
		sqlite3_free(errMsg);
 
		return false;
 
	}
 
	return true;
 
}
 

	
 
void SQLite3Backend::setUser(const UserInfo &user) {
 
	sqlite3_reset(m_setUser);
 
	sqlite3_bind_int(m_setUser, 1, user.id);
 
	if (user.id == 0) {
 
		sqlite3_bind_null(m_setUser, 1);
 
	}
 
	else {
 
		sqlite3_bind_int(m_setUser, 1, user.id);
 
	}
 
	sqlite3_bind_text(m_setUser, 2, user.jid.c_str(), -1, SQLITE_STATIC);
 
	sqlite3_bind_text(m_setUser, 3, user.uin.c_str(), -1, SQLITE_STATIC);
 
	sqlite3_bind_text(m_setUser, 4, user.password.c_str(), -1, SQLITE_STATIC);
 
	sqlite3_bind_text(m_setUser, 5, user.language.c_str(), -1, SQLITE_STATIC);
 
	sqlite3_bind_text(m_setUser, 6, user.encoding.c_str(), -1, SQLITE_STATIC);
 
	sqlite3_bind_int (m_setUser, 7, user.vip);
 

	
 
	if(sqlite3_step(m_setUser) != SQLITE_DONE) {
 
		LOG4CXX_ERROR(logger, "setUser query"<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
 
	}
 
}
 

	
 
bool SQLite3Backend::getUser(const std::string &barejid, UserInfo &user) {
 
// 	SELECT id, jid, uin, password, encoding, language, vip FROM " + m_prefix + "users WHERE jid=?
 
	sqlite3_reset(m_getUser);
 
	sqlite3_bind_text(m_getUser, 1, barejid.c_str(), -1, SQLITE_TRANSIENT);
 

	
 
	int ret;
 
	while((ret = sqlite3_step(m_getUser)) == SQLITE_ROW) {
 
		user.id = sqlite3_column_int(m_getUser, 0);
 
		user.jid = (const char *) sqlite3_column_text(m_getUser, 1);
 
		user.uin = (const char *) sqlite3_column_text(m_getUser, 2);
 
		user.password = (const char *) sqlite3_column_text(m_getUser, 3);
 
		user.encoding = (const char *) sqlite3_column_text(m_getUser, 4);
0 comments (0 inline, 0 general)