📄 dbintf.cpp
字号:
//////////////////////////////////////////////////////////////////
// History:
// 2002.01.09 Start it. (zoohoo@163.com)
// History:
// 2002.01.18 Fix the bug of update database. (zoohoo@163.com)
// History:
// 2002.04.17 Fix the bug of disconnecting database suddenly. (zoohoo@163.com)
// History:
// 2002.05.20 Change function NowDateTime to
// the member function of CGlobal. (zoohoo@163.com)
//////////////////////////////////////////////////////////////////
#if (_MSC_VER >= 1200)
#pragma warning( disable : 4800 ) // one performance warning off
#pragma warning( disable : 4786 ) // warning about too long debug symbol off
#endif
#include "gk.h"
#include "global.h"
#include "odbcFunc.h"
#include "dogclient.h"
int SaveDB(UserInterface* userInterface);
void ExecUpdateSQL(char * now, char * flag, char * reason,
UserInterface* userInterface, COdbcFunc * odbc);
void reconnectSession();
int GetValueFromODBC()
{
int iRes;
char sql[SQL_SIZE];
UserInterface userInterface;
CGlobal::Instance()->m_connectTime ++;
reconnectSession();
for(int i=0;i<CGlobal::Instance()->m_oradbNum;i++)
{
COdbcFunc * odbc = NULL;
// connect successfully
// catch the exception for disconnect database suddenly
try
{
//alloc mem
odbc = new COdbcFunc();
// connect to database
if(odbc->Connect(CGlobal::Instance()->m_oraList[i].connect,
CGlobal::Instance()->m_oraList[i].username,
CGlobal::Instance()->m_oraList[i].password) == 0)
{
RTRACE(6, "Connect odbc " << CGlobal::Instance()->m_oraList[i].connect << " successfully!");
CGlobal::Instance()->m_disconnectTimes = 0;
//send the success message to watchdog
if(CDogClient::Instance()->Init() == 0)
{
CDogClient::Instance()->SendMsg(e_status,
"Intfdb work normally");
RTRACE(3, "Intfdb work normally");
RTRACE(5, "Send message by socket");
CDogClient::Instance()->Close();
}
//send the success message to watchdog
odbc->SetAutoCommit(true);
strcpy(sql, "select ");
strcat(sql, "ServiceId, ");
strcat(sql, "UserGroup, ");
strcat(sql, "AreaNo, ");
strcat(sql, "TeleNumber, ");
strcat(sql, "OldTeleNum, ");
strcat(sql, "OperateType, ");
strcat(sql, "GenTime, ");
strcat(sql, "SendTime, ");
strcat(sql, "BackTime, ");
strcat(sql, "UserType, ");
strcat(sql, "Password, ");
strcat(sql, "Flag, ");
strcat(sql, "RemainTime, ");
strcat(sql, "ACLICP, ");
strcat(sql, "ACLContent, ");
strcat(sql, "SendRecv, ");
strcat(sql, "AddString ");
strcat(sql, " from UserInterface where Flag = 0 or Flag is NULL");
RTRACE(5, sql);
iRes = odbc->ExecSQL(sql);
if(iRes == 0) // execute successly
{
// get fields value
while(odbc->Next() == 0)
{
memset(&userInterface, 0, sizeof userInterface);
odbc->GetFieldValue(1, userInterface.serviceId, sizeof(userInterface.serviceId));
odbc->GetFieldValue(2, userInterface.userGroup, sizeof(userInterface.userGroup));
odbc->GetFieldValue(3, userInterface.areaNo, sizeof(userInterface.areaNo));
odbc->GetFieldValue(4, userInterface.teleNumber, sizeof(userInterface.teleNumber));
odbc->GetFieldValue(5, userInterface.oldTeleNum, sizeof(userInterface.oldTeleNum));
odbc->GetFieldValue(6, &userInterface.operateType);
odbc->GetFieldValue(7, userInterface.genTime, sizeof(userInterface.genTime));
// odbc->GetFieldValue(8, userInterface.sendTime, sizeof(userInterface.sendTime));
CGlobal::Instance()->NowDateTime(userInterface.sendTime);
// odbc->GetFieldValue(9, userInterface.backTime, sizeof(userInterface.backTime));
odbc->GetFieldValue(10, userInterface.userType, sizeof(userInterface.userType));
odbc->GetFieldValue(11, userInterface.password, sizeof(userInterface.password));
odbc->GetFieldValue(12, &userInterface.flag);
odbc->GetFieldValue(13, &userInterface.remainTime);
odbc->GetFieldValue(14, userInterface.aCLICP, sizeof(userInterface.aCLICP));
odbc->GetFieldValue(15, userInterface.aCLContent, sizeof(userInterface.aCLContent));
odbc->GetFieldValue(16, &userInterface.sendRecv);
odbc->GetFieldValue(17, userInterface.addString, sizeof(userInterface.addString));
// strcpy(userInterface.endTime, "2000-02-29 14:15:16 A");
RTRACE(6, "userInterface.serviceId = " << userInterface.serviceId);
RTRACE(6, "userInterface.userGroup = " << userInterface.userGroup);
RTRACE(6, "userInterface.areaNo = " << userInterface.areaNo);
RTRACE(6, "userInterface.teleNumber = " << userInterface.teleNumber);
RTRACE(6, "userInterface.oldTeleNum = " << userInterface.oldTeleNum);
RTRACE(6, "userInterface.operateType = " << userInterface.operateType);
RTRACE(6, "userInterface.genTime = " << userInterface.genTime);
// RTRACE(6, "userInterface.sendTime = " << userInterface.sendTime);
// RTRACE(6, "userInterface.backTime = " << userInterface.backTime);
RTRACE(6, "userInterface.userType = " << userInterface.userType);
RTRACE(6, "userInterface.password = " << userInterface.password);
RTRACE(6, "userInterface.flag = " << userInterface.flag);
RTRACE(6, "userInterface.remainTime = " << userInterface.remainTime);
RTRACE(6, "userInterface.aCLICP = " << userInterface.aCLICP);
RTRACE(6, "userInterface.aCLContent = " << userInterface.aCLContent);
RTRACE(6, "userInterface.sendRecv = " << userInterface.sendRecv);
RTRACE(6, "userInterface.addString = " << userInterface.addString);
RTRACE(6, "\n");
int iFlag = SaveDB(&userInterface);
char buffer[GBLEN];
char now[21];
CGlobal::Instance()->NowDateTime(now);
odbc->AddResult(0);
RTRACE(5, "SaveDB = " << iFlag);
switch(iFlag)
{
// operate database successfully
case 0:
{
RTRACE(3, "\n------------------------------Operate database successfully------------------------------\n");
ExecUpdateSQL(now, "1", "NULL", &userInterface, odbc);
/*
strcpy(sql, "update UserInterface set ");
strcat(sql, "Flag = 1, BackTime = '");
strcat(sql, now);
strcat(sql, "' where AreaNo = '");
strcat(sql, userInterface.areaNo);
strcat(sql, "' and TeleNumber = '");
strcat(sql, userInterface.teleNumber);
strcat(sql, "' and (Flag = 0 or Flag = NULL)");
RTRACE(5, sql);
odbc->ExecSQL(sql, 0); */
break;
}
// operate type not exists
case -2:
{
RTRACE(3, "\n------------------------------Operate type not exists------------------------------\n");
sprintf(buffer, "%s%d", "OperateType = ", userInterface.operateType);
ExecUpdateSQL(now, "2", buffer, &userInterface, odbc);
/*
strcpy(sql, "update UserInterface set ");
strcat(sql, "Flag = 2, BackTime = '");
strcat(sql, now);
strcat(sql, "', AddString = 'OperateType = ");
sprintf(tmp, "%d", userInterface.operateType);
strcat(sql, tmp);
strcat(sql, "'");
strcat(sql, " where AreaNo = '");
strcat(sql, userInterface.areaNo);
strcat(sql, "' and TeleNumber = '");
strcat(sql, userInterface.teleNumber);
strcat(sql, "' and (Flag = 0 or Flag = NULL)");
RTRACE(5, sql);
odbc->ExecSQL(sql, 0); */
break;
}
// UserType not exists
case -3:
{
RTRACE(3, "\n------------------------------User type not exists------------------------------\n");
sprintf(buffer, "UserType=%s", userInterface.userType);
ExecUpdateSQL(now, "2", buffer, &userInterface, odbc);
/*
strcpy(sql, "update UserInterface set ");
strcat(sql, "Flag = 2, BackTime = '");
strcat(sql, now);
strcat(sql, "', AddString = 'UserType = ");
strcat(sql, userInterface.userType);
strcat(sql, "'");
strcat(sql, " where AreaNo = '");
strcat(sql, userInterface.areaNo);
strcat(sql, "' and TeleNumber = '");
strcat(sql, userInterface.teleNumber);
strcat(sql, "' and (Flag = 0 or Flag = NULL)");
RTRACE(5, sql);
odbc->ExecSQL(sql, 0); */
break;
}
// Change telephone number error
case -4:
{
RTRACE(3, "\n------------------------------Change telephone number error------------------------------\n");
strcpy(buffer, "Change telephone number error");
ExecUpdateSQL(now, "2", buffer, &userInterface, odbc);
break;
}
// Change telephone number error
case -5:
{
RTRACE(3, "\n------------------------------Change telephone number error------------------------------\n");
strcpy(buffer, "Change telephone number error");
ExecUpdateSQL(now, "2", buffer, &userInterface, odbc);
break;
}
// User Group not exist
case -6:
{
RTRACE(3, "\n------------------------------User group not exist------------------------------\n");
strcpy(buffer, "User group not exist");
ExecUpdateSQL(now, "2", buffer, &userInterface, odbc);
break;
}
case -7:
{
RTRACE(3, "\n------------------------------Telephone number exists------------------------------\n");
strcpy(buffer, "Telephone number exists");
ExecUpdateSQL(now, "2", buffer, &userInterface, odbc);
break;
}
case -9:
{
RTRACE(3, "\n------------------------------Rollback failed------------------------------\n");
strcpy(buffer, "Rollback failed");
ExecUpdateSQL(now, "2", buffer, &userInterface, odbc);
break;
}
case -10:
{
RTRACE(3, "\n------------------------------User not exist------------------------------\n");
strcpy(buffer, "User not exist");
ExecUpdateSQL(now, "2", buffer, &userInterface, odbc);
break;
}
case -11:
{
RTRACE(3, "\n------------------------------User's status is wrong------------------------------\n");
strcpy(buffer, "The status of user is wrong");
ExecUpdateSQL(now, "2", buffer, &userInterface, odbc);
break;
}
case -12:
{
RTRACE(3, "\n------------------------------Rollback user's status is wrong------------------------------\n");
strcpy(buffer, "Rollback error. The status of user is wrong");
ExecUpdateSQL(now, "2", buffer, &userInterface, odbc);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -