]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_pgsql.cpp
Fix disabling the GeoIP extban in m_geoip.
[user/henk/code/inspircd.git] / src / modules / extra / m_pgsql.cpp
index 25ce6c7f1168f72d281245576a161a1826c1c729..8beea1265ad011aada3c548153cd263228001e2c 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)
+       {
+               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)