LOGON | Teradata Vantage - LOGON - Advanced SQL Engine - Teradata Database

SQL Stored Procedures and Embedded SQL

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
xqq1557098602407.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1148
lifecycle
previous
Product Category
Teradata Vantage™

Purpose

Explicitly connects an embedded SQL application program to the Teradata Database.

Invocation

Executable.

Embedded SQL only.

Syntax

LOGON [:] logon_string
  [ AS { connection_name | :connection_name_variable } ]
logon_string
Variable containing the logon string to be used.
connection_name
Specified name of the connection.
:connection_name_variable
The host variable that contains the connection name.
The preceding colon character is mandatory.

ANSI Compliance

LOGON is a Teradata extension to the ANSI/ISO SQL:2011 standard.

Authorization

None.

Difference Between LOGON and CONNECT

The difference between LOGON and CONNECT is that LOGON allows specification of any of the possible elements of a Teradata SQL logon string, such as TDP ID and account ID, while CONNECT allows only the user ID and password to be specified.

General Rules

  • LOGON is optional.

    If it is used, LOGON must be the first SQL statement executed by the application.

    If omitted, connection to the Teradata Database is made implicitly.

  • logon_string entry identifies a host variable that contains the logon string to be used. It must obey the rules for SQL strings for the client language. Use of the colon character before the host variable is optional.
  • The application program is connected to the Teradata Database using the user ID and password, if any, contained in logon_string. If either of these is missing, an implicit connection is attempted.
  • If logon_string contains a TDP ID, it must appear first and must be separated from the rest of the logon string by a slash (/). If present, it determines the TDP used for the connection; otherwise, the installation defined default TDP is used.
  • LOGON cannot be executed as a dynamic statement.

Rules for AS (connection_name |:connection_name_variable) Clause

  • The connection_name must be unique (up to 30 bytes) and is case-sensitive.
  • If the current active connection does not have a connection name, then the next connection must not include a connection name. A runtime error is returned indicating the connection attempt has been rejected. The current active connection remains unchanged.
  • The :connection_name_variable must be a fixed or varying length character variable no longer than 30 bytes.

Examples 1-3

For all of following examples, the referenced host variables are defined as follows:

EXEC SQL BEGIN DECLARE SECTION;
char logstr[103];
VARCHAR CONNAMEV[30];
char CONNAMEF[31];
char STMTNAMF[31];
VARCHAR STMTNAMV[30];
EXEC SQL END DECLARE SECTION;

The following RDTIN fields are important for these examples:

This RDTIN field … Must …
RdtVersn be set to 10.
RdtExt be set to ‘Y’ to indicate the existence of an extension area.
RdtXTotL include the size of the RDTXCONM extension area.

Additionally, the RdtX007 (RDTXCONM) structure must be included as one of the extension areas because it communicates the connection name.

Example 1: Logging On Using a Host Variable

This example logs on using a host variable to communicate the connection name.

EXEC SQL LOGON :logstr AS SESSION1;

Lines Generated by C Preprocessor2 for Example 1

{
static struct {
       SQLInt16 LogonStrLen;
       char     LogonStr[102];
       } Sql_Stmt010;
static struct {
       SQLInt32 RdtCType;
       SQLInt16 RdtVersn;
       SQLInt16 RdtDec;
       char     RdtUserid[8];
       SQLInt32 RdtEntty;
       char     *RdtCA;
       char     *RdtDAIn;
       char     *RdtDAOut;
       char     *RdtSql;
       char     *RdtRtCon;
       SQLInt32 RdtAux1;
       SQLInt32 RdtAux2;
       char     RdtLCS;
       char     RdtComit;
       char     RdtRelse;
       char     RdtExt;
       char     RdtSepBT;
       char     RdtUCStm;
       char     RdtCmpat;
       char     RdtComp;
       SQLInt16 RdtXTotL;
       char     RdtXFill[2];
       struct {
              SQLInt16 RdtXLen;
              SQLInt16 RdtXType;
              SQLInt32 RdtXCode;
              } RdtX005;
       struct {
              SQLInt16 RdtXLen;
              SQLInt16 RdtXType;
              SQLInt16 RdtXConL;
              char     RdtXConT[30];
              } RdtX007;
       struct {
              SQLInt16 RdtXLen;
              SQLInt16 RdtXType;
              char     RdtLogMech[8];
              char     *RdtLogData;
              } RdtX010;
       } RDTIN010 =
       {110,10,0,{' '},0,0,0,0,0,0,0,0,'N','B','N','Y','N','N',' ','C',
       64,{' '},{8,5,255},{36,7,8,'S','E','S','S','I','O','N','1'},{16,
       10,{' '},0}};
Sql_Stmt010.LogonStrLen = strlen(logstr);
memcpy(Sql_Stmt010.LogonStr,logstr,strlen(logstr));
RDTIN010.RdtSql = (char *)(&Sql_Stmt010);
RDTIN010.RdtCA = (char *)(&sqlca);
RDTIN010.RdtRtCon = SQL_RDTRTCON;
TDARDI(&RDTIN010);
SQL_RDTRTCON = RDTIN010.RdtRtCon;
  }

Example 2

Similar to Example 1, this example logs on using a host variable to communicate the connection name.

EXEC SQL LOGON :logstr AS :CONNAMEV;

Lines Generated by C Preprocessor2 for Example 2

{
static struct {
       SQLInt16 LogonStrLen;
       char     LogonStr[102];
       } Sql_Stmt011;
static struct {
       SQLInt32 RdtCType;
       SQLInt16 RdtVersn;
       SQLInt16 RdtDec;
       char     RdtUserid[8];
       SQLInt32 RdtEntty;
       char     *RdtCA;
       char     *RdtDAIn;
       char     *RdtDAOut;
       char     *RdtSql;
       char     *RdtRtCon;
       SQLInt32 RdtAux1;
       SQLInt32 RdtAux2;
       char     RdtLCS;
       char     RdtComit;
       char     RdtRelse;
       char     RdtExt;
       char     RdtSepBT;
       char     RdtUCStm;
       char     RdtCmpat;
       char     RdtComp;
       SQLInt16 RdtXTotL;
       char     RdtXFill[2];
       struct {
              SQLInt16 RdtXLen;
              SQLInt16 RdtXType;
              SQLInt32 RdtXCode;
              } RdtX005;
       struct {
              SQLInt16 RdtXLen;
              SQLInt16 RdtXType;
              SQLInt16 RdtXConL;
              char     RdtXConT[30];
              } RdtX007;
       struct {
              SQLInt16 RdtXLen;
              SQLInt16 RdtXType;
              char     RdtLogMech[8];
              char     *RdtLogData;
              } RdtX010;
       } RDTIN011 =
       {110,10,0,{' '},0,0,0,0,0,0,0,0,'N','B','N','Y','N','N',' ','C',
       64,{' '},{8,5,255},{36,7,},{16,10,{' '},0}};
Sql_Stmt011.LogonStrLen = strlen(logstr);
memcpy(Sql_Stmt011.LogonStr,logstr,strlen(logstr));
RDTIN011.RdtSql = (char *)(&Sql_Stmt011);
RDTIN011.RdtX007.RdtXConL = CONNAMEV.len;
memcpy(RDTIN011.RdtX007.RdtXConT,CONNAMEV.arr,CONNAMEV.len);
RDTIN011.RdtCA = (char *)(&sqlca);
RDTIN011.RdtRtCon = SQL_RDTRTCON;
TDARDI(&RDTIN011);
SQL_RDTRTCON = RDTIN011.RdtRtCon;
  }

Example 3

The following example logs on using a fixed length character connection name passed to using a host variable.

EXEC SQL LOGON :logstr AS :CONNAMEF;

Lines Generated by C Preprocessor2 for Example 3

{
static struct {
       SQLInt16 LogonStrLen;
       char     LogonStr[102];
       } Sql_Stmt012;
static struct {
       SQLInt32 RdtCType;
       SQLInt16 RdtVersn;
       SQLInt16 RdtDec;
       char     RdtUserid[8];
       SQLInt32 RdtEntty;
       char     *RdtCA;
       char     *RdtDAIn;
       char     *RdtDAOut;
       char     *RdtSql;
       char     *RdtRtCon;
       SQLInt32 RdtAux1;
       SQLInt32 RdtAux2;
       char     RdtLCS;
       char     RdtComit;
       char     RdtRelse;
       char     RdtExt;
       char     RdtSepBT;
       char     RdtUCStm;
       char     RdtCmpat;
       char     RdtComp;
       SQLInt16 RdtXTotL;
       char     RdtXFill[2];
       struct {
              SQLInt16 RdtXLen;
              SQLInt16 RdtXType;
              SQLInt32 RdtXCode;
              } RdtX005;
       struct {
              SQLInt16 RdtXLen;
              SQLInt16 RdtXType;
              SQLInt16 RdtXConL;
              char     RdtXConT[30];
              } RdtX007;
       struct {
              SQLInt16 RdtXLen;
              SQLInt16 RdtXType;
              char     RdtLogMech[8];
              char     *RdtLogData;
              } RdtX010;
       } RDTIN012 =
       {110,10,0,{' '},0,0,0,0,0,0,0,0,'N','B','N','Y','N','N',' ','C',
       64,{' '},{8,5,255},{36,7,},{16,10,{' '},0}};
Sql_Stmt012.LogonStrLen = strlen(logstr);
memcpy(Sql_Stmt012.LogonStr,logstr,strlen(logstr));
RDTIN012.RdtSql = (char *)(&Sql_Stmt012);
RDTIN012.RdtX007.RdtXConL = strlen(CONNAMEF);
memcpy(RDTIN012.RdtX007.RdtXConT,CONNAMEF,strlen(CONNAMEF));
RDTIN012.RdtCA = (char *)(&sqlca);
RDTIN012.RdtRtCon = SQL_RDTRTCON;
TDARDI(&RDTIN012);
SQL_RDTRTCON = RDTIN012.RdtRtCon;
  }

Related Topics

For more information about:
  • An alternative way to connect to the Teradata Database from a client application program, see CONNECT
  • How Preprocessor2 can connect to the Teradata Database without using CONNECT or LOGON statements, see Teradata® Preprocessor2 for Embedded SQL Programmer Guide, B035-2446.