Login Register

Handling binary objects in Recital

In this article Chris Mavin, explains and details how to Store and Retrieve Binary Objects in a Recital Database.

Storing and retrieving binary objects in the Recital RDBMS is achieved using the OBJECTREAD() and OBJECTWRITE() 4GL Functions. Using these Functions it is possible to read binary files into a table and write binary files out from a table simply by using one line of code.

In modern IT, data isn't just represented by numbers and small strings but increasingly multimedia as well. Recital databases can contain all types of information, text, audio, images and video to name but a few. Using a database to store all these data types provides many advantages over simply storing the media on a file system.

Storing your media in a database allows for well structured data organization making it possible to identify and separate the context of the information from its content. Storing your multimedia in a well structured manner allows for very effective querying and flexible indexing of the information. Indexing of the images along with the metadata improves the stored media's availability and quality of service with greatly enhanced query performance.

There are benefits in efficient storage of large amounts of data and scalability when using a database. Although file systems are designed to handle a large number of objects of varying sizes, file systems usually are not optimized for huge numbers of small files. The Recital database is optimized for such cases.

The Recital Database has transactional support for concurrent users using advanced row level locking and transaction isolation levels. Transaction isolation levels allow fine granular control of how isolated each transaction is i.e. what kind of locks are associated with queries inside the transaction.

Tight integration between standard data and multimedia data means greatly improved manageability of the data. Images stored in the database can be directly linked with metadata. In one transaction an image can be updated and all the associated metadata modified. If an image is stored in a file system, then it is possible for deletions or modification of that image to occur leading to related information not being in sync.

There are major advantages in security to storing an image in a Recital database; fine grained access security becomes possible down to column level protection. Access to an image can be restricted to individual users and a number of advanced access capabilities which would not be possible when using just a standard file system.

Back up and recovery of images stored in the database along with metadata is greatly simplified by the requirement of only one backup program to backup the database which will include the images. This simplifies the backup process significantly. In the event of some sort of failure the whole database can be recovered in one procedure. In addition to this the Recital Database has the optional use of journaling which records all queries that update the database allowing the recovery of the database back to the very last committed transaction.

There are portability advantages to storing your media in a Recital database. If you have to port your application and/or data to another platform, having your media stored in a database makes this process easy. Simply install the Recital Database on the platform you are migrating to and then move the database. Recital provides excellent migration tools which allow you to easily migrate your database even to a binary incompatible hardware platform. In summary there are many advantages to using a database to store your multimedia and metadata. This is made even simpler when using a Recital Database as the 4GL provides functions that make working with media and binary objects extremely simple and fast to code.

These are the OBJECTREAD(), OBJECTWRITE(), and OBJECTYPE() functions which are detailed below.


The OBJECTREAD() function reads an external binary file into a Recital Object field. When executed the function returns .T. if the operation was successful, and .F. otherwise.

The Syntax used is as follows:

OBJECTREAD(<filename>,<object field>)

The file to read into the database is specified in <filename> parameter, and can be any valid Recital/4GL expression that returns a valid file name. The first three characters of the file extension are then stored in the Object field as the Objects type. This type can be returned using the OBJECTTYPE() function which we will discuss later in this article.

The field into which the file is placed is specified in <object field> parameter, this must be a Recital Object field in the currently selected work area.
// Read a gif image into the WALLPAPER Object field 
? objectread('images/brickwall.gif',WALLPAPER)


Once a binary object is read into a Recital Object Field, to write the object to an external binary file you use the OBJECTWRITE() function. This writes an external binary file from a Recital Object field. When executed the OBJECTWRITE() function .T. is returned if the external binary file was created successfully, and .F. otherwise.

The Syntax to use is as follows:

OBJECTWRITE(<filename>,<object field> [,<expL>])

The name of the file to create can be specified in the parameter <filename> parameter. This can be any valid Recital/4GL expression that returns a valid filename. It is possible to specify a empty string as the filename parameter providing that the logical expression resolves tobe true (.T.). In this case, a unique temporary file name will be generated and the Object written to this file, with the file name being returned from OBJECTWRITE().

The Recital object field containing the data to be written, is specified in the parameter <object field>, and must be a valid field in the currently selected work area.
//Write the Binary Object stored in ICONS to the filename myicon.gif
? objectwrite("myicon.gif", ICONS) 

// Write the Binary Object stored in PHOTO to a temporary file and return the file name
? objectwrite("", PHOTO, .T.) 


The OBJECTTYPE() function allows you to interrogate a Recital Object Field and return the Object file extension of the Object which is stored in the Database.

The Syntax used is as followed:

? objecttype(IMAGES) 

Copyright © 2024 Recital Software Inc.



User Registration
or Cancel