Re: How to use CLongBinary
Hello,
The addition of blob field to the database needs extra care to be taken. Actually, internally when a new records is being added the Fields are set to null and the dirty flag is set byt the following functions
SetFieldNull()
SetFieldStatusDirty()
But for the blob field this is not done. So, you need to do it explicitly before the update statement.
Are you able to copy the data to CLongBinary object, if not this also has to be done explicitly by copying the data into the CLongBinary objects.
Hope this solves your problem
bye
Re: How to use CLongBinary
Don't worry!
Try CByteArray, works fine!
CByteArray d;
for(int i=0; i<size;++i)
d.SetAtGrow(i, ch[i]);
ch - source of BLOB data with length=size
Re: How to use CLongBinary
Do you have any samples for me? Please do help on how to store image into database (VC++ 5.0)
Re: How to use CLongBinary
This examples for RDBS Interbase:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// quartzDlg.cpp : implementation file
//
#include "stdafx.h"
#include "quartzDlg.h"
void CQuartzDlg::OnStart()
{
register int i;
int transact = FALSE, failed = FALSE;
CDatabase dbase;
try
{
if(! dbase.Open(NULL, FALSE, FALSE, "ODBC;DSN=quartz;USER=dbclient;"))
return;
}
catch(CDBException *e)
{
e->ReportError();
e->Delete();
return;
}
if(dbase.CanTransact() == FALSE)
{
MessageBox("Á*ç* ä***ûõ *å ïîääåðæèâ*åò òð**ç*êöèè","Ïðåäóïðåæäå*èå",
MB_ICONWARNING);
transact = FALSE;
}
else
{
dbase.BeginTrans();
transact = TRUE;
}
CRefer rec(&dbase);
rec.m_strFilter = _T("TYPE1ID=-1");
try
{
if(! rec.Open(CRecordset::snapshot, _T("[REFER]"),
CRecordset::executeDirect|CRecordset::appendOnly))
return;
}
catch(CDBException *e)
{
e->ReportError();
e->Delete();
return;
}
char buf[1024];
while(f.Read(buf, sizeof(buf)))
{
rec.AddNew();
// Blob ------------------------------------------------------//
for(i = 0; i < sizeof(buf); ++i) //
rec.m_SRC.SetAtGrow(i, (BYTE)(buf[i] & 0xff)); //
//
--------------------------------------------------------------//
try
{
rec.Update();
}
catch(CDBException* e)
{
e->ReportError();
e->Delete();
}
}
...
rec.Close();
dbase.Close();
}
//=========================================================================
class CRefer : public CRecordset
{
public:
CRefer(CDatabase* pDatabase = NULL);
DECLARE_DYNAMIC(CRefer)
// Field/Param Data
//{{AFX_FIELD(CRefer, CRecordset)
CByteArray m_SRC;
//}}AFX_FIELD
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CRefer)
public:
virtual CString GetDefaultSQL(); // Default SQL for Recordset
virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support
//}}AFX_VIRTUAL
};
// Refer.cpp : implementation file
//
#include "stdafx.h"
#include "Refer.h"
/////////////////////////////////////////////////////////////////////////////
// CRefer
IMPLEMENT_DYNAMIC(CRefer, CRecordset)
CRefer::CRefer(CDatabase* pdb)
: CRecordset(pdb)
{
//{{AFX_FIELD_INIT(CRefer)
m_nFields = 1;
//}}AFX_FIELD_INIT
m_nDefaultType = snapshot;
}
CString CRefer::GetDefaultSQL()
{
return _T("[REFER]");
}
void CRefer::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CRefer)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Binary(pFX, _T("[SRC]"), m_SRC, 1024);
//}}AFX_FIELD_MAP
}