#编译程序 gcc -o historydb historydb.c -ldb #将2013年8月9日的用户记录写入数据库 (程序自动识别新用户入库,跳过老用户) ./historydb -f 20130809.userlist 20130809 #查询guest1985215666654在2013年8月8日有没有访问业务bch2000 ./historydb -s "bch2000 guest1985215666654" 20130808
#include <assert.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <db.h> #include <sys/types.h> #include <getopt.h> #define DATABASE "/work/stat/read/newstat/test/history.db" struct ViewDate { int year; int month; int day; }; struct ViewData { struct ViewDate date; }; void setDate(struct ViewDate *date,char *s) { assert(s != NULL); char tmp[10]={0}; strncpy(tmp,s,4); date->year = atoi(tmp); memset(tmp,0,10); strncpy(tmp,s+4,2); date->month = atoi(tmp); memset(tmp,0,10); strncpy(tmp,s+6,2); date->day = atoi(tmp); //printf("%d - %d - %d ",date->year, date->month, date->day); } int compareViewData(struct ViewData *data , struct ViewData *storedData) { int dataArray [] = {data->date.year, data->date.month, data->date.day}; int storedDataArray [] = {storedData->date.year, storedData->date.month, storedData->date.day}; int i = 0; for(;i<sizeof(dataArray) / sizeof(int); i++) { if(storedDataArray[i] > dataArray[i]) { return 0; } } return 1; } void printViewData(struct ViewData *data) { printf("print view data : %d - %d - %d ",data->date.year, data->date.month, data->date.day); } char *trim(char *s) { int i = strlen(s); for(;i>0;i--) { if(s[i]==' ' || s[i]==' ' || s[i]=='