|
@@ -3,6 +3,7 @@
|
|
|
|
|
|
#define CHECKDB if (m_pConn == NULL || !m_bConnected) return FALSE
|
|
|
|
|
|
+char* CDatabase::pImage = NULL;
|
|
|
CDatabase::CDatabase():m_pConn(NULL), m_pError(NULL), m_bConnected(FALSE)
|
|
|
{
|
|
|
m_pConn = mysql_init(NULL);
|
|
@@ -14,6 +15,29 @@ CDatabase::~CDatabase()
|
|
|
mysql_library_end();
|
|
|
}
|
|
|
|
|
|
+BOOL CDatabase::SetBinaryField(std::string strCondition, void* pDataIn, int nDataLen)
|
|
|
+{
|
|
|
+ CHECKDB;
|
|
|
+ MYSQL_STMT* stmt = NULL;
|
|
|
+ if (!mysql_stmt_prepare(stmt, strCondition.c_str(), strCondition.length()))
|
|
|
+ {
|
|
|
+ MYSQL_BIND bind;
|
|
|
+ memset(&bind, 0, sizeof(MYSQL_BIND));
|
|
|
+ bind.buffer_type = MYSQL_TYPE_BLOB;
|
|
|
+ (*bind.length) = nDataLen;
|
|
|
+ memcpy(bind.buffer, pDataIn, nDataLen);
|
|
|
+ if (!mysql_stmt_bind_param(stmt, (MYSQL_BIND*)&bind))
|
|
|
+ {
|
|
|
+ if (!mysql_stmt_execute(stmt))
|
|
|
+ {
|
|
|
+ return TRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return FALSE;
|
|
|
+}
|
|
|
+
|
|
|
BOOL CDatabase::Init(std::string host, std::string user, std::string password, std::string db)
|
|
|
{
|
|
|
if (!m_pConn)
|
|
@@ -156,6 +180,221 @@ BOOL CDatabase::QueryProvider(std::vector<STProvider>& vtProvider)
|
|
|
return TRUE;
|
|
|
}
|
|
|
|
|
|
+BOOL CDatabase::InserSoc(const STSOC& soc)
|
|
|
+{
|
|
|
+ CHECKDB;
|
|
|
+#if 0
|
|
|
+ TCHAR szSql[MAX_PATH] = { 0 };
|
|
|
+ _stprintf_s(szSql, INSER_SOC, soc.name.c_str(), soc.provider.c_str(), soc.note.c_str());
|
|
|
+ if (0 != mysql_query(m_pConn, szSql)) {
|
|
|
+#ifdef _DEBUG
|
|
|
+ TRACE1(_T("InserSoc error=%s\n"), m_pError ? m_pError : "");
|
|
|
+#endif
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
+#else
|
|
|
+ MYSQL_STMT* stmt;
|
|
|
+ MYSQL_BIND bind[3];
|
|
|
+ TCHAR szQuery[MAX_PATH] = { 0 };
|
|
|
+ strcpy_s(szQuery, _T("INSERT INTO soc(name, provider, note) VALUES(?,?,?);"));
|
|
|
+ //初始化stmt
|
|
|
+ stmt = mysql_stmt_init(m_pConn);
|
|
|
+ //预处理语句
|
|
|
+ mysql_stmt_prepare(stmt, szQuery, strlen(szQuery));
|
|
|
+ //初始化参数
|
|
|
+ bind[0].buffer_type = MYSQL_TYPE_VARCHAR;
|
|
|
+ bind[0].buffer = (void*)soc.name.c_str();
|
|
|
+ bind[0].is_null = 0;
|
|
|
+ *bind[0].length = soc.name.size();
|
|
|
+
|
|
|
+ bind[1].buffer_type = MYSQL_TYPE_VARCHAR;
|
|
|
+ bind[1].buffer = (void*)soc.provider.c_str();
|
|
|
+ bind[1].is_null = 0;
|
|
|
+ *bind[1].length = soc.provider.size();
|
|
|
+
|
|
|
+ bind[2].buffer_type = MYSQL_TYPE_VARCHAR;
|
|
|
+ bind[2].buffer = (void*)soc.note.c_str();
|
|
|
+ bind[2].is_null = 0;
|
|
|
+ *bind[2].length = soc.note.size();
|
|
|
+
|
|
|
+ //绑定参数123
|
|
|
+ mysql_stmt_bind_param(stmt, bind);
|
|
|
+ //执行预处理mysql语句
|
|
|
+ if (0 != mysql_stmt_execute(stmt))
|
|
|
+ {
|
|
|
+#ifdef _DEBUG
|
|
|
+ TRACE1(_T("InserSoc error=%s\n"), m_pError ? m_pError : "");
|
|
|
+#endif
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+BOOL CDatabase::InserSoc(std::string name, std::string provider, std::string note)
|
|
|
+{
|
|
|
+ CHECKDB;
|
|
|
+#if 0
|
|
|
+ TCHAR szSql[MAX_PATH] = { 0 };
|
|
|
+ _stprintf_s(szSql, INSER_SOC, name.c_str(), provider.c_str(), note.c_str());
|
|
|
+ if (0 != mysql_query(m_pConn, szSql)) {
|
|
|
+#ifdef _DEBUG
|
|
|
+ TRACE1(_T("InserSoc error=%s\n"), m_pError ? m_pError : "");
|
|
|
+#endif
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
+#else
|
|
|
+ //https://dev.mysql.com/doc/c-api/5.6/en/mysql-stmt-execute.html
|
|
|
+ MYSQL_STMT* stmt;
|
|
|
+ MYSQL_BIND bind[3];
|
|
|
+ TCHAR szQuery[MAX_PATH] = { 0 };
|
|
|
+ strcpy_s(szQuery, _T("INSERT INTO soc(name, provider, note) VALUES(?,?,?);"));
|
|
|
+ //初始化stmt
|
|
|
+ stmt = mysql_stmt_init(m_pConn);
|
|
|
+ if (!stmt)
|
|
|
+ return FALSE;
|
|
|
+
|
|
|
+ //预处理语句
|
|
|
+ if (mysql_stmt_prepare(stmt, szQuery, strlen(szQuery)))
|
|
|
+ return FALSE;
|
|
|
+
|
|
|
+ // 字段数量是否匹配;
|
|
|
+ int param_count = mysql_stmt_param_count(stmt);
|
|
|
+ if (param_count != 3)
|
|
|
+ return FALSE;
|
|
|
+
|
|
|
+ //初始化参数
|
|
|
+ memset(bind, 0, sizeof(bind));
|
|
|
+ bind[0].buffer_type = MYSQL_TYPE_VARCHAR;
|
|
|
+ bind[0].buffer = (void*)name.c_str();
|
|
|
+ bind[0].buffer_length = name.size();
|
|
|
+ bind[0].is_null = 0;
|
|
|
+ //bind[0].length = (unsigned long*)name.size();
|
|
|
+ bind[0].length = 0;
|
|
|
+
|
|
|
+ bind[1].buffer_type = MYSQL_TYPE_VARCHAR;
|
|
|
+ bind[1].buffer = (void*)provider.c_str();
|
|
|
+ bind[1].buffer_length = provider.size();
|
|
|
+ bind[1].is_null = 0;
|
|
|
+ //bind[1].length = (unsigned long*)provider.size();
|
|
|
+ bind[1].length = 0;
|
|
|
+
|
|
|
+ bind[2].buffer_type = MYSQL_TYPE_VARCHAR;
|
|
|
+ bind[2].buffer = (void*)note.c_str();
|
|
|
+ bind[2].buffer_length = note.size();
|
|
|
+ bind[2].is_null = 0;
|
|
|
+ //bind[2].length = (unsigned long*)note.size();
|
|
|
+ bind[2].length = 0;
|
|
|
+
|
|
|
+ //绑定参数123
|
|
|
+ if (0 != mysql_stmt_bind_param(stmt, bind))
|
|
|
+ {
|
|
|
+#ifdef _DEBUG
|
|
|
+ TRACE1(_T("InserSoc error=%s\n"), m_pError ? m_pError : "");
|
|
|
+#endif
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ //执行预处理mysql语句
|
|
|
+ if (0 != mysql_stmt_execute(stmt))
|
|
|
+ {
|
|
|
+#ifdef _DEBUG
|
|
|
+ TRACE1(_T("InserSoc error=%s\n"), m_pError ? m_pError : "");
|
|
|
+#endif
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+BOOL CDatabase::DeleteSoc(std::string name)
|
|
|
+{
|
|
|
+ CHECKDB;
|
|
|
+ TCHAR szSql[MAX_PATH] = { 0 };
|
|
|
+ _stprintf_s(szSql, DEL_SOC, name.c_str());
|
|
|
+ if (0 != mysql_query(m_pConn, szSql)) {
|
|
|
+#ifdef _DEBUG
|
|
|
+ TRACE1(_T("DeleteSoc error=%s\n"), m_pError ? m_pError : "");
|
|
|
+#endif
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
+}
|
|
|
+
|
|
|
+BOOL CDatabase::UpdateSoc(std::string name, const STSOC& soc)
|
|
|
+{
|
|
|
+ CHECKDB;
|
|
|
+ TCHAR szSql[MAX_PATH] = { 0 };
|
|
|
+ _stprintf_s(szSql, MOD_SOC, soc.name.c_str(), soc.provider.c_str(), soc.note.c_str(), name.c_str());
|
|
|
+ if (0 != mysql_query(m_pConn, szSql)) {
|
|
|
+#ifdef _DEBUG
|
|
|
+ TRACE1(_T("UpdateSoc error=%s\n"), m_pError ? m_pError : "");
|
|
|
+#endif
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
+}
|
|
|
+
|
|
|
+BOOL CDatabase::QuerySoc(std::vector<STSOC>& vtSoc)
|
|
|
+{
|
|
|
+ CHECKDB;
|
|
|
+ if (0 != mysql_query(m_pConn, QUERY_SOC)) {
|
|
|
+#ifdef _DEBUG
|
|
|
+ TRACE1(_T("QuerySoc error=%s\n"), m_pError ? m_pError : "");
|
|
|
+#endif
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取表数据;
|
|
|
+ MYSQL_RES* pData = mysql_store_result(m_pConn);
|
|
|
+ if (pData == NULL) {
|
|
|
+#ifdef _DEBUG
|
|
|
+ TRACE1(_T("QuerySoc error=%s\n"), m_pError ? m_pError : "");
|
|
|
+#endif
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+#ifdef _DEBUG
|
|
|
+ // 统计表字段;
|
|
|
+ unsigned int nLen = mysql_num_fields(pData);
|
|
|
+ // 字段长度是否一致;
|
|
|
+ if (nLen != 3) {
|
|
|
+ mysql_free_result(pData);
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 打印出字段名称;
|
|
|
+ TCHAR szLog[MAX_PATH] = { 0 };
|
|
|
+ for (int i = 0; i < nLen; i++) {
|
|
|
+ _stprintf_s(szLog, _T("字段名称:%s\n"), mysql_fetch_field(pData)->name);
|
|
|
+ OutputDebugString(szLog);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+ // 遍历数据;
|
|
|
+ MYSQL_ROW row;
|
|
|
+ while ((row = mysql_fetch_row(pData)) != NULL) {
|
|
|
+ STSOC soc;
|
|
|
+ soc.name = row[0];
|
|
|
+ soc.provider = row[1];
|
|
|
+ soc.note = row[2];
|
|
|
+ vtSoc.push_back(soc);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 释放内存;
|
|
|
+ mysql_free_result(pData);
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
BOOL CDatabase::InsertBrand(const STBranch& brand)
|
|
|
{
|
|
@@ -206,7 +445,7 @@ BOOL CDatabase::UpdateBrand(std::string name, const STBranch& brand)
|
|
|
{
|
|
|
CHECKDB;
|
|
|
TCHAR szSql[MAX_PATH] = { 0 };
|
|
|
- _stprintf_s(szSql, MOD_BRAND, name.c_str(), brand.name.c_str(), brand.note.c_str());
|
|
|
+ _stprintf_s(szSql, MOD_BRAND, brand.name.c_str(), brand.note.c_str(), name.c_str());
|
|
|
if (0 != mysql_query(m_pConn, szSql)) {
|
|
|
#ifdef _DEBUG
|
|
|
TRACE1(_T("UpdateBrand error=%s\n"), m_pError ? m_pError : "");
|
|
@@ -268,6 +507,20 @@ BOOL CDatabase::QueryBrand(std::vector<STBranch>& vtBrand)
|
|
|
return TRUE;
|
|
|
}
|
|
|
|
|
|
+BOOL CDatabase::ImportLogo(std::string name, std::string file)
|
|
|
+{
|
|
|
+ if (!PathFileExists(file.c_str()))
|
|
|
+ return FALSE;
|
|
|
+
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+BOOL CDatabase::ExportLogo(std::string name, std::string file)
|
|
|
+{
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
BOOL CDatabase::InsertQuarter(const STQuarter& quarter)
|
|
|
{
|
|
|
CHECKDB;
|
|
@@ -317,7 +570,7 @@ BOOL CDatabase::UpdateQuarter(std::string name, const STQuarter& quarter)
|
|
|
{
|
|
|
CHECKDB;
|
|
|
TCHAR szSql[MAX_PATH] = { 0 };
|
|
|
- _stprintf_s(szSql, MOD_QUARTER, name.c_str(), quarter.name.c_str(), quarter.scp.c_str(), quarter.note.c_str());
|
|
|
+ _stprintf_s(szSql, MOD_QUARTER,quarter.name.c_str(), quarter.scp.c_str(), quarter.note.c_str(), name.c_str());
|
|
|
if (0 != mysql_query(m_pConn, szSql)) {
|
|
|
#ifdef _DEBUG
|
|
|
TRACE1(_T("UpdateQuarter error=%s\n"), m_pError ? m_pError : "");
|
|
@@ -429,7 +682,7 @@ BOOL CDatabase::UpdateServer(std::string name, const STServer& Server)
|
|
|
{
|
|
|
CHECKDB;
|
|
|
TCHAR szSql[MAX_PATH] = { 0 };
|
|
|
- _stprintf_s(szSql, MOD_SERVER, name.c_str(), Server.name.c_str(), Server.ip.c_str(), Server.type.c_str(), Server.user.c_str(), Server.password.c_str(), Server.note.c_str());
|
|
|
+ _stprintf_s(szSql, MOD_SERVER, Server.name.c_str(), Server.ip.c_str(), Server.type.c_str(), Server.user.c_str(), Server.password.c_str(), Server.note.c_str(), name.c_str());
|
|
|
if (0 != mysql_query(m_pConn, szSql)) {
|
|
|
#ifdef _DEBUG
|
|
|
TRACE1(_T("UpdateServer error=%s\n"), m_pError ? m_pError : "");
|