X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fextra%2Fm_sqlite3.cpp;h=e81e990252c7e9b115f1865c6b3fe038306e1bec;hb=e59cb85871f75b7603c63c6cd274d57536cf6794;hp=ac7146e386b3a3e980dff0992753b99e0e6e1555;hpb=c0aba5b728b0a921d95ec120aa638dab1520b42f;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp index ac7146e38..e81e99025 100644 --- a/src/modules/extra/m_sqlite3.cpp +++ b/src/modules/extra/m_sqlite3.cpp @@ -24,6 +24,7 @@ /// $PackageInfo: require_system("centos") pkgconfig sqlite-devel /// $PackageInfo: require_system("darwin") pkg-config sqlite3 +/// $PackageInfo: require_system("debian") libsqlite3-dev pkg-config /// $PackageInfo: require_system("ubuntu") libsqlite3-dev pkg-config #include "inspircd.h" @@ -45,24 +46,24 @@ class SQLConn; typedef insp::flat_map ConnMap; -class SQLite3Result : public SQLResult +class SQLite3Result : public SQL::Result { public: int currentrow; int rows; std::vector columns; - std::vector fieldlists; + std::vector fieldlists; SQLite3Result() : currentrow(0), rows(0) { } - int Rows() + int Rows() CXX11_OVERRIDE { return rows; } - bool GetRow(SQLEntries& result) + bool GetRow(SQL::Row& result) CXX11_OVERRIDE { if (currentrow < rows) { @@ -77,19 +78,32 @@ class SQLite3Result : public SQLResult } } - void GetCols(std::vector& result) + void GetCols(std::vector& result) CXX11_OVERRIDE { result.assign(columns.begin(), columns.end()); } + + bool HasColumn(const std::string& column, size_t& index) CXX11_OVERRIDE + { + for (size_t i = 0; i < columns.size(); ++i) + { + if (columns[i] == column) + { + index = i; + return true; + } + } + return false; + } }; -class SQLConn : public SQLProvider +class SQLConn : public SQL::Provider { sqlite3* conn; reference config; public: - SQLConn(Module* Parent, ConfigTag* tag) : SQLProvider(Parent, "SQL/" + tag->getString("id")), config(tag) + SQLConn(Module* Parent, ConfigTag* tag) : SQL::Provider(Parent, "SQL/" + tag->getString("id")), config(tag) { std::string host = tag->getString("hostname"); if (sqlite3_open_v2(host.c_str(), &conn, SQLITE_OPEN_READWRITE, 0) != SQLITE_OK) @@ -110,14 +124,14 @@ class SQLConn : public SQLProvider } } - void Query(SQLQuery* query, const std::string& q) + void Query(SQL::Query* query, const std::string& q) { SQLite3Result res; sqlite3_stmt *stmt; int err = sqlite3_prepare_v2(conn, q.c_str(), q.length(), &stmt, NULL); if (err != SQLITE_OK) { - SQLerror error(SQL_QSEND_FAIL, sqlite3_errmsg(conn)); + SQL::Error error(SQL::QSEND_FAIL, sqlite3_errmsg(conn)); query->OnError(error); return; } @@ -139,7 +153,7 @@ class SQLConn : public SQLProvider { const char* txt = (const char*)sqlite3_column_text(stmt, i); if (txt) - res.fieldlists[res.rows][i] = SQLEntry(txt); + res.fieldlists[res.rows][i] = SQL::Field(txt); } res.rows++; } @@ -150,7 +164,7 @@ class SQLConn : public SQLProvider } else { - SQLerror error(SQL_QREPLY_FAIL, sqlite3_errmsg(conn)); + SQL::Error error(SQL::QREPLY_FAIL, sqlite3_errmsg(conn)); query->OnError(error); break; } @@ -158,13 +172,13 @@ class SQLConn : public SQLProvider sqlite3_finalize(stmt); } - void submit(SQLQuery* query, const std::string& q) + void Submit(SQL::Query* query, const std::string& q) CXX11_OVERRIDE { Query(query, q); delete query; } - void submit(SQLQuery* query, const std::string& q, const ParamL& p) + void Submit(SQL::Query* query, const std::string& q, const SQL::ParamList& p) CXX11_OVERRIDE { std::string res; unsigned int param = 0; @@ -182,10 +196,10 @@ class SQLConn : public SQLProvider } } } - submit(query, res); + Submit(query, res); } - void submit(SQLQuery* query, const std::string& q, const ParamM& p) + void Submit(SQL::Query* query, const std::string& q, const SQL::ParamMap& p) CXX11_OVERRIDE { std::string res; for(std::string::size_type i = 0; i < q.length(); i++) @@ -200,7 +214,7 @@ class SQLConn : public SQLProvider field.push_back(q[i++]); i--; - ParamM::const_iterator it = p.find(field); + SQL::ParamMap::const_iterator it = p.find(field); if (it != p.end()) { char* escaped = sqlite3_mprintf("%q", it->second.c_str()); @@ -209,7 +223,7 @@ class SQLConn : public SQLProvider } } } - submit(query, res); + Submit(query, res); } }; @@ -240,7 +254,7 @@ class ModuleSQLite3 : public Module ConfigTagList tags = ServerInstance->Config->ConfTags("database"); for(ConfigIter i = tags.first; i != tags.second; i++) { - if (i->second->getString("module", "sqlite") != "sqlite") + if (!stdalgo::string::equalsci(i->second->getString("module"), "sqlite")) continue; SQLConn* conn = new SQLConn(this, i->second); conns.insert(std::make_pair(i->second->getString("id"), conn)); @@ -250,7 +264,7 @@ class ModuleSQLite3 : public Module Version GetVersion() CXX11_OVERRIDE { - return Version("sqlite3 provider", VF_VENDOR); + return Version("Provides SQLite3 support", VF_VENDOR); } };