.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 2000-2004 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$VPC14B$
.tt 2 $$$
.TT 3 $BurkhardD$Analyze_ORACLE_Commands$1999-09-20$
***********************************************************
.nf
 
 .nf


    ========== licence begin  GPL
    Copyright (c) 2000-2004 SAP AG

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end

.fo

 
.fo
.nf
.sp
MODULE  : Analyse_ORACLE_Kommandos
=========
.sp
Purpose : Analysed ORACLE_Kommandos
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :
 
        PROCEDURE
              p14batdbname (
                    PROCEDURE next_symbol (VAR p1: tpc_globals;
                    VAR p2: tpc_partbuffer; p3: integer);
                    VAR apc : tpc_globals;
                    VAR buf : tpc_partbuffer;
                    blen : integer;
                    keyind : integer);
 
        PROCEDURE
              p14batconn (
                    PROCEDURE next_symbol (VAR p1: tpc_globals;
                    VAR p2: tpc_partbuffer; p3: integer);
                    VAR apc : tpc_globals);
 
        PROCEDURE
              p14binsdbname ( VAR apc : tpc_globals;
                    VAR dbname : tsp00_KnlIdentifier);
 
        PROCEDURE
              p14badddbname ( VAR apc : tpc_globals;
                    VAR dbname : tsp00_KnlIdentifier);
 
        PROCEDURE
              p14busingdb (
                    PROCEDURE next_symbol (VAR p1: tpc_globals;
                    VAR p2: tpc_partbuffer; p3: integer);
                    VAR apc : tpc_globals);
 
        PROCEDURE
              p14batdatabase (VAR apc : tpc_globals;
                    VAR dbname : tsp00_KnlIdentifier);
 
        PROCEDURE
              p14bsetupsession (
                    VAR apc : tpc_globals;
                    VAR err : tpc_pre_errors);
 
        PROCEDURE
              p14balter (
                    PROCEDURE next_symbol (VAR p1: tpc_globals;
                    VAR p2: tpc_partbuffer; p3: integer);
                    VAR apc : tpc_globals);
 
        PROCEDURE
              p14bcudeclare ( VAR apc : tpc_globals;
                    VAR cursorn : tsp00_KnlIdentifier);
 
        PROCEDURE
              p14bcusearch (VAR apc : tpc_globals;
                    VAR buf : tpc_partbuffer;
                    blen : integer);
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
&       ifdef TRACE
        FROM
              C-Type-Checker-Module  : VPR102;
  
        PROCEDURE
              m90print (
                    tt : tsp_trace);
 
        PROCEDURE
              m90str (
                    layer   : tsp00_ToolLayer;
                    VAR buf : tsp00_NodeId;
                    pos_anf : integer;
                    len     : integer);
 
        PROCEDURE
              m90int (layer : tsp00_ToolLayer;
                    nam : tsp00_Sname;
                    int : integer);
 
        PROCEDURE
              m90int2 (layer : tsp00_ToolLayer;
                    nam : tsp00_Sname;
                    int  : tsp00_Int2);
 
        PROCEDURE
              m90name (layer : tsp00_ToolLayer;
                    nam : tsp00_Name);
 
        PROCEDURE
              m90identifier  (
                    layer : tsp00_ToolLayer;
                    nam   : tsp00_KnlIdentifier);
 
        PROCEDURE
              m90buf (layer : tsp00_ToolLayer;
                    VAR buf : char;
                    pos_anf : integer;
                    pos_end : integer);
 
        PROCEDURE
              m90buf1 (layer : tsp00_ToolLayer;
                    VAR buf :  tpc_partbuffer;
                    pos_anf : integer;
                    pos_end : integer);
&       endif
 
      ------------------------------ 
 
        FROM
              Precompiler_ORACLE        : VPR08B;
 
        PROCEDURE
              p08bfindgaempty (VAR sqlca : sqlcatype;
                    VAR atgaindex : tsp00_Int2);
 
        PROCEDURE
              p08bfillga (VAR sqlgap : sqlgapointer;
                    index : tsp00_Int2;
                    VAR dbstring : tsp00_NodeId);
 
      ------------------------------ 
 
        FROM
              Analyse_SQLDB_Kommandos  : VPC14E;
 
        PROCEDURE
              p14btypentget (
                    PROCEDURE next_symbol (VAR p1: tpc_globals;
                    VAR p2: tpc_partbuffer; p3: integer);
                    VAR apc : tpc_globals;
                    VAR typentix : tsp00_Int2;
                    VAR vatyp    : tsp00_Int2;
                    VAR lastvatyp: tsp00_Int2;
                    resolve      : tsp00_Int2);
 
      ------------------------------ 
 
        FROM
              Analyse_SQLDB_Kommandos  : VPC14;
 
        PROCEDURE
              p14kaentryinit (VAR apc : tpc_globals);
 
      ------------------------------ 
 
        FROM
              Precompiler_Syntax_Erkennung  : VPC10;
 
        PROCEDURE
              p10getkeyword (VAR apc : tpc_globals;
                    VAR buf : tpc_partbuffer;
                    VAR index : integer);
 
        PROCEDURE
              p10stringliteralget (VAR apc : tpc_globals;
                    VAR buf : tpc_partbuffer);
 
        PROCEDURE
              p10int2unsignedget (VAR apc : tpc_globals;
                    VAR buf : tpc_partbuffer;
                    VAR int : tsp00_Int2);
 
      ------------------------------ 
 
        FROM
              Kommunikation mit Ein-Ausgabeger?ate : VPC11;
 
        PROCEDURE
              p11precomerror (VAR apc : tpc_globals;
                    error : tpc_pre_errors);
 
        PROCEDURE
              p11nerrorlisting  (VAR apc : tpc_globals;
                    VAR nam : tsp00_Lname;
                    naml  : tsp00_Int2;
                    index : tsp00_Int2);
 
      ------------------------------ 
 
        FROM
              Search-Const-Type-Var-Namen   : VPC19C;
 
        PROCEDURE
              p19sqlatallocate (VAR index : tsp00_Int2);
 
        PROCEDURE
              p19sqlcuallocate (VAR index : tsp00_Int2);
 
        PROCEDURE
              p19cparentry  (VAR apc : tpc_globals;
                    kindentry: tsp00_Int2;
                    parm2 : tsp00_Int4;
                    parm3 : tsp00_Int4;
                    parm4 : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              Runtime-Stringroutinen   : VPR05;
 
        PROCEDURE
              p05up2casebuf (VAR buf : tsp00_KnlIdentifier;
                    lwb : tsp00_Int4;
                    upb : tsp00_Int4);
 
        PROCEDURE
              p05searchword  (VAR buf : tpc_partbuffer;
                    lwb : integer;
                    upb : integer;
                    word : tsp00_Sname;
                    lw   : integer;
                    VAR pos : integer);
 
      ------------------------------ 
 
        FROM
              Kernel_move_and_fill   : VGG101;
 
        PROCEDURE
              SAPDB_PascalForcedFill (
                    size        : tsp00_Int4;
                    m           : tsp00_MoveObjPtr;
                    pos         : tsp00_Int4;
                    len         : tsp00_Int4;
                    fillchar    : char);
 
        PROCEDURE
              SAPDB_PascalForcedMove (
                    source_upb  : tsp00_Int4;
                    destin_upb  : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;
                    source_pos  : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;
                    destin_pos  : tsp00_Int4;
                    length      : tsp00_Int4);
 
        PROCEDURE
              s10mv (
                    source_upb  : tsp00_Int4;       
                    destin_upb  : tsp00_Int4;
                    source      : tsp00_MoveObjPtr;    
                    source_pos  : tsp00_Int4;
                    destin      : tsp00_MoveObjPtr;    
                    destin_pos  : tsp00_Int4;
                    length      : tsp00_Int4);
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
        PROCEDURE
              m90buf;
 
              tsp00_Buf   char
 
        PROCEDURE
              m90buf1;
 
              tsp00_Buf tpc_partbuffer
 
        PROCEDURE
              m90str;
 
              tsp00_Buf tsp00_NodeId
 
        PROCEDURE
              p10int2unsignedget;
 
              tsp00_Buf   tpc_partbuffer
 
        PROCEDURE
              p05searchword;
 
              tsp00_MoveObj  tpc_partbuffer
 
        PROCEDURE
              p05up2casebuf;
 
              tsp00_MoveObj  tsp00_KnlIdentifier
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : BurkhardD
.sp
.cp 3
Created : 1992-08-28
.sp
.cp 3
Version : 2002-06-18
.sp
.cp 3
Release :      Date : 1999-09-20
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
.sp 2
PROCEDURE  P14B_AT_DBNAME:
.sp 2
.sp 4
.sp 2
PROCEDURE P14B_AT_CONN:
.sp 2
Searches for AT <dbname> in the statement (only used if the statement is a
CONNECT). Append the <dbname> to sqlat-area (sqlatp[pcat+1].atdbname).
If no AT found, the default <dbname> will be set to bsp_name.
.sp 4
.sp 2
PROCEDURE P14B_USING_DB
.sp 2
Searches for USING <dbnode> in the statement (only used if the statement is a
CONNECT). Append the <dbnode> to sqlat-area (sqlatp[pcat+1].atdbstring) if the
<dbnode> is a string. If the <dbnode> is a :hostvar the atdbindex will be set
to the va1ix_st entry otherwise it will be set to 0.
If no USING found, the default <dbname> will be set to bsp_name.
.sp 4
.sp 2
PROCEDURE P14B_INS_DBNAME
.sp 2
Searches for the <dbname> entry in the sqlat-area and set the kaatindex if
the <dbname> allready exists. It appends the sqlat-area if the <dbname> is
not found in the list (procedure p14badddbname).
.sp 4
.sp 2
PROCEDURE P14B_ADD_DBNAME
.sp 2
Appends the sqlat-area with the <dbname> passed by the argument).
.sp 4
.sp 2
PROCEDURE P14B_AT_DATABASE
.sp 2
Generate a sqlatentry if the statment is a DECLARE DATABASE. The first sqlatentry is the default Database is it always blank.
.sp 4
.sp 2
PROCEDURE P14B_SETUP_SESSION
.sp 2
Set the actual session to the session found in sqlatp[pckaatindex].atgaindex.
If atgaindex is 0, the procedure searches for an empty gaentry and fills it.
it returns an error if no session is empty.
.sp 4
.sp 2
PROCEDURE P14B_ALTER
.sp 2
Analyses the Oracle Stament ALTER SESSION SQL_TRACE [ TRUE ] | [ FALSE ]
this is the equivalenc to the SQL-DB Statement SET TRACE [ LONG ] | [ OFF ]
.sp 4
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
 
.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:
 
.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
 
 
(*------------------------------*) 
 
PROCEDURE
      p14batconn (
            PROCEDURE next_symbol (VAR p1: tpc_globals;
            VAR p2: tpc_partbuffer; p3: integer);
            VAR apc : tpc_globals);
 
VAR
      dbname    : tsp00_KnlIdentifier;
      err       : tpc_pre_errors;
      pos, wlen : integer;
      len : integer;
      atdbindex : tsp00_Int2;
      pcnt : integer;
      ptypentix : tsp00_Int2;
      pvatyp    : tsp00_Int2;
      vix       : tsp00_Int2;
      pvalen    : tsp00_Int2;
      lastvatyp : tsp00_Int2;
      vnam   : tsp00_Lname;
      vnaml  : integer;
      upper  : tsp00_Int2;
 
BEGIN
WITH apc, pcscan, sqlca, pccmdpart,
     sqlxa, pcsqlva, pcsymtab DO
    BEGIN
    upper  := 0;
    dbname := bsp_knl_identifier;
    atdbindex := -1;
    err := cpc_pre_ok;
    pos := 0;
    wlen :=  4; (* ' at ' *)
    p05searchword (partbufp^, 1, part1len,
          ' AT         ', wlen, pos);
    IF  pos <> 0
    THEN
        BEGIN
        syposacc := pos + wlen -1;
        next_symbol (apc, partbufp^, part1len);
        IF  (symb = cpr_s_cstring_literal)
            OR ( symb = cpr_s_string_literal)
        THEN
            BEGIN
            sypos := sypos + 1;
            sylen := sylen -2;
            symb  := cpr_s_identifier;
            END;
        (*ENDIF*) 
        IF  (symb = cpr_s_identifier)
        THEN
            BEGIN
            IF  partbufp^ [sypos-1] = '"'
            THEN
                upper := 2;
            (*ENDIF*) 
            atdbindex := 0;
            IF  sylen > sizeof(tsp00_KnlIdentifier)
            THEN
                len := sizeof(tsp00_KnlIdentifier)
            ELSE
                len := sylen;
            (*ENDIF*) 
            s10mv (partsizlen, sizeof(tsp00_KnlIdentifier), @partbufp^, sypos,
                  @dbname, 1, len);
            (* ueberschreibe "at <dbname>" im buffer mit blanks *)
            SAPDB_PascalForcedFill (partsizlen, @partbufp^, pos,
                  sypos-pos+sylen+upper, bsp_c1 );
            IF  (upper = 0)
            THEN
                p05up2casebuf (dbname, 1, len);
            (*ENDIF*) 
            END
        ELSE
            IF   symb = cpr_s_parameter_name
            THEN
                BEGIN
                IF  sylen > sizeof(tsp00_KnlIdentifier)
                THEN
                    len := sizeof(tsp00_KnlIdentifier)
                ELSE
                    len := sylen;
                (*ENDIF*) 
                s10mv (partsizlen, sizeof(tsp00_KnlIdentifier),
                      @partbufp^, sypos,
                      @dbname, 1, len);
                pcnt  :=  1;
                syposacc := sypos + 1;
                ptypentix := 0;
                p14btypentget (next_symbol, apc, ptypentix,
                      pvatyp, lastvatyp, cpr_is_true);
                SAPDB_PascalForcedFill (partsizlen, @partbufp^, pos, sypos-pos,
                      bsp_c1 );
                IF   ptypentix = 0
                THEN
                    BEGIN
                    p11precomerror (apc, cpc_unknown_parametername);
                    vnam := 'SERVER_DBNAME                   ';
                    vnaml:= 20;
                    p11nerrorlisting ( apc, vnam, vnaml, pcnt);
                    END
                ELSE
                    BEGIN
                    atdbindex := pcpa + 1;
                    WITH ndtabp^ [ndcnt] DO
                        BEGIN
                        IF  ndsqlva1st <> ndsqlva1ix
                        THEN
                            BEGIN
                            p19cparentry (apc, sqlparst, ndsqlva1st,
                                  0 , ndsqlva1cnt);
                            END;
                        (*ENDIF*) 
                        p19cparentry (apc, sqlparel,
                              ndsqlva1ix, 0, 0);
                        END;
                    (*ENDWITH*) 
                    vix  := ndtabp^ [ndcnt].ndsqlva1ix;
                    IF  sqlv1p^[vix].va1indi_pt = sqlvapt
                    THEN
                        vix := sqlv1p^[vix].va1ix_pt;
                    (*ENDIF*) 
                    pvalen := sqlv2p^[sqlv1p^[vix].va1indva2_sc].va2size;
                    IF  NOT (pvatyp in [cpr_vchar..cpr_vbuf,
                        cpr_vstring,  cpr_vstring1])
                    THEN
                        p11precomerror (apc, cpc_datatyp_not_compatible)
                    ELSE
                        BEGIN
                        len := mxsp_name;
                        IF   pvatyp = cpr_vcharc
                        THEN
                            len := len + 1;
                        (*ENDIF*) 
                        IF   len < pvalen
                        THEN
                            BEGIN
                            p11precomerror (apc, cpc_variable_will_be_truncated);
                            vnam := 'DBNAME_PARAMETER                ';
                            vnaml:= 20;
                            p11nerrorlisting ( apc, vnam, vnaml, pcnt);
                            pcerror := cpc_pre_ok;
                            END;
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
                END
            ELSE
                p11precomerror (apc, cpc_invalid_sql_command);
            (*ENDIF*) 
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    p14badddbname (apc, dbname);
    sqlatp^[pckaatind].atdbnamix := atdbindex;
    END;
(*ENDWITH*) 
&ifdef TRACE
WITH  apc.sqlxa.sqlatp^[apc.pckaatind]  DO
    BEGIN
    m90int2(pc, 'pcat        ', apc.pcat);
    m90int2(pc, 'pckaatind   ', apc.pckaatind);
    m90int2(pc, 'xaatcount   ', apc. sqlxa. xaatcount);
    m90int2(pc, 'atdbindex   ', atdbindex);
    m90int2(pc, 'atgaindex   ', atgaindex);
    m90int2(pc, 'atdbnamix   ', atdbnamix );
    IF  atdbname = bsp_knl_identifier
    THEN
        m90name (pc, '** bsp_identifier*')
    ELSE
        m90identifier (pc, atdbname);
    (*ENDIF*) 
    END;
(*ENDWITH*) 
&endif
&ifdef TRACE
m90print('p14batconn   END');
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      p14batdbname (
            PROCEDURE next_symbol (VAR p1: tpc_globals;
            VAR p2: tpc_partbuffer; p3: integer);
            VAR apc : tpc_globals;
            VAR buf : tpc_partbuffer;
            blen : integer;
            keyind : integer);
 
VAR
      dbname : tsp00_KnlIdentifier;
      len : integer;
      slen : integer;
      spos : integer;
      atdbindex : tsp00_Int2;
      pcnt : integer;
      i : tsp00_Int4;
      ptypentix : tsp00_Int2;
      pvatyp    : tsp00_Int2;
      vix       : tsp00_Int2;
      pvalen    : tsp00_Int2;
      lastvatyp : tsp00_Int2;
      vnam   : tsp00_Lname;
      vnaml  : integer;
 
BEGIN
WITH apc, pcscan, sqlca, sqlca, sqlrap^, pccmdpart,
     sqlxa, pcsqlva, pcsymtab DO
    BEGIN
&   ifdef TRACE
    m90buf (pc, buf [1], 1 , blen );
    m90int2 (pc, 'blen        ', blen);
&   endif
    atdbindex := -1;
    dbname := bsp_knl_identifier;
    pcnt   := 0;
    IF  keyind = cpc_i_at
    THEN
        BEGIN
        next_symbol (apc, buf, blen);
        slen := sylen;
        spos := sypos;
        IF  (symb = cpr_s_cstring_literal)
            OR ( symb = cpr_s_string_literal)
        THEN
            BEGIN
            spos := sypos + 1;
            slen := sylen -2;
            symb  := cpr_s_identifier;
            END;
        (*ENDIF*) 
        IF  symb = cpr_s_identifier
        THEN
            BEGIN
            atdbindex := 0;
            IF  slen > sizeof(tsp00_KnlIdentifier)
            THEN
                len := sizeof(tsp00_KnlIdentifier)
            ELSE
                len := slen;
            (*ENDIF*) 
            s10mv (partsizlen, sizeof(tsp00_KnlIdentifier),
                  @buf, spos, @dbname, 1, len);
            IF  buf [spos-1] <> '"'
            THEN
                p05up2casebuf (dbname, 1, len);
            (*ENDIF*) 
            symb := cpc_cs_bufeof;
            IF  ralang <> cpr_la_cobol
            THEN
                next_symbol (apc, buf, blen);
            (*ENDIF*) 
            p14binsdbname ( apc, dbname );
            sqlatp^[pckaatind]. atdbnamix := atdbindex;
            p14bsetupsession (apc, pcerror);
&           ifdef TRACE
            m90int2(pc, 'raactsession', raactsession );
            m90int2(pc, 'pcat        ', apc.pcat);
            m90int2(pc, 'pckaatind   ', apc.pckaatind);
            m90int2(pc, 'xaatcount   ', apc. sqlxa. xaatcount);
            m90int2(pc, 'atdbindex   ', apc. sqlxa.
                  sqlatp^[apc.pckaatind]. atdbindex);
            m90int2(pc, 'atgaindex   ', apc. sqlxa.
                  sqlatp^[apc.pckaatind]. atgaindex);
            IF  apc. sqlxa. sqlatp^[apc.pckaatind]. atdbname
                = bsp_knl_identifier
            THEN
                m90name (pc, '**   bsp_name   **')
            ELSE
                m90identifier (pc, apc. sqlxa.
                      sqlatp^[apc.pckaatind]. atdbname);
            (*ENDIF*) 
&           endif
            END
        ELSE
            IF   symb = cpr_s_parameter_name
            THEN
                BEGIN
                IF  slen > sizeof(tsp00_KnlIdentifier)
                THEN
                    len := sizeof(tsp00_KnlIdentifier)
                ELSE
                    len := slen;
                (*ENDIF*) 
                s10mv (partsizlen, sizeof(tsp00_KnlIdentifier),
                      @buf, spos, @dbname, 1, len);
                pcnt  := pcnt + 1;
                syposacc := sypos + 1;
                ptypentix := 0;
                p14btypentget (next_symbol, apc, ptypentix,
                      pvatyp, lastvatyp, cpr_is_true);
                IF   ptypentix = 0
                THEN
                    BEGIN
                    p11precomerror (apc, cpc_unknown_parametername);
                    vnam := 'SERVER_DBNAME                   ';
                    vnaml:= 20;
                    p11nerrorlisting ( apc, vnam, vnaml, pcnt);
                    END
                ELSE
                    BEGIN
                    atdbindex := pcpa + 1;
                    WITH ndtabp^ [ndcnt] DO
                        BEGIN
                        IF  ndsqlva1st <> ndsqlva1ix
                        THEN
                            BEGIN
                            p19cparentry (apc, sqlparst, ndsqlva1st,
                                  0 , ndsqlva1cnt);
                            END;
                        (*ENDIF*) 
                        p19cparentry (apc, sqlparel,
                              ndsqlva1ix, 0, 0);
                        END;
                    (*ENDWITH*) 
                    vix  := ndtabp^ [ndcnt].ndsqlva1ix;
                    IF  sqlv1p^[vix].va1indi_pt = sqlvapt
                    THEN
                        vix := sqlv1p^[vix].va1ix_pt;
                    (*ENDIF*) 
                    pvalen := sqlv2p^[sqlv1p^[vix].va1indva2_sc].va2size;
                    IF  NOT (pvatyp in [cpr_vchar..cpr_vbuf,
                        cpr_vstring,  cpr_vstring1])
                    THEN
                        p11precomerror (apc, cpc_datatyp_not_compatible)
                    ELSE
                        BEGIN
                        len := mxsp_name;
                        IF   pvatyp = cpr_vcharc
                        THEN
                            len := len + 1;
                        (*ENDIF*) 
                        IF   len < pvalen
                        THEN
                            BEGIN
                            p11precomerror (apc,
                                  cpc_variable_will_be_truncated);
                            vnam := 'DBNAME_PARAMETER                ';
                            vnaml:= 20;
                            p11nerrorlisting ( apc, vnam, vnaml, pcnt);
                            pcerror := cpc_pre_ok;
                            END;
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                    IF  (ralang = cpr_la_c)
                    THEN
                        BEGIN
                        FOR i := 1 TO sylen DO
                            buf [i] := buf [sypos + i - 1];
                        (*ENDFOR*) 
                        syposacc := sylen + 2;
                        buf [syposacc - 1] := ' ';
                        part1len := syposacc;
                        IF  (buf [sypos + i] = cpr_nullchar)
                        THEN
                            BEGIN
                            part1len := syposacc - 1;
                            buf [syposacc - 1] := cpr_nullchar;
                            END
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                    sypos := 1;
                    p14binsdbname ( apc, dbname );
                    sqlatp^[pckaatind]. atdbnamix := atdbindex;
                    p14bsetupsession (apc, pcerror);
                    END;
                (*ENDIF*) 
                END
            ELSE
                pcerror := cpc_invalid_sql_command;
            (*ENDIF*) 
        (*ENDIF*) 
        END
    ELSE
        BEGIN
        (**   apc.pckaatind := cpr_se_primary;  ***)
        p14binsdbname ( apc, dbname );
        sqlatp^[pckaatind]. atdbnamix := atdbindex;
        p14bsetupsession (apc, pcerror);
        END;
    (*ENDIF*) 
    END;
(*ENDWITH*) 
&ifdef TRACE
m90print('p14batdbname END');
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      p14bsetupsession (
            VAR apc : tpc_globals;
            VAR err : tpc_pre_errors);
 
VAR
      i : integer;
      found : boolean;
 
BEGIN
&ifdef TRACE
m90int2(pc, 'pckaatind   ',  apc.pckaatind);
&endif
IF  apc.pckaatind > 0
THEN
    WITH apc, sqlca, sqlgap^, sqlrap^, sqlxa, sqlatp^[pckaatind] DO
        BEGIN
        IF  atdbname <> bsp_knl_identifier
        THEN
            IF  atgaindex = 0
            THEN
                BEGIN
&               ifdef TRACE
                m90int2(pc, 'raactsession', raactsession );
                m90int2(pc, 'atgaindex   ',  atgaindex);
                m90identifier (pc, atdbname);
&               endif
                found := false;
                IF  pckaatind > 1
                THEN
                    BEGIN
                    i := 1;
                    REPEAT
                        IF  sqlatp^[pckaatind].atdbname = sqlatp^[i].atdbname
                        THEN
                            found := true;
                        (*ENDIF*) 
                        i := i + 1;
                    UNTIL
                        found OR (i = pckaatind);
                    (*ENDREPEAT*) 
                    END;
&               ifdef TRACE
                (*ENDIF*) 
                m90int2(pc, 'found       ',  ord(found));
                m90int2(pc, 'i           ',  i);
&               endif
                IF  found
                THEN
                    BEGIN
                    sqlatp^[pckaatind].atgaindex := sqlatp^[i-1].atgaindex;
                    raactsession := sqlatp^[pckaatind].atgaindex;
                    END;
                (*ENDIF*) 
                IF  atdbindex = 0
                THEN
                    BEGIN
                    IF  sqlatp^[pckaatind].atgaindex = 0
                    THEN
                        BEGIN
                        p08bfindgaempty (sqlca, atgaindex);
                        IF  found
                        THEN
                            sqlatp^[i-1].atgaindex := atgaindex;
                        (*ENDIF*) 
                        END;
&                   ifdef TRACE
                    (*ENDIF*) 
                    m90int2(pc, 'atgaindex   ', atgaindex);
&                   endif
                    IF  atgaindex > mxpr_sqlga
                    THEN
                        BEGIN
                        IF  pcan.ancomtyp = cpr_com_sql_conn
                        THEN
                            BEGIN
                            p11precomerror (apc, cpc_connect_no_syntax_check);
                            err := cpc_pre_ok;
                            END
                        ELSE
                            err := cpc_no_sql_statement_check;
                        (*ENDIF*) 
&                       ifdef TRACE
                        m90int(pc, 'err         ', ord(err));
&                       endif
                        END
                    ELSE
                        BEGIN
                        p08bfillga (sqlgap, atgaindex, atdbstring);
                        raactsession := atgaindex;
&                       ifdef TRACE
                        m90str (pc, atdbstring, 1, NODEID_MXSP00);
&                       endif
                        END;
                    (*ENDIF*) 
                    END
                ELSE
                    BEGIN
                    raactsession := cpr_se_primary;
                    err := cpc_pre_ok;
&                   ifdef TRACE
                    m90int(pc, 'err         ', ord(err));
&                   endif
                    END;
                (*ENDIF*) 
                END
            ELSE
                raactsession := atgaindex;
            (*ENDIF*) 
&       ifdef TRACE
        (*ENDIF*) 
        m90int2(pc, 'raactsession', raactsession);
&       endif
        END;
    (*ENDWITH*) 
&ifdef TRACE
(*ENDIF*) 
m90print('p14bsetupses END');
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      p14bcusearch (VAR apc : tpc_globals;
            VAR buf : tpc_partbuffer;
            blen : integer);
 
VAR
      cursorn : tsp00_KnlIdentifier;
      slen : integer;
      spos : integer;
      len : integer;
      ind : integer;
      not_found : boolean;
 
BEGIN
WITH apc, pcscan, sqlca, sqlrap^, pccmdpart  DO
    IF  (rakamode = cpr_kind_oracle)
        OR  (rakamode = cpr_kind_sapr3)
    THEN
        BEGIN
&       ifdef TRACE
        m90buf (pc, buf [1], 1 , blen );
        m90int2 (pc, 'blen        ', blen);
&       endif
        cursorn := bsp_knl_identifier;
        slen := sylen;
        spos := sypos;
        IF  (symb = cpr_s_cstring_literal)
            OR ( symb = cpr_s_string_literal)
        THEN
            BEGIN
            spos := sypos + 1;
            slen := sylen -2;
            symb  := cpr_s_identifier;
            END;
        (*ENDIF*) 
        IF  (symb = cpr_s_identifier )
            OR  (symb = cpr_s_unknown)  (*kanji*)
        THEN
            BEGIN
            IF  slen > sizeof(tsp00_KnlIdentifier)
            THEN
                len := sizeof(tsp00_KnlIdentifier)
            ELSE
                len := slen;
            (*ENDIF*) 
            s10mv (partsizlen, sizeof(cursorn), @buf, spos, @cursorn, 1, len);
            IF  buf [spos-1] <> '"'
            THEN
                p05up2casebuf (cursorn, 1, mxsp_name);
            (*        symb := cpc_cs_bufeof;*)
&           ifdef TRACE
            (*ENDIF*) 
            m90identifier (pc, cursorn);
&           endif
            WITH sqlxa DO
                BEGIN
                not_found := true;
                ind := pccu;
&               ifdef TRACE
                m90int (pc, 'pccu        ', pccu);
&               endif
                WHILE (ind > 0) AND not_found DO
                    BEGIN
                    IF  sqlcup^[ind]. cuname = cursorn
                    THEN
                        not_found := false;
                    (*ENDIF*) 
                    ind := ind - 1;
                    END;
                (*ENDWHILE*) 
                ind := ind+1;
&               ifdef TRACE
                m90int (pc, 'ind         ', ind );
                m90int (pc, 'not_found   ', ord (not_found) );
&               endif
                END;
            (*ENDWITH*) 
            IF  not_found
            THEN
                p11precomerror (apc, cpc_unknown_cursorname)
            ELSE
                BEGIN
                IF  ind > 0
                THEN
                    BEGIN
                    pckacuind := ind;
                    pckaatind := sqlxa. sqlcup^[ind]. cuatindex;
                    END;
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        END;
&   ifdef TRACE
    (*ENDIF*) 
(*ENDWITH*) 
m90int (pc, 'pckaatind   ', apc.pckaatind );
m90int (pc, 'pckacuind   ', apc.pckacuind );
m90print('p14bcusearch END');
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      p14bcudeclare ( VAR apc : tpc_globals;
            VAR cursorn : tsp00_KnlIdentifier);
 
BEGIN
WITH apc DO
    BEGIN
    p19sqlcuallocate (pccu);
    WITH sqlxa, sqlkap^[pcka], sqlcup^[pccu] DO
        BEGIN
        kacuindex := pccu;
        cuatindex := kaatindex;
        cuname := cursorn;
        cuerrd3 := 0;
        custate := cpr_is_false;
        cukind := 0;
        END;
    (*ENDWITH*) 
    END;
(*ENDWITH*) 
&ifdef TRACE
m90int2(pc, 'pccu        ', apc.pccu);
m90int2(pc, 'cuatindex   ', apc.sqlxa.sqlcup^[apc.pccu].cuatindex);
m90identifier (pc, apc.sqlxa.sqlcup^[apc.pccu].cuname);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      p14binsdbname ( VAR apc : tpc_globals;
            VAR dbname : tsp00_KnlIdentifier);
 
VAR
      not_found : boolean;
      ind : integer;
 
BEGIN
&ifdef TRACE
m90int2(pc, 'pckaatind   ', apc.pckaatind);
m90int2(pc, 'pcat        ', apc.pcat);
&endif
WITH apc, sqlca, sqlxa DO
    BEGIN
    not_found := true;
    ind := pcat;
    IF  (dbname[1] <> ':')
    THEN
        WHILE (ind > 0) AND not_found DO
            BEGIN
            IF  sqlatp^ [ind]. atdbname = dbname
            THEN
                not_found := false;
            (*ENDIF*) 
            ind := ind - 1;
            END;
        (*ENDWHILE*) 
&   ifdef TRACE
    (*ENDIF*) 
    m90int2(pc, 'ind         ', ind);
    m90int2(pc, 'not_found   ', ord(not_found));
&   endif
    IF  not_found
    THEN
        p14badddbname (apc, dbname)
    ELSE
        BEGIN
        pckaatind := ind + 1;
        END
    (*ENDIF*) 
    END;
(*ENDWITH*) 
&ifdef TRACE
m90print('p14binsdbnam END');
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      p14badddbname ( VAR apc : tpc_globals;
            VAR dbname : tsp00_KnlIdentifier);
 
VAR
      err   : tpc_pre_errors;
 
BEGIN
err := cpc_pre_ok;
WITH apc, sqlca, sqlxa DO
    BEGIN
    p19sqlatallocate (pcat);
&   ifdef TRACE
    m90int2(pc, 'pckaatind   ', pckaatind);
    m90int2(pc, 'pcat        ', pcat);
&   endif
    sqlatp^[pcat] .atdbname := dbname;
    (* 0  string *)
    (* +n hostvar *)
    sqlatp^ [pcat] .atgaindex := 0;
    sqlatp^ [pcat] .atdbstring := bsp_nodeid;
    sqlatp^ [pcat] .atdbindex  := -1;
    sqlatp^ [pcat] .atdbnamix  := -1;
    pckaatind := pcat;
    xaatcount := pcat;
    IF  err <> cpc_pre_ok
    THEN
        p11precomerror (apc, err);
&   ifdef TRACE
    (*ENDIF*) 
    m90int2(pc, 'pckaatind   ', pckaatind);
    m90int2(pc, 'pcat        ', pcat);
&   endif
    END;
(*ENDWITH*) 
&ifdef TRACE
m90print('p14badddbnam END');
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      p14busingdb (
            PROCEDURE next_symbol (VAR p1: tpc_globals;
            VAR p2: tpc_partbuffer; p3: integer);
            VAR apc : tpc_globals);
 
VAR
      vnam   : tsp00_Lname;
      vnaml  : integer;
      pcnt : integer;
      ptypentix : tsp00_Int2;
      pvatyp    : tsp00_Int2;
      vix       : tsp00_Int2;
      pvalen    : tsp00_Int2;
      lastvatyp : tsp00_Int2;
      err   : tpc_pre_errors;
      pos, len : integer;
      dbstring : tsp00_NodeId;
 
BEGIN
WITH apc, pcscan, sqlca, pccmdpart,
     sqlxa, pcsqlva, pcsymtab DO
    BEGIN
    err := cpc_pre_ok;
    pos := 0;
    pcnt := 0;
    len :=  7;
    p05searchword (partbufp^, 1, part1len,
          ' USING      ', len, pos);
&   ifdef TRACE
    m90int2 (pc, 'pos         ', pos);
&   endif
    IF  pos <> 0
    THEN
        BEGIN
        syposacc := pos + len -1;
        next_symbol (apc, partbufp^, part1len);
        IF   (symb = cpr_s_string_literal)
            OR  (symb = cpr_s_cstring_literal)
        THEN
            BEGIN
            p10stringliteralget (apc, partbufp^);
            IF   sylen > NODEID_MXSP00
            THEN
                len := NODEID_MXSP00
            ELSE
                len := sylen;
            (*ENDIF*) 
            dbstring := bsp_nodeid;
            s10mv (partsizlen, NODEID_MXSP00, @partbufp^,
                  sypos, @dbstring, 1, len);
            (* ueberschreibe "using dbstring" im buffer mit blanks *)
            next_symbol (apc, partbufp^, part1len);
            SAPDB_PascalForcedFill (partsizlen, @partbufp^, pos, sypos-pos+sylen,
                  bsp_c1 );
            IF  sqlatp^[pckaatind].atdbindex = -1
            THEN
                BEGIN
                sqlatp^[pckaatind].atdbstring := dbstring;
                sqlatp^[pckaatind].atdbindex := 0;
                END;
            (*ENDIF*) 
            END
        ELSE
            IF   symb = cpr_s_parameter_name
            THEN
                BEGIN
                IF   sylen > NODEID_MXSP00
                THEN
                    len := NODEID_MXSP00
                ELSE
                    len := sylen;
                (*ENDIF*) 
                dbstring := bsp_nodeid;
                s10mv (partsizlen, NODEID_MXSP00, @partbufp^,
                      sypos, @dbstring, 1, len);
                pcnt  := pcnt + 1;
                syposacc := sypos + 1;
                ptypentix := 0;
                p14btypentget (next_symbol, apc, ptypentix,
                      pvatyp, lastvatyp, cpr_is_true);
                SAPDB_PascalForcedFill (partsizlen, @partbufp^, pos, sypos-pos,
                      bsp_c1 );
                IF   ptypentix = 0
                THEN
                    BEGIN
                    p11precomerror (apc, cpc_unknown_parametername);
                    vnam := 'SERVER_NODEID_PARAM             ';
                    vnaml:= 20;
                    p11nerrorlisting ( apc, vnam, vnaml, pcnt);
                    END
                ELSE
                    BEGIN
                    sqlatp^[pckaatind].atdbindex := pcpa + 1;
                    sqlatp^[pckaatind].atdbstring := dbstring;
                    WITH ndtabp^ [ndcnt] DO
                        BEGIN
                        IF  ndsqlva1st <> ndsqlva1ix
                        THEN
                            BEGIN
                            p19cparentry (apc, sqlparst, ndsqlva1st,
                                  0 , ndsqlva1cnt);
                            END;
                        (*ENDIF*) 
                        p19cparentry (apc, sqlparel,
                              ndsqlva1ix, 0, 0);
                        END;
                    (*ENDWITH*) 
                    vix  := ndtabp^ [ndcnt].ndsqlva1ix;
                    IF  sqlv1p^[vix].va1indi_pt = sqlvapt
                    THEN
                        vix := sqlv1p^[vix].va1ix_pt;
                    (*ENDIF*) 
                    pvalen := sqlv2p^[sqlv1p^[vix].va1indva2_sc].va2size;
                    IF  NOT (pvatyp in [cpr_vchar..cpr_vbuf,
                        cpr_vstring,  cpr_vstring1])
                    THEN
                        p11precomerror (apc, cpc_datatyp_not_compatible)
                    ELSE
                        BEGIN
                        len := NODEID_MXSP00;
                        IF   pvatyp = cpr_vcharc
                        THEN
                            len := len + 1;
                        (*ENDIF*) 
                        IF   len < pvalen
                        THEN
                            BEGIN
                            p11precomerror (apc, cpc_variable_will_be_truncated);
                            vnam := 'NODEID_PARAMETER                ';
                            vnaml:= 20;
                            p11nerrorlisting ( apc, vnam, vnaml, pcnt);
                            pcerror := cpc_pre_ok;
                            END;
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
                END
            ELSE
                p11precomerror (apc, cpc_invalid_sql_command);
            (*ENDIF*) 
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    END;
(*ENDWITH*) 
&ifdef TRACE
WITH apc, pcscan, sqlxa, sqlatp^[pckaatind] DO
    BEGIN
    m90int2 (pc, 'pckaatind   ', pckaatind);
    m90int2 (pc, 'xaatcount   ', xaatcount);
    m90int2 (pc, 'atdbindex   ', atdbindex);
    m90int2 (pc, 'atdbnamix   ', atdbnamix);
    m90int2 (pc, 'atgaindex   ', atgaindex);
    IF  atdbname = bsp_knl_identifier
    THEN
        m90name (pc, '**   bsp_name   **')
    ELSE
        m90identifier (pc, atdbname);
    (*ENDIF*) 
    m90str (pc, atdbstring, 1, NODEID_MXSP00);
    END;
(*ENDWITH*) 
&endif
&ifdef TRACE
m90print('p14busingdb  END');
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      p14batdatabase (VAR apc : tpc_globals;
            VAR dbname : tsp00_KnlIdentifier);
 
BEGIN
&ifdef TRACE
&endif
WITH apc DO
    BEGIN
    p14kaentryinit (apc);
&   ifdef TRACE
    m90int2(pc, 'pcka        ', pcka);
&   endif
    WITH pcscan, sqlca, sqlxa, sqlkap^[pcka] DO
        BEGIN
        katyp     := cpr_com_empty;
        kamode    := sqldbmode;
        kaatindex := 0;
        pcatgacnt := pcatgacnt + 1;
        END;
    (*ENDWITH*) 
    END;
(*ENDWITH*) 
p14badddbname (apc, dbname);
apc.sqlxa.sqlatp^[apc.pcat].atgaindex := apc.pcatgacnt;
&ifdef TRACE
m90print('p14batdataba END');
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      p14balter (
            PROCEDURE next_symbol (VAR p1: tpc_globals;
            VAR p2: tpc_partbuffer; p3: integer);
            VAR apc : tpc_globals);
 
VAR
      keyind : integer;
      err    : tpc_pre_errors;
      trace_set : tsp00_Int2;
      retsyposacc : tsp00_Int2;
      retsymb     : tpr_symbol;
 
BEGIN
trace_set := cpr_trace_empty;
err := cpc_pre_ok;
WITH apc, pcscan, sqlca, pccmdpart DO
    IF  ((sqldbmode = cpr_kind_oracle)
        OR (sqldbmode = cpr_kind_sapr3))
        AND (pcerror = cpc_pre_ok)
    THEN
        BEGIN
        retsyposacc := syposacc;
        retsymb     := symb;
        next_symbol (apc, partbufp^, part1len);
        p10getkeyword (apc, partbufp^, keyind);
        IF   keyind = cpc_i_session
        THEN
            BEGIN
            err := cpc_invalid_sql_command;
            next_symbol (apc, partbufp^, part1len);
            p10getkeyword (apc, partbufp^, keyind);
            IF   keyind = cpc_i_set
            THEN
                BEGIN
                next_symbol (apc, partbufp^, part1len);
                p10getkeyword (apc, partbufp^, keyind);
                IF   keyind = cpc_i_sql_trace
                THEN
                    BEGIN
                    next_symbol (apc, partbufp^, part1len);
                    p10getkeyword (apc, partbufp^, keyind);
                    CASE keyind OF
                        cpc_i_true :
                            BEGIN
                            err := cpc_pre_ok;
                            trace_set := cpr_trace_long;
                            END;
                        cpc_i_false :
                            BEGIN
                            err := cpc_pre_ok;
                            trace_set := cpr_trace_off;
                            END;
                        OTHERWISE:
                            err := cpc_invalid_sql_command;
                        END;
                    (*ENDCASE*) 
                    END;
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        next_symbol (apc, partbufp^, part1len);
        WHILE  (symb <> cpr_s_eof) AND (symb <> cpr_s_bufeof) DO
            next_symbol (apc, partbufp^, part1len);
        (*ENDWHILE*) 
        IF   err <> cpc_pre_ok
        THEN
            p11precomerror (apc, err);
        (*ENDIF*) 
        IF  trace_set = cpr_trace_empty
        THEN
            BEGIN
            syposacc := retsyposacc;
            symb     := retsymb;
            END;
        (*ENDIF*) 
        END;
    (*ENDIF*) 
(*ENDWITH*) 
apc.sqlca.sqloap^.oamodsettrty := trace_set;
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
*-PRETTY-*  statements    :        403
*-PRETTY-*  lines of code :       1034        PRETTYX 3.10 
*-PRETTY-*  lines in file :       1494         1997-12-10 
.PA 
