Handle NULL BLOB-s in MFC
I have an old MFC project that I need to expand. For database operations I use a class derived from CRecordSet, and bind Oracle BLOB to CByteArray. When I retrieve a row with null blob, I get an array with size of 1 byte, and value 0xFF. Is there a way to check if a field is actually NULL in da开发者_如何学JAVAtabase? Or is this 0xFF array actually a value denoting a null BLOB?
OK, I found it. The function is CRecordset::IsFieldNull, the parameter is the address of bound CByteArray object, and the function can be only used between Open() and Close(). Something like this:
void CMySet::DoFieldExchange(CFieldExchange* pFX)
{
...
RFX_Binary(pFX, _T("[THE_BLOB]"), m_TheBlob, MAX_BLOB_SIZE);
}
void CMySet::ReadBlob(CByteArray& theBlob, BOOL& isNull)
{
m_strFilter = ...;
Open();
isNull = IsFieldNull(&m_TheBlob);
if (!isNull)
theBlob.Copy(m_TheBlob);
Close();
}
精彩评论