/*#include <stdlib.h> #include <stdbool.h> #include <stdint.h> */ int main(int argc, char **argv){ TCHDB *hdb; char *key, *value; /* create the object */ hdb = tchdbnew(); /* open the database */ if(!tchdbopen(hdb, "teloon.hdb", HDBOWRITER|HDBOTRUNC)){ fprintf(stderr, "open error\n"); } /* store records */ if(!tchdbput2(hdb, "foo", "hop") || !tchdbput2(hdb, "barz", "step") || !tchdbput2(hdb, "ssss", "jump")){ fprintf(stderr, "put error\n"); } /* retrieve records */ value = tchdbget2(hdb, "foo"); if(value){ printf("%s\n", value); free(value); } else { fprintf(stderr, "get error\n"); } /* traverse records */ tchdbiterinit(hdb); while((key = tchdbiternext2(hdb)) != NULL){ value = tchdbget2(hdb, key); if(value){ printf("%s:%s\n", key, value); free(value); } free(key); } tchdbiterinit(hdb); while((key = tchdbiternext2(hdb)) != NULL){ value = tchdbget2(hdb, key); if(value){ printf("%s:%s\n", key, value); free(value); } free(key); } /* close the database */ if(!tchdbclose(hdb)){ fprintf(stderr, "close error\n"); } /* delete the object */ tchdbdel(hdb); return 0; }
int main(int argc, char *argv[]) { int rc; char *val; char str[30]; bool ret; uint64_t id; uint64_t re; unsigned int num; TCHDB *loong_info; char username[] = "lijinxing"; // id = 1210519264165944251LL; memset(&str, 0, sizeof(str)); id = ident_key(); snprintf(str, sizeof(str), "%llu", id); num = strhash(str); printf("num = %u\r\nmod = %u\r\nstr = %s\r\n", num, num % 10, str); unlink("test.db"); loong_info = tchdbnew(); if(!tchdbopen(loong_info, "test.db", HDBOWRITER | HDBOCREAT)) { rc = tchdbecode(loong_info); printf("loong_info.db open error: %s\r\n", tchdberrmsg(rc)); return 0; } if(!tchdbput(loong_info, username, strlen(username), str, strlen(str))) { rc = tchdbecode(loong_info); printf("loong_user error: %s\r\n", tchdberrmsg(rc)); } if(!tchdbput(loong_info, (char *)&(id), sizeof(uint64_t), str, strlen(str))) { rc = tchdbecode(loong_info); printf("loong_user error: %s\r\n", tchdberrmsg(rc)); } val = tchdbget2(loong_info, username); if(val == NULL) { printf("ûÕÒµ½\r\n"); } else { printf("val = %s\r\n", val); free(val); } if(!tchdbput(loong_info, username, strlen(username), "Àî½õÐÇ", strlen("Àî½õÐÇ"))) { rc = tchdbecode(loong_info); printf("loong_user error: %s\r\n", tchdberrmsg(rc)); } val = tchdbget2(loong_info, username); if(val == NULL) { printf("ûÕÒµ½\r\n"); } else { printf("val = %s\r\n", val); free(val); } /* ret = tchdbout(loong_info, (char *)&(id), sizeof(uint64_t)); if(ret) { printf("uint64_tɾ³ý³É¹¦\r\n"); } else { printf("uint64_tɾ³ýʧ°Ü\r\n"); } val = tchdbget(loong_info, (char *)&(id), sizeof(uint64_t), &rc); if(val == NULL) { printf("id ûÕÒµ½\r\n"); } else { printf("id val = %s\r\n", val); free(val); } ret = tchdbout(loong_info, username, strlen(username)); if(ret) { printf("stringɾ³ý³É¹¦\r\n"); } else { printf("stringɾ³ýʧ°Ü\r\n"); } val = tchdbget2(loong_info, username); if(val == NULL) { printf("ûÕÒµ½\r\n"); } else { printf("val = %s\r\n", val); free(val); } */ tchdbclose(loong_info); tchdbdel(loong_info); Test_out(); // fetch_user_info("1220582278313757000"); return 0; }