Example #1
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();
}
Example #2
0
// ---------------------------------------------------------------------------
// CFotaDB::StateToRowL
// Converts state object to database row (into view object)
// ---------------------------------------------------------------------------
void CFotaDB::StateToRowL(const TPackageState& aPkg, const TDesC8& aPkgURL,
        RDbView& aView)
    {
    HBufC* pkgname = HBufC::NewLC(aPkg.iPkgName.Length());
    HBufC* version = HBufC::NewLC(aPkg.iPkgVersion.Length());

    pkgname->Des().Copy(aPkg.iPkgName);
    version->Des().Copy(aPkg.iPkgVersion);

    aView.SetColL(iColSet->ColNo(KColPkgId), aPkg.iPkgId);
    aView.SetColL(iColSet->ColNo(KColResult), aPkg.iResult);
    aView.SetColL(iColSet->ColNo(KColState), aPkg.iState);
    aView.SetColL(iColSet->ColNo(KColProfileId), aPkg.iProfileId);
    aView.SetColL(iColSet->ColNo(KColPkgName), *pkgname);
    aView.SetColL(iColSet->ColNo(KColVersion), *version);
    aView.SetColL(iColSet->ColNo(KColSmlTryCount), aPkg.iSmlTryCount);
    aView.SetColL(iColSet->ColNo(KColSessionType), aPkg.iSessionType);
    aView.SetColL(iColSet->ColNo(KColIapId), aPkg.iIapId);
    aView.SetColL(iColSet->ColNo(KColPkgSize), aPkg.iPkgSize);
    aView.SetColL(iColSet->ColNo(KColUpdateLtr), aPkg.iUpdateLtr);

    RDbColWriteStream wstream;
    CleanupClosePushL(wstream);
    wstream.OpenL(aView, iColSet->ColNo(KColPkgUrl));
    // Cannot write 8 bit descriptors to databae
    HBufC* buf = HBufC::NewLC(aPkgURL.Length());
    buf->Des().Copy(aPkgURL);
    wstream.WriteL(buf->Des());

    FLOG(_L("CFotaDB::StateToRowL  id:%d result:%d state:%d profileid:%d \
    		name:%d chars version: %d chars url: %d chars sessiontype:%d iapid:%d pkgsize:%d updateltr = %d"),
            aPkg.iPkgId, aPkg.iResult, aPkg.iState, aPkg.iProfileId,
            pkgname->Des().Length(), version->Des().Length(),
            buf->Des().Length(), aPkg.iSessionType, aPkg.iIapId,
            aPkg.iPkgSize, aPkg.iUpdateLtr);

    CleanupStack::PopAndDestroy(buf);
    CleanupStack::PopAndDestroy(&wstream);
    CleanupStack::PopAndDestroy(version);
    CleanupStack::PopAndDestroy(pkgname);
    }
// ---------------------------------------------------------------------------
//  CNSmlDmFotaAdapterDb::SetLongStrValueL()
//  Streams aValue and its length as the value of aColumn in FW object 
//  identified by aObject.
// ---------------------------------------------------------------------------
// 
TInt CNSmlDmFotaAdapterDb::SetLongStrValueL( const TDesC& aColumn, 
                                             const TDesC8& aValue, 
                                             const TNSmlDmFwObjectId aObject )
    {
    _DBG_FILE("CNSmlDmFotaAdapterDb::SetLongStrValueL(): begin");
    
    HBufC* value = ConvertTo16BitLC( aValue );
    
    DBG_ARGS( _S16("CNSmlDmFotaAdapterDb::SetStrValueL(): ('%S', '%S', %d)"),
              &aColumn, value, aObject );
    
    TInt ret = UpdateRowL( aObject );
    
    if ( ret == KErrNone )
        {
        // do update
        
        RDbColWriteStream wStream;
        wStream.OpenL( iView, iColSet->ColNo( aColumn ) );
        CleanupClosePushL( wStream );
        
        wStream.WriteInt32L( value->Length() );
        wStream.WriteL( *value, value->Length() );
        
        CleanupStack::PopAndDestroy( &wStream );
        
        iView.PutL();
        }
    
    CommitAndCompact();
    
    CleanupStack::PopAndDestroy( value );
    
    _DBG_FILE("CNSmlDmFotaAdapterDb::SetLongStrValueL(): end");
    
    return ret;
    }
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
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;
    }