Пример #1
0
static
void dump_tbl ( const KTable *tbl, const char *tblname, int argc, char *argv [] )
{
    if ( argc >= 4 )
    {
        int i;
        for ( i = 3; i < argc; ++ i )
        {
            dump_col_name ( tbl, argv [ 1 ], tblname, argv [ i ] );
        }
    }
    else
    {
        KNamelist *names;
        rc_t rc = KTableListCol ( tbl, & names );
        if ( rc != 0 )
            fprintf ( stderr, "failed to list columns for tbl '%s.%s'\n", argv [ 1 ], tblname );
        else
        {
            uint32_t count;
            rc = KNamelistCount ( names, & count );
            if ( rc != 0 )
                fprintf ( stderr, "failed to count columns for tbl '%s.%s'\n", argv [ 1 ], tblname );
            else
            {
                uint32_t i;
                for ( i = 0; i < count; ++ i )
                {
                    const char *name;
                    rc = KNamelistGet ( names, i, & name );
                    if ( rc != 0 )
                        fprintf ( stderr, "failed to access column name [ %u ] for tbl '%s.%s'\n", i, argv [ 1 ], tblname );
                    else
                    {
                        dump_col_name ( tbl, argv [ 1 ], tblname, name );
                    }
                }
            }

            KNamelistRelease ( names );
        }
    }
}
Пример #2
0
LIB_EXPORT rc_t CC VTableExtendSchema ( const VTable *self )
{
    rc_t rc;

    if ( self == NULL )
        rc = RC ( rcVDB, rcTable, rcUpdating, rcSelf, rcNull );
    else
    {
        /* create symbol table for STable */
        KSymTable tbl;
        rc = init_tbl_symtab ( & tbl, self -> schema, self -> stbl );
        if ( rc == 0 )
        {
            KNamelist *names;
            const char *name;
            uint32_t i, count;

            /* list all physical tables from KTable */
            rc = KTableListCol ( self -> ktbl, & names );
            if ( rc != 0 )
                rc = 0;
            else
            {
                rc = KNamelistCount ( names, & count );
                for ( i = 0; rc == 0 && i < count; ++ i )
                {
                    /* if there are any stray columns, add them in */
                    rc = KNamelistGet ( names, i, & name );
                    if ( rc == 0 && VTableNameAvail ( & tbl, name ) )
                        rc = VTablePopulateStrayKColumn ( self, name );
                }

                KNamelistRelease ( names );
            }

            if ( rc == 0 )
            {
                /* access table's static columns */
                const KMDataNode *cols = self -> col_node;
                if ( cols != NULL )
                {
                    /* list all columns */
                    rc = KMDataNodeListChild ( cols, & names );
                    if (rc == 0) {
                        rc = KNamelistCount ( names, & count );
                        for ( i = 0; rc == 0 && i < count; ++ i )
                        {
                            rc = KNamelistGet ( names, i, & name );
                            if ( rc == 0 && VTableNameAvail ( & tbl, name ) )
                            {
                                const KMDataNode *node;
                                rc = KMDataNodeOpenNodeRead ( cols, & node, "%s", name );
                                if ( rc == 0 )
                                {
                                    /* add in static column */
                                    rc = VTablePopulateStrayStatic ( self, name, node );
                                    KMDataNodeRelease ( node );
                                }
                            }
                        }
                        KNamelistRelease ( names );
                    }
                }
            }
        }

        KSymTableWhack ( & tbl );
    }

    return rc;
}
Пример #3
0
/* ListPhysColumns
 *  avail: 2.4
 */
LIB_EXPORT rc_t CC VTableListPhysColumns ( const VTable *self, KNamelist **names )
{
    rc_t rc;

    if ( names == NULL )
        rc = RC ( rcVDB, rcTable, rcListing, rcParam, rcNull );
    else
    {
        * names = NULL;

        if ( self == NULL )
            rc = RC ( rcVDB, rcTable, rcListing, rcSelf, rcNull );
        else
        {
            KNamelist *kcol_names;
            rc = KTableListCol ( self -> ktbl, & kcol_names );
            if ( rc == 0 )
            {
                uint32_t kcol_count;
                rc = KNamelistCount ( kcol_names, & kcol_count );
                if ( rc == 0 )
                {
                    uint32_t scol_count = 0;
                    KNamelist *scol_names = NULL;
                    const KMDataNode *col_node = self -> col_node;

#if LAZY_OPEN_COL_NODE
                    if ( col_node == NULL )
                    {
                        rc = KMetadataOpenNodeRead ( self -> meta, & ( ( VTable* ) self ) -> col_node, "col" );
                        if ( rc == 0 || GetRCState ( rc ) != rcNotFound )
                            col_node = self -> col_node;
                    }
#endif
                    if ( col_node != NULL )
                    {
                        rc = KMDataNodeListChildren ( col_node, & scol_names );
                        if ( rc == 0 )
                            rc = KNamelistCount ( scol_names, & scol_count );
                    }

                    if ( rc == 0 )
                    {
                        VNamelist *vnames;
                        rc = VNamelistMake ( & vnames, kcol_count + scol_count );
                        if ( rc == 0 )
                        {
                            uint32_t i;
                            const char *name;

                            for ( i = 0; i < kcol_count && rc == 0; ++ i )
                            {
                                rc = KNamelistGet ( kcol_names, i, & name );
                                if ( rc == 0 )
                                    rc = VNamelistAppend ( vnames, name );
                            }

                            for ( i = 0; i < scol_count && rc == 0; ++ i )
                            {
                                rc = KNamelistGet ( scol_names, i, & name );
                                if ( rc == 0 )
                                    rc = VNamelistAppend ( vnames, name );
                            }

                            if ( rc == 0 )
                            {
                                rc = VNamelistToNamelist ( vnames, names );
                                if ( rc == 0 )
                                    VNamelistReorder ( vnames, false );
                            }
                        }

                        VNamelistRelease ( vnames );
                    }

                    KNamelistRelease ( scol_names );
                }

                KNamelistRelease ( kcol_names );
            }
        }
    }

    return rc;
}