X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fextra%2Fm_mysql.cpp;h=45ba67e4ebf23d48b53f5e99313246afff38292a;hb=97a1d6429a735eb279496df010d04e3f42aa4e22;hp=a16a293d75da88d9e3a357b71ddc58a9c4ceb5cd;hpb=b6f57c0f06f4905b04de6ec2069522d2263626c4;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index a16a293d7..45ba67e4e 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -145,7 +145,7 @@ class MySQLresult : public SQL::Result std::vector colnames; std::vector 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; @@ -343,10 +356,9 @@ class SQLConnection : public SQL::Provider // and one byte is the terminating null std::vector buffer(parm.length() * 2 + 1); - // The return value of mysql_escape_string() is the length of the encoded string, + // The return value of mysql_real_escape_string() is the length of the encoded string, // not including the terminating null - unsigned long escapedsize = mysql_escape_string(&buffer[0], parm.c_str(), parm.length()); -// mysql_real_escape_string(connection, queryend, paramscopy[paramnum].c_str(), paramscopy[paramnum].length()); + unsigned long escapedsize = mysql_real_escape_string(connection, &buffer[0], parm.c_str(), parm.length()); res.append(&buffer[0], escapedsize); } } @@ -415,7 +427,7 @@ void ModuleSQL::ReadConfig(ConfigStatus& status) ConfigTagList tags = ServerInstance->Config->ConfTags("database"); for(ConfigIter i = tags.first; i != tags.second; i++) { - if (i->second->getString("module", "mysql") != "mysql") + if (!stdalgo::string::equalsci(i->second->getString("provider"), "mysql")) continue; std::string id = i->second->getString("id"); ConnMap::iterator curr = connections.find(id); @@ -541,7 +553,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);