| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdbIsamfile::Fetch | (hzArray<hzPair>&,const hzString&,const hzString&,) |
Declared in file: hzDatabase.h
Defined in file : hdbIsamfile.cpp
Function Logic:
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 ;
}