Extended Object Names in the .NET Data Provider

Blog
The best minds from Teradata, our partners, and customers blog about whatever takes their fancy.
Teradata Employee

In Teradata Database Release 14.10 object names have been lengthened from 30 bytes of a Latin or KANJISJIS character set to 128 Unicode characters. This capability supports a richer set of characters to compose object names. While using a session character set that may contain limitations due to the supported set of characters, Unicode delimited identifiers are supported in all SQL text statements. Please see the SQL Data Types and Literals manual for information on Unicode delimited identifiers.

The choice of the session character set imposes restrictions on the support of object names. The .NET Data Provider Release 14.10 has incorporated two changes to work around those limitations and still contains some restrictions based upon the session character set and the Teradata metadata support of Unicode delimited identifiers :

  • Executing Commands in a Unicode Session
  • Generating and Supporting Unicode Delimited Identifiers
  • Restrictions in the Data Provider
  1. Executing Commands in a Unicode Session 

    • Connecting to Teradata

      The connection process now is executed in a Unicode session character set, enabling connection to any user or database supported by the Teradata Database. The .NET Data provider supports logon information as Unicode strings. During the connection process, the Data Provider submits the TdConnection.ChangeDatabase command also in a Unicode session, when the Database logon property is supplied.

      The TdConnection.ChangeDatabase command may also be executed independently of the logon process and supports the database name as a Unicode string.

      As an example, the code below is executed in a LATIN1250 session character set, which cannot represent Unicode code points greater than U+00FF. By supplying the user name, password and database strings in Unicode, the Data Provider supports connection to the Teradata Database using an expanded set of Unicode characters.

      TdConnectionStringBuilder blr = new TdConnectionStringBuilder();
      DataSource = "teradb01";
      // The user id contains a Unicode escape sequence representing a CJK character
      blr.UserId = "User\u3029";
      blr.Password = "MyPassword";
      blr.SessionCharacterSet = "LATIN1250_1A0";
      TdConnection con = new TdConnection(blr.ToString());
      con.Open();
    • Changing an Expired Password

      Expired passwords are also supported as a Unicode string, when providing the TdConnectionStringBuilder.NewPassword property as a Unicode string. As the connection is established, and an expired password is detected, the supplied NewPassword Unicode string is used to modify the password. When a password is expired, the only command permitted to the database is a modify user command to modify the password.

  2. Generating and Supporting Unicode Delimited Identifiers

    • Stored Procedure Command Execution Generating Unicode Delimited Identifiers

      Stored Procedure execution accepts Unicode strings while using TdCommand.CommandType.StoredProcedure. The command expects the name of the stored procedure in the TdCommand.CommandText property. The Data Provider will issue the command by constructing a Unicode delimited identifier for the procedure name when the stored procedure name cannot be represented within the current session character set. See the Teradata Database manual Data Types and Literals for more information on Unicode delimited identifiers.

      The following example illustrates calling a stored procedure with a stored procedure name containing a character that is not compatible in the session character set. The session character set is ASCII.

      // The stored procedure definition contains a U+3021 Unicode character and
      // a column name with U+30A1 Unicode character
      //
      // DDL: REPLACE PROCEDURE U&"sptest#3021" UEscape'#'
      // (in col2 INTEGER, out U&"col2#30a1" UEscape'#' INTEGER)
      // begin
      //    set U&"col2#30a1"UEscape'#' = col2;
      // end;
      //
      TdConnectionStringBuilder blr = new TdConnectionStringBuilder();
      blr.DataSource = "teradb01";
      // The user id contains a Unicode escape sequence representing a CJK character
      blr.UserId = "User\u3029";
      blr.Password = "MyPassword";
      blr.SessionCharacterSet = "ASCII";
      TdConnection con = new TdConnection(blr.ToString());
      con.Open();
      TdCommand cmd = new TdCommand();
      cmd.Connection = con;
      cmd.CommandType = CommandType.StoredProcedure;
      // The stored procedure name contains a Unicode escape sequence representing a CJK character
      cmd.CommandText = "sptest\u3021";
      TdParameter param1 = new TdParameter("param1", TdType.Integer);
      param1.Direction = ParameterDirection.Input;
      param1.Value = 10;
      cmd.Parameters.Add(param1);
      TdParameter param2 = new TdParameter("param2", TdType.Integer);
      param1.Direction = ParameterDirection.Output;
      cmd.Parameters.Add(param1);
      using (TdDataReader dr = cmd.ExecuteReader())
      {
            // process the data from the output parameter
            Int32 result = (Int32)cmd.Parameters[1].Value;
      }
      con.Close();

    • Stored Procedure Execution Supporting Unicode Delimited Identifiers

      As mentioned in our Data Provider Developers Reference (TdCommand.CommandText property), if a dot (.) is included within the stored procedure name, then the user must construct the TdCommand.CommandText surrounding the text with double quotes when required or composing the object name with Unicode delimited identifiers when required. The dot character is ambiguous and is sometimes used to separate the database name and the stored procedure name. The following example illustrates calling a stored procedure with a database name and a stored procedure name. The session character set is ASCII. 

      // The stored procedure definition contains a U+3021 Unicode character and
      // a column name with U+30A1 Unicode character
      //
      // DDL: REPLACE PROECDURE U&"sptest#3021" UEscape'#'
      // (in col2 INTEGER, out U&"col2#30a1" UEscape'#' INTEGER)
      // begin
      //    set U&"col2#30a1"UEscape'#' = col2;
      // end;
      //
      TdConnectionStringBuilder blr = new TdConnectionStringBuilder();
      blr.DataSource = "teradb01";
      // The user id contains a Unicode escape sequence representing a CJK character
      blr.UserId = "User\u3029";
      blr.Password = "MyPassword";
      blr.SessionCharacterSet = "ASCII";
      TdConnection con = new TdConnection(blr.ToString());
      con.Open();
      TdCommand cmd = new TdCommand();
      cmd.Connection = con;
      cmd.CommandType = CommandType.StoredProcedure;
      // Compose the stored procedure name as a Unicode delimited identifier
      cmd.CommandText = "tdnetdp.U&\"sptest#3021\"UEscape'#';
      TdParameter param1 = new TdParameter("param1", TdType.Integer);
      param1.Direction = ParameterDirection.Input;
      param1.Value = 10;
      cmd.Parameters.Add(param1);
      TdParameter param2 = new TdParameter("param2", TdType.Integer);
      param1.Direction = ParameterDirection.Output;
      cmd.Parameters.Add(param1);
      using (TdDataReader dr = cmd.ExecuteReader())
      {
            // process the data from the output parameter
            Int32 result = (Int32)cmd.Parameters[1].Value;
      }
      con.Close();

    • TdCommand SQL Execution Supporting Unicode Delimited Identifiers

      Commands that are executed as command text have the option of representing object names that are not representable in the current session character set as Unicode delimited identifiers. Unicode delimited identifiers are fully supported in SQL text. However the metdata from Teradata will contain translation error characters when object names are not representable within the current session character set. This example selects data from a table name and column name that contain characters not representable in the ASCII session character set.

      TdConnectionStringBuilder blr = new TdConnectionStringBuilder();
      blr.DataSource = "teradb01";
      // The user id contains a Unicode escape sequence representing a CJK character
      blr.UserId = "User\u3029";
      blr.Password = "MyPassword";
      blr.SessionCharacterSet = "ASCII";
      TdConnection con = new TdConnection(blr.ToString());
      con.Open();
      // Represent the table name as a Unicode delimited identifier
      String tblName = "U&\"customers#60B1\"UEscape'#'";
      String col1 = "custid";
      // Represent the column name as a Unicode delimited identifier
      String col2 = "U&\"custname#60B3#60B4#60B5\"UEscape'#'";
                 
      String commandSelect = String.Format(CultureInfo.InvariantCulture,
            @" Select {0}, {1} from {2} ", col1, col2, tblName);

      String commandCreateTable = String.Format(CultureInfo.InvariantCulture,
            @"create set table {0} ({1} integer, {2} varchar(30))", tblName, col1, col2);

      String commandInsert =
            String.Format(CultureInfo.InvariantCulture, @"insert into {0} ( 1, 'john');", tblName) +
            String.Format(CultureInfo.InvariantCulture, @"insert into {0} ( 2, 'johnny');", tblName);

      TdCommand queryCmd = new TdCommand(commandCreateTable, con);
      queryCmd.ExecuteNonQuery();
      queryCmd.CommandText = commandInsert;
      queryCmd.ExecuteNonQuery();
      queryCmd.CommandText = commandSelect;
      using (TdDataReader dr = cmd.ExecuteReader())
      {
            // number of rows returned
            Int32 result = (Int32)dr.RecordsReturned;
      }
      con.Close();

  3. Restrictions in the Data Provider

    • TdCommandBuilder Command Execution

      Executing commands within TdCommandBuilder are recommended to use characters only representable within the current session character set or using a Unicode session character set, due to the limitation on extended object name representation within Teradata answer sets. Any characters not representable in the current session character set will be returned by the Teradata Database as translation error characters.

    • Schema Collections and Visual Studio Wizard Applications

       Visual Studio wizards and Visual Studio Server Explorer retrieve object names from Teradata by submitting requests that contain restrictions. The object name representation of these restrictions are limited by the current session character selected by the user. Any characters that are not representable in the current session character set, will be returned by the Teradata Database as translation error characters. To fully support Visual Studio application wizards and Server Explorer, it is recommended to use a Unicode session character set.