Sfoglia il codice sorgente

完善导致图片的接口;

sat23 4 anni fa
parent
commit
2e73838173

+ 30 - 10
CTSManager/CTSManager/CTSManager.cpp

@@ -141,18 +141,38 @@ BOOL CCTSManagerApp::InitInstance()
 			db.UpdateSoc(it->name, *it);
 		}*/
 
-		CFile file;
-		BYTE* pImage = NULL;
-		DWORD dwLength = 0;
-		if ( file.Open(_T("D:\\桌面\\logo\\channels\\AccuWeather.png"), CFile::modeRead) )
-		{
-			dwLength = file.GetLength();
-			pImage = new BYTE[dwLength];
-			file.Read(pImage, dwLength);
-			file.Close();
+		if (0) {
+			CFile file;
+			BYTE* pImage = NULL;
+			DWORD dwLength = 0;
+			if (file.Open(_T("D:\\桌面\\logo\\channels\\AccuWeather.png"), CFile::modeRead))
+			{
+				dwLength = file.GetLength();
+				pImage = new BYTE[dwLength];
+				file.Read(pImage, dwLength);
+				file.Close();
+			}
+
+			db.SetBinaryField("update brand set logo = ? where `name`='SCBC'", pImage, dwLength);
+			if (pImage)
+				delete[]pImage;
+			pImage = NULL;
+			dwLength = 0;
 		}
 
-		db.SetBinaryField("update brand set logo = ? where `name`='SCBC'", pImage, dwLength);
+		if (1)
+		{
+			BYTE* pImage = NULL;
+			DWORD dwLength = 0;
+			db.GetBinaryField("select logo from brand where `name`='SCBC';", (void**)&pImage, dwLength);
+
+			CFile file;
+			if (file.Open(_T("D:\\11.png"), CFile::modeCreate | CFile::modeWrite))
+			{
+				file.Write(pImage, dwLength);
+				file.Close();
+			}
+		}
 	}
 #endif
 

+ 65 - 4
CTSManager/CTSManager/Database.cpp

@@ -18,6 +18,7 @@ CDatabase::~CDatabase()
 BOOL CDatabase::SetBinaryField(std::string strCondition, void* pDataIn, int nDataLen)
 {
 	CHECKDB;
+	BOOL bResult = FALSE;
 	MYSQL_STMT* stmt = NULL;
 	stmt = mysql_stmt_init(m_pConn);
 	if (!stmt)
@@ -34,17 +35,77 @@ BOOL CDatabase::SetBinaryField(std::string strCondition, void* pDataIn, int nDat
 		{
 			if (!mysql_stmt_execute(stmt))
 			{
-				return TRUE;
+				bResult = TRUE;
 			}
 		}
 	}
 
-	return FALSE;
+	mysql_stmt_close(stmt);
+
+	return bResult;
 }
 
-BOOL CDatabase::GetBinaryField(std::string strCondition, void** lpDataOut, int& nDataLen)
+BOOL CDatabase::GetBinaryField(std::string strCondition, void** lpDataOut, unsigned long& nDataLen)
 {
-	return 0;
+	CHECKDB;
+	BOOL bResult = FALSE;
+	MYSQL_STMT* stmt = NULL;
+	stmt = mysql_stmt_init(m_pConn);
+	if (!stmt)
+		return FALSE;
+
+	MYSQL_RES* prepare_meta_result;
+	if (!mysql_stmt_prepare(stmt, strCondition.c_str(), strCondition.length()))
+	{
+		if ( !mysql_stmt_execute(stmt) )
+		{
+			/* Fetch result set meta information */
+			prepare_meta_result = mysql_stmt_result_metadata(stmt);
+			if (prepare_meta_result)
+			{
+				/* Get total columns in the query */
+				//int column_count = mysql_num_fields(prepare_meta_result);
+
+				my_bool is_null;
+				my_bool error;
+				MYSQL_BIND bind[1];
+				memset(bind, 0, sizeof(bind));
+
+				bind[0].buffer_type = MYSQL_TYPE_BLOB;
+				bind[0].buffer = 0;
+				bind[0].buffer_length = 0;
+				bind[0].is_null = &is_null;
+				bind[0].length = &nDataLen; // 返回的缓存长度;
+				bind[0].error = &error;
+
+				/* Bind the result buffers */
+				if (!mysql_stmt_bind_result(stmt, bind))
+				{
+					// 由于没有绑定缓冲区指针,第一次返回缓冲区大小;
+					if (mysql_stmt_fetch(stmt))
+					{
+						if (nDataLen > 1)
+						{
+							*lpDataOut = new char[nDataLen];
+							memset(*lpDataOut, 0, nDataLen);
+							bind[0].buffer = *lpDataOut;
+							bind[0].buffer_length = nDataLen;
+							mysql_stmt_fetch_column(stmt, bind, 0, 0);
+							bResult = TRUE;
+						}
+					}
+				}
+
+				/* Free the prepared result metadata */
+				mysql_free_result(prepare_meta_result);
+			}			
+		}
+	}
+
+	/* Close the statement */
+	mysql_stmt_close(stmt);
+
+	return bResult;
 }
 
 BOOL CDatabase::Init(std::string host, std::string user, std::string password, std::string db)

+ 1 - 1
CTSManager/CTSManager/Database.h

@@ -55,7 +55,7 @@ private:
 	}
 public:
 	BOOL SetBinaryField(std::string strCondition, void* pDataIn, int nDataLen);
-	BOOL GetBinaryField(std::string strCondition, void** lpDataOut, int &nDataLen);
+	BOOL GetBinaryField(std::string strCondition, void** lpDataOut, unsigned long &nDataLen);
 
 	// ³õʼ»¯Á¬½Ó;
 	BOOL Init(std::string host, std::string user, std::string password, std::string db);