AppBuilder中进行直接ODBC API数据库调用访问的基本方法!
2008-09-25 19:27:00 来源:WEB开发网其中,如果cb1、cb2、cb3、cb4、cb5、cb6、cb7、cb8、cb9是接受返回的数据的大小的,如果他们的值等于SQL_NULL_DATA,那么表示此记录的这个字段的值为空。
2、块绑定
CStuffbasicdataQry::CStuffbasicdataQry(CODBCDatabase* pDB) : m_nRowSetSize(1000), m_pDatabase(pDB)
{
m_hstmt = SQL_NULL_HSTMT;
RETCODE ReturnCode = SQLAllocHandle(SQL_HANDLE_STMT, m_pDatabase->GetHDBC(), &m_hstmt);
if (ReturnCode != SQL_SUCCESS)
TRACE("Unable to allocate Statement Handle in CTtttempSetn");
}
CStuffbasicdataQry::~CStuffbasicdataQry()
{
Reset();
if (m_hstmt)
SQLFreeHandle(SQL_HANDLE_STMT, m_hstmt);
}
void CStuffbasicdataQry::Reset()
{
if (m_hstmt)
SQLFreeHandle(SQL_HANDLE_STMT, m_hstmt);
for (int i = 0; i < m_aData.GetSize(); i++)
delete m_aData.GetAt(i);
m_aData.RemoveAll();
}
int CStuffbasicdataQry::Load()
{
CString strSQLString;
//RETCODE ReturnCode;
UDWORD RowsFetched;
UWORD *pRowStatus;
pFF_DB_STUFFBASICDATAQRY_FIELDS pHostData;
ASSERT(m_nRowSetSize > 0);
pRowStatus = new UWORD[m_nRowSetSize];
ASSERT(pRowStatus);
pHostData = new FF_DB_STUFFBASICDATAQRY_FIELDS[m_nRowSetSize];
ASSERT(pHostData);
SQLSetStmtOption(m_hstmt,SQL_BIND_TYPE,sizeof(FF_DB_STUFFBASICDATAQRY_FIELDS));
SQLSetStmtOption(m_hstmt,SQL_CONCURRENCY,SQL_CONCUR_READ_ONLY);
SQLSetStmtOption(m_hstmt,SQL_CURSOR_TYPE,SQL_CURSOR_KEYSET_DRIVEN);
SQLSetStmtOption(m_hstmt,SQL_ROWSET_SIZE,m_nRowSetSize);
strSQLString.Format(
"SELECT * "
" FROM STUFFBASICDATA");
if (SQL_SUCCESS == SQLExecDirect(m_hstmt,(UCHAR*)((LPCTSTR)strSQLString),SQL_NTS))
{
SQLBindCol(m_hstmt,1,SQL_C_CHAR,pHostData[0].m_aStuffID,StuffbasicdataQry_aStuffID_SIZE,&pHostData[0].m_aStuffIDInd);
SQLBindCol(m_hstmt,2,SQL_C_CHAR,pHostData[0].m_aNameCN,StuffbasicdataQry_aNameCN_SIZE,&pHostData[0].m_aNameCNInd);
SQLBindCol(m_hstmt,3,SQL_C_CHAR,pHostData[0].m_aNameEN,StuffbasicdataQry_aNameEN_SIZE,&pHostData[0].m_aNameENInd);
SQLBindCol(m_hstmt,4,SQL_C_CHAR,pHostData[0].m_aEducation,StuffbasicdataQry_aEducation_SIZE,&pHostData[0].m_aEducationInd);
SQLBindCol(m_hstmt,5,SQL_C_CHAR,pHostData[0].m_aGender,StuffbasicdataQry_aGender_SIZE,&pHostData[0].m_aGenderInd);
SQLBindCol(m_hstmt,6,SQL_C_TIMESTAMP,&pHostData[0].m_dWorkDate,0,&pHostData[0].m_dWorkDateInd);
SQLBindCol(m_hstmt,7,SQL_C_CHAR,pHostData[0].m_aDepartment,StuffbasicdataQry_aDepartment_SIZE,&pHostData[0].m_aDepartmentInd);
SQLBindCol(m_hstmt,8,SQL_C_CHAR,pHostData[0].m_aBusiness,StuffbasicdataQry_aBusiness_SIZE,&pHostData[0].m_aBusinessInd);
SQLBindCol(m_hstmt,9,SQL_C_CHAR,pHostData[0].m_aBusinessLevel,StuffbasicdataQry_aBusinessLevel_SIZE,&pHostData[0].m_aBusinessLevelInd);
SQLBindCol(m_hstmt,10,SQL_C_CHAR,pHostData[0].m_aWorkType,StuffbasicdataQry_aWorkType_SIZE,&pHostData[0].m_aWorkTypeInd);
SQLBindCol(m_hstmt,11,SQL_C_TIMESTAMP,&pHostData[0].m_dLeaveWorkDate,0,&pHostData[0].m_dLeaveWorkDateInd);
SQLBindCol(m_hstmt,12,SQL_C_CHAR,pHostData[0].m_aEnageType,StuffbasicdataQry_aEnageType_SIZE,&pHostData[0].m_aEnageTypeInd);
SQLBindCol(m_hstmt,13,SQL_C_TIMESTAMP,&pHostData[0].m_dCreateDocDate,0,&pHostData[0].m_dCreateDocDateInd);
while (SQL_SUCCESS == SQLExtendedFetch(m_hstmt,SQL_FETCH_NEXT,1,&RowsFetched,pRowStatus))
{
for (UINT Count = 0; Count < RowsFetched; Count++)
{
if (pRowStatus[Count] != SQL_ROW_DELETED && pRowStatus[Count] != SQL_ROW_ERROR )
{
pDB_STUFFBASICDATAQRY_FIELDS pData = new DB_STUFFBASICDATAQRY_FIELDS();
ASSERT(pData);
if (pHostData[Count].m_aStuffIDInd == SQL_NULL_DATA)
pData->m_aStuffID = "";
else
pData->m_aStuffID = pHostData[Count].m_aStuffID;
if (pHostData[Count].m_aNameCNInd == SQL_NULL_DATA)
pData->m_aNameCN = "";
else
pData->m_aNameCN = pHostData[Count].m_aNameCN;
if (pHostData[Count].m_aNameENInd == SQL_NULL_DATA)
pData->m_aNameEN = "";
else
pData->m_aNameEN = pHostData[Count].m_aNameEN;
if (pHostData[Count].m_aEducationInd == SQL_NULL_DATA)
pData->m_aEducation = "";
else
pData->m_aEducation = pHostData[Count].m_aEducation;
if (pHostData[Count].m_aGenderInd == SQL_NULL_DATA)
pData->m_aGender = "";
else
pData->m_aGender = pHostData[Count].m_aGender;
pData->m_dWorkDate.SetDateTime(pHostData[Count].m_dWorkDate.year,
pHostData[Count].m_dWorkDate.month,
pHostData[Count].m_dWorkDate.day,
pHostData[Count].m_dWorkDate.hour,
pHostData[Count].m_dWorkDate.minute,
pHostData[Count].m_dWorkDate.second);
if (pHostData[Count].m_aDepartmentInd == SQL_NULL_DATA)
pData->m_aDepartment = "";
else
pData->m_aDepartment = pHostData[Count].m_aDepartment;
if (pHostData[Count].m_aBusinessInd == SQL_NULL_DATA)
pData->m_aBusiness = "";
else
pData->m_aBusiness = pHostData[Count].m_aBusiness;
if (pHostData[Count].m_aBusinessLevelInd == SQL_NULL_DATA)
pData->m_aBusinessLevel = "";
else
pData->m_aBusinessLevel = pHostData[Count].m_aBusinessLevel;
if (pHostData[Count].m_aWorkTypeInd == SQL_NULL_DATA)
pData->m_aWorkType = "";
else
pData->m_aWorkType = pHostData[Count].m_aWorkType;
pData->m_dLeaveWorkDate.SetDateTime(pHostData[Count].m_dLeaveWorkDate.year,
pHostData[Count].m_dLeaveWorkDate.month,
pHostData[Count].m_dLeaveWorkDate.day,
pHostData[Count].m_dLeaveWorkDate.hour,
pHostData[Count].m_dLeaveWorkDate.minute,
pHostData[Count].m_dLeaveWorkDate.second);
if (pHostData[Count].m_aEnageTypeInd == SQL_NULL_DATA)
pData->m_aEnageType = "";
else
pData->m_aEnageType = pHostData[Count].m_aEnageType;
pData->m_dCreateDocDate.SetDateTime(pHostData[Count].m_dCreateDocDate.year,
pHostData[Count].m_dCreateDocDate.month,
pHostData[Count].m_dCreateDocDate.day,
pHostData[Count].m_dCreateDocDate.hour,
pHostData[Count].m_dCreateDocDate.minute,
pHostData[Count].m_dCreateDocDate.second);
m_aData.Add(pData);
}
}
if (RowsFetched < (UINT)m_nRowSetSize)
break;
}
}
delete [] pRowStatus;
delete [] pHostData;
return m_aData.GetSize();
}
Tags:AppBuilder 进行 直接
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接