summaryrefslogtreecommitdiff
path: root/src/modules/extra
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/extra')
-rw-r--r--src/modules/extra/m_mysql.cpp52
-rw-r--r--src/modules/extra/m_pgsql.cpp46
-rw-r--r--src/modules/extra/m_sqlite3.cpp30
3 files changed, 64 insertions, 64 deletions
diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp
index aa396d55f..a16a293d7 100644
--- a/src/modules/extra/m_mysql.cpp
+++ b/src/modules/extra/m_mysql.cpp
@@ -84,17 +84,17 @@ class DispatcherThread;
struct QQueueItem
{
- SQLQuery* q;
+ SQL::Query* q;
std::string query;
SQLConnection* c;
- QQueueItem(SQLQuery* Q, const std::string& S, SQLConnection* C) : q(Q), query(S), c(C) {}
+ QQueueItem(SQL::Query* Q, const std::string& S, SQLConnection* C) : q(Q), query(S), c(C) {}
};
struct RQueueItem
{
- SQLQuery* q;
+ SQL::Query* q;
MySQLresult* r;
- RQueueItem(SQLQuery* Q, MySQLresult* R) : q(Q), r(R) {}
+ RQueueItem(SQL::Query* Q, MySQLresult* R) : q(Q), r(R) {}
};
typedef insp::flat_map<std::string, SQLConnection*> ConnMap;
@@ -136,16 +136,16 @@ class DispatcherThread : public SocketThread
/** Represents a mysql result set
*/
-class MySQLresult : public SQLResult
+class MySQLresult : public SQL::Result
{
public:
- SQLerror err;
+ SQL::Error err;
int currentrow;
int rows;
std::vector<std::string> colnames;
- std::vector<SQLEntries> fieldlists;
+ std::vector<SQL::Row> fieldlists;
- MySQLresult(MYSQL_RES* res, int affected_rows) : err(SQL_NO_ERROR), currentrow(0), rows(0)
+ MySQLresult(MYSQL_RES* res, int affected_rows) : err(SQL::NO_ERROR), currentrow(0), rows(0)
{
if (affected_rows >= 1)
{
@@ -174,9 +174,9 @@ class MySQLresult : public SQLResult
{
std::string a = (fields[field_count].name ? fields[field_count].name : "");
if (row[field_count])
- fieldlists[n].push_back(SQLEntry(row[field_count]));
+ fieldlists[n].push_back(SQL::Field(row[field_count]));
else
- fieldlists[n].push_back(SQLEntry());
+ fieldlists[n].push_back(SQL::Field());
colnames.push_back(a);
field_count++;
}
@@ -188,7 +188,7 @@ class MySQLresult : public SQLResult
}
}
- MySQLresult(SQLerror& e) : err(e)
+ MySQLresult(SQL::Error& e) : err(e)
{
}
@@ -203,16 +203,16 @@ class MySQLresult : public SQLResult
result.assign(colnames.begin(), colnames.end());
}
- SQLEntry GetValue(int row, int column)
+ SQL::Field GetValue(int row, int column)
{
if ((row >= 0) && (row < rows) && (column >= 0) && (column < (int)fieldlists[row].size()))
{
return fieldlists[row][column];
}
- return SQLEntry();
+ return SQL::Field();
}
- bool GetRow(SQLEntries& result) CXX11_OVERRIDE
+ bool GetRow(SQL::Row& result) CXX11_OVERRIDE
{
if (currentrow < rows)
{
@@ -230,7 +230,7 @@ class MySQLresult : public SQLResult
/** Represents a connection to a mysql database
*/
-class SQLConnection : public SQLProvider
+class SQLConnection : public SQL::Provider
{
public:
reference<ConfigTag> config;
@@ -238,7 +238,7 @@ class SQLConnection : public SQLProvider
Mutex lock;
// This constructor creates an SQLConnection object with the given credentials, but does not connect yet.
- SQLConnection(Module* p, ConfigTag* tag) : SQLProvider(p, "SQL/" + tag->getString("id")),
+ SQLConnection(Module* p, ConfigTag* tag) : SQL::Provider(p, "SQL/" + tag->getString("id")),
config(tag), connection(NULL)
{
}
@@ -297,7 +297,7 @@ class SQLConnection : public SQLProvider
{
/* XXX: See /usr/include/mysql/mysqld_error.h for a list of
* possible error numbers and error messages */
- SQLerror e(SQL_QREPLY_FAIL, ConvToStr(mysql_errno(connection)) + ": " + mysql_error(connection));
+ SQL::Error e(SQL::QREPLY_FAIL, InspIRCd::Format("%u: %s", mysql_errno(connection), mysql_error(connection)));
return new MySQLresult(e);
}
}
@@ -319,14 +319,14 @@ class SQLConnection : public SQLProvider
mysql_close(connection);
}
- void submit(SQLQuery* q, const std::string& qs) CXX11_OVERRIDE
+ void Submit(SQL::Query* q, const std::string& qs) CXX11_OVERRIDE
{
Parent()->Dispatcher->LockQueue();
Parent()->qq.push_back(QQueueItem(q, qs, this));
Parent()->Dispatcher->UnlockQueueWakeup();
}
- void submit(SQLQuery* call, const std::string& q, const ParamL& p) CXX11_OVERRIDE
+ void Submit(SQL::Query* call, const std::string& q, const SQL::ParamList& p) CXX11_OVERRIDE
{
std::string res;
unsigned int param = 0;
@@ -351,10 +351,10 @@ class SQLConnection : public SQLProvider
}
}
}
- submit(call, res);
+ Submit(call, res);
}
- void submit(SQLQuery* call, const std::string& q, const ParamM& p) CXX11_OVERRIDE
+ void Submit(SQL::Query* call, const std::string& q, const SQL::ParamMap& p) CXX11_OVERRIDE
{
std::string res;
for(std::string::size_type i = 0; i < q.length(); i++)
@@ -369,7 +369,7 @@ class SQLConnection : 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())
{
std::string parm = it->second;
@@ -380,7 +380,7 @@ class SQLConnection : public SQLProvider
}
}
}
- submit(call, res);
+ Submit(call, res);
}
};
@@ -434,7 +434,7 @@ void ModuleSQL::ReadConfig(ConfigStatus& status)
// now clean up the deleted databases
Dispatcher->LockQueue();
- SQLerror err(SQL_BAD_DBID);
+ SQL::Error err(SQL::BAD_DBID);
for(ConnMap::iterator i = connections.begin(); i != connections.end(); i++)
{
ServerInstance->Modules->DelService(*i->second);
@@ -461,7 +461,7 @@ void ModuleSQL::ReadConfig(ConfigStatus& status)
void ModuleSQL::OnUnloadModule(Module* mod)
{
- SQLerror err(SQL_BAD_DBID);
+ SQL::Error err(SQL::BAD_DBID);
Dispatcher->LockQueue();
unsigned int i = qq.size();
while (i > 0)
@@ -541,7 +541,7 @@ void DispatcherThread::OnNotify()
for(ResultQueue::iterator i = Parent->rq.begin(); i != Parent->rq.end(); i++)
{
MySQLresult* res = i->r;
- if (res->err.id == SQL_NO_ERROR)
+ if (res->err.code == SQL::NO_ERROR)
i->q->OnResult(*res);
else
i->q->OnError(res->err);
diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp
index 7aaf96a67..25ce6c7f1 100644
--- a/src/modules/extra/m_pgsql.cpp
+++ b/src/modules/extra/m_pgsql.cpp
@@ -70,9 +70,9 @@ class ReconnectTimer : public Timer
struct QueueItem
{
- SQLQuery* c;
+ SQL::Query* c;
std::string q;
- QueueItem(SQLQuery* C, const std::string& Q) : c(C), q(Q) {}
+ QueueItem(SQL::Query* C, const std::string& Q) : c(C), q(Q) {}
};
/** PgSQLresult is a subclass of the mostly-pure-virtual class SQLresult.
@@ -82,7 +82,7 @@ struct QueueItem
* data is passes to the module nearly as directly as if it was using the API directly itself.
*/
-class PgSQLresult : public SQLResult
+class PgSQLresult : public SQL::Result
{
PGresult* res;
int currentrow;
@@ -114,16 +114,16 @@ class PgSQLresult : public SQLResult
}
}
- SQLEntry GetValue(int row, int column)
+ SQL::Field GetValue(int row, int column)
{
char* v = PQgetvalue(res, row, column);
if (!v || PQgetisnull(res, row, column))
- return SQLEntry();
+ return SQL::Field();
- return SQLEntry(std::string(v, PQgetlength(res, row, column)));
+ return SQL::Field(std::string(v, PQgetlength(res, row, column)));
}
- bool GetRow(SQLEntries& result) CXX11_OVERRIDE
+ bool GetRow(SQL::Row& result) CXX11_OVERRIDE
{
if (currentrow >= PQntuples(res))
return false;
@@ -141,7 +141,7 @@ class PgSQLresult : public SQLResult
/** SQLConn represents one SQL session.
*/
-class SQLConn : public SQLProvider, public EventHandler
+class SQLConn : public SQL::Provider, public EventHandler
{
public:
reference<ConfigTag> conf; /* The <database> entry */
@@ -151,7 +151,7 @@ class SQLConn : public SQLProvider, public EventHandler
QueueItem qinprog; /* If there is currently a query in progress */
SQLConn(Module* Creator, ConfigTag* tag)
- : SQLProvider(Creator, "SQL/" + tag->getString("id")), conf(tag), sql(NULL), status(CWRITE), qinprog(NULL, "")
+ : SQL::Provider(Creator, "SQL/" + tag->getString("id")), conf(tag), sql(NULL), status(CWRITE), qinprog(NULL, "")
{
if (!DoConnect())
{
@@ -162,14 +162,14 @@ class SQLConn : public SQLProvider, public EventHandler
CullResult cull() CXX11_OVERRIDE
{
- this->SQLProvider::cull();
+ this->SQL::Provider::cull();
ServerInstance->Modules->DelService(*this);
return this->EventHandler::cull();
}
~SQLConn()
{
- SQLerror err(SQL_BAD_DBID);
+ SQL::Error err(SQL::BAD_DBID);
if (qinprog.c)
{
qinprog.c->OnError(err);
@@ -177,7 +177,7 @@ class SQLConn : public SQLProvider, public EventHandler
}
for(std::deque<QueueItem>::iterator i = queue.begin(); i != queue.end(); i++)
{
- SQLQuery* q = i->c;
+ SQL::Query* q = i->c;
q->OnError(err);
delete q;
}
@@ -320,7 +320,7 @@ restart:
case PGRES_BAD_RESPONSE:
case PGRES_FATAL_ERROR:
{
- SQLerror err(SQL_QREPLY_FAIL, PQresultErrorMessage(result));
+ SQL::Error err(SQL::QREPLY_FAIL, PQresultErrorMessage(result));
qinprog.c->OnError(err);
break;
}
@@ -390,7 +390,7 @@ restart:
}
}
- void submit(SQLQuery *req, const std::string& q) CXX11_OVERRIDE
+ void Submit(SQL::Query *req, const std::string& q) CXX11_OVERRIDE
{
if (qinprog.q.empty())
{
@@ -403,7 +403,7 @@ restart:
}
}
- void submit(SQLQuery *req, const std::string& q, const ParamL& p) CXX11_OVERRIDE
+ void Submit(SQL::Query *req, const std::string& q, const SQL::ParamList& p) CXX11_OVERRIDE
{
std::string res;
unsigned int param = 0;
@@ -425,10 +425,10 @@ restart:
}
}
}
- submit(req, res);
+ Submit(req, res);
}
- void submit(SQLQuery *req, const std::string& q, const ParamM& p) CXX11_OVERRIDE
+ void Submit(SQL::Query *req, const std::string& q, const SQL::ParamMap& p) CXX11_OVERRIDE
{
std::string res;
for(std::string::size_type i = 0; i < q.length(); i++)
@@ -443,7 +443,7 @@ restart:
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())
{
std::string parm = it->second;
@@ -456,7 +456,7 @@ restart:
}
}
}
- submit(req, res);
+ Submit(req, res);
}
void DoQuery(const QueueItem& req)
@@ -464,7 +464,7 @@ restart:
if (status != WREAD && status != WWRITE)
{
// whoops, not connected...
- SQLerror err(SQL_BAD_CONN);
+ SQL::Error err(SQL::BAD_CONN);
req.c->OnError(err);
delete req.c;
return;
@@ -476,7 +476,7 @@ restart:
}
else
{
- SQLerror err(SQL_QSEND_FAIL, PQerrorMessage(sql));
+ SQL::Error err(SQL::QSEND_FAIL, PQerrorMessage(sql));
req.c->OnError(err);
delete req.c;
}
@@ -554,7 +554,7 @@ class ModulePgSQL : public Module
void OnUnloadModule(Module* mod) CXX11_OVERRIDE
{
- SQLerror err(SQL_BAD_DBID);
+ SQL::Error err(SQL::BAD_DBID);
for(ConnMap::iterator i = connections.begin(); i != connections.end(); i++)
{
SQLConn* conn = i->second;
@@ -567,7 +567,7 @@ class ModulePgSQL : public Module
std::deque<QueueItem>::iterator j = conn->queue.begin();
while (j != conn->queue.end())
{
- SQLQuery* q = j->c;
+ SQL::Query* q = j->c;
if (q->creator == mod)
{
q->OnError(err);
diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp
index 5f6cd1ce3..0f596a0f7 100644
--- a/src/modules/extra/m_sqlite3.cpp
+++ b/src/modules/extra/m_sqlite3.cpp
@@ -46,13 +46,13 @@
class SQLConn;
typedef insp::flat_map<std::string, SQLConn*> ConnMap;
-class SQLite3Result : public SQLResult
+class SQLite3Result : public SQL::Result
{
public:
int currentrow;
int rows;
std::vector<std::string> columns;
- std::vector<SQLEntries> fieldlists;
+ std::vector<SQL::Row> fieldlists;
SQLite3Result() : currentrow(0), rows(0)
{
@@ -63,7 +63,7 @@ class SQLite3Result : public SQLResult
return rows;
}
- bool GetRow(SQLEntries& result) CXX11_OVERRIDE
+ bool GetRow(SQL::Row& result) CXX11_OVERRIDE
{
if (currentrow < rows)
{
@@ -84,13 +84,13 @@ class SQLite3Result : public SQLResult
}
};
-class SQLConn : public SQLProvider
+class SQLConn : public SQL::Provider
{
sqlite3* conn;
reference<ConfigTag> 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)
@@ -111,14 +111,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;
}
@@ -140,7 +140,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++;
}
@@ -151,7 +151,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;
}
@@ -159,13 +159,13 @@ class SQLConn : public SQLProvider
sqlite3_finalize(stmt);
}
- void submit(SQLQuery* query, const std::string& q) CXX11_OVERRIDE
+ 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) CXX11_OVERRIDE
+ void Submit(SQL::Query* query, const std::string& q, const SQL::ParamList& p) CXX11_OVERRIDE
{
std::string res;
unsigned int param = 0;
@@ -183,10 +183,10 @@ class SQLConn : public SQLProvider
}
}
}
- submit(query, res);
+ Submit(query, res);
}
- void submit(SQLQuery* query, const std::string& q, const ParamM& p) CXX11_OVERRIDE
+ 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++)
@@ -201,7 +201,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());
@@ -210,7 +210,7 @@ class SQLConn : public SQLProvider
}
}
}
- submit(query, res);
+ Submit(query, res);
}
};