Example #1
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;
}
Example #2
0
/* close_table
 */
static
rc_t close_dst_table ( const vtblcp_parms *pb, VTable *tbl, rc_t entry_rc )
{
    rc_t rc;

    /* perform "re-indexing" on columns
       this will go away soon once cursor sessions are supported */
    if ( entry_rc == 0 )
        entry_rc = VTableReindex ( tbl );

    /* close the table */
    rc = VTableRelease ( tbl );

    /* return most important return code */
    return entry_rc ? entry_rc : rc;
}
Example #3
0
static void CC qstats_whack(void *vp)
{
    self_t *self = vp;
    VTable *tbl;
    writer_ctx_t ctx;
    
    memset(&ctx, 0, sizeof(ctx));
    ctx.alignMode = self->alignMode;
    
    ctx.rc = OpenTableAndCursor(self->db, &tbl, &ctx.curs, self->alignMode ? 10 : 7);
    VDatabaseRelease(self->db);
    if (ctx.rc == 0) {
        foreach_statistic(&self->stat, qstats_write, self);
        VCursorRelease(ctx.curs);
        if (ctx.rc == 0)
            VTableReindex(tbl);
        VTableRelease(tbl);
    }
    whack_statistic(&self->stat);
    free(self);
}
Example #4
0
static rc_t static_write(void)
{
    const char *schema_text = "version 1; include 'vdb/vdb.vschema'; table foo #1 { column ascii bar { read = .bar; } physical ascii .bar = bar; }";
    bool force = 1;
    rc_t rc;
    VDBManager *vmgr;
    
    rc = VDBManagerMakeUpdate ( & vmgr, NULL );
    if ( rc != 0 )
        LOGERR ( klogInt, rc, "failed to make VDB manager" );
    else
    {
        VSchema *schema;
        rc = VDBManagerMakeSchema ( vmgr, & schema );
        if ( rc != 0 )
            LOGERR ( klogInt, rc, "failed to make empty schema" );
        else
        {
            rc = VSchemaParseText( schema, "static_schema", schema_text, strlen(schema_text) );
            if ( rc != 0 )
                PLOGERR ( klogErr, (klogErr, rc, "failed to parse schema '$(text)'", "test=%s", schema_text ));
            else
            {
                VTable *vtbl;
                
                rc = VDBManagerCreateTable ( vmgr, & vtbl, schema, "foo", force ? kcmInit : kcmCreate, table_path );
                if ( rc != 0 )
                {
                    PLOGERR ( klogErr, (klogErr, rc, "failed to $(cmode) table '$(path)'"
                             , "cmode=%s,path=%s"
                             , force ? "create or replace" : "create"
                             , table_path
                                        ));
                }
                else
                {
                    VCursor *curs;
                    rc = VTableCreateCursorWrite ( vtbl, & curs, kcmInsert );
                    if ( rc != 0 )
                        LOGERR ( klogInt, rc, "failed to create cursor" );
                    else
                    {
                        uint32_t idx;
                        
                        rc = VCursorAddColumn ( curs, &idx, "bar" );
                        if ( rc != 0 )
                        {
                            PLOGERR ( klogErr, (klogErr, rc, "failed to add column '$(col)' to cursor"
                                     , "col=bar"
                                     ));
                        }
                        else {
                            rc = VCursorOpen ( curs );
                            if ( rc != 0 )
                                LOGERR ( klogErr, rc, "failed to open cursor" );
                            else
                            {
                                int i;
                                
                                for ( i = 0; i != 10 && rc == 0; ++i )
                                {
                                    rc = VCursorOpenRow ( curs );
                                    if ( rc != 0 )
                                        LOGERR ( klogErr, rc, "failed to open cursor row" );
                                    else
                                    {
                                        rc_t rc2;
                                        uint32_t count = sizeof(buff) - 1;
                                        
                                        rc = VCursorWrite ( curs, idx, 8, buff, 0, count );
                                        if ( rc != 0 )
                                        {
                                            int64_t rid = 0;
                                            VCursorRowId ( curs, & rid );
                                            
                                            PLOGERR ( klogInt, (klogInt, rc, "failed to write data to row $(row_id)'"
                                                     , "row_id=%ld"
                                                     , rid
                                                     ));
                                            break;
                                        }
                                        if ( rc == 0 )
                                        {
                                            rc = VCursorCommitRow ( curs );
                                            if ( rc != 0 )
                                                LOGERR ( klogErr, rc, "failed to commit row" );
                                        }
                                        
                                        rc2 = VCursorCloseRow ( curs );
                                        if ( rc2 != 0 )
                                        {
                                            LOGERR ( klogErr, rc2, "failed to close cursor row" );
                                            if ( rc == 0 )
                                                rc = rc2;
                                        }
                                    }
                                }
                                
                                if ( GetRCState ( rc ) == rcDone )
                                    rc = 0;
                                
                                if ( rc == 0 )
                                    rc = VCursorCommit ( curs );
                            }
                        }
                        
                        VCursorRelease ( curs );
                    }
                    
#if 1
                    if ( rc == 0 )
                        rc = VTableReindex ( vtbl );
#endif
                    
                    VTableRelease ( vtbl );
                }
            }
            
            VSchemaRelease ( schema );
        }
        
        VDBManagerRelease ( vmgr );
    }
    
    return rc;
}