diff options
| author | 2006-04-30 17:19:09 +0000 | |
|---|---|---|
| committer | 2006-04-30 17:19:09 +0000 | |
| commit | a3115dc8b811971304ea39c8c89bf6e18c33e955 (patch) | |
| tree | ff0afd7182f3d34304c6df8e2e0383595ca9f979 /src/modules/extra/m_sql.cpp | |
| parent | Fixes for cygwin. (diff) | |
Merge of peaveydk's diff (at last)
git-svn-id: http://svn.inspircd.org/repository/branches/1_0_stable@3919 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/extra/m_sql.cpp')
| -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 515ce792d..e41c90b2f 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); |
