Re: Reading a LONG RAW in ORACLE 7.3

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Fri, 10 Jul 1998 14:51:32 GMT
Message-ID: <35a729f6.7126907_at_192.86.155.100>


A copy of this was sent to "Hans Meijer" <hans_meijer_at_csi.com> (if that email address didn't require changing) On Fri, 10 Jul 1998 12:35:11 +0100, you wrote:

>I have the following problem:
>
>We store audio files (.wav) into a LONG RAW type of field.
>The next step is reading these LONG RAW fields and creating the original
>audio file again because we want to use it.
>
>How do I read those LONG RAW fields and How do I get the original format
>back again.
>
>Regards,
>
>Hans Meijer
>A.M.I.
>
>Netherlands.
>
>hans_meijer_at_csi.com
>
>

what language? Its really hard to answer that if you don't specify a language you are coding in..... anyway, in C using OCI it could look like the following. save_image is a routine that expects you to send it a query that selects 2 columns -- the first a long raw, the second a filename to use to save it to.... It piecewise fetches it 64k at a time and writes it to a file.

Hope this helps

....

void save_images( char * sql_statement ) {
ub1 * ucp;
int UCP_SIZE = 65536;

sb2      indp = 0;
sb2      indp2 = 0;
ub4      ret_len = 0;
ub2      retl = 0;
ub2      retl2 = 0;
ub2      rcode = 0;
ub2      rcode2 = 0;
int      fetched;
text     file_name[255];
FILE     * output;
int     rc;

    ucp = (ub1 *)malloc( UCP_SIZE );
    if ( !ucp )
    {

        printf(  "Unable to allocate %d bytes", UCP_SIZE );
        exit(1);

    }

    if (oparse(&cda, sql_statement, -1, 0, 2))     {

        printf( oerr_cda() );
        exit(1);

    }

    if (odefin(&cda, 1, ucp, UCP_SIZE, 24, -1,     /* if (odefin(&cda, 1, ucp, UCP_SIZE, 8, -1, */

               &indp, (text *) 0, 0, -1, &retl, &rcode))     {

       printf( "Error binding column1\n" );
       printf(oerr_cda());
       fflush( stdout );
       exit(1);

    }
    if (odefin(&cda, 2, file_name, sizeof(file_name), STRING_TYPE, -1,

               &indp2, (text *) 0, 0, -1, &retl2, &rcode2))     {

       printf( "Error binding column2\n" );
       printf(oerr_cda());
       exit(1);

    }

    for( rc = oexfet(&cda, (ub4) 1, 0, 0); !rc; rc = ofetch(&cda) )     {

       output = fopen( file_name, "wb" );
        if ( output == NULL )
        {
            perror( "fopen" );
            printf( "failed to open %s\n", file_name );
            exit(1);
        }
        for( fetched = 0, ret_len = 1; ret_len; fetched += ret_len )
        {
            if (oflng(&cda, 1, ucp, UCP_SIZE,
                        24, &ret_len, fetched ))
                        /* 8, &ret_len, fetched ))  */
            {
                printf(oerr_cda());
                exit(1);
            }
            if ( ret_len )
            {
                if ( fwrite( ucp, 1, ret_len, output ) != ret_len )
                {
                    perror( "fwrite" );
                    printf( "Fwrite of %d bytes fails\n", (int)ret_len );
                    exit(1);
                }
            }
        }
        fclose( output );
        printf( "Wrote File %s with %d bytes\n", file_name, fetched );
    }
}  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA  

http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Fri Jul 10 1998 - 16:51:32 CEST

Original text of this message