📄 clsrecordset.cpp
字号:
iRet = DBT_FIELD_NUM_OVER_STEP;
}
}
else{
iRet = DBT_ERROR_POINTER_NULL;
}
return iRet;
}
/**********************************************************************************
* function name : ClsRecordset::getFieldIndex(char *fieldName, int *iFieldNum)
* function description : get a field index, by Name.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter: fieldName--the field name
* iFieldNum--return the field number
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
***********************************************************************************/
int ClsRecordset::getFieldIndex(const char *fieldName, int *iFieldNum)
{
int i;
int iRet = DATABASE_SUCCESS;
if (iFieldNum != NULL){
for(i = 0; i < m_setcolNum; i++)
{
#ifdef _FORLINUX_
/*compare two strings ignoring case*/
if( 0 == _tstrcasecmp(fieldName, m_setcolName[i]) )
#else
char tempa[DT_MAX_LEN];
char tempb[DT_MAX_LEN];
_tcscpy(tempa, fieldName);
_tcscpy(tempb, m_setcolName[i]);
/*change majuscule to small letter*/
char *tempfieldName = strlwr(tempa);
char *tempstecolname = strlwr(tempb);
/*compare two strings*/
if( 0 == _tcscmp(tempfieldName, tempstecolname) )
#endif
{
*iFieldNum = i;
iRet = DATABASE_SUCCESS;
break;
}
}
if(i == m_setcolNum){
iRet = DBT_FIELDNAME_NOT_EXIST;
}
}
else{
iRet = DBT_ERROR_POINTER_NULL;
}
return iRet;
}
/**************************************************************************
* function name : ClsRecordset::getFieldValue(int fieldnum, void *pResult)
* function description : get a field value, by num.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter: fieldnum--the field num
* pResult--return the field value
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
***************************************************************************/
int ClsRecordset::getFieldValue(int fieldnum, void *pResult)
{
char fp[DT_MAX_LEN];
int iRet = DATABASE_SUCCESS;
if (pResult != NULL){
if((fieldnum >= 0)&&(fieldnum < m_setcolNum)){
#ifdef _FORLINUX_
m_gpointer = (record *)g_list_nth_data(m_dbList, m_pos);
#else
m_gpointer = m_dbvector[m_pos];
#endif
_stprintf(fp, "%s", m_gpointer->pRec[fieldnum] );
if(fp == NULL){
_tcscpy(fp,"");
}
_tcscpy((char*)pResult, fp);
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_FIELD_NUM_OVER_STEP;
}
}
else{
iRet = DBT_ERROR_POINTER_NULL;
}
return iRet;
}
/******************************************************************************
* function name : ClsRecordset::getFieldValue(char *fieldName, void *pResult)
* function description : get a field value, by Name.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter: fieldName--the field name
* pResult--return the field value
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
*******************************************************************************/
int ClsRecordset::getFieldValue(const char *fieldName, void *pResult)
{
int fieldnum;
char fp[DT_MAX_LEN];
int iRet = DATABASE_SUCCESS;
if (pResult != NULL){
iRet = getFieldIndex(fieldName, &fieldnum);
if( DATABASE_SUCCESS == iRet ){
if((fieldnum >= 0)&&(fieldnum < m_setcolNum)){
#ifdef _FORLINUX_
m_gpointer = (record *)g_list_nth_data(m_dbList, m_pos);
#else
m_gpointer = m_dbvector[m_pos];
#endif
_stprintf(fp, "%s", m_gpointer->pRec[fieldnum] );
if(fp == NULL){
_tcscpy(fp, "");
}
_tcscpy((char*)pResult, fp);
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_FIELD_NUM_OVER_STEP;
}
}
}
else{
iRet = DBT_ERROR_POINTER_NULL;
}
return iRet;
}
/*******************************************************************************
* function name : ClsRecordset::getRecordStr(char *sResult, char *sDelim)
* function description : get row info.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter: sResult--return the row info
* sDelim--the delimiter
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
*******************************************************************************/
int ClsRecordset::getRecordStr(char *sResult, char *sDelim)
{
int iFCound;
int i, maxRCount;
char fp[DT_MAX_LEN];
char fp1[DT_MAX_LEN];
int iRet = DATABASE_SUCCESS;
if (sResult != NULL){
_tcscpy(fp, "");
_tcscpy(fp1, "");
iRet = getRecordCount(&maxRCount);
if(DATABASE_SUCCESS == iRet){
if((m_pos >= 0)&&(m_pos < maxRCount)){
#ifdef _FORLINUX_
m_gpointer = (record *)g_list_nth_data(m_dbList, m_pos);
#else
m_gpointer = m_dbvector[m_pos];
#endif
if( DATABASE_SUCCESS == getFieldCount(&iFCound) ){
for(i = 0; i < iFCound-1; i++){
if (i == 0){
_stprintf(fp, "%s%s", m_gpointer->pRec[i] ? m_gpointer->pRec[i] : "NULL", sDelim);
}
else if(i != (iFCound-1)){
_stprintf(fp1, "%s%s", m_gpointer->pRec[i] ? m_gpointer->pRec[i] : "NULL",sDelim);
_tcscat(fp, fp1);
}
}
_stprintf(fp1, "%s\n", m_gpointer->pRec[iFCound-1] ? m_gpointer->pRec[iFCound-1] : "NULL");
_tcscat(fp, fp1);
_tcscpy(sResult, fp);
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_FIELD_COUNT_FAILED;
}
}
else{
iRet = DBT_MPOS_OVER_STEP;
}
}
}
else{
iRet = DBT_ERROR_POINTER_NULL;
}
return iRet;
}
/***********************************************************************
* function name : ClsRecordset::getRecord(char *sResult, char *sDelim)
* function description : get record all info.
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter: sResult--return the record all info
* sDelim--the delimiter
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
*************************************************************************/
int ClsRecordset::getRecord(char *sResult, char *sDelim)
{
int iRCound, iFCound;
int i;
char fp[DT_MAX_LEN];
char fp1[DT_MAX_LEN];
char fp2[DT_MAX_LEN];
int iRet = DATABASE_SUCCESS;
if (sResult != NULL){
_tcscpy(fp, "");
_tcscpy(fp1, "");
_tcscpy(fp2, "");
if( DATABASE_SUCCESS == getRecordCount(&iRCound) ){
if( DATABASE_SUCCESS == getFieldCount(&iFCound) ){
for(int n = 0; n < iRCound; n++){
/************************************************************************
* Bug Modification
* Author : Wang Wen-Peng (itc205008)
* Date : 2006-7-26
* Reason : Local variable fp1 should be initialized in every circle.
************************************************************************/
_tcscpy(fp1, "");
#ifdef _FORLINUX_
m_gpointer = (record *)g_list_nth_data(m_dbList, n);
#else
m_gpointer = m_dbvector[n];
#endif
for(i = 0; i < (iFCound-1); i++){
if (i == 0){
_stprintf(fp1, "%s%s", m_gpointer->pRec[i] ? m_gpointer->pRec[i] : "NULL", sDelim);
}
else if(i != (iFCound-1)){
_stprintf(fp2, "%s%s", m_gpointer->pRec[i] ? m_gpointer->pRec[i] : "NULL",sDelim);
_tcscat(fp1, fp2);
}
}
_stprintf(fp2, "%s\n", m_gpointer->pRec[iFCound-1] ? m_gpointer->pRec[iFCound-1] : "NULL");
_tcscat(fp1, fp2);
_tcscat(fp, fp1);
}
_tcscpy(sResult, fp);
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_FIELD_COUNT_FAILED;
}
}
else{
iRet = DBT_RECORD_COUNT_FAILED;
}
}
else{
iRet = DBT_ERROR_POINTER_NULL;
}
return iRet;
}
/******************************************************************
* function name : ClsRecordset::getErrorMsg(char *sError)
* function description :get the error message of the last action
* finished date: 2004-8-18
* Author : FanZiqiang
* parameter: sError -- pointer to the error message
* retrun value: SAN_SUCCESS--action succeed;other--action failed
* restrained condition: NONE
* side effect: Describe NONE
*******************************************************************/
int ClsRecordset::getErrorMsg(char *sError)
{
int iRet = DATABASE_SUCCESS;
if (sError != NULL){
iRet = DATABASE_SUCCESS;
}
else{
iRet = DBT_ERROR_POINTER_NULL;
}
return iRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -