Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: defining a variable to hold LONG field using OCI
A copy of this was sent to shaih_at_NoSpaMinter.net.il (Shaya)
(if that email address didn't require changing)
On Wed, 18 Nov 1998 14:52:16 GMT, you wrote:
>Hi All
>I'm using Oracle 7.3 and I'm trying to work with LONG fields.
>
>How can I get the actual size of the data in a long field before I use
>the odefin() so I don't have to allocate all 2^32 (max size)?
>
>My LONG field needs to get sometimes a data length of over 2000 bytes
>(up to 100M) , but most of the times it is much shorter (under 1024
>bytes) is there some other type I can use to hold it?
>
>Thanks in advance
>Shaya
>Remove the NoSpaM from my e-mail address to reply
you could piecewise fetch the data. Here is a quick example. this function expects a sql statement that fetches 2 columns -- column 1 is a long raw and column2 is the name of a file to open and write the long raw to (change the odefin call to bind a datatype = 8 instead of 24 to allow this to work for LONGS)...
#include <stdio.h> #include <string.h> #include <stdlib.h>
#include "unload.h"
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);
&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
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 Wed Nov 18 1998 - 11:33:17 CST