|
@@ -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)
|