From 4e0997924d4052dede401fa1c0a1a91ae81c9aa3 Mon Sep 17 00:00:00 2001 From: danieldg Date: Sat, 6 Mar 2010 19:23:44 +0000 Subject: Add column names to SQLv3, allow sqloper to specify its own query string git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12606 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/extra/m_sqlite3.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/modules/extra') diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp index 4a0538bc8..cc54b90bf 100644 --- a/src/modules/extra/m_sqlite3.cpp +++ b/src/modules/extra/m_sqlite3.cpp @@ -28,7 +28,8 @@ class SQLite3Result : public SQLResult public: int currentrow; int rows; - std::vector > fieldlists; + std::vector columns; + std::vector fieldlists; SQLite3Result() : currentrow(0), rows(0) { @@ -43,7 +44,7 @@ class SQLite3Result : public SQLResult return rows; } - virtual bool GetRow(std::vector& result) + virtual bool GetRow(SQLEntries& result) { if (currentrow < rows) { @@ -57,6 +58,10 @@ class SQLite3Result : public SQLResult return false; } } + virtual void GetCols(std::vector& result) + { + result.assign(columns.begin(), columns.end()); + } }; class SQLConn : public refcountbase @@ -94,6 +99,11 @@ class SQLConn : public refcountbase return; } int cols = sqlite3_column_count(stmt); + res.columns.resize(cols); + for(int i=0; i < cols; i++) + { + res.columns[i] = sqlite3_column_name(stmt, i); + } while (1) { err = sqlite3_step(stmt); @@ -105,7 +115,8 @@ class SQLConn : public refcountbase for(int i=0; i < cols; i++) { const char* txt = (const char*)sqlite3_column_text(stmt, i); - res.fieldlists[res.rows][i] = txt ? txt : ""; + if (txt) + res.fieldlists[res.rows][i] = SQLEntry(txt); } res.rows++; } @@ -132,7 +143,7 @@ class SQLiteProvider : public SQLProvider SQLiteProvider(Module* Parent) : SQLProvider(Parent, "SQL/SQLite") {} - std::string FormatQuery(std::string q, ParamL p) + std::string FormatQuery(const std::string& q, const ParamL& p) { std::string res; unsigned int param = 0; @@ -154,7 +165,7 @@ class SQLiteProvider : public SQLProvider return res; } - std::string FormatQuery(std::string q, ParamM p) + std::string FormatQuery(const std::string& q, const ParamM& p) { std::string res; for(std::string::size_type i = 0; i < q.length(); i++) @@ -169,9 +180,13 @@ class SQLiteProvider : public SQLProvider field.push_back(q[i++]); i--; - char* escaped = sqlite3_mprintf("%q", p[field].c_str()); - res.append(escaped); - sqlite3_free(escaped); + ParamM::const_iterator it = p.find(field); + if (it != p.end()) + { + char* escaped = sqlite3_mprintf("%q", it->second.c_str()); + res.append(escaped); + sqlite3_free(escaped); + } } } return res; -- cgit v1.2.3