MMdEQueryObserver Class Reference

class MMdEQueryObserver

Observer interface for MdE database queries.

Example of doing a query to metadata database:

A class needs to implement MMdEQueryObserver interface if it is going to do a query to MdE database.

class CMdEQueryExample : public MMdEQueryObserver { void HandleQueryNewResults(CMdEQuery& aQuery, TInt aFirstNewItemIndex, TInt aNewItemCount) ; void HandleQueryCompleted(CMdEQuery& aQuery, TInt aError) ; ... CMdESession* iMdeSession; // session to MdE, created before trying to do the query CMdEQuery* iQuery; };

void CMdEQueryExample::DoQuery() { CMdENamespaceDef& defNS = iMdeSession->GetDefaultNamespaceDefL();

// In this function we create a query with following conditions: // Right object in relation must be a location object. // Left object in relation must have id 6.

// First create an object query. We want to find location objects so let's give that // as a condition to the query. CMdEObjectDef& rightObjDef = defNS.GetObjectDefL( MdeConstants::Location::KLocationObject ); iQuery = iMdeSession->NewObjectQueryL( defNS, rightObjDef, this );

// Result mode EQueryResultModeItem means we want the query to return items. // Other options are: EQueryResultModeId, EQueryResultModeCount, // EQueryResultModeDistinctValues and EQueryResultModeObjectWithFreetexts. iQuery->SetResultMode( EQueryResultModeItem );

// ELogicConditionOperatorAnd means we want all conditions to be true. iQuery->Conditions().SetOperator( ELogicConditionOperatorAnd );

// Add a relation condition to the query. The location object is the right side object of // the relation. CMdERelationCondition& filterCond = iQuery->Conditions(). AddRelationConditionL( ERelationConditionSideRight );

// The object on the left side of the relation must have ID 6. filterCond.LeftL().AddObjectConditionL( 6 );

iQuery->FindL( 10, 1 ); // Start the query! The first parameter is maximum number of result items. // The second parameter is number of results per observer // notification. This query returns maximum of 10 location items // and gives a notification (HandleQueryNewResults) for each. }

void CMdEQueryExample::HandleQueryCompleted( CMdEQuery& aQuery, TInt aError ) { // query is completed if( aQuery.Count() > 0 && aError == KErrNone ) { // some items were found! } }

void CMdEQueryExample::HandleQueryNewResults(CMdEQuery& aQuery, TInt aFirstNewItemIndex, TInt aNewItemCount) { // query is not yet completed but new results were found }

CMdEQuery::FindL

Public Member Functions
void HandleQueryCompleted (CMdEQuery &, TInt )
void HandleQueryNewResults (CMdEQuery &, TInt , TInt )

Member Functions Documentation

HandleQueryCompleted(CMdEQuery &, TInt)

void HandleQueryCompleted ( CMdEQuery & aQuery,
TInt aError
) [pure virtual]

Called to notify the observer that the query has been completed, or that an error has occured.

Parameters

CMdEQuery & aQuery Query instance.
TInt aError KErrNone, if the query was completed successfully. Otherwise one of the system-wide error codes.

HandleQueryNewResults(CMdEQuery &, TInt, TInt)

void HandleQueryNewResults ( CMdEQuery & aQuery,
TInt aFirstNewItemIndex,
TInt aNewItemCount
) [pure virtual]

Called to notify the observer that new results have been received in the query.

Parameters

CMdEQuery & aQuery Query instance that received new results.
TInt aFirstNewItemIndex Index of the first new item that was added to the result item array.
TInt aNewItemCount Number of items added to the result item array.