Пример #1
0
static
uint32_t dump_col ( const KColumn *col, const char *dbname, const char *tblname, const char *colname )
{
    rc_t rc = 0;
    int64_t row, first;
    const KColumnBlob *blob;
    uint32_t count, num_blobs;

    for ( num_blobs = 0, row = 1; rc == 0 && num_blobs < blob_limit; ++ num_blobs, row = first + count )
    {
        rc = KColumnOpenBlobRead ( col, & blob, row );
        if ( rc == 0 )
        {
            rc = KColumnBlobIdRange ( blob, & first, & count );
            if ( rc != 0 )
                fprintf ( stderr, "failed to get row-range for blob containing row '%s.%s.%s.%ld'\n", dbname, tblname, colname, row );
            else
            {
                size_t num_read, remaining;
                rc = KColumnBlobRead ( blob, 0, & first, 0, & num_read, & remaining );
                if ( rc != 0 )
                    fprintf ( stderr, "failed to get size of blob containing row '%s.%s.%s.%ld'\n", dbname, tblname, colname, row );
                else
                {
                    printf ( "  %ld .. %ld ( %u rows ), %zu bytes\n", first, first + count - 1, count, remaining );
                }
            }

            KColumnBlobRelease ( blob );
        }
        else if ( GetRCState ( rc ) == rcNotFound )
            return num_blobs;
        else
        {
            fprintf ( stderr, "failed to open blob for row '%s.%s.%s.%ld'\n", dbname, tblname, colname, row );
        }
    }

    for ( ; rc == 0; ++ num_blobs, row = first + count )
    {
        rc = KColumnOpenBlobRead ( col, & blob, row );
        if ( rc == 0 )
        {
            rc = KColumnBlobIdRange ( blob, & first, & count );
            KColumnBlobRelease ( blob );
        }
    }

    return num_blobs;
}
Пример #2
0
/* ReadAll
 *  read entire blob, plus any auxiliary checksum data
 *
 *  "buffer" [ OUT ] - pointer to a KDataBuffer structure that will be initialized
 *  and resized to contain the entire blob. upon success, will contain the number of bytes
 *  in buffer->elem_count and buffer->elem_bits == 8.
 *
 *  "opt_cs_data [ OUT, NULL OKAY ] - optional output parameter for checksum data
 *  associated with the blob in "buffer", if any exist.
 *
 *  "cs_data_size" [ IN ] - sizeof of * opt_cs_data if not NULL, 0 otherwise
 */
LIB_EXPORT rc_t CC KColumnBlobReadAll ( const KColumnBlob * self, KDataBuffer * buffer,
    KColumnBlobCSData * opt_cs_data, size_t cs_data_size )
{
    rc_t rc = 0;

    if ( opt_cs_data != NULL )
        memset ( opt_cs_data, 0, cs_data_size );

    if ( buffer == NULL )
        rc = RC ( rcDB, rcBlob, rcReading, rcParam, rcNull );
    else
    {
        if ( self == NULL )
            rc = RC ( rcDB, rcBlob, rcReading, rcSelf, rcNull );
        else
        {
            /* determine blob size */
            size_t bsize = self -> loc . u . blob . size;

            /* ignore blobs of size 0 */
            if ( bsize == 0 )
                rc = 0;
            else
            {
                /* initialize the buffer */
                rc = KDataBufferMakeBytes ( buffer, bsize );
                if ( rc == 0 )
                {
                    /* read the blob */
                    size_t num_read, remaining;
                    rc = KColumnBlobRead ( self, 0, buffer -> base, bsize, & num_read, & remaining );
                    if ( rc == 0 )
                    {
                        /* test that num_read is everything and we have no remaining */
                        if ( num_read != bsize || remaining != 0 )
                            rc = RC ( rcDB, rcBlob, rcReading, rcTransfer, rcIncomplete );

                        else
                        {
                            /* set for MD5 - just due to switch ordering */
                            size_t cs_bytes = 16;

                            /* if not reading checksum data, then we're done */
                            if ( opt_cs_data == NULL )
                                return 0;

                            /* see what checksumming is in use */
                            switch ( self -> col -> checksum )
                            {
                            case kcsNone:
                                return 0;

                            case kcsCRC32:
                                /* reset for CRC32 */
                                cs_bytes = 4;

                                /* no break */

                            case kcsMD5:
                                if ( cs_data_size < cs_bytes )
                                {
                                    rc = RC ( rcDB, rcBlob, rcReading, rcParam, rcTooShort );
                                    break;
                                }

                                /* read checksum information */
                                rc = KColumnDataRead ( & self -> col -> df,
                                    & self -> pmorig, bsize, opt_cs_data, cs_bytes, & num_read );
                                if ( rc == 0 )
                                {
                                    if ( num_read != cs_bytes )
                                        rc = RC ( rcDB, rcBlob, rcReading, rcTransfer, rcIncomplete );
                                    else
                                    {
                                        /* success - read the blob AND the checksum data */
                                        return 0;
                                    }
                                }
                                break;
                            }
                        }
                    }

                    KDataBufferWhack ( buffer );
                }
            }
        }

        memset ( buffer, 0, sizeof * buffer );
    }

    return rc;
}