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, Double, 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 tables fields depending on user's DBMS:
Type of the field in the repository table | Oracle | Microsoft SQL Server | DB2 |
Custom | LONG RAW | VARBINARY(MAX) | BLOB |
Text | CLOB (NCLOB when working with Unicode) | VARCHAR(MAX) (NVARCHAR(MAX) on working in Unicode) | CLOB (NCLOB when working with Unicode) |
Binary | BLOB | VARBINARY(MAX) | BLOB |
To get supported DBMS version, see theSupported 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 set 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 reference 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. For this purpose a static method is used FromVariant of the class IOStream. 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 this 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 | An 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 entry back.
The Button button named BNext. It is used to move data in the cache one entry forward.
The Button button named BAdd. It is used to create a new entry.
A Label named ImgName. It is used to display path and name of the loaded file.
An ImageBox (PictureBox in Fore.NET) 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 cache entries are obtained. Clicking the BPrior and BNext buttons allows navigating the cache entries. Any move in the cache invokes the LoadRecord procedure. This procedure retrieves values of current entry fields. Image from the IMG field is loaded in the stream, the content of which is loaded in the ImgBox component. Clicking the BAdd button displays the file selection dialog box. After selecting an image file, a new entry is added. File name and the file itself are recorded in the table. The Fore.NET example uses the ForeIOStreamMarshaler class that allows casting the IIOStream Fore type to the System.IO.Stream .NET type, which is needed for loading the image in the PictureBox component.
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: