Beispiel #1
0
LIB_EXPORT rc_t CC SRAMgrVOpenTableUpdate(SRAMgr *mgr, SRATable **rslt, const char *spec, va_list args) {
    SRATable *self;
    char path[4096];
    rc_t rc;
    
    if (mgr == NULL)
        return RC(RC_MODULE, RC_TARGET, rcConstructing, rcSelf, rcNull);
    if (spec == NULL || rslt == NULL)
        return RC(RC_MODULE, RC_TARGET, rcConstructing, rcParam, rcNull);
    
    *rslt = NULL;
    
    rc = ResolveTablePath(mgr, path, sizeof(path), spec, args);
    if (rc)
        return rc;
    
    self = calloc(1, sizeof(*self));
    if (self == NULL)
        return RC(RC_MODULE, RC_TARGET, rcConstructing, rcMemory, rcExhausted);
    
    rc = VDBManagerOpenTableUpdate(mgr->vmgr, &self->vtbl, mgr->schema, "%s", path);
    if (rc == 0) {
        rc = VTableOpenMetadataUpdate(self->vtbl, &self->meta);
        if (rc == 0) {
            rc = KMetadataVersion(self->meta, &self->metavers);
            if (rc == 0) {
                rc = VTableCreateCursorWrite(self->vtbl, &self->curs, kcmInsert);
                if (rc == 0) {
                    self->mgr = SRAMgrAttach(mgr);
                    self->mode = mgr->mode;
                    self->read_only = false;
                    KRefcountInit(&self->refcount, 1, "SRATable", "OpenTableUpdate", path);
                    
                    rc = SRATableFillOut ( self, true );
                    if ( rc == 0 )
                    {
                        VectorInit ( & self -> wcol, 0, 16 );
                    
                        *rslt = self;
                        return 0;
                    }
                }
            }
        }
    }
    SRATableWhack(self);
    return rc;
}
Beispiel #2
0
LIB_EXPORT rc_t CC SRAMgrVCreateTable ( SRAMgr *self, SRATable **rslt,
    const char *typespec, const char *spec, va_list args )
{
    rc_t rc;

    if ( rslt == NULL )
        rc = RC ( rcSRA, rcTable, rcConstructing, rcParam, rcNull );
    else
    {
        if ( self == NULL )
            rc = RC ( rcSRA, rcTable, rcConstructing, rcSelf, rcNull );
        else if ( spec == NULL )
            rc = RC ( rcSRA, rcTable, rcConstructing, rcString, rcNull );
        else if ( spec [ 0 ] == 0 )
            rc = RC ( rcSRA, rcTable, rcConstructing, rcString, rcEmpty );
        else
        {
            char path [ 4097 ];
            size_t act_size = 0;
            
            rc = string_vprintf(path, 4097, &act_size, spec, args);
            path[act_size] = '\0';
            if ( rc == 0 )
            {
                VTable *vtbl;
                rc = VDBManagerCreateTable ( self -> vmgr, & vtbl, self -> schema,
                                             typespec, ( self -> mode & kcmBitMask ) | kcmCreate, "%s", path );
                if ( rc == 0 )
                {
                    rc = VTableColumnCreateParams ( vtbl, kcmCreate, kcsCRC32, 0 );
                    if ( rc == 0 )
                    {
                        SRATable *tbl = calloc ( 1, sizeof * tbl );
                        if ( tbl == NULL )
                            rc = RC ( rcSRA, rcTable, rcConstructing, rcMemory, rcExhausted );
                        else
                        {
                            tbl -> vtbl = vtbl;

                            rc = VTableOpenMetadataUpdate ( vtbl, & tbl -> meta );
                            if ( rc == 0 )
                                rc = KMetadataVersion ( tbl -> meta, & tbl -> metavers );
                            if ( rc == 0 )
                                rc = VTableCreateCursorWrite ( vtbl, & tbl -> curs, kcmInsert );
                            if ( rc == 0 )
                            {
                                tbl -> mgr = SRAMgrAttach ( self );
                                tbl -> mode = self -> mode;
                                tbl -> read_only = false;
                                KRefcountInit ( & tbl -> refcount, 1, "SRATable", "OpenTableUpdate", path );
                                VectorInit ( & tbl -> wcol, 0, 16 );
                                * rslt = tbl;
                                return 0;
                            }

                            vtbl = NULL;
                            SRATableWhack ( tbl );
                        }
                    }

                    VTableRelease ( vtbl );
                }
            }
        }

        * rslt = NULL;
    }

    return rc;
}
Beispiel #3
0
/* 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;
}
Beispiel #4
0
 /* Version
  *  returns the metadata format version
  */
 inline rc_t Version ( uint32_t *version ) const  throw()
 { return KMetadataVersion ( this, version ); }