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) |
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.
CMdEQuery & aQuery | Query instance. |
TInt aError | KErrNone, if the query was completed successfully. Otherwise one of the system-wide error codes. |
void | HandleQueryNewResults | ( | CMdEQuery & | aQuery, |
TInt | aFirstNewItemIndex, | |||
TInt | aNewItemCount | |||
) | [pure virtual] |
Called to notify the observer that new results have been received in the query.
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.