| Return Type | Function name | Arguments |
|---|---|---|
| bool | hdbIsamfile::Exists | (const hzString&,) |
Declared in file: hzDatabase.h
Defined in file : hdbIsamfile.cpp
Function Logic:
Function body:
bool hdbIsamfile::Exists (const hzString& key)
{
_hzfunc("hdbIsamfile::Exists") ;
hzMapM<hzString,hzString> tmp ;
char* i ;
char* j ;
hzString strA ;
hzString strB ;
uint32_t nPos ;
uint32_t addr ;
uint32_t nC ;
m_Error.Clear() ;
m_Cond = E_OK ;
m_Error.Printf("%s called\n", *_fn) ;
if (m_nInitState < 1) { hzwarn(E_NOINIT, "ISAM file not initialized") ; return false ; }
if (m_nInitState < 2) { hzwarn(E_NOTOPEN, "ISAM file not open") ; return false ; }
if (!key)
return false ;
if (!m_Index.Count())
return false ;
nPos = m_Index.Target(key) ;
if (nPos >&eq; m_Index.Count())
nPos = m_Index.Count() -1;
strA = m_Index.GetKey(nPos) ;
if (strA > key)
nPos-- ;
for (; nPos < m_Index.Count() ; nPos++)
{
if (m_Index.GetKey(nPos) > key)
break ;
addr = m_Index.GetObj(nPos) ;
m_RdD.seekg(addr * m_nBlkSize) ;
if (m_RdD.fail())
{ m_Cond = E_READFAIL ; m_Error.Printf("%s: Failed to seek to block %d (position %d) in data block\n", *_fn, addr, addr * m_nBlkSize) ; return false ; }
m_RdD.read(m_Buf, HZ_BLOCKSIZE) ;
if (m_RdD.fail())
{ m_Cond = E_READFAIL ; m_Error.Printf("%s: Failed to read block %d (position %d) in data block\n", *_fn, addr, addr * m_nBlkSize) ; return false ; }
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;
}
}
}
return tmp.Exists(key) ;
}