Author: baufo
Date: Fri Dec  5 23:39:25 2008
New Revision: 31294

URL: http://svn.gna.org/viewcvs/wesnoth?rev=31294&view=rev
Log:
Making the forum user handler use the mysql C API rather than the C++ wrappers

Modified:
    trunk/src/server/forum_user_handler.cpp
    trunk/src/server/forum_user_handler.hpp

Modified: trunk/src/server/forum_user_handler.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/forum_user_handler.cpp?rev=31294&r1=31293&r2=31294&view=diff
==============================================================================
--- trunk/src/server/forum_user_handler.cpp (original)
+++ trunk/src/server/forum_user_handler.cpp Fri Dec  5 23:39:25 2008
@@ -27,12 +27,15 @@
        db_users_table_ = c["db_users_table"];
        db_extra_table_ = c["db_extra_table"];
 
-       // Connect to the database
-       try {
-               db_interface_.connect(db_name_.c_str(), db_host_.c_str(), 
db_user_.c_str(), db_password_.c_str());
-       } catch(...) {
-                ERR_UH << "Could not connect to database: " << 
db_interface_.error() << std::endl;
-       }
+       conn = mysql_init(NULL);
+
+       if(!conn || !mysql_real_connect(conn, db_host_.c_str(),  
db_user_.c_str(), db_password_.c_str(), db_name_.c_str(), 0, NULL, 0)) {
+               ERR_UH << "Could not connect to database: " << 
mysql_errno(conn) << ": " << mysql_error(conn) << std::endl;
+       }
+}
+
+fuh::~fuh() {
+       mysql_close(conn);
 }
 
 void fuh::add_user(const std::string& name, const std::string& mail, const 
std::string& password) {
@@ -133,7 +136,7 @@
 
        // Make a test query for this username
        try {
-               return db_query("SELECT username FROM " + db_users_table_ + " 
WHERE username='" + name + "'").num_rows() > 0;
+               return mysql_fetch_row(db_query("SELECT username FROM " + 
db_users_table_ + " WHERE username='" + name + "'"));
        } catch (error e) {
                ERR_UH << "Could not execute test query for user '" << name << 
"' :" << e.message << std::endl;
                // If the database is down just let all usernames log in
@@ -223,30 +226,21 @@
        }
 }
 
-mysqlpp::Result fuh::db_query(const std::string& sql) {
-       try {
-               mysqlpp::Query query = db_interface_.query();
-               query << sql;
-               return query.store();
-       } catch(...) {
+MYSQL_RES* fuh::db_query(const std::string& sql) {
+       if(mysql_query(conn, sql.c_str())) {
                WRN_UH << "not connected to database, reconnecting..." << 
std::endl;
-               //Try to reconnect
-               try {
-                       db_interface_.connect(db_name_.c_str(), 
db_host_.c_str(), db_user_.c_str(), db_password_.c_str());
-
-                       // Execute the query again
-                       mysqlpp::Query query = db_interface_.query();
-                       query << sql;
-                       return query.store();
-               } catch(...) {
-                       ERR_UH << "Could not connect to database: " << 
db_interface_.error() << std::endl;
+               //Try to reconnect and execute query again
+               if(!mysql_real_connect(conn, db_host_.c_str(),  
db_user_.c_str(), db_password_.c_str(), db_name_.c_str(), 0, NULL, 0)
+                               || mysql_query(conn, sql.c_str())) {
+                       ERR_UH << "Could not connect to database: " << 
mysql_errno(conn) << ": " << mysql_error(conn) << std::endl;
                        throw error("Error querying database.");
                }
        }
-}
-
-std::string fuh::db_query_to_string(const std::string& query) {
-       return std::string(db_query(query).at(0).at(0));
+       return mysql_store_result(conn);
+}
+
+std::string fuh::db_query_to_string(const std::string& sql) {
+       return std::string(mysql_fetch_row(db_query(sql))[0]);
 }
 
 
@@ -276,7 +270,7 @@
 
        // Make a test query for this username
        try {
-               return db_query("SELECT username FROM " + db_extra_table_ + " 
WHERE username='" + name + "'").num_rows() > 0;
+               return mysql_fetch_row(db_query("SELECT username FROM " + 
db_extra_table_ + " WHERE username='" + name + "'"));
        } catch (error e) {
                ERR_UH << "Could not execute test query for user '" << name << 
"' :" << e.message << std::endl;
                return false;

Modified: trunk/src/server/forum_user_handler.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/forum_user_handler.hpp?rev=31294&r1=31293&r2=31294&view=diff
==============================================================================
--- trunk/src/server/forum_user_handler.hpp (original)
+++ trunk/src/server/forum_user_handler.hpp Fri Dec  5 23:39:25 2008
@@ -19,7 +19,7 @@
 
 #include <vector>
 
-#include <mysql++/mysql++.h>
+#include <mysql/mysql.h>
 #include "../md5.hpp"
 
 /**
@@ -43,7 +43,7 @@
 class fuh : public user_handler {
        public:
                fuh(const config& c);
-               ~fuh() {}
+               ~fuh();
 
                // Throws user_handler::error
                void add_user(const std::string& name, const std::string& mail, 
const std::string& password);
@@ -92,11 +92,11 @@
                std::string db_name_, db_host_, db_user_, db_password_, 
db_users_table_, db_extra_table_;
 
                // Throws user_handler::error
-               mysqlpp::Result db_query(const std::string& query);
+               MYSQL_RES* db_query(const std::string& query);
 
                // Throws user_handler::error via db_query() 
                std::string db_query_to_string(const std::string& query);
-               mysqlpp::Connection db_interface_;
+               MYSQL *conn;
 
                // Query a detail for a particular user from the database
                std::string get_detail_for_user(const std::string& name, const 
std::string& detail);


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to