.nf
 
 
    ========== licence begin  GPL
    Copyright (C) 2000 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
*****************************************************
Copyright by SAP AG, 1999
SAP Database Technology
 
Release :      Date : 2000-11-17
*****************************************************
modname : VAK361
changed : 2000-11-17
module  : Catalog_Migration
 
Author  : ThomasA
Created : 1985-02-06
*****************************************************
 
Purpose : Catalog migrations due to catalog changes
 
Define  :
 
        PROCEDURE
              a361migrate (VAR acv : tak_all_command_glob;
                    VAR prevKnlVersion  : tsp00_Version;
                    VAR in_warm_session : boolean);
 
.CM *-END-* define --------------------------------------
***********************************************************
 
Use     :
 
        FROM
              Scanner : VAK01;
 
        VAR
              a01defaultkey         : tgg_sysinfokey;
              a01controluser        : tsp_knl_identifier;
              a01_il_b_identifier   : tsp_knl_identifier;
 
        PROCEDURE
              a01sets_identifier (
                    VAR id         : tsp_knl_identifier;
                    set_identifier : tak_oldidentifier);
 
      ------------------------------ 
 
        FROM
              AK_universal_semantic_tools : VAK06;
 
        PROCEDURE
              a06a_mblock_init (
                    VAR acv   : tak_all_command_glob;
                    mtype     : tgg_message_type;
                    m2type    : tgg_message2_type;
                    VAR tree  : tgg00_FileId);
 
        PROCEDURE
              a06determine_username (
                    VAR acv       : tak_all_command_glob;
                    VAR userid    : tgg_surrogate;
                    VAR user_name : tsp_knl_identifier);
 
        PROCEDURE
              a06extcolno (
                    VAR baserec     : tak_baserecord;
                    extcolno        : integer;
                    VAR colinfo_ptr : tak00_colinfo_ptr);
 
        PROCEDURE
              a06inc_linkage (VAR linkage : tsp_c2);
 
        PROCEDURE
              a06lsend_mess_buf (
                    VAR acv         : tak_all_command_glob;
                    VAR mbuf        : tgg_mess_block;
                    call_from_rsend : boolean;
                    VAR e           : tgg_basis_error);
 
      ------------------------------ 
 
        FROM
              AK_Identifier_Handling : VAK061;
 
        PROCEDURE
              a061assign_colname (value : tsp_c18;
                    VAR colname : tsp_knl_identifier);
 
      ------------------------------ 
 
        FROM
              AK_error_handling : VAK07;
 
        PROCEDURE
              a07_b_put_error (
                    VAR acv  : tak_all_command_glob;
                    b_err    : tgg_basis_error;
                    err_code : tsp_int4);
 
      ------------------------------ 
 
        FROM
              Systeminfo_cache   : VAK10;
 
        PROCEDURE
              a10add_sysinfo (
                    VAR acv      : tak_all_command_glob;
                    VAR syspoint : tak_sysbufferaddress;
                    VAR b_err    : tgg_basis_error);
 
        PROCEDURE
              a10_cache_delete  (
                    VAR acv     : tak_all_command_glob;
                    is_rollback : boolean);
 
        PROCEDURE
              a10del_sysinfo (
                    VAR acv     : tak_all_command_glob;
                    VAR syskey  : tgg_sysinfokey;
                    VAR b_err   : tgg_basis_error);
 
        PROCEDURE
              a10key_del  (
                    VAR acv         : tak_all_command_glob;
                    VAR  syspointer : tak_sysbufferaddress);
 
        PROCEDURE
              a10next_sysinfo (VAR acv : tak_all_command_glob;
                    VAR syskey   : tgg_sysinfokey;
                    stop_prefix  : integer;
                    dstate       : tak_directory_state;
                    reckind      : tsp_c2;
                    VAR syspoint : tak_sysbufferaddress;
                    VAR b_err    : tgg_basis_error);
 
        PROCEDURE
              a10new (
                    VAR acv  : tak_all_command_glob;
                    obj_size : tsp_int4;
                    VAR p    : tak_param_info_ptr);
 
        PROCEDURE
              a10_nil_get_sysinfo (
                    VAR acv      : tak_all_command_glob;
                    VAR syskey   : tgg_sysinfokey;
                    dstate       : tak_directory_state;
                    syslen       : tsp_int2;
                    VAR syspoint : tak_sysbufferaddress;
                    VAR b_err    : tgg_basis_error);
 
        PROCEDURE
              a10rel_sysinfo (syspointer : tak_sysbufferaddress);
 
        PROCEDURE
              a10repl_sysinfo (
                    VAR acv      : tak_all_command_glob;
                    VAR syspoint : tak_sysbufferaddress;
                    VAR b_err    : tgg_basis_error);
 
        PROCEDURE
              a10get_sysinfo (
                    VAR acv      : tak_all_command_glob;
                    VAR syskey   : tgg_sysinfokey;
                    dstate       : tak_directory_state;
                    VAR syspoint : tak_sysbufferaddress;
                    VAR b_err    : tgg_basis_error);
&       IFDEF TRACE
 
      ------------------------------ 
 
        FROM
              Test_Procedures : vta01;
 
        PROCEDURE
              t01int4 (
                    debug    : tgg00_Debug;
                    nam      : tsp00_Sname;
                    int4     : tsp00_Int4);
 
        PROCEDURE
              t01buf (
                    debug    : tgg00_Debug;
                    VAR buf  : tsp00_Buf;
                    startpos : integer;
                    endpos   : integer);
 
        PROCEDURE
              t01moveobj (
                    debug    : tgg00_Debug;
                    VAR buf  : tsp00_MoveObj;
                    startpos : tsp00_Int4;
                    endpos   : tsp00_Int4);
&       ENDIF
 
      ------------------------------ 
 
        FROM
              AK_Grant_Revoke : VAK22;
 
        FUNCTION
              a22exist_user  (
                    VAR acv       : tak_all_command_glob;
                    VAR user      : tsp_knl_identifier;
                    errorpos      : integer;
                    VAR user_info : tak_user_info) : boolean;
 
      ------------------------------ 
 
        FROM
              AK_Index : VAK24;
 
        PROCEDURE
              a24init_index_scan (
                    VAR acv            : tak_all_command_glob;
                    VAR tabid          : tgg_surrogate;
                    VAR index_scan_rec : tak_index_scan_record);
 
        PROCEDURE
              a24MigrateUnnamedIndex (
                    VAR acv  : tak_all_command_glob;
                    basePtr  : tak_sysbufferaddress;
                    opType   : tgg_stack_op_type;
                    colptr   : tak00_colinfo_ptr);
 
        FUNCTION
              a24next_named_index (
                    VAR acv            : tak_all_command_glob;
                    VAR index_scan_rec : tak_index_scan_record) : boolean;
 
        PROCEDURE
              a24finish_index_scan (
                    VAR acv            : tak_all_command_glob;
                    VAR index_scan_rec : tak_index_scan_record);
 
      ------------------------------ 
 
        FROM
              Kernel_Sink: VAK34;
 
        PROCEDURE
              a34AllocPacket (
                    VAR acv        : tak_all_command_glob;
                    VAR packet_ptr : tsp1_packet_ptr;
                    VAR size       : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              AK_distributor : VAK35;
 
        PROCEDURE
              a35_asql_statement (VAR acv : tak_all_command_glob);
 
      ------------------------------ 
 
        FROM
              AK_Connect : VAK51;
 
        PROCEDURE
              a51connect (
                    VAR acv          : tak_all_command_glob;
                    VAR connect_rec  : tak_connect_rec;
                    change_curr_user : boolean;
                    utility_connect  : boolean);
 
        PROCEDURE
              a51switch_user (
                    VAR acv            : tak_all_command_glob;
                    VAR new_user_name  : tsp_knl_identifier;
                    VAR curr_user_name : tsp_knl_identifier);
 
      ------------------------------ 
 
        FROM
              DML_Help_Procedures : VAK542;
 
        PROCEDURE
              a542internal_packet (
                    VAR acv                 : tak_all_command_glob;
                    release_internal_packet : boolean;
                    required_len            : tsp_int4);
 
        PROCEDURE
              a542pop_packet (VAR acv : tak_all_command_glob);
 
      ------------------------------ 
 
        FROM
              AK_Lock_Commit_Rollback : VAK52;
 
        PROCEDURE
              a52_ex_commit_rollback (
                    VAR acv        : tak_all_command_glob;
                    m_type         : tgg_message_type;
                    n_rel          : boolean;
                    normal_release : boolean);
 
        PROCEDURE
              a52new_subtrans (
                    VAR acv           : tak_all_command_glob;
                    VAR subtrans_name : tsp_knl_identifier);
 
        PROCEDURE
              a52end_rollback_subtrans (
                    VAR acv           : tak_all_command_glob;
                    VAR subtrans_name : tsp_knl_identifier;
                    m_type : tgg_message_type);
 
      ------------------------------ 
 
        FROM
              filesysteminterface_1 : VBD01;
 
        PROCEDURE
              b01tcreate_file (
                    VAR t       : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
      ------------------------------ 
 
        FROM
              filesysteminterface_3 : VBD03;
 
        PROCEDURE
              bd03SetToNotAccessible(
                    VAR Trans   : tgg00_TransContext;
                    VAR FiledId : tgg00_FileId );
 
      ------------------------------ 
 
        FROM
              filesysteminterface_7 : VBD07;
 
        PROCEDURE
              b07cadd_record (
                    VAR t       : tgg00_TransContext;
                    VAR file_id : tgg00_FileId;
                    VAR b       : tgg00_Rec);
 
        PROCEDURE
              b07cnext_record (
                    VAR t            : tgg00_TransContext;
                    VAR curr         : tgg00_FileId;
                    VAR rk           : tgg00_Lkey;
                    VAR set_result   : tgg00_BdSetResultRecord;
                    VAR tree_pos     : tgg00_FilePos;
                    VAR b            : tsp_buf);
 
      ------------------------------ 
 
        FROM
              filesysteminterface_2 : VBD02;
 
        PROCEDURE
              b02next_record (
                    VAR t       : tgg00_TransContext;
                    VAR file_id : tgg00_FileId;
                    VAR rk      : tgg_sysinfokey;
                    inclusive   : boolean;
                    VAR b       : tgg00_Rec);
 
        PROCEDURE
              b02get_record (
                    VAR t       : tgg00_TransContext;
                    VAR file_id : tgg00_FileId;
                    VAR rk      : tgg_sysinfokey;
                    VAR b       : tgg00_Rec);
&       ifdef TRACE
 
      ------------------------------ 
 
        FROM
              error_text_handling : VBD06;
 
        VAR
              b06check_rec : boolean;
&       endif
 
      ------------------------------ 
 
        FROM
              KB_file_table_handling : VKB64;
 
        PROCEDURE
              k64rename_bd_file (
                    VAR t         : tgg00_TransContext;
                    VAR source_id : tgg00_FileId;
                    VAR target_id : tgg00_FileId);
 
      ------------------------------ 
 
        FROM
              KB_Logging : VKB560;
 
        PROCEDURE
              kb560StartSavepointAndWait (VAR Trans : tgg00_TransContext;
                    MessType2 : tgg00_MessType2);
 
      ------------------------------ 
 
        FROM
              Configuration_Parameter : VGG01;
 
        VAR
              g01glob        : tgg_kernel_globals;
              g01controluser : tgg_controluser;
              g01tabid       : tgg_tabid_globals;
              g01localsite   : tgg_serverdb_no;
              g01unicode     : boolean;
 
        PROCEDURE
              g01mblock_init (
                    VAR source_trans : tgg00_TransContext;
                    mess_type  : tgg_message_type;
                    mess2_type : tgg_message2_type;
                    VAR mblock : tgg_mess_block);
 
        PROCEDURE
              g01abort (
                    msg_no     : tsp_int4;
                    msg_label  : tsp_c8;
                    msg_text   : tsp_c24;
                    bad_value  : tsp_int4);
 
        PROCEDURE
              g01optextmsg (
                    msg_prio  : tsp3_priority;
                    msg_type  : tsp3_msg_type;
                    msg_no    : tsp_int4;
                    msg_label : tsp_c8;
                    msg_text  : tsp_c40);
 
        FUNCTION
              g01packet_size : tsp_int4;
 
        PROCEDURE
              g01stack_init (
                    VAR mblock : tgg_mess_block;
                    stack_ptr  : tgg_stack_list_ptr;
                    stack_size : tsp_int4;
                    qual_ptr   : tgg_qual_buf_ptr;
                    qual_size  : tsp_int4);
 
      ------------------------------ 
 
        FROM
              Kernel-Version : VGG11;
 
        PROCEDURE
              g11ParseVersion    (VAR vers            : tsp_version;
                    VAR majorRelease    : integer;
                    VAR minorRelease    : integer;
                    VAR correctionLevel : integer;
                    VAR buildNumber     : integer);
 
      ------------------------------ 
 
        FROM
              GG_edit_routines : VGG17;
 
        PROCEDURE
              g17int4to_line (
                    intval    : tsp00_Int4;
                    with_zero : boolean;
                    int_len   : integer;
                    ln_pos    : integer;
                    VAR ln    : tsp00_C40 (*ptocSynonym char**));
 
        PROCEDURE
              g17hexto_line (
                    c          : char;
                    VAR ln_len : integer;
                    VAR ln     : tsp00_C40 (*ptocSynonym char**));
 
      ------------------------------ 
 
        FROM
              RTE-Extension-10 : VSP10;
 
        PROCEDURE
              s10mv1 (
                    size1   : tsp_int4;          size2 : tsp_int4;
                    VAR b1  : tsp00_C20;         pos1  : tsp_int4;
                    VAR b2  : tsp_moveobj;       pos2  : tsp_int4;
                    length  : tsp_int4);
 
      ------------------------------ 
 
        FROM
              PUT-Conversions : VSP41;
 
        PROCEDURE
              s41plint (
                    VAR buf : tsp_moveobj;
                    pos     : tsp_int4;
                    len     : integer;
                    frac    : integer;
                    source  : tsp_int4;
                    VAR res : tsp_num_error);
 
      ------------------------------ 
 
        FROM
              Kernel_move_and_fill : VGG10;
 
        PROCEDURE
              g10mv8 (
                    mod_id     : tsp_c6;               mod_num  : tsp_int4;
                    source_upb : tsp_int4;             dest_upb : tsp_int4;
                    VAR source : tak_systembuffer;     src_pos  : tsp_int4;
                    VAR destin : tak_systembuffer;     dest_pos : tsp_int4;
                    length     : tsp_int4;
                    VAR e      : tgg_basis_error);
 
        PROCEDURE
              g10mv9 (
                    mod_id     : tsp_c6;               mod_num  : tsp_int4;
                    source_upb : tsp_int4;             dest_upb : tsp_int4;
                    VAR source : tak_messblock_record; src_pos  : tsp_int4;
                    VAR destin : tsp_moveobj;          dest_pos : tsp_int4;
                    length     : tsp_int4;
                    VAR e      : tgg_basis_error);
 
        PROCEDURE
              g10mv10 (
                    mod_id     : tsp_c6;           mod_num  : tsp_int4;
                    source_upb : tsp_int4;          dest_upb : tsp_int4;
                    VAR source : tsp_buf;           src_pos  : tsp_int4;
                    VAR destin : tsp_moveobj;       dest_pos : tsp_int4;
                    length     : tsp_int4;
                    VAR e      : tgg_basis_error);
 
        PROCEDURE
              g10mv11 (
                    mod_id     : tsp_c6;           mod_num  : tsp_int4;
                    source_upb : tsp_int4;          dest_upb : tsp_int4;
                    VAR source : tsp_moveobj;       src_pos  : tsp_int4;
                    VAR destin : tsp_moveobj;       dest_pos : tsp_int4;
                    length     : tsp_int4;
                    VAR e      : tgg_basis_error);
 
      ------------------------------ 
 
        FROM
              Packet_handling : VSP26;
 
        PROCEDURE
              s26init_cmd_packet (
                    packet_ptr               : tsp1_packet_ptr;
                    VAR first_segm_ptr       : tsp1_segment_ptr);
 
        PROCEDURE
              s26finish_part (
                    packet_ptr           : tsp1_packet_ptr;
                    VAR finish_part      : tsp1_part);
 
        PROCEDURE
              s26new_part_init (
                    packet_ptr             : tsp1_packet_ptr;
                    VAR segm               : tsp1_segment;
                    VAR new_part_ptr       : tsp1_part_ptr);
 
      ------------------------------ 
 
        FROM
              Version : VSP100;
 
        PROCEDURE
              sp100_GetSenderIDVersionP  (VAR SenderIDP  : tsp00_C5 );
 
.CM *-END-* use -----------------------------------------
***********************************************************
 
Synonym :
 
        PROCEDURE
              t01buf1;
 
              tsp00_Buf tak_systembuffer
 
        PROCEDURE
              b02next_record;
 
              tgg00_Lkey tgg_sysinfokey
 
        PROCEDURE
              b02get_record;
 
              tgg00_Lkey tgg_sysinfokey;
 
        PROCEDURE
              b07cnext_record;
 
              tsp00_MoveObj tsp_buf
 
        PROCEDURE
              s10mv1;
 
              tsp_moveobj tsp00_C20
 
        PROCEDURE
              g10mv8;
 
              tsp_moveobj tak_systembuffer
              tsp_moveobj tak_systembuffer
 
        PROCEDURE
              g10mv9;
 
              tsp_moveobj tak_messblock_record
 
        PROCEDURE
              g10mv10;
 
              tsp_moveobj tsp_buf
 
        PROCEDURE
              g17int4to_line;
 
              tsp00_Line tsp00_C40
 
        PROCEDURE
              g17hexto_line;
 
              tsp00_Line tsp00_C40
 
        PROCEDURE
              a10new;
 
              tak_sysbufferaddress tak_param_info_ptr
 
.CM *-END-* synonym -------------------------------------
***********************************************************
.CM -lll-
Code    :
 
 
CONST
      c_call_from_rsend         = true;
      c_is_rollback             = true;
      c_release                 = true;
      c_inclusive               = true;
      cak361_csmindex           = '\04';
 
TYPE
 
      tak361_MigrationGlob = RECORD
            prot_tree          : tgg00_FileId;
            refConstraint_tree : tgg00_FileId;
            view_tree          : tgg00_FileId;
            synonym_tree       : tgg00_FileId;
            surrogateMap_tree  : tgg00_FileId;
            cntRefConstraints  : tsp00_Int4;
            cntViews           : tsp00_Int4;
            cntSynonyms        : tsp00_Int4;
      END;
 
 
      tak361_SurrogateInfoRecord = RECORD
            CASE boolean OF
                true :
                    (r : tgg00_Rec);
                false :
                    (recOffset    : ARRAY[1..cgg_rec_key_offset] OF char;
                    oldSurrogate : tgg_surrogate;
                    newSurrogate : tgg_surrogate;
                    );
                END;
            (*ENDCASE*) 
 
      tak361_migratphase = (
            create_users,
            sysfile1,
            sysfile2,
            finished);
 
      tak361_Rec = RECORD
            CASE integer OF
                1 :
                    (align : tsp00_Addr);
                2 :
                    (syskey : tgg00_SysInfoKey);
                3 :
                    (rec : tgg00_Rec);
                END;
            (*ENDCASE*) 
 
 
 
(*------------------------------*) 
 
PROCEDURE
      a361migrate (VAR acv : tak_all_command_glob;
            VAR prevKnlVersion  : tsp00_Version;
            VAR in_warm_session : boolean);
 
CONST
      c_msg_users          = 'Migrating User Catalog Data             ';
      c_msg_cat1           = 'Migrating Catalog File 1                ';
      c_msg_cat2           = 'Migrating Catalog File 2                ';
      c_msg_ref_constraint = 'Migrating Referential Constraints       ';
 
VAR
      _migrationRequired : boolean;
      _majorRelease      : integer;
      _minorRelease      : integer;
      _correctionLevel   : integer;
      _buildNumber       : integer;
      _phase             : tak361_migratphase;
      _mtype             : tgg00_MessType;
      _rec_buf           : tak361_Rec;
      _b_err             : tgg_basis_error;
      _upb               : tsp00_Int4;
      _recFill           : tsp00_Int4;
      _pageCnt           : tsp00_Int4;
      _buf               : tak_sysbufferaddress;
      _sysk              : tgg_sysinfokey;
      _connect_rec       : tak_connect_rec;
      _catalog_tree      : tgg00_FileId;
      _msg               : tsp_c40;
      _MGlob             : tak361_MigrationGlob;
 
BEGIN
g11ParseVersion (prevKnlVersion,
      _majorRelease, _minorRelease, _correctionLevel, _buildNumber);
IF  (_majorRelease = 7) AND (_minorRelease = 2) AND (_correctionLevel < 5)
THEN
    BEGIN (* Not the last 7.2 Release *)
    g01abort (csp3_a361_no_direct_migration, csp3_n_migration,
          'NO MIGRATION 3.1 TO 7.4 ', _minorRelease)
    END;
(*ENDIF*) 
_migrationRequired :=
      (_minorRelease < 4)
      OR
      ((_minorRelease = 4) AND (_correctionLevel <= 2))
      OR
      ((_minorRelease = 4) AND (_correctionLevel  = 3) AND (_buildNumber < 4))
      OR
      (g01unicode AND  (_minorRelease = 4) AND (_correctionLevel  = 3) AND (_buildNumber < 15));
IF  _migrationRequired
THEN
    BEGIN
    IF  NOT in_warm_session
    THEN
        BEGIN
        WITH _connect_rec DO
            BEGIN
            cn_username       := a01controluser;
            cn_password       := g01controluser.ggcu_password;
            cn_timeout        := csp_maxint2;
            cn_global_state   := [ hsConsistentLock_egg00 ];
            cn_internal       := true;
            cn_tmp_cache_size := 0
            END;
        (*ENDWITH*) 
        (*  remove_locks /  k51del_transid_from_locklist (acv.a_transinf.tri_trans.trTaskId_gg00,
              acv.a_transinf.tri_trans.trIndex_gg00); *)
        a51connect( acv, _connect_rec, true, true );
        in_warm_session := ( acv.a_return_segm^.sp1r_returncode = 0 );
        END;
    (*ENDIF*) 
    a10_cache_delete (acv, NOT c_is_rollback);
    acv.a_p_arr1.pbasep := NIL;
    ak361InitMigrationGlob( acv, _MGlob);
    IF  (_minorRelease = 2) OR (_minorRelease = 3)
    THEN
        BEGIN
        _msg := 'start of catalog migration : source is  ';
        g01optextmsg (sp3p_console, sp3m_info, csp3_a361_no_direct_migration,
              csp3_n_migration, _msg);
        g01optextmsg (sp3p_console, sp3m_info, csp3_a361_no_direct_migration,
              csp3_n_migration, prevKnlVersion);
        _buf  := @_rec_buf;
        _sysk := a01defaultkey;
        _msg := c_msg_users;
        _catalog_tree    := g01tabid.sys1_cat;
        _sysk.sauthid    := cgg_zero_id;
        (* build cgg_local_site *)
        _sysk.skeylen    := 0;
        _recFill         := 0;
        _phase           := sysfile1;
        REPEAT
&           ifdef trace
            b06check_rec := false;
&           endif
            b02next_record( acv.a_transinf.tri_trans, _catalog_tree,
                  _sysk, NOT c_inclusive, _rec_buf.rec );
&           ifdef trace
            b06check_rec := true;
&           endif
            _b_err := acv.a_transinf.tri_trans.trError_gg00;
            IF  (_b_err = e_ok) OR (_b_err = e_key_not_found)
            THEN
                BEGIN
&               ifdef trace
                t01buf (ak_sem, _rec_buf.rec.recBuf_gg00, 1, _rec_buf.rec.recLen_gg00);
&               endif
                _b_err   := e_ok;
                _sysk    := _buf^.syskey;
                CASE _buf^.syskey.sentrytyp[2] OF
                    cak_cforeignkey :
                        BEGIN
                        _MGlob.cntRefConstraints  :=
                              _MGlob.cntRefConstraints + 1;
                        ak361TempStoreRecord (acv, _MGlob.refConstraint_tree,
                              _buf, _b_err)
                        END;
                    (* PTS 1117920 M.Ki. *)
                    cak_cpermmessblock :
                        ak361Messblock (acv, _catalog_tree, _sysk, _buf, _b_err);
                    cak_cprimarykey :
                        BEGIN
                        _MGlob.cntRefConstraints := _MGlob.cntRefConstraints + 1;
                        ak361TempStoreRecord (acv, _MGlob.refConstraint_tree,
                              _buf, _b_err);
                        END;
                    cak361_csmindex :
                        ak361SingleIndexRecord  (acv, _buf, _b_err);
                    cak_csysdba :
                        ak361SysdbaRecord       (acv, _sysk, _buf, _b_err);
                    cak_ctable :
                        BEGIN
                        ak361TableRecord  (acv, _MGlob, _sysk, _b_err);
                        _sysk.slinkage[1] := chr(255);
                        _sysk.slinkage[2] := chr(255)
                        END;
                    cak_ccontainer :
                        ak361ContainerRecord (acv, _sysk, _b_err);
                    OTHERWISE
                        BEGIN
                        (* nothing to do *)
                        END;
                    END;
                (*ENDCASE*) 
                END
            ELSE
                IF  _b_err = e_no_next_record
                THEN
                    BEGIN
                    _phase := succ(_phase);
                    IF  _phase = finished
                    THEN
                        BEGIN
                        _msg := c_msg_ref_constraint;
                        _upb := _MGlob.cntRefConstraints;
                        END
                    ELSE
                        BEGIN
                        _b_err   := e_ok;
                        _pageCnt := 0;
                        CASE _phase OF
                            sysfile1:
                                BEGIN
                                _msg            := c_msg_cat1;
                                _catalog_tree   := g01tabid.sys1_cat;
                                _sysk           := a01defaultkey;
                                _sysk.skeylen   := 0;
                                END;
                            sysfile2 :
                                BEGIN
                                _msg            := c_msg_cat2;
                                _catalog_tree   := g01tabid.sys2_cat;
                                _sysk           := a01defaultkey;
                                _sysk.sentrytyp := cak_esysfile2;
                                END;
                            END;
                        (*ENDCASE*) 
                        END;
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
            (*ENDIF*) 
        UNTIL
            (_b_err <> e_ok);
        (*ENDREPEAT*) 
        a10_cache_delete (acv, NOT c_is_rollback);
        IF  _b_err <> e_no_next_record
        THEN
            a07_b_put_error (acv, _b_err, 1)
        ELSE
            BEGIN
            ak361MigrateRefConstraints (acv, _MGlob, _b_err);
            IF  _b_err <> e_no_next_record
            THEN
                a07_b_put_error (acv, _b_err, 1)
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        IF  acv.a_return_segm^.sp1r_returncode = 0
        THEN
            ak361CreateProtTable( acv, _MGlob );
        (*ENDIF*) 
        IF  acv.a_return_segm^.sp1r_returncode = 0
        THEN
            ak361ReCreateViews( acv, _MGlob );
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  ((_minorRelease < 4    ) OR                        (* 7.2 + 7.3  *)
        ( _correctionLevel <= 2) OR                        (* <= 7.4.2   *)
        (( _correctionLevel = 3) AND (_buildNumber < 2)))  (* <  7.4.3.2 *)
        AND
        (acv.a_return_segm^.sp1r_returncode = 0)
    THEN
        ak361MigrateDBProcedures(acv, _minorRelease, _correctionLevel, _buildNumber);
    (* PTS 1117216 E.Z. *)
    (*ENDIF*) 
    IF  ((_minorRelease < 4    ) OR                        (* 7.2 + 7.3  *)
        ( _correctionLevel <= 2) OR                        (* <= 7.4.2   *)
        ((_correctionLevel  = 3) AND (_buildNumber < 4)))  (* <  7.4.3.4 *)
        AND
        (acv.a_return_segm^.sp1r_returncode = 0)
    THEN
        ak361InitDefCodeInUserRec (acv);
    (*ENDIF*) 
    IF  ((_minorRelease < 4    ) OR                        (* 7.2 + 7.3   *)
        ( _correctionLevel <= 2) OR                        (* <= 7.4.2    *)
        ((_correctionLevel  = 3) AND (_buildNumber < 15))) (* <  7.4.3.14 *)
        AND
        g01unicode
        AND
        (acv.a_return_segm^.sp1r_returncode = 0)
    THEN
        ak361MigrateMapcharSet (acv);
    (*ENDIF*) 
    ak361SetNewVersion (acv);
    IF  in_warm_session
    THEN
        BEGIN
        acv.a_curr_user_name := a01controluser;
        acv.a_curr_user_id   := cak_util_user_id;
        IF  acv.a_return_segm^.sp1r_returncode = 0
        THEN
            _mtype := m_commit
        ELSE
            BEGIN
            _msg := 'migration failed with error             ';
            g17int4to_line (acv.a_return_segm^.sp1r_returncode,
                  false, 5, 29, _msg);
            g01optextmsg (sp3p_console, sp3m_error, csp3_a361_no_direct_migration,
                  csp3_n_migration, _msg);
            _mtype := m_rollback;
            END;
        (*ENDIF*) 
        a52_ex_commit_rollback (acv, _mtype,
              NOT c_release, NOT c_release);
        IF  acv.a_return_segm^.sp1r_returncode = 0
        THEN
            BEGIN
            kb560StartSavepointAndWait (acv.a_transinf.tri_trans, mm_config);
            IF  acv.a_transinf.tri_trans.trError_gg00 <> e_ok
            THEN
                a07_b_put_error (acv, acv.a_transinf.tri_trans.trError_gg00, 1);
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    END;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361CreateProtTable (
            VAR acv   : tak_all_command_glob;
            VAR MGlob : tak361_MigrationGlob);
 
CONST
      cmd1  = 'DROP TABLE VIEW_MIGRATION_PROT                    ';
      cmd1v = 'CREATE TABLE VIEW_MIGRATION_PROT (ERROR_NO INTEGER';
      cmd2v = ', ERROR_POS INTEGER, STATEMENT CHAR(2000))        ';
 
TYPE
      TStatement = ARRAY[0..1] OF tsp00_C50;
 
VAR
      _pStmt          : ^TStatement;
      _b_err          : tgg_basis_error;
      _curr_user_name : tsp_knl_identifier;
      _buf            : tak_sysbufferaddress;
      _partPtr        : tsp1_part_ptr;
      _syskey         : tgg_sysinfokey;
 
BEGIN
a542internal_packet (acv, true, 2 * sizeof(TStatement));
IF  acv.a_return_segm^.sp1r_returncode = 0
THEN
    BEGIN
    _pStmt := @acv.a_cmd_part^.sp1p_buf;
    (* get sysdba user *)
    _syskey           := a01defaultkey;
    _syskey.sentrytyp := cak_esysdba;
    _syskey.ssite     := g01localsite;
    a10get_sysinfo (acv, _syskey, d_release, _buf, _b_err);
    IF  _b_err = e_ok
    THEN
        BEGIN
        _syskey.sauthid   := _buf^.ssysdba.sysauthid;
        _syskey.sentrytyp := cak_euser;
        _syskey.slinkage  := cak_init_linkage;
        a10get_sysinfo (acv, _syskey, d_release, _buf, _b_err);
        IF  _b_err = e_ok
        THEN
            g01glob.sysuser_name := _buf^.suser.username
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  _b_err <> e_ok
    THEN
        g01glob.sysuser_name := a01controluser;
    (*ENDIF*) 
    a51switch_user( acv, g01glob.sysuser_name, _curr_user_name );
    (* PTS 1117920 M.Ki. *)
    (* drop table in case it already existed *)
    _partPtr   := acv.a_cmd_part;
    _pStmt^[0] := cmd1;
    acv.a_cmd_part^.sp1p_buf_len := sizeof(_pStmt^);
    ak361StatementToUnicode ( acv );
    a35_asql_statement( acv );
    acv.a_return_segm^.sp1r_returncode := 0; (* ignore errors *)
    acv.a_cmd_part := _partPtr;
    _pStmt^[0]     := cmd1v;
    _pStmt^[1]     := cmd2v;
    acv.a_cmd_part^.sp1p_buf_len := sizeof(_pStmt^);
    ak361StatementToUnicode ( acv );
    a35_asql_statement( acv );
    a542pop_packet( acv );
    a51switch_user( acv, _curr_user_name, _curr_user_name );
    END;
(*ENDIF*) 
IF  acv.a_return_segm^.sp1r_returncode = 0
THEN
    MGlob.prot_tree := acv.a_p_arr1.pbasep^.sbase.btreeid;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361InitMigrationGlob (
            VAR acv         : tak_all_command_glob;
            VAR MGlob       : tak361_MigrationGlob);
 
BEGIN
MGlob.cntRefConstraints             := 0;
MGlob.cntViews                      := 0;
MGlob.cntSynonyms                   := 0;
MGlob.view_tree                     := acv.a_pars_curr;
MGlob.view_tree.fileTfnTemp_gg00    := ttfnTrigger_egg00;
MGlob.view_tree.fileFsNode_gg00[1]  := chr(1);
b01tcreate_file( acv.a_transinf.tri_trans, MGlob.view_tree );
IF  acv.a_transinf.tri_trans.trError_gg00 = e_ok
THEN
    BEGIN
    MGlob.refConstraint_tree := MGlob.view_tree;
    MGlob.refConstraint_tree.fileFsNode_gg00[1]  := chr(2);
    b01tcreate_file (acv.a_transinf.tri_trans, MGlob.refConstraint_tree);
    END;
(*ENDIF*) 
IF  acv.a_transinf.tri_trans.trError_gg00 = e_ok
THEN
    BEGIN
    MGlob.synonym_tree := MGlob.view_tree;
    MGlob.synonym_tree.fileFsNode_gg00[1]  := chr(3);
    b01tcreate_file (acv.a_transinf.tri_trans, MGlob.synonym_tree);
    END;
(*ENDIF*) 
IF  acv.a_transinf.tri_trans.trError_gg00 = e_ok
THEN
    BEGIN
    MGlob.surrogateMap_tree := MGlob.view_tree;
    MGlob.surrogateMap_tree.fileFsNode_gg00[1]  := chr(4);
    b01tcreate_file (acv.a_transinf.tri_trans, MGlob.surrogateMap_tree);
    END;
(*ENDIF*) 
IF  acv.a_transinf.tri_trans.trError_gg00 <> e_ok
THEN
    a07_b_put_error (acv, acv.a_transinf.tri_trans.trError_gg00, 1)
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361SetNewVersion (VAR acv : tak_all_command_glob);
 
VAR
      b_err : tgg00_BasisError;
      pBuf  : tak_sysbufferaddress;
      sysk  : tgg00_SysInfoKey;
 
BEGIN
IF  acv.a_return_segm^.sp1r_returncode = 0
THEN
    BEGIN
    sysk           := a01defaultkey;
    sysk.sentrytyp := cak_esysdba;
    a10get_sysinfo( acv, sysk, d_release, pBuf, b_err );
    IF  b_err = e_ok
    THEN
        BEGIN
        pBuf^.ssysdba.sysversion := cak_sysdba_version;
        a10repl_sysinfo( acv, pBuf, b_err );
        END;
    (*ENDIF*) 
    END;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361StatementToUnicode (VAR acv : tak_all_command_glob);
 
VAR
      ix : integer;
 
BEGIN
IF  g01unicode
THEN
    BEGIN
    FOR ix := acv.a_cmd_part^.sp1p_buf_len DOWNTO 1 DO
        BEGIN
        acv.a_cmd_part^.sp1p_buf[2*ix  ] := acv.a_cmd_part^.sp1p_buf[ix];
        acv.a_cmd_part^.sp1p_buf[2*ix-1] := chr(0);
        END;
    (*ENDFOR*) 
    acv.a_cmd_part^.sp1p_buf_len := acv.a_cmd_part^.sp1p_buf_len * 2;
    END;
(*ENDIF*) 
END;
 
(* PTS 1117216 E.Z. *)
(*------------------------------*) 
 
PROCEDURE
      ak361InitDefCodeInUserRec (VAR acv : tak_all_command_glob);
 
VAR
      b_err       : tgg_basis_error;
      sysk        : tgg00_SysInfoKey;
      sysbuf      : tak_sysbufferaddress;
      _msg        : tsp00_C40;
 
BEGIN
WITH acv DO
    BEGIN
    IF  a_return_segm^.sp1r_returncode = 0
    THEN
        BEGIN
        _msg := 'migrating to user def code              ';
        g01optextmsg (sp3p_console, sp3m_info, csp3_a361_no_direct_migration,
              csp3_n_migration, _msg);
        sysk            := a01defaultkey;
        sysk.sauthid[1] := chr(255);
        sysk.sauthid[2] := chr(255);
        sysk.sentrytyp  := cak_euser;
        REPEAT
            a10next_sysinfo (acv, sysk, 0, d_release,
                  cak_euser, sysbuf, b_err);
            IF  b_err = e_ok
            THEN
                BEGIN
                sysbuf^.suser.userchardefcode := csp_instance_code;
                a10repl_sysinfo (acv, sysbuf, b_err);
                END;
            (*ENDIF*) 
            a10key_del (acv, sysbuf);
        UNTIL
            b_err <> e_ok;
        (*ENDREPEAT*) 
        IF  b_err <> e_no_next_record
        THEN
            a07_b_put_error (acv, b_err, 1);
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361MigrateDBProcedures(VAR acv : tak_all_command_glob;
            minorRelease    : integer;
            correctionLevel : integer;
            buildNumber     : integer);
 
TYPE
 
      tak_old_param_info  =  RECORD
            param_datatype     : tsp_data_type;
            param_datafrac     : tsp00_Uint1;
            param_datalength   : tsp_int2;
            param_inoutlength  : tsp_int2;
            param_in_out       : tsp_c2;
            param_com_datatype : tsp_int2;
            param_type_id      : tsp_c2;
            param_offset       : tsp_int2;
            param_new_old      : tak_param_state;
            param_name_len     : char;
            param_name         : tsp_c256;
      END;
 
 
VAR
      b_err             : tgg00_BasisError;
      migrationRequired : boolean;
      pos               : integer;
      ix                : integer;
      jx                : integer;
      length            : integer;
      mBuf              : ^tak_methodrecord;
      pBuf              : tak_sysbufferaddress;
      sysk              : tgg00_SysInfoKey;
      oldParamInfo      : tak_old_param_info;
      pOldParamInfo     : ^tsp_moveobj;
      b                 : tak361_Rec;
      msg               : tsp00_C40;
 
BEGIN
(* 7.4.3 introduced offsets for ascii and unicode clients into parameter description *)
(* expand olf parameter descriptions if necessary                                    *)
migrationRequired := true;
IF  (minorRelease = 4)
    AND
    ((correctionLevel = 2) OR ((correctionLevel = 3) AND (buildNumber < 2)))
THEN
    BEGIN
    (* this may be a 7.4.2 or an early internal 7.4.3 release *)
    (* check if migration is necessary                        *)
    sysk           := a01defaultkey;
    sysk.sauthid   := g01glob.sysuser_id;
    sysk.sentrytyp := cak_emethodref;
    a01sets_identifier (sysk.sappl, 'FORCE_CHECKPOINT  ');
    sysk.skeylen   := sysk.skeylen + sizeof (sysk.sappl);
    a10get_sysinfo (acv, sysk,
          d_release, pBuf, b_err);
    IF  b_err = e_ok
    THEN
        BEGIN
        sysk           := a01defaultkey;
        sysk.stableid  := pBuf^.smethodref.mrf_method_id;
        sysk.sentrytyp := cak_emethod;
&       ifdef trace
        b06check_rec := false;
&       endif
        b02get_record( acv.a_transinf.tri_trans, g01tabid.sys2_cat, sysk, b.rec );
&       ifdef trace
        b06check_rec := true;
&       endif
        b_err := acv.a_transinf.tri_trans.trError_gg00;
        END;
    (*ENDIF*) 
    IF  b_err = e_ok
    THEN
        BEGIN
        pos := sizeof (tak_methodrecord) -
              sizeof (tak_param_array)        +
              sizeof (tak_old_param_info)     -
              sizeof (tsp_c256)               - 1;
        migrationRequired :=
              (b.rec.recBuf_gg00[pos] <> chr(0)) OR (b.rec.recBuf_gg00[pos+1] <> chr(0));
        END;
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  migrationRequired
THEN
    BEGIN (* scan all db procedures *)
    msg := 'migrating db-procedures to 7.4.3 layout ';
    g01optextmsg (sp3p_console, sp3m_info, csp3_a361_no_direct_migration,
          csp3_n_migration, msg);
    pOldParamInfo := @oldParamInfo;
    sysk.skeylen  := 0;
    REPEAT
&       ifdef trace
        b06check_rec := false;
&       endif
        b02next_record( acv.a_transinf.tri_trans, g01tabid.sys2_cat,
              sysk, NOT c_inclusive, b.rec );
&       ifdef trace
        b06check_rec := true;
&       endif
        b_err := acv.a_transinf.tri_trans.trError_gg00;
        IF  (b_err = e_ok) OR (b_err = e_key_not_found)
        THEN
            BEGIN
&           ifdef trace
            t01buf (ak_sem, b.rec.recBuf_gg00, 1, b.rec.recLen_gg00);
&           endif
            b_err   := e_ok;
            sysk    := b.syskey;
            IF  (sysk.sentrytyp[2] = cak_cmethod) AND (sysk.slinkage <> cak_init_linkage)
            THEN
                BEGIN
                msg := 'unexpected record found, skipped        ';
                g01optextmsg (sp3p_console, sp3m_info, csp3_a361_no_direct_migration,
                      csp3_n_migration, msg);
                msg    := bsp_c40;
                length := 0;
                FOR ix := 1 TO sysk.skeylen DO
                    BEGIN
                    g17hexto_line (sysk.sstandardkey[ix], length, msg);
                    END;
                (*ENDFOR*) 
                g01optextmsg (sp3p_console, sp3m_info, csp3_a361_no_direct_migration,
                      csp3_n_migration, msg);
                END;
            (*ENDIF*) 
            IF  (sysk.sentrytyp[2] = cak_cmethod) AND (sysk.slinkage = cak_init_linkage)
            THEN
                BEGIN
                mBuf := @b.rec;
                a10del_sysinfo (acv, sysk, b_err);
                IF  b_err = e_ok
                THEN
                    a10_nil_get_sysinfo (acv, sysk, d_fix,
                          sizeof (tak_methodrecord) - sizeof(tak_param_array) +
                          mBuf^.me_param_cnt * sizeof(mBuf^.me_param_list[1]),
                          pBuf, b_err);
                (*ENDIF*) 
                IF  b_err = e_ok
                THEN
                    BEGIN
                    FOR ix := 1 TO mBuf^.me_param_cnt DO
                        pBuf^.smethod.me_param_list[ix] := NIL;
                    (*ENDFOR*) 
                    pBuf^.smethod.me_segmentid  := mBuf^.me_segmentid;
                    pBuf^.smethod.me_param_cnt  := mBuf^.me_param_cnt;
                    pBuf^.smethod.me_type       := mBuf^.me_type;
                    pBuf^.smethod.me_debug      := mBuf^.me_debug;
                    pBuf^.smethod.me_sql        := mBuf^.me_sql;
                    pBuf^.smethod.me_cursor     := mBuf^.me_cursor;
                    pBuf^.smethod.me_dispid     := mBuf^.me_dispid;
                    pBuf^.smethod.me_coclsid    := mBuf^.me_coclsid;
                    pBuf^.smethod.me_iid        := mBuf^.me_iid;
                    pBuf^.smethod.me_package_id := mBuf^.me_package_id;
                    pos := sizeof (tak_methodrecord) - sizeof (tak_param_array) + 1;
                    ix  := 1;
                    WHILE ix <= pBuf^.smethod.me_param_cnt DO
                        BEGIN
                        IF  pos > mBuf^.me_reclen
                        THEN
                            BEGIN
                            a06inc_linkage (sysk.slinkage);
&                           ifdef trace
                            b06check_rec := false;
&                           endif
                            b02get_record( acv.a_transinf.tri_trans, g01tabid.sys2_cat, sysk, b.rec );
&                           ifdef trace
                            b06check_rec := true;
&                           endif
                            b_err := acv.a_transinf.tri_trans.trError_gg00;
                            IF  b_err = e_ok
                            THEN
                                a10del_sysinfo (acv, sysk, b_err);
                            (*ENDIF*) 
                            IF  b_err <> e_ok
                            THEN
                                b_err := acv.a_transinf.tri_trans.trError_gg00;
                            (*ENDIF*) 
                            pos   := cak_sysbufferoffset + sizeof (mBuf^.me_segmentid) + 1
                            END;
                        (*ENDIF*) 
                        IF  b_err = e_ok
                        THEN
                            BEGIN
                            length := sizeof (tak_old_param_info) - sizeof (tsp_c256) +
                                  ord (b.rec.recBuf_gg00[pos + sizeof (tak_old_param_info)  -
                                  sizeof (tsp_c256) - 1]);
&                           ifdef trace
                            t01int4 (ak_sem, 'length      ', length);
&                           endif
                            a10new (acv,
                                  length + sizeof(tak_param_info) - sizeof(tak_old_param_info),
                                  pBuf^.smethod.me_param_list[ix]);
                            IF  pBuf^.smethod.me_param_list[ix] = NIL
                            THEN
                                b_err := e_no_more_memory
                            ELSE
                                BEGIN
                                g10mv10('VAK361',   1,    
                                      sizeof( b.rec.recBuf_gg00 ), sizeof( oldParamInfo ),
                                      b.rec.recBuf_gg00, pos, pOldParamInfo^, 1,
                                      length, b_err);
                                IF  b_err = e_ok
                                THEN
                                    WITH pBuf^.smethod.me_param_list[ix]^ DO
                                        BEGIN
                                        param_datatype       := oldParamInfo.param_datatype;
                                        param_datafrac       := oldParamInfo.param_datafrac;
                                        param_datalength     := oldParamInfo.param_datalength;
                                        param_inoutlength    := oldParamInfo.param_inoutlength;
                                        param_in_out         := oldParamInfo.param_in_out;
                                        param_com_datatype   := oldParamInfo.param_com_datatype;
                                        param_type_id        := oldParamInfo.param_type_id;
                                        param_cpp_offset     := oldParamInfo.param_offset;
                                        param_ascii_offset   := oldParamInfo.param_offset;
                                        param_unicode_offset := oldParamInfo.param_offset;
                                        param_new_old        := oldParamInfo.param_new_old;
                                        param_name_len       := oldParamInfo.param_name_len;
                                        FOR jx := 1 TO ord(param_name_len) DO
                                            param_name[jx] := oldParamInfo.param_name[jx];
                                        (*ENDFOR*) 
                                        END;
                                    (*ENDWITH*) 
                                (*ENDIF*) 
                                pos := pos + length;
                                END;
                            (*ENDIF*) 
                            END;
                        (*ENDIF*) 
                        IF  b_err <> e_ok
                        THEN
                            ix := csp_maxint2 (* exit loop *)
                        ELSE
                            ix := ix + 1;
                        (*ENDIF*) 
                        END;
                    (*ENDWHILE*) 
                    END;
                (*ENDIF*) 
                IF  b_err = e_ok
                THEN
                    BEGIN
                    a10rel_sysinfo  (pBuf);
                    a10add_sysinfo (acv, pBuf, b_err);
                    END;
                (*ENDIF*) 
                sysk.slinkage[1] := chr(255);
                sysk.slinkage[2] := chr(255);
                END;
            (*ENDIF*) 
            END;
        (*ENDIF*) 
    UNTIL
        (b_err <> e_ok);
    (*ENDREPEAT*) 
    IF  b_err = e_no_next_record
    THEN
        b_err := e_ok;
    (*ENDIF*) 
    END;
(* PTS 1117216 E.Z. *)
(*ENDIF*) 
IF  b_err <> e_ok
THEN
    a07_b_put_error (acv, b_err, 1)
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361MigrateMapcharSet (
            VAR acv : tak_all_command_glob);
 
VAR
      e           : tgg00_BasisError;
      offset      : integer;
      pCharSet    : tak_sysbufferaddress;
      pNewCharSet : tak_sysbufferaddress;
      sysk        : tgg00_SysInfoKey;
      newSysk     : tgg00_SysInfoKey;
      msg         : tsp00_C40;
 
BEGIN
msg := 'migrating mapset                        ';
g01optextmsg (sp3p_console, sp3m_info, csp3_a361_no_direct_migration,
      csp3_n_migration, msg);
sysk             := a01defaultkey;
sysk.sentrytyp   := cak_emapset;
sysk.slinkage    := cak_init_linkage;
a061assign_colname (cgg_default_mapchar_set, sysk.sidentifier);
sysk.skeylen     := sizeof (sysk.stableid) +
      sizeof (sysk.sentrytyp) + sizeof (sysk.slinkage) +
      sizeof (sysk.sidentifier);
a10get_sysinfo (acv, sysk, d_release, pCharSet, e);
IF  e = e_ok
THEN
    BEGIN
    newSysk := sysk;
    a01sets_identifier (sysk.sidentifier, cgg_default_mapchar_set);
    a10_nil_get_sysinfo (acv, sysk, d_release,
          pCharSet^.b_sl, pNewCharSet, e);
    IF  e = e_ok
    THEN
        BEGIN
        offset := cgg_rec_key_offset + pCharSet^.b_kl;
        g10mv8('VAK361',   2,    
              pCharSet^.b_sl, pCharSet^.b_sl,
              pCharSet^, offset + 1,
              pNewCharSet^, offset + 1,
              pCharSet^.b_sl - offset, e);
        IF  e = e_ok
        THEN
            a10add_sysinfo (acv, pNewCharSet, e);
        (*ENDIF*) 
        IF  e = e_ok
        THEN
            a10del_sysinfo (acv, sysk, e)
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    END;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361MigrateRefConstraints (
            VAR acv         : tak_all_command_glob;
            VAR MGlob       : tak361_MigrationGlob;
            VAR e           : tgg_basis_error);
 
VAR
      indexFound     : boolean;
      updateRec      : boolean;
      set_result     : tgg_bd_set_result_record;
      tree_pos       : tgg00_FilePos;
      b              : tak361_Rec;
      pKey           : ^tgg00_Lkey;
      pos            : integer;
      ix             : integer;
      surrogate      : tgg_surrogate;
      pLink          : ^tak_linkrecord;
      index_scan_rec : tak_index_scan_record;
 
BEGIN
WITH set_result DO
    BEGIN
    bd_key_check_len := 0;
    bd_max_rec_cnt   := 1;
    bd_max_fill_len  := sizeof( b.rec.recBuf_gg00 );
    bd_next          := true;
    bd_drop_page     := false
    END;
(*ENDWITH*) 
pKey      := @b;
pKey^.len := 0;
pLink     := @b;
REPEAT
    tree_pos.tpsPno_gg00 := NIL_PAGE_NO_GG00;
    b07cnext_record (acv.a_transinf.tri_trans, MGlob.refConstraint_tree,
          pKey^, set_result, tree_pos, b.rec.recBuf_gg00);
    e := acv.a_transinf.tri_trans.trError_gg00;
    IF  (e = e_ok) OR (e = e_key_not_found)
    THEN
        BEGIN
        e         := e_ok;
        updateRec := false;
        pos       := sizeof(tak_linkrecord) - sizeof(pLink^.linkdef) + 1;
        ix        := 0;
        WHILE (pos < pLink^.lreclen) AND (e = e_ok) DO
            BEGIN
            ix  := ix + 1;
            IF  (pLink^.linkdef[ix].lindexid[1] > chr(0)) AND
                (pLink^.linkdef[ix].lcolcount = 1)        AND
                (pLink^.linkdef[ix].lprimcolseq[1] <= 255)
            THEN
                BEGIN
                IF  pLink^.lentrytype = cak_eprimarykey
                THEN
                    surrogate := pLink^.lsurrogate
                ELSE
                    surrogate := pLink^.linkdef[ix].ltableid;
                (*ENDIF*) 
                indexFound := false;
                a24init_index_scan (acv, surrogate, index_scan_rec);
                WHILE NOT indexFound AND a24next_named_index (acv, index_scan_rec) DO
                    WITH index_scan_rec.isr_buf^.smindex.indexdef[index_scan_rec.isr_index] DO
                        BEGIN
                        IF  (icount = 1) AND
                            (icolseq[1] = pLink^.linkdef[ix].lprimcolseq[1])
                        THEN
                            BEGIN
&                           ifdef trace
                            t01int4 (td_always, 'new indexid ', indexno);
&                           endif
                            pLink^.linkdef[ix].lindexid[1] := chr(indexno);
                            indexFound := true;
                            updateRec  := true;
                            END;
                        (*ENDIF*) 
                        END;
                    (*ENDWITH*) 
                (*ENDWHILE*) 
                a24finish_index_scan (acv, index_scan_rec);
                END;
            (*ENDIF*) 
            pos := pos +  sizeof(pLink^.linkdef[ix])
            END;
        (*ENDWHILE*) 
        IF  updateRec
        THEN
            ak361UpdateRecord (acv, @b, e);
        (*ENDIF*) 
        END;
    (*ENDIF*) 
UNTIL
    e <> e_ok;
(*ENDREPEAT*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361ReCreateViews (
            VAR acv        : tak_all_command_glob;
            VAR MGlob      : tak361_MigrationGlob);
 
VAR
      _e                   : tgg_basis_error;
      _m_type              : tgg_message_type;
      _retCode             : integer;
      _tabcount            : tsp00_Int2;
      _pos                 : integer;
      _move_len            : integer;
      _sql_save            : tak_internal_sql_kind;
      _set_result          : tgg_bd_set_result_record;
      _tree_pos            : tgg00_FilePos;
      _b                   : tak361_Rec;
      create_or_replace    : tsp00_C20;
      _pKey                : ^tgg00_Lkey;
      _pSyskey             : ^tgg_sysinfokey;
      _user_info           : tak_user_info;
      _oldTabId            : tgg_surrogate;
      _pView               : tak_sysbufferaddress;
      _pViewtext           : ^tak_viewtextrecord;
      _part_ptr            : tsp1_part_ptr;
      _segm_ptr            : tsp1_segment_ptr;
      _packet_ptr          : tsp1_packet_ptr;
      _cnt                 : tsp00_Int4;
      _size                : tsp00_Int4;
      _msg                 : tsp00_C40;
 
BEGIN
_msg := 'Migrating Views                         ';
_packet_ptr := acv.a_in_packet;
_size       := g01packet_size;
a34AllocPacket( acv, acv.a_in_packet, _size );
IF  acv.a_return_segm^.sp1r_returncode = 0
THEN
    BEGIN
    _sql_save := acv.a_internal_sql;
    acv.a_in_packet^.sp1_header.sp1h_varpart_size :=
          _size - sizeof( acv.a_in_packet^.sp1_header );
    s26init_cmd_packet( acv.a_in_packet, _segm_ptr );
    sp100_GetSenderIDVersionP( acv.a_in_packet^.sp1_header.sp1h_appl_version );
    _segm_ptr^.sp1s_segm_header.sp1c_parsing_again := false;
    _segm_ptr^.sp1s_segm_header.sp1c_mess_type     := sp1m_dbs;
    _segm_ptr^.sp1s_segm_header.sp1c_producer      := sp1pr_installation;
    _segm_ptr^.sp1p_buf_size                       :=
          _size - sizeof (tsp1_segment_header);
    s26new_part_init (acv.a_in_packet, _segm_ptr^, _part_ptr);
    acv.a_cmd_part            := _part_ptr;
    _part_ptr^.sp1p_part_kind := sp1pk_command;
    _part_ptr^.sp1p_buf_len   := 0;
    acv.a_cmd_segm  := @acv.a_in_packet^.sp1_segm;
    _pViewtext      := @_b;
    _pKey           := @_b;
    _pSyskey        := @_b;
    _pKey^.len      := 0;
    WITH _set_result DO
        BEGIN
        bd_key_check_len := 0;
        bd_max_rec_cnt   := 1;
        bd_max_fill_len  := sizeof( _b.rec.recBuf_gg00 );
        bd_next          := true;
        bd_drop_page     := false
        END;
    (*ENDWITH*) 
    acv.a_curr_user_id := cgg_zero_id;
    _pView             := NIL;
    _cnt               := 0;
    REPEAT
        BEGIN
        _tree_pos.tpsPno_gg00 := NIL_PAGE_NO_GG00;
        b07cnext_record( acv.a_transinf.tri_trans, MGlob.view_tree,
              _pKey^, _set_result, _tree_pos, _b.rec.recBuf_gg00 );
        _e := acv.a_transinf.tri_trans.trError_gg00;
        IF  ( _e = e_ok ) OR ( _e = e_key_not_found )
        THEN
            BEGIN
            _e := e_ok;
            IF  _pViewtext^.vtsegno = cak_init_linkage
            THEN
                BEGIN
                IF  _pView <> NIL
                THEN
                    BEGIN
                    a10rel_sysinfo( _pView );
                    a10repl_sysinfo( acv, _pView, _e );
                    _pView := NIL;
                    END;
                (*ENDIF*) 
                _oldTabId               := _pSyskey^.stableid;
                _part_ptr^.sp1p_buf_len := 0;
                IF  _pViewtext^.vtcontext >= 30
                THEN
                    acv.a_sqlmode := sqlm_oracle
                ELSE
                    IF  _pViewtext^.vtcontext >= 20
                    THEN
                        acv.a_sqlmode := sqlm_db2
                    ELSE
                        IF  _pViewtext^.vtcontext >= 10
                        THEN
                            acv.a_sqlmode := sqlm_ansi
                        ELSE
                            acv.a_sqlmode := sqlm_adabas;
                        (*ENDIF*) 
                    (*ENDIF*) 
                (*ENDIF*) 
                CASE _pViewtext^.vtcontext MOD 10 OF
                    0 :
                        acv.a_dt_format := dtf_none;
                    1 :
                        acv.a_dt_format := dtf_normal;
                    2 :
                        acv.a_dt_format := dtf_iso;
                    3 :
                        acv.a_dt_format := dtf_usa;
                    4 :
                        acv.a_dt_format := dtf_eur;
                    5 :
                        acv.a_dt_format := dtf_jis;
                    6 :
                        acv.a_dt_format := dtf_oracle_date;
                    7 :
                        (* PTS 1112472 E.Z. *)
                        acv.a_dt_format := dtf_iso;
                    8 :
                        acv.a_dt_format := dtf_ts_eur;
                    9 :
                        acv.a_dt_format := dtf_future;
                    END;
                (*ENDCASE*) 
                a06determine_username( acv,
                      _pViewtext^.vttab[ 1 ].vtttableid,
                      acv.a_curr_user_name );
                acv.a_curr_user_id := _pViewtext^.vttab[ 1 ].vtttableid;
                IF  a22exist_user( acv, acv.a_curr_user_name, 1,
                    _user_info )
                THEN
                    BEGIN
                    acv.a_current_user_kind := _user_info.ui_kind;
                    acv.a_acc_dba_id        := _user_info.ui_owner;
                    a06determine_username( acv,
                          acv.a_acc_dba_id, acv.a_acc_dbaname );
                    END;
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            _tabcount := _pViewtext^.vttabcount;
            _pos := sizeof( _pViewtext^ ) -
                  sizeof( _pViewtext^.vttbuf ) +
                  _tabcount * sizeof( _pViewtext^.vttab[1] ) + 1;
            _move_len := _pViewtext^.vtreclen - _pos + 1;
            IF  _pViewtext^.vtsegno = cak_init_linkage
            THEN
                BEGIN
                _pos      := _pos + 6;       (* remove keyword SELECT *)
                _move_len := _move_len - 6;
                create_or_replace := 'CREATE OR REPLACE   ';
                s10mv1 (sizeof(create_or_replace), _part_ptr^.sp1p_buf_size,
                      create_or_replace, 1, _part_ptr^.sp1p_buf, _part_ptr^.sp1p_buf_len + 1,
                      sizeof(create_or_replace));
                _part_ptr^.sp1p_buf_len :=
                      _part_ptr^.sp1p_buf_len + sizeof(create_or_replace);
                END;
            (*ENDIF*) 
            g10mv10('VAK361',   3,    
                  sizeof( _b.rec.recBuf_gg00 ), _part_ptr^.sp1p_buf_size,
                  _b.rec.recBuf_gg00, _pos, _part_ptr^.sp1p_buf,
                  _part_ptr^.sp1p_buf_len + 1,
                  _move_len, _e );
            _part_ptr^.sp1p_buf_len := _part_ptr^.sp1p_buf_len +
                  _move_len;
            IF  NOT  _pViewtext^.vtnextexist
            THEN
                BEGIN
                s26finish_part( acv.a_in_packet, _part_ptr^ );
                a10_cache_delete( acv, NOT c_is_rollback );
                a52new_subtrans( acv, a01_il_b_identifier );
                acv.a_internal_sql := sql_restore_schema; (* PTS 1117920 M.Ki. *)
                a35_asql_statement( acv );
                _cnt := _cnt + 1;
                _retCode := acv.a_return_segm^.sp1r_returncode;
                _pos     := acv.a_return_segm^.sp1r_errorpos;
                IF  _retCode = 0
                THEN
                    BEGIN
                    _m_type := m_end;
                    END
                ELSE
                    _m_type := m_rollback;
                (*ENDIF*) 
                acv.a_return_segm^.sp1r_returncode := 0;
                a52end_rollback_subtrans( acv, a01_il_b_identifier,
                      _m_type );
                IF  _retCode <> 0
                THEN
                    BEGIN
                    ak361WriteProt( acv, MGlob, _retCode, _pos );
                    _pSyskey^.sentrytyp[ 1 ] := chr( 255 ); (* skip all of this view *)
                    END;
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        END;
    UNTIL
        ( _e <> e_ok ) OR ( acv.a_return_segm^.sp1r_returncode <> 0 );
    (*ENDREPEAT*) 
    IF  _e <> e_no_next_record
    THEN
        a07_b_put_error (acv, _e, 1)
    ELSE
        IF  _pView <> NIL
        THEN
            BEGIN
            a10rel_sysinfo( _pView );
            a10repl_sysinfo( acv, _pView, _e );
            IF  _e <> e_ok
            THEN
                a07_b_put_error (acv, _e, 1);
            (*ENDIF*) 
            END;
        (*ENDIF*) 
    (*ENDIF*) 
    acv.a_internal_sql := _sql_save;
    END;
(*ENDIF*) 
acv.a_in_packet := _packet_ptr;
acv.a_cmd_segm  := @acv.a_in_packet^.sp1_segm;
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361SingleIndexRecord (
            VAR acv     : tak_all_command_glob;
            oldIndexRec : tak_sysbufferaddress;
            VAR e       : tgg00_BasisError);
 
BEGIN
a10del_sysinfo (acv, oldIndexRec^.syskey, e)
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361StoreCreateViewStmt (
            VAR acv         : tak_all_command_glob;
            VAR MGlob       : tak361_MigrationGlob;
            Syskey          : tgg_sysinfokey; (* must not be VAR !! *)
            VAR ownerId     : tgg_surrogate;
            VAR e           : tgg00_BasisError);
 
VAR
      next_exist   : boolean;
      b            : tak361_Rec;
      pViewText    : ^tak_viewtextrecord;
 
BEGIN
pViewText        := @b;
Syskey.sentrytyp := cak_eviewtext;
REPEAT
&   ifdef trace
    b06check_rec := false;
&   endif
    b02get_record( acv.a_transinf.tri_trans, g01tabid.sys1_cat, Syskey, b.rec );
&   ifdef trace
    b06check_rec := true;
&   endif
    e := acv.a_transinf.tri_trans.trError_gg00;
    IF  e = e_ok
    THEN
        BEGIN
        next_exist := pViewText^.vtnextexist;
        IF  Syskey.slinkage = cak_init_linkage
        THEN
            pViewText^.vttab[ 1 ]. vtttableid := ownerId;
        (*ENDIF*) 
        b07cadd_record ( acv.a_transinf.tri_trans, MGlob.view_tree, b.rec );
        e := acv.a_transinf.tri_trans.trError_gg00;
        a06inc_linkage( Syskey.slinkage );
        END;
    (*ENDIF*) 
UNTIL
    NOT next_exist OR ( e <> e_ok );
(*ENDREPEAT*) 
MGlob.cntViews := MGlob.cntViews + 1;
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361SysdbaRecord (
            VAR acv      : tak_all_command_glob;
            VAR Syskey   : tgg_sysinfokey;
            oldSysdbaRec : tak_sysbufferaddress;
            VAR e        : tgg00_BasisError);
 
VAR
      sysbuf : tak_sysbufferaddress;
 
BEGIN
a10_nil_get_sysinfo (acv, Syskey, d_release, sizeof (tak_sysdbarecord), sysbuf, e);
IF  e = e_ok
THEN
    BEGIN
    sysbuf^.ssysdba.syssegmentid := cgg_local_segment_id;
    sysbuf^.ssysdba.sysactivated := oldSysdbaRec^.ssysdba.sysactivated;
    sysbuf^.ssysdba.sysversion   := cak_sysdba_version;
    sysbuf^.ssysdba.sysauthid    := oldSysdbaRec^.ssysdba.sysauthid
    END;
(*ENDIF*) 
IF  e = e_ok
THEN
    a10repl_sysinfo (acv, sysbuf, e)
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361Messblock (
            VAR acv          : tak_all_command_glob;
            VAR catalog_tree : tgg00_FileId;
            VAR Syskey       : tgg_sysinfokey;
            oldMessblock     : tak_sysbufferaddress;
            VAR e            : tgg00_BasisError);
 
TYPE
 
      tak361_73MessBufHeader = RECORD
            mb_qual_len   : tsp00_Int4;
            mb_data_len   : tsp00_Int4;
            (* *)
            mb_src_site   : tgg00_ServerdbNo;
            mb_reply      : boolean;
            mb_replicated : tgg00_Replicated;
            mb_type       : tgg00_MessType;
            mb_type2      : tgg00_MessType2;
            mb_struct     : tgg00_MessBufStruct;
            mb_fill1      : boolean;
      END;
 
 
VAR
      messblock : tak_messblock_record;
      mess73    : ^tak361_73MessBufHeader;
      (* PTS 1117920 M.Ki. *)
 
BEGIN
IF  Syskey.skeylen = mxak_standard_sysk
THEN
    BEGIN
    mess73 := @oldMessblock^.smessblock.mbr_mess_block;
    messblock.mbr_keylen        := oldMessblock^.smessblock.mbr_keylen;
    messblock.mbr_varcol_offset := oldMessblock^.smessblock.mbr_varcol_offset;
    messblock.mbr_varcol_cnt    := oldMessblock^.smessblock.mbr_varcol_cnt;
    messblock.mbr_surrogate     := oldMessblock^.smessblock.mbr_surrogate;
    messblock.mbr_entrytype     := oldMessblock^.smessblock.mbr_entrytype;
    messblock.mbr_linkage       := oldMessblock^.smessblock.mbr_linkage;
    messblock.mbr_segment_id    := oldMessblock^.smessblock.mbr_segment_id;
    messblock.mbr_stack_len     := oldMessblock^.smessblock.mbr_stack_len;
    messblock.mbr_filler1       := cgg_zero_c2;
    messblock.mbr_mess_block.mb_qual_len   := mess73^.mb_qual_len;
    messblock.mbr_mess_block.mb_data_len   := mess73^.mb_data_len;
    messblock.mbr_mess_block.mb_strat_len  := 0;
    messblock.mbr_mess_block.mb_fill2      := 0;
    messblock.mbr_mess_block.mb_src_site   := mess73^.mb_src_site;
    messblock.mbr_mess_block.mb_replicated := mess73^.mb_replicated;
    messblock.mbr_mess_block.mb_type       := mess73^.mb_type;
    messblock.mbr_mess_block.mb_type2      := mess73^.mb_type2;
    messblock.mbr_mess_block.mb_struct     := mess73^.mb_struct;
    messblock.mbr_mess_block.mb_reply      := mess73^.mb_reply;
    messblock.mbr_mess_block.mb_fill1      := false;
    (* record grows by 2*sizeof(tsp00_Int4) *)
    messblock.mbr_reclen := oldMessblock^.smessblock.mbr_reclen
          + 2*sizeof(tsp00_Int4);
    a06a_mblock_init (acv, m_update_rec, mm_nil, catalog_tree );
    g10mv9('VAK361',   4,    
          sizeof (tak_messblock_record), acv.a_mblock.mb_data_size,
          messblock, 1,
          acv.a_mblock.mb_data^.mbp_buf, 1,
          messblock.mbr_reclen,
          e);
    acv.a_mblock.mb_data_len := messblock.mbr_reclen;
    a06lsend_mess_buf(acv, acv.a_mblock, NOT c_call_from_rsend, e);
    (* skip part records of current mess block *)
    Syskey.skeylen    := Syskey.skeylen + 1;
    Syskey.stablen[1] := chr(255);
    END;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361TableRecord (
            VAR acv           : tak_all_command_glob;
            VAR MGlob         : tak361_MigrationGlob;
            VAR Syskey        : tgg_sysinfokey;
            VAR e             : tgg00_BasisError);
 
CONST
      cak72_max_sindex_colno = 255;
 
VAR
      indexnoset             : SET OF 1..MAX_INV_PER_TAB_GG00;
      unnamedIndexedColumns  : tak_columnset;
      nullableIndexedColumns : tak_columnset; (* PTS 1118568 *)
      checkIndexes           : boolean;
      updIndexRec            : boolean;
      indexExist             : boolean;
      ix                     : integer;
      colptr                 : tak00_colinfo_ptr;
      pBase                  : tak_sysbufferaddress;
      oldIndexId             : tgg00_FileId;
      newIndexId             : tgg00_FileId;
      index_scan_rec         : tak_index_scan_record;
      pTable                 : ^tak_baserecord;
      opType                 : ARRAY[1..cak72_max_sindex_colno] OF tgg_stack_op_type;
 
BEGIN
a10get_sysinfo (acv, Syskey, d_fix, pBase, e);
IF  e = e_ok
THEN
    BEGIN
    unnamedIndexedColumns  := [];
    nullableIndexedColumns := []; (* PTS 1118568 *)
    checkIndexes           := false;
    pTable                 := @pBase^.sbase;
    indexExist             := false; (* PTS 1112699 *)
    IF  pTable^.btablekind in [twithkey, twithoutkey]
    THEN
        BEGIN
        indexExist := pTable^.bindexexist; (* PTS 1112699 *)
        FOR ix := pTable^.bfirstindex TO pTable^.blastindex DO
            BEGIN
            IF  ctunused in pTable^.bcolumn[ix]^.ccolpropset
            THEN
                BEGIN
                checkIndexes          := true;
                IF  pTable^.bcolumn[ix]^.creccolno <= cak72_max_sindex_colno
                THEN
                    BEGIN
                    unnamedIndexedColumns := unnamedIndexedColumns +
                          [pTable^.bcolumn[ix]^.creccolno];
                    IF  ctopt in pTable^.bcolumn[ix]^.ccolpropset (* PTS 1118568 *)
                    THEN
                        nullableIndexedColumns := nullableIndexedColumns +
                              [pTable^.bcolumn[ix]^.creccolno];
                    (*ENDIF*) 
                    opType[pTable^.bcolumn[ix]^.creccolno] := pTable^.bcolumn[ix]^.ccolstack.eop;
                    pTable^.bindexexist := true
                    END;
                (*ENDIF*) 
                pTable^.bcolumn[ix]^.ccolpropset :=
                      pTable^.bcolumn[ix]^.ccolpropset - [ctunused] + [ctmulti];
                IF  pTable^.bcolumn[ix]^.ccolstack.eop in  (* PTS ??? *)
                    [op_unique, op_unique_desc, op_order_desc, op_order_asc]
                THEN
                    pTable^.bcolumn[ix]^.ccolstack.eop := op_none;
                (*ENDIF*) 
                pTable^.bcolumn[ix]^.ccolstack.ecol_tab[1] := chr(0);
                END;
            (*ENDIF*) 
            END;
        (*ENDFOR*) 
        IF  checkIndexes
        THEN
            a10repl_sysinfo( acv, pBase, e)
        (*ENDIF*) 
        END
    ELSE
        BEGIN
        IF  pTable^.btablekind <> tsynonym
        THEN
            ak361StoreCreateViewStmt (acv, MGlob, Syskey, pTable^.bauthid, e);
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  checkIndexes AND pTable^.bindexexist AND (e = e_ok)
    THEN
        BEGIN
        indexnoset := [];
        IF  indexExist
        THEN
            BEGIN
            a24init_index_scan (acv, pTable^.bsurrogate, index_scan_rec);
            WHILE a24next_named_index (acv, index_scan_rec) DO
                WITH index_scan_rec.isr_buf^.smindex.indexdef[index_scan_rec.isr_index] DO
                    BEGIN
                    IF  icount > 1
                    THEN
                        BEGIN
                        indexnoset := indexnoset + [indexno];
                        END;
                    (*ENDIF*) 
                    END;
                (*ENDWITH*) 
            (*ENDWHILE*) 
            a24finish_index_scan (acv, index_scan_rec);
            a24init_index_scan (acv, pTable^.bsurrogate, index_scan_rec);
            WHILE a24next_named_index (acv, index_scan_rec) AND (e = e_ok) DO
                WITH index_scan_rec.isr_buf^.smindex.indexdef[index_scan_rec.isr_index] DO
                    BEGIN
                    IF  index_scan_rec.isr_index = 1
                    THEN
                        updIndexRec := false;
                    (*ENDIF*) 
                    IF  (icount = 1) AND (icolseq[1] <= cak72_max_sindex_colno)
                    THEN
                        BEGIN
                        unnamedIndexedColumns := unnamedIndexedColumns -
                              [icolseq[1]];
                        updIndexRec    := true;
                        indexno        := -1;
                        ix             := 1;
                        WHILE (ix < MAX_INV_PER_TAB_GG00) AND (indexno < 0) DO
                            BEGIN
                            IF  ix in indexnoset
                            THEN
                                ix := ix + 1
                            ELSE
                                indexno := ix;
                            (*ENDIF*) 
                            END;
                        (*ENDWHILE*) 
                        indexnoset := indexnoset + [indexno];
                        oldIndexId                           := pTable^.btreeid;
                        oldIndexId.fileRoot_gg00             := NIL_PAGE_NO_GG00;
                        oldIndexId.fileRootCheck_gg00        := ROOT_CHECK_GG00;
                        oldIndexId.fileVersion_gg00.ci2_gg00 := cgg_dummy_file_version;
                        oldIndexId.fileTfnNo_gg00[ 1 ]       := chr(icolseq[1]);
                        oldIndexId.fileTfn_gg00              := tfnInv_egg00;
                        newIndexId                           := oldIndexId;
                        newIndexId.fileTfnNo_gg00[ 1 ]       := chr(indexno);
                        newIndexId.fileTfn_gg00              := tfnMulti_egg00;
                        k64rename_bd_file (acv.a_transinf.tri_trans, oldIndexId, newIndexId);
                        IF  acv.a_transinf.tri_trans.trError_gg00 <> e_ok
                        THEN
                            a07_b_put_error (acv, acv.a_transinf.tri_trans.trError_gg00, 1)
                                  (* PTS 1118231 E.Z. *)
                        ELSE
                            icolstack[1].ecol_tab[1] := chr (indexno);
                        (*ENDIF*) 
                        IF  icolseq[1] in nullableIndexedColumns (* PTS 1118568 *)
                        THEN
                            BEGIN
                            bd03SetToNotAccessible(acv.a_transinf.tri_trans, newIndexId);
                            nullableIndexedColumns := nullableIndexedColumns
                                  - [icolseq[1]];
                            END
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                    IF  updIndexRec
                        AND
                        ((index_scan_rec.isr_index = cak_max_index_per_rec)
                        OR
                        ((index_scan_rec.isr_index = index_scan_rec.isr_buf^.smindex.indexcount) AND
                        ( index_scan_rec.isr_buf^.smindex.indexcount < cak_max_index_per_rec)))
                    THEN
                        BEGIN
                        a10repl_sysinfo( acv, index_scan_rec.isr_buf, e );
                        updIndexRec := false
                        END
                    (*ENDIF*) 
                    END;
                (*ENDWITH*) 
            (*ENDWHILE*) 
            a24finish_index_scan (acv, index_scan_rec);
            END;
        (*ENDIF*) 
        IF  unnamedIndexedColumns <> []
        THEN
            BEGIN
            ix := 1;
            WHILE (ix <= cak72_max_sindex_colno) AND (e = e_ok) DO
                BEGIN
                IF  ix in unnamedIndexedColumns
                THEN
                    BEGIN
                    (* drop single index *)
                    oldIndexId                           := pTable^.btreeid;
                    oldIndexId.fileRoot_gg00             := NIL_PAGE_NO_GG00;
                    oldIndexId.fileRootCheck_gg00        := ROOT_CHECK_GG00;
                    oldIndexId.fileVersion_gg00.ci2_gg00 := cgg_dummy_file_version;
                    oldIndexId.fileTfnNo_gg00[ 1 ]       := chr(ix);
                    oldIndexId.fileTfn_gg00              := tfnInv_egg00;
                    a06a_mblock_init (acv, m_drop, mm_table, oldIndexId );
                    a06lsend_mess_buf(acv, acv.a_mblock, NOT c_call_from_rsend, e);
                    IF  e = e_ok
                    THEN
                        BEGIN
                        (* recreate index *)
                        a06extcolno (pTable^, ix, colptr);
                        a24MigrateUnnamedIndex (acv, pBase, opType[ix], colptr);
                        END;
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
                ix := ix + 1;
                END;
            (*ENDWHILE*) 
            END;
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    a10key_del(acv, pBase);
    END;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361ContainerRecord (VAR acv : tak_all_command_glob;
            VAR Syskey  : tgg_sysinfokey;
            VAR e       : tgg00_BasisError);
 
VAR
      pContainer : tak_sysbufferaddress;
 
BEGIN
a10get_sysinfo (acv, Syskey, d_release, pContainer, e);
IF  e = e_ok
THEN
    IF  pContainer^.sclass.findexexist
    THEN
        IF  pContainer^.sclass.ftree.fileNumObjKeyFiles_gg00 = 0
        THEN
            BEGIN
            pContainer^.sclass.ftree.fileNumObjKeyFiles_gg00 := 1;
            a10repl_sysinfo (acv, pContainer, e);
            END;
        (*ENDIF*) 
    (*ENDIF*) 
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361TempStoreRecord (
            VAR acv  : tak_all_command_glob;
            VAR tree : tgg00_FileId;
            sysbuf   : tak_sysbufferaddress;
            VAR e    : tgg00_BasisError);
 
VAR
      pRecBuf : ^tgg_rec_buf;
 
BEGIN
pRecBuf := @sysbuf^;
b07cadd_record (acv.a_transinf.tri_trans, tree, pRecBuf^);
e := acv.a_transinf.tri_trans.trError_gg00;
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361UpdateRecord (
            VAR acv      : tak_all_command_glob;
            oldRec       : tak_sysbufferaddress;
            VAR e        : tgg00_BasisError);
 
VAR
      pRec   : ^tgg00_Rec;
      auxC2  : tsp00_C2;
      mblock : tgg_mess_block;
      qual   : tgg_rec_buf;
      stack  : ARRAY[0..1] OF tgg_stack_entry;
 
BEGIN
pRec  := @oldRec^;
auxC2 := cgg_local_segment_id;
pRec^.recBody_gg00[pRec^.recKeyLen_gg00 + 1] := auxC2[1];
pRec^.recBody_gg00[pRec^.recKeyLen_gg00 + 2] := auxC2[2];
g01mblock_init( acv.a_transinf.tri_trans, m_update_rec, mm_nil, mblock );
g01stack_init( mblock, @stack, sizeof( stack ), @qual, sizeof( qual ) );
mblock.mb_data      := @pRec^;
mblock.mb_data_size := pRec^.recLen_gg00;
mblock.mb_data_len  := pRec^.recLen_gg00;
IF  oldRec^.syskey.sentrytyp < cak_esysfile2
THEN
    mblock.mb_qual^.mtree := g01tabid.sys1_cat
ELSE
    mblock.mb_qual^.mtree := g01tabid.sys2_cat;
(*ENDIF*) 
a06lsend_mess_buf  (acv, mblock, NOT c_call_from_rsend, e)
END;
 
(*------------------------------*) 
 
PROCEDURE
      ak361WriteProt (
            VAR acv           : tak_all_command_glob;
            VAR MGlob         : tak361_MigrationGlob;
            errCode           : integer;
            errPos            : integer);
 
VAR
      _e           : tgg_basis_error;
      _res         : tsp_num_error;
      _pos         : integer;
      _digits      : integer;
      _intInOutLen : integer;
      _i2c2        : tsp_int_map_c2;
      _stmtLen     : tsp00_Int4;
 
BEGIN
&ifdef trace
t01moveobj (ak_sem, acv.a_cmd_part^.sp1p_buf, 1, acv.a_cmd_part^.sp1p_buf_len);
&endif
_digits      := 10;
_intInOutLen := ( _digits + 1 ) DIV 2 + 2;
a06a_mblock_init( acv, m_insert, mm_nokey, MGlob.prot_tree );
acv.a_mblock.mb_data^.mbp_rec.recLen_gg00          :=
      cgg_rec_key_offset + 1 + sizeof(tgg_surrogate) + 2 * _intInOutLen;
acv.a_mblock.mb_data^.mbp_rec.recKeyLen_gg00       := 1 + sizeof( tgg_surrogate );
acv.a_mblock.mb_data^.mbp_rec.recVarcolOffset_gg00 :=
      2 * _intInOutLen;
acv.a_mblock.mb_data^.mbp_rec.recVarcolCnt_gg00    := 0;
_pos := cgg_rec_key_offset + 1 + sizeof( tgg_surrogate ) + 1;
acv.a_mblock.mb_data^.mbp_buf[ _pos ] := csp_defined_byte;
s41plint( acv.a_mblock.mb_data^.mbp_buf, _pos + 1, _digits, 0, errCode, _res );
_pos := _pos + _intInOutLen;
acv.a_mblock.mb_data^.mbp_buf[ _pos ] := csp_defined_byte;
s41plint( acv.a_mblock.mb_data^.mbp_buf, _pos + 1, _digits, 0, errPos, _res );
_pos     := _pos + _intInOutLen;
_stmtLen := acv.a_cmd_part^.sp1p_buf_len;
IF  _stmtLen > 2000
THEN
    _stmtLen := 2000;
(*ENDIF*) 
_i2c2.map_int := _stmtLen + 1;
acv.a_mblock.mb_data^.mbp_buf[ _pos     ] := _i2c2.map_c2[ 1 ];
acv.a_mblock.mb_data^.mbp_buf[ _pos + 1 ] := _i2c2.map_c2[ 2 ];
acv.a_mblock.mb_data^.mbp_buf[ _pos + 2 ] := csp_ascii_blank;
g10mv11('VAK361',   5,    
      acv.a_cmd_part^.sp1p_buf_size, acv.a_mblock.mb_data_size,
      acv.a_cmd_part^.sp1p_buf, 1, acv.a_mblock.mb_data^.mbp_buf, _pos + 3,
      _stmtLen, acv.a_return_segm^.sp1r_returncode );
acv.a_mblock.mb_data^.mbp_rec.recLen_gg00 :=
      acv.a_mblock.mb_data^.mbp_rec.recLen_gg00 + 3 + _stmtLen;
acv.a_mblock.mb_data_len := acv.a_mblock.mb_data^.mbp_rec.recLen_gg00;
a06lsend_mess_buf( acv, acv.a_mblock, NOT c_call_from_rsend, _e );
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
