int open_db(char *addr, int port, TCRDB **rdb) { int ecode=0; if (*rdb != NULL) { if(!tcrdbclose(*rdb)){ ecode = tcrdbecode(*rdb); fprintf(stderr, "close error: %s\n", tcrdberrmsg(ecode)); } tcrdbdel(*rdb); *rdb = NULL; } *rdb = tcrdbnew(); if(!tcrdbopen(*rdb, addr, port)){ ecode = tcrdbecode(*rdb); fprintf(stderr, "open error(%s:%d): %s\n", addr, port, tcrdberrmsg(ecode)); *rdb = NULL; } else { char *status = tcrdbstat(*rdb); printf("adding indices\n---------------------\n"); tcrdbtblsetindex(*rdb, "x", RDBITDECIMAL); tcrdbtblsetindex(*rdb, "y", RDBITDECIMAL); printf("%s---------------------\n", status); if (status) free(status); } return ecode; }
static int rdb_stat(lua_State *L){ TCRDB *rdb = rdb_getrdb(L, 1); char *status = tcrdbstat(rdb); lua_pushstring(L, status); free(status); return 1; }
static VALUE mTokyoMessenger_stat(VALUE vself){ TCRDB *db = mTokyoMessenger_getdb(vself); return rb_str_new2(tcrdbstat(db)); }