LOGOFF | Teradata Vantage - LOGOFF - 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

Disconnects an embedded SQL application program from the Teradata Database.

Invocation

Executable.

Embedded SQL only.

Syntax

LOGOFF [
  CURRENT |
  ALL |
  connection_name |
  :connection_name_variable
]
CURRENT
Logs off the current session only.
ALL
Logs off all sessions connected with the current user.
connection_name
The name of the connection.
:connection_name_variable
The host variable that contains the connection name.
The preceding colon character is mandatory.

ANSI Compliance

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

Authorization

None.

Rules

  • The LOGOFF statement is optional. If omitted, a disconnect from the Teradata Database is implicitly executed when the application program terminates.
  • LOGOFF can be used without regard to whether the connection to the Teradata Database was established by means of a CONNECT statement, a LOGON statement or an implicit connection.
  • If the application is executing in COMMIT mode, LOGOFF causes any outstanding transaction to be committed.

    If an application is running in any of the other transaction modes, LOGOFF does not cause outstanding transactions to be committed.

  • LOGOFF cannot be executed as a dynamic statement.
  • LOGOFF ALL disconnects all active connections.
  • LOGOFF CURRENT disconnects the current active connection. (This is the default when no disconnect object is specified.)
  • LOGOFF connection_name disconnects the named connection. Each connection name must be unique (up to 30 bytes) and is case-sensitive.
  • LOGOFF :namevar disconnects the named connection stored in :namevar. :namevar must be a fixed or varying length character variable no longer than 30 bytes.

Examples 1 - 4

The following RDTIN fields are important for the following LOGOFF statements that specify a disconnect object:

This RDTIN field … Must …
RdtVersn be set to 10.
RdtAux1 be set to one of the following values:
  • 0, which means to disconnect the current connection
  • 1, which means to disconnect all connections
  • 2, which means to disconnect named connection
RdtExt be set to ‘Y’, indicating the existence of an extension area, only if a named connection is specified.
RdtXTotL include the size of the RDTXCONM extension area, only if a named connection is specified.

Additionally, the RdtX007 (RDTXCONM) structure must be included as one of the extension areas because it communicates the connection name if you only specify a named connection.

Example 1

The following example disconnects using an explicit connection name:

EXEC SQL LOGOFF SESSION1;

Lines Generated by C Preprocessor2 for Example 1

{
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;
       } RDTIN006 =
       {200,10,0,{' '},0,0,0,0,0,0,2,0,'N','B','N','Y','N','N',' ','C',
       48,{' '},{8,5,255},{36,7,8,'S','E','S','S','I','O','N','1'}};
RDTIN006.RdtCA = (char *)(&sqlca);
RDTIN006.RdtRtCon = SQL_RDTRTCON;
TDARDI(&RDTIN006);
SQL_RDTRTCON = RDTIN006.RdtRtCon;
  }

Example 2

The following example disconnects using a connection name supplied by means of the VARCHAR host variable connamev:

EXEC SQL LOGOFF :CONNAMEV;

Lines Generated by C Preprocessor2 for Example 2

{
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;
       } RDTIN007 =
       {200,10,0,{' '},0,0,0,0,0,0,2,0,'N','B','N','Y','N','N',' ','C',
       48,{' '},{8,5,255},{36,7,}};
RDTIN007.RdtX007.RdtXConL = CONNAMEV.len;
memcpy(RDTIN007.RdtX007.RdtXConT,CONNAMEV.arr,CONNAMEV.len);
RDTIN007.RdtCA = (char *)(&sqlca);
RDTIN007.RdtRtCon = SQL_RDTRTCON;
TDARDI(&RDTIN007);
SQL_RDTRTCON = RDTIN007.RdtRtCon;
  }

Example 3

The following example disconnects using a connection name supplied by means of the fixed length host variable connamef:

EXEC SQL LOGOFF :CONNAMEF;

Lines Generated by C Preprocessor2 for Example 3

{
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;
       } RDTIN008 =
       {200,10,0,{' '},0,0,0,0,0,0,2,0,'N','B','N','Y','N','N',' ','C',
       48,{' '},{8,5,255},{36,7,}};
RDTIN008.RdtX007.RdtXConL = strlen(CONNAMEF);
memcpy(RDTIN008.RdtX007.RdtXConT,CONNAMEF,strlen(CONNAMEF));
RDTIN008.RdtCA = (char *)(&sqlca);
RDTIN008.RdtRtCon = SQL_RDTRTCON;
TDARDI(&RDTIN008);
SQL_RDTRTCON = RDTIN008.RdtRtCon;
  }

Example 4

The following example disconnects all connections:

EXEC SQL LOGOFF ALL;

Lines Generated by C Preprocessor2 for Example 4

{
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;
       } RDTIN009 =
       {200,10,0,{' '},0,0,0,0,0,0,1,0,'N','B','N','Y','N','N',' ','C',
       12,{' '},{8,5,255}};
RDTIN009.RdtCA = (char *)(&sqlca);
RDTIN009.RdtRtCon = SQL_RDTRTCON;
TDARDI(&RDTIN009);
SQL_RDTRTCON = RDTIN009.RdtRtCon;
  }

Example: LOGOFF CURRENT

The code generated for a LOGOFF CURRENT statement is the same as LOGOFF without specifying a disconnect object.

The RDTIN RdtAux1 field must be set to 0.