使用库pkdbapi访问

头文件:pkdbapi/pkdbapi.h

包含库:pkdbapi.lib

示例代码:

#include "pkdbapi/pkdbapi.h"
#define NULLASSTRING(x) x==NULL?"":x
extern CPKLog g_logger;


	CPKDbApi dbApi;
	nRet = dbApi.InitFromConfigFile(");
    if(nRet != 0)
    {
        g_logger.LogMessage(PK_LOGLEVEL_ERROR, "Init Database Failed:%d!(初始化数据库失败), 无法加载系统配置, 程序将无法继续执行,请处理...", nRet);
        dbApi.UnInitialize();
        return -2;
    }



	sprintf(szSql, "SELECT distinct DRV.id as id, DRV.modulename as name, DRV.modulename as modulename,DRV.description \
                   as description, DRV.platform as platform, DRV.enable FROM t_device_driver DRV"); 

    vector<vector<string> > vecRow;
    string strError;
    nRet = pDbApi->SQLExecute(szSql, vecRow, &strError);
    if (nRet != 0)
    {
        g_logger.LogMessage(PK_LOGLEVEL_ERROR, "Query Database failed:%s!(查询数据库失败), error:%s, 无法加载驱动列表, 程序将无法继续执行,请处理...", szSql, strError.c_str());
        return -2;
    }

    // 非禁用和非模拟的设备信息
    for (unsigned int iRow = 0; iRow< vecRow.size(); iRow++)
    {
        vector<string> &row = vecRow[iRow];
        int iCol = 0;
        string strDriverId = NULLASSTRING(row[iCol].c_str());
        iCol++;
        string strDriverName = NULLASSTRING(row[iCol].c_str());
        iCol++;
        string strDriverModuleName = NULLASSTRING(row[iCol].c_str());
        iCol++;
        strDriverName = strDriverModuleName; // 驱动名必须等于模块名,否则后面共享内存会开错误名字导致驱动无法接收到!
        string strDriverDesc = NULLASSTRING(row[iCol].c_str());
        iCol++;
        string strDriverSupportPlatform = NULLASSTRING(row[iCol].c_str());
        iCol++;
    }

     dbApi.UnInitialize()