Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ylmbtm committed Sep 11, 2021
1 parent 5a51ea0 commit 890e514
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 47 deletions.
40 changes: 16 additions & 24 deletions Server/Src/ServerEngine/DBInterface/DBConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ CDBConnection::~CDBConnection( void )
BOOL CDBConnection::Init()
{
mysql_library_init( 0, NULL, NULL );
mysql_thread_init();

return TRUE;
}

BOOL CDBConnection::Uninit()
{
mysql_thread_end();
mysql_library_end();
return TRUE;
}
Expand Down Expand Up @@ -141,22 +139,19 @@ BOOL CDBConnection::Execute(CDBStoredProcedure* pDBStoredProcedure)
m_nErrno = mysql_errno(m_pMySql);
m_strError = mysql_error(m_pMySql);

CLog::GetInstancePtr()->LogError("ExecuteWrite1 Failed [mysql_stmt_execute], ErrorNo:%d, ErrorMsg:%s, StmtErrNo:%d, StmtErrStr:%s",
m_nErrno, m_strError.c_str(),
mysql_stmt_errno(pLastStmt),
mysql_stmt_error(pLastStmt));
CLog::GetInstancePtr()->LogError("WriteDB1 Failed, ErrorNo:%d, ErrorMsg:%s", m_nErrno, m_strError.c_str());

if (pDBStoredProcedure->m_pMybind[0].buffer_type == MYSQL_TYPE_LONGLONG)
{
CLog::GetInstancePtr()->LogError("ExecuteWrite1 Failed key:%lld, Sql:[%s]", *(UINT64*)pDBStoredProcedure->m_pMybind[0].buffer, pDBStoredProcedure->m_strSql.c_str());
CLog::GetInstancePtr()->LogError("WriteDB1 Failed key:%lld, Sql:[%s]", *(UINT64*)pDBStoredProcedure->m_pMybind[0].buffer, pDBStoredProcedure->m_strSql.substr(0, 100).c_str());
}
else if (pDBStoredProcedure->m_pMybind[0].buffer_type == MYSQL_TYPE_LONG)
{
CLog::GetInstancePtr()->LogError("ExecuteWrite1 Failed key:%ld, Sql:[%s]", *(UINT32*)pDBStoredProcedure->m_pMybind[0].buffer, pDBStoredProcedure->m_strSql.c_str());
CLog::GetInstancePtr()->LogError("WriteDB1 Failed key:%ld, Sql:[%s]", *(UINT32*)pDBStoredProcedure->m_pMybind[0].buffer, pDBStoredProcedure->m_strSql.substr(0, 100).c_str());
}
else
{
CLog::GetInstancePtr()->LogError("ExecuteWrite1 Failed Sql:[%s]", pDBStoredProcedure->m_strSql.c_str());
CLog::GetInstancePtr()->LogError("WriteDB1 Failed Sql:[%s]", pDBStoredProcedure->m_strSql.substr(0, 100).c_str());
}

mysql_stmt_close(pLastStmt);
Expand All @@ -182,8 +177,8 @@ BOOL CDBConnection::Execute(CDBStoredProcedure* pDBStoredProcedure)
{
m_nErrno = mysql_errno(m_pMySql);
m_strError = mysql_error(m_pMySql);
CLog::GetInstancePtr()->LogError("ExecuteWrite2 Failed [mysql_stmt_init], ErrorNo:%d, ErrorMsg:%s", m_nErrno, m_strError.c_str());
CLog::GetInstancePtr()->LogError("ExecuteWrite2 Failed Sql:[%s]", pDBStoredProcedure->m_strSql.c_str());
CLog::GetInstancePtr()->LogError("WriteDB2 Failed, ErrorNo:%d, ErrorMsg:%s", m_nErrno, m_strError.c_str());
CLog::GetInstancePtr()->LogError("WriteDB2 Failed Sql:[%s]", pDBStoredProcedure->m_strSql.substr(0, 100).c_str());
return FALSE;
}

Expand All @@ -193,8 +188,8 @@ BOOL CDBConnection::Execute(CDBStoredProcedure* pDBStoredProcedure)
m_strError = mysql_error(m_pMySql);
mysql_stmt_close(pMySqlStmt);
pMySqlStmt = NULL;
CLog::GetInstancePtr()->LogError("ExecuteWrite3 Failed [mysql_stmt_prepare], ErrorNo:%d, ErrorMsg:%s", m_nErrno, m_strError.c_str());
CLog::GetInstancePtr()->LogError("ExecuteWrite3 Failed Sql:[%s]", pDBStoredProcedure->m_strSql.c_str());
CLog::GetInstancePtr()->LogError("WriteDB3 Failed, ErrorNo:%d, ErrorMsg:%s", m_nErrno, m_strError.c_str());
CLog::GetInstancePtr()->LogError("WriteDB3 Failed Sql:[%s]", pDBStoredProcedure->m_strSql.substr(0, 100).c_str());
return FALSE;
}

Expand All @@ -207,17 +202,17 @@ BOOL CDBConnection::Execute(CDBStoredProcedure* pDBStoredProcedure)
m_strError = mysql_error(m_pMySql);
mysql_stmt_close(pMySqlStmt);
pMySqlStmt = NULL;
CLog::GetInstancePtr()->LogError("ExecuteWrite4 Failed [mysql_stmt_param_count], ParamCount not equal ProcedureCount!");
CLog::GetInstancePtr()->LogError("ExecuteWrite4 Failed Sql:[%s]", pDBStoredProcedure->m_strSql.c_str());
CLog::GetInstancePtr()->LogError("WriteDB4 Failed, ParamCount not equal ProcedureCount!");
CLog::GetInstancePtr()->LogError("WriteDB4 Failed Sql:[%s]", pDBStoredProcedure->m_strSql.substr(0, 100).c_str());
return FALSE;
}

if (0 != mysql_stmt_bind_param(pMySqlStmt, pDBStoredProcedure->m_pMybind))
{
m_nErrno = mysql_errno(m_pMySql);
m_strError = mysql_error(m_pMySql);
CLog::GetInstancePtr()->LogError("ExecuteWrite5 Failed [mysql_stmt_bind_param], ErrorNo:%d, ErrorMsg:%s", m_nErrno, m_strError.c_str());
CLog::GetInstancePtr()->LogError("ExecuteWrite5 Failed Sql:[%s]", pDBStoredProcedure->m_strSql.c_str());
CLog::GetInstancePtr()->LogError("WriteDB5 Failed, ErrorNo:%d, ErrorMsg:%s", m_nErrno, m_strError.c_str());
CLog::GetInstancePtr()->LogError("WriteDB5 Failed Sql:[%s]", pDBStoredProcedure->m_strSql.substr(0, 100).c_str());
mysql_stmt_close(pMySqlStmt);
pMySqlStmt = NULL;
return FALSE;
Expand All @@ -229,22 +224,19 @@ BOOL CDBConnection::Execute(CDBStoredProcedure* pDBStoredProcedure)
m_strError = mysql_error(m_pMySql);


CLog::GetInstancePtr()->LogError("ExecuteWrite6 Failed [mysql_stmt_execute], ErrorNo:%d, ErrorMsg:%s, StmtErrNo:%d, StmtErrStr:%s",
m_nErrno, m_strError.c_str(),
mysql_stmt_errno(pMySqlStmt),
mysql_stmt_error(pMySqlStmt));
CLog::GetInstancePtr()->LogError("WriteDB6 Failed, ErrorNo:%d, ErrorMsg:%s", m_nErrno, m_strError.c_str());

if (pDBStoredProcedure->m_pMybind[0].buffer_type == MYSQL_TYPE_LONGLONG)
{
CLog::GetInstancePtr()->LogError("ExecuteWrite6 Failed key:%lld, Sql:[%s]", *(UINT64*)pDBStoredProcedure->m_pMybind[0].buffer, pDBStoredProcedure->m_strSql.c_str());
CLog::GetInstancePtr()->LogError("WriteDB6 Failed key:%lld, Sql:[%s]", *(UINT64*)pDBStoredProcedure->m_pMybind[0].buffer, pDBStoredProcedure->m_strSql.substr(0, 100).c_str());
}
else if (pDBStoredProcedure->m_pMybind[0].buffer_type == MYSQL_TYPE_LONG)
{
CLog::GetInstancePtr()->LogError("ExecuteWrite6 Failed key:%ld, Sql:[%s]", *(UINT32*)pDBStoredProcedure->m_pMybind[0].buffer, pDBStoredProcedure->m_strSql.c_str());
CLog::GetInstancePtr()->LogError("WriteDB6 Failed key:%ld, Sql:[%s]", *(UINT32*)pDBStoredProcedure->m_pMybind[0].buffer, pDBStoredProcedure->m_strSql.substr(0, 100).c_str());
}
else
{
CLog::GetInstancePtr()->LogError("ExecuteWrite6 Failed Sql:[%s]", pDBStoredProcedure->m_strSql.c_str());
CLog::GetInstancePtr()->LogError("WriteDB6 Failed Sql:[%s]", pDBStoredProcedure->m_strSql.substr(0, 100).c_str());
}


Expand Down
46 changes: 23 additions & 23 deletions Server/Src/ServerEngine/DBInterface/DBConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,43 @@
class CDBConnection : public IDBInterface
{
public:
CDBConnection( void );
~CDBConnection( void );
CDBConnection( void );
~CDBConnection( void );

BOOL Init();
BOOL Init();

BOOL Uninit();
BOOL Uninit();

BOOL SetConnectParam(char const* szHost, char const* szUser, char const* szPwd, char const* szDb, int nPort, char const* szCharSet = "utf8");
BOOL SetConnectParam(char const* szHost, char const* szUser, char const* szPwd, char const* szDb, int nPort, char const* szCharSet = "utf8mb4");

BOOL Connect(char const* szHost, char const* szUser, char const* szPwd, char const* szDb, int nPort, char const* szCharSet = "utf8");
BOOL Connect(char const* szHost, char const* szUser, char const* szPwd, char const* szDb, int nPort, char const* szCharSet = "utf8mb4");

void Close(void);
void Close(void);

BOOL Execute(CDBStoredProcedure* pDBStoredProcedure);
BOOL Execute(CDBStoredProcedure* pDBStoredProcedure);

BOOL Query(CDBStoredProcedure* pDBStoredProcedure);
BOOL Query(CDBStoredProcedure* pDBStoredProcedure);

BOOL Execute(std::string sql);
BOOL Execute(std::string sql);

BOOL Query(std::string sql);
BOOL Query(std::string sql);

int GetError(void) const;
int GetError(void) const;

BOOL Reconnect(void);
BOOL Reconnect(void);

BOOL Ping();
BOOL Ping();

private:
MYSQL* m_pMySql;
std::string m_strHost;
std::string m_strUser;
std::string m_strPwd;
std::string m_strDB;
int m_nPort;
int m_nErrno;
std::string m_strError;
std::string m_strCharSet;
MYSQL* m_pMySql;
std::string m_strHost;
std::string m_strUser;
std::string m_strPwd;
std::string m_strDB;
int m_nPort;
int m_nErrno;
std::string m_strError;
std::string m_strCharSet;
};

#endif // _SQL_CONN_H_

0 comments on commit 890e514

Please sign in to comment.