查找數據庫裏的blob字段並保存在文件中

BOOL CtestDlg::AnalysisFileContent(const CString &strFileName,const CString &strPath)
{
CppSQLite3DB *pDB=new CppSQLite3DB;
pDB->open(ph_convertToUTF8(strPath,CP_ACP1).c_str());
CString strSQL = L"select * from Files ";
//strSQL += strFileName+L"'";
CppSQLite3Query query = pDB->execQuery(ph_convertToUTF8(strSQL).c_str());
for(int i=0;!query.eof()&&i<20;query.nextRow(),i++)
{
int len;
const unsigned char * strContent;
CString strFileName=ph_convertFromUTF8(query.getStringField("fileID")).c_str();
strContent=query.getBlobField("file",len);
try
{
CString s=L"C:\\Users\\zj\\Desktop\\text\\";
s+=strFileName;
CFile  m_outFile;
if (m_outFile.Open(s,CFile::modeCreate|CFile::modeWrite))
{


m_outFile.Write(strContent,len);
}
}
catch (exception & e)
{
return false;
}
catch (CException * e)
{
return false;
}
}

return TRUE;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章