コード例 #1
0
// ---------------------------------------------------------------------------
// CLbtDbOperationAO::ExecuteSyncQuery
// ---------------------------------------------------------------------------
//
TInt CLbtDbOperationAO::ExecuteSyncQuery(
    RDbView& aView,
    TDesC& aQuery)
{
    FUNC_ENTER("CLbtDbOperationAO::ExecuteSyncQuery");
    TInt err = aView.Prepare( iDb, TDbQuery(aQuery, EDbCompareFolded),KDbUnlimitedWindow );
    // This should evaluate the query fully
    if ( err == KErrNone )
    {
        err = aView.EvaluateAll();
    }
    return err;
}
コード例 #2
0
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0018
@SYMTestCaseDesc Open table test.
				 This test app has no capabilities and it is restricted to be able to
				 open tables B and C in read-only mode.
@SYMTestPriority High
@SYMTestActions  Open table test.
@SYMTestExpectedResults The test must not fail.
@SYMREQ REQ2429
                 DBMS shall provide an API to apply security policies to database tables.
*/
static void Test1L()
	{
	TheTest.Printf(_L("An attempt to open tables in update/insert mode\n"));
	//The test must fail, because the test app cannot satisfy table A, B, C, policy W.
	TInt err = TheTbl.Open(TheDb, KTblNameA);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameB);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameC);
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("An attempt to open tables in read-only mode\n"));
	//The test must pass for table B & C, but the test app cannot satisfy table A, policy R.
	err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EReadOnly);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TheTbl.Close();
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TheTbl.Close();

	TheTest.Printf(_L("An attempt to read tables\n"));
	//The test must pass for table B & C, but the test app cannot satisfy table A, policy R.
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM A")));
	TEST2(err, KErrPermissionDenied);
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM B")));
	TEST2(err, KErrNone);
	TInt cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM C")));
	TEST2(err, KErrNone);
	cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();
	}
コード例 #3
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;   
}
コード例 #4
0
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0011
@SYMTestCaseDesc SQL tests. The caller has a set of capabilities which satisfy database's
                 schema security policy only. The test checks that the capapbility checking
				 on the DBMS server side works properly. Some of the SQL statements won't be
				 executed and the returned error will be KErrPermisssionDenied.
@SYMTestPriority High
@SYMTestActions  Attempts to execute various INSERT/UPDATE/SELECT SQL statements.
@SYMTestExpectedResults The test must not fail.
@SYMREQ REQ2429
                 DBMS shall provide an API to apply security policies to database tables.
*/
static void TblSqlL()
	{
	TheTest.Printf(_L("SELECT SQL\n"));
	//The test must fail, because the test app cannot satisfy table A, policy R.
	TInt err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM A")));
	TEST2(err, KErrPermissionDenied);
	//The test must pass, because table B has no R policy.
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM B")));
	TEST2(err, KErrNone);
	TheView.Close();
	//The test must pass, because table C has no R policy.
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM C")));
	TEST2(err, KErrNone);
	TheView.Close();

	TheTest.Printf(_L("INSERT/UPDATE SQL\n"));
	//The test must fail, because the test app cannot satisfy table A, policy W.
	err = TheDb.Execute(_L("INSERT INTO A (DATA2) VALUES(45)"));
	TEST2(err, KErrPermissionDenied);
	//The test must fail, because the test app cannot satisfy table B, policy W.
	err = TheDb.Execute(_L("INSERT INTO B (DATA2) VALUES(45)"));
	TEST2(err, KErrPermissionDenied);
	//The test must fail, because the test app cannot satisfy table C, policy W.
	err = TheDb.Execute(_L("INSERT INTO C (DATA2) VALUES(45)"));
	TEST2(err, KErrPermissionDenied);

	//The test must fail, because the test app cannot satisfy table A, policy W.
	err = TheDb.Execute(_L("UPDATE A SET DATA2=56 WHERE ID = 0"));
	TEST2(err, KErrPermissionDenied);
	//The test must fail, because the test app cannot satisfy table B, policy W.
	err = TheDb.Execute(_L("UPDATE B SET DATA2=56 WHERE ID = 0"));
	TEST2(err, KErrPermissionDenied);
	//The test must fail, because the test app cannot satisfy table C, policy W.
	err = TheDb.Execute(_L("UPDATE C SET DATA2=56 WHERE ID = 0"));
	TEST2(err, KErrPermissionDenied);
	}
コード例 #5
0
ファイル: MsgDataBase.cpp プロジェクト: DrJukka/Symbian_Codes
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ 
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
}
コード例 #6
0
ファイル: MsgDataBase.cpp プロジェクト: DrJukka/Symbian_Codes
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ 
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();
	}
}
コード例 #7
0
ファイル: MsgDataBase.cpp プロジェクト: DrJukka/Symbian_Codes
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ 
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->iNunmber)
		    	Myview.SetColL(3,*aData->iNunmber);
		    
		    if(aData->iName)
		    	Myview.SetColL(4,*aData->iName);
			
			Myview.SetColL(5,aData->iTime);
			Myview.SetColL(6,aData->iRepeat);
			
			if(aData->iEnabled)
				Myview.SetColL(7,0x100);
			else
				Myview.SetColL(7,0x000);
				
			Myview.PutL();
		}
				
		CleanupStack::PopAndDestroy(1); // Myview
		iItemsDatabase.Commit();
	}
}
コード例 #8
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();
	);
コード例 #9
0
TUint32 CAlmSettingsSession::CategoryL(const TAny* aSrc)
{
  _LIT(KSQL,"select id from categories where name='%S'");
  RDbView view;
  TBuf<128> sql;
  HBufC8* param0=ValueLC(aSrc);
  TPtrC name((const TUint16*)param0->Ptr(),param0->Length()/2);
  sql.Format(KSQL,&name);
  User::LeaveIfError(view.Prepare(iServer.DbL(),TDbQuery(sql),RDbView::EReadOnly));
  CleanupClosePushL(view);
  User::LeaveIfError(view.EvaluateAll());
  if(!view.FirstL()) User::Leave(KErrNotFound);
  view.GetL();
  TUint32 cid=view.ColUint32(1);
  CleanupStack::PopAndDestroy(2); //view,param1
  return cid;
}
コード例 #10
0
/**
Helper function. Get the next available itemId for the item.
Reads all existing ItemIds for the specified DscId, then calculates last+1
or first-1 depending on aPos. Will never return 0 as its reserved to mean
not yet persistent.
*/
TInt CDscDatabase::GetNextItemIdL(TDscPosition aPos, const TUid& aDscId) const
	{	
	RDbView view;
	CleanupClosePushL(view);
	RBuf sqlCmd;
	CleanupClosePushL(sqlCmd);
	
	sqlCmd.CreateL(KSqlQueryAllItemIdsLength);
	sqlCmd.Format(KSqlQueryAllItemIds, &KItemIdCol, &KItemTable,&KDscIdCol, aDscId, &KItemIdCol );

	DebugPrint(sqlCmd);
	
	User::LeaveIfError(view.Prepare(iDatabase, sqlCmd));
	User::LeaveIfError(view.EvaluateAll());  		
	CleanupStack::PopAndDestroy(&sqlCmd);
	
	TInt nextId = 1; //add first item with id=1 and reserve 0 to mean "not yet persistent"
	if (aPos==ELast && view.LastL())
		{
		//add at ELast: pos =max of itemId+1
		view.GetL();
		nextId = view.ColInt(1);
		if(KMaxTInt == nextId)
			{
			User::Leave(KErrOverflow);
			}
		//increase, make sure to not use 0 as itemid in the database
		nextId = (-1==nextId) ? (nextId+2) : (nextId+1);
		}		
	else if (aPos==EFirst && view.FirstL())
		{
		//add at EFirst: pos=min of itemId-1	
		view.GetL();
		nextId = view.ColInt(1);
		if(KMinTInt == nextId)
			{
			User::Leave(KErrUnderflow);
			}
		//decrease, but reserve 0 to mean "not yet persistent"
		nextId = (1==nextId) ? (nextId-2) : (nextId-1);
		}
	
	CleanupStack::PopAndDestroy(&view);
	return nextId;
	}
コード例 #11
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;
}
コード例 #12
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;
}
コード例 #13
0
// -----------------------------------------------------------------------------
// 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;
    }
コード例 #14
0
ファイル: FotaDB.cpp プロジェクト: kuailexs/symbiandump-mw3
// ---------------------------------------------------------------------------
// 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   <<"));
    }
コード例 #15
0
void InsertStatsTableL()
	{
	RDbView view;
	TInt err = view.Prepare(TheDatabase, _L("select * from STATS"), view.EInsertOnly);
	TEST2(err, KErrNone);
	TheRowSet = view;	

	CDbColSet* colSet = TheRowSet.ColSetL();
	const TInt KCategoryIdIdx = colSet->ColNo(KCategoryId);
	const TInt KTrackCntIdx = colSet->ColNo(KNoOfTracks);
	const TInt KMarkedToPlayCntIdx = colSet->ColNo(KNoMarked2Play);
	const TInt KUnmarkedToPlayCntIdx = colSet->ColNo(KNoUnmarked2Play);
	const TInt KAutoStartCntIdx = colSet->ColNo(KNoAutostart);
	const TInt KManualStartCntIdx = colSet->ColNo(KNoManualStart);
	const TInt KSizeMusicFilesIdx = colSet->ColNo(KSizeOfMusicFiles);
	delete colSet;

	TInt default_Stat = 0;

	err = TheDatabase.Begin();
	TEST2(err, KErrNone);
	
	for (TInt ii=0;ii<KStatsRecordCount;++ii)
		{
		TheRowSet.InsertL();
		TheRowSet.SetColL(KCategoryIdIdx, ii);
		TheRowSet.SetColL(KTrackCntIdx,default_Stat);
		TheRowSet.SetColL(KMarkedToPlayCntIdx,default_Stat);
		TheRowSet.SetColL(KUnmarkedToPlayCntIdx,default_Stat);
		TheRowSet.SetColL(KAutoStartCntIdx,default_Stat);
		TheRowSet.SetColL(KManualStartCntIdx,default_Stat);
		TheRowSet.SetColL(KSizeMusicFilesIdx,default_Stat);
		TheRowSet.PutL();
		}

	err = TheDatabase.Commit();
	TEST2(err, KErrNone);
	
	//err = TheDatabase.Compact();
	//TEST2(err, KErrNone);

	TheRowSet.Close();	
	}
コード例 #16
0
//Check the existance of a DSC	
TBool CDscDatabase::DscExistsL(const TUid& aDscId) const
	{
	RDbView view;
	CleanupClosePushL(view);

	RBuf sqlCmd;
	CleanupClosePushL(sqlCmd);
	sqlCmd.CreateL(KSqlSelectDscLength);

	sqlCmd.Format(KSqlSelectDsc, &KDscIdCol, &KDscTable, &KDscIdCol, aDscId);
	DebugPrint(sqlCmd);
	User::LeaveIfError(view.Prepare(iDatabase, sqlCmd));
	User::LeaveIfError(view.EvaluateAll());  
	const TBool dscExists = !view.IsEmptyL(); 
	
	CleanupStack::PopAndDestroy(&sqlCmd);
	CleanupStack::PopAndDestroy(&view);
	
	return (dscExists);
	}
コード例 #17
0
// -----------------------------------------------------------------------------
// 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;
    }
コード例 #18
0
void SelectTracksL(TInt aCount, RArray<TInt>& aTracks)
	{
	TUint32 fc = User::FastCounter();
	RDbView view;
	TUint32 fc2 = User::FastCounter();
	TInt err = view.Prepare(TheDatabase, _L("select id from TRACKS"), view.EReadOnly);
	TEST2(err, KErrNone);
	PrintFcDiffAsUs(_L("###\"Prepare()\",time=%d us\r\n"), CalcTickDiff(fc2, User::FastCounter()));
	fc2 = User::FastCounter();
	err = view.EvaluateAll();
	TEST2(err, KErrNone);
	PrintFcDiffAsUs(_L("###\"EvaluateAll()\",time=%d us\r\n"), CalcTickDiff(fc2, User::FastCounter()));
	TheRowSet = view;

	TUint32 diff1 = 0, diff2 = 0;
	TInt count = 0;	
	while(count < aCount)
		{
		fc2 = User::FastCounter();
		if(!TheRowSet.NextL())
			{
			break;	
			}
		diff1 += CalcTickDiff(fc2, User::FastCounter());	
		fc2 = User::FastCounter();
		TheRowSet.GetL();
		diff2 += CalcTickDiff(fc2, User::FastCounter());	
		aTracks.Append(TheRowSet.ColInt(1));
		++count;
		}
	TEST2(count, aCount);
	PrintFcDiffAsUs(_L("###\"Total NextL()\",time=%d us\r\n"), diff1);
	PrintFcDiffAsUs(_L("###\"Total GetL()\",time=%d us\r\n"), diff2);
	
	fc2 = User::FastCounter();
	TheRowSet.Close();	
	PrintFcDiffAsUs(_L("###\"Close()\",time=%d us\r\n"), CalcTickDiff(fc2, User::FastCounter()));
	PrintFcDiffAsUs(_L("###\"SELECT FROM TRACKS\",time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
	}
コード例 #19
0
ファイル: MsgDataBase.cpp プロジェクト: DrJukka/Symbian_Codes
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ 
void CScheduleDB::DeleteFromDatabaseL(TInt& aIndex,const TBool& aMessage)
{	
	TFileName QueryBuffer;
	QueryBuffer.Copy(_L("SELECT * FROM "));
	
	if(aMessage)
		QueryBuffer.Append(KtxtItemlist2);
	else
		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();
}
コード例 #20
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
}
コード例 #21
0
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;
	}
コード例 #22
0
void eapol_am_wlan_authentication_symbian_c::RetrievePSKL(TPSKEntry& entry)
{
	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT, 
		(EAPL("eapol_am_wlan_authentication_symbian_c::RetrievePSKL(): this = 0x%08x\n"),
		this));
	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eapol_am_wlan_authentication_symbian_c::RetrievePSKL()");

	// Open database
	RDbNamedDatabase db;

	TFileName aPrivateDatabasePathName;

	EapPluginTools::GetPrivatePathL(
		m_session,
		aPrivateDatabasePathName);

	aPrivateDatabasePathName.Append(KEapolDatabaseName);

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

	TInt error = db.Open(m_session, aPrivateDatabasePathName);

	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT, 
		(EAPL("eapol_am_wlan_authentication_symbian_c::RetrievePSKL(): db.Open(), error = %d\n"),
		 error));

	User::LeaveIfError(error);
	
	CleanupClosePushL(db);

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

	RDbView view;

	CleanupClosePushL(view);

	_LIT(KSQL, "SELECT %S, %S, %S, %S, %S FROM %S WHERE %S=%d AND %S=%d");

	sqlStatement.Format(KSQL, &KServiceType, &KServiceIndex, &KSSID, &KPassword, &KPSK,
		&KEapolPSKTableName, &KServiceType, entry.indexType, &KServiceIndex, entry.index);
		
	User::LeaveIfError(view.Prepare(db, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
	User::LeaveIfError(view.EvaluateAll());	

	TInt rows = view.CountL();
	
	if (rows == 0)
	{
		// No saved PSK
		User::Leave(KErrNotFound);
	}
	view.FirstL();
	view.GetL();

	entry.ssid.Copy(view.ColDes8(3));
	entry.password.Copy(view.ColDes8(4));
	entry.psk.Copy(view.ColDes8(5));

	CleanupStack::PopAndDestroy(&view);
	CleanupStack::PopAndDestroy(sqlbuf);
	CleanupStack::PopAndDestroy(&db);
}
コード例 #23
0
TInt eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL()
	{

	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): m_index_type=%d, m_index=%d, m_tunneling_type=0xfe%06x%08x\n"),
		m_index_type,
		m_index,
		m_tunneling_type.get_vendor_id(),
		m_tunneling_type.get_vendor_type()));

	TInt status = KErrNone;
	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
	TPtr sqlStatement = buf->Des();
	
	// Query all the relevant parameters
	_LIT(KSQLQuery, "SELECT %S, %S, %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
	
	sqlStatement.Format(
		KSQLQuery,
		&cf_str_EAP_GTC_passcode_prompt_literal,
		&cf_str_EAP_GTC_identity_literal,
		&cf_str_EAP_GTC_passcode_literal,
		&KGtcTableName,
		&KServiceType,
		m_index_type, 
		&KServiceIndex,
		m_index,
		&KTunnelingTypeVendorId,
		m_tunneling_type.get_vendor_id(),
		&KTunnelingType, 
		m_tunneling_type.get_vendor_type());
	

	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): Reads database\n")));

	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
	view.FirstL();
	view.GetL();
	
	// Get column set so we get the correct column numbers
	CDbColSet* colSet = view.ColSetL();
	CleanupStack::PushL(colSet);

	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): Reads database\n")));

	TPtrC username = view.ColDes(colSet->ColNo( cf_str_EAP_GTC_identity_literal ) );

	EAP_TRACE_DATA_DEBUG(
		m_am_tools,
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): username"),
		username.Ptr(),
		username.Size()));

	TPtrC password = view.ColDes(colSet->ColNo( cf_str_EAP_GTC_passcode_literal ) );

	EAP_TRACE_DATA_DEBUG(
		m_am_tools,
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): password"),
		password.Ptr(),
		password.Size()));

	TUint prompt = view.ColUint(colSet->ColNo(cf_str_EAP_GTC_passcode_prompt_literal));

	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): prompt=%d\n"),
		prompt));


	if ((EEapDbFalse != prompt)
		 || (username.Size() == 0) 
		 || (password.Size() == 0))
		{

		if (username.Size() == 0)
			{
			m_dialog_data_ptr->iUsername.Zero();
			}
		else
			{
			m_dialog_data_ptr->iUsername.Copy(username);
			}

		status = KErrCancel;
		}
	else
		{
		status = KErrNone;	
		m_dialog_data_ptr->iUsername.Copy(username);
		m_dialog_data_ptr->iPassword.Copy(password);
		}
		
	CleanupStack::PopAndDestroy(colSet); // Delete colSet.
	CleanupStack::PopAndDestroy(&view); // Close view.
	CleanupStack::PopAndDestroy(buf); // Delete buf.
		
	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): status=%d\n"),
		status));

	return status;
	}
コード例 #24
0
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);

}
コード例 #25
0
/**
@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();
	}
コード例 #26
0
void eapol_am_wlan_authentication_symbian_c::read_configureL(
	const TDesC& aDbName,
	const TDesC& aTableName,
	eap_config_string field,
	const u32_t /*field_length*/,
	eap_variable_data_c * const data)
{	
	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT, 
		(EAPL("eapol_am_wlan_authentication_symbian_c::read_configureL(): %s, this = 0x%08x => 0x%08x\n"),
		 (m_is_client == true) ? "client": "server",
		 this,
		 dynamic_cast<abs_eap_base_timer_c *>(this)));
	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, TRACE_FLAGS_DEFAULT, "returns: eapol_am_wlan_authentication_symbian_c::read_configureL()");

	// Open database
	RDbNamedDatabase db;

	TInt error = db.Open(m_session, aDbName);

	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT, 
		(EAPL("eapol_am_wlan_authentication_symbian_c::read_configureL(): db.Open(), error = %d\n"),
		 error));

	User::LeaveIfError(error);
	
	CleanupClosePushL(db);


	// Create a buffer for the ascii strings - initialised with the argument
	HBufC8* asciibuf = HBufC8::NewLC(128);
	TPtr8 asciiString = asciibuf->Des();
	asciiString.Copy(reinterpret_cast<const unsigned char *>(field));
		
	// Buffer for unicode parameter
	HBufC* unicodebuf = HBufC::NewLC(128);
	TPtr unicodeString = unicodebuf->Des();
	
	// Convert to unicode 
	unicodeString.Copy(asciiString);

	// Now do the database query
	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
	TPtr sqlStatement = buf->Des();
	_LIT(KSQLQueryRow, "SELECT %S FROM %S");
	sqlStatement.Format( KSQLQueryRow, &unicodeString, &aTableName );
	
	RDbView view;
	User::LeaveIfError(view.Prepare(db, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
	CleanupClosePushL(view);
	User::LeaveIfError(view.EvaluateAll());	
	if (view.FirstL())
	{
		eap_status_e status(eap_status_process_general_error);
		view.GetL();		
		switch (view.ColType(1))
		{
		case EDbColText:				
			{
				unicodeString = view.ColDes(1);
				// Convert to 8-bit
				asciiString.Copy(unicodeString);
				if (asciiString.Size() > 0)
				{
					status = data->set_copy_of_buffer(asciiString.Ptr(), asciiString.Size());
					if (status != eap_status_ok)
					{
						User::Leave(m_am_tools->convert_eapol_error_to_am_error(
							EAP_STATUS_RETURN(m_am_tools, status)));
					}
				} 
				else 
				{
					// Empty field. Do nothing...data remains invalid and the stack knows what to do hopefully.
					break;
				}
			}
			break;
		case EDbColUint32:
			{
				TUint value;
				value = view.ColUint32(1);
				status = data->set_copy_of_buffer((const unsigned char *) &value, sizeof(value));
				if (status != eap_status_ok)
				{
					User::Leave(m_am_tools->convert_eapol_error_to_am_error(
						EAP_STATUS_RETURN(m_am_tools, status)));
				}
			}
			break;
		default:
			EAP_TRACE_DEBUG(
				m_am_tools,
				TRACE_FLAGS_DEFAULT,
				(EAPL("ERROR: read_configureL: Unexpected column type.\n")));
			User::Panic(_L("EAPOL"), 1);			
		}
	} 
	else 
	{
		// Could not find parameter
		EAP_TRACE_DEBUG(
			m_am_tools,
			TRACE_FLAGS_DEFAULT,
			(EAPL("ERROR: read_configureL: Could not find configuration parameter.\n")));
		User::Leave(m_am_tools->convert_eapol_error_to_am_error(
							EAP_STATUS_RETURN(m_am_tools, eap_status_not_found)));
	}		
	
	// Close database
	CleanupStack::PopAndDestroy(&view);
	CleanupStack::PopAndDestroy(buf);
	CleanupStack::PopAndDestroy(unicodebuf);
	CleanupStack::PopAndDestroy(asciibuf);
	CleanupStack::PopAndDestroy(&db);


	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
}
コード例 #27
0
void InsertTrackTableL()
	{	
	HBufC* randomDataBuf = HBufC::NewLC(KTestBlobSize);
	TPtr randomData(randomDataBuf->Des());
	FillRandomData(randomData);
	
	RDbView view;
	TInt err = view.Prepare(TheDatabase, _L("select * from TRACKS"), view.EInsertOnly);
	TEST2(err, KErrNone);
	TheRowSet = view;	
	
	CDbColSet* colSet = TheRowSet.ColSetL();
	const TInt KIdIdx = colSet->ColNo(KId);
	const TInt KLastNameIdx = colSet->ColNo(KLastName);
	const TInt KFirstNameIdx = colSet->ColNo(KFirstName);
	const TInt KTitleIdx = colSet->ColNo(KTitle);
	const TInt KDownloadSiteIdx = colSet->ColNo(KDownloadSite);
	const TInt KBandNameIdx = colSet->ColNo(KBandName);
	const TInt KOriginIdx = colSet->ColNo(KOrigin);
	const TInt KAutoStartIdx = colSet->ColNo(KAutoStart);
	const TInt KInitVolumeIdx = colSet->ColNo(KInitVolume);
	const TInt KMarkedToPlayIdx = colSet->ColNo(KMarked2Play);
	const TInt KCategoryIdIdx = colSet->ColNo(KCategoryId);
	//const TInt KMusicFileIdx = colSet->ColNo(KMusicFile);
	delete colSet;
	colSet = NULL;

	err = TheDatabase.Begin();
	TEST2(err, KErrNone);
	
	for (TInt ii=1;ii<=KTrackRecordCount;++ii)
		{
		TheRowSet.InsertL();
		TheRowSet.SetColL(KIdIdx, ii);
		TheRowSet.SetColL(KLastNameIdx, _L("Dummy"));
		TheRowSet.SetColL(KFirstNameIdx,_L("Dummy"));
		TheRowSet.SetColL(KTitleIdx,_L("Dummy"));
		TheRowSet.SetColL(KDownloadSiteIdx,_L("Dummy"));
		TheRowSet.SetColL(KBandNameIdx,_L("Dummy"));
		TheRowSet.SetColL(KOriginIdx,_L("Dummy"));
		TheRowSet.SetColL(KAutoStartIdx,(ii%2));
		TheRowSet.SetColL(KInitVolumeIdx,(ii%2));
		TheRowSet.SetColL(KMarkedToPlayIdx,(ii%2));
		TheRowSet.SetColL(KCategoryIdIdx,(ii%KCategoryRecordCount));

		//RDbColWriteStream musicfile;
		//musicfile.OpenLC(TheRowSet, KMusicFileIdx);
		//musicfile.WriteL(randomData,KTestBlobSize);
		//musicfile.CommitL();
		//CleanupStack::PopAndDestroy(&musicfile);

		TheRowSet.PutL();
		}

	err = TheDatabase.Commit();
	TEST2(err, KErrNone);

	//err = TheDatabase.Compact();
	//TEST2(err, KErrNone);

	TheRowSet.Close();	

	////////////////////////////////////////////////////////////////////////////////////////////////

	err = view.Prepare(TheDatabase, _L("select * from TRACKS2"), view.EInsertOnly);
	TEST2(err, KErrNone);
	TheRowSet = view;	
	
	colSet = TheRowSet.ColSetL();
	const TInt KIdIdx2 = colSet->ColNo(KId);
	const TInt KMusicFileIdx2 = colSet->ColNo(KMusicFile);
	delete colSet;

	err = TheDatabase.Begin();
	TEST2(err, KErrNone);

	for (TInt ii=1;ii<=KTrackRecordCount;++ii)
		{
		TheRowSet.InsertL();
		TheRowSet.SetColL(KIdIdx2, ii);
		
		RDbColWriteStream musicfile;
		musicfile.OpenLC(TheRowSet, KMusicFileIdx2);
		musicfile.WriteL(randomData,KTestBlobSize);
		musicfile.CommitL();
		CleanupStack::PopAndDestroy(&musicfile);
		
		TheRowSet.PutL();
		}

	err = TheDatabase.Commit();
	TEST2(err, KErrNone);

	//err = TheDatabase.Compact();
	//TEST2(err, KErrNone);

	TheRowSet.Close();	

	CleanupStack::PopAndDestroy(randomDataBuf);
	}
コード例 #28
0
// ---------------------------------------------------------------------------
// CIRNmsLogDb:AddNmsLogStartL()
// adds the NmsLog log entry into data base
// ---------------------------------------------------------------------------
//
void CIRNmsLogDb::AddNmsLogStartL( CIRNmsLogger& aNmsLog )
    {
    IRLOG_DEBUG( "CIRNmsLogDb::AddNmsLogStartL" );
    OpenDbL();
    RDbTable nmsLogtable;
    TInt error=nmsLogtable.Open( iNmsLogDb, KNmsLogTable, nmsLogtable.
        EUpdatable );
    CleanupClosePushL( nmsLogtable );
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    
    //! arrange the presets in incresing order of index
    nmsLogtable.SetIndex( KNmsLogIndex );
    nmsLogtable.Reset();

    //if NmsLog log is greater or equal to than 5
    if ( nmsLogtable.CountL() >= KMaxNoNmsLog )
        {
        //first row is selected
        nmsLogtable.FirstL();
        //the current row is selected
        nmsLogtable.GetL();
        //delete that entry
        nmsLogtable.DeleteL();
        }    
    CleanupStack::PopAndDestroy( &nmsLogtable );
    //Algorithm : else condition need not handle seperatly
    //Algorithm : add NmsLogid and informations like
    //starttime,connectedfrom,NmsLogid,connectiontype,channelid
    //currentnetwork,homenetwork,NmsLogtable 
    //Algorithm: if no. of NmsLog is greater than 5

    _LIT( query, "SELECT * FROM %S" );    
    HBufC* sqlStr=HBufC::NewLC( query().Length() + KNmsLogTable().Length() );
    sqlStr->Des().Format( query, &KNmsLogTable );
    
    // Create a view on the database
    RDbView view;     
    error = view.Prepare( iNmsLogDb, *sqlStr );
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    CleanupStack::PopAndDestroy( sqlStr );     
    CleanupClosePushL( view );
    error = view.EvaluateAll();
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    CDbColSet* columns = view.ColSetL();
    CleanupStack::PushL( columns );
    
    RDbColWriteStream writeStream;
    TRAP( error, //trap start
       // Insert a row. Column order matches sql select statement
        view.InsertL();
        //get index
        view.SetColL( columns->ColNo( KID ), aNmsLog.NmsLogId() );    
        //!open stream
        writeStream.OpenLC( view, columns->ColNo( KNmsLogCol ) );
        aNmsLog.ExternalizeL( writeStream );
        writeStream.CommitL();
        CleanupStack::PopAndDestroy( &writeStream );
         );
コード例 #29
0
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0016
@SYMTestCaseDesc R/W operations at a table level.
				 This test app has "PowerMgmt" (TABLE A: READ) capability, which allows it to
				 read data from table A. B and C tables can be read too, because they do
				 not have read security policy.
@SYMTestPriority High
@SYMTestActions  R/W table operations.
@SYMTestExpectedResults The test must not fail.
@SYMREQ REQ2429
                 DBMS shall provide an API to apply security policies to database tables.
*/
static void TblRWL()
	{
	TheTest.Printf(_L("Table A - Write\n"));
	TInt err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	//The test must fail, because the test app cannot satisfy table A, policy W.
	TRAP(err, TheTbl.InsertL());
	TEST2(err, KErrPermissionDenied);
	err = TheDb.Execute(_L("UPDATE A SET DATA1 = 400 WHERE ID < 10"));
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("Table A - Read\n"));
	//The test must pass, because the test app can satisfy table A, policy R.
	TBool res = EFalse;
	TRAP(err, res = TheTbl.FirstL());
	TEST2(err, KErrNone);
	TEST(res);
	TInt cnt = TheTbl.CountL();
	TEST(cnt > 0);
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM A")));
	TEST2(err, KErrNone);
	cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();

	TheTbl.Close();

	TheTest.Printf(_L("Table B - Write\n"));
	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	//The test must fail, because the test app cannot satisfy table B, policy W.
	TRAP(err, TheTbl.InsertL());
	TEST2(err, KErrPermissionDenied);
	err = TheDb.Execute(_L("INSERT INTO B (DATA2) VALUES (45)"));
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("Table B - Read\n"));
	//The test must pass, because table B has no R policy.
	TRAP(err, res = TheTbl.FirstL());
	TEST2(err, KErrNone);
	TEST(res);
	cnt = TheTbl.CountL();
	TEST(cnt > 0);
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM B")));
	TEST2(err, KErrNone);
	cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();

	TheTbl.Close();

	TheTest.Printf(_L("Table C - Write\n"));
	err = TheTbl.Open(TheDb, KTblNameC);
	//The test must fail, because the test app cannot satisfy table C, policy W.
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TRAP(err, TheTbl.InsertL());
	TEST2(err, KErrPermissionDenied);
	err = TheDb.Execute(_L("UPDATE C SET DATA1 = 400 WHERE ID < 10"));
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("Table C - Read\n"));
	//The test must pass, because table C has no R policy.
	TRAP(err, res = TheTbl.FirstL());
	TEST2(err, KErrNone);
	TEST(res);
	cnt = TheTbl.CountL();
	TEST(cnt > 0);
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM C")));
	TEST2(err, KErrNone);
	cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();

	TheTbl.Close();
	}
コード例 #30
0
/**
@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 );
	}