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 CNSmlDSSettings::CreateDatabaseL(const TDesC& aFullName) { // 50 is the extra length neede for integer lengths HBufC* createProfileTable = HBufC::NewLC( KDSCreateProfilesTable().Length() + 50); TPtr profileTablePtr = createProfileTable->Des(); profileTablePtr.Format(KDSCreateProfilesTable,KNSmlMaxProfileNameLength,KNSmlMaxUsernameLength,KNSmlMaxPasswordLength,KNSmlMaxURLLength,KNSmlMaxServerIdLength,KNSmlMaxHttpAuthUsernameLength,KNSmlMaxHttpAuthPasswordLength, KNSmlDSVisibilityArraySize ); // 25 is the extra length neede for integer lengths HBufC* createAdaptersTable = HBufC::NewLC( KDSCreateAdaptersTable().Length() + 25); TPtr adaptersTablePtr = createAdaptersTable->Des(); adaptersTablePtr.Format(KDSCreateAdaptersTable,KNSmlMaxAdapterDisplayNameLength,KNSmlMaxRemoteNameLength, KNSmlMaxLocalNameLength ); User::LeaveIfError( iDatabase.Create( this->iRdbSession, aFullName, KNSmlDBMSSecureSOSServerID ) ); iDatabase.Begin(); iDatabase.Execute( *createProfileTable ); iDatabase.Execute( *createAdaptersTable ); CDbColSet* colSet = CDbColSet::NewLC(); colSet->AddL(TDbCol(KNSmlVersionColumnMajor(), EDbColUint16)); colSet->AddL(TDbCol(KNSmlVersionColumnMinor(), EDbColUint16)); User::LeaveIfError(iDatabase.CreateTable(KNSmlTableVersion(), *colSet)); CleanupStack::PopAndDestroy( ); //colset RDbTable table; User::LeaveIfError(table.Open(iDatabase, KNSmlTableVersion())); CleanupClosePushL(table); colSet = table.ColSetL(); CleanupStack::PushL(colSet); table.InsertL(); table.SetColL(colSet->ColNo(KNSmlVersionColumnMajor), KNSmlSettingsCurrentVersionMajor); table.SetColL(colSet->ColNo(KNSmlVersionColumnMinor), KNSmlSettingsCurrentVersionMinor); table.PutL(); iDatabase.Commit(); CreateHiddenProfilesL(); TInt keyVal; TRAPD (err ,ReadRepositoryL(KNsmlDsCustomProfiles, keyVal)); if (err == KErrNone && keyVal) { TBool aRestore = EFalse; CreateXMLProfilesL(aRestore); } iDatabase.Close(); CleanupStack::PopAndDestroy( 4 ); // createAdaptersTable, createProfileTable, colSet, 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); }
// -------------------------------- // CNSmlRoamTable::ConstructL() // Second constructor // -------------------------------- // void CNSmlRoamTable::ConstructL() { RDbTable dbTable; CleanupClosePushL( dbTable ); TInt result = dbTable.Open(iDatabase, KTable); if (result != KErrNone) { User::LeaveIfError( iDatabase.Execute( KSQLCreateTable ) ); User::LeaveIfError( iDatabase.Execute( KSQLCreateIndex ) ); User::LeaveIfError( dbTable.Open(iDatabase, KTable) ); } iColSet = dbTable.ColSetL(); CleanupStack::PopAndDestroy(); //dbTable }
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(); }