'Declaration Public Overrides NotOverridable Property Size As Integer
'Usage Dim instance As TdParameter Dim value As Integer instance.Size = value value = instance.Size
public override int Size {get; set;}
'Declaration Public Overrides NotOverridable Property Size As Integer
'Usage Dim instance As TdParameter Dim value As Integer instance.Size = value value = instance.Size
public override int Size {get; set;}
The Size
property is used for binary and string types and has different meanings dependent on the data type:
Size
property refers to the number of bytes in the data. This is the case when the TdParameter.DbType property is set to DbType.AnsiString
, for example.Size
property refers to the number of characters in the string. This is the case when the DbType
property is set to DbType.String
or the TdType
property is set to TdType.VarChar
or TdType.Clob
.The Size property is ignored for XML output parameters.
When creating a parameter for a character array or a string, the application programmer must be cognizant of the Session Character Set used for logging on to the Teradata database. It is important to understand when to specify the number of bytes or the number of characters.
For example, if a column in a table is defined with the server character sets Kanjisjis or Kanji1, any parameters that refer to these columns must have the DbType
property set to DbType.AnsiString
. The value of Size
must represent the number of bytes of the string to be sent to Teradata.
The following are descriptions of additional scenarios and their expected behaviors:
SCENARIO 1
Scenario: A table that contains a column defined as VARCHAR(20) CHARACTER SET KANJISJIS
. The DbType
has been set to DbType.AnsiString
, the size of this column is defined in bytes (please refer to the "SQL Reference: Data Types and Literals" for more information). The Session Character Set has been set to UTF16. The character array has a length of 8 and contains only ASCII data.
Expected Behavior: Each character in the array will take two bytes of space after being encoded into the UTF16 Session Character Set. If the Size
property has been set to 4, then only two characters of the array will be sent to Teradata. If the Size
has been set to 20, all 8 characters will be sent.
SCENARIO 2
Scenario: A table contains a parameter declared as VARCHAR(64000) CHARACTER SET LATIN
, and the session character set has been set to UTF8. In the application, the DbType
is set to DbType.String
or DbType.AnsiString
and the character array contains ASCII characters. The Size
has been set to 32,001.
Expected Behavior: The Teradata database will return an error indicating that the column or character expression is larger than the max size. This is because the maximum size of a VarChar literal in a Unicode session character set is 32,000 characters. There are several ways to avoid this problem:
SCENARIO 3
Scenario: The Session Character Set has been set to UTF16. The DbType
has been set to DbType.AnsiString
. The Size
has been set to an odd value.
Expected Behavior: The Teradata database will return an error about a malformed character. In this scenario, the Size
must be a multiple of the minimum character length in bytes. Since the minimum character length in bytes for a UTF16 character set is 2, Size
must always be an even value.
Target Platforms: Windows 7, Windows 8, Windows 8.1, Windows 10, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2