📄 dhadofield.cpp
字号:
case DBVT_BOOL:
bval = AsBool();
dwSize=sizeof(bval);
fwrite(&dwSize, 1, sizeof(dwSize), fp);
fwrite(&bval, 1, dwSize, fp);
break;
case DBVT_UCHAR:
cval = AsChar();
dwSize=sizeof(cval);
fwrite(&dwSize, 1, sizeof(dwSize), fp);
fwrite(&cval, 1, dwSize, fp);
break;
case DBVT_SHORT:
sval = AsShort();
dwSize=sizeof(sval);
fwrite(&dwSize, 1, sizeof(dwSize), fp);
fwrite(&sval, 1, dwSize, fp);
break;
case DBVT_LONG:
lval = AsLong();
dwSize=sizeof(lval);
fwrite(&dwSize, 1, sizeof(dwSize), fp);
fwrite(&lval, 1, dwSize, fp);
break;
case DBVT_SINGLE:
fval = AsFloat();
dwSize=sizeof(fval);
fwrite(&dwSize, 1, sizeof(dwSize), fp);
fwrite(&fval, 1, dwSize, fp);
break;
case DBVT_DOUBLE:
dval = AsDouble();
dwSize=sizeof(dval);
fwrite(&dwSize, 1, sizeof(dwSize), fp);
fwrite(&dval, 1, dwSize, fp);
break;
case DBVT_DATE:
tmval = AsDate();
tmstamp.year = tmval.GetYear();
tmstamp.day = tmval.GetDay();
tmstamp.month = tmval.GetMonth();
tmstamp.hour = tmval.GetHour();
tmstamp.minute = tmval.GetMinute();
tmstamp.second = tmval.GetSecond();
if(tmstamp.hour==99 && tmstamp.minute==99 && tmstamp.second==99)
{
dwSize=0;
fwrite(&dwSize, 1, sizeof(dwSize), fp);
}
else
{
dwSize=sizeof(TIMESTAMP_STRUCT);
fwrite(&dwSize, 1, sizeof(dwSize), fp);
fwrite(&tmstamp, 1, dwSize, fp);
}
break;
case DBVT_STRING:
strval = AsString();
dwSize=strval.GetLength();
fwrite(&dwSize, 1, sizeof(dwSize), fp);
fwrite(strval.GetBuffer(0), 1, dwSize, fp);
break;
case DBVT_BINARY:
pbinval = AsBinary();
dwSize=pbinval->m_dwDataLength;
fwrite(&dwSize, 1, sizeof(dwSize), fp);
LPSTR pVal=(LPSTR)GlobalLock(pbinval->m_hData);
fwrite(pVal, 1, dwSize, fp);
GlobalUnlock(pbinval->m_hData);
break;
}
return TRUE;
}
catch(_com_error& e)
{
TRACE1("%s\n", e.Description());
return FALSE;
}
}
DWORD CDHAdoField::DumpToMemory(void *pMem)
{
try
{
DWORD dwSize;
//写入字段类型
//fwrite(&m_dwType, 1, sizeof(m_dwType), fp);
if(IsNull())
{
//写入字段长度
dwSize=0;
return dwSize;
}
bool bval;
unsigned char cval;
short sval;
long lval;
float fval;
double dval;
CString strval;
CLongBinary *pbinval;
COleDateTime tmval;
TIMESTAMP_STRUCT tmstamp;
switch( GetDBVT() )
{
case DBVT_BOOL:
bval = AsBool();
dwSize=sizeof(bval);
memcpy(pMem, &bval,dwSize);
break;
case DBVT_UCHAR:
cval = AsChar();
dwSize=sizeof(cval);
memcpy(pMem, &cval,dwSize);
break;
case DBVT_SHORT:
sval = AsShort();
dwSize=sizeof(sval);
memcpy(pMem, &sval,dwSize);
break;
case DBVT_LONG:
lval = AsLong();
dwSize=sizeof(lval);
memcpy(pMem, &lval,dwSize);
break;
case DBVT_SINGLE:
fval = AsFloat();
dwSize=sizeof(fval);
memcpy(pMem, &fval,dwSize);
break;
case DBVT_DOUBLE:
dval = AsDouble();
dwSize=sizeof(dval);
memcpy(pMem, &dval,dwSize);
break;
case DBVT_DATE:
tmval = AsDate();
tmstamp.year = tmval.GetYear();
tmstamp.day = tmval.GetDay();
tmstamp.month = tmval.GetMonth();
tmstamp.hour = tmval.GetHour();
tmstamp.minute = tmval.GetMinute();
tmstamp.second = tmval.GetSecond();
if(tmstamp.hour==99 && tmstamp.minute==99 && tmstamp.second==99)
{
dwSize=0;
}
else
{
dwSize=sizeof(TIMESTAMP_STRUCT);
memcpy(pMem, &tmstamp,dwSize);
}
break;
case DBVT_STRING:
strval = AsString();
dwSize=strval.GetLength();
memcpy(pMem, strval.GetBuffer(0),dwSize);
break;
case DBVT_BINARY:
pbinval = AsBinary();
dwSize=pbinval->m_dwDataLength;
LPSTR pVal=(LPSTR)GlobalLock(pbinval->m_hData);
memcpy(pMem, pVal,dwSize);
GlobalUnlock(pbinval->m_hData);
break;
}
return dwSize;
}
catch(_com_error& e)
{
TRACE1("%s\n", e.Description());
return 0;
}
}
DWORD CDHAdoField::GetDumpLength()
{
try
{
DWORD dwSize;
//写入字段类型
//fwrite(&m_dwType, 1, sizeof(m_dwType), fp);
if(IsNull())
{
//写入字段长度
dwSize=0;
return dwSize;
}
CString strval;
CLongBinary *pbinval;
COleDateTime tmval;
TIMESTAMP_STRUCT tmstamp;
switch( GetDBVT() )
{
case DBVT_BOOL:
dwSize=sizeof(bool);
break;
case DBVT_UCHAR:
dwSize=sizeof(unsigned char);
break;
case DBVT_SHORT:
dwSize=sizeof(short);
break;
case DBVT_LONG:
dwSize=sizeof(long);
break;
case DBVT_SINGLE:
dwSize=sizeof(float);
break;
case DBVT_DOUBLE:
dwSize=sizeof(double);
break;
case DBVT_DATE:
tmval = AsDate();
tmstamp.year = tmval.GetYear();
tmstamp.day = tmval.GetDay();
tmstamp.month = tmval.GetMonth();
tmstamp.hour = tmval.GetHour();
tmstamp.minute = tmval.GetMinute();
tmstamp.second = tmval.GetSecond();
if(tmstamp.hour==99 && tmstamp.minute==99 && tmstamp.second==99)
{
dwSize=0;
}
else
{
dwSize=sizeof(TIMESTAMP_STRUCT);
}
break;
case DBVT_STRING:
strval = AsString();
dwSize=strval.GetLength();
break;
case DBVT_BINARY:
pbinval = AsBinary();
dwSize=pbinval->m_dwDataLength;
break;
}
return dwSize;
}
catch(_com_error& e)
{
TRACE1("%s\n", e.Description());
return 0;
}
}
CDHAdoField& CDHAdoField::operator =( const bool bVal )
{
try
{
unsigned char cval = (bVal) ? 'T' : 'F';
short sval = (bVal) ? 1 : 0;
switch( GetDBVT() ) {
case DBVT_NULL:
// Undefined data type
ASSERT( FALSE );
case DBVT_BOOL:
m_FieldPtr->PutValue(bVal);
return *this;
case DBVT_UCHAR:
m_FieldPtr->PutValue(cval);
return *this;
case DBVT_SHORT:
m_FieldPtr->PutValue(sval);
return *this;
case DBVT_LONG:
m_FieldPtr->PutValue((long)sval);
return *this;
case DBVT_SINGLE:
m_FieldPtr->PutValue((float)((bVal) ? 1.0 : 0.0));
return *this;
case DBVT_DOUBLE:
m_FieldPtr->PutValue((double)((bVal) ? 1.0 : 0.0));
return *this;
case DBVT_DATE:
// Cannot convert to datetime
ASSERT( FALSE );
return *this;
case DBVT_STRING:
m_FieldPtr->PutValue(_bstr_t((bVal) ? "T" : "F")) ;
return *this;
case DBVT_BINARY:
// CRecordset does not support writing to CLongBinary fields
ASSERT( FALSE );
return *this;
}
// Undefined data type
ASSERT( FALSE );
return *this;
}
catch(_com_error& e)
{
TRACE1("%s\n", e.Description());
return *this;
}
}
CDHAdoField& CDHAdoField::operator =( const unsigned char chVal )
{
try
{
switch( GetDBVT() ) {
case DBVT_NULL:
// Undefined data type
ASSERT( FALSE );
case DBVT_BOOL:
m_FieldPtr->PutValue((chVal == 'T' || chVal == '1'));
return *this;
case DBVT_UCHAR:
m_FieldPtr->PutValue((unsigned char)chVal);
return *this;
case DBVT_SHORT:
m_FieldPtr->PutValue((short)chVal);
return *this;
case DBVT_LONG:
m_FieldPtr->PutValue((long)chVal);
return *this;
case DBVT_SINGLE:
m_FieldPtr->PutValue((float)chVal);
return *this;
case DBVT_DOUBLE:
m_FieldPtr->PutValue((double)chVal);
return *this;
case DBVT_DATE:
// Cannot convert to datetime
ASSERT( FALSE );
return *this;
case DBVT_STRING:
m_FieldPtr->PutValue(chVal);
return *this;
case DBVT_BINARY:
// CRecordset does not support writing to CLongBinary fields
ASSERT( FALSE );
return *this;
}
// Undefined data type
ASSERT( FALSE );
return *this;
}
catch(_com_error& e)
{
TRACE1("%s\n", e.Description());
return *this;
}
}
CDHAdoField& CDHAdoField::operator =( const short sVal )
{
try
{
CString str;
switch( GetDBVT() ) {
case DBVT_NULL:
// Undefined data type
ASSERT( FALSE );
case DBVT_BOOL:
m_FieldPtr->PutValue((sVal != 0));
return *this;
case DBVT_UCHAR:
m_FieldPtr->PutValue((unsigned char)sVal);
return *this;
case DBVT_SHORT:
m_FieldPtr->PutValue((short)sVal);
return *this;
case DBVT_LONG:
m_FieldPtr->PutValue((long)sVal);
return *this;
case DBVT_SINGLE:
m_FieldPtr->PutValue((float)sVal);
return *this;
case DBVT_DOUBLE:
m_FieldPtr->PutValue((double)sVal);
return *this;
case DBVT_DATE:
ASSERT( FALSE );
return *this;
case DBVT_STRING:
str.Format( "%d", sVal );
m_FieldPtr->PutValue(_bstr_t(str));
return *this;
case DBVT_BINARY:
// CRecordset does not support writing to CLongBinary fields
ASSERT( FALSE );
return *this;
}
// Undefined data type
ASSERT( FALSE );
return *this;
}
catch(_com_error& e)
{
TRACE1("%s\n", e.Description());
return *this;
}
}
CDHAdoField& CDHAdoField::operator =( const int iVal )
{
try
{
CString str;
switch( GetDBVT() ) {
case DBVT_NULL:
// Undefined data type
ASSERT( FALSE );
case DBVT_BOOL:
m_FieldPtr->PutValue((iVal != 0));
return *this;
case DBVT_UCHAR:
m_FieldPtr->PutValue((unsigned char)iVal);
return *this;
case DBVT_SHORT:
m_FieldPtr->PutValue((short)iVal);
return *this;
case DBVT_LONG:
m_FieldPtr->PutValue((long)iVal);
return *this;
case DBVT_SINGLE:
m_FieldPtr->PutValue((float)iVal);
return *this;
case DBVT_DOUBLE:
m_FieldPtr->PutValue((double)iVal);
return *this;
case DBVT_DATE:
ASSERT( FALSE );
return *this;
case DBVT_STRING:
str.Format( "%d", iVal );
m_FieldPtr->PutValue(_bstr_t(str));
return *this;
case DBVT_BINARY:
// CRecordset does not support writing to CLongBinary fields
ASSERT( FALSE );
return *this;
}
// Undefined data type
ASSERT( FALSE );
return *this;
}
catch(_com_error& e)
{
TRACE1("%s\n", e.Description());
return *this;
}
}
CDHAdoField& CDHAdoField::operator =( const long lVal )
{
try
{
CString str;
switch( GetDBVT() ) {
case DBVT_NULL:
// Undefined data type
ASSERT( FALSE );
case DBVT_BOOL:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -