
As already mentioned in the blog post about the Update 5.7.05, the property spValueAlpha of CteNode objects can now hold up to 65,520 characters. In this article, I would like to discuss the background and the resulting changes for string processing.
Background
When reading XML files, it increasingly became the case that the content of individual nodes no longer fit within the previous limit of 4,096 characters. As a result, any strings longer than this were truncated at that point. The limit was subsequently increased to 65,520 characters.
Why 65,520 characters
Internally, the length has been extended to 65,536 bytes. However, 16 bytes are occupied by a header that contains the length of the string, the character set, and other information about the string.
Implications for other strings
Up to client version 5.7.04, assigning a string longer than 4,096 characters triggers the runtime error _ErrValueRange. If the target variable is shorter than 4,096 characters and a value that is too large (≤ 4,096 characters) is assigned to it, the runtime error _ErrStringOverflow occurred.
Starting with client version 5.7.05, commands that expect a string (e.g., StrIns()) can be passed a string with a maximum of 65,520 characters. Therefore, the runtime error _ErrValueRange is now only triggered if this limit is exceeded. Since variables and fields of type alpha have a maximum length of 4,096 characters, the runtime error _ErrStringOverflow now occurs when assigning a string that is too long. The same happens when a function is passed an alpha value that is too long.
Required changes to the applications
This adjustment results in the following change for applications. In all places where the runtime error _ErrValueRange is ignored or caught, _ErrStringOverflow must now be handled instead. If the string can exceed 65,520 characters, _ErrValueRange must still be handled.
Processing long strings
A string longer than 4,096 characters cannot be assigned directly to a field or variable. However, it is possible to write the string to a memory object using MemWriteStr(). Character set conversions can then be performed there using MemCnv(). The memory object can also be imported into a BLOb using BinWriteMem(). Alternatively, the string can be split into individual blocks using StrCut().
To generate a long value for the spValueAlpha property, a BLOb can also be exported to a memory object using BinReadMem(). This can then be reassigned to the property using MemReadStr(). Individual strings can also be “added” using + up to a maximum length of 65,520 characters.
Example
local
{
tAlpha : alpha(4096);
tNode : handle;
}
{
// Ignore runtime error _ErrStringOverflow
ErrIgnore(_ErrStringOverflow, true);
tAlpha # StrChar(65, 4095);
// Would result in a runtime error _ErrStringOverflow
tAlpha # tAlpha + '12';
ErrIgnore(_ErrStringOverflow, false);
try
{
// Ignore runtime error _ErrValueRange
ErrTryIgnore(_ErrValueRange);
tNode # CteOpen(_CteNode);
tNode->spValueAlpha # StrChar(65, 65519);
// Would result in a runtime error _ErrValueRanged result in a runtime error _ErrValueRange
tNode->spValueAlpha # tNode->spValueAlpha + '12';
}
tNode->CteClose();
}