adorecordset.cpp
来自「连接orcale数据库」· C++ 代码 · 共 2,069 行 · 第 1/5 页
CPP
2,069 行
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->Fields->GetItem(_variant_t(lIndex))->ActualSize;
}
catch (_com_error e)
{
TRACE(_T("Warning: GetFieldActualSize 方法发生异常. 错误信息: %ws \n"), CString(LPCTSTR (e.Description())));
return -1;
}
}
long CAdoRecordSet::GetFieldActualSize(LPCTSTR lpszFieldName)
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->Fields->GetItem(_variant_t(lpszFieldName))->ActualSize;
}
catch (_com_error e)
{
TRACE(_T("Warning: GetFieldActualSize 方法发生异常. 错误信息: %ws \n"), CString(LPCTSTR (e.Description())));
return -1;
}
}
/*========================================================================
returns: 返回下列值之一. 相应的 OLE DB 类型标识符在下表的说明栏的括
号中给出.
[常量] [说明]
---------------------------------------------------------
adArray 与其他类型一起加入逻辑 OR 以指示该数据是那种类型的
安全数组 (DBTYPE_ARRAY).
adBigInt 8 字节带符号的整数 (DBTYPE_I8).
adBinary 二进制值 (DBTYPE_BYTES).
adBoolean 布尔型值 (DBTYPE_BOOL).
adByRef 与其他类型一起加入逻辑 OR 以指示该数据是其他类型数
据的指针 (DBTYPE_BYREF).
adBSTR 以空结尾的字符串 (Unicode) (DBTYPE_BSTR).
adChar 字符串值 (DBTYPE_STR).
adCurrency 货币值 (DBTYPE_CY).货币数字的小数点位置固定、小数
点右侧有四位数字.该值保存为 8 字节范围为10,000 的带符
号整型值.
adDate 日期值 (DBTYPE_DATE).日期按双精度型数值来保存, 数
字全部表示从 1899 年 12 月 30 开始的日期数.小数部分是
一天当中的片段时间.
adDBDate 日期值 (yyyymmdd) (DBTYPE_DBDATE).
adDBTime 时间值 (hhmmss) (DBTYPE_DBTIME).
adDBTimeStamp 时间戳 (yyyymmddhhmmss 加 10 亿分之一的小数)(DBTYPE_DBTIMESTAMP).
adDecimal 具有固定精度和范围的精确数字值 (DBTYPE_DECIMAL).
adDouble 双精度浮点值 (DBTYPE_R8).
adEmpty 未指定值 (DBTYPE_EMPTY).
adError 32 - 位错误代码 (DBTYPE_ERROR).
adGUID 全局唯一的标识符 (GUID) (DBTYPE_GUID).
adIDispatch OLE 对象上 Idispatch 接口的指针 (DBTYPE_IDISPATCH).
adInteger 4 字节的带符号整型 (DBTYPE_I4).
adIUnknown OLE 对象上 IUnknown 接口的指针 (DBTYPE_IUNKNOWN).
adLongVarBinary 长二进制值.
adLongVarChar 长字符串值.
adLongVarWChar 以空结尾的长字符串值.
adNumeric 具有固定精度和范围的精确数字值 (DBTYPE_NUMERIC).
adSingle 单精度浮点值 (DBTYPE_R4).
adSmallInt 2 字节带符号整型 (DBTYPE_I2).
adTinyInt 1 字节带符号整型 (DBTYPE_I1).
adUnsignedBigInt 8 字节不带符号整型 (DBTYPE_UI8).
adUnsignedInt 4 字节不带符号整型 (DBTYPE_UI4).
adUnsignedSmallInt 2 字节不带符号整型 (DBTYPE_UI2).
adUnsignedTinyInt 1 字节不带符号整型 (DBTYPE_UI1).
adUserDefined 用户定义的变量 (DBTYPE_UDT).
adVarBinary 二进制值.
adVarChar 字符串值.
adVariant 自动变体型 (DBTYPE_VARIANT).
adVector 与其他类型一起加入逻辑 OR 中, 指示数据是 DBVECTOR
结构(由 OLE DB 定义).该结构含有元素的计数和其他类型
(DBTYPE_VECTOR) 数据的指针.
adVarWChar 以空结尾的 Unicode 字符串.
adWChar 以空结尾的 Unicode 字符串 (DBTYPE_WSTR).
----------------------------------------------------------
Remarks: 返回指定字段的数据类型.
==========================================================================*/
DataTypeEnum CAdoRecordSet::GetFieldType(long lIndex)
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->Fields->GetItem(_variant_t(lIndex))->GetType();
}
catch (_com_error e)
{
TRACE(_T("Warning: GetField 方法发生异常. 错误信息: %ws \n"), CString(LPCTSTR (e.Description())));
return adEmpty;
}
}
DataTypeEnum CAdoRecordSet::GetFieldType(LPCTSTR lpszFieldName)
{
ASSERT(m_pRecordset != NULL);
try
{
return m_pRecordset->Fields->GetItem(_variant_t(lpszFieldName))->GetType();
}
catch (_com_error e)
{
TRACE(_T("Warning: GetField发生异常. 错误信息: %ws \n"), CString(LPCTSTR (e.Description())));
return adEmpty;
}
}
BOOL CAdoRecordSet::IsFieldNull(LPCTSTR lpFieldName)
{
try
{
_variant_t vt = m_pRecordset->Fields->GetItem(lpFieldName)->Value;
return (vt.vt == VT_NULL);
}
catch (_com_error e)
{
TRACE(_T("Warning: IsFieldNull 方法发生异常. 错误信息: %ws \n"), CString(LPCTSTR (e.Description())));
return FALSE;
}
}
BOOL CAdoRecordSet::IsFieldNull(long index)
{
try
{
_variant_t vt = m_pRecordset->Fields->GetItem(_variant_t(index))->Value;
return (vt.vt == VT_NULL);
}
catch (_com_error e)
{
TRACE(_T("Warning: IsFieldNull 方法发生异常. 错误信息: %ws \n"), CString(LPCTSTR (e.Description())));
return FALSE;
}
}
/*========================================================================
Name: 取得指定列的字段对象的指针.
==========================================================================*/
FieldPtr CAdoRecordSet::GetField(long lIndex)
{
try
{
return GetFields()->GetItem(_variant_t(lIndex));
}
catch (_com_error e)
{
TRACE(_T("Warning: GetField发生异常. 错误信息: %ws \n"), CString(LPCTSTR (e.Description())));
return NULL;
}
}
FieldPtr CAdoRecordSet::GetField(LPCTSTR lpszFieldName)
{
try
{
return GetFields()->GetItem(_variant_t(lpszFieldName));
}
catch (_com_error e)
{
TRACE(_T("Warning: GetField发生异常. 错误信息: %ws \n"), CString(LPCTSTR (e.Description())));
return NULL;
}
}
/*########################################################################
------------------------------------------------
设置字段的值
------------------------------------------------
########################################################################*/
BOOL CAdoRecordSet::PutCollect(long index, const _variant_t &value)
{
ASSERT(m_pRecordset != NULL);
ASSERT(index < GetFieldsCount());
try
{
if (m_pRecordset != NULL)
{
m_pRecordset->PutCollect(_variant_t(index), value);
return TRUE;
}
}
catch (_com_error e)
{
TRACE(_T("Warning: PutCollect 方法发生异常. 错误信息: %ws \n"), CString(LPCTSTR (e.Description())));
return FALSE;
}
return FALSE;
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const _variant_t &value)
{
ASSERT(m_pRecordset != NULL);
try
{
if (m_pRecordset != NULL)
{
m_pRecordset->put_Collect(_variant_t(strFieldName), value);
return TRUE;
}
}
catch (_com_error e)
{
return FALSE;
TRACE(_T("Warning: PutCollect 方法发生异常. 错误信息: %ws \n"), CString(LPCTSTR (e.Description())));
}
return FALSE;
}
BOOL CAdoRecordSet::PutCollect(long index, const bool &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adBoolean)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(index, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const bool &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adBoolean)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(strFieldName, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(long index, const BYTE &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adUnsignedTinyInt)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(index, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const BYTE &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adUnsignedTinyInt)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(strFieldName, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(long index, const short &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adSmallInt)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(index, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const short &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adSmallInt)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(strFieldName, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(long index, const int &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adInteger)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(index, _variant_t(long(value)));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const int &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adInteger)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(strFieldName, _variant_t(long(value)));
}
BOOL CAdoRecordSet::PutCollect(long index, const long &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adBigInt)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(index, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const long &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adBigInt)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(strFieldName, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(long index, const DWORD &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adUnsignedBigInt)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
_variant_t vt;
vt.vt = VT_UI4;
vt.ulVal = value;
return PutCollect(index, vt);
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const DWORD &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adUnsignedBigInt)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
_variant_t vt;
vt.vt = VT_UI4;
vt.ulVal = value;
return PutCollect(strFieldName, vt);
}
BOOL CAdoRecordSet::PutCollect(long index, const float &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adSingle)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(index, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const float &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adSingle)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(strFieldName, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(long index, const double &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(index) != adDouble)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(index, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const double &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if (GetFieldType(strFieldName) != adDouble)
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
#endif
return PutCollect(strFieldName, _variant_t(value));
}
BOOL CAdoRecordSet::PutCollect(long index, const COleDateTime &value)
{
ASSERT(m_pRecordset != NULL);
#ifdef _DEBUG
if ( GetFieldType(index) != adDate
&& GetFieldType(index) != adDBDate
&& GetFieldType(index) != adDBTime
&& GetFieldType(index) != adDBTimeStamp)
{
TRACE(_T("Warning: 你要存贮的字段与变量的数据类型不符; \n"));
}
#endif
_variant_t vt;
vt.vt = VT_DATE;
vt.date = value;
return PutCollect(index, vt);
}
BOOL CAdoRecordSet::PutCollect(LPCTSTR strFieldName, const COleDateTime &value)
{
ASSERT(m_pRecordset != NULL);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?