BYTE

The BYTE data type stores any type of binary data, such as images or sounds.

Syntax

BYTE

Usage

A BYTE variable is actually a 'locator' for a large object stored in a file or in memory. The BYTE data type is a complex type that cannot be used like simple types such as INTEGER or CHAR: It is designed to handle a large amount of unstructured binary data. This type has a theoretical limit of 2^31 bytes (~2.14 Gigabytes), but the practical limit depends from the disk or memory resources available to the process. Use the BYTE data type to store, fetch or update the contents of a BYTE database column when using IBM® Informix®, or the content of a BLOB column when using another type of database.

Keep in mind that a BYTE variable must be initialized with the LOCATE instruction before usage. You might want to free resources allocated to the BYTE variable with the FREE instruction. A FREE will remove the file if the LOB variable is located in a file.

The LOCATE instruction basically defines where the large data object has to be stored (in file or memory). This instruction will actually allow you to fetch a LOB into memory or into a file, or insert a LOB from memory or from a file into the database.

When you assign a BYTE variable to another BYTE variable, the LOB data is not duplicated, only the handler is copied.

If you need to clone the large object, you can use the I/O built-in methods to read/write data from/to a specific file. The large object can be located in memory, in a specific file or in a temporary file (the temp directory can be defined by the DBTEMP environment variable.

Methods

Table 1. Object methods of the BYTE data type
Name Description
readFile(fileName STRING)
Reads data from a file and copies into memory or to the file used by the variables according to the LOCATE statement issued on the object.
writeFile(fileName STRING)
Writes data from the variable (memory or source file) to the destination file passed as parameter. The file is created if it does not exist.
MAIN
  DEFINE b BYTE
  DATABASE stock 
  LOCATE b IN MEMORY
  SELECT png_image INTO b FROM images WHERE image_id = 123
  CALL b.writeFile("/tmp/image.png")
END MAIN