aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/extra/m_pgsql.cpp
diff options
context:
space:
mode:
authorGravatar Daniel Vassdal2015-03-02 03:06:55 +0100
committerGravatar Peter Powell2018-04-07 11:50:08 +0100
commitd38f2ad213e875d40556116cba3230064eacb861 (patch)
tree3aa8bd0b9c3ba0ab7c337c42be53f7756becc07e /src/modules/extra/m_pgsql.cpp
parentRefactor m_sqloper to be a full opers.conf replacement (#983). (diff)
downloadinspircd++-d38f2ad213e875d40556116cba3230064eacb861.tar.gz
inspircd++-d38f2ad213e875d40556116cba3230064eacb861.tar.bz2
inspircd++-d38f2ad213e875d40556116cba3230064eacb861.zip
SQL: Add HasColumn() to check if a result contains a named column.
Diffstat (limited to 'src/modules/extra/m_pgsql.cpp')
-rw-r--r--src/modules/extra/m_pgsql.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp
index 25ce6c7f1..8beea1265 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<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)