Updating RAW Data field in Oracle Database - Urgent

"Rahul Johri" <[email protected]> Thu, 13 Mar 2003 09:39:09
Newsgroups gmane.comp.db.oracle.devel,gmane.spam.detected
Message-ID <LYRIS-1796914-910239-2003.03.13-09.22.04--gcdod-oracle#[email protected]>
Hi,
   I am using Oracle 9i DB Release 2. I have a component developed in VC++ 
which uses ISequentialStream interface to interact with a raw data field 
in the Oracle database to perform varios read/write activities.

When using the same component with SQL 2000 , it works fine.
I am able to add , query record from the Oracle DB  but while updating the 
RAW field , I get an error "IDispatch Error #3105" and the update fails.

Following is the code used:
####################################

class CNHRecType
{
public:
	TCHAR	m_NHType[4];
	LONG	m_NHUID;
	TCHAR	m_NHReference[13];
	DBTIMESTAMP	m_NHDateTimePosted;
	TCHAR	m_NHOpIDPosted[5];
	DBTIMESTAMP	m_NHDateTimeChg;
	TCHAR	m_NHOpIDChg[5];
	ISequentialStream* m_NHData;

	ULONG m_BLOBDATA_LENGTH;
	ULONG m_BLOBDATA_STATUS;

	void Clear() {
		ZeroMemory(&m_NHType,4);
		m_NHUID = 0L;
		ZeroMemory(&m_NHReference,13);
		ZeroMemory(&m_NHDateTimePosted,sizeof(DBTIMESTAMP));
		ZeroMemory(&m_NHOpIDPosted,5);
		ZeroMemory(&m_NHDateTimePosted,sizeof(DBTIMESTAMP));
		ZeroMemory(&m_NHOpIDChg,5);
		m_NHData = NULL;
		m_BLOBDATA_LENGTH = 0;
		m_BLOBDATA_STATUS = DBSTATUS_S_OK;
	}
};



class CAccNHUpdateRec : public CNHRecType
{
public:

	CAccNHUpdateRec() { Clear(); }
	~CAccNHUpdateRec() {}

	DEFINE_COMMAND_EX(CAccNHUpdateRec, 
		L"UPDATE NHeader SET  NHOpIDChg=? , NHData=?  where 
NHUID=? and NHTYPE=?")

	BEGIN_PARAM_MAP(CAccNHUpdateRec)
		COLUMN_ENTRY(1, m_NHOpIDChg)
		BLOB_ENTRY_LENGTH_STATUS(2, IID_ISequentialStream, 
STGM_WRITE, m_NHData, m_BLOBDATA_LENGTH, m_BLOBDATA_STATUS)
		COLUMN_ENTRY(4, m_NHUID)
		COLUMN_ENTRY(5, m_NHType)
	END_PARAM_MAP()

};

NOTESEXTENSION_API int UpdateNotesDetails(long NHUID,TCHAR* NHType,TCHAR* 
NHReference,TCHAR* NHOpIDChg)
{

    HRESULT hRes = ::CoInitialize(NULL);

	HANDLE hFile;
	DWORD	dwCount = 0;
	DWORD	dwBufSize = 0;
	LPBYTE	pBuf ;
	ULONG	ulBytesWritten = 0;
	LONG	lRowsAffected = 0;
	CPBLogger	log;
	char	szBuf[512];

	


	
	CComBSTR	login,access,catalog,datasource,driver;
	IRegistryPtr	spRegistry;
	CDBPropSet	m_dbprop;


    OutputDebugString("Getting Registry Information");
	HRESULT hr = spRegistry.CreateInstance(__uuidof(Registry));
	if ( SUCCEEDED(hr) ) 
	{
		spRegistry->GetParamsEx
(&login,&access,&catalog,&datasource ,&driver);
		//database properties
		m_dbprop.SetGUID(DBPROPSET_DBINIT);
		m_dbprop.AddProperty(DBPROP_AUTH_PASSWORD,access);
		m_dbprop.AddProperty(DBPROP_AUTH_USERID,login);
		m_dbprop.AddProperty(DBPROP_INIT_CATALOG,catalog);
		m_dbprop.AddProperty(DBPROP_INIT_DATASOURCE,datasource);
	        m_dbprop.AddProperty(DBPROP_INIT_OLEDBSERVICES, (long)
DBPROPVAL_OS_ENABLEALL);
		m_dbprop.AddProperty(DBPROP_INIT_LCID, (long)1033);
		m_dbprop.AddProperty(DBPROP_INIT_PROMPT, (short)4);
		m_dbprop.AddProperty(DBPROP_CLIENTCURSOR,true);

		OutputDebugString("*Connection Information*");
		OutputDebugString("");

	}
	else 
	{
		_com_error	err(hr);
		sprintf(szBuf,"spRegistry.CreateInstance() Failed\n");
//		MessageBox(0,szBuf,"Error",MB_OK) ;
		OutputDebugString(szBuf);
		sprintf(szBuf,"\tErrorMessage:%s\n",err.ErrorMessage());
//		MessageBox(0,szBuf,"Error",MB_OK) ;
		OutputDebugString(szBuf);
		sprintf(szBuf,"\tDescription:%S\n",err.Description());
//		MessageBox(0,szBuf,"Error",MB_OK) ;
		OutputDebugString(szBuf);
		OutputDebugString("");
		
	}


	USES_CONVERSION;
	CISSHelper ISSHelper;
    

	CCommand<CAccessor<CAccNHUpdateRec> > cmd;
	CDataSource	ds;
	CSession	sess;

        CString strDrv = "Driver : ";
	strDrv += W2A(driver); 
	strDrv += W2A(login);
	strDrv += W2A(access);
	strDrv += W2A(catalog);
	MessageBox(0,strDrv,"UpdateNotesDetails",MB_OK);
	hr = ds.OpenWithServiceComponents(W2A(driver),&m_dbprop );
	if ( FAILED(hr) )
	{
		MessageBox(0,"Cannot Open 
Connection","UpdateNotesDetails",MB_OK);
		_com_error	err(hr);
		sprintf(szBuf,"\tErrorMessage: %s",err.ErrorMessage());
		MessageBox(0,szBuf,"Error",MB_OK) ;
		sprintf(szBuf,"\tDescription: %S",err.Description());
		MessageBox(0,szBuf,"Error",MB_OK) ;
		sprintf(szBuf,"\thr(0x%X): %s",err.Error(),GetHRDesc(hr));
		MessageBox(0,szBuf,"Error",MB_OK) ;
		return 0;
	}
	else
	{
		MessageBox(0,"Connection 
Opened","UpdateNotesDetails",MB_OK);
	}
		
	hr = sess.Open(ds);
	if ( FAILED(hr) )
	{
		MessageBox(0,"Cannot Open 
Session","UpdateNotesDetails",MB_OK);
		return 0;
	}
	else
	{
		MessageBox(0,"Session Opened","UpdateNotesDetails",MB_OK);
	}
		


	WIN32_FIND_DATA FindFileData;
	HANDLE hFind;
	CContainer	cContainer;
	vector<CContainer> m_vectFiles;
	vector<CContainer>::iterator iter;

    hFind = FindFirstFile("tempfile", &FindFileData);
			lstrcpy
(cContainer.m_szFilename,FindFileData.cFileName); 
			cContainer.m_lUID=NHUID;
			lstrcpy(cContainer.m_szReference,NHReference);
			lstrcpy(cContainer.m_szType,NHType); 
			m_vectFiles.push_back(cContainer);
   FindClose(hFind);

	for (iter = m_vectFiles.begin(); iter != m_vectFiles.end(); 
iter++) 
	{
		MessageBox(0,"Inside Loop","Loop",MB_OK);
		cContainer = *iter;
		hFile = CreateFile
(cContainer.m_szFilename,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_N
ORMAL,NULL);
		if ( hFile == INVALID_HANDLE_VALUE ) {
			MessageBox(0,"No File","UpdateNotesDetails",MB_OK);
			continue;
		}
		CFile myFile( hFile );
		dwBufSize = (DWORD)( myFile.GetLength() );
		pBuf = new BYTE[dwBufSize];
		ZeroMemory(pBuf,dwBufSize);
		myFile.Read(pBuf,dwBufSize);
		myFile.Close();
		hr = ISSHelper.Write(pBuf,dwBufSize,&ulBytesWritten);
		if ( FAILED(hr) ) return 0;
		
		MessageBox(0,(LPCTSTR)pBuf,"UpdateNotesDetails",MB_OK); 


		cmd.Clear();
		cmd.m_NHData =(ISequentialStream*)&ISSHelper;
		lstrcpy(cmd.m_NHOpIDChg,NHOpIDChg);   
		cmd.m_NHUID =NHUID;
		lstrcpy(cmd.m_NHType,NHType);
		//lstrcpy(cmd.m_NHReference,NHReference);
		
		cmd.m_BLOBDATA_LENGTH = ISSHelper.m_ulLength;
		cmd.m_BLOBDATA_STATUS = DBSTATUS_S_OK;
		sess.StartTransaction(ISOLATIONLEVEL_SERIALIZABLE);
		hr = cmd.Open(sess,NULL,&m_dbprop,&lRowsAffected);
		if ( SUCCEEDED(hr) )
		{
			MessageBox(0,"Success","UpdateNotesDetails",MB_OK);
		}
		else
		{
			char szBuf[500];
			_com_error	err(hr);
			sprintf(szBuf,"\tErrorMessage:%
s\n",err.ErrorMessage());
			MessageBox(0,szBuf,"Error Message",MB_OK);  
			sprintf(szBuf,"\tDescription:%S\n",err.Description
());
			MessageBox(0,szBuf,"Error Description",MB_OK);  
			MessageBox
(0,"Unsuccessful","UpdateNotesDetails",MB_OK);
		}
		sess.Commit();
		ISSHelper.Clear();
		delete	[]pBuf;
		cmd.Close();
	}

---
Change your mail options at http://p2p.wrox.com/manager.asp or 
to unsubscribe send a blank email to [email protected].