Consultor Eletrônico



Kbase 30720: 4GL. How to Implement BLOB Support in a Progress Database
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/10/1998
Solution ID: P720

GOAL:

How to implement BLOB support in a Progress Database

GOAL:

How to store and retrieve image / picture files in a Database field

FIX:

Use the following code example to implement BLOB support.

For the following code examples, certain assumptions are made:

Only bitmaps (*.BMP) will be stored in the database.

The bitmaps will be broken out into 16K (16,384 byte) chunks.

A bitmap will be added to the database by clicking on a push button and selecting a bitmap from the standard MS-Windows file open dialog box.

A bitmap will be retrieved and displayed by clicking on a row in a browse widget (i.e. the VALUE-CHANGED event).

There are only three (3) widgets on the window.  They are as follows:

1)  A push button which is used to add a bitmap to the database.

2)  A browse widget which displays a list of available bitmaps which are stored in the database and by which the user can select an image to be retrieved and displayed.

3)  An image widget which is used to display the retrieved bitmaps.

The widgets are named as follows:

1)  PBN-AddBitmap        /* push button used to add bitmap    */

2)  BRW-AvailableBitmaps /* browse listing available bitmaps  */

3)  IMG-Display          /* image widget that displays bitmap */

The database is made up of the following fields:

-  ImageName      CHARACTER, FORMAT "X(60)"
-  ImageSequence  INTEGER
-  ImageData      RAW

An index has also been defined containing ImageName and ImageSequence as fields in the index.  The index is defined as unique and primary.


/* CODE TO STORE A BITMAP IN THE DATABASE */

ON CHOOSE OF PBN-AddBitmap IN FRAME {&FRAME-NAME}
DO:
   DEFINE VARIABLE chrFileName  AS CHARACTER NO-UNDO.
   DEFINE VARIABLE logResult    AS LOGICAL   NO-UNDO.
   DEFINE VARIABLE rawImageData AS RAW       NO-UNDO.
   DEFINE VARIABLE intSequence  AS INTEGER   NO-UNDO INITIAL 1.

   SYSTEM-DIALOG GET-FILE chrFileName
       TITLE "Please Select a Bitmap to Add to the Database"
       FILTERS "Bitmap Files (*.bmp)" "*.bmp"
       MUST-EXIST RETURN-TO-START-DIR UPDATE logResult.

   IF logResult = False THEN
       RETURN NO-APPLY.

   ASSIGN logResult            = SESSION:SET-WAIT-STATE("GENERAL")
          LENGTH(rawImageData) = 16384.

   INPUT FROM VALUE(chrFileName) BINARY NO-MAP NO-CONVERT.

   REPEAT:
       IMPORT UNFORMATTED rawImageData.
       CREATE IMAGES.
       ASSIGN IMAGES.ImageName     = chrFileName
              IMAGES.ImageSequence = intSequence
              IMAGES.ImageData     = rawImageData
              intSequence          = intSequence + 1.
   END.

   INPUT CLOSE.

   ASSIGN logResult = SESSION:SET-WAIT-STATE("").

   OPEN QUERY BRW-AvailableBitmaps
       FOR EACH IMAGES
           WHERE IMAGES.IMAGE-SEQUENCE = 1 NO-LOCK.
END.


/* CODE TO RETRIEVE BITMAPS FROM THE DB */

ON VALUE-CHANGED OF BRW-AvailableBitmaps IN FRAME {&FRAME-NAME}
DO:
   DEFINE VARIABLE chrImageName AS CHARACTER NO-UNDO.
   DEFINE VARIABLE logResult    AS LOGICAL   NO-UNDO.

   ASSIGN logResult    = SESSION:SET-WAIT-STATE("GENERAL")
          chrImageName = IMAGES.ImageName.

   OUTPUT TO C:\TEMPBLOB.BMP NO-MAP NO-CONVERT BINARY.

   FOR EACH IMAGE NO-LOCK WHERE IMAGE.ImageName = chrImageName:
       PUT CONTROL IMAGE.ImageData.
   END.

   OUTPUT CLOSE.

   ASSIGN logResult = SESSION:SET-WAIT-STATE("")
          logResult = IMG-Display:LOAD-IMAGE("")
          logResult = IMG-Display:LOAD-IMAGE("C:\TEMPBLOB.BMP").
END.