In this article:
Article number: KB000031
When working with the repository table, on creating new fields the user should specify the data type to be stored in this field. In addition to basic types (String, Integer, Real, Date), one of the custom data types can be specified: Custom, Text or Binary. A certain type of field is created in the physical table on the server, to which this repository table corresponds. The following are the types of physical table fields depending on DBMS in use:
Type of the field in the repository table | PostgreSQL | Oracle | Microsoft SQL Server | DB2 |
Custom | LO | LONG RAW | VARBINARY(MAX) | BLOB |
Text | Text | CLOB (NCLOB when working with Unicode) | VARCHAR(MAX) (NVARCHAR(MAX) on working in Unicode) | CLOB (NCLOB when working with Unicode) |
Binary | LO | BLOB | VARBINARY(MAX) | BLOB |
To get supported DBMS version, see the Supported DBMS section.
Text fields are used to store character information. The values of such fields are specified as any character data, which length does not exceed the limit specified for this type of data.
Custom and binary fields are used to store binary data. Streams are used to work with this data type as described below.
Custom and binary fields take link to a stream that contains any data as their value. The stream may be associated with any file or created dynamically in memory. Repository objects that support saving to the stream can also be stored in custom fields. After transaction, stream data is recorded in the repository database. Custom and binary field values are also retrieved in the stream. This is executed by the FromVariant static method of the IOStream class. Data loaded in the stream can be edited and resaved later.
Var
//...
Fields: IDatasetInstanceFields;
StreamData: IIOStream;
//...
Begin
//...
Fields.FindById("<Field ID>").Value := StreamData;
//...
Var
//...
Fields: IDatasetInstanceFields;
StreamData: IIOStream;
//...
Begin
//...
StreamData := IOStream.FromVariant(Fields.FindById("<Field ID>").Value);
//...
Consider an example of writing and reading data in a binary field. To execute the example, create a table with the TImages identifier with the following fields:
Field identifier | Field type | Brief description |
IMG_NAME | Text | File name. |
IMG | Binary | Image file. |
Also create a form as an example. The following components are placed on the form:
The Button button named BPrior. It is used to move data in the cache one record back.
The Button button named BNext. It is used to move data in the cache one record forward.
The Button button named BAdd. It is used to create a new record.
A Label named ImgName. It is used to display path and name of the loaded file.
ImageBox named ImgBox. It is used to display images.
FileOpenDialog named OpenImageDlg. It is used to select image files.
When the form is loaded, the table opens and records cache is obtained. Clicking the BPrior and BNext buttons allows for navigating the cache records. Any move in the cache invokes the LoadRecord procedure. This procedure retrieves values of current records fields. An image from the IMG field is loaded in the stream, which contents is loaded in the ImgBox component. Clicking the BAdd button displays the file selection dialog box. After selecting an image file, a new record is added. File name and the file itself are recorded in the table.
To store a repository object in the IMG field, for example a regular report, transform the code above and add the following components to the form:
UiReport named UiReport1. Data source for the ReportBox visual component.
ReportBox named ReportBox1. Visual component for displaying the regular report loaded from the repository table.
MetabaseOpenDialog named OpenReportDlg. It is used to select a regular report from the repository.
See also: