How import images (BLOB) in a Progress Table

maretix

Member
Hi to all.
I need to import a thirdy party products catalogue.
I did not have This catalogue yet...but thirdy party told me it will contain product code, ean code , product image.
I read about BLOB field ...so i will prepare a progress table (Versione 10.2.b i have) with a Blob field.
I read about COPY-LOB statement and i read examples about it.

My question is ...could be correct a 4GL code like this to import data in a Progress table ??
Or as anyone any good example of IMPORT of a catalogue file with images ???
I have really no experience about it...
I understood before need to use a MEMPTR variable and then i can copy it in a BLOB field DB...

Code:
DEF VAR w-product AS CHAR.
DEF VAR w-eancode AS CHAR.
DEF VAR w-memptr  AS MEMPRT NO-UNDO. /* I imagine to use a MEMPRT to import an image..*/

SET-SIZE(w-memptr) = 100. /* i read i have to set size of memprt variable */

INPUT FROM (Filename)

REPEAT:
IMPORT  UNFORMATTED w-product
                                                   w-eancode
                                                   w-memptr.

FIND FIRST table WHERE table.product = w-product NO-ERROR.
IF AVAIL table THEN ASSIGN table.product = w-product
                                                          table.eancode = w-eancode
                                                          table.image = w-memprt.
                                                         /* i read i could also to do an ASSIGN instead of COPY-LOB*/

END.

SET-SIZE(w-memprt) = 0 /* i read i need to clear memory */

INPUT CLOSE.

Regards in advance for any help.

Thanks.

Edit: Added CODE tags.
 
Last edited by a moderator:
You can store images in a BLOB column. But that isn't a sufficient argument that you should.

Have you considered putting the images in the file system and storing the filenames and path(s) in the database?
 
This is something we are getting bitten by at the moment. We had a "can you just" thing with blobs a few years back and somebody implemented it. We now have 175GB of blob data in the database - more than 50% of db size on disk! We will be changing this to a file system solution over the next few months.
 
As an asside...
Code:
FIND FIRST table WHERE table.product = w-product NO-ERROR.
This is terrible coding IMO. Will there only be one table with that product? If so, you don't need to add FIRST. If there are many, then how do you know it has the right one? Additionally, you are not specifying a lock. You should fine records with NO-LOCK or EXCLUSIVE-LOCK as you require them. Your code will result in share locks and contention issues.

Actually there are some other problems with your code, so I'm hoping it's just pseudo-code. :)
 
Last edited:
As for a solution, you are seriously over-complicating this. If you do go down the blob route then all you need is something like this:
Code:
     COPY-LOB FILE lv-FileName 
            TO OBJECT BinaryObject.BloObject NO-ERROR.

No need for mem pointers or anything like that.
 
As for a solution, you are seriously over-complicating this. If you do go down the blob route then all you need is something like this:
Code:
     COPY-LOB FILE lv-FileName
            TO OBJECT BinaryObject.BloObject NO-ERROR.

No need for mem pointers or anything like that.

Thanks to all of you for your kind reply.
Yes Cringer ,,,my code was terrible ...it was only a pseudo code...to have an example how to store an image..only this !!!
You are really right !!!!
Yes i think the best solution is to create a table with only path and name of images (as Post of Rob FitzPatrick.suggest)...and store all of them in the file system..we have a good Nas server that can do that work...
I read about COPY-LOB FILE and you are right..good solution to store an image file in a BLOB field...
Sorry i am new about that kind of problem...so i asked help and advices to you and Rob...

Many thanks a lot !!!
 
You can store images in a BLOB column. But that isn't a sufficient argument that you should.

Have you considered putting the images in the file system and storing the filenames and path(s) in the database?

Hi Rob.
Many thanks for your kind reply.
I think you are right and the best solution is to store all products images in our file system (We have a good NAS Serverthat can do it).
So we need to store images in a table for example named 'Images' with fields as ProductId,,Description...Path Image..Name Image

Example :

ProductId = 'SAM012345'
Description = 'Samsung Printer Mod. 2345 Black'
Path Image = '/ak98/aku/nas0/images/samsumg'
Name Image = 'SAM012345.jpg'

Something like this i think...

Many thanks Rob...!!!!
 
Welll...

Sometimes you want stuff in the db because it is safer there. Yes, it might use a lot of space etc. But sometimes that's ok.
 
Well, I guess the safety of data is a function of where your security knowledge and experience lies. Given OE's developer-friendly (i.e. wide open) default security configuration, you have to take steps to secure it. If a person is comfortable with locking down OE databases and knows the various ways to get at the data and how to mitigate those risks then maybe that data is safer there.

On the other hand, if data is "unsafe" in the file system then its logical access controls are probably configured badly. So if your security expertise is stronger in the OS than in OE then its probably better to store the files in the file system.
 
Hello Everyone,

I have a related question:

I am trying to store images into database BLOB filed and later wants to display them accordingly, i tried this code to store images:

Code:
CREATE temp.
COPY-LOB FILE "c:\rajat\image.jpeg"
       TO OBJECT temp.bigb.

This code compiles successfully but when i ran this code, i got an ERROR: CANNOT OPEN FILE "c:\rajat\image.jpeg" ERROR:2. One more thing, once i store the image in BLOB field then how could i display it later(by using frame or something: no idea ).

Thanks & Regards,
Rajat.
 
Does the file actually exist? You might need to put VALUE() around the file name for it to work.

To display the image you could create an image widget on a screen and point it to the image you have extracted from the blob into a temporary location. Although bare in mind that Progress image widgets will resize the image to the size of the widget.
 
Hi Cringer,

Yes, file exists. i tried to put file name in VALUE() but this time compilation error for COPY-LOB statement.
After reading the documentation it seems that either VALUE() doesn't work with COPY-LOB or i am writing wrong syntax for this, please suggest?

Code:
DEF VAR l-path AS CHAR INIT "c:\rajat\image.jpeg" NO-UNDO.
CREATE temp.
COPY-LOB FILE VALUE(l-path)
        TO OBJECT temp.bigb.

Is there any documentation or link or code, that i can go through to display the images from BLOB field.

Thanks & Regards!
Rajat.
 
Just checked - our code is...
Code:
COPY-LOB FILE lv-FileName
            TO OBJECT BinaryObject.BloObject NO-ERROR.
 
Yes, it works fine. :)

I am not getting much idea that from where i should start coding for displaying BLOB images(image widgets), is there any code or documentation or something that i can follow for the same?

Thanks & Regards!
Rajat.
 
You might be better off calling out to a web browser and giving the image as the page you want to display.
 
Displaying images is a very generic requirement. If you are running a classic Progress GUI ( prowin32.exe ) then the ABL provides an image widget that you can use to display the images. Plus there are all sorts of OCX controls out in the market that you could use too. If you are running a .NET GUI then you would use whatever .NET provides to display images.

Nevertheless, in the ABL you could code something like this:
Code:
define image logoImage  size 129 by 3.33.
logoImage:load-image ( imageFileName ).

Heavy Regards, RealHeavyDude.
 
Back
Top