Determine if the supplied key matches any found in the ISAM
| Return Type | Function name | Arguments |
|---|---|---|
| bool | hdbIsamfile::Exists | (hzString&,) |
Declared in file: hzDatabase.h
Defined in file : hdbIsamfile.cpp
Function Logic:
Function body:
bool hdbIsamfile::Exists (hzString& key)
{
// Determine if the supplied key matches any found in the ISAM
//
// Argument: key The search key
//
// Returns: True If the key is found
// False Otherwise
_hzfunc("hdbIsamfile::Exists") ;
hzMapM<hzString,hzString> tmp ; // Temp map of key/object pairs found in target data area
char* i ; // Buffer iterator
char* j ; // Buffer iterator
hzString strA ; // Key string
hzString strB ; // Object string
uint32_t nPos ; // Position of target within m_Index map
uint32_t addr ; // Address of target data block
uint32_t nC ; // Counter
// Check init state
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 ;
// Identify target data block
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 ;
// Read in target data block
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) ;
}