|
-
April 22nd, 1999, 09:31 AM
#1
How to use CLongBinary
Hi,
We are trying to write a BLOB (LOB) column in a database via ODBC. In the RecordSet we have bound that column to a CLongBinary object but we have problems using it. After inserting a new record in the database, the field of that column appears always NULL.
Does anyone know whats the problem?
Thanks
-
April 22nd, 1999, 04:48 PM
#2
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
-
June 24th, 1999, 08:41 AM
#3
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
-
August 4th, 1999, 02:27 AM
#4
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)
Regards,
Ramkrishna Pawar
-
August 10th, 1999, 12:37 AM
#5
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: oFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CRefer)
pFX->SetFieldType(CFieldExchange: utputColumn);
RFX_Binary(pFX, _T("[SRC]"), m_SRC, 1024);
//}}AFX_FIELD_MAP
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|