X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fextra%2Fm_pgsql.cpp;h=bb727b623ea504dd4d3dbd4a874fd59e61531702;hb=77730fd5f09f8fc193205654c8bba84d34365670;hp=25ce6c7f1168f72d281245576a161a1826c1c729;hpb=b6f57c0f06f4905b04de6ec2069522d2263626c4;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp index 25ce6c7f1..bb727b623 100644 --- a/src/modules/extra/m_pgsql.cpp +++ b/src/modules/extra/m_pgsql.cpp @@ -87,6 +87,16 @@ class PgSQLresult : public SQL::Result PGresult* res; int currentrow; int rows; + std::vector colnames; + + void getColNames() + { + colnames.resize(PQnfields(res)); + for(unsigned int i=0; i < colnames.size(); i++) + { + colnames[i] = PQfname(res, i); + } + } public: PgSQLresult(PGresult* result) : res(result), currentrow(0) { @@ -107,11 +117,25 @@ class PgSQLresult : public SQL::Result void GetCols(std::vector& result) CXX11_OVERRIDE { - result.resize(PQnfields(res)); - for(unsigned int i=0; i < result.size(); i++) + if (colnames.empty()) + getColNames(); + result = colnames; + } + + bool HasColumn(const std::string& column, size_t& index) CXX11_OVERRIDE + { + if (colnames.empty()) + getColNames(); + + for (size_t i = 0; i < colnames.size(); ++i) { - result[i] = PQfname(res, i); + if (colnames[i] == column) + { + index = i; + return true; + } } + return false; } SQL::Field GetValue(int row, int column) @@ -522,7 +546,7 @@ class ModulePgSQL : public Module ConfigTagList tags = ServerInstance->Config->ConfTags("database"); for(ConfigIter i = tags.first; i != tags.second; i++) { - if (i->second->getString("module", "pgsql") != "pgsql") + if (!stdalgo::string::equalsci(i->second->getString("module"), "pgsql")) continue; std::string id = i->second->getString("id"); ConnMap::iterator curr = connections.find(id);