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; }
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 ); } } }
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; }
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; }
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; }
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; }
/* 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; }
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; }
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; }
/* * 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; }
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; }
static rc_t init_self( self_t *self, VTable const * const srctbl, char const column[] ) { VDatabase const * db; rc_t rc = VTableOpenParentRead( srctbl, &db ); if ( rc == 0 ) { VTable const * tbl; rc = VDatabaseOpenTableRead( db, &tbl, "SEQUENCE" ); VDatabaseRelease( db ); if ( rc == 0 ) { bool has_column = does_table_have_column( tbl, column ); if ( !has_column ) VTableRelease( tbl ); else { VCursor const * curs; #if CURSOR_CACHE_SIZE rc = VTableCreateCachedCursorRead( tbl, &curs, CURSOR_CACHE_SIZE ); #else rc = VTableCreateCursorRead( tbl, &curs ); #endif VTableRelease( tbl ); if ( rc == 0 ) { uint32_t col_idx; rc = VCursorAddColumn( curs, &col_idx, "%s", column ); if ( rc == 0 ) { rc = VCursorOpen( curs ); if ( rc == 0 ) { self->curs = curs; self->col_idx = col_idx; return 0; } if ( GetRCObject( rc ) == (enum RCObject)rcColumn && GetRCState( rc ) == rcUndefined ) rc = 0; } VCursorRelease( curs ); } } } } return rc; }
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; }
/* 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; }
void CVDBCursor::Init(const CVDBTable& table) { if ( *this ) { NCBI_THROW2(CSraException, eInvalidState, "Cannot init VDB cursor again", RC(rcApp, rcCursor, rcConstructing, rcSelf, rcOpen)); } if ( rc_t rc = VTableCreateCursorRead(table, x_InitPtr()) ) { *x_InitPtr() = 0; NCBI_THROW2(CSraException, eInitFailed, "Cannot create VDB cursor", rc); } if ( rc_t rc = VCursorPermitPostOpenAdd(*this) ) { NCBI_THROW2(CSraException, eInitFailed, "Cannot allow VDB cursor post open column add", rc); } if ( rc_t rc = VCursorOpen(*this) ) { NCBI_THROW2(CSraException, eInitFailed, "Cannot open VDB cursor", rc); } m_Table = table; }
static rc_t prepare_ref_node( ref_node * node ) { rc_t rc = VTableCreateCursorRead ( node->tab, &node->cur ); if ( rc != 0 ) { PLOGERR( klogInt, ( klogInt, rc, "error to create cursor on table $(db_name).$(tab_name)", "db_name=%S,tab_name=%s", node->name, HITMAP_TAB ) ); } else { rc = VCursorAddColumn ( node->cur, &node->hits_idx, HITS_COLUMN ); if ( rc != 0 ) { PLOGERR( klogInt, ( klogInt, rc, "error to add column $(col_name) to cursor for table $(db_name).$(tab_name)", "col_name=%s,db_name=%S,tab_name=%s", HITS_COLUMN, node->name, HITMAP_TAB ) ); } else { rc = VCursorOpen( node->cur ); if ( rc != 0 ) { PLOGERR( klogInt, ( klogInt, rc, "error to open cursor for table $(tab_name)", "tab_name=%S", node->name ) ); } else { node->valid = true; } } } 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 run(const TestCase& test_case) { rc_t rc; KDirectory * cur_dir; const VDBManager * manager; const VDatabase * database; const VTable * table; const VCursor * cursor; uint32_t name_idx; uint32_t name_range_idx; rc = KDirectoryNativeDir( &cur_dir ); if ( rc != 0 ) LOGERR( klogInt, rc, "KDirectoryNativeDir() failed" ); else { rc = VDBManagerMakeRead ( &manager, cur_dir ); if ( rc != 0 ) LOGERR( klogInt, rc, "VDBManagerMakeRead() failed" ); else { rc = VDBManagerOpenDBRead( manager, &database, NULL, "%s", test_case.path ); if (rc != 0) LOGERR( klogInt, rc, "VDBManagerOpenDBRead() failed" ); else { rc = VDatabaseOpenTableRead( database, &table, "%s", TABLE_NAME ); if ( rc != 0 ) LOGERR( klogInt, rc, "VDatabaseOpenTableRead() failed" ); else { rc = VTableCreateCursorRead( table, &cursor ); if ( rc != 0 ) LOGERR( klogInt, rc, "VTableCreateCursorRead() failed" ); else { /* add columns to cursor */ rc = VCursorAddColumn( cursor, &name_idx, "(utf8)NAME" ); if ( rc != 0 ) LOGERR( klogInt, rc, "VCursorAddColumn() failed" ); else { rc = VCursorAddColumn( cursor, &name_range_idx, "NAME_RANGE" ); if ( rc != 0 ) LOGERR( klogInt, rc, "VCursorAddColumn() failed" ); else { rc = VCursorOpen( cursor ); if (rc != 0) LOGERR( klogInt, rc, "VCursorOpen() failed" ); else rc = runChecks( test_case, cursor, name_idx, name_range_idx ); } } VCursorRelease( cursor ); } VTableRelease( table ); } VDatabaseRelease( database ); } VDBManagerRelease( manager ); } KDirectoryRelease( cur_dir ); } return rc; }
uint32_t vdcd_parse_string( col_defs* defs, const char* src, const VTable *my_table ) { uint32_t count, found = 0; char colname[MAX_COL_NAME_LEN+1]; size_t i_dest = 0; if ( defs == NULL ) return false; if ( src == NULL ) return false; while ( *src ) { if ( *src == ',' ) { if ( i_dest > 0 ) { colname[i_dest]=0; vdcd_append_col( defs, colname ); } i_dest = 0; } else { if ( i_dest < MAX_COL_NAME_LEN ) colname[i_dest++]=*src; } src++; } if ( i_dest > 0 ) { colname[i_dest]=0; vdcd_append_col( defs, colname ); } count = VectorLength( &defs->cols ); if ( count > 0 && my_table != NULL ) { const VCursor *my_cursor; rc_t rc = VTableCreateCursorRead( my_table, &my_cursor ); DISP_RC( rc, "VTableCreateCursorRead() failed" ); if ( rc == 0 ) { uint32_t idx; for ( idx = 0; idx < count; ++idx ) { col_def *col = ( col_def * )VectorGet( &(defs->cols), idx ); if ( col != NULL ) { rc = VCursorAddColumn( my_cursor, &(col->idx), col->name ); DISP_RC( rc, "VCursorAddColumn() failed" ); if ( rc == 0 ) { rc = VCursorDatatype( my_cursor, col->idx, &(col->type_decl), &(col->type_desc) ); DISP_RC( rc, "VCursorDatatype() failed" ); if ( rc == 0 ) found++; } } } rc = VCursorRelease( my_cursor ); DISP_RC( rc, "VCursorRelease() failed" ); } } return found; }
rc_t init_vdb_objects ( VDBManager const** mgr, VDatabase const** db, VTable const** table_ref, VTable const** table_pa, VCursor const** cursor_ref, VCursor const** cursor_pa, char const* db_path, char const* const* column_names_ref, uint32_t* column_index_ref, size_t column_count_ref, char const* const* column_names_pa, uint32_t* column_index_pa, size_t column_count_pa, char* error_buf, size_t error_buf_size ) { rc_t rc = 0; rc = VDBManagerMakeRead ( mgr, NULL ); if ( rc != 0 ) { rc_t res = string_printf ( error_buf, error_buf_size, NULL, "ERROR: VDBManagerMakeRead failed with error: 0x%08x (%u) [%R]", rc, rc, rc); if (res == rcBuffer || res == rcInsufficient) error_buf [ error_buf_size - 1 ] = '\0'; return rc; } rc = VDBManagerOpenDBRead ( *mgr, db, NULL, db_path ); if ( rc != 0 ) { rc_t res = string_printf ( error_buf, error_buf_size, NULL, "ERROR: VDBManagerOpenDBRead(%s) failed with error: 0x%08x (%u) [%R]", db_path, rc, rc, rc); if (res == rcBuffer || res == rcInsufficient) error_buf [ error_buf_size - 1 ] = '\0'; return rc; } rc = VDatabaseOpenTableRead ( *db, table_ref, "REFERENCE" ); if ( rc != 0 ) { rc_t res = string_printf ( error_buf, error_buf_size, NULL, "ERROR: VDatabaseOpenTableRead(REFERENCE) failed with error: 0x%08x (%u) [%R]", rc, rc, rc); if (res == rcBuffer || res == rcInsufficient) error_buf [ error_buf_size - 1 ] = '\0'; return rc; } rc = VDatabaseOpenTableRead ( *db, table_pa, "PRIMARY_ALIGNMENT" ); if ( rc != 0 ) { rc_t res = string_printf ( error_buf, error_buf_size, NULL, "ERROR: VDatabaseOpenTableRead(PRIMARY_ALIGNMENT) failed with error: 0x%08x (%u) [%R]", rc, rc, rc); if (res == rcBuffer || res == rcInsufficient) error_buf [ error_buf_size - 1 ] = '\0'; return rc; } rc = VTableCreateCursorRead ( *table_ref, cursor_ref ); /*rc = VTableCreateCachedCursorRead ( *table_ref, cursor_ref, (size_t)64 << 30 );*/ if ( rc != 0 ) { rc_t res = string_printf ( error_buf, error_buf_size, NULL, "ERROR: VTableCreateCursorRead(ref) failed with error: 0x%08x (%u) [%R]", rc, rc, rc); if (res == rcBuffer || res == rcInsufficient) error_buf [ error_buf_size - 1 ] = '\0'; return rc; } rc = init_column_index ( *cursor_ref, column_names_ref, column_index_ref, column_count_ref, error_buf, error_buf_size ); if ( rc != 0 ) return rc; rc = VCursorOpen ( *cursor_ref ); if ( rc != 0 ) { rc_t res = string_printf ( error_buf, error_buf_size, NULL, "ERROR: VCursorOpen(ref) failed with error: 0x%08x (%u) [%R]", rc, rc, rc); if (res == rcBuffer || res == rcInsufficient) error_buf [ error_buf_size - 1 ] = '\0'; return rc; } rc = VTableCreateCursorRead ( *table_pa, cursor_pa ); /*rc = VTableCreateCachedCursorRead ( *table_pa, cursor_pa, (size_t)64 << 30 );*/ if ( rc != 0 ) { rc_t res = string_printf ( error_buf, error_buf_size, NULL, "ERROR: VTableCreateCursorRead(pa) failed with error: 0x%08x (%u) [%R]", rc, rc, rc); if (res == rcBuffer || res == rcInsufficient) error_buf [ error_buf_size - 1 ] = '\0'; return rc; } rc = init_column_index ( *cursor_pa, column_names_pa, column_index_pa, column_count_pa, error_buf, error_buf_size ); if ( rc != 0 ) return rc; rc = VCursorOpen ( *cursor_pa ); if ( rc != 0 ) { rc_t res = string_printf ( error_buf, error_buf_size, NULL, "ERROR: VCursorOpen(pa) failed with error: 0x%08x (%u) [%R]", rc, rc, rc); if (res == rcBuffer || res == rcInsufficient) error_buf [ error_buf_size - 1 ] = '\0'; return rc; } 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 DbInit(rc_t rc, const CmdLine* args, Db* db) { const char name[] = "READ_FILTER"; assert(args && db); memset(db, 0, sizeof *db); if (rc != 0) { return rc; } db->table = args->table; if (rc == 0) { rc = VDBManagerMakeUpdate(&db->mgr, NULL); DISP_RC(rc, "while calling VDBManagerMakeUpdate"); } if (rc == 0) { rc = VDBManagerWritable(db->mgr, args->table); if (rc != 0) { if (GetRCState(rc) == rcLocked) { rc = VDBManagerUnlock(db->mgr, args->table); if (rc != 0) { PLOGERR(klogErr, (klogErr, rc, "while calling VDBManagerUnlock('$(table)')", "table=%s", args->table)); } db->locked = true; } else { PLOGERR(klogErr, (klogErr, rc, "while calling VDBManagerWritable('$(table)')", "table=%s", args->table)); if (rc == RC(rcDB, rcPath, rcAccessing, rcPath, rcReadonly)) { PLOGERR(klogErr, (klogErr, rc, "N.B. It is possible '$(table)' was not locked properly" , "table=%s", args->table)); } } } } if (rc == 0) { db->locked = true; /* has to be locked in production mode */ rc = VDBManagerOpenTableUpdate (db->mgr, &db->tbl, NULL, args->table); if (rc != 0) { VDatabase *vdb; rc_t rc2 = VDBManagerOpenDBUpdate ( db->mgr, &vdb, NULL , args->table ); if( rc2 == 0) { rc2 = VDatabaseOpenTableUpdate ( vdb, &db->tbl, "SEQUENCE" ); if (rc2 == 0 ) rc = 0; VDatabaseRelease ( vdb ); } } if(rc != 0){ PLOGERR(klogErr, (klogErr, rc, "while opening VTable '$(table)'", "table=%s", args->table)); } } if( rc == 0) { rc = VTableCreateCursorRead(db->tbl, &db->rCursor); DISP_RC(rc, "while creating read cursor"); if (rc == 0) { rc = VCursorAddColumn(db->rCursor, &db->rFilterIdx, "%s", name); if (rc != 0) { PLOGERR(klogErr, (klogErr, rc, "while adding $(name) to read cursor", "name=%s", name)); } } if (rc == 0) { rc = VCursorOpen(db->rCursor); DISP_RC(rc, "while opening read cursor"); } } if (rc == 0) { rc = VTableCreateCursorWrite(db->tbl, &db->wCursor, kcmInsert); DISP_RC(rc, "while creating write cursor"); if (rc == 0) { rc = VCursorAddColumn(db->wCursor, &db->wIdx, "%s", name); if (rc != 0) { PLOGERR(klogErr, (klogErr, rc, "while adding $(name) to write cursor", "name=%s", name)); } } if (rc == 0) { rc = VCursorOpen(db->wCursor); DISP_RC(rc, "while opening write cursor"); } } return rc; }
static rc_t detect_read_len( ref_node *node ) { const VCursor *temp_cursor; rc_t rc = VTableCreateCursorRead ( node->tab, &temp_cursor ); if ( rc != 0 ) { PLOGERR( klogInt, ( klogInt, rc, "error to create cursor on table $(tab_name)", "tab_name=%S", node->name ) ); } else { uint32_t idx; rc = VCursorAddColumn ( temp_cursor, &idx, MAXLEN_COLUMN ); if ( rc != 0 ) { PLOGERR( klogInt, ( klogInt, rc, "error to add column $(col_name) to cursor for table $(db_name).$(tab_name)", "col_name=%s,db_name=%S,tab_name=%s", MAXLEN_COLUMN, node->name, HITMAP_TAB ) ); } else { rc = VCursorOpen( temp_cursor ); if ( rc != 0 ) { PLOGERR( klogInt, ( klogInt, rc, "error to open cursor for table $(db_name).$(tab_name to read $(col_name)", "col_name=%s,db_name=%S,tab_name=%s", MAXLEN_COLUMN, node->name, HITMAP_TAB ) ); } else { uint32_t elem_bits, boff, row_len; const void *base; rc = VCursorCellDataDirect ( temp_cursor, 1, idx, &elem_bits, &base, &boff, &row_len ); if ( rc != 0 ) { PLOGERR( klogInt, ( klogInt, rc, "error to read $(col_name) from 1st row in table $(db_name).$(tab_name)", "col_name=%s,db_name=%S,tab_name=%s", MAXLEN_COLUMN, node->name, HITMAP_TAB ) ); } else { node->read_len = *((uint32_t *)base); if ( node->read_len == 0 ) { rc = RC( rcApp, rcNoTarg, rcReading, rcParam, rcInvalid ); PLOGERR( klogInt, ( klogInt, rc, "$(col_name) == 0 discoverd in table $(db_name).$(tab_name)", "col_name=%s,db_name=%S,tab_name=%s", MAXLEN_COLUMN, node->name, HITMAP_TAB ) ); } } } } VCursorRelease( temp_cursor ); } 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; }
/** * returns true if accession is good */ bool checkAccession ( const char * accession, const CheckCorruptConfig * config ) { rc_t rc; KDirectory * cur_dir; const VDBManager * manager; const VDatabase * database; const VTable * pa_table; const VTable * sa_table; const VTable * seq_table; const VCursor * pa_cursor; const VCursor * sa_cursor; const VCursor * seq_cursor; rc = KDirectoryNativeDir( &cur_dir ); if ( rc != 0 ) PLOGERR( klogInt, (klogInt, rc, "$(ACC) KDirectoryNativeDir() failed", "ACC=%s", accession)); else { rc = VDBManagerMakeRead ( &manager, cur_dir ); if ( rc != 0 ) PLOGERR( klogInt, (klogInt, rc, "$(ACC) VDBManagerMakeRead() failed", "ACC=%s", accession)); else { int type = VDBManagerPathType ( manager, "%s", accession ); if ( ( type & ~ kptAlias ) != kptDatabase ) PLOGMSG (klogInfo, (klogInfo, "$(ACC) SKIPPING - can't be opened as a database", "ACC=%s", accession)); else { rc = VDBManagerOpenDBRead( manager, &database, NULL, "%s", accession ); if (rc != 0) PLOGERR( klogInt, (klogInt, rc, "$(ACC) VDBManagerOpenDBRead() failed", "ACC=%s", accession)); else { rc = VDatabaseOpenTableRead( database, &pa_table, "%s", "PRIMARY_ALIGNMENT" ); if ( rc != 0 ) { PLOGMSG (klogInfo, (klogInfo, "$(ACC) SKIPPING - failed to open PRIMARY_ALIGNMENT table", "ACC=%s", accession)); rc = 0; } else { rc = VTableCreateCursorRead( pa_table, &pa_cursor ); if ( rc != 0 ) PLOGERR( klogInt, (klogInt, rc, "$(ACC) VTableCreateCursorRead() failed for PRIMARY_ALIGNMENT cursor", "ACC=%s", accession)); else { rc = VDatabaseOpenTableRead( database, &sa_table, "%s", "SECONDARY_ALIGNMENT" ); if ( rc != 0 ) { PLOGMSG (klogInfo, (klogInfo, "$(ACC) SKIPPING - failed to open SECONDARY_ALIGNMENT table", "ACC=%s", accession)); rc = 0; } else { rc = VTableCreateCursorRead( sa_table, &sa_cursor ); if ( rc != 0 ) PLOGERR( klogInt, (klogInt, rc, "$(ACC) VTableCreateCursorRead() failed for SECONDARY_ALIGNMENT cursor", "ACC=%s", accession)); else { rc = VDatabaseOpenTableRead( database, &seq_table, "%s", "SEQUENCE" ); if ( rc != 0 ) { PLOGMSG (klogInfo, (klogInfo, "$(ACC) SKIPPING - failed to open SEQUENCE table", "ACC=%s", accession)); rc = 0; } else { rc = VTableCreateCursorRead( seq_table, &seq_cursor ); if ( rc != 0 ) PLOGERR( klogInt, (klogInt, rc, "VTableCreateCursorRead() failed for SEQUENCE cursor", "ACC=%s", accession)); else { try { runChecks( accession, config, pa_cursor, sa_cursor, seq_cursor ); } catch ( VDB_ERROR & x ) { PLOGERR (klogErr, (klogInfo, x.rc, "$(ACC) VDB error: $(MSG)", "ACC=%s,MSG=%s", accession, x.msg)); rc = 1; } catch ( VDB_ROW_ERROR & x ) { PLOGERR (klogErr, (klogInfo, x.rc, "$(ACC) VDB error: $(MSG) row_id: $(ROW_ID)", "ACC=%s,MSG=%s,ROW_ID=%ld", accession, x.msg, x.row_id)); rc = 1; } catch ( DATA_ERROR & x ) { KOutMsg("%s\n", accession); PLOGMSG (klogInfo, (klogInfo, "$(ACC) Invalid data: $(MSG) ", "ACC=%s,MSG=%s", accession, x.msg.c_str())); rc = 1; } VCursorRelease( seq_cursor ); } VTableRelease( seq_table ); } VCursorRelease( sa_cursor ); } VTableRelease( sa_table ); } VCursorRelease( pa_cursor ); } VTableRelease( pa_table ); } VDatabaseRelease( database ); } } VDBManagerRelease( manager ); } KDirectoryRelease( cur_dir ); } return rc == 0; }
static rc_t cg_dump_src_dst_rows_vdb( cg_dump_opts * opts, const VDBManager * mgr, const char * src, cg_dump_ctx * cg_ctx ) { const VDatabase * db; rc_t rc = VDBManagerOpenDBRead( mgr, &db, NULL, "%s", src ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot open database" ); } else { rc = parse_sg_lookup( cg_ctx->lookup, db ); /* in sg_lookup.c */ if ( rc == 0 ) { const VTable * seq; rc = VDatabaseOpenTableRead( db, &seq, "SEQUENCE" ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot open SEQUENCE-table" ); } else { const VTable * prim; rc = VDatabaseOpenTableRead( db, &prim, "PRIMARY_ALIGNMENT" ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot open PRIMARY-ALIGNMENT-table" ); } else { if ( opts->cursor_cache > 0 ) rc = VTableCreateCachedCursorRead( seq, &cg_ctx->seq_cur, opts->cursor_cache ); else rc = VTableCreateCursorRead( seq, &cg_ctx->seq_cur ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot create cursor for SEQUENCE-table" ); } else { /* if ( opts->cursor_cache > 0 ) rc = VTableCreateCachedCursorRead( prim, &cg_ctx->prim_cur, opts->cursor_cache ); else rc = VTableCreateCursorRead( prim, &cg_ctx->prim_cur ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot create cursor for PRIMARY_ALIGNMENT-table" ); } */ if ( rc == 0 ) { rc = cg_dump_src_dst_rows_cur( opts, cg_ctx ); /* <================== */ /* VCursorRelease( cg_ctx->prim_cur ); */ } VCursorRelease( cg_ctx->seq_cur ); } /* VTableRelease( prim ); */ } VTableRelease( seq ); } } VDatabaseRelease( db ); } return rc; }
static rc_t report_deletes_db( const VDBManager *vdb_mgr, const char * path, uint32_t min_len ) { const VDatabase *db; rc_t rc = VDBManagerOpenDBRead( vdb_mgr, &db, NULL, "%s", path ); if ( rc != 0 ) { (void)PLOGERR( klogErr, ( klogInt, rc, "cannot open database $(db_name)", "db_name=%s", path ) ); } else { const VTable *tab; rc = VDatabaseOpenTableRead( db, &tab, "PRIMARY_ALIGNMENT" ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot open table PRIMARY_ALIGNMENT" ); } else { const VCursor *cur; rc = VTableCreateCursorRead( tab, &cur ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot open cursor on table PRIMARY_ALIGNMENT" ); } else { uint32_t cigar_idx; rc = VCursorAddColumn( cur, &cigar_idx, "CIGAR_SHORT" ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot add CIGAR_SHORT to cursor" ); } else { rc = VCursorOpen( cur ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot open cursor" ); } else { int64_t first; uint64_t count; rc = VCursorIdRange ( cur, cigar_idx, &first, &count ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot detect row-range" ); } else { rc = cigar_loop( cur, cigar_idx, first, count, min_len ); } } } VCursorRelease( cur ); } VTableRelease( tab ); } VDatabaseRelease( db ); } return rc; }
/* OpenRead * open an existing table * * "tbl" [ OUT ] - return parameter for table * * "spec" [ IN ] - NUL terminated UTF-8 string giving path * to table. */ static rc_t CC SRAMgrVOpenAltTableRead ( const SRAMgr *self, const SRATable **rslt, const char *altname, const char *spec, va_list args ) { rc_t rc; if ( rslt == NULL ) rc = RC ( rcSRA, rcTable, rcOpening, rcParam, rcNull ); else { if ( self == NULL ) rc = RC ( rcSRA, rcMgr, rcAccessing, rcSelf, rcNull ); else if ( spec == NULL ) rc = RC ( rcSRA, rcTable, rcOpening, rcName, rcNull ); else if ( spec [ 0 ] == 0 ) rc = RC ( rcSRA, rcTable, rcOpening, rcName, rcEmpty ); else { char path [ 4096 ]; rc = ResolveTablePath ( self, path, sizeof path, spec, args ); if ( rc == 0 ) { SRATable *tbl = calloc ( 1, sizeof *tbl ); if ( tbl == NULL ) rc = RC ( rcSRA, rcTable, rcConstructing, rcMemory, rcExhausted ); else { VSchema *schema = NULL; rc = VDBManagerMakeSRASchema(self -> vmgr, & schema); if ( rc == 0 ) { rc = VDBManagerOpenTableRead ( self -> vmgr, & tbl -> vtbl, schema, path ); if ( rc != 0 && GetRCObject ( rc ) == rcTable && GetRCState ( rc ) == rcIncorrect ) { const VDatabase *db; rc_t rc2 = VDBManagerOpenDBRead ( self -> vmgr, & db, schema, path ); if ( rc2 == 0 ) { rc2 = VDatabaseOpenTableRead ( db, & tbl -> vtbl, altname ); if ( rc2 == 0 ) rc = 0; VDatabaseRelease ( db ); } } VSchemaRelease(schema); if ( rc == 0 ) { rc = VTableOpenMetadataRead ( tbl -> vtbl, & tbl -> meta ); if ( rc == 0 ) { rc = KMetadataVersion ( tbl -> meta, & tbl -> metavers ); if ( rc == 0 ) { rc = VTableCreateCursorRead ( tbl -> vtbl, & tbl -> curs ); if ( rc == 0 ) { tbl -> mgr = SRAMgrAttach ( self ); tbl -> mode = self -> mode; tbl -> read_only = true; KRefcountInit ( & tbl -> refcount, 1, "SRATable", "OpenTableRead", path ); rc = SRATableFillOut ( tbl, false ); if ( rc == 0 ) { * rslt = tbl; return 0; } } } } } } SRATableWhack ( tbl ); } } } * rslt = NULL; } return rc; }