Kbase 17093: How to Implement BLOB Support in a Progress Database (8.2+)
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  3/14/2000 |
|
How to Implement BLOB Support in a Progress Database (8.2+)
INTRODUCTION:
=============
This knowledgebase entry describes how to store and retrieve binary
data in a Progress database.
This information only applies to Progress versions 8.2A and higher.
WHY YOU NEED TO KNOW THIS:
==========================
You need to know this if you have the need to store and retrieve
binary data from a Progress database (obviously).
CODE ASSUMPTIONS:
=================
In the following code examples I am making the following
assumptions:
- 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 */
DATABASE STRUCTURE:
===================
The database is made up of the following fields:
- ImageName CHARACTER, FORMAT "X(60)"
- ImageSequence INTEGER
- ImageData RAW
I also have an index 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 A BITMAP FROM THE DATABASE:
============================================
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.
Progress Software Technical Support Note # 17093