8. Working with Images and Text Strings : How You Can Work with Images : BitmapObject Class : How You Can Store Images in a Database
 
Share this page                  
How You Can Store Images in a Database
To store images in a database, use OpenROAD to add them to a table. OpenROAD automatically creates a special bitmap storage table called ii_stored_bitmaps. However, you can create your own bitmap storage table to improve distribution of the images in the database and avoid transaction bottlenecks. For more information about creating your own bitmap storage table, see How You Can Create a Bitmap Storage Table (see How You Can Create a Bitmap Storage Table).
Each image in the bitmap storage table is associated with a handle, called a DBHandle, which you use to access the image. For example, to display an image stored in the database, you can set the value of the DBHandle attribute to the DBHandle for that image. OpenROAD then displays the image that is associated with that particular DBHandle. You must store the DBHandles for the images in a separate table from the images themselves.
Use the InsertIntoDB method to add the image to the database table. The InsertIntoDB method adds the image to the table you specify or, if you do not specify a table, to the system table. (To use a bitmap storage table other than the system table, you must set it up as described in How You Can Create a Bitmap Storage Table (see How You Can Create a Bitmap Storage Table).)
To add the images to the database, you would perform the following basic steps:
1. Define a varchar(76) column to hold the DBHandles in the table that contains the data for your application.
2. Decide whether to store the images in the system table or your own table.
3. Set the FileHandle attribute of the BitmapObject to the file name. OpenROAD copies the image from the specified file and stores the copy in the bitmap object.
If there is an image field on your form, you can use the BitmapObject associated with the image field. If there is no image field, declare a variable of type bitmap object to use for loading the images.
4. Use the InsertIntoDB method to insert into the database table the image that is now in the bitmap object. After this method completes, OpenROAD stores the new DBHandle for the image in the DBHandle attribute.
5. Add the current value of the DBHandle attribute to your database table so that you can access the image the next time you need it.
6. Commit the changes to the database.
The image is now stored in the database. You can display the image by setting the DBHandle attribute, and you can replace or delete the image, if necessary, with the UpdateInDB or DeleteFromDB methods, respectively.
For a description of updating images in the database, see Update Bitmaps in a Database (see Update Bitmaps in a Database). For more information about error handling for the InsertIntoDB method, see Working with a Database (see Working with a Database).
Note:  Do not use these database methods for BitmapObjects with autocommit turned on because the multiple database statements involved in accessing the BitmapObject data can produce incorrect results.