Exemple #1
0
static
rc_t RefPosMake ( RefPos **objp, const VTable *tbl, const VCursor *native_curs )
{
    rc_t rc;

    /* create the object */
    RefPos *obj = malloc ( sizeof * obj );
    if ( obj == NULL ) {
        rc = RC ( rcXF, rcFunction, rcConstructing, rcMemory, rcExhausted );
    } else {
	obj->curs=NULL;
        BSTreeInit(&obj->tr_range);
        /* open the reference table cursor*/
	  
	if( (rc = AlignRefTableCursor(tbl, native_curs, &obj->curs, NULL)) == 0 ) {
                uint32_t itmp;
                if(  (rc = VCursorAddColumn(obj->curs, &itmp, "(U32)MAX_SEQ_LEN")) == 0 || GetRCState(rc) == rcExists)  {
                    const void *base;
                    uint32_t row_len;
                    rc = VCursorCellDataDirect(obj->curs, 1, itmp, NULL, &base, NULL, &row_len);
                    if(rc == 0) {
                        assert(row_len == 1);
                        memcpy(&obj->max_seq_len, base, 4);
                    }
                }
                if( GetRCObject(rc) == rcColumn && GetRCState(rc) == rcNotFound ) {
		    /*** no MAX_SEQ_LEN means that REF_POS==REF_START **/
		    VCursorRelease(obj->curs);
		    obj->curs = NULL;
                    obj->max_seq_len = 0;
		    obj->name_range_idx = 0;
		    obj->name_idx = 0;
                    rc = 0;
                } else if( rc == 0 ) {
                        /* add columns to cursor */
			rc = VCursorAddColumn(obj->curs, &obj->name_idx, "(utf8)NAME");
			if(rc == 0 || GetRCState(rc) == rcExists)
				rc = VCursorAddColumn(obj->curs, &obj->name_range_idx, "NAME_RANGE");
			if(GetRCState(rc) == rcExists)
				rc = 0;
                }
        }
        if( rc == 0 ) {
            *objp = obj;
        } else {
	    VCursorRelease(obj->curs);
            free(obj);
        }
    }
    return rc;
}
Exemple #2
0
static rc_t test_ref_iterator( trans_ctx *ctx,
                               const char * ref_name, 
                               INSDC_coord_zero ref_pos,
                               INSDC_coord_len ref_len,
                               bool skip_empty,
                               bool nodebug )
{
    rc_t rc;
    ReferenceIterator *ref_iter = NULL;
    struct VCursor const *ref_cursor = NULL;
    struct VCursor const *align_cursor = NULL;
    PlacementRecordExtendFuncs ef;

    /* (1) make the reference-iterator */
    ef.data = ( void * )ctx->almgr;
    ef.destroy = NULL; /* ext_rec_destroy; */
    ef.populate = ext_rec_populate;
    ef.alloc_size = ext_rec_size;
    ef.fixed_size = 0;

    rc = AlignMgrMakeReferenceIterator ( ctx->almgr, &ref_iter, &ef, 0 /* min_mapq*/ );
    if ( rc != 0 )
        LOGERR( klogInt, rc, "AlignMgrMakeReferenceIterator() failed" );

    /* (2) prepare the alignmnet-cursor (for the needs of the callback...)*/
    if ( rc == 0 )
        rc = get_prim_align_cursor( ctx->db, &align_cursor );

    /* (3) all placements to the ref-iter AND WALK THE REFERENCE-ITERATOR! */
    if ( rc == 0 )
    {
        rc = ReferenceIteratorAddPlacements( ref_iter, ctx->ref_obj, ref_pos, ref_len,
                                             ref_cursor, align_cursor, primary_align_ids, NULL );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "ReferenceIteratorAddPlacements() failed" );
        else
        {
            /* =============================================== */
            rc = walk_ref_iter( ref_iter, skip_empty, nodebug );
            /* =============================================== */
        }
    }

    if ( ref_cursor != NULL ) VCursorRelease ( ref_cursor );
    if ( align_cursor != NULL ) VCursorRelease ( align_cursor );
    if ( ref_iter != NULL ) ReferenceIteratorRelease( ref_iter );
    return rc;
}
Exemple #3
0
/* detect min and max spot-id from a temp. cursor */
static rc_t SRATableGetMinMax( SRATable * self )
{
    const VCursor *temp_cursor;
    rc_t rc;

    assert( self != NULL );
    assert( self->vtbl != NULL);
    rc = VTableCreateCursorRead( self->vtbl, &temp_cursor );
    if ( rc == 0 )
    {
        uint32_t idx;
        rc = VCursorAddColumn ( temp_cursor, &idx, "READ" );
        if ( rc == 0 )
        {
            rc = VCursorOpen( temp_cursor );
            if ( rc == 0 )
            {
                int64_t  first;
                uint64_t count;
                rc = VCursorIdRange( temp_cursor, 0, &first, &count );
                if ( rc == 0 )
                {
                    self->min_spot_id = first;
                    self->max_spot_id = first + count;
                    self->spot_count = count;
                }
            }
        }
        VCursorRelease( temp_cursor );
    }
    return rc;
}
Exemple #4
0
static uint64_t get_rowcount( const VTable * tab )
{
    uint64_t res = 0;
    col_defs *my_col_defs;
    if ( vdcd_init( &my_col_defs, 1024 ) )
    {
        if ( vdcd_extract_from_table( my_col_defs, tab ) > 0 )
        {
            const VCursor * cur;
            rc_t rc = VTableCreateCursorRead( tab, &cur );
            if ( rc == 0 )
            {
                if ( vdcd_add_to_cursor( my_col_defs, cur ) )
                {
                    rc = VCursorOpen( cur );
                    if ( rc == 0 )
                    {
                        uint32_t idx;
                        if ( vdcd_get_first_none_static_column_idx( my_col_defs, cur, &idx ) )
                        {
                            int64_t first;
                            rc = VCursorIdRange( cur, idx, &first, &res );
                        }
                    }
                }
                VCursorRelease( cur );
            }
        }
        vdcd_destroy( my_col_defs );
    }
    return res;
}
Exemple #5
0
static rc_t report_ref_table( const VDBManager *vdb_mgr, const char * path, int64_t start, int64_t stop )
{
    const VDatabase* db;
    rc_t rc = VDBManagerOpenDBRead ( vdb_mgr, &db, NULL, "%s", path );
    if ( rc != 0 )
    {
        (void)LOGERR( klogErr, rc, "cannot open vdb-database" );
    }
    else
    {
        const VTable* tb;
        rc = VDatabaseOpenTableRead ( db, &tb, "REFERENCE" );
        if ( rc != 0 )
        {
            (void)LOGERR( klogErr, rc, "cannot open REFERENCE-table" );
        }
        else
        {
            const VCursor *cur;
            rc = VTableCreateCursorRead ( tb, &cur );
            if ( rc != 0 )
            {
                (void)LOGERR( klogErr, rc, "cannot open REFERENCE-cursor" );
            }
            else
            {
                rc = report_ref_cursor( cur, start, stop );
                VCursorRelease( cur );
            }
            VTableRelease ( tb );
        }
        VDatabaseRelease ( db );
    }
    return rc;
}
Exemple #6
0
static rc_t ref_walker_add_iterator( struct ref_walker * self, const char * ref_name,
                        uint64_t start, uint64_t end, const char * src_name, Vector * cur_id_vector,
                        const VDatabase *db, const ReferenceObj * ref_obj, ReferenceIterator * ref_iter,
                        const char * table_name, align_id_src id_selector )
{
    walker_col_ids * cursor_ids;
    rc_t rc = make_cursor_ids( cur_id_vector, &cursor_ids );
    if ( rc == 0 )
    {
        const VTable *tbl;
        rc_t rc = VDatabaseOpenTableRead ( db, &tbl, table_name );
        if ( rc == 0 )
        {
            const VCursor *cursor;
            rc = add_required_columns( self, tbl, &cursor, cursor_ids );
            if ( rc == 0 )
            {
                rc = ReferenceIteratorAddPlacements ( ref_iter,             /* the outer ref-iter */
                                                      ref_obj,              /* the ref-obj for this chromosome */
                                                      start - 1,            /* start ( zero-based ) */
                                                      ( end - start ) + 1,  /* length */
                                                      NULL,                 /* ref-cursor */
                                                      cursor,               /* align-cursor */
                                                      id_selector,          /* which id's */
                                                      self->spot_group,     /* what read-group */
                                                      cursor_ids            /* placement-context */
                                                     );
                VCursorRelease( cursor );
            }
            VTableRelease ( tbl );
        }
    }
    return rc;
}
static
rc_t RefNameMake ( RefName **objp, const VTable *tbl, const VCursor *native_curs )
{
    rc_t rc;

    /* create the object */
    RefName *obj = malloc ( sizeof * obj );
    if ( obj == NULL ) {
        rc = RC ( rcXF, rcFunction, rcConstructing, rcMemory, rcExhausted );
    } else {
	obj->curs=NULL;
        /* open the reference cursor */
	rc = AlignRefTableCursor(tbl, native_curs, &obj->curs, NULL);
	if(rc == 0){
                /* add columns to cursor */
		rc = VCursorAddColumn(obj->curs, &obj->name_idx, "(utf8)REF_NAME");
		if( GetRCObject(rc) == rcColumn && GetRCState(rc) == rcNotFound ) {
			rc = VCursorAddColumn(obj->curs, &obj->name_idx, "(utf8)NAME");
		}
		if(GetRCState(rc) == rcExists){
			rc = 0;
		}
                if( rc == 0 ) {
                    *objp = obj;
                    return 0;
                }
                VCursorRelease ( obj -> curs );
        }
        free ( obj );
    }
    return rc;
}
Exemple #8
0
static void get_string_cell( char * buffer, size_t buffer_size, const VTable * tab, int64_t row, const char * column )
{
    if ( has_col( tab, column ) )
    {
        const VCursor * cur;
        rc_t rc = VTableCreateCursorRead( tab, &cur );
        if ( rc == 0 )
        {
            uint32_t idx;
            rc = VCursorAddColumn( cur, &idx, column );
            if ( rc == 0 )
            {
                rc = VCursorOpen( cur );
                if ( rc == 0 )
                {
                    const char * src;
                    uint32_t row_len;
                    rc = VCursorCellDataDirect( cur, row, idx, NULL, (const void**)&src, NULL, &row_len );
                    if ( rc == 0 )
                    {
                        size_t num_writ;
                        string_printf( buffer, buffer_size, &num_writ, "%.*s", row_len, src );
                    }
                }
            }
            VCursorRelease( cur );
        }
    }
}
Exemple #9
0
rc_t close_cursor (const VTable * table, const VCursor * cursor)
{
    rc_t rc1, rc2;
    rc1 = VCursorRelease (cursor);
    rc2 = VTableRelease (table);
    return (rc1?rc1:rc2);
}
Exemple #10
0
rc_t open_read_cursor (const VTable * table, const VCursor ** cursor,
                       uint32_t * idx1, uint32_t * idx2, uint32_t * idx3, uint32_t * idx4,
                       const char * name1, const char * name2, const char * name3, const char * name4)
{
    rc_t rc;

    rc = VTableCreateCursorRead (table, cursor);
    if (rc)
    {
        LOGERR (klogErr, rc, "Failed to create Cursor");
    }
    else
    {
        do
        {
            rc = VCursorAddColumn (*cursor, idx1, name1);
            if (rc)
            {
                pLOGERR (klogErr, rc, "Failed to add column $(C)", PLOG_S(C), name1);
                break;
            }

            rc = VCursorAddColumn (*cursor, idx2, name2);
            if (rc)
            {
                pLOGERR (klogErr, rc, "Failed to add column $(C)", PLOG_S(C), name2);
                break;
            }

            rc = VCursorAddColumn (*cursor, idx3, name3);
            if (rc)
            {
                pLOGERR (klogErr, rc, "Failed to add column $(C)", PLOG_S(C), name3);
                break;
            }

            rc = VCursorAddColumn (*cursor, idx4, name4);
            if (rc)
            {
                pLOGERR (klogErr, rc, "Failed to add column $(C)", PLOG_S(C), name4);
                break;
            }

            rc = VCursorOpen (*cursor);
            if (rc)
            {
                LOGERR (klogErr, rc, "Failed to open cursor");
                break;
            }

            return 0;
        }
        while (0);

        VCursorRelease (*cursor);
    }
    *idx1 = *idx2 = *idx3 = *idx4 = 0;
    *cursor = NULL;
    return rc;
}
Exemple #11
0
static rc_t OpenTableAndCursor(VDatabase *db, VTable **ptbl, VCursor **pcurs, uint32_t cid[], unsigned ncols)
{
    rc_t rc = VDatabaseCreateTable(db, ptbl, "READ_STATS",
                                   kcmCreate | kcmMD5, "READ_STATS");
    
    if (rc == 0) {
        rc = VTableColumnCreateParams(*ptbl, kcmCreate, kcsCRC32, 0);
        if (rc == 0) {
            rc = VTableCreateCursorWrite(*ptbl, &pcurs, kcmInsert);
            if (rc == 0) {
                unsigned i;
                
                for (i = 0; i < ncols && rc == 0; ++i) {
                    rc = VCursorAddColumn(*pcurs, &cid[i], column_name[i]);
                }
                if (rc == 0) {
                    rc = VCursorOpen(*pcurs);
                    if (rc == 0)
                        return 0;
                }
                VCursorRelease(*pcurs);
            }
        }
        VTableRelease(*ptbl);
    }
    *pcurs = NULL;
    *ptbl = NULL;
    return rc;
}
Exemple #12
0
/* ListColumns
 *  list writable column names
 *
 *  "names" [ OUT ] - return parameter for namelist
 *
 *  availability: v2.1
 */
static
rc_t list_writable_columns ( VTable *self )
{
    rc_t rc;
    VCursor *curs;

    if ( self -> read_only )
    {
        self -> write_col_cache_valid = true;
        return 0;
    }

    rc = VTableCreateCursorWriteInt ( self, & curs, kcmInsert, false );
    if (  rc == 0 )
    {
	/* no need for schema-based triggers to fire **/
	VCursorSuspendTriggers ( curs );
        /* let this private VCursor-function list the columns */
        rc = VCursorListWritableColumns ( curs, & self -> write_col_cache );
        VCursorRelease ( curs );
        if ( rc == 0 )
            self -> write_col_cache_valid = true;
    }

    return rc;
}
Exemple #13
0
static void CC whack_ref_node( BSTNode *n, void *data )
{
    ref_node * node = ( ref_node * )n;
    bool * info = ( bool * )data;

    if ( *info )
    {
        OUTMSG(( "node >%S< used for %lu bytes (%lu active)\n",
                  node->name, node->bytes_requested, node->active_positions ));
    }

    if ( node->cur != NULL )
    {
        VCursorRelease( node->cur );
    }
    if ( node->tab != NULL )
    {
        VTableRelease( node->tab );
    }
    if ( node->name != NULL )
    {
        StringWhack ( node->name );
    }
    free( n );
}
Exemple #14
0
static const char * get_platform( const VTable * tab )
{
    const char * res = PT_NONE;
    const VCursor * cur;
    rc_t rc = VTableCreateCursorRead( tab, &cur );
    if ( rc == 0 )
    {
        uint32_t idx;
        rc = VCursorAddColumn( cur, &idx, "PLATFORM" );
        if ( rc == 0 )
        {
            rc = VCursorOpen( cur );
            if ( rc == 0 )
            {
                const uint8_t * pf;
                rc = VCursorCellDataDirect( cur, 1, idx, NULL, (const void**)&pf, NULL, NULL );
                if ( rc == 0 )
                {
                    res = vdcd_get_platform_txt( *pf );
                }
            }
        }
        VCursorRelease( cur );
    }
    return res;
}
Exemple #15
0
static
rc_t RestoreReadMake ( RestoreRead **objp, const VTable *tbl, const VCursor* native_curs )
{
    rc_t rc;
    char name[]="PRIMARY_ALIGNMENT";

    /* create the object */
    RestoreRead *obj = malloc ( sizeof * obj );
    memset(obj,0,sizeof * obj);
    if ( obj == NULL )
    {
		*objp=0;
        rc = RC ( rcXF, rcFunction, rcConstructing, rcMemory, rcExhausted );
    }
    else
	{
		rc = VCursorLinkedCursorGet(native_curs,name,&obj->curs);
		if(rc == 0){
			VCursorAddRef(obj->curs);
		} else {
			/* get at the parent database */
			const VDatabase *db;
			rc = VTableOpenParentRead ( tbl, & db );
			if ( rc == 0 )
			{
				const VTable *patbl;
				/* open the primary alignment table */
				rc = VDatabaseOpenTableRead ( db, & patbl, name );
				VDatabaseRelease ( db );
				if ( rc == 0 )
				{
					/* create a cursor */
					rc = VTableCreateCachedCursorRead( patbl, &obj->curs, 32*1024*1024UL );
					VTableRelease ( patbl );
					if ( rc == 0 )
					{
						/* add columns to cursor */
						rc = VCursorAddColumn ( obj -> curs, & obj -> read_idx, "( INSDC:4na:bin ) READ" );
						if ( rc == 0 )
						{
							rc = VCursorOpen ( obj -> curs );
							if ( rc == 0 )
							{
								VCursorLinkedCursorSet( native_curs, name, obj->curs );
								SUB_DEBUG( ( "SUB.Make in 'seq-restore-read.c'\n" ) );
								* objp = obj;
								return 0;
							}
						}
						VCursorRelease ( obj -> curs );
					}
				}
			}
			free ( obj );
		}
	}
    return rc;
}
Exemple #16
0
static 
rc_t SaveObjects ( const ObjectTable* data,  VDatabase* db )
{
    VTable* tbl;
    rc_t rc = VDatabaseCreateTable(db, &tbl, "object_inst", kcmCreate | kcmMD5, "OBJECTS");
    if (rc == 0)
    {
        rc_t rc2;
        VCursor *cur;
        rc = VTableCreateCursorWrite( tbl, &cur, kcmInsert );
        if (rc == 0)
        {
            uint32_t id_idx, name_idx, proj_idx, dname_idx, size_idx, csum_idx, enc_idx;
            if (rc == 0) rc = VCursorAddColumn( cur, &id_idx,    "id" );
            if (rc == 0) rc = VCursorAddColumn( cur, &name_idx,  "name" );
            if (rc == 0) rc = VCursorAddColumn( cur, &proj_idx,    "project" );
            if (rc == 0) rc = VCursorAddColumn( cur, &dname_idx, "display_name" );
            if (rc == 0) rc = VCursorAddColumn( cur, &size_idx,  "size" );
            if (rc == 0) rc = VCursorAddColumn( cur, &csum_idx,  "checksum" );
            if (rc == 0) rc = VCursorAddColumn( cur, &enc_idx,   "encryption_key" );

            if (rc == 0)
            {
                rc = VCursorOpen( cur );
                if (rc == 0)
                {
                    const Object* obj = (const Object*)BSTreeFirst(data);
                    while (rc == 0 && obj != NULL)
                    {
                        rc = VCursorOpenRow( cur );
                        
                        if (rc == 0) rc = VCursorWrite( cur, id_idx,    sizeof(obj->id) * 8,                   &obj->id,                  0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, name_idx,  StringLength(obj->name) * 8,           obj->name->addr,           0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, proj_idx,  StringLength(obj->project) * 8,        obj->project->addr,        0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, dname_idx, StringLength(obj->display_name) * 8,   obj->display_name->addr,   0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, size_idx,  sizeof(obj->size) * 8,                 &obj->size,                0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, csum_idx,  StringLength(obj->encryption_key) * 8, obj->encryption_key->addr, 0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, enc_idx,   StringLength(obj->encryption_key) * 8, obj->encryption_key->addr, 0, 1);
                        
                        if (rc == 0) rc = VCursorCommitRow( cur );
                        if (rc == 0) rc = VCursorCloseRow( cur );
                        
                        obj = (const Object*)BSTNodeNext(&obj->dad);
                    }
                    if (rc == 0) rc = VCursorCommit( cur );
                }
            }
            rc2 = VCursorRelease(cur);
            if (rc == 0)
                rc = rc2;
        }
        
        rc2 = VTableRelease(tbl);
        if (rc == 0)
            rc = rc2;
    }
    return rc;
}
Exemple #17
0
rc_t VTableCreateCursorWriteInt ( VTable *self, VCursor **cursp, KCreateMode mode, bool create_thread )
{
    rc_t rc;

    if ( cursp == NULL )
        rc = RC ( rcVDB, rcCursor, rcCreating, rcParam, rcNull );
    else
    {
        if ( self == NULL )
            rc = RC ( rcVDB, rcTable, rcAccessing, rcSelf, rcNull );
        else if ( self -> read_only )
            rc = RC ( rcVDB, rcCursor, rcCreating, rcTable, rcReadonly );
#if VCURSOR_WRITE_MODES_SUPPORTED
#error "expecting kcmInsert mode only"
#else
        else if ( mode != kcmInsert )
            rc = RC ( rcVDB, rcCursor, rcCreating, rcMode, rcUnsupported );
#endif
        else
        {
            VCursor *curs;

#if LAZY_OPEN_COL_NODE
            if ( self -> col_node == NULL )
                KMetadataOpenNodeUpdate ( self -> meta, & self -> col_node, "col" );
#endif
            rc = VCursorMake ( & curs, self );
            if ( rc == 0 )
            {
                rc = VCursorSupplementSchema ( curs );
#if VCURSOR_FLUSH_THREAD
                if ( rc == 0 && create_thread )
                {
                    rc = KLockMake ( & curs -> flush_lock );
                    if ( rc == 0 )
                        rc = KConditionMake ( & curs -> flush_cond );
                    if ( rc == 0 )
                        rc = KThreadMake ( & curs -> flush_thread, run_flush_thread, curs );
                }
		if(rc == 0)
			rc = VCursorLaunchPagemapThread(curs);
#endif
                if ( rc == 0 )
                {
                    * cursp = curs;
                    return 0;
                }

                VCursorRelease ( curs );
            }
        }

        * cursp = NULL;
    }

    return rc;
}
Exemple #18
0
static
void CC RestoreReadWhack ( void *obj )
{
    RestoreRead * self = obj;
    if ( self != NULL )
    {
        VCursorRelease ( self -> curs );
        free ( self );
    }
}
Exemple #19
0
static
void CC RefSeqIDWhack ( void *obj )
{
    RefSeqID * self = obj;
    if ( self != NULL )
    {
        VCursorRelease ( self -> curs );
        free ( self );
    }
}
static rc_t DbDestroy(Db* db)
{
    rc_t rc = 0;

    assert(db);

    {
        rc_t rc2 = VCursorRelease(db->rCursor);
        db->rCursor = NULL;
        if (rc == 0)
        {   rc = rc2; }
    }

    {
        rc_t rc2 = VCursorRelease(db->wCursor);
        db->wCursor = NULL;
        if (rc == 0)
        {   rc = rc2; }
    }

    {
        rc_t rc2 = VTableRelease(db->tbl);
        db->tbl = NULL;
        if (rc == 0)
        {   rc = rc2; }
    }

    if (db->locked) {
        rc_t rc2 = VDBManagerLock(db->mgr, "%s", db->table);
        if (rc == 0)
        {   rc = rc2; }
    }

    {
        rc_t rc2 = VDBManagerRelease(db->mgr);
        db->mgr = NULL;
        if (rc == 0)
        {   rc = rc2; }
    }

    return rc;
}
Exemple #21
0
static
void CC RefPosWhack ( void *obj )
{
    RefPos * self = obj;
    if ( self != NULL )
    {
    	BSTreeWhack( &self->tr_range, bst_range_free, NULL );
        VCursorRelease ( self -> curs );
        free ( self );
    }
}
Exemple #22
0
/* vtblcp
 */
static
rc_t vtblcp ( const vtblcp_parms *pb, const VTable *stbl, VTable *dtbl, const Vector *v )
{
    const VCursor *scurs;
    rc_t rc = VTableCreateCursorRead ( stbl, & scurs );
    if ( rc != 0 )
        LOGERR ( klogInt, rc, "failed to create empty destination cursor" );
    else
    {
        VCursor *dcurs;
        rc = VTableCreateCursorWrite ( dtbl, & dcurs, kcmInsert );
        if ( rc != 0 )
            LOGERR ( klogInt, rc, "failed to create empty destination cursor" );
        else
        {
            uint32_t count = VectorLength ( v );
            vtblcp_column_map *cm = malloc ( sizeof *cm * count );
            if ( cm == NULL )
            {
                rc = RC ( rcExe, rcVector, rcAllocating, rcMemory, rcExhausted );
                LOGERR ( klogInt, rc, "failed to create column index map" );
            }
            else
            {
                uint32_t rd_filt;
                rc = populate_cursors ( dtbl, dcurs, scurs, cm, v, & rd_filt );

                if ( rc == 0 )
                    rc = copy_table ( pb, dcurs, scurs, cm, count, rd_filt );

                free ( cm );
            }

            VCursorRelease ( dcurs );
        }
            
        VCursorRelease ( scurs );
    }

    return rc;
}
Exemple #23
0
/* Commit
 *  commit all changes
 */
LIB_EXPORT rc_t CC SRATableCommit( SRATable *self ) {
    rc_t rc;
    
    if (self == NULL)
        return RC(RC_MODULE, RC_TARGET, rcCommitting, rcSelf, rcNull);
    rc = VCursorCommit(self->curs);
    VCursorRelease(self->curs);
    self->curs = NULL;
    if (rc == 0)
        rc = VTableReindex(self->vtbl);
    return rc;
}
Exemple #24
0
static rc_t vdb_fastq_tbl( const p_dump_context ctx,
                           const VTable * tbl,
                           fastq_ctx * fctx )
{
    rc_t rc = vdb_prepare_cursor( ctx, tbl, fctx );
    DISP_RC( rc, "the table lacks READ and/or QUALITY column" );
    if ( rc == 0 )
    {
        int64_t  first;
        uint64_t count;
        rc = VCursorIdRange( fctx->cursor, fctx->idx_read, &first, &count );
        DISP_RC( rc, "VCursorIdRange() failed" );
        if ( rc == 0 )
        {
            /* if the user did not specify a row-range, take all rows */
            if ( vdn_range_defined( ctx->row_generator ) == false )
            {
                vdn_set_range( ctx->row_generator, first, count );
            }
            /* if the user did specify a row-range, check the boundaries */
            else
            {
                vdn_check_range( ctx->row_generator, first, count );
            }

            if ( vdn_range_defined( ctx->row_generator ) )
            {
                if ( ctx->format == df_fastq )
                {
                    if ( fctx->idx_name == INVALID_COLUMN)
                        rc = vdb_fastq_loop_without_name( ctx, fctx ); /* <--- */
                    else
                        rc = vdb_fastq_loop_with_name( ctx, fctx ); /* <--- */
                }
                else if ( ctx->format == df_fasta )
                {
                    if ( ctx->max_line_len == 0 )
                        ctx->max_line_len = DEF_FASTA_LEN;
                    if ( fctx->idx_name == INVALID_COLUMN)
                        rc = vdb_fasta_loop_without_name( ctx, fctx ); /* <--- */
                    else
                        rc = vdb_fasta_loop_with_name( ctx, fctx ); /* <--- */
                }
            }
            else
            {
                rc = RC( rcExe, rcDatabase, rcReading, rcRange, rcEmpty );
            }
        }
        VCursorRelease( fctx->cursor );
    }
    return rc;
}
static rc_t read_statistic_from_table( statistic * data,
                                       KDirectory *dir,
                                       context *ctx,
                                       const VDatabase *my_database,
                                       const char *table_name )
{
    const VTable *my_table;
    rc_t rc = VDatabaseOpenTableRead( my_database, &my_table, "%s", table_name );
    if ( rc != 0 )
    {
        LogErr( klogInt, rc, "VDatabaseOpenTableRead() failed\n" );
    }
    else
    {
        const VCursor *my_cursor;
        rc = VTableCreateCursorRead( my_table, &my_cursor );
        if ( rc != 0 )
            LogErr( klogInt, rc, "VTableCreateCursorRead() failed\n" );
        else
        {
/*
            spot_pos sequence;

            rc = make_spot_pos( &sequence, my_database );
            if ( rc == 0 )
            {
*/
                statistic_reader reader;

/*
                rc = make_statistic_reader( &reader, &sequence, dir, my_cursor,
                            ctx->exclude_file_path, ctx->info );
*/
                rc = make_statistic_reader( &reader, NULL, dir, my_cursor,
                            ctx->exclude_file_path, ctx->info );

                if ( rc == 0 )
                {
                    /* ******************************************************* */
                    rc = read_loop( data, ctx, &reader, my_cursor );
                    /* ******************************************************* */
                    whack_reader( &reader );
                }
/*
                whack_spot_pos( &sequence );
            }
*/
            VCursorRelease( my_cursor );
        }
        VTableRelease( my_table );
    }
    return rc;
}
Exemple #26
0
void SRATableDestroy ( SRATable *self )
{
    VectorWhack ( & self -> wcol, column_release, NULL );
    VCursorRelease(self->curs);
    KMetadataRelease ( self -> meta );
    VTableRelease ( self -> vtbl );
    SRAMgrSever ( self -> mgr );

    memset(self, 0, sizeof *self);

    free ( self );
}
Exemple #27
0
static 
rc_t SaveProjects( const ProjectTable* data, VDatabase* db )
{
    VTable* tbl;
    rc_t rc = VDatabaseCreateTable(db, &tbl, "project_inst", kcmCreate | kcmMD5, "PROJECTS");
    if (rc == 0)
    {
        rc_t rc2;
        VCursor *cur;
        rc = VTableCreateCursorWrite( tbl, &cur, kcmInsert );
        if (rc == 0)
        {
            uint32_t id_idx, name_idx, dl_idx, enc_idx;
            rc = VCursorAddColumn( cur, &id_idx, "id" );
            rc = VCursorAddColumn( cur, &name_idx, "name" );
            rc = VCursorAddColumn( cur, &dl_idx, "download_ticket" );
            rc = VCursorAddColumn( cur, &enc_idx, "encryption_key" );
            if (rc == 0)
            {
                rc = VCursorOpen( cur );
                if (rc == 0)
                {
                    const Project* p = (const Project*)BSTreeFirst(data);
                    while (rc == 0 && p != NULL)
                    {
                        rc = VCursorOpenRow( cur );
                        
                        if (rc == 0) rc = VCursorWrite( cur, id_idx,    sizeof(p->id) * 8,                      &p->id,                     0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, name_idx,  StringLength(p->name) * 8,              p->name->addr,              0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, dl_idx,    StringLength(p->download_ticket) * 8,   p->download_ticket->addr,   0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, enc_idx,   StringLength(p->encryption_key) * 8,    p->encryption_key->addr,    0, 1);
                        
                        if (rc == 0) rc = VCursorCommitRow( cur );
                        if (rc == 0) rc = VCursorCloseRow( cur );
                        
                        p = (const Project*)BSTNodeNext(&p->dad);
                    }
                    if (rc == 0)
                        rc = VCursorCommit( cur );
                }
            }
            rc2 = VCursorRelease(cur);
            if (rc == 0)
                rc = rc2;
        }
        
        rc2 = VTableRelease(tbl);
        if (rc == 0)
            rc = rc2;
    }
    return rc;
}
Exemple #28
0
bool vdcd_extract_from_table( col_defs* defs, const VTable *my_table )
{
    bool col_defs_found = false;
    KNamelist *names;
    rc_t rc = VTableListCol( my_table, &names );
    DISP_RC( rc, "VTableListCol() failed" );
    if ( rc == 0 )
    {
        const VCursor *my_cursor;
        rc = VTableCreateCursorRead( my_table, &my_cursor );
        DISP_RC( rc, "VTableCreateCursorRead() failed" );
        if ( rc == 0 )
        {
            uint32_t n;
            uint32_t found = 0;
            rc = KNamelistCount( names, &n );
            DISP_RC( rc, "KNamelistCount() failed" );
            if ( rc == 0 )
            {
                uint32_t i;
                for ( i = 0; i < n && rc ==0; ++i )
                {
                    const char *col_name;
                    rc = KNamelistGet( names, i, &col_name );
                    DISP_RC( rc, "KNamelistGet() failed" );
                    if ( rc == 0 )
                    {
                        p_col_def def = vdcd_append_col( defs, col_name );
                        rc = VCursorAddColumn( my_cursor, &(def->idx), def->name );
                        DISP_RC( rc, "VCursorAddColumn() failed" );
                        if ( rc == 0 )
                        {
                            rc = VCursorDatatype( my_cursor, def->idx,
                                      &(def->type_decl), &(def->type_desc) );
                            DISP_RC( rc, "VCursorDatatype() failed" );
                            if ( rc == 0 )
                            {
                                found++;
                            }
                        }
                    }
                }
                col_defs_found = ( found > 0 );
            }
            rc = VCursorRelease( my_cursor );
            DISP_RC( rc, "VCursorRelease() failed" );
        }
        rc = KNamelistRelease( names );
        DISP_RC( rc, "KNamelistRelease() failed" );
    }
    return col_defs_found;
}
Exemple #29
0
static
void CC Read_Restorer_Whack ( void *obj )
{
    Read_Restorer * self = obj;
    if ( self != NULL )
    {
        VCursorRelease ( self -> curs );
#if READ_RESTORER_VERSION == 2
        rr_store_release ( self -> read_store );
#endif
        free ( self );
    }
}
Exemple #30
0
/*
 * calls VTableListReadableColumns to get a list of all column-names of the table
 * creates a temporary read-cursor to test and get the column-type
 * walks the KNamelist with the available column-names
 * tries to add every one of them to the temp. cursor
 * if the column can be added to the cursor, it is appended
 * to the column-definition list
*/
rc_t col_defs_extract_from_table( col_defs* defs, const VTable *table )
{
    KNamelist *names;
    rc_t rc;

    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );
    if ( table == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull );

    rc = VTableListReadableColumns( table, &names );
    DISP_RC( rc, "col_defs_extract_from_table:VTableListReadableColumns() failed" );
    if ( rc == 0 )
    {
        const VCursor *cursor;
        rc = VTableCreateCursorRead( table, &cursor );
        DISP_RC( rc, "col_defs_extract_from_table:VTableCreateCursorRead() failed" );
        if ( rc == 0 )
        {
            uint32_t count;
            rc = KNamelistCount( names, &count );
            DISP_RC( rc, "col_defs_extract_from_table:KNamelistCount() failed" );
            if ( rc == 0 )
            {
                uint32_t idx;
                for ( idx = 0; idx < count && rc == 0; ++idx )
                {
                    const char *name;
                    rc = KNamelistGet( names, idx, &name );
                    DISP_RC( rc, "col_defs_extract_from_table:KNamelistGet() failed" );
                    if ( rc == 0 )
                    {
                        uint32_t temp_idx;
                        rc_t rc1 = VCursorAddColumn( cursor, &temp_idx, "%s", name );
                        DISP_RC( rc1, "col_defs_extract_from_table:VCursorAddColumn() failed" );
                        if ( rc1 == 0 )
                        {
                            rc = col_defs_append_col( defs, name );
                            DISP_RC( rc, "col_defs_extract_from_table:col_defs_append_col() failed" );
                        }
                    }
                }
            }
            rc = VCursorRelease( cursor );
            DISP_RC( rc, "col_defs_extract_from_table:VCursorRelease() failed" );
        }
        rc = KNamelistRelease( names );
        DISP_RC( rc, "col_defs_extract_from_table:KNamelistRelease() failed" );
    }
    return rc;
}