// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
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 #2
0
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ 
void CScheduleDB::SaveToDatabaseL(CMsgStored* aData)
{	
	if(aData)
	{
		TFileName QueryBuffer;
		QueryBuffer.Copy(_L("SELECT * FROM "));
		QueryBuffer.Append(KtxtItemlist2);
		
		iItemsDatabase.Begin();

		RDbView Myview;
		Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer));
		CleanupClosePushL(Myview);

		Myview.InsertL(); 

	    if(aData->iMessage)
	    	Myview.SetColL(2,*aData->iMessage);

		Myview.PutL();  
		
		aData->iIndex = Myview.ColInt(1);// autoincrement gives us unique index.
				
		CleanupStack::PopAndDestroy(1); // Myview
		iItemsDatabase.Commit();
	}
}
Beispiel #3
0
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ 
void CScheduleDB::UpdateDatabaseL(CMsgStored* aData)
{	
	if(aData)
	{
		TFileName QueryBuffer;
		QueryBuffer.Copy(_L("SELECT * FROM "));
		QueryBuffer.Append(KtxtItemlist2);
		QueryBuffer.Append(_L(" WHERE "));
		QueryBuffer.Append(NCol0);
		QueryBuffer.Append(_L(" = "));
		QueryBuffer.AppendNum(aData->iIndex);

		iItemsDatabase.Begin();
		
		RDbView Myview;
		Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer));
		CleanupClosePushL(Myview);
		
		Myview.EvaluateAll();
		Myview.FirstL();
		
		if(Myview.AtRow())            
		{			
			Myview.UpdateL();

		    if(aData->iMessage)
		    	Myview.SetColL(2,*aData->iMessage);

			Myview.PutL();
		}
				
		CleanupStack::PopAndDestroy(1); // Myview
		iItemsDatabase.Commit();
	}
}
// -----------------------------------------------------------------------------
// CWPInternetAPDB::SaveToDatabaseL
// -----------------------------------------------------------------------------
//   
void CSCOMOAdapterDb::SaveToDatabaseL(TInt& aIndex, TUint32 aLuid,
        TInt aProfileid, TInt aRetryCount, const TDesC8& aSourceURI,
        const TDesC8& aServerid, const TDesC8& aCorrelator)
    {

    BeginDatabaseTransaction();

    TFileName sqlQuery;
    sqlQuery.Copy(_L("SELECT * FROM "));
    sqlQuery.Append(KTableAMMgmtObject);

    RDbView view;
    view.Prepare(iDatabase, TDbQuery(sqlQuery));
    CleanupClosePushL(view);

    view.InsertL();

    view.SetColL(2, aLuid);
    view.SetColL(3, aProfileid);
    view.SetColL(4, aServerid);
    view.SetColL(5, aCorrelator);
    view.SetColL(6, aSourceURI);
    view.SetColL(7, aRetryCount);

    view.PutL();

    aIndex = view.ColInt(1);// autoincrement gives us unique index.

    CleanupStack::PopAndDestroy(1); // view
    
    CommitDatabaseTransaction();

    }
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
void CExPolicy_Server::AddToValDatabase(RDbDatabase& aDatabase,const TDesC& aCode,const TDesC8& aString)
{
	TFileName QueryBuffer;
	QueryBuffer.Copy(_L("SELECT * FROM "));
	QueryBuffer.Append(KtxtVallist);

	aDatabase.Begin();

	RDbView Myview;
	Myview.Prepare(aDatabase,TDbQuery(QueryBuffer));
	CleanupClosePushL(Myview);

	Myview.InsertL(); 
		
	Myview.SetColL(2,aCode);
	
	QueryBuffer.Copy(aString);
	
	Myview.SetColL(3,QueryBuffer);

	Myview.PutL();  
		
	CleanupStack::PopAndDestroy(1); // Myview
	aDatabase.Commit();
}
void CSCOMOAdapterDb::UpdateRetryCountForLuidL(TInt aLuid, TInt aRetryCount)
{
	TFileName sqlQuery;
	
	PrepareLuidQuery(aLuid, sqlQuery);
	
	BeginDatabaseTransaction();
	
	RDbView view;
	view.Prepare(iDatabase, TDbQuery(sqlQuery));
	CleanupClosePushL(view);
	
	view.EvaluateAll();
	view.FirstL();
	
	if(view.AtRow())            
	{			
		view.UpdateL();
		view.SetColL(7, aRetryCount);		
		view.PutL();
	}
			
	CleanupStack::PopAndDestroy(1); // view
	
    CommitDatabaseTransaction();
}
// -----------------------------------------------------------------------------
// CWPInternetAPDB::SaveToDatabaseL
// -----------------------------------------------------------------------------
//   
void CWPInternetAPDB::SaveToDatabaseL(TInt& aIndex, TUint aAPId,
        TUint32 aBearerType, const TDesC& aOriginator)
    {
    FLOG( _L( "[Provisioning] CWPInternetAPDB::SaveToDatabaseL" ) );

    //If there is any existing rows for the same APID, delete those
    if (DeleteFromDatabaseL(aAPId))
        {
        iItemsDatabase.Begin();
        }

    TFileName QueryBuffer;
    QueryBuffer.Copy(_L("SELECT * FROM "));
    QueryBuffer.Append(KtxtItemlist);

    RDbView Myview;
    Myview.Prepare(iItemsDatabase, TDbQuery(QueryBuffer));
    CleanupClosePushL(Myview);

    Myview.InsertL();

    Myview.SetColL(2, aAPId);
    Myview.SetColL(3, aBearerType);
    Myview.SetColL(4, aOriginator);

    Myview.PutL();

    aIndex = Myview.ColInt(1);// autoincrement gives us unique index.

    CleanupStack::PopAndDestroy(1); // Myview
    iItemsDatabase.Commit();
    FLOG( _L( "[Provisioning] CWPInternetAPDB::SaveToDatabaseL:done" ) );
    }
// --------------------------------
// CNSmlRoamTable::AddItemL( CNSmlRoamItem& aItem )
// Adds item to IAP table
// --------------------------------
//
void CNSmlRoamTable::AddItemL( CNSmlRoamItem& aItem )
	{

	RFs fs;
	User::LeaveIfError( fs.Connect() );
	CleanupClosePushL(fs);
	
	if (SysUtil::FFSSpaceBelowCriticalLevelL(&fs, 12))
		{
		User::Leave( KErrDiskFull );
		}

	CleanupStack::PopAndDestroy(); //fs

	TBuf<KNSmlMaxSQLLength> sqlBuf;
	sqlBuf.Format( KSQLInsertQuery, aItem.iProfileId, aItem.iIAPId, aItem.iPriority );

	RDbView view;
	CleanupClosePushL( view );

	view.Prepare(iDatabase, TDbQuery(KSQLMatchQuery2), RDbView::EInsertOnly);
	view.InsertL();
	view.SetColL( iColSet->ColNo( KColProfileId ), aItem.iProfileId );
	view.SetColL( iColSet->ColNo( KColPriority ), aItem.iPriority );
	view.SetColL( iColSet->ColNo( KColIapId ), aItem.iIAPId );
	view.PutL();

	CleanupStack::PopAndDestroy(); //view

#ifdef __MODULETEST
	test.iAdded++;
#endif
	}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
EXPORT_C void PosLmLandmarkHandler::AddCategoriesToLandmarkL(
    CPosLmLocalDbAccess& aDbAccess,
    const RArray<TPosLmItemId>& aCategories,
    const TPosLmItemId& aLandmarkId)
    {
    if (aCategories.Count() > 0)
        {
        HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
        sql->Des().Format(KPosLmSqlSelect, &KPosLmSqlAll,
            &KPosLmLandmarkCategoryTable);

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

        for (TInt i = 0; i < aCategories.Count(); i++)
            {
            view.InsertL();
            view.SetColL(EPosLmLccLandmarkIdCol, aLandmarkId);
            view.SetColL(EPosLmLccCategoryIdCol, aCategories[i]);
            view.PutL();
            }

        CleanupStack::PopAndDestroy(2, sql); //&view
        }
    }
static void ViewTestL()
	{
	RDbView view;
	CleanupClosePushL(view);
	
	TheTest.Next(_L("Prepare()"));	
	TInt err = view.Prepare(TheDb1, TDbQuery(_L("SELECT * FROM ATbl")));
	TEST2(err, KErrNone);
	
	TheTest.Next(_L("Update()"));	
	TBool res = view.FirstL();
	TEST(res);
	view.GetL();
	view.UpdateL();
	view.SetColL(2, 100);
	view.SetColL(3, 200);
	view.PutL();
	
	CleanupStack::PopAndDestroy(&view);

	TheTest.Next(_L("Prepare() with an update sql"));	
	CleanupClosePushL(view);
	err = view.Prepare(TheDb1, TDbQuery(_L("UPDATE ATbl SET DATA1 = 400 WHERE ID = 0")));
	TEST2(err, KErrArgument);
	CleanupStack::PopAndDestroy(&view);
	}
Beispiel #11
0
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ 
void CScheduleDB::UpdateDatabaseL(CMsgSched* aData)
{	
	if(aData)
	{
		TFileName QueryBuffer;
		QueryBuffer.Copy(_L("SELECT * FROM "));
		QueryBuffer.Append(KtxtItemlist);
		QueryBuffer.Append(_L(" WHERE "));
		QueryBuffer.Append(NCol0);
		QueryBuffer.Append(_L(" = "));
		QueryBuffer.AppendNum(aData->iIndex);

		iItemsDatabase.Begin();
		
		RDbView Myview;
		Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer));
		CleanupClosePushL(Myview);
		
		Myview.EvaluateAll();
		Myview.FirstL();
		
		if(Myview.AtRow())            
		{			
			Myview.UpdateL();
			
			if(aData->iUnicode)
				Myview.SetColL(2,0x100);
			else
				Myview.SetColL(2,0x000);
		    
		    if(aData->iNunmber)
		    	Myview.SetColL(3,*aData->iNunmber);
		    
		    if(aData->iMessage)
		    	Myview.SetColL(4,*aData->iMessage);
			
			Myview.SetColL(5,aData->iTime);
			Myview.SetColL(6,aData->iRepeat);
			
			if(aData->iEnabled)
				Myview.SetColL(7,0x100);
			else
				Myview.SetColL(7,0x000);

			if(aData->iFlashSMS)
				Myview.SetColL(8,0x100);
			else
				Myview.SetColL(8,0x000);
				
			Myview.PutL();
		}
				
		CleanupStack::PopAndDestroy(1); // Myview
		iItemsDatabase.Commit();
	}
}
void CAlmSettingsSession::ProcessDataL(void)
{
  TInt func=Message().Function();
  _LIT(KSQL,"select id,name,cid,value from settings where cid=%u and name='%S'");
  RDbView view;
  TBuf<128> sql;
  TUint32 cid=CategoryL(Message().Ptr0());
  HBufC8* param1=ValueLC(Message().Ptr1());
  TPtrC name((const TUint16*)param1->Ptr(),param1->Length()/2);
  sql.Format(KSQL,cid,&name);
  User::LeaveIfError(view.Prepare(iServer.DbL(),TDbQuery(sql),(func==ESettingsServerRequestSet)?RDbView::EUpdatable:RDbView::EReadOnly));
  CleanupClosePushL(view);
  User::LeaveIfError(view.EvaluateAll());
  TBool first=view.FirstL();
  if(func==ESettingsServerRequestSet)
  {
    if(first) view.UpdateL();
    else view.InsertL();
    CleanupCancelPushL(view);
    if(!first)
    {
      view.SetColL(2,name);
      view.SetColL(3,cid);
    }
    HBufC8* value=ValueLC(Message().Ptr2());
    view.SetColL(4,*value);
    view.PutL();
    CleanupStack::Pop(); //view cancel
    CleanupStack::PopAndDestroy(); //value
    iServer.Notify();
  }
  else
  {
    if(!first) User::Leave(KErrNotFound);
    view.GetL();
    TInt len=view.ColSize(4);
    if(func==ESettingsServerRequestGetData)
    {
      HBufC8* data=HBufC8::NewLC(len);
      TPtr8 ptr(data->Des());
      RDbColReadStream stream;
      stream.OpenLC(view,4);
      stream.ReadL(ptr,len);
      Message().WriteL(Message().Ptr2(),ptr);
      CleanupStack::PopAndDestroy(2); //stream,data
    }
    else
    {
      TPckgC<TInt> size(len);
      Message().WriteL(Message().Ptr2(),size);
    }
  }
  CleanupStack::PopAndDestroy(2); //view,param1

}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
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
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ 
void CScheduleDB::SaveToDatabaseL(CMsgSched* aData)
{	
	if(aData)
	{
		TFileName QueryBuffer;
		QueryBuffer.Copy(_L("SELECT * FROM "));
		QueryBuffer.Append(KtxtItemlist);
		
		iItemsDatabase.Begin();

		RDbView Myview;
		Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer));
		CleanupClosePushL(Myview);

		Myview.InsertL(); 
		
		if(aData->iUnicode)
			Myview.SetColL(2,0x100);
		else
			Myview.SetColL(2,0x000);
	    
	    if(aData->iNunmber)
	    	Myview.SetColL(3,*aData->iNunmber);
	    
	    if(aData->iMessage)
	    	Myview.SetColL(4,*aData->iMessage);
		
		Myview.SetColL(5,aData->iTime);
		Myview.SetColL(6,aData->iRepeat);
		
		if(aData->iEnabled)
			Myview.SetColL(7,0x100);
		else
			Myview.SetColL(7,0x000);		

		if(aData->iFlashSMS)
			Myview.SetColL(8,0x100);
		else
			Myview.SetColL(8,0x000);
		
		Myview.PutL();  
		
		aData->iIndex = Myview.ColInt(1);// autoincrement gives us unique index.
				
		CleanupStack::PopAndDestroy(1); // Myview
		iItemsDatabase.Commit();
	}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
void PosLmLandmarkHandler::InsertFieldL(
    RDbView& view,
    const TPositionFieldId& aFieldId,
    const CPosLandmark& aLandmark)
    {
    TPtrC fieldValue;

    User::LeaveIfError(aLandmark.GetPositionField(aFieldId, fieldValue));

    view.InsertL();
    view.SetColL(EPosLmLfcLandmarkIdCol, aLandmark.LandmarkId());
    view.SetColL(EPosLmLfcFieldTypeCol, (TUint)aFieldId);
    PosLmLongTextColHandler::WriteToLongTextColumnL(fieldValue, view,
        EPosLmLfcFieldStringCol);
    view.PutL();
    }
// --------------------------------
// CNSmlRoamTable::UpdateItemL(RDbView& aView, CNSmlRoamItem& aItem )
// Updates item in the IAP table
// --------------------------------
//
void CNSmlRoamTable::UpdateItemL(RDbView& aView, CNSmlRoamItem& aItem )
	{
	
	aView.FirstL();
	aView.UpdateL();
	
	aView.SetColL( iColSet->ColNo( KColProfileId ), aItem.iProfileId );
	aView.SetColL( iColSet->ColNo( KColPriority ), aItem.iPriority );
	aView.SetColL( iColSet->ColNo( KColIapId ), aItem.iIAPId );

	aView.PutL();

#ifdef __MODULETEST	
	test.iUpdated++;
#endif
	}
Beispiel #17
0
/*
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
*/
TInt CExPolicy_Server::UpdateStatusL(TBool& aValue, TBool aProtect)
{	
	TInt ErrRet(KErrNone);
	
	TRAP(ErrRet,
	DeleteStatusInfoL();

	if(aProtect)
	{
		iProtectStatus = aValue;
	}
	else
	{
		iScreenStatus = aValue;
	}

	TFileName QueryBuffer;
	QueryBuffer.Copy(_L("SELECT * FROM "));
	QueryBuffer.Append(KtxtStatuslist);
	
	iItemsDatabase.Begin();
	
	RDbView Myview;
	Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer));
	CleanupClosePushL(Myview);
	
	Myview.EvaluateAll();
	Myview.FirstL();
	
	Myview.InsertL(); 
		
	if(iProtectStatus)
		Myview.SetColL(2,0x100);
	else
		Myview.SetColL(2,0x000);
	
	if(iScreenStatus)
		Myview.SetColL(3,0x100);
	else
		Myview.SetColL(3,0x000);

	Myview.PutL(); 
			
	CleanupStack::PopAndDestroy(1); // Myview
	iItemsDatabase.Commit();
	);
Beispiel #18
0
// ---------------------------------------------------------------------------
// CFotaDB::AddPackageStateL
// Adds state to db
// ---------------------------------------------------------------------------
void CFotaDB::AddPackageStateL(const TPackageState& aState,
        const TDesC8& aPkgURL)
    {
    FLOG(_L("  CFotaDB::AddPackageStateL   >>"));
    TInt err;
    RDbView view;
    CleanupClosePushL(view);
    TPackageState pkgstate(aState);
    pkgstate.iResult = -1; // result should be -1 if no Execs have been done
    err = view.Prepare(iStateDB, TDbQuery(KSelectAll), RDbView::EInsertOnly);
    __LEAVE_IF_ERROR(err);
    FLOG(_L("  CFotaDB::AddPackageStateL   inserting. pkgid:%d result:%d  state:%d"),
            pkgstate.iPkgId, pkgstate.iResult, pkgstate.iState);
    view.InsertL();
    StateToRowL(pkgstate, aPkgURL, view);
    view.PutL();
    CleanupStack::PopAndDestroy(); //view
    FLOG(_L("  CFotaDB::AddPackageStateL   <<"));
    }
// -----------------------------------------------------------------------------
// PosLmIconHandler::AddIconPathL
//
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
void PosLmIconHandler::AddIconPathL(
    CPosLmLocalDbAccess& aDbAccess,
    const TDesC& aIconPath,
    TUint32& aIconPathId)
    {
    HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
    sql->Des().Format(KPosLmSqlSelect, &KPosLmSqlAll, &KPosLmIconTable);

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

    view.InsertL();
    PosLmLongTextColHandler::WriteToLongTextColumnL(aIconPath, view,
        EPosLmIcIconPathCol);
    view.PutL();

    aIconPathId = view.ColUint32(EPosLmIcIconIdCol);

    CleanupStack::PopAndDestroy(2, sql); //&view
    }
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
void PosLmLandmarkHandler::AddBasicLandmarkInfoL(
    CPosLmLocalDbAccess& aDbAccess,
    CPosLandmark& aLandmark)
    {
    TPtrC iconPath;
    TInt iconIndex;
    TInt maskIndex;
    TUint32 iconPathId = 0;

    // Fetch icon path id if the landmark has an icon.
    if (aLandmark.GetIcon(iconPath, iconIndex, maskIndex) == KErrNone)
        {
        PosLmIconHandler::GetIconPathIdL(aDbAccess, iconPath, iconPathId);
        }

    HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
    sql->Des().Format(KPosLmSqlSelect, &KPosLmSqlAll, &KPosLmLandmarkTable);

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

    view.InsertL();

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

    view.PutL();

    // Fetch and set the landmark id
    PosLmImplExtension::SetLandmarkIdL(aLandmark,
        view.ColUint32(EPosLmLcLandmarkIdCol));

    CleanupStack::PopAndDestroy(2, sql); //&view
    }
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-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 );
	}
void eap_am_type_securid_symbian_c::store_authentication_timeL()
{
	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
	
	EAP_TRACE_DEBUG(m_am_tools, 
		TRACE_FLAGS_DEFAULT, (
		EAPL("eap_am_type_securid_symbian_c::store_authentication_timeL: EAP-tunneling type=0xfe%06x%08x\n"),
		m_tunneling_type.get_vendor_id(),
		m_tunneling_type.get_vendor_type()));	

	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
	TPtr sqlStatement = buf->Des();
	
	// Query all the relevant parameters
	_LIT(KSQLQuery, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
	
	if (m_eap_type == eap_type_generic_token_card)
	{
		sqlStatement.Format(
			KSQLQuery,
			&KGTCLastFullAuthTime,
			&KGtcTableName,
			&KServiceType,
			m_index_type, 
			&KServiceIndex,
			m_index,
			&KTunnelingTypeVendorId,
			m_tunneling_type.get_vendor_id(),
			&KTunnelingType, 
			m_tunneling_type.get_vendor_type());
	}
	else
	{
		// Secure ID is not supported at the moment.
		// Leave with error.

		CleanupStack::PopAndDestroy(buf); // Delete buf.
		User::Leave(KErrNotSupported);		
	}

	RDbView view;
	// Evaluate view
	User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
	CleanupClosePushL(view);
	
	User::LeaveIfError(view.EvaluateAll());
	
	// Get the first (and only) row for updation.
	view.FirstL();
	view.UpdateL();
	
	// Get column set so we get the correct column numbers
	CDbColSet* colSet = view.ColSetL();
	CleanupStack::PushL(colSet);

	// Get the current universal time.
	TTime currentTime;
	currentTime.UniversalTime();
		
#if defined(_DEBUG) || defined(DEBUG)	
	
	TDateTime currentDateTime = currentTime.DateTime();
	
	EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT,
	(EAPL("eap_am_type_securid_symbian_c::store_authentication_time, %2d-%2d-%4d : %2d-%2d-%2d-%d\n"), 
	currentDateTime.Day()+1, currentDateTime.Month()+1,currentDateTime.Year(), currentDateTime.Hour(),
	currentDateTime.Minute(), currentDateTime.Second(), currentDateTime.MicroSecond()));

#endif

	TInt64 fullAuthTime = currentTime.Int64();
	
	view.SetColL(colSet->ColNo(KGTCLastFullAuthTime), fullAuthTime);

	view.PutL();	

	CleanupStack::PopAndDestroy(colSet); // Delete colSet.
	CleanupStack::PopAndDestroy(&view); // Close view.
	CleanupStack::PopAndDestroy(buf); // Delete buf.

	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);			
}