]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_mssql.cpp
Fix this (thx danieldg and owine)
[user/henk/code/inspircd.git] / src / modules / extra / m_mssql.cpp
index 853651e1c1a6639d2c5736be40800fd9a0175bf8..ab4d2aa717e6af1d90beaafaa33390716e35e149 100644 (file)
@@ -294,6 +294,9 @@ class SQLConn : public classbase
 
        SQLerror Query(SQLrequest &req)
        {
+               if (!sock)
+                       return SQLerror(BAD_CONN, "Socket was NULL, check if SQL server is running.");
+                       
                /* Pointer to the buffer we screw around with substitution in */
                char* query;
 
@@ -368,22 +371,24 @@ class SQLConn : public classbase
                res->dbid = host.id;
                res->query = req.query.q;
 
-               const char* msquery = strdup(req.query.q.data());
+               char* msquery = strdup(req.query.q.data());
                Instance->Logs->Log("m_mssql",DEBUG,"doing Query: %s",msquery);
                if (tds_submit_query(sock, msquery) != TDS_SUCCEED)
                {
                        std::string error("failed to execute: "+std::string(req.query.q.data()));
                        delete[] query;
                        delete res;
+                       free(msquery);
                        return SQLerror(QSEND_FAIL, error);
                }
                delete[] query;
+               free(msquery);
                
                int tds_res;
                while (tds_process_tokens(sock, &tds_res, NULL, TDS_TOKEN_RESULTS) == TDS_SUCCEED)
                {
-                       Instance->Logs->Log("m_mssql",DEBUG,"<******> result type: %d", tds_res);
-                       Instance->Logs->Log("m_mssql",DEBUG,"AFFECTED ROWS: %d", sock->rows_affected);
+                       //Instance->Logs->Log("m_mssql",DEBUG,"<******> result type: %d", tds_res);
+                       //Instance->Logs->Log("m_mssql",DEBUG,"AFFECTED ROWS: %d", sock->rows_affected);
                        switch (tds_res)
                        {
                                case TDS_ROWFMT_RESULT:
@@ -435,8 +440,6 @@ class SQLConn : public classbase
                                        break;
                        }       
                }
-               Instance->Logs->Log("m_mssql",DEBUG,"WEEEEEEEEE 4");
-
                results.push_back(res);
                SendNotify();
                return SQLerror();
@@ -444,17 +447,15 @@ class SQLConn : public classbase
 
        static int HandleMessage(const TDSCONTEXT * pContext, TDSSOCKET * pTdsSocket, TDSMESSAGE * pMessage)
        {
-               /* TODO: FIXME */
-               //Instance->Logs->Log("m_mssql",DEBUG,pMessage->message);
-               //printf("Message: %s\n", pMessage->message);
+               SQLConn* sc = (SQLConn*)pContext->parent;
+               sc->Instance->Logs->Log("m_mssql", DEBUG, "Message for DB with id: %s -> %s", sc->host.id.c_str(), pMessage->message);
                return 0;
        }
 
        static int HandleError(const TDSCONTEXT * pContext, TDSSOCKET * pTdsSocket, TDSMESSAGE * pMessage)
        {
-               /* TODO: FIXME */
-               //Instance->Logs->Log("m_mssql",DEBUG,pMessage->message);
-               //printf("Error: %s\n", pMessage->message);
+               SQLConn* sc = (SQLConn*)pContext->parent;
+               sc->Instance->Logs->Log("m_mssql", DEFAULT, "Error for DB with id: %s -> %s", sc->host.id.c_str(), pMessage->message);
                return 0;
        }
 
@@ -473,7 +474,7 @@ class SQLConn : public classbase
                CloseDB();
 
                TDSCONTEXT* cont;
-               cont = tds_alloc_context(NULL);
+               cont = tds_alloc_context(this);
                cont->msg_handler = HandleMessage;
                cont->err_handler = HandleError;
 
@@ -500,6 +501,9 @@ class SQLConn : public classbase
                        tds_free_socket(sock);
                if (conn)
                        tds_free_connection(conn);
+               login = NULL;
+               sock = NULL;
+               conn = NULL;
        }
 
        SQLhost GetConfHost()
@@ -650,7 +654,6 @@ class ModuleMsSQL : public Module
                        host.name       = conf.ReadValue("database", "name", i);
                        host.user       = conf.ReadValue("database", "username", i);
                        host.pass       = conf.ReadValue("database", "password", i);
-                       host.ssl        = conf.ReadFlag("database", "ssl", "0", i);
                        if (h == host)
                                return true;
                }
@@ -672,7 +675,6 @@ class ModuleMsSQL : public Module
                        host.name       = conf.ReadValue("database", "name", i);
                        host.user       = conf.ReadValue("database", "username", i);
                        host.pass       = conf.ReadValue("database", "password", i);
-                       host.ssl        = conf.ReadFlag("database", "ssl", "0", i);
 
                        if (HasHost(host))
                                continue;