]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_pgsql.cpp
Merge tag 'v2.0.27' into master.
[user/henk/code/inspircd.git] / src / modules / extra / m_pgsql.cpp
index 25ce6c7f1168f72d281245576a161a1826c1c729..bb727b623ea504dd4d3dbd4a874fd59e61531702 100644 (file)
@@ -87,6 +87,16 @@ class PgSQLresult : public SQL::Result
        PGresult* res;
        int currentrow;
        int rows;
+       std::vector<std::string> 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<std::string>& 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);