// -----------------------------------------------------------------------------
// PosLmIconHandler::GetIconPathIdL
//
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
void PosLmIconHandler::GetIconPathIdL(
    CPosLmLocalDbAccess& aDbAccess,
    const TDesC& aIconPath,
    TUint32& aIconPathId)
    {
    // First search icon table for icon path
    HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen+KMaxFileName);
    sql->Des().Format(KPosLmSqlFindString, &KPosLmIconIdCol, &KPosLmIconTable,
        &KPosLmIconPathCol, &aIconPath);

    RDbView view;
    aDbAccess.PrepareViewLC(
        CPosLmLocalDbAccess::EUpdatablePreparation, view, *sql);

    if (!view.NextL())
        {
        // Icon path not found. Add icon path to database.
        AddIconPathL(aDbAccess, aIconPath, aIconPathId);
        }
    else
        {
        // Icon path found. Fetch number.
        view.GetL();
        aIconPathId = view.ColUint32(1);
        }

    CleanupStack::PopAndDestroy(2, sql); //&view
    }
Beispiel #2
0
// ---------------------------------------------------------------------------
// CFotaDB::GetStateL
// Gets pkg state from db
// ---------------------------------------------------------------------------
TPackageState CFotaDB::GetStateL(const TInt aPkgId, TDes8& aPkgURL)
    {
    RDbView view;
    TPackageState s;
    CleanupClosePushL(view);

    s.iState = RFotaEngineSession::EIdle; // default state is idle

    HBufC* select = HBufC::NewLC(KSelect_where_packageid().Length() + 10);
    select->Des().Format(KSelect_where_packageid, aPkgId);

    TInt err = view.Prepare(iStateDB, TDbQuery(*select));
    __LEAVE_IF_ERROR(err);
    view.EvaluateAll();
    view.FirstL();

    while (view.AtRow())
        {
        view.GetL();
        HBufC8* url;
        s = RowToStateL(url, view);
        CleanupStack::PushL(url);
        aPkgURL.Copy(url->Des());
        CleanupStack::PopAndDestroy(); // url
        view.NextL();
        }
    CleanupStack::PopAndDestroy(); //select
    CleanupStack::PopAndDestroy(); //view
    return s;
    }
// -----------------------------------------------------------------------------
// CWPInternetAPDB::ReadItemsL
// -----------------------------------------------------------------------------
// 
void CWPInternetAPDB::ReadItemsL(RArray<TAccessPointItem>& aItemArray,
        TFileName QueryBuffer)
    {
    FLOG( _L( "[Provisioning] CWPInternetAPDB::ReadItemsL" ) );
    RDbView Myview;
    Myview.Prepare(iItemsDatabase, TDbQuery(QueryBuffer));
    CleanupClosePushL(Myview);
    Myview.EvaluateAll();
    if ( Myview.FirstL())
    {
    	while (Myview.AtRow())
        {
        Myview.GetL();

        TAccessPointItem AccessPointItem;
        AccessPointItem.iIndex = Myview.ColInt(1);
        AccessPointItem.iAPID = Myview.ColInt(2);
        AccessPointItem.iBearerType = Myview.ColInt(3);
        AccessPointItem.iOriginator.Copy(Myview.ColDes(4));

        aItemArray.Append(AccessPointItem);
        Myview.NextL();
        }
    }

    CleanupStack::PopAndDestroy(); // Myview
    FLOG( _L( "[Provisioning] CWPInternetAPDB::ReadItemsL: done" ) );
    }
Beispiel #4
0
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ 
void CScheduleDB::DeleteFromDatabaseL(TInt& aIndex)
{	
	TFileName QueryBuffer;
	QueryBuffer.Copy(_L("SELECT * FROM "));
	QueryBuffer.Append(KtxtItemlist);
	
	QueryBuffer.Append(_L(" WHERE "));
	QueryBuffer.Append(NCol0);
	QueryBuffer.Append(_L(" = "));
	QueryBuffer.AppendNum(aIndex);
			
	iItemsDatabase.Begin();
	
	RDbView Myview;
	// query buffr with index finds only the selected item row.
	Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer));
	CleanupClosePushL(Myview);
	
	Myview.EvaluateAll();
	Myview.FirstL();
	// we have autoincrement in index so it should be unique
	// but just to make sure, we use 'while', instead of 'if'
	while(Myview.AtRow())            
	{	
		Myview.GetL();
		Myview.DeleteL();	
		Myview.NextL();
	}
			
	CleanupStack::PopAndDestroy(1); // Myview
	iItemsDatabase.Commit();
	// compacts the databse, by physicaly removig deleted data.
	iItemsDatabase.Compact();
}
// -----------------------------------------------------------------------------
// CWPInternetAPDB::ReadItemsL
// -----------------------------------------------------------------------------
// 
void CSCOMOAdapterDb::ReadItemsL(RPointerArray<CAMDbItem>& aItemArray,
        TDesC& aSqlQuery)
    {

    RDbView view;
    view.Prepare(iDatabase, TDbQuery(aSqlQuery));
    CleanupClosePushL(view);
    view.EvaluateAll();
    view.FirstL();

    while (view.AtRow())
        {
        view.GetL();

        CAMDbItem *dbitem = new(ELeave) CAMDbItem;
        dbitem->id = view.ColInt(1);
        dbitem->iLUID = view.ColInt(2);
        dbitem->iProfileId = view.ColInt(3);

        dbitem->iServerID = (view.ColDes8(4)).AllocL();
        dbitem->iCorrelator = (view.ColDes8(5)).AllocL();
        dbitem->iSourceURI = (view.ColDes8(6)).AllocL();

        dbitem->iRetryCount = view.ColInt(7);

        aItemArray.AppendL(dbitem);
        view.NextL();
        }

    CleanupStack::PopAndDestroy(); // view

    }
Beispiel #6
0
// ---------------------------------------------------------------------------
// CFotaDB::GetAllL
// Get all states
// ---------------------------------------------------------------------------
void CFotaDB::GetAllL(RArray<TInt>& aStates)
    {
    RDbView view;
    CleanupClosePushL(view);

    TInt err = view.Prepare(iStateDB, TDbQuery(KSelectAll));
    __LEAVE_IF_ERROR(err);
    view.EvaluateAll();

    view.FirstL();
    FLOG(_L("[fota DB] --- rows ------------------------------------------------------------------- v"));
    while (view.AtRow())
        {
        view.GetL();
        HBufC8* url;
        TPackageState s = RowToStateL(url, view);
        aStates.Append(s.iPkgId);
        CleanupStack::PushL(url);
        FLOG(_L("[fotaDB] pkgid: %d profid:%d state:%d  result:%d \
                url: %d chars sessiontype:%d IapId:%d Pkgsize:%d UpdateLtr:%d"),
                s.iPkgId, s.iProfileId, s.iState, s.iResult,
                url->Des().Length(), s.iSessionType, s.iIapId, s.iPkgSize,
                s.iUpdateLtr);
        CleanupStack::PopAndDestroy(); // url
        view.NextL();
        }
    FLOG(_L("[fota DB] --- rows ------------------------------------------------------------------- ^"));
    view.Close();
    CleanupStack::PopAndDestroy(); //view
    }
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
TBool PosLmLandmarkHandler::ReadIconPathIdL(
    CPosLmLocalDbAccess& aDbAccess,
    const TPosLmItemId& aLandmarkId,
    TUint32& aIconPathId)
    {
    HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
    sql->Des().Format(KPosLmSqlFindUint, &KPosLmIconIdCol,
        &KPosLmLandmarkTable, &KPosLmLandmarkIdCol, aLandmarkId);

    RDbView view;
    aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EUpdatablePreparation, view,
        *sql);

    TBool iconIsSet = EFalse;

    if (view.NextL())
        {
        view.GetL();

        if (!view.IsColNull(1))
            {
            aIconPathId = view.ColUint32(1);
            iconIsSet = ETrue;
            }
        }

    CleanupStack::PopAndDestroy(2, sql); //&view

    return iconIsSet;
    }
void CExPolicy_Server::ReadDbItemsL(TBool aImsi)
{
	TFileName QueryBuffer;
	QueryBuffer.Copy(_L("SELECT * FROM "));// just get all columns & rows
	
	if(aImsi)
		QueryBuffer.Append(KtxtImsilist);
	else
		QueryBuffer.Append(KtxtNumberlist);
	
	
	RDbView Myview;
	Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer));
	CleanupClosePushL(Myview);
	Myview.EvaluateAll();
	Myview.FirstL();
	
	while(Myview.AtRow()) // Just delete one instance of the message           
	{	
		Myview.GetL();		
		
		TExampleItem NewItem;	
		NewItem.iIndex = Myview.ColInt(1);
        NewItem.iName.Copy(Myview.ColDes(2));
        NewItem.iValue.Copy(Myview.ColDes(3));
		
		if(aImsi)
			iImsiArray.Append(NewItem);	
		else
			iNumberArray.Append(NewItem);	
		Myview.NextL();
	} 
	
	CleanupStack::PopAndDestroy(1); // Myview
}
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
TBool CExPolicy_Server::OkToAddToValDb(RDbDatabase& aDatabase,const TDesC& aCode,const TDesC8& aString)
{
	TBool Ret(ETrue);
	
	TFileName QueryBuffer;
	QueryBuffer.Copy(_L("SELECT * FROM "));
	QueryBuffer.Append(KtxtVallist);
	
	RDbView Myview;
	Myview.Prepare(aDatabase,TDbQuery(QueryBuffer));
	CleanupClosePushL(Myview);
	Myview.EvaluateAll();
	Myview.FirstL();
	
	QueryBuffer.Copy(aString);
		
	while(Myview.AtRow()) // Just delete one instance of the message           
	{	
		Myview.GetL();		
		
		if(QueryBuffer == Myview.ColDes(3)
		&& aCode == Myview.ColDes(2))
		{
			Ret = EFalse;
			break;	
		}
			
		Myview.NextL();
	} 
	
	CleanupStack::PopAndDestroy(1); // Myview
	
	return Ret;
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
void PosLmLandmarkHandler::UpdateFieldsForLandmarkL(
    CPosLmLocalDbAccess& aDbAccess,
    const RArray<TUint>& aFieldIds,
    const CPosLandmark& aLandmark)
    {
    for (TInt i = 0; i < aFieldIds.Count(); i++)
        {
        HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
        sql->Des().Format(KPosLmSqlFind2Uint, &KPosLmSqlAll,
            &KPosLmLandmarkFieldTable, &KPosLmLandmarkIdCol,
            aLandmark.LandmarkId(), &KPosLmFieldTypeCol, aFieldIds[i]);

        RDbView view;
        aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EUpdatablePreparation,
            view, *sql);

        TPtrC fieldValue;
        User::LeaveIfError(aLandmark.GetPositionField(
            (TPositionFieldId)aFieldIds[i], fieldValue));

        if (view.NextL())
            {
            view.UpdateL();
            PosLmLongTextColHandler::WriteToLongTextColumnL(fieldValue, view,
                EPosLmLfcFieldStringCol);
            view.PutL();
            }

        CleanupStack::PopAndDestroy(2, sql); //&view
        }
    }
Beispiel #11
0
TInt CSCPParamDB :: GetApplicationIDListL(RArray <TUid>& aIDArray) {
    _SCPDB_LOG(_L("[CSCPParamDB]-> GetApplicationIDList() >>>"));
    
    RDbView lDBView;
    CleanupClosePushL(lDBView);
    
    HBufC* lSelectQry  = HBufC :: NewLC(KSelectAll().Length());
    lSelectQry->Des().Append(KSelectAll);
    
    __LEAVE_IF_ERROR(lDBView.Prepare(iParameterDB, TDbQuery(*lSelectQry)));
    __LEAVE_IF_ERROR(lDBView.EvaluateAll());
    
    TBool lStatus(EFalse);
    TInt lRet(KErrNone);
    
    TRAP(lRet, lStatus = lDBView.FirstL());
    
    if(lRet == KErrNone && lStatus) {
        do {
            lDBView.GetL();
            TUid lAppUID = TUid :: Uid(lDBView.ColInt(iColSet->ColNo(KColAppId)));
            
            if(aIDArray.Find(lAppUID) == KErrNotFound) {
                aIDArray.AppendL(lAppUID);
            }
        }
        while(lDBView.NextL());
    }
    
    _SCPDB_LOG(_L("[CSCPParamDB]-> GetApplicationIDList() >>>"));
    CleanupStack :: PopAndDestroy(2);
    return KErrNone;
}
Beispiel #12
0
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ 
void CScheduleDB::ReadDbItemsL(RPointerArray<CMsgStored>& aItemArray)
{
	aItemArray.ResetAndDestroy();// first reset the array
	
	TFileName QueryBuffer;
	QueryBuffer.Copy(_L("SELECT * FROM "));// just get all columns & rows
	QueryBuffer.Append(KtxtItemlist2);
		
	RDbView Myview;
	Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer));
	CleanupClosePushL(Myview);
	Myview.EvaluateAll();
	Myview.FirstL();
	
	while(Myview.AtRow()) // Just delete one instance of the message           
	{	
		Myview.GetL();		
		
		CMsgStored* NewItem = new(ELeave)CMsgStored();	
		aItemArray.Append(NewItem);
		
		NewItem->iIndex = Myview.ColInt32(1);
		NewItem->iMessage = Myview.ColDes(2).AllocL();
				
		Myview.NextL();
	} 
	
	CleanupStack::PopAndDestroy(1); // Myview
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
void PosLmLandmarkHandler::UpdateIconAndBasicLandmarkInfoL(
    CPosLmLocalDbAccess& aDbAccess,
    const CPosLandmark& aLandmark,
    const CPosLandmark& aOldLandmark)
    {
    if (!CheckIfIconAndBasicInfoAreEqualL(aLandmark, aOldLandmark))
        {
        TUint32 oldIconId;
        TBool oldIconExists = ReadIconPathIdL(aDbAccess, aLandmark.LandmarkId(),
            oldIconId);

        TPtrC path;
        TInt iconIndex;
        TInt maskIndex;
        TUint32 iconId = 0;

        if (aLandmark.GetIcon(path, iconIndex, maskIndex) == KErrNone)
            {
            PosLmIconHandler::GetIconPathIdL(aDbAccess, path, iconId);
            }

        HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
        sql->Des().Format(KPosLmSqlFindUint, &KPosLmSqlAll,
            &KPosLmLandmarkTable, &KPosLmLandmarkIdCol, aLandmark.LandmarkId());

        RDbView view;
        aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EUpdatablePreparation,
            view, *sql);

        if (view.NextL())
            {
            view.UpdateL();

            SetIconL(view, aLandmark, iconId);
            SetPositionL(view, aLandmark);
            SetCoverageRadiusL(view, aLandmark);
            SetLandmarkNameL(view, aLandmark);
            SetLandmarkDescriptionL(view, aLandmark);

            view.PutL();
            }
        else
            {
            User::Leave(KErrNotFound);
            }

        CleanupStack::PopAndDestroy(2, sql); //&view

        if (oldIconExists)
            {
            PosLmIconHandler::RemoveIconIfNotUsedL(aDbAccess, oldIconId);
            }
        }
    }
Beispiel #14
0
TInt CSCPParamDB :: GetValuesForParameterL(TInt aParamID, RPointerArray <HBufC>& aParamValues, const TInt32 aApp) {
    _SCPDB_LOG(_L("[CSCPParamDB]-> GetValueForParameterL >>>"));

    RDbView lDBView;
    CleanupClosePushL(lDBView);

    HBufC* lSelectQry  = HBufC :: NewLC(KSelectWhereParamIdAppID().Length() + 40);
    lSelectQry->Des().Format (KSelectWhereParamIdAppID, aParamID, aApp);

    __LEAVE_IF_ERROR(lDBView.Prepare(iParameterDB, TDbQuery(*lSelectQry)));
    __LEAVE_IF_ERROR(lDBView.EvaluateAll());
    
    if (lDBView.FirstL())
    {
    	TInt size(0);
    	TInt lRowCount = lDBView.CountL();

    	if(lRowCount == 0) {
        _SCPDB_LOG(_L("[CSCPParamDB]-> No Rows found for this parameter"));
        CleanupStack :: PopAndDestroy(2);
        return KErrNotFound;
    	}
    
    	TInt lErr(KErrNone);
    
    	do {
        lDBView.GetL();
        size = lDBView.ColDes(iColSet->ColNo(KColValueDes)).Size();

        if(size) {
            HBufC* lBuff = HBufC :: NewL(size);
            TPtr lPtr(lBuff->Des());
            lPtr.Copy(lDBView.ColDes(iColSet->ColNo(KColValueDes)));
          
            TRAP(lErr, aParamValues.AppendL(lBuff));
            
            if(lErr != KErrNone) {
                aParamValues.ResetAndDestroy();
                User :: Leave(lErr);
            }
        }
    	}
    	while(lDBView.NextL());
    }

    CleanupStack :: PopAndDestroy(2);
    _SCPDB_LOG(_L("[CSCPParamDB]-> GetValuesForParameterL <<<"));
    return KErrNone;   
}
Beispiel #15
0
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ 
void CScheduleDB::ReadDbItemsL(RPointerArray<CMsgSched>& aItemArray)
{
	aItemArray.ResetAndDestroy();// first reset the array
	
	TFileName QueryBuffer;
	QueryBuffer.Copy(_L("SELECT * FROM "));// just get all columns & rows
	QueryBuffer.Append(KtxtItemlist);
		
	RDbView Myview;
	Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer));
	CleanupClosePushL(Myview);
	Myview.EvaluateAll();
	Myview.FirstL();
	
	while(Myview.AtRow()) // Just delete one instance of the message           
	{	
		Myview.GetL();		
		
		CMsgSched* NewItem = new(ELeave)CMsgSched();	
		aItemArray.Append(NewItem);
		
		NewItem->iIndex  = Myview.ColInt32(1);
        NewItem->iTime   = Myview.ColTime(5);
        NewItem->iRepeat = Myview.ColInt32(6);
        
        if(Myview.ColInt32(2) > 50)
        	NewItem->iUnicode = ETrue;
        else
        	NewItem->iUnicode = EFalse;
        
        NewItem->iNunmber = Myview.ColDes(3).AllocL();
		NewItem->iMessage = Myview.ColDes(4).AllocL();
		
		if(Myview.ColInt32(7) > 50)
		  	NewItem->iEnabled = ETrue;
		else
			NewItem->iEnabled = EFalse;

		if(Myview.ColInt32(8) > 50)
		  	NewItem->iFlashSMS = ETrue;
		else
			NewItem->iFlashSMS = EFalse;
				
		Myview.NextL();
	} 
	
	CleanupStack::PopAndDestroy(1); // Myview
}
Beispiel #16
0
TInt CSCPParamDB :: ListParamsUsedByAppL(RArray <TInt>& aParamIds, const TInt32 aApp) {
    _SCPDB_LOG(_L("[CSCPParamDB]-> ListParamsUsedByApp() >>>"));
    
    RDbView lDBView;
    CleanupClosePushL(lDBView);
    
    HBufC* lSelectQry(NULL);
    
    if(aApp == -1) {
        lSelectQry = HBufC :: NewLC(KSelectAllAscParamID().Length());
        lSelectQry->Des().Append(KSelectAllAscParamID);
    }
    else {
        lSelectQry = HBufC :: NewLC(KSelectWhereAppIdByAscParamID().Length() + 15);
        lSelectQry->Des().Format(KSelectWhereAppIdByAscParamID, aApp);
    }
    
    _SCPDB_LOG(_L("[CSCPParamDB]-> SQL Query: %S"), &lSelectQry->Des());
    _SCPDB_LOG(_L("[CSCPParamDB]-> Executing the query..."));
    __LEAVE_IF_ERROR(lDBView.Prepare(iParameterDB, TDbQuery(lSelectQry->Des())));
    __LEAVE_IF_ERROR(lDBView.EvaluateAll());
    
    TInt lErr(KErrNone);
    TInt lStatus(KErrNone);    
    
    TRAP(lErr, lStatus = lDBView.FirstL());
    _SCPDB_LOG(_L("[CSCPParamDB]-> Fetching values for the column KColParamId"));
    
    if(lErr == KErrNone && lStatus) {
        do {
            lDBView.GetL();
            TInt lPID = lDBView.ColInt(iColSet->ColNo(KColParamId));
            
            if(aParamIds.Find(lPID) == KErrNotFound) {
                aParamIds.AppendL(lPID);
            }
        }
        while(lDBView.NextL());
    }
    
    _SCPDB_LOG(_L("[CSCPParamDB]-> Query execution complete..."));
    CleanupStack :: PopAndDestroy(2);
    _SCPDB_LOG(_L("[CSCPParamDB]-> ListParamsUsedByApp() <<<"));
    return KErrNone;
}
Beispiel #17
0
TInt CSCPParamDB :: ListEntriesL(RArray <TInt32>& aNumCols, RPointerArray <HBufC>& aDesCols, const TInt32 aApp) {
    _SCPDB_LOG(_L("[CSCPParamDB]-> ListEntries() >>>"));
    
    RDbView lDBView;
    CleanupClosePushL(lDBView);
    
    HBufC* lSelectQry(NULL);
    
    if(aApp == -1) {
        lSelectQry = HBufC :: NewLC(KSelectAll().Length() + 50);
        lSelectQry->Des().Format(KSelectAll);
    }
    else {
        lSelectQry = HBufC :: NewLC(KSelectWhereAppId().Length() + 30);
        lSelectQry->Des().Format(KSelectWhereAppId, aApp);
    }
    
    __LEAVE_IF_ERROR(lDBView.Prepare(iParameterDB, TDbQuery(*lSelectQry)));
    __LEAVE_IF_ERROR(lDBView.EvaluateAll());

    TInt lRet(KErrNone);
    TBool lStatus(EFalse);
    
    TRAP(lRet, lStatus = lDBView.FirstL());
    
    if(lRet == KErrNone && lStatus) {
        do {
            lDBView.GetL();

            aNumCols.AppendL(lDBView.ColInt(iColSet->ColNo(KColParamId)));
            aNumCols.AppendL(lDBView.ColInt(iColSet->ColNo(KColAppId)));
            aNumCols.AppendL(lDBView.ColInt(iColSet->ColNo(KColValueInt)));           

            TPtrC lValueDes = lDBView.ColDes16(iColSet->ColNo(KColValueDes));
            HBufC* lBuff = HBufC :: NewL(lValueDes.Length());
            lBuff->Des().Append(lValueDes);
            aDesCols.AppendL(lBuff);
        }
        while(lDBView.NextL());
    }
    
    _SCPDB_LOG(_L("[CSCPParamDB]-> ListEntries() <<<"));
    CleanupStack :: PopAndDestroy(2);
    return KErrNone;
}
// -----------------------------------------------------------------------------
// CWPInternetAPDB::DeleteFromDatabaseL
// -----------------------------------------------------------------------------
//
TBool CWPInternetAPDB::DeleteFromDatabaseL(TUint aAPId)
    {
    FLOG( _L( "[Provisioning] CWPInternetAPDB::DeleteFromDatabaseL" ) );
    TBool rowsdeleted = EFalse;
    TFileName QueryBuffer;
    QueryBuffer.Copy(_L("SELECT * FROM "));
    QueryBuffer.Append(KtxtItemlist);
    QueryBuffer.Append(_L(" WHERE "));
    QueryBuffer.Append(NCol2);
    QueryBuffer.Append(_L(" = "));
    QueryBuffer.AppendNum(aAPId);

    iItemsDatabase.Begin();

    RDbView Myview;
    // query buffer with index finds only the selected item row.
    Myview.Prepare(iItemsDatabase, TDbQuery(QueryBuffer));
    CleanupClosePushL(Myview);

    Myview.EvaluateAll();
    if( Myview.FirstL())
    {
    	if (!Myview.IsEmptyL())
        {
        // we have autoincrement in index so it should be unique
        // but just to make sure, we use 'while', instead of 'if'
        while (Myview.AtRow())
            {
            Myview.GetL();
            Myview.DeleteL();
            Myview.NextL();
            }

        iItemsDatabase.Commit();
        // compacts the databse, by physically removig deleted data.
        iItemsDatabase.Compact();
        rowsdeleted = ETrue;
        }
    }
    CleanupStack::PopAndDestroy(1); // Myview

    FLOG( _L( "[Provisioning] CWPInternetAPDB::DeleteFromDatabaseL: done" ) );
    return rowsdeleted;
    }
// -----------------------------------------------------------------------------
// CWPInternetAPDB::DeleteFromDatabaseL
// -----------------------------------------------------------------------------
//
TBool CSCOMOAdapterDb::DeleteFromDatabaseL(TUint32 aLuid)
    {

    TBool rowsdeleted = EFalse;
    TFileName sqlQuery;
	
	PrepareLuidQuery(aLuid, sqlQuery);
	

    BeginDatabaseTransaction();

    RDbView view;
    // query buffer with index finds only the selected item row.
    view.Prepare(iDatabase, TDbQuery(sqlQuery));
    CleanupClosePushL(view);

    view.EvaluateAll();
    view.FirstL();

    if (!view.IsEmptyL())
        {
        // we have autoincrement in index so it should be unique
        // but just to make sure, we use 'while', instead of 'if'
        while (view.AtRow())
            {
            view.GetL();
            view.DeleteL();
            view.NextL();
            }

        
        CommitDatabaseTransaction();
        // compacts the databse, by physically removig deleted data.
        iDatabase.Compact();
        rowsdeleted = ETrue;
        }
    CleanupStack::PopAndDestroy(1); // view


    return rowsdeleted;
    }
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
void PosLmLandmarkHandler::ReadCategoriesL(
    CPosLmLocalDbAccess& aDbAccess,
    CPosLandmark& aLandmark)
    {
    HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
    sql->Des().Format(KPosLmSqlFindUint, &KPosLmSqlAll,
        &KPosLmLandmarkCategoryTable, &KPosLmLandmarkIdCol,
        aLandmark.LandmarkId());

    RDbView view;
    aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EUpdatablePreparation, view,
        *sql);

    while (view.NextL())
        {
        view.GetL();
        aLandmark.AddCategoryL(view.ColUint32(EPosLmLccCategoryIdCol));
        }

    CleanupStack::PopAndDestroy(2, sql); //&view
    }
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
void PosLmLandmarkHandler::OpenLandmarkViewLC(
    TPosLmItemId aLandmarkId,
    RDbView& aView,
    CPosLmLocalDbAccess& aDbAccess )
    {
    HBufC* sql = HBufC::NewLC( KPosLmSqlStatementMaxLen );
    sql->Des().Format( KPosLmSqlFindUint, &KPosLmSqlAll, &KPosLmLandmarkTable,
        &KPosLmLandmarkIdCol, aLandmarkId );

    aDbAccess.PrepareViewLC( 
        CPosLmLocalDbAccess::EUpdatablePreparation, aView, *sql );

    if ( !aView.NextL() )
        {
        User::Leave( KErrNotFound );
        }
    
    CleanupStack::Pop( &aView );
    CleanupStack::PopAndDestroy( sql );
    CleanupClosePushL( aView );
    }
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
void PosLmLandmarkHandler::ReadFieldsL(
    CPosLmLocalDbAccess& aDbAccess,
    CPosLandmark& aLandmark,
    TBool aHasRequestedFields,
    const RArray<TUint>& aRequestedFields)
    {
    if (!aHasRequestedFields || aRequestedFields.Count() > 0)
        {
        HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
        sql->Des().Format(KPosLmSqlFindUint, &KPosLmSqlAll,
            &KPosLmLandmarkFieldTable, &KPosLmLandmarkIdCol,
            aLandmark.LandmarkId());

        RDbView view;
        aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EUpdatablePreparation,
            view, *sql);

        HBufC* textFieldBuffer = HBufC::NewLC(KPosLmMaxTextFieldLength);

        while (view.NextL())
            {
            view.GetL();

            TUint16 fieldType = view.ColUint16(EPosLmLfcFieldTypeCol);

            if (!aHasRequestedFields ||
                aRequestedFields.Find(fieldType) != KErrNotFound)
                {
                TPtr buffer = textFieldBuffer->Des();
                PosLmLongTextColHandler::ReadFromLongTextColumnL(
                    buffer, view, EPosLmLfcFieldStringCol);

                aLandmark.SetPositionFieldL(fieldType, *textFieldBuffer);
                }
            }

        CleanupStack::PopAndDestroy(3, sql); //&view, textFieldBuffer
        }
    }
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
EXPORT_C void PosLmLandmarkHandler::GetAllLandmarkIdsL(
    CPosLmLocalDbAccess& aDbAccess,
    TBool aUseSort,
    TBool aSortDescending,
    RArray<TPosLmItemId>& aLandmarkIds)
    {
    aLandmarkIds.Reset();

    HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);

    if (aUseSort)
        {
        sql->Des().Format(KPosLmSqlSelectOrderByString, &KPosLmLandmarkIdCol,
            &KPosLmLandmarkTable, &KPosLmNameCol);

        if (aSortDescending)
            {
            sql->Des().Append(KPosLmSqlDescOrder);
            }
        }
    else
        {
        sql->Des().Format(KPosLmSqlSelect, &KPosLmLandmarkIdCol,
            &KPosLmLandmarkTable);
        }

    RDbView view;
    aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EUpdatablePreparation, view,
        *sql, EDbCompareCollated);

    aLandmarkIds.ReserveL( view.CountL() );
    while ( view.NextL() )
        {
        view.GetL();
        aLandmarkIds.AppendL( view.ColUint32(1) );
        }

    CleanupStack::PopAndDestroy(2, sql); //&view
    }
// --------------------------------
// CNSmlRoamTable::GetItemsForIdL( TInt aProfileId )
// Return array of IAPs for profile id
// --------------------------------
//
EXPORT_C CNSmlIAPArray* CNSmlRoamTable::GetItemsForIdL( TInt aProfileId )
	{
	RDbView view;
	CleanupClosePushL( view );
	
	CNSmlIAPArray* array = new (ELeave) CArrayFixFlat<TUint32>(4);
	CleanupStack::PushL( array );
	
	IsNewItemL(view, aProfileId);
	
	view.FirstL();
		
	while (view.AtRow())
		{
		view.GetL();
		array->AppendL( view.ColUint32( iColSet->ColNo( KColIapId ) ));
		view.NextL();
		}
	
	CleanupStack::Pop(); //array
	CleanupStack::PopAndDestroy(); //view
	return array;
	}
Beispiel #25
0
/*
-------------------------------------------------------------------------------
************ internal database handling functions ****************************
-------------------------------------------------------------------------------
*/
void CExPolicy_Server::ReadStatusItemsL(void)
{
	iScreenStatus = iProtectStatus = EFalse;
	
	TFileName QueryBuffer;
	QueryBuffer.Copy(_L("SELECT * FROM "));// just get all columns & rows
	QueryBuffer.Append(KtxtStatuslist);
	
	RDbView Myview;
	Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer));
	CleanupClosePushL(Myview);
	Myview.EvaluateAll();
	Myview.FirstL();
	
	while(Myview.AtRow()) // Just delete one instance of the message           
	{	
		Myview.GetL();		
		
		TExampleItem NewItem;	
		NewItem.iIndex = Myview.ColInt(1);
		
		if(Myview.ColInt(2) > 50)
		{
			iProtectStatus = ETrue;
		}
		
 		if(Myview.ColInt(3) > 50)
		{
			iScreenStatus = ETrue;
		}
			
		Myview.NextL();
	} 
	
	CleanupStack::PopAndDestroy(1); // Myview
}
static TInt SearchForL( const TPtrC& aSearchString, RDbNamedDatabase& aDb )
	{
	_LIT( KSQLSearchStatement, "select Notes from CDs where Notes like '%S'" );
	TBuf<512> query;
	query.Format( KSQLSearchStatement, &aSearchString );

	// Display query
	_LIT( KQueryFormatter, "\r\n %S\r\n" );
	TBuf<512> msg;
	msg.Format( KQueryFormatter, &query );
	TheTest.Printf( msg );

	// create a view on the database
	RDbView view;
	// use EDbCompareCollated in order to search case-insensitive
	__LEAVE_IF_ERROR( view.Prepare( aDb, TDbQuery( query, EDbCompareCollated ) ) );
	__LEAVE_IF_ERROR( view.EvaluateAll() );

	// iterate across the row set
	TInt noOfMatches = 0;
	for ( view.FirstL(); view.AtRow(); view.NextL() )
		{
		// retrieve the row
		view.GetL();
		noOfMatches++;
		}

	// Display no of matches
	_LIT( KNoOfMatchFormatter, " Found %d matches\r\n" );
	msg.Format( KNoOfMatchFormatter, noOfMatches );
	TheTest.Printf( msg );

	// close the view
	view.Close();
	return noOfMatches;
	}
void eapol_am_wlan_authentication_symbian_c::SavePSKL(TPSKEntry& entry)
{
	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT, 
		(EAPL("eapol_am_wlan_authentication_symbian_c::SavePSKL(): this = 0x%08x\n"),
		this));
	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eapol_am_wlan_authentication_symbian_c::SavePSKL()");

	// Connect to CommDBif so that we can delete PSK entries that have no IAP associated anymore.
	CWLanSettings* wlan_settings = new(ELeave) CWLanSettings;
	CleanupStack::PushL(wlan_settings);
	
	SWLANSettings wlanSettings;

	if (wlan_settings->Connect() != KErrNone)
	{
		// Could not connect to CommDB			
		User::Leave(KErrCouldNotConnect);
	}

	// Open database
	RDbNamedDatabase db;

	TFileName aPrivateDatabasePathName;

	EapPluginTools::GetPrivatePathL(
		m_session,
		aPrivateDatabasePathName);

	aPrivateDatabasePathName.Append(KEapolDatabaseName);

	EAP_TRACE_DATA_DEBUG_SYMBIAN(("aPrivateDatabasePathName",
		aPrivateDatabasePathName.Ptr(),
		aPrivateDatabasePathName.Size()));

	User::LeaveIfError(db.Open(m_session, aPrivateDatabasePathName));	
	
	CleanupClosePushL(db);

	HBufC* sqlbuf = HBufC::NewLC(KMaxSqlQueryLength);
	TPtr sqlStatement = sqlbuf->Des();

	RDbView view;

	_LIT(KSQL, "SELECT %S, %S, %S, %S, %S FROM %S");
	
	sqlStatement.Format(KSQL, &KServiceType, &KServiceIndex, &KSSID, &KPassword, &KPSK,
		&KEapolPSKTableName);

	User::LeaveIfError(view.Prepare(db, TDbQuery(sqlStatement), TDbWindow::EUnlimited));	
	CleanupClosePushL(view);
	User::LeaveIfError(view.EvaluateAll());
	
	// Get column set so we get the correct column numbers
	CDbColSet* colSet = view.ColSetL();		
	CleanupStack::PushL(colSet);
	
	// Delete old row and also rows that have no associated IAP settings.
	if (view.FirstL())
	{
		do {
			view.GetL();

			if ((wlan_settings->GetWlanSettingsForService(view.ColUint32(colSet->ColNo(KServiceIndex)), wlanSettings) != KErrNone)
				|| (view.ColUint32(colSet->ColNo(KServiceType)) == static_cast<TUint>(entry.indexType)
					&& view.ColUint32(colSet->ColNo(KServiceIndex)) == static_cast<TUint>(entry.index)))
			{	
				// Not found or current IAP
				view.DeleteL();	
			}
			
		} while (view.NextL() != EFalse);
	}

	wlan_settings->Disconnect();
	
	view.InsertL();
	
	view.SetColL(colSet->ColNo(KServiceType), (TUint)entry.indexType);
	view.SetColL(colSet->ColNo(KServiceIndex), (TUint)entry.index);
	view.SetColL(colSet->ColNo(KSSID), entry.ssid);
	view.SetColL(colSet->ColNo(KPassword), entry.password);
	view.SetColL(colSet->ColNo(KPSK), entry.psk);	
	
	view.PutL();
	
	CleanupStack::PopAndDestroy( colSet ); // Delete colSet.	

	CleanupStack::PopAndDestroy(&view);
	CleanupStack::PopAndDestroy(sqlbuf);
	CleanupStack::PopAndDestroy(&db);
	CleanupStack::PopAndDestroy(wlan_settings);

}
/**
@SYMTestCaseID			SYSLIB-DBMS-CT-3407
@SYMTestCaseDesc		Test for defect DEF103023 - DBMS requires ReadDeviceData and WriteDeviceData capability to read from the db.
 						The current test application has no capabilities at all.
 						"C:TestDB.DB" database is a secure shared database with:
 							- no "READ" polycy (no restrictions apply to the database read operations);
 							- "WRITE" policy with "WriteUserData" capability defined;
 							- "SCHEMA" policy with "NetworkServices" capability defined;
 							- table C has no defined securoty policy, so the database security policy will be used;
 						The current test application should be able to:
 							- begin/commit/rollback a "read-only" transaction;
 						But should fail if:
 							- begin a transaction and try to modify the database within the transaction;
 						This test function asserts the test cases described above.
@SYMTestPriority		High
@SYMTestActions			Test for defect DEF103023 - DBMS requires ReadDeviceData and WriteDeviceData capability to read from the db.
@SYMTestExpectedResults Test must not fail
@SYMDEF					DEF103023
*/
void DEF103023L()
	{
	TheTest.Printf(_L("Begin a transaction. Read-only operations tested\n"));
	TInt err = TheDb.Begin();
	TEST2(err, KErrNone);
	TheTest.Printf(_L("Perform some read-only operations inside the transaction\n"));
	err = TheView.Prepare(TheDb, _L("SELECT * FROM C"));
	TEST2(err, KErrNone);
	err = TheView.EvaluateAll();
	TEST2(err, KErrNone);
	TInt cnt = TheView.CountL();
	TEST(cnt > 0);
	TBool rc = TheView.FirstL();
	TEST(rc);
	TheView.GetL();
	TInt val = TheView.ColInt32(1);
	rc = TheView.LastL();
	TEST(rc);
	rc = TheView.NextL();
	TEST(!rc);
	rc = TheView.PreviousL();
	TEST(rc);
	TheView.BeginningL();
	TheView.EndL();
	TheView.Close();
	TheTest.Printf(_L("Commit a transaction\n"));
	err = TheDb.Commit();
	TEST2(err, KErrNone);
	//
	TheTest.Printf(_L("Begin a transaction. Read-only operations tested\n"));
	err = TheDb.Begin();
	TEST2(err, KErrNone);
	err = TheView.Prepare(TheDb, _L("SELECT * FROM C"));
	TEST2(err, KErrNone);
	err = TheView.EvaluateAll();
	TEST2(err, KErrNone);
	cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();
	TheTest.Printf(_L("Rollback a transaction\n"));
	TheDb.Rollback();
	//
	TheTest.Printf(_L("Begin a transaction. Tested operations violate the database security\n"));
	err = TheDb.Begin();
	TEST2(err, KErrNone);
	err = TheView.Prepare(TheDb, _L("SELECT * FROM C"));
	TEST2(err, KErrNone);
	err = TheView.EvaluateAll();
	TEST2(err, KErrNone);
	rc = TheView.FirstL();
	TEST(rc);
	TheView.GetL();
	TheTest.Printf(_L("An attempt to update a record within the transaction\n"));
	TRAP(err, TheView.UpdateL());
	TEST2(err, KErrPermissionDenied);
	TheTest.Printf(_L("An attempt to delete a record within the transaction\n"));
	TRAP(err, TheView.DeleteL());
	TEST2(err, KErrPermissionDenied);
	TheTest.Printf(_L("An attempt to insert a record within the transaction\n"));
	TRAP(err, TheView.InsertL());
	TEST2(err, KErrPermissionDenied);
	TheView.Close();
	TheTest.Printf(_L("An attempt to modify the database schema within the transaction\n"));
	err = TheDb.Execute(_L("CREATE TABLE C2(Id INTEGER, Z INTEGER)"));
	TEST2(err, KErrPermissionDenied);
	TheTest.Printf(_L("An attempt to execute an INSERT statement within the transaction\n"));
	err = TheDb.Execute(_L("INSERT INTO C VALUES(100)"));
	TEST2(err, KErrPermissionDenied);
	TheTest.Printf(_L("An attempt to modify the database within the transaction using RDbUpdate\n"));
	RDbUpdate update;
	err = update.Execute(TheDb, _L("INSERT INTO C VALUES(200)"));
	TEST2(err, KErrPermissionDenied);
	update.Close();
	TheTest.Printf(_L("Rollback a transaction\n"));
	TheDb.Rollback();
	}
/**
@SYMTestCaseID          SYSLIB-DBMS-CT-0645
@SYMTestCaseDesc        Searching for data from a database
@SYMTestPriority        Medium
@SYMTestActions         Tests for EDbColText,EDbColLongText column type
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
static void TestSearchL( TInt aIndex )
	{
	// Default database
	_LIT( KComposer1, "Elgar" );
	_LIT( KCol1, "Artist" );
	_LIT( KCol2, "Notes" );
	_LIT( KTable, "CDs" );

	TInt err = TheFsSession.Delete( KSearchTestDbPath );
	if ( ( err != KErrNone ) && ( err != KErrNotFound ) && ( err != KErrPathNotFound ) )
		{
		__LEAVE( err );
		}

	RDbNamedDatabase db;
	CleanupClosePushL( db );
	__LEAVE_IF_ERROR( db.Create( TheFsSession, KSearchTestDbPath ) );

	//
	// Create the database table
	//
	// Create a table definition
	CDbColSet* columns = CDbColSet::NewLC();
	// add the columns
	columns->AddL( TDbCol( KCol1, EDbColText ) );
	if ( aIndex == 0 )
		columns->AddL( TDbCol( KCol2, EDbColText ) );
	else
		columns->AddL( TDbCol( KCol2, EDbColLongText ) );
	// if the column is of type "EDbColText" instead,
	// all searching is working properly
	// Create a table
	__LEAVE_IF_ERROR( db.CreateTable( KTable, *columns ) );
	// cleanup the column set
	CleanupStack::PopAndDestroy( columns );

	//
	// Add data
	//
	// create a view on the database
	_LIT( KSQLStatement, "select Artist,Notes from CDs order by Artist" );
	RDbView view;
	__LEAVE_IF_ERROR( view.Prepare( db, TDbQuery( KSQLStatement, EDbCompareNormal ) ) );
	__LEAVE_IF_ERROR( view.EvaluateAll() );

	// Get the structure of rowset
	CDbColSet* colSet = view.ColSetL();
	// insert a row
	view.InsertL();
	view.SetColL( colSet->ColNo( KCol1 ), KComposer1 ); // Artist
	// Use the stream
	// RDbColWriteStream out;
	// TDbColNo col = colSet->ColNo( KCol2 ); // Ordinal position of long column
	//
	// out.OpenLC( view, col );
	// out.WriteL( _L( "Some additional comment here." ) );
	// out.Close();
	//
	// CleanupStack::PopAndDestroy(); // out
	view.SetColL( colSet->ColNo( KCol2 ), _L( "Some additional comment here." ) );
	view.PutL();
	// close the view
	view.Close();
	delete colSet;

	//
	// Display the data
	//
	_LIT( KRowFormatter, "\r\n Artist: %S \r\n Notes: %S \r\n" );
	__LEAVE_IF_ERROR( view.Prepare( db, TDbQuery( KSQLStatement, EDbCompareNormal ) ) );
	__LEAVE_IF_ERROR( view.EvaluateAll() );

	// Get the structure of the rowset
	colSet = view.ColSetL();
	// iterate across the row set
	for ( view.FirstL(); view.AtRow(); view.NextL() )
		{
		// retrieve the row
		view.GetL();
		// while the rowset is on this row, can use a TPtrC to
		// refer to any text columns
		TPtrC artist = view.ColDes( colSet->ColNo( KCol1 ) );
		// and a stream for long columns
		RDbColReadStream in;
		TDbColNo col = colSet->ColNo( KCol2 ); // Ordinal position of long column
		TBuf<256> notes; // Buffer for out notes
		in.OpenLC( view, col );
		in.ReadL( notes, view.ColLength( col ) );
		in.Close();
		CleanupStack::PopAndDestroy(); // in
		// Display the artist and notes
		TBuf<512> msg;
		msg.Format( KRowFormatter, &artist, &notes );
		TheTest.Printf( msg );
		}
	// close the view
	view.Close();
	delete colSet;

	//
	// Search for the data
	//
	TInt result;
	result = SearchForL( _L( "Some*" ), db ); // matches
	TEST(result == 1);
	result = SearchForL( _L( "some*" ), db ); // defect causes no match, should match
	TEST(result == 1);
	result = SearchForL( _L( "*some*" ), db ); // matches
	TEST(result == 1);
	result = SearchForL( _L( "s?me*" ), db ); // matches
	TEST(result == 1);
	result = SearchForL( _L( "Some additional comment here." ), db ); // matches
	TEST(result == 1);
	result = SearchForL( _L( "some additional comment here." ), db ); // defect causes no match, should match
	TEST(result == 1);

	CleanupStack::PopAndDestroy( &db );
	}