예제 #1
0
파일: tchmgr.c 프로젝트: Fleurer/nanodb
/* perform optimize command */
static int procoptimize(const char *path, int bnum, int apow, int fpow, int opts, int omode,
                        bool df){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
  if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  if(df){
    if(!tchdbdefrag(hdb, INT64_MAX)){
      printerr(hdb);
      err = true;
    }
  } else {
    if(!tchdboptimize(hdb, bnum, apow, fpow, opts)){
      printerr(hdb);
      err = true;
    }
  }
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
예제 #2
0
파일: tchmgr.c 프로젝트: kadoma/fms
/* perform list command */
static int proclist(const char *path, int omode, bool pv, bool px){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbopen(hdb, path, HDBOREADER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  if(!tchdbiterinit(hdb)){
    printerr(hdb);
    err = true;
  }
  TCXSTR *key = tcxstrnew();
  TCXSTR *val = tcxstrnew();
  while(tchdbiternext3(hdb, key, val)){
    printdata(tcxstrptr(key), tcxstrsize(key), px);
    if(pv){
      putchar('\t');
      printdata(tcxstrptr(val), tcxstrsize(val), px);
    }
    putchar('\n');
  }
  tcxstrdel(val);
  tcxstrdel(key);
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
예제 #3
0
파일: tchmgr.c 프로젝트: Fleurer/nanodb
/* perform get command */
static int procget(const char *path, const char *kbuf, int ksiz, int omode, bool px, bool pz){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
  if(!tchdbopen(hdb, path, HDBOREADER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  int vsiz;
  char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
  if(vbuf){
    printdata(vbuf, vsiz, px);
    if(!pz) putchar('\n');
    tcfree(vbuf);
  } else {
    printerr(hdb);
    err = true;
  }
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
예제 #4
0
static mrb_value
hdb_close(mrb_state *mrb, mrb_value self)
{
  hdb_context *context = DATA_PTR(self);

  return mrb_bool_value(tchdbclose(context->hdb));
}
예제 #5
0
파일: dbtest.cpp 프로젝트: teloon/simpleDDD
/*#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;
} 
예제 #6
0
 void close()
 {
    if(bOpen_ && pdb_)
    {
       tchdbclose(pdb_);
       bOpen_ = false;
    }
 }
예제 #7
0
파일: jbhmgr.c 프로젝트: Dean-Jansen/ejdb
/* perform inform command */
static int procinform(const char *path, int omode) {
    TCHDB *hdb = tchdbnew();
    if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
    tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL);
    if (!tchdbopen(hdb, path, HDBOREADER | omode)) {
        printerr(hdb);
        tchdbdel(hdb);
        return 1;
    }
    bool err = false;
    const char *npath = tchdbpath(hdb);
    if (!npath) npath = "(unknown)";
    printf("path: %s\n", npath);
    const char *type = "(unknown)";
    switch (tchdbtype(hdb)) {
        case TCDBTHASH: type = "hash";
            break;
        case TCDBTBTREE: type = "btree";
            break;
        case TCDBTFIXED: type = "fixed";
            break;
        case TCDBTTABLE: type = "table";
            break;
    }
    printf("database type: %s\n", type);
    uint8_t flags = tchdbflags(hdb);
    printf("additional flags:");
    if (flags & HDBFOPEN) printf(" open");
    if (flags & HDBFFATAL) printf(" fatal");
    printf("\n");
    printf("bucket number: %" PRIu64 "\n", (uint64_t) tchdbbnum(hdb));
#ifndef NDEBUG
    if (hdb->cnt_writerec >= 0)
        printf("used bucket number: %" PRId64 "\n", (int64_t) tchdbbnumused(hdb));
#endif
    printf("alignment: %u\n", tchdbalign(hdb));
    printf("free block pool: %u\n", tchdbfbpmax(hdb));
    printf("inode number: %" PRId64 "\n", (int64_t) tchdbinode(hdb));
    char date[48];
    tcdatestrwww(tchdbmtime(hdb), INT_MAX, date);
    printf("modified time: %s\n", date);
    uint8_t opts = tchdbopts(hdb);
    printf("options:");
    if (opts & HDBTLARGE) printf(" large");
    if (opts & HDBTDEFLATE) printf(" deflate");
    if (opts & HDBTBZIP) printf(" bzip");
    if (opts & HDBTTCBS) printf(" tcbs");
    if (opts & HDBTEXCODEC) printf(" excodec");
    printf("\n");
    printf("record number: %" PRIu64 "\n", (uint64_t) tchdbrnum(hdb));
    printf("file size: %" PRIu64 "\n", (uint64_t) tchdbfsiz(hdb));
    if (!tchdbclose(hdb)) {
        if (!err) printerr(hdb);
        err = true;
    }
    tchdbdel(hdb);
    return err ? 1 : 0;
}
예제 #8
0
파일: jbhmgr.c 프로젝트: Dean-Jansen/ejdb
/* perform put command */
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
        int omode, int dmode) {
    TCHDB *hdb = tchdbnew();
    if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
    if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
    if (!tchdbopen(hdb, path, HDBOWRITER | omode)) {
        printerr(hdb);
        tchdbdel(hdb);
        return 1;
    }
    bool err = false;
    int inum;
    double dnum;
    switch (dmode) {
        case -1:
            if (!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(hdb);
                err = true;
            }
            break;
        case 1:
            if (!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(hdb);
                err = true;
            }
            break;
        case 10:
            inum = tchdbaddint(hdb, kbuf, ksiz, tcatoi(vbuf));
            if (inum == INT_MIN) {
                printerr(hdb);
                err = true;
            } else {
                printf("%d\n", inum);
            }
            break;
        case 11:
            dnum = tchdbadddouble(hdb, kbuf, ksiz, tcatof(vbuf));
            if (isnan(dnum)) {
                printerr(hdb);
                err = true;
            } else {
                printf("%.6f\n", dnum);
            }
            break;
        default:
            if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(hdb);
                err = true;
            }
            break;
    }
    if (!tchdbclose(hdb)) {
        if (!err) printerr(hdb);
        err = true;
    }
    tchdbdel(hdb);
    return err ? 1 : 0;
}
예제 #9
0
static bool OpenTokyoDatabase(const char *filename, TCHDB **hdb)
{
    *hdb = tchdbnew();

    if (!tchdbsetmutex(*hdb))
    {
        return false;
    }

    if (!tchdbopen(*hdb, filename, HDBOWRITER | HDBOCREAT))
    {
        return false;
    }

    static int threshold = -1; /* GLOBAL_X */

    if (threshold == -1)
    {
        /** 
           Optimize always if TCDB_OPTIMIZE_PERCENT is equal to 100
           Never optimize if  TCDB_OPTIMIZE_PERCENT is equal to 0
         */
        const char *perc = getenv("TCDB_OPTIMIZE_PERCENT");
        if (perc != NULL)
        {
            /* Environment variable exists */
            char *end;
            long result = strtol(perc, &end, 10);
 
            /* Environment variable is a number and in 0..100 range */
            if (!*end && result >-1 && result < 101)
            {
               threshold = 100 - (int)result;
            }
            else
            {
                /* This corresponds to 1% */
                threshold = 99; 
            }
        }
        else
        {
            /* This corresponds to 1% */
            threshold = 99; 
        }
    }
    if ((threshold != 100) && (threshold == 0 || (int)(rand()%threshold) == 0))
    {
        if (!tchdboptimize(*hdb, -1, -1, -1, false))
        {
            tchdbclose(*hdb);
            return false;
        }
    }

    return true;
}
예제 #10
0
파일: tcfiler.c 프로젝트: wix/tcfiler
void close_db(){
    if(use_cabinet_lib){ 
        tchdbclose(hdb);
        tchdbdel(hdb);
    } else{ 
        tcrdbclose(tdb);
        tcrdbdel(tdb);
    }
}
예제 #11
0
파일: tchmgr.c 프로젝트: Fleurer/nanodb
/* perform list command */
static int proclist(const char *path, int omode, int max, bool pv, bool px, const char *fmstr){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
  if(!tchdbopen(hdb, path, HDBOREADER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  if(fmstr){
    TCLIST *keys = tchdbfwmkeys2(hdb, fmstr, max);
    for(int i = 0; i < tclistnum(keys); i++){
      int ksiz;
      const char *kbuf = tclistval(keys, i, &ksiz);
      printdata(kbuf, ksiz, px);
      if(pv){
        int vsiz;
        char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
        if(vbuf){
          putchar('\t');
          printdata(vbuf, vsiz, px);
          tcfree(vbuf);
        }
      }
      putchar('\n');
    }
    tclistdel(keys);
  } else {
    if(!tchdbiterinit(hdb)){
      printerr(hdb);
      err = true;
    }
    TCXSTR *key = tcxstrnew();
    TCXSTR *val = tcxstrnew();
    int cnt = 0;
    while(tchdbiternext3(hdb, key, val)){
      printdata(tcxstrptr(key), tcxstrsize(key), px);
      if(pv){
        putchar('\t');
        printdata(tcxstrptr(val), tcxstrsize(val), px);
      }
      putchar('\n');
      if(max >= 0 && ++cnt >= max) break;
    }
    tcxstrdel(val);
    tcxstrdel(key);
  }
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
예제 #12
0
static int
_tc_close (mu_dbm_file_t db)
{
  if (db->db_descr)
    {
      TCHDB *hdb = db->db_descr;
      tchdbclose (hdb);
      tchdbdel (hdb);
      db->db_descr = NULL;
    }
  return 0;
}
예제 #13
0
/** 
 *close database 
 */
int CloseDB(tcDatabase hdb)
{
    int ecode;
    if (!tchdbclose((TCHDB*)hdb))
    {
        ecode = tchdbecode((TCHDB*)hdb);
        fprintf(stderr, "close error: %s\n", tchdberrmsg(ecode));
        exit(-1);
    }
    tchdbdel((TCHDB*)hdb);
    return SUCCESS;
}
예제 #14
0
char *get_host_pubkey(char *host) {
	char *key;
	char value[BUFSIZE];
	char *buffer = (char *) malloc(BUFSIZE *sizeof(char));
	char *keyname = NULL;
	char needle[BUFSIZE];
	TCHDB *hdb;
  hdb = tchdbnew();
	int ecode;
	struct addrinfo *result;
	struct addrinfo *res;

	if(tchdbopen(hdb,LASTSEEN_DB,HDBOREADER) != 1){
		printf("%s for database '%s'\n",tchdberrmsg(tchdbecode(hdb)),LASTSEEN_DB);
		return NULL;
	}
	int error = getaddrinfo(host,NULL,NULL,&result);

	for(res = result; res != NULL; res = res->ai_next) {
		inet_ntop(res->ai_family, get_in_addr((struct sockaddr *)res->ai_addr), needle, sizeof(needle));

		tchdbiterinit(hdb);
		while((key = tchdbiternext2(hdb)) != NULL && keyname == NULL){
			if(strspn(key,"k") == 1){
				tchdbget3(hdb, key, strlen(key) + 1, value, BUFSIZE);
				if(strcmp(value,needle) == 0){
					keyname = ++key;
				}
			}
		}
	}
	tchdbclose(hdb);

	if(keyname) {
		sprintf(buffer,"%s/root-%s.pub",PPKEYS,keyname);
		return buffer;
	}else{
		for(res = result; res != NULL; res = res->ai_next) {
			inet_ntop(res->ai_family, get_in_addr((struct sockaddr *)res->ai_addr), needle, sizeof(needle));
			sprintf(buffer,"%s/root-%s.pub",PPKEYS,needle);
			if(file_exist(buffer)){
				return buffer;
			}
		}
	}
	return NULL;
}
예제 #15
0
파일: tchmgr.c 프로젝트: Fleurer/nanodb
/* perform importtsv command */
static int procimporttsv(const char *path, const char *file, int omode, bool sc){
  FILE *ifp = file ? fopen(file, "rb") : stdin;
  if(!ifp){
    fprintf(stderr, "%s: could not open\n", file ? file : "(stdin)");
    return 1;
  }
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
  if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    if(ifp != stdin) fclose(ifp);
    return 1;
  }
  bool err = false;
  char *line;
  int cnt = 0;
  while(!err && (line = mygetline(ifp)) != NULL){
    char *pv = strchr(line, '\t');
    if(!pv){
      tcfree(line);
      continue;
    }
    *pv = '\0';
    if(sc) tcstrutfnorm(line, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
    if(!tchdbput2(hdb, line, pv + 1)){
      printerr(hdb);
      err = true;
    }
    tcfree(line);
    if(cnt > 0 && cnt % 100 == 0){
      putchar('.');
      fflush(stdout);
      if(cnt % 5000 == 0) printf(" (%08d)\n", cnt);
    }
    cnt++;
  }
  printf(" (%08d)\n", cnt);
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  if(ifp != stdin) fclose(ifp);
  return err ? 1 : 0;
}
예제 #16
0
파일: tchmgr.c 프로젝트: maiha/tokyocabinet
/* perform count command */
static int proccount(const char *path, int omode){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL);
  if(!tchdbopen(hdb, path, HDBOREADER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  printf("%llu\n", (unsigned long long)tchdbrnum(hdb));
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
예제 #17
0
파일: tctest.c 프로젝트: Fleurer/nanodb
/* perform write command */
int dowrite(char *name, int rnum){
  TCHDB *hdb;
  int i, err, len;
  char buf[RECBUFSIZ];
  if(showprgr) printf("<Writing Test of Hash>\n  name=%s  rnum=%d\n\n", name, rnum);
  /* open a database */
  hdb = tchdbnew();
  tchdbtune(hdb, rnum * 3, 0, 0, 0);
  tchdbsetxmsiz(hdb, rnum * 48);
  if(!tchdbopen(hdb, name, HDBOWRITER | HDBOCREAT | HDBOTRUNC)){
    fprintf(stderr, "tchdbopen failed\n");
    tchdbdel(hdb);
    return 1;
  }
  err = FALSE;
  /* loop for each record */
  for(i = 1; i <= rnum; i++){
    /* store a record */
    len = sprintf(buf, "%08d", i);
    if(!tchdbputasync(hdb, buf, len, buf, len)){
      fprintf(stderr, "tchdbputasync failed\n");
      err = TRUE;
      break;
    }
    /* print progression */
    if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
      putchar('.');
      fflush(stdout);
      if(i == rnum || i % (rnum / 10) == 0){
        printf(" (%08d)\n", i);
        fflush(stdout);
      }
    }
  }
  /* close the database */
  if(!tchdbclose(hdb)){
    fprintf(stderr, "tchdbclose failed\n");
    tchdbdel(hdb);
    return 1;
  }
  tchdbdel(hdb);
  if(showprgr && !err) printf("ok\n\n");
  return err ? 1 : 0;
}
예제 #18
0
void DBPrivCloseDB(DBPriv *db)
{
    int ret;

    if ((ret = pthread_mutex_destroy(&db->cursor_lock)) != 0)
    {
        errno = ret;
        Log(LOG_LEVEL_ERR, "Unable to destroy mutex during Tokyo Cabinet database handle close. (pthread_mutex_destroy: %s)",
            GetErrorStr());
    }

    if (!tchdbclose(db->hdb))
    {
        Log(LOG_LEVEL_ERR, "Closing database failed. (tchdbclose: %s)", ErrorMessage(db->hdb));
    }

    tchdbdel(db->hdb);
    free(db);
}
예제 #19
0
int main (int argc, char *argv[])
{
    TCHDB * const restrict hdb = tchdbnew(); /* create the object */
    char *value;
    const char *p;
    const char *end;
    struct stat st;
    int fd;
    const unsigned int klen = 8;
    /* input stream must have keys of constant len 8 */

    if (argc < 3) return -1;

    /* open the database */
    if(!tchdbopen(hdb, argv[1], HDBOREADER | HDBONOLCK)) {
        fprintf(stderr, "open error: %s\n", tchdberrmsg(tchdbecode(hdb)));
        return -1;
    }

    /* open input file */
    if ((fd = open(argv[2], O_RDONLY, 0777)) == -1) {perror("open"); return -1;}
    if (fstat(fd, &st) != 0)                        {perror("fstat");return -1;}
    p = (const char *)mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
    if (p == MAP_FAILED)                            {perror("mmap"); return -1;}
    close(fd);

    /* read each key from input mmap and query mcdb
     * (no error checking since key might not exist) */
    for (end = p+st.st_size; p < end; p += klen) {
      #if 0
        tchdbvsiz(hdb, p, klen); /* retrieve record value size */
      #else
        if ((value = tchdbget(hdb, p, klen, &fd))) /* retrieve records */
            free(value);
      #endif
    }

    if(!tchdbclose(hdb)) /* close the database */
        fprintf(stderr, "close error: %s\n", tchdberrmsg(tchdbecode(hdb)));
    tchdbdel(hdb);       /* delete the object */
    return 0;
}
예제 #20
0
파일: tchmgr.c 프로젝트: kadoma/fms
/* perform inform command */
static int procinform(const char *path, int omode){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbopen(hdb, path, HDBOREADER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  const char *npath = tchdbpath(hdb);
  if(!npath) npath = "(unknown)";
  printf("path: %s\n", npath);
  const char *type = "(unknown)";
  switch(tchdbtype(hdb)){
  case HDBTHASH: type = "hash"; break;
  case HDBTBTREE: type = "btree"; break;
  }
  printf("database type: %s\n", type);
  uint8_t flags = tchdbflags(hdb);
  printf("additional flags:");
  if(flags & HDBFOPEN) printf(" open");
  if(flags & HDBFFATAL) printf(" fatal");
  printf("\n");
  printf("bucket number: %llu\n", (unsigned long long)tchdbbnum(hdb));
  if(hdb->cnt_writerec >= 0)
    printf("used bucket number: %lld\n", (long long)tchdbbnumused(hdb));
  printf("alignment: %u\n", tchdbalign(hdb));
  printf("free block pool: %u\n", tchdbfbpmax(hdb));
  uint8_t opts = tchdbopts(hdb);
  printf("options:");
  if(opts & HDBTLARGE) printf(" large");
  if(opts & HDBTDEFLATE) printf(" deflate");
  printf("\n");
  printf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb));
  printf("file size: %llu\n", (unsigned long long)tchdbfsiz(hdb));
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
예제 #21
0
void DBPrivCloseDB(DBPriv *db)
{
    int ret;

    if ((ret = pthread_mutex_destroy(&db->cursor_lock)) != 0)
    {
        errno = ret;
        CfOut(cf_error, "pthread_mutex_destroy",
              "Unable to destroy mutex during Tokyo Cabinet database handle close");
    }

    if (!tchdbclose(db->hdb))
    {
	CfOut(cf_error, "", "!! tchdbclose: Closing database failed: %s",
              ErrorMessage(db->hdb));
    }

    tchdbdel(db->hdb);
    free(db);
}
예제 #22
0
파일: tchmgr.c 프로젝트: kadoma/fms
/* perform optimize command */
static int procoptimize(const char *path, int bnum, int apow, int fpow, int opts, int omode){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  if(!tchdboptimize(hdb, bnum, apow, fpow, opts)){
    printerr(hdb);
    err = true;
  }
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
예제 #23
0
파일: tchmgr.c 프로젝트: kadoma/fms
/* perform out command */
static int procout(const char *path, const char *kbuf, int ksiz, int omode){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  if(!tchdbout(hdb, kbuf, ksiz)){
    printerr(hdb);
    err = true;
  }
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
예제 #24
0
파일: tchmgr.c 프로젝트: kadoma/fms
/* perform create command */
static int proccreate(const char *path, int bnum, int apow, int fpow, int opts){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbtune(hdb, bnum, apow, fpow, opts)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  if(!tchdbclose(hdb)){
    printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
예제 #25
0
파일: jbhmgr.c 프로젝트: Dean-Jansen/ejdb
/* perform out command */
static int procout(const char *path, const char *kbuf, int ksiz, int omode) {
    TCHDB *hdb = tchdbnew();
    if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
    if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
    if (!tchdbopen(hdb, path, HDBOWRITER | omode)) {
        printerr(hdb);
        tchdbdel(hdb);
        return 1;
    }
    bool err = false;
    if (!tchdbout(hdb, kbuf, ksiz)) {
        printerr(hdb);
        err = true;
    }
    if (!tchdbclose(hdb)) {
        if (!err) printerr(hdb);
        err = true;
    }
    tchdbdel(hdb);
    return err ? 1 : 0;
}
예제 #26
0
파일: jbhmgr.c 프로젝트: Dean-Jansen/ejdb
/* perform create command */
static int proccreate(const char *path, int bnum, int apow, int fpow, int opts) {
    TCHDB *hdb = tchdbnew();
    if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
    if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
    if (!tchdbtune(hdb, bnum, apow, fpow, opts)) {
        printerr(hdb);
        tchdbdel(hdb);
        return 1;
    }
    if (!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC)) {
        printerr(hdb);
        tchdbdel(hdb);
        return 1;
    }
    bool err = false;
    if (!tchdbclose(hdb)) {
        printerr(hdb);
        err = true;
    }
    tchdbdel(hdb);
    return err ? 1 : 0;
}
예제 #27
0
파일: tchmgr.c 프로젝트: kadoma/fms
/* perform put command */
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
                   int omode, int dmode){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  switch(dmode){
  case -1:
    if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)){
      printerr(hdb);
      err = true;
    }
    break;
  case 1:
    if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
      printerr(hdb);
      err = true;
    }
    break;
  default:
    if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
      printerr(hdb);
      err = true;
    }
    break;
  }
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
예제 #28
0
파일: db_obj.cpp 프로젝트: Quix0r/seeks
 bool db_obj_local::dbclose()
 {
   return tchdbclose(_hdb);
 }
예제 #29
0
파일: t.c 프로젝트: wsjtangy/loongsso
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;
}
예제 #30
0
void Retsu::Column::close() {	
  if(!tchdbclose(this->database)){
    //		throw StorageError("Could not close dimension at " + Path());
  }
}