Posted on 2010-11-03 11:56
S.l.e!ep.¢% 阅读(1407)
评论(0) 编辑 收藏 引用 所属分类:
FastDB
没有什么说的,以下是常用的功能代码.
#include "fastdb.h"
#include <stdio.h>
USE_FASTDB_NAMESPACE
const int nRecords = 100000;
const int arraySize = 100;
class RecordUser {
public:
char const* szName;
char const* szEmail;
TYPE_DESCRIPTOR(((KEY(szName, INDEXED)), KEY(szEmail, HASHED)));
};
dbDatabase db;
REGISTER_IN(RecordUser,&db);
int main( int argc , char* argv[] )
{
int n;
if(db.open("Users")){
RecordUser rec;
char szName[32];
char szEmail[32];
for(int i=0;i<20;i++)
{
sprintf(szName,"name%00000008d",i);
rec.szName = szName;
sprintf(szEmail,"email%d",i);
rec.szEmail = szEmail;
insert(rec);
}
db.commit();
dbCursor<RecordUser> cursor1;
dbQuery sql1,sql2;
sql1 = "szName=",szName;
sql2 = "order by szName desc";
sprintf(szName,"name%00000008d",5);
//cursor1.selectByKey(char const* key, void const* value);
n = cursor1.select(sql1,dbCursorForUpdate);
if(n>0)
{
do{
printf("szName=%s szEmail=%s id=%d\r\n",cursor1->szName,cursor1->szEmail,cursor1.currentId());
cursor1->szEmail="bluker@sohu.com";
cursor1.update();
} while (cursor1.next());
}
//cursor1.removeAll();
//cursor1.remove(); //删除当前记录
//cursor1.removeAllSelected();//删除选择的记录
printf("\r\n");
//cursor1.setSelectionLimit(1000);//cursor1.unsetSelectionLimit();
n = cursor1.select(sql2,dbCursorViewOnly);
if(n>0)
{
do{
printf("szName=%s szEmail=%s id=%d\r\n",cursor1->szName,cursor1->szEmail,cursor1.currentId());
} while (cursor1.next());
}
}
return 0;
}