/*!***************************************************************************
 
  module      : vkb45
  author      : JuergenA
  responsible : UweH
  special area: KB_stringcol_read_search_length
  last changed: 1999-09-27
  Copyright (c) 2000-2005 SAP AG
  see also    :
  description :
 
 
 .nf

    ========== licence begin  GPL
    Copyright (c) 2000-2005 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

 
*****************************************************************************/
 
.tt 1 $SAP$LiveCache$VKB45$
.tt 3 $UweH$KB_stringcol_read_search_length$1999-09-27$
 
Module  : KB_stringcol_read_search_length
 
Define  :
 
        PROCEDURE
              k45cnread_column (VAR m : tgg00_MessBlock);
 
        PROCEDURE
              k45test_short_col_upgraded (
                    VAR m        : tgg00_MessBlock;
                    VAR upgraded : boolean);
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
&       ifdef TRACE
        FROM
              Test_Procedures : VTA01;
 
        PROCEDURE
              t01basis_error (
                    debug : tgg00_Debug;
                    nam   : tsp00_Sname;
                    b_err : tgg00_BasisError);
 
        PROCEDURE
              t01bool (
                    debug    : tgg00_Debug;
                    nam      : tsp00_Sname;
                    curr_bool: boolean);
 
        PROCEDURE
              t01int4 (
                    layer    : tgg00_Debug;
                    nam      : tsp00_Sname;
                    int      : tsp00_Int4);
&       endif
 
      ------------------------------ 
 
        FROM
              KB_stringcol_open_close : VKB44;
 
        PROCEDURE
              k44get_short_col_rec (
                    VAR m          : tgg00_MessBlock;
                    VAR shc_buf    : tgg00_Rec;
                    VAR prim_tabid : tgg00_Surrogate;
                    VAR shc_id     : tgg00_Surrogate);
 
      ------------------------------ 
 
        FROM
              KB_ServerTasks : VKB900;
 
        PROCEDURE
              kb900PrefetchLob (
                    VAR trans       : tgg00_TransContext;
                    VAR fileId      : tgg00_FileId;
                    lobPosition     : tsp00_Int4;
                    lobBytesToRead  : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              filesysteminterface_1 : VBD01;
 
        PROCEDURE
              b01filestate (
                    VAR t         : tgg00_TransContext;
                    VAR file_id   : tgg00_FileId);
 
      ------------------------------ 
 
        FROM
              filesysteminterface_5 : VBD05;
 
        PROCEDURE
              b05length_bytestr (
                    VAR t              : tgg00_TransContext;
                    VAR file_id        : tgg00_FileId;
                    VAR filelength     : tsp00_Int4;
                    VAR page_count     : tsp00_Int4;
                    VAR str_vers       : tsp00_Int4);
 
        PROCEDURE
              bd05ReadLob (
                    VAR t       : tgg00_TransContext;
                    VAR file_id : tgg00_FileId;
                    pos         : tsp00_Int4;
                    VAR length  : tsp00_Int4;
                    buf_size    : tsp00_Int4;
                    buf_addr    : tsp00_MoveObjPtr;
                    bufpos      : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              Configuration_Parameter : VGG01;
 
        FUNCTION
              g01BlobPrefetchLowerLimit : tsp00_Int4;
 
        PROCEDURE
              g01mblock_init (
                    VAR source_trans : tgg00_TransContext;
                    mess_type  : tgg00_MessType;
                    mess2_type : tgg00_MessType2;
                    VAR mblock : tgg00_MessBlock);
 
      ------------------------------ 
 
        FROM
              Kernel_move_and_fill : VGG101;
 
        PROCEDURE
              SAPDB_PascalMove (
                    mod_id     : tsp00_C6;
                    mod_num    : tsp00_Int4;
                    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;
                    VAR err    : tgg00_BasisError);
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
        PROCEDURE
              s49onecmatch;
 
              tsp00_MoveObj tsp00_Key
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  :
.sp
.cp 3
Created : 1986-01-28
.sp
.cp 3
.sp
.cp 3
Release :      Date : 1999-09-27
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
.sp 2
.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
      k45cnread_column (VAR m : tgg00_MessBlock);
 
VAR
      upgraded   : boolean;
      dummy_vers : tsp00_Int4;
      page_count : tsp00_Int4;
      prim_tabid : tgg00_Surrogate;
      shc_buf    : tgg00_Rec;
 
BEGIN
WITH m, mb_qual^, ml_long_qual DO
    BEGIN
    mb_trns^.trError_gg00 := e_ok;
    IF  lq_len > mb_data_size - lq_data_offset
    THEN
        IF  lq_trunc_req
        THEN
            lq_len := mb_data_size - lq_data_offset
        ELSE
            mb_trns^.trError_gg00 := e_st_invalid_length;
        (*ENDIF*) 
&   ifdef TRACE
    (*ENDIF*) 
    t01int4 (fs_kb, 'curr data sz', mb_data_size - lq_data_offset);
    t01int4 (fs_kb, 'read len    ', lq_len);
&   endif
    upgraded := false;
    IF  mb_trns^.trError_gg00 = e_ok
    THEN
        BEGIN
        prim_tabid := lq_lock_tabid;
        IF  NOT lq_long_in_file
        THEN
            BEGIN
            k44get_short_col_rec (m, shc_buf, prim_tabid, mtree.fileTabId_gg00);
            IF  mb_trns^.trError_gg00 = e_ok
            THEN
                BEGIN
                lq_long_size := shc_buf.len - cgg_rec_key_offset -
                      shc_buf.keylen;
                IF  (lq_pos < 0) (* PTS 1122546 D.T. *)
                THEN
                    BEGIN
                    lq_pos := lq_long_size + lq_pos + 1;
                    IF  (lq_pos < 1)
                    THEN
                        mb_trns^.trError_gg00 := e_file_limit;
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
                IF  mb_trns^.trError_gg00 = e_ok
                THEN
                    BEGIN
                    IF  (lq_pos > lq_long_size) OR
                        (lq_pos < 1           )
                    THEN
                        BEGIN
                        IF  lq_long_size = 0
                        THEN
                            BEGIN
                            mb_data_len     := lq_data_offset;
                            lq_len          := 0;
                            mb_trns^.trError_gg00 := e_key_not_found
                            END
                        ELSE
                            mb_trns^.trError_gg00 := e_file_limit;
                        (*ENDIF*) 
                        END
                    ELSE
                        BEGIN
                        IF  lq_long_size < lq_pos + lq_len - 1
                        THEN
                            lq_len := lq_long_size - lq_pos + 1;
&                       ifdef TRACE
                        (*ENDIF*) 
                        t01int4 (fs_kb, 'read len    ', lq_len);
&                       endif
                        SAPDB_PascalMove ('VKB45 ',   1,    
                              sizeof (shc_buf.buf), mb_data_size,
                              @shc_buf.buf,
                              cgg_rec_key_offset + shc_buf.keylen + lq_pos,
                              @mb_data^.mbp_buf, lq_data_offset + 1,
                              lq_len, mb_trns^.trError_gg00);
                        mb_data_len := lq_data_offset + lq_len;
                        IF  lq_data_offset > cgg_rec_key_offset
                        THEN
                            BEGIN
                            mb_data^.mbp_reclen := mb_data_len ;
                            mb_data^.mbp_keylen := LOCK_MXGG04 + PERM_KEY_MXSP00
                            END
                        (*ENDIF*) 
                        END
                    (*ENDIF*) 
                    END
                (*ENDIF*) 
                END
            ELSE
                IF  mb_trns^.trError_gg00 = e_key_not_found
                THEN
                    BEGIN
                    k45test_short_col_upgraded (m, upgraded);
                    IF  mb_trns^.trError_gg00 = e_file_read_only
                    THEN
                        mb_trns^.trError_gg00 := e_ok
                    (*ENDIF*) 
                    END
                (*ENDIF*) 
            (*ENDIF*) 
            END
        (*ENDIF*) 
        END;
&   ifdef TRACE
    (*ENDIF*) 
    t01int4 (fs_kb, 'upgraded    ', ord (upgraded));
&   endif
    IF  upgraded
    THEN
        lq_long_in_file := true;
    (*ENDIF*) 
    IF  (mb_trns^.trError_gg00 = e_ok) AND (lq_long_in_file)
    THEN
        BEGIN
        b05length_bytestr (mb_trns^, mb_qual^.mtree, lq_long_size,
              page_count, dummy_vers);
        IF  mb_trns^.trError_gg00 = e_ok
        THEN
            IF  (lq_pos < 0)
            THEN
                BEGIN
                lq_pos := lq_long_size + lq_pos + 1;
                IF  (lq_pos < 1)
                THEN
                    mb_trns^.trError_gg00 := e_file_limit;
                (*ENDIF*) 
                END;
            (*ENDIF*) 
        (*ENDIF*) 
        IF  mb_trns^.trError_gg00 = e_ok
        THEN
            BEGIN
            bd05ReadLob (mb_trns^, mtree, lq_pos, lq_len,
                  mb_data_size, @mb_data^.mbp_buf, lq_data_offset + 1);
            mb_data_len  := lq_data_offset + lq_len;
            IF  lq_data_offset > cgg_rec_key_offset
            THEN
                BEGIN
                mb_data^.mbp_reclen := mb_data_len ;
                mb_data^.mbp_keylen := LOCK_MXGG04 + PERM_KEY_MXSP00;
                END;
            IF  mb_trns^.trError_gg00 = e_ok
            THEN
                BEGIN
                (* Before the order segment is send back to the client   *)
                (* a prefetch is started to get the next requested pages *)
                (* as long as the communication takes place              *)
                IF  (
                    (lq_long_size > g01BlobPrefetchLowerLimit               ) AND
                    ((lq_long_size - (lq_pos + lq_len)) > sizeof(tsp00_Page)) AND
                    (lq_len > sizeof(tsp00_Page))
                    )
                THEN
                    kb900PrefetchLob (mb_trns^, mtree, (lq_pos + lq_len), lq_len );
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  mb_trns^.trError_gg00 = e_ok
    THEN
        BEGIN
        lq_pos      := lq_pos + lq_len;
        mcol_pos    := 0;
        mcol_cnt    := 0;
        mfirst_free := 1;
        mb_qual_len := MB_PART1_HEAD_MXGG00 + sizeof (ml_long_qual);
        mb_type     := m_return_result;
        mb_type2    := mm_nil;
        mb_struct   := mbs_long
        END
    ELSE
        BEGIN
        IF  mb_trns^.trError_gg00 = e_key_not_found
        THEN
            BEGIN
            mb_trns^.trError_gg00 := e_ok;
            lq_pos      := lq_pos + lq_len;
            mb_qual_len := MB_PART1_HEAD_MXGG00 + sizeof (ml_long_qual);
            mb_type     := m_return_result;
            mb_type2    := mm_nil;
            mb_struct   := mbs_long
            END
        ELSE
            BEGIN
            mb_qual_len := 0;
            mb_data_len := 0;
            mb_type     := m_return_error
            END
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      k45test_short_col_upgraded (
            VAR m        : tgg00_MessBlock;
            VAR upgraded : boolean);
 
BEGIN
m.mb_trns^.trError_gg00        := e_ok;
m.mb_qual^.mtree.fileType_gg00 := [ftsByteStr_egg00, ftsConcurrent_egg00];
m.mb_qual^.mtree.fileTfn_gg00  := tfnColumn_egg00;
b01filestate (m.mb_trns^, m.mb_qual^.mtree);
IF  (m.mb_trns^.trError_gg00 = e_ok) OR
    (m.mb_trns^.trError_gg00 = e_file_read_only)
THEN
    upgraded := true;
(*ENDIF*) 
;
(* ELSE
      IF  m.mb_trns^.trError_gg00 = e_file_not_found
      THEN
      m.mb_trns^.trError_gg00 := e_key_not_found *)
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
