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 }
//Adds some data to the test table static void AddTestDataL(RDbNamedDatabase& aDb) { RDbTable tbl; CleanupClosePushL(tbl); TEST2(tbl.Open(aDb, KTestTableName, RDbRowSet::EUpdatable), KErrNone); for(TInt i=0;i<KTestRecordsCount;++i) { tbl.InsertL(); tbl.SetColL(2, _L8("1ABCDEFGHI2ABCDEFGHI3ABCDEFGHI4ABCDEFGHI5ABCDEFGHI6ABCDEFGHI7ABCDEFGHI8ABCDEFGHI9ABCDEFGHI0ABCDEFGHI")); tbl.PutL(); } TEST(tbl.CountL() == KTestRecordsCount); CleanupStack::PopAndDestroy(&tbl); }
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); }
LOCAL_C void CreateTableL() { TheDatabase.Begin(); test(TheDatabase.Execute(KCreateTable)==KErrNone); RDbTable table; test(table.Open(TheDatabase,KTableName,table.EInsertOnly)==KErrNone); for (TInt ii=0;ii<KRecords;++ii) { table.InsertL(); table.SetColL(1,ii); table.PutL(); } table.Close(); test(TheDatabase.Execute(KCreateIndex)==KErrNone); test (TheDatabase.Commit()==KErrNone); }
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; }
/** @SYMTestCaseID SYSLIB-DBMS-CT-0581 @SYMTestCaseDesc Tests the database definition and enquiry functions @SYMTestPriority Medium @SYMTestActions Tests for bookmark which saves the current location of a rowset. @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ LOCAL_C void TestBookmark() { test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0581 creating alien bookmark ")); CDbColSet* cs=CDbColSet::NewLC(); TDbCol col(_L("column"),EDbColUint8); col.iAttributes=TDbCol::ENotNull+TDbCol::EAutoIncrement; cs->AddL(col); test (TheDatabase.CreateTable(KOtherTable,*cs)==KErrNone); CleanupStack::PopAndDestroy(); RDbTable extra; test (extra.Open(TheDatabase,KOtherTable)==KErrNone); extra.InsertL(); extra.PutL(); TDbBookmark alien=extra.Bookmark(); extra.Close(); // test.Next(_L("Alien bookmark")); test (TheTable.Open(TheDatabase,KTableName)==KErrNone); TRAPD(r,TheTable.GotoL(alien)); test (r==KErrNotFound); test (TheTable.SetIndex(KIndexInt)==KErrNone); TRAP(r,TheTable.GotoL(alien)); test (r==KErrNotFound); test (TheTable.SetIndex(KIndexText)==KErrNone); TRAP(r,TheTable.GotoL(alien)); test (r==KErrNotFound); // test.Next(_L("Cross-view bookmarks")); TheTable.LastL(); // indexed view TheTable.PreviousL(); TDbBookmark mark=TheTable.Bookmark(); test (extra.Open(TheDatabase,KTableName)==KErrNone); TRAP(r,extra.GotoL(mark)); test (r==KErrNone); test (extra.PreviousL()); TRAP(r,TheTable.GotoL(extra.Bookmark())); test (r==KErrNone); extra.Close(); // test.Next(_L("Bookmark persistence")); TheTable.Close(); test (TheTable.Open(TheDatabase,KTableName)==KErrNone); TRAP(r,TheTable.GotoL(mark)); test (r==KErrNone); TheTable.Close(); // test.Next(_L("Delete alien record")); test (extra.Open(TheDatabase,KOtherTable)==KErrNone); TRAP(r, extra.GotoL(mark)); test (r==KErrNotFound); TRAP(r,extra.GotoL(alien)); test (r==KErrNone); extra.DeleteL(); TRAP(r,extra.GotoL(alien)); test (r==KErrNotFound); extra.Close(); // test.Next(_L("Delete extra table")); test (TheDatabase.DropTable(KOtherTable)==KErrNone); test (TheTable.Open(TheDatabase,KTableName)==KErrNone); TRAP(r,TheTable.GotoL(alien)); test (r==KErrNotFound); TheTable.Close(); // test.End(); }