コード例 #1
0
ファイル: wdatabase.c プロジェクト: thelegend6420/ncbi-vdb
/* OpenUpdate
 *  finish create operation
 */
static
rc_t VDatabaseOpenUpdate ( VDatabase *self, const char *decl )
{
    /* open metadata */
    rc_t rc = KDatabaseOpenMetadataUpdate ( self -> kdb, & self -> meta );
    if ( rc == 0 )
    {
        /* fetch stored schema */
        rc = VDatabaseLoadSchema ( self );
        if ( rc == 0 )
        {
            /* fetch requested schema */
            const SDatabase *sdb = self -> sdb;
            if ( decl != NULL && decl [ 0 ] != 0 )
            {
                uint32_t type;
                const SNameOverload *name;
                sdb = ( self -> dad != NULL ) ?
                    SDatabaseFind ( self -> dad -> sdb, self -> schema,
                        & name, & type, decl, "VDatabaseOpenUpdate" ):
                    VSchemaFind ( self -> schema,
                        & name, & type, decl, "VDatabaseOpenUpdate", true );
                if ( sdb != NULL && type != eDatabase )
                {
                    PLOGMSG ( klogWarn, ( klogWarn, "expression '$(expr)' is not a database",
                               "expr=%s", decl ));
                    sdb = NULL;
                }
            }

            /* error if the two definitions differ */
            if ( sdb != NULL && self -> sdb != NULL && sdb != self -> sdb )
                rc = RC ( rcVDB, rcDatabase, rcOpening, rcSchema, rcIncorrect );
            else if ( sdb == NULL && self -> sdb == NULL )
                rc = RC ( rcVDB, rcDatabase, rcOpening, rcSchema, rcNotFound );
            else
            {
                if ( sdb != NULL )
                    self -> sdb = sdb;

                /* write schema to metadata */
                rc = VDatabaseStoreSchema ( self );
                if ( rc == 0 )
                    return 0;
            }
        }
    }

    DBGMSG(DBG_VDB, DBG_FLAG(DBG_VDB_VDB), ("VDatabaseOpenUpdate = %d\n", rc));

    return rc;
}
コード例 #2
0
ファイル: wtable.c プロジェクト: binlu1981/ncbi-vdb
/* OpenUpdate
 *  finish create operation
 */
static
rc_t VTableOpenUpdate ( VTable *self, const char *decl )
{
    /* open metadata */
    rc_t rc = KTableOpenMetadataUpdate ( self -> ktbl, & self -> meta );
    if ( rc == 0 )
    {
        /* open "col" node */
        rc = KMetadataOpenNodeUpdate ( self -> meta, & self -> col_node, "col" );
        if ( rc == 0 )
        {
            /* fetch stored schema */
            rc = VTableLoadSchema ( self );
            if ( rc == 0 )
            {
                /* fetch requested schema */
                const STable *stbl = self -> stbl;
                if ( decl != NULL && decl [ 0 ] != 0 )
                {
                    uint32_t type;
                    const SNameOverload *name;

                    if ( self -> db != NULL )
                    {
                        const STblMember *mbr = SDatabaseFind ( self -> db -> sdb,
                            self -> schema, & name, & type, decl, "VTableOpenUpdate" );
                        if ( mbr == NULL || type != eTblMember )
                        {
                            PLOGMSG ( klogWarn, ( klogWarn, "expression '$(expr)' is not a table member",
                                       "expr=%s", decl ));
                            stbl = NULL;
                        }
                        else
                        {
                            stbl = mbr -> tbl;
                            assert ( stbl != NULL );
                        }
                    }
                    else
                    {
                        stbl = VSchemaFind ( self -> schema,
                            & name, & type, decl, "VTableOpenUpdate", true );
                        if ( stbl != NULL && type != eTable )
                        {
                            PLOGMSG ( klogWarn, ( klogWarn, "expression '$(expr)' is not a table",
                                       "expr=%s", decl ));
                            stbl = NULL;
                        }
                    }
                }

                /* error if the two definitions differ */
                if ( stbl != NULL && self -> stbl != NULL && stbl != self -> stbl )
                    rc = RC ( rcVDB, rcTable, rcOpening, rcSchema, rcIncorrect );
                else if ( stbl == NULL && self -> stbl == NULL )
                    rc = RC ( rcVDB, rcTable, rcOpening, rcSchema, rcNotFound );
                else if ( self -> stbl == NULL )
                {

                    /* write schema to metadata */
                    self -> stbl = stbl;
                    rc = VTableStoreSchema ( self );
                }
                else if ( stbl != NULL )
                {
                    /* use latest schema but don't overwrite in metadata */
                    self -> stbl = stbl;
                }
            }
        }
    }

    DBGMSG(DBG_VDB, DBG_FLAG(DBG_VDB_VDB), ("VTableOpenUpdate = %d\n", rc));

    return rc;
}