Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
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;
}
Пример #4
0
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;
}