/* 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; }
/* adddouble */ JNIEXPORT jdouble JNICALL Java_tokyocabinet_HDB_adddouble (JNIEnv *env, jobject self, jbyteArray key, jdouble num){ if(!key){ throwillarg(env); return 0.0; } TCHDB *hdb = (TCHDB *)(intptr_t)(*env)->GetLongField(env, self, hdb_fid_ptr); jboolean ick; jbyte *kbuf = (*env)->GetByteArrayElements(env, key, &ick); if(!kbuf){ throwoutmem(env); return 0.0; } int ksiz = (*env)->GetArrayLength(env, key); num = tchdbadddouble(hdb, kbuf, ksiz, num); if(ick) (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT); return num; }