Skip to content

Commit

Permalink
Merge of peaveydk's diff (at last)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.inspircd.org/repository/branches/1_0_stable@3919 e03df62e-2008-0410-955e-edbf42e46eb7
  • Loading branch information
braindigitalis committed Apr 30, 2006
1 parent de50731 commit a3115dc
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/modules/extra/m_sql.cpp
Expand Up @@ -64,22 +64,24 @@ class SQLConnection
this->pass = thispass;
this->db = thisdb;
this->id = myid;
unsigned int timeout = 1;
mysql_init(&connection);
mysql_options(&connection,MYSQL_OPT_CONNECT_TIMEOUT,(char*)&timeout);
}

// This method connects to the database using the credentials supplied to the constructor, and returns
// true upon success.
bool Connect()
{
unsigned int timeout = 1;
mysql_init(&connection);
mysql_options(&connection,MYSQL_OPT_CONNECT_TIMEOUT,(char*)&timeout);
return mysql_real_connect(&connection, host.c_str(), user.c_str(), pass.c_str(), db.c_str(), 0, NULL, 0);
}

// This method issues a query that expects multiple rows of results. Use GetRow() and QueryDone() to retrieve
// multiple rows.
bool QueryResult(std::string query)
{
if (!CheckConnection()) return false;

int r = mysql_query(&connection, query.c_str());
if (!r)
{
Expand All @@ -92,6 +94,8 @@ class SQLConnection
// the number of effected rows is returned in the return value.
unsigned long QueryCount(std::string query)
{
if (!CheckConnection()) return 0;

int r = mysql_query(&connection, query.c_str());
if (!r)
{
Expand Down Expand Up @@ -139,11 +143,28 @@ class SQLConnection
if (res)
{
mysql_free_result(res);
res = NULL;
return true;
}
else return false;
}

bool ConnectionLost()
{
if (&connection) {
return (mysql_ping(&connection) != 0);
}
else return false;
}

bool CheckConnection()
{
if (ConnectionLost()) {
return Connect();
}
else return true;
}

std::string GetError()
{
return mysql_error(&connection);
Expand Down

0 comments on commit a3115dc

Please sign in to comment.