在SIT实习了20几天,对公司整体架构有个初步而模糊的了解后,我进入了研发部的AAA小组,带我的老师先给了我一堆的文档看,看得人整个晕乎乎的(在学校里可没受过这种罪!)。前几天老师(madeline)叫写一个程序以熟悉cachedb的相关函数,鼓捣了几天,终于于昨天大功告成。以下是我的程序(New0001.cpp):
#include <stdio.h>
#include "cacheapi.h"
#include "cachecursor.h"
#include "cachequery.h"
#include "hdb.h"
int main()
{
int ret = 0;
int TabId=20803;
int IndexId = 0;
int value;
int one = 0;
char *two = NULL;
char *three =NULL;
char *four = NULL;
long long five = 0;
int six = 0;
int seven = 0;
long long eight = 0;
long long nine = 0;
long long ten = 0;
int eleven = 0;
int twelve = 0;
long long thirteen = 0;
long long fourteen = 0;
char *fifteen = NULL;
CacheDBCursor cdb;
ret = cdb.syDbInitLog("my log");
if(ret < 0)
{
printf("初始化日志文件失败!\n");
return -1;
}
ret = cdb.syDbConnect();
if(ret < 0)
{
printf("数据库连接失败!\n");
return -1;
}
/* ret = cdb.syOpenCursor(TabId,IndexId,value);
if(ret < 0)
{
printf("Open cursor failed, table CACHE_FIELD_DIC[%d], ret[%d].\n",TabId, ret);
return -1;
}
ret = cdb.syFetchCursor();
if(ret < 0)
{
printf("Get record failed.Table CACHE_FIELD_DIC[%d], ret[%d].\n",TabId, ret);
return -1;
}*/
ret = cdb.syGetRecord(TabId, IndexId, value);
if(ret<0)
{
printf("Get record failed.Table CACHE_FIELD_DIC[%d],ret[%d].\n",TabId,ret);
return -1;
}
ret = cdb.syGetInt(1,one);
if(ret < 0)
{
printf("get one failed.Table CACHE_FIELD_DIC[%d],Fieldid[1],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetStr(2,two);
if(ret < 0)
{
printf("get two failed.Table CACHE_FIELD_DIC[%d],Fieldid[2],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetStr(3,three);
if(ret < 0)
{
printf("get three failed.Table CACHE_FIELD_DIC[%d],Fieldid[3],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetStr(4,four);
if(ret < 0)
{
printf("get four failed.Table CACHE_FIELD_DIC[%d],Fieldid[4],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetLong(5,five);
if(ret < 0)
{
printf("get five failed.Table CACHE_FIELD_DIC[%d],Fieldid[5],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetInt(6,six);
if(ret < 0)
{
printf("get six failed.Table CACHE_FIELD_DIC[%d],Fieldid[6],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetInt(7,seven);
if(ret < 0)
{
printf("get seven failed.Table CACHE_FIELD_DIC[%d],Fieldid[7],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetLong(8,eight);
if(ret < 0)
{
printf("get eight failed.Table CACHE_FIELD_DIC[%d],Fieldid[8],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetLong(9,nine);
if(ret < 0)
{
printf("get nine failed.Table CACHE_FIELD_DIC[%d],Fieldid[9],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetLong(10,ten);
if(ret < 0)
{
printf("get ten failed.Table CACHE_FIELD_DIC[%d],Fieldid[10],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetInt(11,eleven);
if(ret < 0)
{
printf("get eleven failed.Table CACHE_FIELD_DIC[%d],Fieldid[11],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetInt(12,twelve);
if(ret < 0)
{
printf("get twelve failed.Table CACHE_FIELD_DIC[%d],Fieldid[12],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetLong(13,thirteen);
if(ret < 0)
{
printf("get thirteen failed.Table CACHE_FIELD_DIC[%d],Fieldid[13],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetLong(14,fourteen);
if(ret < 0)
{
printf("get fourteen failed.Table CACHE_FIELD_DIC[%d],Fieldid[14],ret[%d]\n",TabId, ret);
return -1;
}
ret = cdb.syGetStr(15,fifteen);
if(ret < 0)
{
printf("get fifteen failed.Table CACHE_FIELD_DIC[%d],Fieldid[15],ret[%d]\n",TabId, ret);
return -1;
}
printf("打印所有取得的值:\n");
printf("%d %s %s %s %lld\n",one,two,three,four,five);
printf("%d %d %lld %lld %lld\n",six,seven,eight,nine,ten);
printf("%d %d %lld %lld %s\n",eleven,twelve,thirteen,fourteen,fifteen);
ret = cdb.syCloseCursor();
return 0;
}
当然并不是一开始就写成上面那样,也是实验了很多次,出了很多错,最后在madeline的指导帮助下得以完成。将New0001.cpp,makefile以及几个库文件libmdbcore.so,libcachequery.so,libhdb.so上传到服务器,然后在linux终端输入make指令就顺利执行了。
2010年10月14日于青岛