LIB_EXPORT rc_t CC SRAMgrVOpenTableUpdate(SRAMgr *mgr, SRATable **rslt, const char *spec, va_list args) { SRATable *self; char path[4096]; rc_t rc; if (mgr == NULL) return RC(RC_MODULE, RC_TARGET, rcConstructing, rcSelf, rcNull); if (spec == NULL || rslt == NULL) return RC(RC_MODULE, RC_TARGET, rcConstructing, rcParam, rcNull); *rslt = NULL; rc = ResolveTablePath(mgr, path, sizeof(path), spec, args); if (rc) return rc; self = calloc(1, sizeof(*self)); if (self == NULL) return RC(RC_MODULE, RC_TARGET, rcConstructing, rcMemory, rcExhausted); rc = VDBManagerOpenTableUpdate(mgr->vmgr, &self->vtbl, mgr->schema, "%s", path); if (rc == 0) { rc = VTableOpenMetadataUpdate(self->vtbl, &self->meta); if (rc == 0) { rc = KMetadataVersion(self->meta, &self->metavers); if (rc == 0) { rc = VTableCreateCursorWrite(self->vtbl, &self->curs, kcmInsert); if (rc == 0) { self->mgr = SRAMgrAttach(mgr); self->mode = mgr->mode; self->read_only = false; KRefcountInit(&self->refcount, 1, "SRATable", "OpenTableUpdate", path); rc = SRATableFillOut ( self, true ); if ( rc == 0 ) { VectorInit ( & self -> wcol, 0, 16 ); *rslt = self; return 0; } } } } } SRATableWhack(self); return rc; }
rc_t CC KMain(int argc, char* argv[]) { const char table[] = "/home/klymenka/REDACT-IN"; const char name[] = "READ_FILTER"; rc_t rc = 0; bool locked = false; VDBManager* mgr; VTable *tbl; const VCursor *rCursor = NULL; int i; LogLevelSet("info"); for (i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-+")) { if (++i <= argc) { #if _DEBUGGING KDbgSetString(argv[i]); #endif } } } /*KDbgSetString("VDB");*/ if (rc == 0) { /* +01: ManagerMake */ LOGMSG(klogInfo, "VDBManagerMakeUpdate"); rc = VDBManagerMakeUpdate(&mgr, NULL); DISP_RC_INT(rc, "while calling VDBManagerMakeUpdate"); } if (rc == 0) { rc = VDBManagerWritable(mgr, table); if (GetRCState(rc) == rcLocked) { LOGMSG(klogInfo, "VDBManagerUnlock"); rc = VDBManagerUnlock(mgr, table); DISP_RC_INT(rc, "while calling VDBManagerUnlock"); locked = true; } } if (rc == 0) { /* +02: OpenTable */ PLOGMSG(klogInfo, (klogInfo, "VDBManagerOpenTableUpdate(\"$(t)\")", "t=%s", table)); rc = VDBManagerOpenTableUpdate (mgr, &tbl, NULL, table); if (rc != 0) { PLOGERR(klogErr, (klogErr, rc, "while opening VTable '$(path)'", "path=%s", table)); } } if (rc == 0) { /* +03: CreateCursorRead */ LOGMSG(klogInfo, "VDBManagerUnlock"); rc = VTableCreateCursorRead(tbl, &rCursor); DISP_RC_INT(rc, "while creating read cursor"); #if 1 if (rc == 0) { uint32_t idx; PLOGMSG(klogInfo, (klogInfo, "VCursorAddColumn(read cursor, \"$(n)\")", "n=%s", name)); rc = VCursorAddColumn(rCursor, &idx, name); if (rc != 0) { PLOGERR(klogErr, (klogErr, rc, "while adding $(name) to read cursor", "name=%s", name)); } } #endif if (rc == 0) { LOGMSG(klogInfo, "VCursorOpen(read cursor)"); rc = VCursorOpen(rCursor); DISP_RC_INT(rc, "while opening read cursor"); } } if (rc == 0) { VCursor *cursor; uint32_t idx; /* +04: CreateCursorWrite */ LOGMSG(klogInfo, "VTableCreateCursorWrite"); rc = VTableCreateCursorWrite(tbl, &cursor, kcmInsert); DISP_RC_INT(rc, "while creating write cursor"); if (rc == 0) { PLOGMSG(klogInfo, (klogInfo, "VCursorAddColumn(write cursor, \"$(n)\")", "n=%s", name)); rc = VCursorAddColumn(cursor, &idx, name); if (rc != 0) { PLOGERR(klogErr, (klogErr, rc, "while adding $(name) to write cursor", "name=%s", name)); } } if (rc == 0) { LOGMSG(klogInfo, "VCursorOpen(write cursor)"); rc = VCursorOpen(cursor); DISP_RC_INT(rc, "while opening write cursor"); } #if 1 for (i = 0; i < 3 && rc == 0; ++i) { if (rc == 0) { PLOGMSG(klogInfo, (klogInfo, "VCursorOpenRow(write cursor) $(i)", "i=%d", i)); rc = VCursorOpenRow(cursor); DISP_RC_INT(rc, "while opening row to write"); } if (rc == 0) { char buffer[1]; char b; switch (i) { case 0: buffer[0] = SRA_READ_FILTER_CRITERIA; buffer[0] = SRA_READ_FILTER_REJECT; break; case 1: buffer[0] = SRA_READ_FILTER_REJECT; buffer[0] = SRA_READ_FILTER_CRITERIA; break; case 2: buffer[0] = SRA_READ_FILTER_REDACTED; break; } buffer[0] = SRA_READ_FILTER_PASS; b = buffer[0]; PLOGMSG(klogInfo, (klogInfo, "VCursorWrite('$(v)') $(i)", "v=%s,i=%d", b == SRA_READ_FILTER_REDACTED ? "SRA_READ_FILTER_REDACTED" : "?", i)); rc = VCursorWrite(cursor, idx, 8, buffer, 0, 1); DISP_RC_INT(rc, "while writing"); } if (rc == 0) { PLOGMSG(klogInfo, (klogInfo, "VCursorCommitRow(write cursor) $(i)", "i=%d", i)); rc = VCursorCommitRow(cursor); DISP_RC_INT(rc, "while committing row"); } PLOGMSG(klogInfo, (klogInfo, "VCursorCloseRow(write cursor) $(i)", "i=%d", i)); { rc_t rc2 = VCursorCloseRow(cursor); DISP_RC_INT(rc2, "while closing row"); if (rc == 0) { rc = rc2; } } } #endif LOGMSG(klogInfo, "VCursorRelease(read cursor)"); /* -03: CreateCursorRead */ VCursorRelease(rCursor); if (rc == 0) { LOGMSG(klogInfo, "VCursorCommit(write cursor)"); rc = VCursorCommit(cursor); DISP_RC_INT(rc, "while committing cursor"); } LOGMSG(klogInfo, "VCursorRelease(write cursor)"); /* -04: CreateCursorWrite */ VCursorRelease(cursor); } LOGMSG(klogInfo, "VTableRelease"); /* -02: OpenTable */ VTableRelease(tbl); LOGMSG(klogInfo, "VDBManagerLock"); if (locked) { rc_t rc2 = VDBManagerLock(mgr, table); DISP_RC_INT(rc2, "while VDBManagerLock"); } /* -01: ManagerMake */ LOGMSG(klogInfo, "VDBManagerRelease"); VDBManagerRelease(mgr); if (rc == 0) { LOGMSG(klogInfo, "SUCCESS"); } else { LOGMSG(klogInfo, "FAILURE"); } return rc; }
static rc_t DbInit(rc_t rc, const CmdLine* args, Db* db) { const char name[] = "READ_FILTER"; assert(args && db); memset(db, 0, sizeof *db); if (rc != 0) { return rc; } db->table = args->table; if (rc == 0) { rc = VDBManagerMakeUpdate(&db->mgr, NULL); DISP_RC(rc, "while calling VDBManagerMakeUpdate"); } if (rc == 0) { rc = VDBManagerWritable(db->mgr, args->table); if (rc != 0) { if (GetRCState(rc) == rcLocked) { rc = VDBManagerUnlock(db->mgr, args->table); if (rc != 0) { PLOGERR(klogErr, (klogErr, rc, "while calling VDBManagerUnlock('$(table)')", "table=%s", args->table)); } db->locked = true; } else { PLOGERR(klogErr, (klogErr, rc, "while calling VDBManagerWritable('$(table)')", "table=%s", args->table)); if (rc == RC(rcDB, rcPath, rcAccessing, rcPath, rcReadonly)) { PLOGERR(klogErr, (klogErr, rc, "N.B. It is possible '$(table)' was not locked properly" , "table=%s", args->table)); } } } } if (rc == 0) { db->locked = true; /* has to be locked in production mode */ rc = VDBManagerOpenTableUpdate (db->mgr, &db->tbl, NULL, args->table); if (rc != 0) { VDatabase *vdb; rc_t rc2 = VDBManagerOpenDBUpdate ( db->mgr, &vdb, NULL , args->table ); if( rc2 == 0) { rc2 = VDatabaseOpenTableUpdate ( vdb, &db->tbl, "SEQUENCE" ); if (rc2 == 0 ) rc = 0; VDatabaseRelease ( vdb ); } } if(rc != 0){ PLOGERR(klogErr, (klogErr, rc, "while opening VTable '$(table)'", "table=%s", args->table)); } } if( rc == 0) { rc = VTableCreateCursorRead(db->tbl, &db->rCursor); DISP_RC(rc, "while creating read cursor"); if (rc == 0) { rc = VCursorAddColumn(db->rCursor, &db->rFilterIdx, "%s", name); if (rc != 0) { PLOGERR(klogErr, (klogErr, rc, "while adding $(name) to read cursor", "name=%s", name)); } } if (rc == 0) { rc = VCursorOpen(db->rCursor); DISP_RC(rc, "while opening read cursor"); } } if (rc == 0) { rc = VTableCreateCursorWrite(db->tbl, &db->wCursor, kcmInsert); DISP_RC(rc, "while creating write cursor"); if (rc == 0) { rc = VCursorAddColumn(db->wCursor, &db->wIdx, "%s", name); if (rc != 0) { PLOGERR(klogErr, (klogErr, rc, "while adding $(name) to write cursor", "name=%s", name)); } } if (rc == 0) { rc = VCursorOpen(db->wCursor); DISP_RC(rc, "while opening write cursor"); } } return rc; }
static rc_t open_and_run (Context * context) { KDirectory * pwd; rc_t rc; rc = KDirectoryNativeDir (&pwd); if (rc) LOGERR (klogFatal, rc, "Unable to open file system"); else { if (PathExists (pwd, kptDile, context->file_path)) { if (PathExists (pwd, kptDile, context->file_path)) { VDBManager * vmgr; rc = VDBManagerMakeUpdate (&vmgr, pwd); if (rc) LOGERR (kptInt, "Failed to create a database manager"); else { VSchema * vschema; rc = VDBManagerMakeSchema (vmgr, &vschema); if (rc) LOGERR (kptInt, "Failed to create schema"); else { rc = VSchemaParseFile (vschema, args->schema); if (rc) PLOGERR (klogFatal, (klogFatal, "Unable to parse schema file ($S)", "S=%s", args->schema)); else { VTable * vtable; rc = VDBManagerOpenTableUpdate (vmgr, &vtable, SCHEMA, args->table); if (rc) PLOGERR (klogFatal, (klogFatal, "Unable to open table ($T)", "T=%s", args->table)); else { VTableRelease (vtable); } } VSchemaRelease (vschema); } VDBManagerRelease (vmgr); } } else PLOGERR (kptFatal, (kptFatal, "table paramaeter is not a table directory ($F)", "F=%s", args->table)); } else PLOGERR (kptFatal, (kptFatal, "file paramaeter is not a file ($F)", "F=%s", context->file_path)); KPathType pt; pt = KDirectoryPathType (arg->file); if ((pt & ~kptAlias) != kptFile) else { } KDirectoryRelease (pwd); } return rc; }