]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_mysql.cpp
Add ConfigTag::getUInt for reading unsigned config values.
[user/henk/code/inspircd.git] / src / modules / extra / m_mysql.cpp
index a16a293d75da88d9e3a357b71ddc58a9c4ceb5cd..0a7d4d993ce6d78a4e5c91d7d86e15fa004bac4d 100644 (file)
@@ -145,7 +145,7 @@ class MySQLresult : public SQL::Result
        std::vector<std::string> colnames;
        std::vector<SQL::Row> fieldlists;
 
-       MySQLresult(MYSQL_RES* res, int affected_rows) : err(SQL::NO_ERROR), currentrow(0), rows(0)
+       MySQLresult(MYSQL_RES* res, int affected_rows) : err(SQL::SUCCESS), currentrow(0), rows(0)
        {
                if (affected_rows >= 1)
                {
@@ -203,6 +203,19 @@ class MySQLresult : public SQL::Result
                result.assign(colnames.begin(), colnames.end());
        }
 
+       bool HasColumn(const std::string& column, size_t& index)
+       {
+               for (size_t i = 0; i < colnames.size(); ++i)
+               {
+                       if (colnames[i] == column)
+                       {
+                               index = i;
+                               return true;
+                       }
+               }
+               return false;
+       }
+
        SQL::Field GetValue(int row, int column)
        {
                if ((row >= 0) && (row < rows) && (column >= 0) && (column < (int)fieldlists[row].size()))
@@ -259,7 +272,7 @@ class SQLConnection : public SQL::Provider
                std::string user = config->getString("user");
                std::string pass = config->getString("pass");
                std::string dbname = config->getString("name");
-               int port = config->getInt("port");
+               unsigned int port = config->getUInt("port", 3306);
                bool rv = mysql_real_connect(connection, host.c_str(), user.c_str(), pass.c_str(), dbname.c_str(), port, NULL, 0);
                if (!rv)
                        return rv;
@@ -541,7 +554,7 @@ void DispatcherThread::OnNotify()
        for(ResultQueue::iterator i = Parent->rq.begin(); i != Parent->rq.end(); i++)
        {
                MySQLresult* res = i->r;
-               if (res->err.code == SQL::NO_ERROR)
+               if (res->err.code == SQL::SUCCESS)
                        i->q->OnResult(*res);
                else
                        i->q->OnError(res->err);