TEXT TO BLOB

4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next

version 11 (Modified)


TEXT TO BLOB (text; blob; textFormat{; offset | *})

ParameterTypeDescription
textStringText to write into the BLOB
blobBLOBBLOB to receive the text
textFormatNumberFormat and character set of text
offset | *Variable | *Offset within the BLOB (expressed in bytes)
or * to append the value
New offset after writing if not *

Description

The TEXT TO BLOB command writes the Text value text into the BLOB blob.

The textFormat parameter fixes the internal format and the character set of the text value to be written. In databases created beginning with version 11, 4D uses the Unicode character set (UTF8) by default for managing text. For the sake of compatibility, this command can be used to "force" conversion using the Mac Roman character set (used in previous versions of 4D). The character set is chosen via the textFormat parameter. To do this, pass one of the following constants (found in the"BLOB" theme) in the textFormat parameter:

ConstantTypeValue
Mac C stringLong Integer0
Mac Pascal stringLong Integer1
Mac Text with lengthLong Integer2
Mac Text without lengthLong Integer3
UTF8 C stringLong Integer4
UTF8 Text with lengthLong Integer5
UTF8 Text without lengthLong Integer6

Notes:

The "UTF8" constants can only be used when the application runs in Unicode mode.

The "Mac" constants cannot work with texts greater than 32 KB.

If you want to work with character sets other than UTF8, use the CONVERT FROM TEXT command.

The following table describes each of these formats:

Text formatDescription and Examples
C string The text is ended by a NULL character (ASCII code $00).
UTF8"" $00
"Café" $43 61 66 C3 A9 00
Mac"" $00
"Café" $43 61 66 8E 00
Pascal stringThe text is preceded by a 1-byte length.
UTF8-
-
Mac"" $00
"Café" $04 43 61 66 8E
Text with lengthThe text is preceded by a 3-byte (UTF8) or 2-byte (Mac) length.
UTF8"" $00 00 00 00
"Café" $00 00 00 05 43 61 66 C3 A9
Mac"" $00 00
"Café" $00 04 43 61 66 8E
Text without lengthThe text is composed only of its characters.
UTF8"" No data
"Café" $43 61 66 C3 A9
Mac"" No data
"Café" $43 61 66 8E

If you specify the * optional parameter, the Text value is appended to the BLOB; the size of the BLOB is extended accordingly. Using the * optional parameter, you can sequentially store any number of Integer, Long Integer, Real or Text values (see other BLOB commands) in a BLOB, as long as the BLOB fits into memory.

If you do not specify the * optional parameter nor the offset variable parameter, the Text value is stored at the beginning of the BLOB, overriding its previous contents; the size of the BLOB is adjusted accordingly.

If you pass the offset variable parameter, the Text value is written at the offset (starting from zero) within the BLOB. No matter where you write the Text value, the size of the BLOB is, increased according to the location you passed (plus up to the size of the text, if necessary). New allocated bytes, other than the ones you are writing, are initialized to zero.

After the call, the offset variable parameter is returned, incremented by the number of bytes that have been written. Therfore, you can reuse that same variable with another BLOB writing command to write another value.

Example

After executing this code:

   SET BLOB SIZE (vxBlob;0)
   C_TEXT (vtValue)
   vtValue := "Café"  ` Length of vtValue is 4 bytes
   TEXT TO BLOB (vtValue;vxBlob;Mac C string)  ` Size of BLOB becomes 5 bytes
   TEXT TO BLOB (vtValue;vxBlob;Mac Pascal string)  ` Size of BLOB becomes 5 bytes
   TEXT TO BLOB (vtValue;vxBlob;Mac Text with length)  ` Size of BLOB becomes 6 bytes
   TEXT TO BLOB (vtValue;vxBlob;Mac Text without length)  ` Size of BLOB becomes 4 bytes
   TEXT TO BLOB (vtValue;vxBlob;UTF8 C string)  ` Size of BLOB becomes  6 bytes
   TEXT TO BLOB (vtValue;vxBlob;UTF8 Text with length)  ` Size of BLOB becomes 9 bytes
   TEXT TO BLOB (vtValue;vxBlob;UTF8 Text without length)  ` Size of BLOB becomes 5 bytes

See Also

BLOB to integer, BLOB to longint, BLOB to real, BLOB to text, CONVERT FROM TEXT, INTEGER TO BLOB, LONGINT TO BLOB, REAL TO BLOB.


4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next