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

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

Function Logic:

0:START 1:m_nInitState<1 2:Return E_NOINIT 3:m_nInitState<2 4:Return E_NOTOPEN 5:hzArray::Clear hzChain::Clear 6:!keyLo&&!keyHi 7:hzChain::Printf 8:Return E_ARGUMENT 9:!m_Index.Count() 10:Return E_NOTFOUND 11:!keyHi 12:keyB keyA 13:!keyLo 14:keyB keyA 15:keyHi 16:keyA keyB 17:keyA keyB 18:hzMapM::Target nPos 19:nPos>=m_Index.Count() 20:hzMapM::Count nPos 21:hzMapM::GetKey strA 22:strA>keyA 23:items 24:nPos 25:m_Index.GetKey(nPos)>keyB 26:hzMapM::GetObj addr ifstream::seekg ifstream::fail 27:m_RdD.fail() 28:hzChain::Printf 29:Return E_READFAIL 30:ifstream::read ifstream::fail 31:m_RdD.fail() 32:hzChain::Printf 33:Return E_READFAIL 34:nC 35:m_Buf[nC]==(char)10 36:* 37:!strA 38:strA j 39:*j 40:strB 41:j 42:!strA 43:hzMapM::Insert strB strA 44:hzMapM::First nLo 45:nLo<0 46:Return E_NOTFOUND 47:hzMapM::Last nHi 48:nLo<=nHi; 49:hzMapM::GetKey pair hzMapM::GetObj pair hzArray::Add 50:Return rc

Function body:

hzEcode hdbIsamfile::Fetch (hzArray<hzPair>& result, const hzString& keyLo, const hzString& keyHi)
{
   _hzfunc("hdbIsamfile::Fetch") ;
   hzMapM<hzString,hzString>   tmp ;
   char*       i ;
   char*       j ;
   hzString    keyA ;
   hzString    keyB ;
   hzString    strA ;
   hzString    strB ;
   hzPair      pair ;
   uint32_t    nPos ;
   uint32_t    addr ;
   uint32_t    nC ;
   int32_t     nLo ;
   int32_t     nHi ;
   hzEcode     rc = E_OK ;
   if (m_nInitState < 1)   return E_NOINIT ;
   if (m_nInitState < 2)   return E_NOTOPEN ;
   result.Clear() ;
   m_Error.Clear() ;
   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 ; }
   }
   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 ;
       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;
           }
       }
   }
   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 ;
}