char* CAppConfig::LoadGameL(midend *aME, const game *aGame) { TPtrC8 name((const TUint8*)aGame->name); RDbTable table; TDbSeekKey seekKey(name); char *errmsg = ""; User::LeaveIfError(table.Open(iDb, KAutosaveTable, table.EReadOnly)); CleanupClosePushL(table); User::LeaveIfError(table.SetIndex(KAutosaveIndex)); CDbColSet* colSet = table.ColSetL(); CleanupStack::PushL(colSet); TInt saveColNo = colSet->ColNo(KAutosaveSaveCol); if (table.SeekL(seekKey)) { table.GetL(); RDbColReadStream stream; stream.OpenLC(table,saveColNo); errmsg = midend_deserialise(aME, read_game, &stream); CleanupStack::PopAndDestroy(&stream); } CleanupStack::PopAndDestroy(colSet); CleanupStack::PopAndDestroy(&table); return errmsg; }
void CAppConfig::GetConfigL(const TDesC &aKey, const TConfig &aConfig) { RDbTable table; TDbSeekKey seekKey(aKey); User::LeaveIfError(table.Open(iDb, KConfigTable, table.EReadOnly)); CleanupClosePushL(table); User::LeaveIfError(table.SetIndex(KConfigIndex)); CDbColSet* colSet = table.ColSetL(); CleanupStack::PushL(colSet); TInt valueColNo = colSet->ColNo(KConfigValueCol); if (table.SeekL(seekKey)) { table.GetL(); TPtrC value = table.ColDes(valueColNo); switch (aConfig.iType) { case EConfigBool: *aConfig.iValue.iBool = value.Compare(KBoolTrue) == 0 ? ETrue : EFalse; break; case EConfigInt: { TLex lex(value); TInt lvalue; if (lex.Val(lvalue) == KErrNone) { *aConfig.iValue.iInt = lvalue; } break; } case EConfigText: if (aConfig.iValue.iText->MaxLength() > value.Length()) { aConfig.iValue.iText->Copy(value.Left(aConfig.iValue.iText->MaxLength())); } else { aConfig.iValue.iText->Copy(value); } break; case EConfigText8: if (aConfig.iValue.iText8->MaxLength() > value.Length()) { aConfig.iValue.iText8->Copy(value.Left(aConfig.iValue.iText8->MaxLength())); } else { aConfig.iValue.iText8->Copy(value); } break; } } CleanupStack::PopAndDestroy(colSet); CleanupStack::PopAndDestroy(&table); }
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); }
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(); }
// --------------------------------------------------------------------------- // 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 ); );
//-------------------------------------------------------------------- //-------------------------------------------------------------------- // 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; }
//-------------------------------------------------------------------- //-------------------------------------------------------------------- // void CPosLmNameIndex::LoadL() { // Skip index loading for empty databases TInt numLandmarks = PosLmServerUtility::TotalLandmarkCountL( iDbAccess ); if ( numLandmarks == 0 ) { iTimeStamp.UniversalTime(); iStatus = KErrNone; return; } RDbTable table; TInt err = table.Open( iDatabase, KPosLmIndexTable, RDbRowSet::EReadOnly ); if ( err ) { LOG("NameIndex::LoadL: index table not found"); User::Leave( err ); } CleanupClosePushL( table ); table.FirstL(); if ( table.AtEnd() ) { LOG("NameIndex::LoadL: index not found"); User::Leave( KErrNotFound ); } table.GetL(); // verify that index is valid for current language if ( !table.IsColNull( EPosLmIncLanguageCol ) ) { TLanguage lang = (TLanguage) table.ColInt32( EPosLmIncLanguageCol ); if ( User::Language() != lang ) { LOG2("NameIndex::LoadL: index not valid, lang %d, current lang %d", lang, User::Language() ); User::Leave( KErrCorrupt ); } } else { LOG("NameIndex::LoadL: index lang not found"); User::Leave( KErrCorrupt ); } // read the index if ( !table.IsColNull( EPosLmIncIndexDataCol ) ) { RDbColReadStream readStream; readStream.OpenL( table, EPosLmIncIndexDataCol ); CleanupClosePushL( readStream ); InternalizeL( readStream ); CleanupStack::PopAndDestroy( &readStream ); // basic check for the index if ( Count() != numLandmarks ) { LOG2("NameIndex::LoadL: index not valid, count %d, landmarks in db %d", Count(), numLandmarks ); User::Leave( KErrCorrupt ); } } else { LOG("NameIndex::LoadL: index data not found"); User::Leave( KErrCorrupt ); } // read the time stamp iTimeStamp.UniversalTime(); if ( !table.IsColNull( EPosLmIncTimestampCol ) ) { iTimeStamp = table.ColTime( EPosLmIncTimestampCol ); } else { LOG("NameIndex::LoadL: index timestamp not found"); User::Leave( KErrCorrupt ); } CleanupStack::PopAndDestroy ( &table ); // index is valid iStatus = KErrNone; }