📄 dbinterface.cpp
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../inc/dbInterface.hpp"
/**************************************/
#define MAX_TMSI_LEN 4 //the TMSI/P-TMSI is 4 octets long
#define MAX_IMSI_LEN 15 //The IMSI shall not exceed 15 digits
#define MAX_MSISDN_LEN 32
#define MAX_FILENAME_LEN 128 //NOTE
#define MAX_A_SPC_LEN 3 //A接口点码长度BYTE
#define MAX_LR_LEN 3
#define MAX_TIME_LEN 32
#define MAX_FACILITY_LEN 256 //
#define MAX_FN_LEN 32
#define MINIX(a, b) ((a) > (b) ? (b) : (a))
/**************************************/
#ifndef _MULTITHREAD_SUPPORT_
exec sql include sqlca;
#endif
static unsigned long iConnectCnt;
int getConnectName(char* cntBuf)
{
int cnt = ++iConnectCnt;
sprintf(cntBuf, "joyit@zyj%d", cnt);
return cnt;
}
int connectDb(char *uname, char *pwd, char *srv)
{
exec sql begin declare section;
char username[32];
char passwd[32] ;
char servname[32];
char cntname[32];
exec sql end declare section;
if(uname != NULL) strncpy(username, uname, 32);
if(pwd != NULL) strncpy(passwd, pwd, 32);
if(srv != NULL) strncpy(servname, srv, 32);
int id = getConnectName(cntname);
exec sql connect :username identified by :passwd at :cntname using :servname;
if(sqlca.sqlcode < 0)
return sqlca.sqlcode;
else return id;
}
int disconnectDb(int id)
{
if(0 == id)
{
exec sql disconnect all;
}
else
{
exec sql begin declare section;
char cntname[32];
exec sql end declare section;
sprintf(cntname, "joyit@zyj%d", id);
exec sql disconnect :cntname;
}
return sqlca.sqlcode;
}
char* getLastError()
{
static char error[512];
memset(error, 0, 512);
snprintf(error, 512, sqlca.sqlerrm.sqlerrmc);
return error;
}
int WriteRealtimeStatus(RealTimeStatus * pTimeStatus)
{
exec sql begin declare section;
struct _RealTimeStatus
{
CS_CHAR UpdateTime[32];
CS_CHAR NEname[64];
CS_INT NEid;
CS_INT NEavailability;
CS_FLOAT NEcpu;
CS_FLOAT NEram;
CS_FLOAT NEhd;
}TimeStatus;
exec sql end declare section;
memcpy(&TimeStatus,pTimeStatus,sizeof(TimeStatus));
TimeStatus.NEcpu=pTimeStatus->NEcpu;
TimeStatus.NEhd=pTimeStatus->NEhd;
TimeStatus.NEram=pTimeStatus->NEram;
exec sql insert into SapDB.dbo.TBL_RealtimeStatus(UpdateTime,NEname,NEid,NEavailability,NEcpu,NEram,NEhd) values(:TimeStatus.UpdateTime,:TimeStatus.NEname,:TimeStatus.NEid,:TimeStatus.NEavailability,:TimeStatus.NEcpu,:TimeStatus.NEram,:TimeStatus.NEhd);
exec sql commit work;
exec sql update SapDB.dbo.TBL_RealtimeStatus set UpdateTime=:TimeStatus.UpdateTime,NEavailability=:TimeStatus.NEavailability,NEcpu=:TimeStatus.NEcpu,NEram=:TimeStatus.NEram,NEhd=:TimeStatus.NEhd where NEname=:TimeStatus.NEname and NEid=:TimeStatus.NEid;
if(0!=sqlca.sqlcode)
return sqlca.sqlcode;
exec sql commit work;
return sqlca.sqlcode;
}
void CommitWork()
{
exec sql commit work;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -