Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to read the buffer from the SQL's image field type ? [modified]

How to read the buffer from the SQL's image field type ? [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
databasedebugginghelptutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wangningyu
    wrote on last edited by
    #1

    :) I use this way to read the binary buffers from the SQL's image field type. the m_pBuffer's value is 0xFF all the same int the Debug Mode / Watch. But I use the SQL Query Analyzer, it can be found. why is it ? the filed info: Version varchar(100) Buffer image(16) the code fragment:

    BOOL CTestDlg::ReadBinary()
    {
    try
    {
    OleInitialize(NULL);
    CString strTemp = _T("");
    CString strDat = _T("");
    CString strVer = _T("");
    char *pBuf = NULL;
    _bstr_t bstrsource = "select * from db_somedatease";

    	m\_pRecordset.CreateInstance("ADODB.Recordset");
    	m\_pRecordset->Open(bstrsource,\_variant\_t((IDispatch\*)m\_pConnection,TRUE),adOpenStatic,adLockOptimistic,adCmdText);
    	m\_pRecordset->MoveFirst();
    	while(VARIANT\_FALSE == m\_pRecordset->adoEOF)
    	{
    		HANDLE		m\_hFile	   = INVALID\_HANDLE\_VALUE;
    		HANDLE		m\_hMapping = INVALID\_HANDLE\_VALUE;
    		DWORD		m\_dwSize   = 0;
    		char		\*m\_pSrc    = NULL;
    		char		\*m\_pBuffer = NULL;
    		\_variant\_t	vtVer = m\_pRecordset->GetCollect("Version");
    		VARIANT		varBLOB;
    
    		// get the file path by version field.
    		strVer = VariantToCString(vtVer);
    		strTemp.Format(\_T("%s\\\\Dat\\\\%s.tmp"),GetExePath(),strVer);
    
    		// get the file size, and then use file mapping.
    		m\_dwSize = m\_pRecordset->GetFields()->GetItem("Buffer")->ActualSize;
    		if (m\_dwSize > 0)
    		{
    			m\_hFile = CreateFile(strTemp,GENERIC\_ALL,FILE\_SHARE\_READ | FILE\_SHARE\_WRITE,NULL,
    				CREATE\_ALWAYS,FILE\_ATTRIBUTE\_NORMAL,NULL);
    			
    			if(m\_hFile == INVALID\_HANDLE\_VALUE)
    			{
    				CString	strError = \_T("");
    				strError.Format(\_T("CreateFile Failed!Error Code: %d"),GetLastError());
    				::MessageBox(NULL,strError,NULL,NULL);
    				return FALSE;
    			}
    			
    			m\_hMapping = CreateFileMapping(m\_hFile,NULL,PAGE\_READWRITE,0,m\_dwSize,NULL);
    			if(m\_hMapping == NULL)
    			{
    				CString	strError = \_T("");
    				strError.Format(\_T("CreateFileMapping Failed!Error Code: %d"),GetLastError());
    				::MessageBox(NULL,strError,NULL,NULL);
    				CloseHandle(m\_hFile);
    				return FALSE;
    			}
    			
    			m\_pSrc = (char \*)MapViewOfFile(m\_hMapping,FILE\_MAP\_ALL\_ACCESS,0,0,0);
    			if(m\_pSrc == NULL)
    			{
    				CString	strError = \_T("");
    				strError.Format(\_T("MapViewOfFile Failed!Error Code: %d"),GetLastError());
    				::MessageBox(NULL,strError,NULL,NULL);
    				CloseHandle(m\_hMapping);
    				CloseHandle(m\_hFile);
    			}
    			memset(m\_pSrc,0xFF,m\_dwSize);
    			VariantInit(&varBLOB);
    			
    			// get the binary file size.
    			varBLOB = m\_pRecordset->GetFields()->Get
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups