clobs and blobs -- HELP

YET71

New Member
Im having some dificulty figuring out how to use clobs and blobs.

If someone has some examples of how to:

1) load an image into a blob using a CGI wrapper
2) load an image into a blob in gui.
3) display an image from a blob using CGI wrapper
4) display an image from a blob in gui.
5) Load and display a clob...
id be extremely greatful...

ive been struggling with this for a little while... the answer is probably simple, i just cant seem to get my head around it. :(

Patrick.
 

Kirmik

Member
I've never actually used Blobs and Clobs so what I'm about to say may not be entirely accurate but try it and see how you get on:


Saving to the database as a BLOB

Code:
 [font='Courier New']COPY-LOB from file image.jpg [/font]
[font='Courier New']TO database.field   [/font]
[font='Courier New']CONVERT SOURCE  “filename”. [/font]





Viewing BLOBs:
You can't view the BLOB directly from the database. Instead you have to write the file to disk and then view it that way
Here's an example of displaying an image from a blob in gui.

Code:
 [font='Courier New']/* Find the employee record */ [/font]
[font='Courier New']FIND employee WHERE NAME EQ "John Public". [/font]
[font='Courier New']
[/font][font='Courier New']/* Create a temporary file to hold the image */ [/font][font='Courier New']picFile = SESSION:TEMP-DIRECTORY + “\” [/font]
[font='Courier New']  + customer.NAME + ".jpg". [/font]
[font='Courier New']
[/font][font='Courier New']/* Copy the image from the blob field to the [/font][font='Courier New'] * temporary file with COPY-LOB code */ [/font]
[font='Courier New']COPY-LOB employee.picture TO FILE picFile. [/font]
[font='Courier New'][/font]
[font='Courier New']/* Associate the image with a button */
[/font][font='Courier New']picture:LOAD-IMAGE(picFile). [/font][font='Courier New'][/font]
[font='Courier New']/* Delete the temporary file */ [/font]
[font='Courier New']OS-DELETE VALUE(picFile). [/font]
 

YET71

New Member
Kirmik: thanks for your help.. but ive still got a few issues.. \

my code is as follows:
Code:
DEFINE VAR picFile AS c.
DEFINE IMAGE chPic FILE "X:\img\yoda.gif".
FORM chPic WITH FRAME oout.
/* test that the Load-Image bit is correct... */
VIEW FRAME oout.
chPic:LOAD-IMAGE("X:\img\yoda.gif") IN FRAME oout.
 
/* load data into blob */
FIND webimg WHERE webimg.id = 1.
COPY-LOB FROM FILE "X:\img\yoda.gif" TO webimg.data.  
/* should probably have more options here, but i couldnt figure out "CONVERT TARGET CODEPAGE 'something' "*/
 
/* display from blob */
 picFile = "X:\" + string(webimg.id) + ".jpg".
/* output to screen, to confirm picFile is correct */
 MESSAGE picFile VIEW-AS ALERT-BOX.

COPY-LOB webimg.data TO FILE picFile. 
 
VIEW FRAME oout.
chPic:LOAD-IMAGE(picFile) IN FRAME oout. 
PAUSE.
 
 
/* before the pause errors occur:
 
** unable to query attribute LOAD-IMAGE for image chPic.
 
and ...
 
Could not retrieve length of blob to read.
 
*/
ive been thrown in at the deepend i think.. 5 years of chui.. and this is my first go at gui.. :( not to mention the jump from v8 to v10.
i think the blob isnt being loaded in correctly, but there is no error msg, so im not 100% sure.
 

Kirmik

Member
Hmmm - I dont have OE10 at the minute so can't test it for you but my initial thought is that you're loading a GIF and then trying to re-assemble it as a JPEG. That won't work for sure as the file formats are completely different. That may get rid of your "unable to query attribute LOAD-IMAGE for image chPic" error, assuming it successfully created file to disk in the first place.

Beyond that... sorry I can't be much more help :(
 

YET71

New Member
its not retrieving the length of the blob.
if someone knows how to check if there is data within a blob, that might help.
i tried to do a LENGTH(STRING(webimg.data)) ( comes back with 1).

ive also tried to load the img into a memptr then into a blob.. still same response.

thx for your help Kirmic.
 
Top