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;
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;
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;
}
CloseDB();
TDSCONTEXT* cont;
- cont = tds_alloc_context(NULL);
+ cont = tds_alloc_context(this);
cont->msg_handler = HandleMessage;
cont->err_handler = HandleError;
tds_free_socket(sock);
if (conn)
tds_free_connection(conn);
+ login = NULL;
+ sock = NULL;
+ conn = NULL;
}
SQLhost GetConfHost()
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;
}
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;