Fetches objects matching the key or falling within a range of two keys.

Return TypeFunction nameArguments
hzEcodehdbIsamfile::Fetch(hzArray<hzPair>&,hzString&,hzString&,)

Declared in file: hzDatabase.h
Defined in file : hdbIsamfile.cpp

Function Logic:

0:START 1:unknown 2:Return E_NOINIT 3:unknown 4:Return E_NOTOPEN 5:items items 6:unknown 7:items 8:Return E_ARGUMENT 9:unknown 10:Return E_NOTFOUND 11:unknown 12:keyB 13:keyA 14:!keyLo 15:keyB 16:keyA 17:unknown 18:keyA keyB 19:keyA keyB 20:nPos 21:unknown 22:m_Index 23:nPos 24:strA 25:unknown 26:items 27:unknown 28:unknown 29:addr items 30:unknown 31:items 32:Return E_READFAIL 33:items 34:unknown 35:items 36:Return E_READFAIL 37:unknown 38:unknown 39:* 40:unknown 41:strA i j 42:unknown 43:strB i 44:j 45:unknown 46:items strB strA 47:nLo 48:unknown 49:Return E_NOTFOUND 50:nHi 51:unknown 52:pair pair items 53:Return rc

Function body:

hzEcode hdbIsamfile::Fetch (hzArray<hzPair>& result)hzString& keyLo, hzString& keyHi, 
{
   //  Fetches objects matching the key or falling within a range of two keys.
   //  
   //  Arguments: 1) obj  The object to be populated
   //     2) datumId The object id
   //  
   //  Returns: E_NOTOPEN If the reader stream is not open for reading
   //     E_READFAIL The reader stream is already in a fialed state
   //     E_CORRUPT Row metadata not as expected. Possible overwrites
   //     E_FORMAT Data format error
   //     E_OK  The operation was successful
   _hzfunc("hdbIsamfile::Fetch") ;
   hzMapM<hzString,hzString>   tmp ;   //  Temp map of key/object pairs found in target data area
   char*       i ;             //  Buffer iterator
   char*       j ;             //  Buffer iterator
   hzString    keyA ;          //  Key string
   hzString    keyB ;          //  Key string
   hzString    strA ;          //  Key string
   hzString    strB ;          //  Object string
   hzPair      pair ;          //  For output
   uint32_t    nPos ;          //  Position of target within m_Index map
   uint32_t    addr ;          //  Address of target data block
   uint32_t    nC ;            //  Counter
   int32_t     nLo ;           //  Position of first target within tmp map
   int32_t     nHi ;           //  Position of last target within tmp map
   hzEcode     rc = E_OK ;     //  Return code
   //  Check init state
   if (m_nInitState < 1)   return E_NOINIT ;
   if (m_nInitState < 2)   return E_NOTOPEN ;
   result.Clear() ;
   m_Error.Clear() ;
   //  Sort the keys
   if (!keyLo && !keyHi)
       { m_Error.Printf("No keys supplied\n") ; return E_ARGUMENT ; }
   if (!m_Index.Count())
       return E_NOTFOUND ;
   if (!keyHi)
       keyA = keyB = keyLo ;
   else if (!keyLo)
       keyA = keyB = keyHi ;
   else
   {
       if (keyHi < keyLo)
           { keyA = keyHi ; keyB = keyLo ; }
       else
           { keyA = keyLo ; keyB = keyHi ; }
   }
   //  Identify target data block
   nPos = m_Index.Target(keyA) ;
   if (nPos >&eq; m_Index.Count())
       nPos = m_Index.Count() -1;
   strA = m_Index.GetKey(nPos) ;
   if (strA > keyA)
       nPos-- ;
   for (; nPos < m_Index.Count() ; nPos++)
   {
       if (m_Index.GetKey(nPos) > keyB)
           break ;
       //  Read in target data block
       addr = m_Index.GetObj(nPos) ;
       m_RdD.seekg(addr * m_nBlkSize) ;
       if (m_RdD.fail())
           { m_Error.Printf("%s: Failed to seek to block %d (position %d) in data block\n", *_fn, addr, addr * m_nBlkSize) ; return E_READFAIL ; }
       m_RdD.read(m_Buf, HZ_BLOCKSIZE) ;
       if (m_RdD.fail())
           { m_Error.Printf("%s: Failed to read block %d (position %d) in data block\n", *_fn, addr, addr * m_nBlkSize) ; return E_READFAIL ; }
       for (i = j = m_Buf, nC = 0; nC < HZ_BLOCKSIZE ; i++, nC++)
       {
           if (m_Buf[nC] == CHAR_NL)
           {
               *i = 0;
               if (!strA)
                   { strA = j ; j = i + 1; continue ; }
               if (*j)
                   strB = j ;
               j = i + 1;
               if (!strA)
                   break ;
               tmp.Insert(strA, strB) ;
               strA = strB = (char*) 0;
           }
       }
   }
   //  If object id is zero return blank object
   nLo = tmp.First(keyA) ;
   if (nLo < 0)
       return E_NOTFOUND ;
   nHi = tmp.Last(keyB) ;
   for (; nLo <&eq; nHi ; nLo++)
   {
       pair.name = tmp.GetKey(nLo) ;
       pair.value = tmp.GetObj(nLo) ;
       result.Add(pair) ;
   }
   return rc ;
}