Beispiel #1
0
void CAppConfig::SetConfigL(const TDesC &aKey, const TConfig &aConfig) {
    TBuf<KConfigValueMaxLength> value;
    switch (aConfig.iType) {
        case EConfigBool:
            if (*aConfig.iValue.iBool) {
                value.Copy(KBoolTrue);
            } else {
                value.Copy(KBoolFalse);
            }
            break;
        case EConfigInt:
            value.Num(*aConfig.iValue.iInt);
            break;
        case EConfigText:
            value.Copy(*aConfig.iValue.iText);
            break;
        case EConfigText8:
            value.Copy(*aConfig.iValue.iText8);
            break;
    }
    
    RDbTable table;
    TDbSeekKey seekKey(aKey);
    
    User::LeaveIfError(table.Open(iDb, KConfigTable, table.EUpdatable));
    
    CleanupClosePushL(table);
    
    User::LeaveIfError(table.SetIndex(KConfigIndex));
    
    CDbColSet* colSet = table.ColSetL();
    CleanupStack::PushL(colSet);
    
    TInt keyColNo = colSet->ColNo(KConfigKeyCol);
    TInt valueColNo = colSet->ColNo(KConfigValueCol);
    
    if (table.SeekL(seekKey)) {
        table.GetL();
        table.UpdateL();
        table.SetColL(valueColNo, value);
    } else {
        table.InsertL();
        table.SetColL(keyColNo, aKey);
        table.SetColL(valueColNo, value);
    }
    table.PutL();
    
    CleanupStack::PopAndDestroy(colSet);
    CleanupStack::PopAndDestroy(&table);
}
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0010
@SYMTestCaseDesc Table R/w operations. 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 R/W table operations won't be
				 executed and the returned error will be KErrPermisssionDenied.
@SYMTestPriority High
@SYMTestActions  Attempts to execute RDbTable::Insert()/RDbTable::Update()/RDbTable::FirstL()
                 on different tables from the test database.
@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("An attempt to write in table B\n"));
	TInt err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	//"Write table B" test must fail, because the test app has no capabilities
	//to satisfy table B, policy W.
	TRAP(err, TheTbl.InsertL());
	TEST2(err, KErrPermissionDenied);
	TRAP(err, TheTbl.UpdateL());
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("An attempt to read from table B\n"));
	//"Read table B" test must pass, because table B has no R policy
	TBool res = TheTbl.FirstL();
	TEST(!res);

	TheTbl.Close();

	TheTest.Printf(_L("An attempt to write in table C\n"));
	//"Write table C" test must fail, because the test app has no capabilities
	//to satisfy table C, policy W.
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TRAP(err, TheTbl.InsertL());
	TEST2(err, KErrPermissionDenied);
	TRAP(err, TheTbl.UpdateL());
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("An attempt to read from table C\n"));
	//"Read table C" test must pass, because table C has no R policy
	res = TheTbl.FirstL();
	TEST(!res);

	TheTbl.Close();
	}
Beispiel #3
0
void CAppConfig::SaveGameL(midend *aME, const game *aGame) {
    TPtrC8 name((const TUint8*)aGame->name);
    RDbTable table;
    TDbSeekKey seekKey(name);
    
    User::LeaveIfError(table.Open(iDb, KAutosaveTable, table.EUpdatable));
    
    CleanupClosePushL(table);
    
    User::LeaveIfError(table.SetIndex(KAutosaveIndex));
    
    CDbColSet* colSet = table.ColSetL();
    CleanupStack::PushL(colSet);
    
    TInt nameColNo = colSet->ColNo(KAutosaveNameCol);
    TInt saveColNo = colSet->ColNo(KAutosaveSaveCol);
    TInt dateColNo = colSet->ColNo(KAutosaveDateCol);
    
    if (table.SeekL(seekKey)) {
        table.GetL();
        table.UpdateL();
    } else {
        table.InsertL();
        table.SetColL(nameColNo, name);
    }
    TTime now;
    now.HomeTime();
    table.SetColL(dateColNo, now);
    
    RDbColWriteStream stream;
    stream.OpenL(table, saveColNo);
    CleanupClosePushL(stream);
    
    midend_serialise(aME, save_game, &stream);
    CleanupStack::PopAndDestroy(&stream);
    
    table.PutL();
    
    CleanupStack::PopAndDestroy(colSet);
    CleanupStack::PopAndDestroy(&table);
    
    iDb.Compact();
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
void CPosLmNameIndex::SaveL( TChar aDrive )
    {
    RDbTable table;
    TInt err = table.Open( iDatabase, KPosLmIndexTable, RDbRowSet::EUpdatable );
    if ( err == KErrNotFound )
        {
        PosLmDatabaseManager::CreateIndexTableL( iDatabase );
        err = table.Open( iDatabase, KPosLmIndexTable, RDbRowSet::EUpdatable );
        }
    User::LeaveIfError( err );
    CleanupClosePushL( table );

    TInt currentSize = 0;
    table.FirstL();
    if ( table.AtEnd() )
        {
        table.InsertL();
        }
    else
        {
        table.GetL();
        currentSize = table.ColSize( EPosLmIncIndexDataCol ); 
        table.UpdateL();
        }
    
    if ( currentSize < DataSize() )
        {
        // check disk size
        CPosLmDiskUtilities* diskUtilities = CPosLmDiskUtilities::NewL();
        CleanupStack::PushL( diskUtilities );
    
        TInt bytesToWrite = DataSize() - currentSize;
        diskUtilities->DiskSpaceBelowCriticalLevelL( bytesToWrite, aDrive );
    
        CleanupStack::PopAndDestroy( diskUtilities );
        }
    
    // current language
    table.SetColL( EPosLmIncLanguageCol, User::Language() );
    
    // index data
    RDbColWriteStream writeStream;
    writeStream.OpenL( table, EPosLmIncIndexDataCol );
    CleanupClosePushL( writeStream );
    ExternalizeL( writeStream );
    CleanupStack::PopAndDestroy( &writeStream );
    
    // index timestamp
    TTime now;
    now.UniversalTime();
    table.SetColL( EPosLmIncTimestampCol, now );

#ifdef _DEBUG  
    TBuf<64> mtime;
    now.FormatL( mtime, KPosLmTimeFormat );
    LOG1( "NameIndex: Saving index timestamp %S", &mtime); 
#endif    

    table.PutL();
    CleanupStack::PopAndDestroy ( &table );
    
    iTimeStamp = now;
    }