soc.2009.transport: 62fea0cf: Log sql errors

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Fri Aug 7 06:15:59 EDT 2009


-----------------------------------------------------------------
Revision: 62fea0cfc33153f077c6b4fef36db56f4e095291
Ancestor: fff143e2813184e70dd3082bae79df8e33f496cd
Author: hanzz at soc.pidgin.im
Date: 2009-08-07T10:11:16
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/62fea0cfc33153f077c6b4fef36db56f4e095291

Modified files:
        sql.cpp

ChangeLog: 

Log sql errors

-------------- next part --------------
============================================================
--- sql.cpp	00c8f54d7218a91f1d6d55612a7b62f5868ef514
+++ sql.cpp	88ade6eb2c99caef0ee93bd5cec44357e12c9f49
@@ -20,6 +20,7 @@
 
 #include "sql.h"
 #include "parser.h"
+#include "log.h"
 
 SQLClass::SQLClass(GlooxMessageHandler *parent){
 	p=parent;
@@ -45,12 +46,23 @@ bool SQLClass::isVIP(const std::string &
 		
 		query << "SELECT COUNT(jid) as is_vip FROM `users` WHERE jid='"<< jid <<"' and expire>NOW();";
 		res = query.store();
+		if (!res) {
+			Log().Get("SQL ERROR") << query.str();
+			Log().Get("SQL ERROR") << query.error();
+			return true;
+		}
 	}
 	else {
 		mysqlpp::Query query = sql->query();
 		query << "SELECT COUNT(jid) as is_vip FROM `vips` WHERE jid='"<< jid <<"'";
 		res = query.store();
+		if (!res) {
+			Log().Get("SQL ERROR") << query.str();
+			Log().Get("SQL ERROR") << query.error();
+			return true;
+		}
 	}
+
 #if MYSQLPP_HEADER_VERSION < 0x030000
 	myrow = res.fetch_row();
 	if (int(myrow.at(0))==0)
@@ -80,6 +92,11 @@ long SQLClass::getRegisteredUsersCount()
 	mysqlpp::Row myrow;
 	query << "select count(*) as count from "<< p->configuration().sqlPrefix <<"users";
 	res = query.store();
+	if (!res) {
+		Log().Get("SQL ERROR") << query.str();
+		Log().Get("SQL ERROR") << query.error();
+		return 0;
+	}
 #if MYSQLPP_HEADER_VERSION < 0x030000
 	if (res){
 		myrow = res.fetch_row();
@@ -186,6 +203,11 @@ UserRow SQLClass::getUserByJid(const std
 	user.jid="";
 	user.uin="";
 	user.password="";
+	if (!res) {
+		Log().Get("SQL ERROR") << query.str();
+		Log().Get("SQL ERROR") << query.error();
+		return user;
+	}
 #if MYSQLPP_HEADER_VERSION < 0x030000
 	if (res.size()) {
 		mysqlpp::Row row = res.fetch_row();
@@ -220,6 +242,12 @@ std::map<std::string,RosterRow> SQLClass
 	mysqlpp::StoreQueryResult res = query.store();
 #endif
 
+	if (!res) {
+		Log().Get("SQL ERROR") << query.str();
+		Log().Get("SQL ERROR") << query.error();
+		return rows;
+	}
+
 #if MYSQLPP_HEADER_VERSION < 0x030000
 	if (res) {
 		mysqlpp::Row row;
@@ -269,6 +297,13 @@ std::map<std::string,RosterRow> SQLClass
 #else
 	mysqlpp::StoreQueryResult res = query.store();
 #endif
+
+	if (!res) {
+		Log().Get("SQL ERROR") << query.str();
+		Log().Get("SQL ERROR") << query.error();
+		return rows;
+	}
+
 #if MYSQLPP_HEADER_VERSION < 0x030000
 	if (res) {
 		mysqlpp::Row row;
@@ -322,6 +357,11 @@ void SQLClass::getRandomStatus(std::stri
     query << "SELECT reklama FROM ad_statusy ORDER BY RAND() LIMIT 1";
 
     res = query.store();
+	if (!res) {
+		Log().Get("SQL ERROR") << query.str();
+		Log().Get("SQL ERROR") << query.error();
+		return;
+	}
 #if MYSQLPP_HEADER_VERSION < 0x030000
     if (res) {
         if (row = res.fetch_row()) {
@@ -370,6 +410,13 @@ GHashTable * SQLClass::getSettings(const
     query << "SELECT * FROM "<< p->configuration().sqlPrefix <<"settings WHERE jid=\"" << jid << "\";";
 
     res = query.store();
+
+	if (!res) {
+		Log().Get("SQL ERROR") << query.str();
+		Log().Get("SQL ERROR") << query.error();
+		return settings;
+	}
+	
 	if (res) {
 #if MYSQLPP_HEADER_VERSION < 0x030000
 		mysqlpp::Row row;


More information about the Commits mailing list