rc_t write_statistic_into_tab( KDirectory *dir, statistic * data, const KNamelist *schema_list, const char *output_file_path, uint64_t * written, bool show_progress ) { VDBManager *my_manager; rc_t rc; if ( written != NULL ) *written = 0; rc = VDBManagerMakeUpdate ( &my_manager, dir ); if ( rc != 0 ) LogErr( klogInt, rc, "VDBManagerMakeUpdate() failed\n" ); else { VSchema * my_schema; rc = make_schema( schema_list, my_manager, &my_schema ); if ( rc == 0 ) { VTable * my_table; rc = VDBManagerCreateTable( my_manager, &my_table, my_schema, "NCBI:align:tbl:qstat", kcmInit | kcmParents, output_file_path ); if ( rc != 0 ) LogErr( klogInt, rc, "VDBManagerCreateTable() failed\n" ); else { rc = write_statistic_cmn( my_table, data, written, show_progress ); VTableRelease( my_table ); } VSchemaRelease( my_schema ); } VDBManagerRelease( my_manager ); } return rc; }
static rc_t gather_statistic( statistic * data, KDirectory *dir, context *ctx ) { VDBManager *my_manager; /* because this tool is linked against the write-version of vdb and kdb, there is no Read-Manager available... */ rc_t rc = VDBManagerMakeUpdate ( &my_manager, dir ); if ( rc != 0 ) LogErr( klogInt, rc, "VDBManagerMakeUpdate() failed\n" ); else { const VDatabase *my_database; rc = VDBManagerOpenDBRead( my_manager, &my_database, NULL, "%s", ctx->src_path ); if ( rc != 0 ) LogErr( klogInt, rc, "VDBManagerOpenDBRead() failed\n" ); else { /* ******************************************************* */ rc = read_statistic_from_table( data, dir, ctx, my_database, "PRIMARY_ALIGNMENT" ); /* ******************************************************* */ VDatabaseRelease( my_database ); } VDBManagerRelease( my_manager ); } return rc; }
rc_t KeyRingDatabaseLoad ( struct KeyRingData* self, const struct KDirectory* dir, const char* path ) { VDBManager* innerMgr; rc_t rc = VDBManagerMakeUpdate( &innerMgr, (KDirectory*)dir ); if (rc == 0) { rc_t rc2; const VDatabase* db; rc = VDBManagerOpenDBRead(innerMgr, & db, NULL, "%s", path); if (rc == 0) { rc = LoadProjects(&self->projects, db); if (rc == 0) rc = LoadObjects(&self->objects, db); /*TODO: LoadKeys */ rc2 = VDatabaseRelease(db); if (rc == 0) rc = rc2; } rc2 = VDBManagerRelease(innerMgr); if (rc == 0) rc = rc2; } return rc; }
static rc_t ref_seq_load_main( const p_context ctx ) { KDirectory *dir; rc_t rc = KDirectoryNativeDir( &dir ); if ( rc != 0 ) { LOGERR( klogErr, rc, "ref_seq_load_main:KDirectoryNativeDir() failed" ); } else { VDBManager *mgr; rc = VDBManagerMakeUpdate ( &mgr, dir ); if ( rc != 0 ) { LOGERR( klogErr, rc, "ref_seq_load_main:VDBManagerMakeRead() failed" ); } else { rc = prepare_load( dir, ctx ); if ( rc != 0 ) { LOGERR( klogInt, rc, "ref_seq_load_main:prepare_load() failed" ); } else { char tblpath[ 4096 ]; rc = KDirectoryResolvePath( dir, true, tblpath, sizeof tblpath, ctx->dst_path ); if ( rc != 0 ) { LOGERR( klogErr, rc, "ref_seq_load_main:KDirectoryResolvePath() failed" ); } else { KPathType type = VDBManagerPathType( mgr, tblpath ); if ( type != kptNotFound ) { rc = RC( rcExe, rcDatabase, rcCreating, rcFile, rcExists ); PLOGERR( klogErr, ( klogErr, rc, "$(path)", "path=%s", tblpath ) ); } } } if ( rc == 0 ) { rc = perform_load( ctx, dir, mgr ); /* <====================== */ if ( rc != 0 ) { remove_path( dir, ctx->dst_path, ctx->quiet ); } } VDBManagerRelease( mgr ); } KDirectoryRelease( dir ); } return rc; }
static rc_t DB_Init(const SParam* p, DB_Handle* h) { rc_t rc; if( (rc = VDBManagerMakeUpdate(&h->mgr, NULL)) != 0 ) { LOGERR(klogErr, rc, "failed to create VDB Manager"); } else if( (rc = VDBManagerMakeSchema(h->mgr, &h->schema)) != 0 ) { LOGERR(klogErr, rc, "failed to create schema"); } else if( (rc = VSchemaParseFile(h->schema, p->schema)) != 0 ) { PLOGERR(klogErr, (klogErr, rc, "failed to parse schema file '$(schema)'", PLOG_S(schema), p->schema)); } else if( (rc = VDBManagerCreateDB(h->mgr, &h->db, h->schema, "NCBI:align:db:alignment_evidence", p->force ? kcmInit : kcmCreate, p->out)) != 0 ) { PLOGERR(klogErr, (klogErr, rc, "failed to create database at '$(path)'", PLOG_S(path), p->out)); } else if( (rc = ReferenceMgr_Make(&h->rmgr, h->db, h->mgr, (p->force_refw ? ewrefmgr_co_allREADs : 0), p->refseqcfg, p->refseqpath, p->refseq_chunk, 350 * 1024 * 1024, 0)) != 0 ) { LOGERR(klogErr, rc, "failed to create reference manager"); } else if( (rc = CGWriterAlgn_Make(&h->walgn, &h->mappings, h->db, h->rmgr, p->min_mapq, p->single_mate, p->cluster_size)) != 0 ) { LOGERR(klogErr, rc, "failed to create alignment writer"); } else if( (rc = CGWriterSeq_Make(&h->wseq, &h->reads, h->db, (p->force_readw ? ewseq_co_SaveRead : 0) | (p->no_spot_group ? 0 : ewseq_co_SpotGroup), p->qual_quant)) != 0 ) { LOGERR(klogErr, rc, "failed to create sequence writer"); } else if( p->asm_path && (rc = CGWriterEvdInt_Make(&h->wev_int, &h->ev_int, h->db, h->rmgr, 0)) != 0 ) { LOGERR(klogErr, rc, "failed to create evidence intervals writer"); } else if( p->asm_path && (rc = CGWriterEvdDnbs_Make(&h->wev_dnb, &h->ev_dnb, h->db, h->rmgr, 0)) != 0 ) { LOGERR(klogErr, rc, "failed to create evidence dnbs writer"); } else { const char** r = p->refFiles; while( rc == 0 && *r != NULL ) { if( (rc = ReferenceMgr_FastaPath(h->rmgr, *r++)) != 0 ) { PLOGERR(klogInfo, (klogInfo, rc, "fasta file '$(file)'", "file=%s", r[-1])); } } } return rc; }
/* init_mgr */ static rc_t init_mgr ( const vtblcp_parms *pb, VDBManager **mgrp ) { VDBManager *mgr; rc_t rc = VDBManagerMakeUpdate ( & mgr, NULL ); if ( rc != 0 ) LOGERR ( klogInt, rc, "failed to open vdb library" ); else { /* currently have no manager parameters */ * mgrp = mgr; } return rc; }
rc_t write_statistic_into_db( KDirectory *dir, statistic * data, const KNamelist *schema_list, const char *src_path, uint64_t * written, bool show_progress ) { VDBManager *my_manager; rc_t rc; if ( written != NULL ) *written = 0; rc = VDBManagerMakeUpdate ( &my_manager, dir ); if ( rc != 0 ) LogErr( klogInt, rc, "VDBManagerMakeUpdate() failed\n" ); else { VSchema * my_schema; rc = make_schema( schema_list, my_manager, &my_schema ); if ( rc == 0 ) { VDatabase *my_database; rc = VDBManagerOpenDBUpdate( my_manager, &my_database, my_schema, src_path ); if ( rc != 0 ) LogErr( klogInt, rc, "VDBManagerOpenDBUpdate() failed\n" ); else { VTable * my_table; rc = VDatabaseCreateTable( my_database, &my_table, "QUAL_STAT", kcmOpen | kcmParents, "QUAL_STAT" ); if ( rc !=0 ) LogErr( klogInt, rc, "VDatabaseCreateTable() failed\n" ); else { rc = write_statistic_cmn( my_table, data, written, show_progress ); VTableRelease( my_table ); } VDatabaseRelease( my_database ); } VSchemaRelease( my_schema ); } VDBManagerRelease( my_manager ); } return rc; }
rc_t make_ref_exclude( ref_exclude *exclude, KDirectory *dir, const char * path, bool info ) { rc_t rc; BSTreeInit( &exclude->ref_nodes ); BSTreeInit( &exclude->translations ); exclude->last_used_ref_node = NULL; exclude->info = info; rc = VDBManagerMakeUpdate ( &exclude->mgr, dir ); if ( rc != 0 ) { LogErr( klogInt, rc, "VDBManagerMakeUpdate() in make_ref_exclude() failed\n" ); } else { insert_trans_nodes( &exclude->translations ); exclude->path = string_dup_measure ( path, NULL ); } return rc; }
rc_t KeyRingDatabaseSave ( struct KeyRingData* self, struct KDirectory* wd, const char* path ) { rc_t rc; VDBManager* vdbMgr; rc = VDBManagerMakeUpdate( &vdbMgr, wd ); if (rc == 0) { VSchema* schema; rc = VDBManagerMakeSchema(vdbMgr, &schema); if (rc == 0) { rc = VSchemaParseText ( schema, "keyring_schema", schema_text, string_measure(schema_text, NULL) ); if (rc == 0) { /* create a database */ VDatabase* db; rc = VDBManagerCreateDB(vdbMgr, & db, schema, "keyring:KEYRING", kcmCreate | kcmMD5, path); if (rc == 0) { rc_t rc2; rc = SaveProjects(&self->projects, db); if (rc == 0) rc = SaveObjects(&self->objects, db); /*TODO: SaveKeys */ rc2 = VDatabaseRelease(db); if (rc == 0) rc = rc2; } } VSchemaRelease(schema); } VDBManagerRelease(vdbMgr); } return rc; }
rc_t KMain ( int argc, char *argv [] ) { VDBManager *vmgr; rc_t rc = VDBManagerMakeUpdate ( & vmgr, NULL ); if ( rc != 0 ) LOGERR ( klogInt, rc, "failed to make update manager" ); else { VSchema *vschema; rc = VDBManagerMakeSchema ( vmgr, & vschema ); if ( rc != 0 ) LOGERR ( klogInt, rc, "failed to make empty schema" ); else { const char *file = "align/align.vschema"; #if _DEBUGGING VSchemaListSymtab ( vschema ); #endif rc = VSchemaParseFile ( vschema, "align/align.vschema" ); #if _DEBUGGING VSchemaListSymtab ( vschema ); #endif if ( rc != 0 ) { pLOGERR ( klogErr, rc, "failed to parse schema file '$(file)'" , "file=%s" , file ); } else { VDatabase *vdb; const char *path = "test-ac-db"; const char *typespec = "NCBI:align:db:alignment"; rc = VDBManagerCreateDB ( vmgr, & vdb, vschema, typespec, kcmInit, path ); if ( rc != 0 ) { pLOGERR ( klogInt, rc, "failed to create '$(typespec)' db at '$(path)'" , "typespec=%s,path=%s" , typespec , path ); } else { VTable *vtbl; const char *member = "align"; path = member; rc = VDatabaseCreateTable ( vdb, & vtbl, member, kcmInit, path ); if ( rc != 0 ) { pLOGERR ( klogInt, rc, "failed to create '$(member)' table at '$(path)'" , "member=%s,path=%s" , member , path ); } else { printf ( "done\n" ); VTableRelease ( vtbl ); } VDatabaseRelease ( vdb ); } } VSchemaRelease ( vschema ); } VDBManagerRelease ( vmgr ); } return rc; }
rc_t run (const char * table_path, uint64_t N ) { static const char *colInf[] = { "C1: Same value, same length", "C2: Var. value, same length", "C3: Var. value, var. legnth", "C4: Same value except I row", "C5: Same value except L row" }; rc_t rc; uint64_t row = 0; VDBManager *mgr = NULL; VSchema *schema = NULL; VTable *table = NULL; VCursor *cursor; uint32_t idx[COLUMNS]; uint64_t total[COLUMNS]; int i = 0, j = 0, prev = 0; char *buffer[BUFFERS]; /* Initialize arrays */ memset(&idx, 0, sizeof idx); memset(&total, 0, sizeof total); for (i = 0; i < BUFFERS; ++i) { char c; size_t sz = ROWLEN + 1; if (i == (BUFFERS - 1)) sz += ROWLEN; buffer[i] = malloc(sz); for (j = 0, c = 0; j < sz - 1; ++j, ++c) { if (c >= ROWLEN) c -= ROWLEN; buffer[i][j] = '0' + c; } buffer[i][j] = '\0'; } /* Create manager */ rc = VDBManagerMakeUpdate(&mgr, NULL); if (rc != 0) { LOGERR(klogInt, rc, "failed to open vdb library"); } /* Initialize schema */ if (rc == 0) { rc = VDBManagerMakeSchema(mgr, &schema); if (rc != 0) LOGERR(klogInt, rc, "failed to create empty schema"); } if (rc == 0) { char text[512] = "table Table #1 {\n"; char col [128]; for (i = 1; i <= COLUMNS; ++i) { sprintf(col, " column ascii C%d = .C%d; physical ascii .C%d = C%d;\n", i, i, i, i); strcat(text, col); } strcat(text, "};"); STSMSG(1,("Parsing schema:\n%s", text)); rc = VSchemaParseText(schema, "Schema", text, strlen(text)); if (rc != 0) LOGERR(klogInt, rc, "failed to parse schema"); } /* Create table */ if (rc == 0) { STSMSG(1,("Creating %s", tablePath)); rc = VDBManagerCreateTable(mgr, &table, schema, "Table", kcmInit, tablePath); if (rc != 0) LOGERR(klogInt, rc, "failed to create table"); } /* Initialize cursor */ if (rc == 0) { rc = VTableCreateCursorWrite(table, &cursor, kcmInsert); if (rc != 0) LOGERR(klogInt, rc, "failed to create cursor"); } for (i = 0; rc == 0 && i < COLUMNS; ++i) { char col[3]; sprintf(col, "C%d", i + 1); STSMSG(2,("Adding column %s to cursor", col)); rc = VCursorAddColumn(cursor, &idx[i], col); if (rc != 0) PLOGERR(klogInt, (klogInt, rc, "failed to add $(c) to cursor", "c=%s", col)); } if (rc == 0) { rc = VCursorOpen(cursor); if (rc != 0) LOGERR(klogInt, rc, "failed to open cursor"); } /* Write data */ for (row = 0; row < N && rc == 0; ++row) { int max = 2 * ROWLEN - 1; int sz = 0; if ((row % 2) == 0) { int min = 1; sz = min + (int) (max * (rand() / (RAND_MAX + 1.0))); prev = sz; buffer[1][0] = '1'; } else { sz = max + 1 - prev; buffer[1][0] = '2'; } rc = Quitting(); if (rc == 0) { KStsLevel lvl = 2; if (row > 0 && ((row % ROWS) == 0)) { lvl = 1; } STSMSG (lvl, ("Writing row %ji / %ji", row + 1, N)); rc = VCursorOpenRow(cursor); if (rc != 0) LOGERR(klogInt, rc, "failed to open row"); } for (j = 0; j < COLUMNS && rc == 0; ++j) { uint32_t count = 0; int buf = j; switch (j) { case 0: case 1: count = strlen(buffer[j]); break; case 2: count = sz; break; case 3: buf = 0; if (row == 0) buf = 1; count = strlen(buffer[buf]); break; case 4: buf = 0; if (row == (N - 1)) buf = 1; count = strlen(buffer[buf]); break; default: assert(0); break; } STSMSG (3, ("Row %ji/Col.%d: %sd %.*s\n", row + 1, j + 1, count, count, buffer[buf])); rc = VCursorWrite (cursor, idx[j], 8, buffer[buf], 0, count); if (rc != 0) PLOGERR(klogInt, (klogInt, rc, "failed to write row[$i]", "i=%d", j + 1)); total[j] += count; } if (rc == 0) { rc = VCursorCommitRow(cursor); if (rc != 0) LOGERR(klogInt, rc, "failed to commit row"); } if (rc == 0) { rc = VCursorCloseRow(cursor); if (rc != 0) LOGERR(klogInt, rc, "failed to close row"); } } if (rc == 0) { STSMSG (1, ("Commiting cursor\n")); rc = VCursorCommit(cursor); if (rc != 0) LOGERR(klogInt, rc, "failed to commit cursor"); } /* Cleanup */ VCursorRelease(cursor); VTableRelease(table); VSchemaRelease(schema); VDBManagerRelease(mgr); for (i = 0; i < BUFFERS; ++i) { free(buffer[i]); } /* Log */ if (rc == 0) { PLOGMSG(klogInfo, (klogInfo, "$(t)", "t=%s", tablePath)); PLOGMSG(klogInfo,(klogInfo, "$(n)($(N)) rows written - $(b) bytes per row", PLOG_I64(n) "," PLOG_X64(N) ",b=%d", N, N, ROWLEN)); for (i = 0; i < COLUMNS; ++i) { PLOGMSG(klogInfo,(klogInfo, "$(i): $(n)($(N)) bytes", "i=%s," PLOG_I64(n) "," PLOG_X64(N), colInf[i], total[i], total[i])); } } if (rc == 0) { KDirectory *dir = NULL; uint64_t sizes[COLUMNS]; memset(&sizes, 0, sizeof sizes); rc = KDirectoryNativeDir(&dir); if (rc != 0) LOGERR(klogInt, rc, "failed to KDirectoryNativeDir"); else { for (i = 1; i <= COLUMNS; ++i) { uint64_t size = 0; #define FORMAT "%s/col/%s/data" #define KFORMAT "$(d)/col/$(n)/data", "d=%s,n=%s" #define STATUS(action) (action FORMAT, tablePath, name) char name[3]; sprintf(name, "C%d", i); STSMSG (1, STATUS("checking ")); rc = KDirectoryFileSize(dir, &size, FORMAT, tablePath, name); if (rc != 0) { if (GetRCState(rc) == rcNotFound) { STSMSG (2, STATUS("not found ")); rc = 0; } else PLOGERR(klogInt, (klogInt, rc, "failed to check " KFORMAT, tablePath, name)); } else { STSMSG (2, STATUS("found ")); } PLOGMSG(klogInfo, (klogInfo, "Size of $(d)/col/$(n)/data = $(s)", "d=%s,n=%s," PLOG_I64(s), tablePath, name, size)); sizes[i - 1] = size; } } KDirectoryRelease(dir); if (rc == 0) { puts(""); KOutMsg("%ld rows, %d bytes per row:\n", N, ROWLEN); for (i = 0; i < COLUMNS; ++i) { puts(colInf[i]); } puts(""); for (i = 0; i < COLUMNS; ++i) { int64_t over = sizes[i] - total[i]; KOutMsg("C%d: %9ld bytes written; " "%9ld in 'data'", i + 1, total[i], sizes[i]); if (over > 0) { double p = 100.0 * over / sizes[i]; printf(": %7ld extra bytes (%.4f%%)\n", over, p); } else { puts(""); } } } } return rc; }
rc_t CC KMain ( int argc, char *argv [] ) { Args *args; rc_t rc = ArgsMakeAndHandle ( & args, argc, argv, 0 ); if ( rc != 0 ) LogErr ( klogErr, rc, "failed to parse arguments" ); else { uint32_t paramc; rc = ArgsParamCount ( args, & paramc ); if ( rc != 0 ) LogErr ( klogInt, rc, "failed to obtain param count" ); else { if ( paramc == 0 ) { rc = RC ( rcExe, rcArgv, rcParsing, rcParam, rcInsufficient ); LogErr ( klogErr, rc, "missing target object" ); MiniUsage ( args ); } else if ( paramc > 1 ) { rc = RC ( rcExe, rcArgv, rcParsing, rcParam, rcExcessive ); LogErr ( klogErr, rc, "expected single target object" ); MiniUsage ( args ); } else { const char *target; rc = ArgsParamValue ( args, 0, & target ); if ( rc != 0 ) LogErr ( klogInt, rc, "failed to obtain param value" ); else { VDBManager *mgr; #if TOOLS_USE_SRAPATH != 0 char full [ 4096 ]; SRAPath *sra_path; rc = SRAPathMake ( & sra_path, NULL ); if ( rc == 0 ) { if ( ! SRAPathTest ( sra_path, target ) ) { rc = SRAPathFind ( sra_path, target, full, sizeof full ); if ( rc == 0 ) target = full; } SRAPathRelease ( sra_path ); } #endif rc = VDBManagerMakeUpdate ( & mgr, NULL ); if ( rc != 0 ) LogErr ( klogInt, rc, "failed to open VDB manager" ); else { rc = VDBManagerLock ( mgr, target ); if ( rc == 0 ) pLogMsg ( klogInfo, "locked '$(target)'", "target=%s", target ); else switch ( GetRCState ( rc ) ) { case rcLocked: pLogMsg ( klogInfo, "'$(target)' was already locked", "target=%s", target ); break; default: pLogErr ( klogErr, rc, "failed to lock '$(target)'", "target=%s", target ); } VDBManagerRelease ( mgr ); } } } } ArgsWhack ( args ); } return rc; }
static rc_t pacbio_load( context *ctx, ld_context *lctx, bool cache_content, bool check_src_obj ) { bool consensus_present = true; rc_t rc1 = 0; rc_t rc = KLoadProgressbar_Make( &lctx->xml_progress, 0 ); if ( rc != 0 ) LOGERR( klogErr, rc, "cannot create LoadProgressBar" ); if ( rc == 0 ) { rc = VDBManagerMakeUpdate ( &lctx->vdb_mgr, lctx->wd ); if ( rc != 0 ) LOGERR( klogErr, rc, "cannot create vdb-update-manager" ); } if ( rc == 0 ) rc = pacbio_load_schema( lctx, ctx->schema_name ); if ( rc == 0 ) { rc = VSchemaParseFile ( lctx->schema, ctx->schema_name ); if ( rc != 0 ) PLOGERR( klogErr, ( klogErr, rc, "cannot to parse schema file '$(schema)'", "schema=%s", ctx->schema_name ) ); } if ( rc == 0 ) { rc = MakeHDF5RootDir ( lctx->wd, &lctx->hdf5_dir, false, ctx->src_path ); if ( rc != 0 ) PLOGERR( klogErr, ( klogErr, rc, "cannot open hdf5-source-file '$(srcfile)'", "srcfile=%s", ctx->src_path ) ); } if ( rc == 0 ) { KCreateMode cmode = kcmMD5 | kcmParents; if ( ctx->force ) cmode |= kcmInit; else cmode |= kcmCreate; rc = VDBManagerCreateDB( lctx->vdb_mgr, & lctx->database, lctx->schema, PACBIO_SCHEMA_DB, cmode, ctx->dst_path ); if ( rc != 0 ) PLOGERR( klogErr, ( klogErr, rc, "cannot create output-database '$(dst)'", "dst=%s", ctx->dst_path ) ); } if ( rc == 0 && ctx_ld_sequence( ctx ) ) rc = load_seq( lctx, cache_content, check_src_obj ); if ( rc == 0 && ctx_ld_consensus( ctx ) ) { rc1 = load_consensus( lctx, cache_content, check_src_obj ); if ( rc1 != 0 ) { LOGMSG( klogWarn, "the consensus-group is missing" ); VDatabaseDropTable ( lctx->database, "CONSENSUS" ); consensus_present = false; } } if ( rc == 0 ) { if ( rc1 == 0 ) { /* CONSENSUS exists, create a alias named SEQUENCE to CONSENSUS */ /* rc = pacbio_make_alias( lctx->database, "CONSENSUS", "SEQUENCE" ); */ } else { /* CONSENSUS does not exist, create a alias named SEQUENCE to PULSE */ /* rc = pacbio_make_alias( lctx->database, "PULSE", "SEQUENCE" ); */ } } if ( rc == 0 && ctx_ld_passes( ctx )&& consensus_present ) { rc1 = load_passes( lctx, cache_content, check_src_obj ); if ( rc1 != 0 ) LOGMSG( klogWarn, "the passes-table is missing" ); } if ( rc == 0 && ctx_ld_metrics( ctx ) ) { rc1 = load_metrics( lctx, cache_content, check_src_obj ); if ( rc1 != 0 ) LOGMSG( klogWarn, "the metrics-table is missing" ); } return rc; }
rc_t run_tests (void) { VDBManager * mgr; rc_t rc; if (verbose) printf("%s call VDBManagerMakeUpdate\n", __func__); rc = VDBManagerMakeUpdate (&mgr, NULL); if (rc) { LOGERR (klogInt, rc, "Failed to open VDBManager"); return rc; } else { VSchema * schema; if (verbose) printf("%s call VDBManagerMakeSchema\n", __func__); rc = VDBManagerMakeSchema (mgr, &schema); printf("%s schema == %p\n", __func__, (void*)schema); if (rc) LOGERR (klogInt, rc, "Failed to make empty schema"); else { if(verbose) printf("%s call VSchemaParseText\n", __func__); rc = VSchemaParseText (schema, "rowlen_schema", schema_text, string_size (schema_text)); if (rc) LOGERR (klogInt, rc, "Failed to parse internal schema"); else { int ix; for ( ix = 0; ix < 6; ++ix) { VTable * table; rc_t orc; if (verbose) printf("%s call open_table\n", __func__); rc = open_table (mgr, schema, &table); if (rc) { LOGERR (klogErr, rc, "Failed to open table"); break; } if (verbose) printf("%s call run_test\n", __func__); rc = run_test (table, &tests[ix]); if (rc) { pLOGERR (klogErr, rc, "Failed $(D)", PLOG_S(D), tests[ix].test_name); } if (verbose) printf("%s call VTableRelease\n", __func__); orc = VTableRelease (table); if (orc) { LOGERR (klogErr, rc, "failed to close table"); } if (orc && (rc == 0)) rc = orc; if (rc) break; } } if (verbose) printf("%s call VSchemaRelease\n", __func__); VSchemaRelease (schema); } if (verbose) printf("%s call VDBManagerRelease\n", __func__); VDBManagerRelease (mgr); } 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; }
static rc_t process(const char* dbname) { rc_t rc; KHashFile* hf = NULL; rc = KHashFileMake(&hf, NULL); if (rc) { fprintf(stderr, "Couldn't create KHashFile\n"); return rc; } KDirectory* srcdir = NULL; rc = KDirectoryNativeDir(&srcdir); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } VDBManager* mgr = NULL; rc = VDBManagerMakeUpdate(&mgr, NULL); // NULL=No working directory if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } VDatabase* db = NULL; rc = VDBManagerOpenDBUpdate(mgr, &db, NULL, dbname); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } const VTable* tbl = NULL; rc = VDatabaseOpenTableRead(db, &tbl, "hdrs"); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } const VCursor* curs = NULL; rc = VTableCreateCursorRead(tbl, &curs); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } uint32_t group_idx = 0; // HDR, TAG, VALUE uint32_t hdr_idx = 0; uint32_t tag_idx = 0; uint32_t value_idx = 0; rc = VCursorAddColumn(curs, &group_idx, "GROUP"); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } rc = VCursorAddColumn(curs, &hdr_idx, "HDR"); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } rc = VCursorAddColumn(curs, &tag_idx, "TAG"); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } rc = VCursorAddColumn(curs, &value_idx, "VALUE"); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } rc = VCursorOpen(curs); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } int64_t start = 0; uint64_t count = 0; rc = VCursorIdRange(curs, 0, &start, &count); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } printf("start=%ld,count=%lu\n", start, count); while (count--) { uint64_t group; uint32_t row_len = 0; rc = VCursorReadDirect(curs, start, group_idx, 64, &group, 1, &row_len); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } printf("group=%lu, row_len=%d\n", group, row_len); char hdr[8]; rc = VCursorReadDirect(curs, start, hdr_idx, 8, &hdr, sizeof(hdr), &row_len); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } hdr[row_len] = '\0'; printf("hdr=%s, row_len=%d\n", hdr, row_len); char tag[8]; rc = VCursorReadDirect(curs, start, tag_idx, 8, &tag, sizeof(tag), &row_len); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } tag[row_len] = '\0'; printf("tag=%s, row_len=%d\n", tag, row_len); char value[8192]; rc = VCursorReadDirect(curs, start, value_idx, 8, &value, sizeof(value), &row_len); if (rc) { fprintf(stderr, "Failed %d %d", __LINE__, rc); return rc; } value[row_len] = '\0'; printf("value=%s, row_len=%d\n", value, row_len); if (!strcmp(hdr, "SQ") && !strcmp(tag, "SN")) { if (check_dup(hf, "SQ:SN", value)) { fprintf(stderr, "Duplicate SQ:SN value '%s'\n", value); } } if (!strcmp(hdr, "RG") && !strcmp(tag, "ID")) { if (check_dup(hf, "RG:ID", value)) { fprintf(stderr, "Duplicate RG:ID value '%s'\n", value); } } if (!strcmp(hdr, "PG") && !strcmp(tag, "ID")) { if (check_dup(hf, "PG:ID", value)) { fprintf(stderr, "Duplicate PG:ID value '%s'\n", value); } } start++; printf("\n"); } printf("Set has %lu elements\n", KHashFileCount(hf)); fprintf(stderr, "Made verifier for %s\n", dbname); KHashFileDispose(hf); VCursorRelease(curs); VTableRelease(tbl); VDatabaseRelease(db); VDBManagerRelease(mgr); KDirectoryRelease(srcdir); return 0; }
static rc_t static_write(void) { const char *schema_text = "version 1; include 'vdb/vdb.vschema'; table foo #1 { column ascii bar { read = .bar; } physical ascii .bar = bar; }"; bool force = 1; rc_t rc; VDBManager *vmgr; rc = VDBManagerMakeUpdate ( & vmgr, NULL ); if ( rc != 0 ) LOGERR ( klogInt, rc, "failed to make VDB manager" ); else { VSchema *schema; rc = VDBManagerMakeSchema ( vmgr, & schema ); if ( rc != 0 ) LOGERR ( klogInt, rc, "failed to make empty schema" ); else { rc = VSchemaParseText( schema, "static_schema", schema_text, strlen(schema_text) ); if ( rc != 0 ) PLOGERR ( klogErr, (klogErr, rc, "failed to parse schema '$(text)'", "test=%s", schema_text )); else { VTable *vtbl; rc = VDBManagerCreateTable ( vmgr, & vtbl, schema, "foo", force ? kcmInit : kcmCreate, table_path ); if ( rc != 0 ) { PLOGERR ( klogErr, (klogErr, rc, "failed to $(cmode) table '$(path)'" , "cmode=%s,path=%s" , force ? "create or replace" : "create" , table_path )); } else { VCursor *curs; rc = VTableCreateCursorWrite ( vtbl, & curs, kcmInsert ); if ( rc != 0 ) LOGERR ( klogInt, rc, "failed to create cursor" ); else { uint32_t idx; rc = VCursorAddColumn ( curs, &idx, "bar" ); if ( rc != 0 ) { PLOGERR ( klogErr, (klogErr, rc, "failed to add column '$(col)' to cursor" , "col=bar" )); } else { rc = VCursorOpen ( curs ); if ( rc != 0 ) LOGERR ( klogErr, rc, "failed to open cursor" ); else { int i; for ( i = 0; i != 10 && rc == 0; ++i ) { rc = VCursorOpenRow ( curs ); if ( rc != 0 ) LOGERR ( klogErr, rc, "failed to open cursor row" ); else { rc_t rc2; uint32_t count = sizeof(buff) - 1; rc = VCursorWrite ( curs, idx, 8, buff, 0, count ); if ( rc != 0 ) { int64_t rid = 0; VCursorRowId ( curs, & rid ); PLOGERR ( klogInt, (klogInt, rc, "failed to write data to row $(row_id)'" , "row_id=%ld" , rid )); break; } if ( rc == 0 ) { rc = VCursorCommitRow ( curs ); if ( rc != 0 ) LOGERR ( klogErr, rc, "failed to commit row" ); } rc2 = VCursorCloseRow ( curs ); if ( rc2 != 0 ) { LOGERR ( klogErr, rc2, "failed to close cursor row" ); if ( rc == 0 ) rc = rc2; } } } if ( GetRCState ( rc ) == rcDone ) rc = 0; if ( rc == 0 ) rc = VCursorCommit ( curs ); } } VCursorRelease ( curs ); } #if 1 if ( rc == 0 ) rc = VTableReindex ( vtbl ); #endif VTableRelease ( vtbl ); } } VSchemaRelease ( schema ); } VDBManagerRelease ( vmgr ); } return rc; }
rc_t correct( const char * obj ) { KDirectory * dir; rc_t rc = KDirectoryNativeDir( &dir ); if ( rc != 0 ) { LOGERR( klogErr, rc, "creation of KDirectory failed" ); } else { VDBManager * vdb_mgr; rc = VDBManagerMakeUpdate ( &vdb_mgr, dir ); if ( rc != 0 ) { LOGERR( klogErr, rc, "creation of VDBManager failed" ); } else { VDatabase * vdb_db; rc = VDBManagerOpenDBUpdate ( vdb_mgr, &vdb_db, NULL, "%s", obj ); if ( rc != 0 ) { LOGERR( klogErr, rc, "vdb: open for update failed" ); } else { KDatabase *kdb; rc = VDatabaseOpenKDatabaseUpdate ( vdb_db, & kdb ); if ( rc != 0 ) { LOGERR( klogErr, rc, "kdb: open for update failed" ); } else { if ( KDatabaseExists ( kdb, kptTable, CONSENSUS ) ) { if ( KDatabaseExists ( kdb, kptTable, PULSE ) ) { OUTMSG(( "table >%s< does already exist in >%s<\n", PULSE, obj )); } else { if ( KDatabaseExists ( kdb, kptTable, SEQUENCE ) ) { rc = KDatabaseRenameTable ( kdb, true, SEQUENCE, PULSE ); if ( rc != 0 ) { LOGERR( klogErr, rc, "kdb: renaming table failed" ); } else { OUTMSG(( "table >%s< renamed to >%s< in >%s<\n", SEQUENCE, PULSE, obj )); } if ( rc == 0 ) { rc = KDatabaseAliasTable ( kdb, CONSENSUS, SEQUENCE ); if ( rc != 0 ) { LOGERR( klogErr, rc, "kdb: creating table-alias failed" ); } else { OUTMSG(( "alias >%s< created for >%s< in >%s<\n", SEQUENCE, CONSENSUS, obj )); } } } } } else { OUTMSG(( "table >%s< does not exist in >%s<\n", CONSENSUS, obj )); } KDatabaseRelease ( kdb ); } VDatabaseRelease( vdb_db ); } VDBManagerRelease( vdb_mgr ); } KDirectoryRelease( dir ); } return rc; }
static rc_t static_read(void) { rc_t rc; VDBManager *vmgr; rc = VDBManagerMakeUpdate ( & vmgr, 0 ); if ( rc != 0 ) LOGERR ( klogInt, rc, "failed to make VDB manager" ); else { const VTable *vtbl; rc = VDBManagerOpenTableRead(vmgr, &vtbl, 0, table_path ); if ( rc != 0 ) { PLOGERR ( klogErr, (klogErr, rc, "failed to $(cmode) table '$(path)'" , "cmode=%s,path=%s" , "open" , table_path )); } else { const VCursor *curs; rc = VTableCreateCursorRead(vtbl, &curs); if (rc == 0) { uint32_t idx; rc = VCursorAddColumn(curs, &idx, "bar"); if (rc == 0) { rc = VCursorOpen(curs); if (rc == 0) { int i; for (i = 0; rc == 0 && i != 10; ++i) { rc = VCursorOpenRow(curs); if (rc == 0) { char buffer[1024]; uint32_t len; rc = VCursorRead(curs, idx, 8, buffer, sizeof(buffer), &len); assert(len == strlen(buff)); assert(memcmp(buff, buffer, len) == 0); } VCursorCloseRow(curs); } } else { PLOGERR ( klogErr, (klogErr, rc, "failed to $(cmode) cursor" , "cmode=open" )); } } else { PLOGERR ( klogErr, (klogErr, rc, "failed to add column $(col)" , "col=bar" )); } VCursorRelease(curs); } else { PLOGERR ( klogErr, (klogErr, rc, "failed to $(cmode) cursor" , "cmode=create" )); } VTableRelease(vtbl); } VDBManagerRelease(vmgr); } return rc; }
rc_t open (param_block * pb) { rc_t rc; rc = KDirectoryNativeDir (&pb->pwd); if (rc) LOGERR (klogFatal, rc, "Failed to open file system"); else { rc = KDirectoryOpenFileRead (pb->pwd, &pb->file, "%s", pb->file_path); if (rc) LOGERR (klogFatal, rc, "Failed to open input file"); else { rc = KMMapMakeRead (&pb->mmap, pb->file); if (rc) LOGERR (klogFatal, rc, "unable to map file"); else { rc = VDBManagerMakeUpdate (&pb->mgr, pb->pwd); if (rc) LOGERR (klogFatal, rc, "Failed to open DB Manager"); else { rc = VDBManagerMakeSchema (pb->mgr, &pb->schema); if (rc) LOGERR (klogFatal, rc, "Failed to create a schema object"); else { VSchemaAddIncludePath (pb->schema, "interfaces"); rc = VSchemaParseFile (pb->schema, "%s", pb->schema_path); if (rc) LOGERR (klogFatal, rc, "Failed to parse schema"); else { rc = VDBManagerCreateTable (pb->mgr, &pb->table, pb->schema, TYPESPEC, kcmCreate, "%s", pb->table_path); if (rc) LOGERR (klogFatal, rc, "Failed to create table"); else { rc = VTableCreateCursorWrite (pb->table, &pb->cursor, kcmCreate); if (rc) LOGERR (klogFatal, rc, "Failed to create cursor"); else { rc = VCursorAddColumn (pb->cursor, &pb->idx, "READ"); if (rc) LOGERR (klogFatal, rc, "Failed to add READ to cursor"); else { rc = VCursorOpen (pb->cursor); if (rc) LOGERR (klogFatal, rc, "Failed to open cursor"); else { rc = write_rows (pb); if (rc == 0) VCursorCommit (pb->cursor); } } VCursorRelease (pb->cursor); } VTableRelease (pb->table); } } VSchemaRelease (pb->schema); } VDBManagerRelease (pb->mgr); } KMMapRelease (pb->mmap); } KFileRelease (pb->file); } KDirectoryRelease (pb->pwd); } 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; }