Beispiel #1
0
long *OGRMIAttrIndex::GetAllMatches( OGRField *psKey )

{
    GByte *pabyKey = BuildKey( psKey );
    long  *panFIDList = NULL, nFID;
    int   nFIDCount=0, nFIDMax=2;

    panFIDList = (long *) CPLMalloc(sizeof(long) * 2);

    nFID = poINDFile->FindFirst( iIndex, pabyKey );
    while( nFID > 0 )
    {
        if( nFIDCount >= nFIDMax-1 )
        {
            nFIDMax = nFIDMax * 2 + 10;
            panFIDList = (long *) CPLRealloc(panFIDList, sizeof(long)*nFIDMax);
        }
        panFIDList[nFIDCount++] = nFID - 1;
        
        nFID = poINDFile->FindNext( iIndex, pabyKey );
    }

    panFIDList[nFIDCount] = OGRNullFID;
    
    return panFIDList;
}
Beispiel #2
0
GIntBig *OGRMIAttrIndex::GetAllMatches( OGRField *psKey, GIntBig* panFIDList, int* nFIDCount, int* nLength )
{
    GByte *pabyKey = BuildKey( psKey );

    if (panFIDList == nullptr)
    {
        panFIDList = static_cast<GIntBig *>(CPLMalloc(sizeof(GIntBig) * 2));
        *nFIDCount = 0;
        *nLength = 2;
    }

    GIntBig nFID = poINDFile->FindFirst( iIndex, pabyKey );
    while( nFID > 0 )
    {
        if( *nFIDCount >= *nLength-1 )
        {
            *nLength = (*nLength) * 2 + 10;
            panFIDList = static_cast<GIntBig *>(CPLRealloc(panFIDList, sizeof(GIntBig)* (*nLength)));
        }
        panFIDList[(*nFIDCount)++] = nFID - 1;

        nFID = poINDFile->FindNext( iIndex, pabyKey );
    }

    panFIDList[*nFIDCount] = OGRNullFID;

    return panFIDList;
}
Beispiel #3
0
/**********************************************************************
 *                          SearchIndex()
 *
 * Search a TAB dataset's .IND file for pszVal in index nIndexNo
 **********************************************************************/
static int SearchIndex(const char *pszFname, int nIndexNo, const char *pszVal)
{
    TABFile     oTABFile;
    TABINDFile  *poINDFile;

    /*---------------------------------------------------------------------
     * Try to open source file
     *--------------------------------------------------------------------*/
    if (oTABFile.Open(pszFname, "rb") != 0)
    {
        printf("Failed to open %s as a TABFile.\n", pszFname);
        return -1;
    }

    /*---------------------------------------------------------------------
     * Fetch IND file handle
     *--------------------------------------------------------------------*/
    if ((poINDFile = oTABFile.GetINDFileRef()) == NULL)
    {
        printf("Dataset %s has no .IND file\n", pszFname);
        return -1;
    }

    /*---------------------------------------------------------------------
     * Search the index.
     * For now we search only 'char' index types!!!
     *--------------------------------------------------------------------*/
    GByte *pKey;
    int nRecordNo;

    pKey = poINDFile->BuildKey(nIndexNo, pszVal);
    nRecordNo = poINDFile->FindFirst(nIndexNo, pKey);

    if (nRecordNo < 1)
    {
        printf("Value '%s' not found in index #%d\n", pszVal, nIndexNo);
    }
    else
    {
        while(nRecordNo > 0)
        {
            printf("Record %d...\n", nRecordNo);

            nRecordNo = poINDFile->FindNext(nIndexNo, pKey);
        }
    }

    /*---------------------------------------------------------------------
     * Cleanup and exit.
     *--------------------------------------------------------------------*/
    oTABFile.Close();

    return 0;

}