📄 clsrecordset.cpp
字号:
#include "clsrecordset.h"
#include <stdlib.h>
ClsRecordset::ClsRecordset(ClsDbTools *pDbt)
{
/*get record volume*/
#ifdef _FORLINUX_
m_dbList = pDbt->m_recordList;
#else
m_dbvector = pDbt->m_datavector;
#endif
m_gpointer = NULL;
m_setcolName = NULL;
m_pos = 0;
/*get field number*/
m_setcolNum = pDbt->m_colNum;
/*get field name*/
m_setcolName = (char**)_tmalloc(m_setcolNum * (sizeof(char*)));
for (int i = 0; i < m_setcolNum; i++){
m_setcolName[i] = (char*)_tmalloc(128);
_tcscpy(m_setcolName[i], pDbt->m_colName[i]);
}
}
ClsRecordset::~ClsRecordset()
{
/*free record volume*/
#ifdef _FORLINUX_
m_dbList = NULL;
#else
m_dbvector.clear( );
#endif
for (int i = 0; i<m_setcolNum; i++){
_tfree(m_setcolName[i]);
}
_tfree(m_setcolName);
m_setcolName=NULL;
}
/******************************************************************
* function name : ClsRecordset::getPosition(int *iPosition)
* function description : get nonce position's point.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter: iPosition--return nonce row number.
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
******************************************************************/
int ClsRecordset::getPosition(int *iPosition)
{
int iRet = DATABASE_SUCCESS;
int maxRCount; //the record number
if (iPosition != NULL){
iRet = getRecordCount(&maxRCount); //get record number
if(DATABASE_SUCCESS == iRet){
if((m_pos >= 0)&&(m_pos < maxRCount)){
*iPosition = m_pos;
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_MPOS_OVER_STEP;
}
}
}
else{
iRet = DBT_ERROR_POINTER_NULL;
}
return iRet;
}
/******************************************************************
* function name : ClsRecordset::Move(int iRowNum)
* function description : move point ,by row num.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter: iRowNum--row number
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
******************************************************************/
int ClsRecordset::Move(int iRowNum)
{
int iRet = DATABASE_SUCCESS;
int maxRCount;
iRet = getRecordCount(&maxRCount);//get record number
if(DATABASE_SUCCESS == iRet){
if((iRowNum >= 0)&&(iRowNum < maxRCount)){
m_pos = iRowNum;
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_MPOS_OVER_STEP;
}
}
return iRet;
}
/*****************************************************************
* function name : ClsRecordset::MoveFirst()
* function description : move ponit to first.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter:
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
******************************************************************/
int ClsRecordset::MoveFirst()
{
int iRet = DATABASE_SUCCESS;
int maxRCount;
iRet = getRecordCount(&maxRCount);//get record number
if(DATABASE_SUCCESS == iRet){
if(maxRCount > 0){
m_pos = 0;
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_EMPTY_REC;
}
}
return iRet;
}
/*****************************************************************
* function name : ClsRecordset::MoveLast()
* function description : move the point to last
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter:
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
******************************************************************/
int ClsRecordset::MoveLast()
{
int iRet = DATABASE_SUCCESS;
int rcount;
iRet = getRecordCount(&rcount);//get record number
if(DATABASE_SUCCESS == iRet){
if(rcount > 0){
m_pos = (rcount-1);
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_EMPTY_REC;
}
}
return iRet;
}
/******************************************************************
* function name : ClsRecordset::MovePrevious()
* function description : the point move previous.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter:
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
******************************************************************/
int ClsRecordset::MovePrevious()
{
int iRet = DATABASE_SUCCESS;
if( 0 == m_pos ){
iRet = DBT_POSITION_IS_FIRST;
}
else{
int maxRCount;
iRet = getRecordCount(&maxRCount);//get record number
if(DATABASE_SUCCESS == iRet){
if((m_pos > 0)&&(m_pos < maxRCount)){
m_pos--;
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_MPOS_OVER_STEP;
}
}
}
return iRet;
}
/*****************************************************************
* function name : ClsRecordset::moveNext()
* function description : the point move next.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter:
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
*****************************************************************/
int ClsRecordset::MoveNext()
{
int iRet = DATABASE_SUCCESS;
int maxRCount;
iRet = getRecordCount(&maxRCount);//get record number
if(DATABASE_SUCCESS == iRet){
if(m_pos == (maxRCount-1)){
iRet = DBT_POSITION_IS_LAST;
}
else{
if((m_pos >= 0)&&(m_pos < (maxRCount-1))){
m_pos++;
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_MPOS_OVER_STEP;
}
}
}
return iRet;
}
/*****************************************************************
* function name : ClsRecordset::getRecordCount(int *iRecordCount)
* function description : get record count.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter: iRecordCount--return record count
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
******************************************************************/
int ClsRecordset::getRecordCount(int *iRecordCount)
{
int iRet = DATABASE_SUCCESS;
unsigned int guint;
if (iRecordCount != NULL){
//get record number
#ifdef _FORLINUX_
guint = g_list_length(m_dbList);
#else
guint = m_dbvector.size();
#endif
*iRecordCount = guint;
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_ERROR_POINTER_NULL;
}
return iRet;
}
/****************************************************************
* function name : ClsRecordset::getFieldCount(int *iFieldCount)
* function description : get field count.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter: iFieldCount--return field count
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
*****************************************************************/
int ClsRecordset::getFieldCount(int *iFieldCount)
{
int iRet = DATABASE_SUCCESS;
if (iFieldCount != NULL){
*iFieldCount = m_setcolNum;
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_ERROR_POINTER_NULL;
}
return iRet;
}
/****************************************************************************
* function name : ClsRecordset::getFieldName(int fieldnum, char *sFieldName)
* function description : get a field name, by num.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter: fieldnum--the field number;
* sFieldName--return the field name
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
*****************************************************************************/
int ClsRecordset::getFieldName(int fieldnum, char *sFieldName)
{
int iRet = DATABASE_SUCCESS;
if (sFieldName != NULL){
if((fieldnum >= 0)&&(fieldnum < m_setcolNum)){
_tcscpy(sFieldName, m_setcolName[fieldnum]);
iRet = DATABASE_SUCCESS;
}
else{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -