Esempio n. 1
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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
static rc_t report_ref_cursor( const VCursor *cur, int64_t start, int64_t stop )
{
    report_row_ctx row_ctx;
    rc_t rc = VCursorAddColumn ( cur, &row_ctx.prim_idx, "PRIMARY_ALIGNMENT_IDS" );
    if ( rc != 0 )
    {
        (void)LOGERR( klogErr, rc, "cannot add column >PRIMARY_ALIGNMENT_IDS<" );
    }
    else
    {
        rc = VCursorAddColumn ( cur, &row_ctx.sec_idx, "SECONDARY_ALIGNMENT_IDS" );
        if ( rc != 0 )
        {
            (void)LOGERR( klogErr, rc, "cannot add column >SECONDARY_ALIGNMENT_IDS<" );
        }
        else
        {
            rc = VCursorOpen ( cur );
            if ( rc != 0 )
            {
                (void)LOGERR( klogErr, rc, "cannot open REFERENCE-CURSOR" );
            }
            else
            {
                for ( row_ctx.row_id = start; rc == 0 && row_ctx.row_id <= stop; ++row_ctx.row_id )
                {
                    rc = report_ref_row( cur, &row_ctx );
                }
            }
        }
    }
    return rc;
}
Esempio n. 4
0
static rc_t get_prim_align_cursor( const VDatabase *db, const VCursor **curs )
{
    const VTable *tbl;
    rc_t rc = VDatabaseOpenTableRead ( db, &tbl, "PRIMARY_ALIGNMENT" );
    if ( rc != 0 )
        LOGERR( klogInt, rc, "VDatabaseOpenTableRead(PRIMARY_ALIGNMENT) failed" );
    else
    {
        rc = VTableCreateCursorRead ( tbl, curs );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "VTableCreateCursorRead(tab=PRIMARY_ALIGNMENT) failed" );
        else
        {
            uint32_t throw_away_idx;
            rc = VCursorAddColumn ( *curs, &throw_away_idx, "QUALITY" );
            if ( rc != 0 )
                LOGERR( klogInt, rc, "VTableCreateCursorRead(QUALITY) failed" );
            else
            {
                rc = VCursorAddColumn ( *curs, &throw_away_idx, "REF_ORIENTATION" );
                if ( rc != 0 )
                    LOGERR( klogInt, rc, "VTableCreateCursorRead(REF_ORIENTATION) failed" );
            }
        }
        VTableRelease ( tbl );
    }
    return rc;
}
Esempio n. 5
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;
}
Esempio n. 6
0
/* GetSpotId
 *  convert spot name to spot id
 *
 *  "id" [ OUT ] - return parameter for min(spot_id)-max(spot_id)
 *
 *  "spot_name" [ IN ] - external spot name string
 *  in platform canonical format.
 */
LIB_EXPORT rc_t CC SRATableGetSpotId ( const SRATable *self,
        spotid_t *rslt, const char *spot_name )
{
    rc_t rc;
    if( self == NULL || spot_name == NULL){
        rc=RC(rcSRA, rcTable, rcListing, rcSelf, rcName);
    } else {
        rc=VCursorParamsSet((struct VCursorParams*)self->curs,"QUERY_BY_NAME" ,spot_name);
        if( rc == 0) {
            struct {
                uint64_t start_id;
                uint64_t id_count;
                int64_t x;
                int64_t y;
            } out;
            uint32_t idx,len;
            rc = VCursorAddColumn(self->curs, &idx, "SPOT_IDS_FOUND");
            if( rc == 0 || GetRCState(rc) == rcExists){
                rc = VCursorReadDirect(self->curs,1,idx,sizeof(out) * 8,&out, 1 , &len);
                if ( rc == 0 ) {
                    if(out.id_count==1) {
                        if(rslt) *rslt=out.start_id;
                        return 0;
                    } else if(out.id_count > 1) { /*** doing table range scan in Name space - not relying on X and Y***/
                        uint32_t x_idx;
                        rc = VCursorAddColumn(self->curs, &x_idx, "X");
                        if( rc == 0 || GetRCState(rc) == rcExists){
                            uint32_t y_idx;
                            rc = VCursorAddColumn(self->curs, &y_idx, "Y");
                            if(rc == 0 || GetRCState(rc) == rcExists){
                                spotid_t rowid;
                                for(rowid = out.start_id; rowid < out.start_id + out.id_count; rowid ++){
                                    int32_t x,y;
                                    rc = VCursorReadDirect(self->curs,rowid,x_idx,32,&x,1, &len);
                                    if(rc == 0){
                                        rc = VCursorReadDirect(self->curs,rowid,y_idx,32,&y,1, &len);
                                        if(rc == 0 && x==out.x && y==out.y){
                                            if(rslt) *rslt=rowid;
                                            return 0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    rc = RC ( rcSRA, rcIndex, rcSearching, rcColumn, rcNotFound );
                }
            }
        }
    }
    return rc;
}
Esempio n. 7
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;
}
Esempio n. 8
0
/*
 * adds all columns marked with to_copy == true to the cursor
*/
rc_t col_defs_add_to_wr_cursor( col_defs* defs, const VCursor* cursor, bool show )
{
    uint32_t idx, len;

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

    len = VectorLength( &(defs->cols) );
    for ( idx = 0;  idx < len; ++idx )
    {
        p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
        if ( col != NULL )
            if ( col->to_copy && col->dst_cast != NULL )
            {
                rc_t rc = VCursorAddColumn( cursor, &(col->dst_idx), "%s", col->dst_cast );
                col->to_copy = ( rc == 0 );
                if ( show )
                {
                    if ( col->to_copy )
                        KOutMsg( "added to wr-cursor: >%s<\n", col->name );
                    else
                        KOutMsg( "cannot add >%s<\n", col->name );
                }
            }
    }
    return 0;
}
Esempio n. 9
0
static void CC vdcd_add_1_to_cursor( void *item, void *data )
{
    rc_t rc;
    p_col_def my_col_def = (p_col_def)item;
    p_add_2_cur_context ctx = (p_add_2_cur_context)data;

    if ( my_col_def == NULL ) return;
    if ( ctx == NULL ) return;
    if ( ctx->my_cursor == NULL ) return;
    rc = VCursorAddColumn( ctx->my_cursor, &(my_col_def->idx), my_col_def->name );
    DISP_RC( rc, "VCursorAddColumn() failed" );

    /***************************************************************************
    !!! extract type information !!!
    **************************************************************************/
    if ( rc == 0 )
    {
        rc = VCursorDatatype( ctx->my_cursor, my_col_def->idx,
                              &(my_col_def->type_decl), &(my_col_def->type_desc) );
        DISP_RC( rc, "VCursorDatatype() failed" );
        if ( rc == 0 )
        {
            ctx->count++;
            my_col_def->valid = true;
        }
    }
}
Esempio n. 10
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;
}
Esempio n. 11
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 );
        }
    }
}
Esempio n. 12
0
/*
 * walks the list of column-definitions and tries to add all off them
 * to the given cursor, it stops if one of them fails to be added
 * for every column it detects type_decl and type_desc
 * if both calls are successful the column-def is marked as valid
*/
rc_t col_defs_add_to_rd_cursor( col_defs* defs, const VCursor *cursor, bool show )
{
    rc_t rc = 0;
    uint32_t idx, len;
    
    if ( defs == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcSelf, rcNull );
    if ( cursor == NULL )
        return RC( rcExe, rcNoTarg, rcResolving, rcParam, rcNull );

    len = VectorLength( &(defs->cols) );
    for ( idx = 0;  idx < len && rc == 0; ++idx )
    {
        p_col_def col = (p_col_def) VectorGet ( &(defs->cols), idx );
        if ( col != NULL )
        {
            if ( col->src_cast != NULL )
            {
                rc = VCursorAddColumn( cursor, &(col->src_idx), "%s", col->src_cast );
                DISP_RC( rc, "col_defs_add_to_cursor:VCursorAddColumn() failed" );
                if ( rc == 0 )
                {
                    rc = VCursorDatatype( cursor, col->src_idx,
                              &(col->type_decl), &(col->type_desc) );
                    DISP_RC( rc, "col_defs_add_to_cursor:VCursorDatatype() failed" );
                    col->src_valid = ( rc == 0 );
                    if ( show && col->src_valid )
                        KOutMsg( "added to rd-cursor: >%s<\n", col->name );
                }

            }
        }
    }
    return rc;
}
Esempio n. 13
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;
}
Esempio n. 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;
}
Esempio n. 15
0
rc_t open_write_cursor (VTable * table, VCursor ** cursor,
                        uint32_t * dat, uint32_t * len, 
                        const char * dat_name, const char* len_name)
{
    rc_t rc;

    rc = VTableCreateCursorWrite (table, cursor, kcmInsert);
    if (rc)
    {
        LOGERR (klogErr, rc, "Failed to create Cursor");
        *cursor = NULL;
    }
    else
    {
        do
        {
            rc = VCursorAddColumn (*cursor, dat, dat_name);
            if (rc)
            {
                pLOGERR (klogErr, rc, "Failed to add column $(C)", PLOG_S(C), dat_name);
                break;
            }

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

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

            return 0;
        }
        while (0);
    }
    VCursorRelease (*cursor);
    *dat = 0;
    *len = 0;
    *cursor = NULL;
    return rc;
}
Esempio n. 16
0
static rc_t add_required_columns( struct ref_walker * self, const VTable *tbl, const VCursor ** cursor,
                                  walker_col_ids * cursor_ids )
{
    rc_t rc = VTableCreateCursorRead ( tbl, cursor );
    if ( rc != 0 )
    {
        LOGERR( klogInt, rc, "VTableCreateCursorRead() failed" );
    }

    if ( rc == 0 && !self->omit_quality )
    {
        rc = VCursorAddColumn ( *cursor, &cursor_ids->idx_quality, COL_QUALITY );
        if ( rc != 0 )
        {
            LOGERR( klogInt, rc, "VCursorAddColumn(QUALITY) failed" );
        }
    }

    if ( rc == 0 )
    {
        rc = VCursorAddColumn ( *cursor, &cursor_ids->idx_ref_orientation, COL_REF_ORIENTATION );
        if ( rc != 0 )
        {
            LOGERR( klogInt, rc, "VCursorAddColumn(REF_ORIENTATION) failed" );
        }
    }

    if ( rc == 0 )
    {
        rc = VCursorAddColumn ( *cursor, &cursor_ids->idx_read_filter, COL_READ_FILTER );
        if ( rc != 0 )
        {
            LOGERR( klogInt, rc, "VCursorAddColumn(READ_FILTER) failed" );
        }
    }

    if ( rc == 0 && self->read_tlen )
    {
        rc = VCursorAddColumn ( *cursor, &cursor_ids->idx_template_len, COL_TEMPLATE_LEN );
        if ( rc != 0 )
        {
            LOGERR( klogInt, rc, "VCursorAddColumn(TEMPLATE_LEN) failed" );
        }
    }
    return rc;
}
Esempio n. 17
0
rc_t add_column( const VCursor *cursor, col *column, const char *name )
{
    rc_t rc = VCursorAddColumn ( cursor, &column->idx, "%s", name );
    if ( rc != 0 )
        PLOGERR( klogInt, ( klogInt, rc, 
                            "VCursorAddColumn($(name)) failed", "name=%s", name ) );
    return rc;
}
Esempio n. 18
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;
}
Esempio n. 19
0
static
rc_t RefSeqIDMake ( RefSeqID **objp, const VTable *tbl, const VCursor *native_curs )
{
    rc_t rc;

    /* create the object */
    RefSeqID *obj = malloc ( sizeof * obj );
    if ( obj == NULL )
    {
        rc = RC( rcXF, rcFunction, rcConstructing, rcMemory, rcExhausted );
    }
    else
    {
        obj->curs=NULL;

        SUB_DEBUG( ( "SUB.Make in 'align_ref_seq_id.c'\n" ) );

        /* open the reference cursor */
        rc = AlignRefTableCursor( tbl, native_curs, &obj->curs, NULL );
        if ( rc == 0 )
        {
            /* add columns to cursor */
            rc = VCursorAddColumn( obj->curs, &obj->seqID_idx, "SEQ_ID" );
            if ( GetRCObject( rc ) == ( enum RCObject ) rcColumn && GetRCState( rc ) == rcNotFound )
            {
                rc = VCursorAddColumn( obj->curs, &obj->seqID_idx, "REF_SEQ_ID" );
            }
            
            if ( GetRCState( rc ) == rcExists )
            {
                rc = 0;
            }

            if ( rc == 0 )
            {
                *objp = obj;
                return 0;
            }

            VCursorRelease ( obj -> curs );
        }
        free ( obj );
    }
    return rc;
}
Esempio n. 20
0
rc_t add_column( const VCursor * cursor, const char *colname, uint32_t * idx )
{
    rc_t rc = VCursorAddColumn( cursor, idx, "%s", colname );
    if ( rc != 0 )
    {
        (void)PLOGERR( klogInt, ( klogInt, rc, "VCursorAddColumn( $(cn) ) failed", "cn=%s", colname ) );
    }
    return rc;
}
Esempio n. 21
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;
}
Esempio n. 22
0
static rc_t cg_dump_add_column( const VCursor * cur, uint32_t * idx, const char * col_name, const char * cur_name )
{
    rc_t rc = VCursorAddColumn ( cur, idx, "%s", col_name );
    if ( rc != 0 )
    {
        (void)PLOGERR( klogErr, ( klogErr, rc, "cannot add $(col_name) to $(cur_name)",
                                  "col_name=%s,cur_name=%s", col_name, cur_name ) );
    }
    return rc;
}
Esempio n. 23
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;
}
Esempio n. 24
0
static rc_t vdb_prepare_cursor( const p_dump_context ctx, const VTable * tbl, fastq_ctx * fctx )
{
    rc_t rc;

    /* first we try to open READ/QUALITY/NAME */
    rc = VTableCreateCachedCursorRead( tbl, &fctx->cursor, ctx->cur_cache_size );
    DISP_RC( rc, "VTableCreateCursorRead( 1st ) failed" );
    if ( rc == 0 )
    {
        rc = VCursorAddColumn( fctx->cursor, &fctx->idx_read, "(INSDC:dna:text)READ" );
        if ( rc == 0 && ctx->format == df_fastq )
            rc = VCursorAddColumn( fctx->cursor, &fctx->idx_qual, "(INSDC:quality:text:phred_33)QUALITY" );
        else
            fctx->idx_qual = INVALID_COLUMN;
        if ( rc == 0 )
            rc = VCursorAddColumn( fctx->cursor, &fctx->idx_name, "(ascii)NAME" );
        if ( rc == 0 )
            rc = VCursorOpen ( fctx->cursor );

        if ( rc != 0 )
        {
            VCursorRelease( fctx->cursor );
            rc = VTableCreateCachedCursorRead( tbl, &fctx->cursor, ctx->cur_cache_size );
            DISP_RC( rc, "VTableCreateCursorRead( 2nd ) failed" );
            if ( rc == 0 )
            {
                rc = VCursorAddColumn( fctx->cursor, &fctx->idx_read, "(INSDC:dna:text)READ" );
                if ( rc == 0 && ctx->format == df_fastq )
                    rc = VCursorAddColumn( fctx->cursor, &fctx->idx_qual, "(INSDC:quality:text:phred_33)QUALITY" );
                else
                    fctx->idx_qual = INVALID_COLUMN;
                if ( rc == 0 )
                    rc = VCursorOpen ( fctx->cursor );
                fctx->idx_name = INVALID_COLUMN;
            }
        }
    }
    return rc;
}
Esempio n. 25
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;
}
Esempio n. 26
0
static rc_t prepare_align_cursor( struct VCursor const *align )
{
    rc_t rc = 0;
    uint32_t i, throw_away_idx;

    for ( i = 0; i < ALIGN_COL_COUNT && rc == 0; ++i ) {
        rc =VCursorAddColumn ( align, &throw_away_idx, "%s", align_cols[ i ] );
        if( GetRCState(rc) == rcExists ) {
            rc = 0;
        }
    }
        
    return rc;
}
Esempio n. 27
0
void add_opt_column( const VCursor * cursor, const KNamelist *names, const char *colname, uint32_t * idx )
{
    bool available = namelist_contains( names, col_name_without_type( colname ) );
    if ( available )
    {
        rc_t rc = VCursorAddColumn( cursor, idx, "%s", colname );
        if ( rc != 0 )
            *idx = COL_NOT_AVAILABLE;
    }
    else
    {
        *idx = COL_NOT_AVAILABLE;
    }
}
Esempio n. 28
0
    /* sort by cid */
    return VCtxIdCmp ( & a -> cid, & b -> cid );
}

#if 0 /* more for later */
static
rc_t create_cursor_all_readable_columns(const VTable *self,
                                        unsigned *ncol, uint32_t **idx,
                                        const VCursor **curs)
{
    KNamelist *list;
    rc_t rc = VTableListReadableColumns(self, &list);
    
    if (rc == 0) {
        rc = VTableCreateCursorReadInternal(self, curs);
        if (rc == 0) {
            uint32_t n;
            
            rc = KNamelistCount(list, ncol);
            if (rc == 0) {
                n = *ncol;
                *idx = malloc(n * sizeof(**idx));
                if (idx) {
                    unsigned i;
                    
                    for (i = 0; i != (unsigned)n; ++i) {
                        const char *name;
                        
                        rc = KNamelistGet(list, i, &name);
                        if (rc)
                            break;
                        rc = VCursorAddColumn(*curs, &(*idx)[i], name);
                        if (rc)
                            break;
                    }
                    if (rc)
                        free(*idx);
                }
                else
                    rc = RC(rcVDB, rcTable, rcValidating, rcMemory, rcExhausted);
            }
            if (rc)
                VCursorRelease(*curs);
        }
        KNamelistRelease(list);
    }
    if (rc) {
        *idx = NULL;
        *curs = NULL;
        *ncol = 0;
    }
    return rc;
}
Esempio n. 29
0
static
rc_t LocalRefIDMake ( LocalRefID **objp, const VTable *tbl, const VCursor *native_curs)
{
    rc_t rc;
    /* create the object */
    LocalRefID *obj = malloc ( sizeof * obj );
    if ( obj == NULL )
    {
        rc = RC( rcXF, rcFunction, rcConstructing, rcMemory, rcExhausted );
    }
    else
    {
        const VCursor *curs=NULL;
        /* open the reference table cursor*/
        rc = AlignRefTableCursor( tbl, native_curs, &curs, NULL );
        if ( rc == 0 )
        {
            uint32_t itmp;
            rc = VCursorAddColumn( curs, &itmp, "(U32)MAX_SEQ_LEN" );
            if ( rc == 0 || GetRCState( rc ) == rcExists )
            {
                const void *base;
                uint32_t row_len;
                rc = VCursorCellDataDirect( curs, 1, itmp, NULL, &base, NULL, &row_len );
                if ( rc == 0 )
                {
                    assert( row_len == 1 );
                    memmove( &obj->max_seq_len, base, 4 );
                }
            }

            if ( ( GetRCObject( rc ) == ( enum RCObject )rcColumn ) && ( GetRCState( rc ) == rcNotFound ) )
            {
                obj->max_seq_len = 0;
                rc = 0;
            }

            VCursorRelease( curs );
            if ( rc == 0 )
            {
                *objp = obj;
                return 0;
            }
        }
        free ( obj );
    }
    return rc;
}
Esempio n. 30
0
static
rc_t SRATable_ReadColBack(const VTable* tbl, const char* col_name, uint32_t elem_bits, void *buffer, uint32_t blen)
{
    rc_t rc = 0;
    uint32_t idx;
    const VCursor* curs = NULL;
   
    if( (rc = VTableCreateCursorRead(tbl, &curs)) == 0 &&
        (rc = VCursorAddColumn(curs, &idx, "%s", col_name)) == 0 &&
        (rc = VCursorOpen(curs)) == 0 ) {
        uint32_t len;
        rc = VCursorReadDirect(curs, 1, idx, elem_bits, buffer, blen, &len);
    }
    VCursorRelease(curs);
    return rc;
}