diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-04-30 17:19:00 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-04-30 17:19:00 +0000 |
commit | 79a2655915baad60ad6061aabaa0010922a8a4be (patch) | |
tree | bf55020fda1a7175706659e7f8e9aff3c489b01b /src/modules/extra | |
parent | 317057b622acff5fdda450b42412f64152df5bc8 (diff) |
Merge of peaveydk's diff (at last)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3918 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/extra')
-rw-r--r-- | src/modules/extra/m_sql.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/modules/extra/m_sql.cpp b/src/modules/extra/m_sql.cpp index 1c5da9366..be43910de 100644 --- a/src/modules/extra/m_sql.cpp +++ b/src/modules/extra/m_sql.cpp @@ -64,15 +64,15 @@ 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); } @@ -80,6 +80,8 @@ class SQLConnection // multiple rows. bool QueryResult(std::string query) { + if (!CheckConnection()) return false; + int r = mysql_query(&connection, query.c_str()); if (!r) { @@ -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) { @@ -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); |