Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

~How to use RAW and LONG RAW columns ?

26 views
Skip to first unread message

Richard Mc Connell

unread,
Jun 25, 1998, 3:00:00 AM6/25/98
to

Hey Y'all,

I'm trying to store BINARY files in a LONG RAW column (such as BITMAPs,
DOC files, WAVs etc), but none of my reference books tell me HOW to
actually do it.

I'm using Pro*C with Oracle 7.2 (so I can't use BLOBs !!)

Got any ideas ???


Thanks,
Richard

email: ric...@rockdb.demon.co.uk

Vladimir Pasechnik

unread,
Jun 25, 1998, 3:00:00 AM6/25/98
to

RC> Hey Y'all,
RC>
RC> I'm trying to store BINARY files in a LONG RAW column (such as BITMAPs,
RC> DOC files, WAVs etc), but none of my reference books tell me HOW to
RC> actually do it.
RC>
RC> I'm using Pro*C with Oracle 7.2 (so I can't use BLOBs !!)
RC>
RC> Got any ideas ???
RC>
RC>
RC> Thanks,
RC> Richard
RC>
RC> email: ric...@rockdb.demon.co.uk

Hi, Richard.
In Pro*C 2.x you can work with LONG RAW columns, using expression
EXEC SQL TYPE <your_structure> IS long varraw (MAX_FILE_SIZE);

where <your_structure> is

typedef struct { long len; char buf[MAX_FILE_SIZE]; } <your_structure>;

Example from sample going with the Pro*C 2.x documentation:

#include <sqlca.h>
#include <string.h>
#include <stdio.h>
#include <io.h>

#define DISCARD (void)
#define S2VCPY(vch,s) \
DISCARD strcpy((char *)vch.arr,s);\
vch.len = (unsigned short) strlen(s)
#define VCHNULL(v) v.arr[v.len] = '\0'
EXEC SQL BEGIN DECLARE SECTION;
#define MAX_FILE_SIZE 500000
typedef struct { long len; char buf[MAX_FILE_SIZE]; } long_varraw;
EXEC SQL END DECLARE SECTION;
EXEC SQL TYPE long_varraw IS long varraw (MAX_FILE_SIZE);

int insert(char *key,char *file)
{
EXEC SQL BEGIN DECLARE SECTION;
long_varraw lvr1;
VARCHAR key1[20];
EXEC SQL END DECLARE SECTION;
EXEC SQL DECLARE db_name DATABASE;

printf("Inserting file %s under key %s...\n", file, key);
S2VCPY(key1,key);
lvr1.len = read_file(file, lvr1.buf, MAX_FILE_SIZE);
if (lvr1.len == -1)
{ fprintf(stderr,"\n\nError while reading file ô%sô:\n", file);
EXEC SQL AT db_name ROLLBACK WORK RELEASE;
return(1);
}

EXEC SQL WHENEVER SQLERROR DO sql_error("insert");
EXEC SQL AT db_name INSERT INTO executables (name, binary)
VALUES (:key1, :lvr1);
EXEC SQL AT db_name COMMIT;
printf("Inserted.\n");
}

int read_file(char *filename,char *buf,long bufsize)
{
#define LOCAL_BUFFERSIZE 512

char local_buffer[LOCAL_BUFFERSIZE];
FILE *stream;
int number_read,in_fd,total_size=0;

if ((stream=fopen( filename, "rb" ))==NULL)
{ printf("Can't open file %s for read\n",filename); return(-2);}
in_fd=_fileno(stream);
while ((number_read = _read(in_fd, local_buffer,
LOCAL_BUFFERSIZE)) > 0)
{
if (total_size + number_read > bufsize)
{ close(in_fd); return(-1); }
memcpy(buf+total_size, local_buffer, number_read);
total_size += number_read;
}
_close(in_fd);
return(total_size);
}


I hope it will help.

WBR,
Vlad

UniSoft,ltd
Dniepropetrovsk
Ukraine


Michel Scory

unread,
Jul 1, 1998, 3:00:00 AM7/1/98
to

No way to do that with SQL or PL/SQL.
That's possible using OLE (getchunk, write(?)chunk). Check also CTXLOAD
(perhaps limited to ascii characters). In a Intranet environment you can
use Oracle Application Server 3.x in CGI mode.

Richard Mc Connell a écrit dans le message
<35921F79...@rockdb.demon.co.uk>...
>Hey Y'all,


>
>I'm trying to store BINARY files in a LONG RAW column (such as BITMAPs,

>DOC files, WAVs etc), but none of my reference books tell me HOW to

>actually do it.


>
>I'm using Pro*C with Oracle 7.2 (so I can't use BLOBs !!)
>

0 new messages