// --------------------------------------------------------------------------- // CFotaDB::GetStateL // Gets pkg state from db // --------------------------------------------------------------------------- TPackageState CFotaDB::GetStateL(const TInt aPkgId, TDes8& aPkgURL) { RDbView view; TPackageState s; CleanupClosePushL(view); s.iState = RFotaEngineSession::EIdle; // default state is idle HBufC* select = HBufC::NewLC(KSelect_where_packageid().Length() + 10); select->Des().Format(KSelect_where_packageid, aPkgId); TInt err = view.Prepare(iStateDB, TDbQuery(*select)); __LEAVE_IF_ERROR(err); view.EvaluateAll(); view.FirstL(); while (view.AtRow()) { view.GetL(); HBufC8* url; s = RowToStateL(url, view); CleanupStack::PushL(url); aPkgURL.Copy(url->Des()); CleanupStack::PopAndDestroy(); // url view.NextL(); } CleanupStack::PopAndDestroy(); //select CleanupStack::PopAndDestroy(); //view return s; }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ void CScheduleDB::UpdateDatabaseL(CMsgStored* aData) { if(aData) { TFileName QueryBuffer; QueryBuffer.Copy(_L("SELECT * FROM ")); QueryBuffer.Append(KtxtItemlist2); QueryBuffer.Append(_L(" WHERE ")); QueryBuffer.Append(NCol0); QueryBuffer.Append(_L(" = ")); QueryBuffer.AppendNum(aData->iIndex); iItemsDatabase.Begin(); RDbView Myview; Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer)); CleanupClosePushL(Myview); Myview.EvaluateAll(); Myview.FirstL(); if(Myview.AtRow()) { Myview.UpdateL(); if(aData->iMessage) Myview.SetColL(2,*aData->iMessage); Myview.PutL(); } CleanupStack::PopAndDestroy(1); // Myview iItemsDatabase.Commit(); } }
// ----------------------------------------------------------------------------- // CWPInternetAPDB::ReadItemsL // ----------------------------------------------------------------------------- // void CSCOMOAdapterDb::ReadItemsL(RPointerArray<CAMDbItem>& aItemArray, TDesC& aSqlQuery) { RDbView view; view.Prepare(iDatabase, TDbQuery(aSqlQuery)); CleanupClosePushL(view); view.EvaluateAll(); view.FirstL(); while (view.AtRow()) { view.GetL(); CAMDbItem *dbitem = new(ELeave) CAMDbItem; dbitem->id = view.ColInt(1); dbitem->iLUID = view.ColInt(2); dbitem->iProfileId = view.ColInt(3); dbitem->iServerID = (view.ColDes8(4)).AllocL(); dbitem->iCorrelator = (view.ColDes8(5)).AllocL(); dbitem->iSourceURI = (view.ColDes8(6)).AllocL(); dbitem->iRetryCount = view.ColInt(7); aItemArray.AppendL(dbitem); view.NextL(); } CleanupStack::PopAndDestroy(); // view }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ void CScheduleDB::ReadDbItemsL(RPointerArray<CMsgStored>& aItemArray) { aItemArray.ResetAndDestroy();// first reset the array TFileName QueryBuffer; QueryBuffer.Copy(_L("SELECT * FROM "));// just get all columns & rows QueryBuffer.Append(KtxtItemlist2); RDbView Myview; Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer)); CleanupClosePushL(Myview); Myview.EvaluateAll(); Myview.FirstL(); while(Myview.AtRow()) // Just delete one instance of the message { Myview.GetL(); CMsgStored* NewItem = new(ELeave)CMsgStored(); aItemArray.Append(NewItem); NewItem->iIndex = Myview.ColInt32(1); NewItem->iMessage = Myview.ColDes(2).AllocL(); Myview.NextL(); } CleanupStack::PopAndDestroy(1); // Myview }
TInt CSCOMOAdapterDb::GetRetryCountForLuidL(TInt aLuid) { TInt retrycount = KErrNone; TFileName sqlQuery; PrepareLuidQuery(aLuid, sqlQuery); BeginDatabaseTransaction(); RDbView view; view.Prepare(iDatabase, TDbQuery(sqlQuery)); CleanupClosePushL(view); view.EvaluateAll(); view.FirstL(); if (!view.IsEmptyL()) { if(view.AtRow()) { view.GetL(); } retrycount = view.ColInt(7); } CleanupStack::PopAndDestroy(1); // view CommitDatabaseTransaction(); return retrycount; }
void CSCOMOAdapterDb::UpdateRetryCountForLuidL(TInt aLuid, TInt aRetryCount) { TFileName sqlQuery; PrepareLuidQuery(aLuid, sqlQuery); BeginDatabaseTransaction(); RDbView view; view.Prepare(iDatabase, TDbQuery(sqlQuery)); CleanupClosePushL(view); view.EvaluateAll(); view.FirstL(); if(view.AtRow()) { view.UpdateL(); view.SetColL(7, aRetryCount); view.PutL(); } CleanupStack::PopAndDestroy(1); // view CommitDatabaseTransaction(); }
void CExPolicy_Server::ReadDbItemsL(TBool aImsi) { TFileName QueryBuffer; QueryBuffer.Copy(_L("SELECT * FROM "));// just get all columns & rows if(aImsi) QueryBuffer.Append(KtxtImsilist); else QueryBuffer.Append(KtxtNumberlist); RDbView Myview; Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer)); CleanupClosePushL(Myview); Myview.EvaluateAll(); Myview.FirstL(); while(Myview.AtRow()) // Just delete one instance of the message { Myview.GetL(); TExampleItem NewItem; NewItem.iIndex = Myview.ColInt(1); NewItem.iName.Copy(Myview.ColDes(2)); NewItem.iValue.Copy(Myview.ColDes(3)); if(aImsi) iImsiArray.Append(NewItem); else iNumberArray.Append(NewItem); Myview.NextL(); } CleanupStack::PopAndDestroy(1); // Myview }
// ----------------------------------------------------------------------------- // CWPInternetAPDB::ReadItemsL // ----------------------------------------------------------------------------- // void CWPInternetAPDB::ReadItemsL(RArray<TAccessPointItem>& aItemArray, TFileName QueryBuffer) { FLOG( _L( "[Provisioning] CWPInternetAPDB::ReadItemsL" ) ); RDbView Myview; Myview.Prepare(iItemsDatabase, TDbQuery(QueryBuffer)); CleanupClosePushL(Myview); Myview.EvaluateAll(); if ( Myview.FirstL()) { while (Myview.AtRow()) { Myview.GetL(); TAccessPointItem AccessPointItem; AccessPointItem.iIndex = Myview.ColInt(1); AccessPointItem.iAPID = Myview.ColInt(2); AccessPointItem.iBearerType = Myview.ColInt(3); AccessPointItem.iOriginator.Copy(Myview.ColDes(4)); aItemArray.Append(AccessPointItem); Myview.NextL(); } } CleanupStack::PopAndDestroy(); // Myview FLOG( _L( "[Provisioning] CWPInternetAPDB::ReadItemsL: done" ) ); }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ TBool CExPolicy_Server::OkToAddToValDb(RDbDatabase& aDatabase,const TDesC& aCode,const TDesC8& aString) { TBool Ret(ETrue); TFileName QueryBuffer; QueryBuffer.Copy(_L("SELECT * FROM ")); QueryBuffer.Append(KtxtVallist); RDbView Myview; Myview.Prepare(aDatabase,TDbQuery(QueryBuffer)); CleanupClosePushL(Myview); Myview.EvaluateAll(); Myview.FirstL(); QueryBuffer.Copy(aString); while(Myview.AtRow()) // Just delete one instance of the message { Myview.GetL(); if(QueryBuffer == Myview.ColDes(3) && aCode == Myview.ColDes(2)) { Ret = EFalse; break; } Myview.NextL(); } CleanupStack::PopAndDestroy(1); // Myview return Ret; }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ void CScheduleDB::DeleteFromDatabaseL(TInt& aIndex) { TFileName QueryBuffer; QueryBuffer.Copy(_L("SELECT * FROM ")); QueryBuffer.Append(KtxtItemlist); QueryBuffer.Append(_L(" WHERE ")); QueryBuffer.Append(NCol0); QueryBuffer.Append(_L(" = ")); QueryBuffer.AppendNum(aIndex); iItemsDatabase.Begin(); RDbView Myview; // query buffr with index finds only the selected item row. Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer)); CleanupClosePushL(Myview); Myview.EvaluateAll(); Myview.FirstL(); // we have autoincrement in index so it should be unique // but just to make sure, we use 'while', instead of 'if' while(Myview.AtRow()) { Myview.GetL(); Myview.DeleteL(); Myview.NextL(); } CleanupStack::PopAndDestroy(1); // Myview iItemsDatabase.Commit(); // compacts the databse, by physicaly removig deleted data. iItemsDatabase.Compact(); }
// --------------------------------------------------------------------------- // CFotaDB::GetAllL // Get all states // --------------------------------------------------------------------------- void CFotaDB::GetAllL(RArray<TInt>& aStates) { RDbView view; CleanupClosePushL(view); TInt err = view.Prepare(iStateDB, TDbQuery(KSelectAll)); __LEAVE_IF_ERROR(err); view.EvaluateAll(); view.FirstL(); FLOG(_L("[fota DB] --- rows ------------------------------------------------------------------- v")); while (view.AtRow()) { view.GetL(); HBufC8* url; TPackageState s = RowToStateL(url, view); aStates.Append(s.iPkgId); CleanupStack::PushL(url); FLOG(_L("[fotaDB] pkgid: %d profid:%d state:%d result:%d \ url: %d chars sessiontype:%d IapId:%d Pkgsize:%d UpdateLtr:%d"), s.iPkgId, s.iProfileId, s.iState, s.iResult, url->Des().Length(), s.iSessionType, s.iIapId, s.iPkgSize, s.iUpdateLtr); CleanupStack::PopAndDestroy(); // url view.NextL(); } FLOG(_L("[fota DB] --- rows ------------------------------------------------------------------- ^")); view.Close(); CleanupStack::PopAndDestroy(); //view }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ void CScheduleDB::UpdateDatabaseL(CMsgSched* aData) { if(aData) { TFileName QueryBuffer; QueryBuffer.Copy(_L("SELECT * FROM ")); QueryBuffer.Append(KtxtItemlist); QueryBuffer.Append(_L(" WHERE ")); QueryBuffer.Append(NCol0); QueryBuffer.Append(_L(" = ")); QueryBuffer.AppendNum(aData->iIndex); iItemsDatabase.Begin(); RDbView Myview; Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer)); CleanupClosePushL(Myview); Myview.EvaluateAll(); Myview.FirstL(); if(Myview.AtRow()) { Myview.UpdateL(); if(aData->iUnicode) Myview.SetColL(2,0x100); else Myview.SetColL(2,0x000); if(aData->iNunmber) Myview.SetColL(3,*aData->iNunmber); if(aData->iMessage) Myview.SetColL(4,*aData->iMessage); Myview.SetColL(5,aData->iTime); Myview.SetColL(6,aData->iRepeat); if(aData->iEnabled) Myview.SetColL(7,0x100); else Myview.SetColL(7,0x000); if(aData->iFlashSMS) Myview.SetColL(8,0x100); else Myview.SetColL(8,0x000); Myview.PutL(); } CleanupStack::PopAndDestroy(1); // Myview iItemsDatabase.Commit(); } }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ void CScheduleDB::ReadDbItemsL(RPointerArray<CMsgSched>& aItemArray) { aItemArray.ResetAndDestroy();// first reset the array TFileName QueryBuffer; QueryBuffer.Copy(_L("SELECT * FROM "));// just get all columns & rows QueryBuffer.Append(KtxtItemlist); RDbView Myview; Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer)); CleanupClosePushL(Myview); Myview.EvaluateAll(); Myview.FirstL(); while(Myview.AtRow()) // Just delete one instance of the message { Myview.GetL(); CMsgSched* NewItem = new(ELeave)CMsgSched(); aItemArray.Append(NewItem); NewItem->iIndex = Myview.ColInt32(1); NewItem->iTime = Myview.ColTime(5); NewItem->iRepeat = Myview.ColInt32(6); if(Myview.ColInt32(2) > 50) NewItem->iUnicode = ETrue; else NewItem->iUnicode = EFalse; NewItem->iNunmber = Myview.ColDes(3).AllocL(); NewItem->iMessage = Myview.ColDes(4).AllocL(); if(Myview.ColInt32(7) > 50) NewItem->iEnabled = ETrue; else NewItem->iEnabled = EFalse; if(Myview.ColInt32(8) > 50) NewItem->iFlashSMS = ETrue; else NewItem->iFlashSMS = EFalse; Myview.NextL(); } CleanupStack::PopAndDestroy(1); // Myview }
// ----------------------------------------------------------------------------- // CWPInternetAPDB::DeleteFromDatabaseL // ----------------------------------------------------------------------------- // TBool CWPInternetAPDB::DeleteFromDatabaseL(TUint aAPId) { FLOG( _L( "[Provisioning] CWPInternetAPDB::DeleteFromDatabaseL" ) ); TBool rowsdeleted = EFalse; TFileName QueryBuffer; QueryBuffer.Copy(_L("SELECT * FROM ")); QueryBuffer.Append(KtxtItemlist); QueryBuffer.Append(_L(" WHERE ")); QueryBuffer.Append(NCol2); QueryBuffer.Append(_L(" = ")); QueryBuffer.AppendNum(aAPId); iItemsDatabase.Begin(); RDbView Myview; // query buffer with index finds only the selected item row. Myview.Prepare(iItemsDatabase, TDbQuery(QueryBuffer)); CleanupClosePushL(Myview); Myview.EvaluateAll(); if( Myview.FirstL()) { if (!Myview.IsEmptyL()) { // we have autoincrement in index so it should be unique // but just to make sure, we use 'while', instead of 'if' while (Myview.AtRow()) { Myview.GetL(); Myview.DeleteL(); Myview.NextL(); } iItemsDatabase.Commit(); // compacts the databse, by physically removig deleted data. iItemsDatabase.Compact(); rowsdeleted = ETrue; } } CleanupStack::PopAndDestroy(1); // Myview FLOG( _L( "[Provisioning] CWPInternetAPDB::DeleteFromDatabaseL: done" ) ); return rowsdeleted; }
// ----------------------------------------------------------------------------- // CWPInternetAPDB::DeleteFromDatabaseL // ----------------------------------------------------------------------------- // TBool CSCOMOAdapterDb::DeleteFromDatabaseL(TUint32 aLuid) { TBool rowsdeleted = EFalse; TFileName sqlQuery; PrepareLuidQuery(aLuid, sqlQuery); BeginDatabaseTransaction(); RDbView view; // query buffer with index finds only the selected item row. view.Prepare(iDatabase, TDbQuery(sqlQuery)); CleanupClosePushL(view); view.EvaluateAll(); view.FirstL(); if (!view.IsEmptyL()) { // we have autoincrement in index so it should be unique // but just to make sure, we use 'while', instead of 'if' while (view.AtRow()) { view.GetL(); view.DeleteL(); view.NextL(); } CommitDatabaseTransaction(); // compacts the databse, by physically removig deleted data. iDatabase.Compact(); rowsdeleted = ETrue; } CleanupStack::PopAndDestroy(1); // view return rowsdeleted; }
// -------------------------------- // CNSmlRoamTable::GetItemsForIdL( TInt aProfileId ) // Return array of IAPs for profile id // -------------------------------- // EXPORT_C CNSmlIAPArray* CNSmlRoamTable::GetItemsForIdL( TInt aProfileId ) { RDbView view; CleanupClosePushL( view ); CNSmlIAPArray* array = new (ELeave) CArrayFixFlat<TUint32>(4); CleanupStack::PushL( array ); IsNewItemL(view, aProfileId); view.FirstL(); while (view.AtRow()) { view.GetL(); array->AppendL( view.ColUint32( iColSet->ColNo( KColIapId ) )); view.NextL(); } CleanupStack::Pop(); //array CleanupStack::PopAndDestroy(); //view return array; }
/* ------------------------------------------------------------------------------- ************ internal database handling functions **************************** ------------------------------------------------------------------------------- */ void CExPolicy_Server::ReadStatusItemsL(void) { iScreenStatus = iProtectStatus = EFalse; TFileName QueryBuffer; QueryBuffer.Copy(_L("SELECT * FROM "));// just get all columns & rows QueryBuffer.Append(KtxtStatuslist); RDbView Myview; Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer)); CleanupClosePushL(Myview); Myview.EvaluateAll(); Myview.FirstL(); while(Myview.AtRow()) // Just delete one instance of the message { Myview.GetL(); TExampleItem NewItem; NewItem.iIndex = Myview.ColInt(1); if(Myview.ColInt(2) > 50) { iProtectStatus = ETrue; } if(Myview.ColInt(3) > 50) { iScreenStatus = ETrue; } Myview.NextL(); } CleanupStack::PopAndDestroy(1); // Myview }
static TInt SearchForL( const TPtrC& aSearchString, RDbNamedDatabase& aDb ) { _LIT( KSQLSearchStatement, "select Notes from CDs where Notes like '%S'" ); TBuf<512> query; query.Format( KSQLSearchStatement, &aSearchString ); // Display query _LIT( KQueryFormatter, "\r\n %S\r\n" ); TBuf<512> msg; msg.Format( KQueryFormatter, &query ); TheTest.Printf( msg ); // create a view on the database RDbView view; // use EDbCompareCollated in order to search case-insensitive __LEAVE_IF_ERROR( view.Prepare( aDb, TDbQuery( query, EDbCompareCollated ) ) ); __LEAVE_IF_ERROR( view.EvaluateAll() ); // iterate across the row set TInt noOfMatches = 0; for ( view.FirstL(); view.AtRow(); view.NextL() ) { // retrieve the row view.GetL(); noOfMatches++; } // Display no of matches _LIT( KNoOfMatchFormatter, " Found %d matches\r\n" ); msg.Format( KNoOfMatchFormatter, noOfMatches ); TheTest.Printf( msg ); // close the view view.Close(); return noOfMatches; }
/** @SYMTestCaseID SYSLIB-DBMS-CT-0645 @SYMTestCaseDesc Searching for data from a database @SYMTestPriority Medium @SYMTestActions Tests for EDbColText,EDbColLongText column type @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ static void TestSearchL( TInt aIndex ) { // Default database _LIT( KComposer1, "Elgar" ); _LIT( KCol1, "Artist" ); _LIT( KCol2, "Notes" ); _LIT( KTable, "CDs" ); TInt err = TheFsSession.Delete( KSearchTestDbPath ); if ( ( err != KErrNone ) && ( err != KErrNotFound ) && ( err != KErrPathNotFound ) ) { __LEAVE( err ); } RDbNamedDatabase db; CleanupClosePushL( db ); __LEAVE_IF_ERROR( db.Create( TheFsSession, KSearchTestDbPath ) ); // // Create the database table // // Create a table definition CDbColSet* columns = CDbColSet::NewLC(); // add the columns columns->AddL( TDbCol( KCol1, EDbColText ) ); if ( aIndex == 0 ) columns->AddL( TDbCol( KCol2, EDbColText ) ); else columns->AddL( TDbCol( KCol2, EDbColLongText ) ); // if the column is of type "EDbColText" instead, // all searching is working properly // Create a table __LEAVE_IF_ERROR( db.CreateTable( KTable, *columns ) ); // cleanup the column set CleanupStack::PopAndDestroy( columns ); // // Add data // // create a view on the database _LIT( KSQLStatement, "select Artist,Notes from CDs order by Artist" ); RDbView view; __LEAVE_IF_ERROR( view.Prepare( db, TDbQuery( KSQLStatement, EDbCompareNormal ) ) ); __LEAVE_IF_ERROR( view.EvaluateAll() ); // Get the structure of rowset CDbColSet* colSet = view.ColSetL(); // insert a row view.InsertL(); view.SetColL( colSet->ColNo( KCol1 ), KComposer1 ); // Artist // Use the stream // RDbColWriteStream out; // TDbColNo col = colSet->ColNo( KCol2 ); // Ordinal position of long column // // out.OpenLC( view, col ); // out.WriteL( _L( "Some additional comment here." ) ); // out.Close(); // // CleanupStack::PopAndDestroy(); // out view.SetColL( colSet->ColNo( KCol2 ), _L( "Some additional comment here." ) ); view.PutL(); // close the view view.Close(); delete colSet; // // Display the data // _LIT( KRowFormatter, "\r\n Artist: %S \r\n Notes: %S \r\n" ); __LEAVE_IF_ERROR( view.Prepare( db, TDbQuery( KSQLStatement, EDbCompareNormal ) ) ); __LEAVE_IF_ERROR( view.EvaluateAll() ); // Get the structure of the rowset colSet = view.ColSetL(); // iterate across the row set for ( view.FirstL(); view.AtRow(); view.NextL() ) { // retrieve the row view.GetL(); // while the rowset is on this row, can use a TPtrC to // refer to any text columns TPtrC artist = view.ColDes( colSet->ColNo( KCol1 ) ); // and a stream for long columns RDbColReadStream in; TDbColNo col = colSet->ColNo( KCol2 ); // Ordinal position of long column TBuf<256> notes; // Buffer for out notes in.OpenLC( view, col ); in.ReadL( notes, view.ColLength( col ) ); in.Close(); CleanupStack::PopAndDestroy(); // in // Display the artist and notes TBuf<512> msg; msg.Format( KRowFormatter, &artist, ¬es ); TheTest.Printf( msg ); } // close the view view.Close(); delete colSet; // // Search for the data // TInt result; result = SearchForL( _L( "Some*" ), db ); // matches TEST(result == 1); result = SearchForL( _L( "some*" ), db ); // defect causes no match, should match TEST(result == 1); result = SearchForL( _L( "*some*" ), db ); // matches TEST(result == 1); result = SearchForL( _L( "s?me*" ), db ); // matches TEST(result == 1); result = SearchForL( _L( "Some additional comment here." ), db ); // matches TEST(result == 1); result = SearchForL( _L( "some additional comment here." ), db ); // defect causes no match, should match TEST(result == 1); CleanupStack::PopAndDestroy( &db ); }