📄 emv_dbfunc.c
字号:
#include "emv_global.h"#include "emv_dbfunc.h"int giDbHandle1 = -1;int giDbHandle2 = -1;int giDbType = -1;/***************************************************************************** * * 获取数据库全局句柄. * * @param 无 * * @return 若成功,返回句柄;否则,返回-1. * *****************************************************************************/int get_db_connection(void){ int iRetCode; int iConfHandle; char sServerType[32]; char sServerName[32]; char sDbName[32]; char sUsername[32]; char sPassword[32]; int iLoginTimeout; char sTmp[32]; int iDbHandle; emv_debug("Begin get_db_handle()..."); iConfHandle=emv_conf_open("db.conf", 0); if(iConfHandle<0){ emv_error("打开配置文件(db.conf)失败."); return -1; }#ifdef EMV2 iRetCode=emv_conf_getvalue(iConfHandle,"","DB_TYPE",sServerType,sizeof(sServerType)); if(iRetCode<0){ emv_error("配置文件(db.conf)中取键(DB_TYPE)的值失败."); emv_conf_close(iConfHandle); return -1; } sServerType[0]=toupper(sServerType[0]); iRetCode=emv_conf_getvalue(iConfHandle,"","SERVER_NAME",sServerName,sizeof(sServerName)); if(iRetCode<0){ emv_error("配置文件(db.conf)中取键(SERVER_NAME)的值失败."); emv_conf_close(iConfHandle); return -1; } iRetCode=emv_conf_getvalue(iConfHandle,"","DB_NAME",sDbName,sizeof(sDbName)); if(iRetCode<0){ emv_error("配置文件(db.conf)中取键(DB_NAME)的值失败."); emv_conf_close(iConfHandle); return -1; } iRetCode=emv_conf_getvalue(iConfHandle,"","USER_NAME",sTmp,sizeof(sTmp)); if(iRetCode<0){ emv_error("配置文件(db.conf)中取键(USER_NAME)的值失败."); emv_conf_close(iConfHandle); return -1; } zm_decrypt(sTmp,sUsername); iRetCode=emv_conf_getvalue(iConfHandle,"","PASSWORD",sTmp,sizeof(sTmp)); if(iRetCode<0){ emv_error("配置文件(db.conf)中取键(PASSWORD)的值失败."); emv_conf_close(iConfHandle); return -1; } zm_decrypt(sTmp,sPassword); iRetCode=emv_conf_getvalue(iConfHandle,"","CONNECT_TIMEOUT",sTmp,sizeof(sTmp)); if(iRetCode<0){ emv_error("配置文件(db.conf)中取键(CONNECT_TIMEOUT)的值失败."); emv_conf_close(iConfHandle); return -1; } iLoginTimeout=atoi(sTmp);#else iRetCode=emv_conf_getvalue(iConfHandle,"","ServerType",sServerType,sizeof(sServerType)); if(iRetCode<0){ emv_error("配置文件(db.conf)中取键(ServerType)的值失败."); emv_conf_close(iConfHandle); return -1; } iRetCode=emv_conf_getvalue(iConfHandle,sServerType,"ServerName",sServerName,sizeof(sServerName)); if(iRetCode<0){ emv_error("配置文件(db.conf)之段(%s)中取键(ServerName)的值失败.", sServerType); emv_conf_close(iConfHandle); return -1; } iRetCode=emv_conf_getvalue(iConfHandle,sServerType,"DbName",sDbName,sizeof(sDbName)); if(iRetCode<0){ emv_error("配置文件(db.conf)之段(%s)中取键(DbName)的值失败.", sServerType); emv_conf_close(iConfHandle); return -1; } iRetCode=emv_conf_getvalue(iConfHandle,sServerType,"Username",sTmp,sizeof(sTmp)); if(iRetCode<0){ emv_error("配置文件(db.conf)之段(%s)中取键(Username)的值失败.", sServerType); emv_conf_close(iConfHandle); return -1; } zm_decrypt(sTmp, sUsername); iRetCode=emv_conf_getvalue(iConfHandle,sServerType,"Password",sTmp,sizeof(sTmp)); if(iRetCode<0){ emv_error("配置文件(db.conf)之段(%s)中取键(Password)的值失败.", sServerType); emv_conf_close(iConfHandle); return -1; } zm_decrypt(sTmp,sPassword); iRetCode=emv_conf_getvalue(iConfHandle,sServerType,"LoginTimeout",sTmp,sizeof(sTmp)); if(iRetCode<0){ emv_error("配置文件(db.conf)之段(%s)中取键(LoginTimeout)的值失败.", sServerType); emv_conf_close(iConfHandle); return -1; } iLoginTimeout=atoi(sTmp);#endif emv_conf_close(iConfHandle); iDbHandle=emv_db_open(sServerType,sServerName,sDbName,sUsername,sPassword,iLoginTimeout); if(iDbHandle<0){ emv_error("打开数据库(%s,%s,%s,%s,%s,%d)失败.", sServerType,sServerName,sDbName,sUsername,sPassword,iLoginTimeout); return -1; } emv_debug("End get_db_handle()."); return iDbHandle;} //end of get_db_handleint emv_db_type(int iDbHandle){ const char *pDbType; int iDbType = DB_TYPE_UNKNOWN; pDbType = get_db_type(iDbHandle); if (!strcasecmp(pDbType, "Oracle")) { iDbType = DB_TYPE_ORACLE; } else if (!strcasecmp(pDbType, "Sybase")) { iDbType = DB_TYPE_SYBASE; } else if (!strcasecmp(pDbType, "MySQL")) { iDbType = DB_TYPE_MYSQL; } return iDbType;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -