// ---------------------------------------------------------------------------
// Find entry by ID.
// ---------------------------------------------------------------------------
//
EXPORT_C TInt CCenRepDatabaseUtil::FindEntryL( 
    TInt aEntryId,
    RIpAppPropArray& aArray )
    {
    //CENREPDATABASELOG( "CCenRepDatabaseUtil::FindEntryL - IN" );
    
    RKeyArray keys;
    CleanupClosePushL( keys );

    // Find all rows where ID is aServiceId (entry row + each property row)
    TInt err = iRepository->FindEqL( iStartKey, iColMask, aEntryId, keys );

    TInt count = keys.Count();

    if ( KErrNone == err && count > 0 )
        {
        TUint32 idKey = keys[ 0 ];

        for ( TInt i = 1; i <= iColCount; i++ )
            {
            RBuf value;
            value.CreateL( KCenRepMaxDesLength );
            value.CleanupClosePushL();
            TUint32 propertyKey = idKey + i * iColIncrement;
            TInt errProperty = iRepository->Get( propertyKey, value );
            if( errProperty == KErrNone && value.Compare( KNullDesC ) != 0 )
                {
                CCenRepDatabaseProperty* property = CCenRepDatabaseProperty::NewLC();
                property->SetName( propertyKey - idKey + iStartKey );
                User::LeaveIfError( property->SetValue( value ) );
                User::LeaveIfError( aArray.Append( property ) );
                CleanupStack::Pop( property );
                }
                
            CleanupStack::PopAndDestroy( &value );
            }
        }

    CleanupStack::PopAndDestroy( &keys );
    
    //CENREPDATABASELOG( "CCenRepDatabaseUtil::FindEntryL - OUT" );
    
    return err;

    }
// ---------------------------------------------------------------------------
// Find property and its value by ID.
// ---------------------------------------------------------------------------
//
EXPORT_C TInt CCenRepDatabaseUtil::FindPropertyL( TInt aEntryId, 
                    TUint32 aPropertyName,
                    CCenRepDatabaseProperty& aProperty )
    {
    //CENREPDATABASELOG( "CCenRepDatabaseUtil::FindPropertyL - IN" );
    
    RKeyArray keys;
    CleanupClosePushL( keys );
    TBool found = EFalse;

    // Find all rows where ID is aServiceId (entry row + each property row)
    TInt err = iRepository->FindEqL( iStartKey, iColMask, aEntryId, keys );

    TInt count = keys.Count();

    if ( KErrNone == err && count > 0 )
        {
        TUint32 idKey = keys[ 0 ];

        for ( TInt i = 1; i <= iColCount; i++ )
            {
            TUint32 propertyKey = idKey + i * iColIncrement;
            TUint32 propertyName = propertyKey - idKey + iStartKey;
            if( propertyName == aPropertyName )
                {
                RBuf value;
                value.CreateL( KCenRepMaxDesLength );
                value.CleanupClosePushL();
                
                err = iRepository->Get( propertyKey, value );
                if( err == KErrNone )
                    {
                    if( value.Compare( KNullDesC ) != 0 )
                        {
                        aProperty.SetName( propertyName );
                        User::LeaveIfError( aProperty.SetValue( value ) );
                        found = ETrue;
                        }
                    }
                
                CleanupStack::PopAndDestroy( &value );
                break;
                }
            }
        }

    if( found )
        {
        err = KErrNone;
        }
    else
        {
        if( err == KErrNone )
            {
            err = KErrNotFound;
            }
        }
    CleanupStack::PopAndDestroy( &keys );
    
    //CENREPDATABASELOG( "CCenRepDatabaseUtil::FindPropertyL - OUT" );
    
    return err;
    }