//This test checks how RDbDatabase::Commit() works if there are some active RDbRowSet objects - //read-only and updatable. The expectation is that the Commit() call won't fail, the RDbRowSet objects //retain their pre-commit positions. void CommitTestL() { //Create 2 test tables, insert some records in the first table TheDatabase.Close(); TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName); TEST2(err, KErrNone); err = TheDatabase.Execute(_L("CREATE TABLE AA1(Id INTEGER)")); TEST2(err, KErrNone); err = TheDatabase.Execute(_L("CREATE TABLE AA2(Id INTEGER)")); TEST2(err, KErrNone); err = TheDatabase.Execute(_L("INSERT INTO AA1(Id) VALUES(1)")); TEST2(err, 1); err = TheDatabase.Execute(_L("INSERT INTO AA1(Id) VALUES(2)")); TEST2(err, 1); err = TheDatabase.Execute(_L("INSERT INTO AA1(Id) VALUES(3)")); TEST2(err, 1); //Begin transaction err = TheDatabase.Begin(); TEST2(err, KErrNone); //Prepare read-only view and call FirstL() (TheRowSet object) RDbView view; err = view.Prepare(TheDatabase, _L("select * from AA1"), RDbRowSet::EReadOnly); TEST2(err, KErrNone); TheRowSet = view; err = view.EvaluateAll(); //DBMS can use FirstL() without the EvaluateAll() call in this case TEST2(err, KErrNone); TBool rc = TheRowSet.FirstL(); TEST(rc); //Prepare updatable view and call NextL() (TheRowSet2 object) err = view.Prepare(TheDatabase, _L("select * from AA1"), RDbRowSet::EUpdatable); TEST2(err, KErrNone); TheRowSet2 = view; err = view.EvaluateAll(); //DBMS can use NextL() without the EvaluateAll() call in this case TEST2(err, KErrNone); rc = TheRowSet2.FirstL(); TEST(rc); rc = TheRowSet2.NextL(); TEST(rc); //Execute one INSERT statement err = TheDatabase.Execute(_L("INSERT INTO AA2(Id) VALUES(1)")); TEST2(err, 1); //Commit transaction err = TheDatabase.Commit(); TEST2(err, KErrNone); //Check the retrieved by TheRowSet record TheRowSet.GetL(); TEST2(TheRowSet.ColInt(1), 1); //Check the retrieved by TheRowSet2 record TheRowSet2.GetL(); TEST2(TheRowSet2.ColInt(1), 2); //Cleanup TheRowSet2.Close(); TheRowSet.Close(); TheDatabase.Close(); }
// --------------------------------------------------------------------------- // 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 }
//Query the aItem from Table DscItem void CDscDatabase::QueryItemL(RDbView& aView, const CDscItem& aItem) const { RBuf sqlCmd; CleanupClosePushL(sqlCmd); if (aItem.ItemId()) { sqlCmd.CreateL(KSqlSelectDscItemOnIdLength); sqlCmd.Format( KSqlSelectDscItemOnId, &KDscIdCol, &KItemIdCol, &KFileNameCol, &KArgListCol,&KStartMethodCol, &KTimeoutCol, &KNoOfRetriesCol, &KMonitorCol, &KStartupTypeCol, &KViewlessCol, &KStartInBackgroundCol, &KItemTable, &KDscIdCol, aItem.DscId(), &KItemIdCol, aItem.ItemId()); } else { const TPtrC filename = aItem.FileName(); const TPtrC argList = aItem.Args(); //whitespace already trimmed LeaveIfFileParamsNotValidL(aItem); const TInt length = KSqlSelectDscItemOnNameLength + filename.Length() + argList.Length(); sqlCmd.CreateL(length); sqlCmd.Format(KSqlSelectDscItemOnName, &KDscIdCol, &KItemIdCol, &KFileNameCol,&KArgListCol, &KStartMethodCol, &KTimeoutCol, &KNoOfRetriesCol, &KMonitorCol, &KStartupTypeCol, &KViewlessCol, &KStartInBackgroundCol, &KItemTable, &KDscIdCol, aItem.DscId(), &KFileNameCol, &filename, &KArgListCol, &argList); } DebugPrint(sqlCmd); User::LeaveIfError(aView.Prepare(iDatabase, sqlCmd)); User::LeaveIfError(aView.EvaluateAll()); //no error for non existing item CleanupStack::PopAndDestroy(&sqlCmd); }
void CDscDatabase::GetDscDescriptionL(const TUid &aDscId, TDes& aDescription) const { RDbView view; CleanupClosePushL(view); RBuf sqlCmd; CleanupClosePushL(sqlCmd); sqlCmd.CreateL(KSqlSelectDscDescriptionLength); sqlCmd.Format(KSqlSelectDscDescription, &KDescriptionCol, &KDscTable, &KDscIdCol, aDscId); DebugPrint(sqlCmd); User::LeaveIfError(view.Prepare(iDatabase, sqlCmd)); User::LeaveIfError(view.EvaluateAll()); CleanupStack::PopAndDestroy(&sqlCmd); if(view.IsEmptyL()) { User::Leave(KErrNotFound); } view.FirstL(); view.GetL(); //Check the length of aDescription TPtrC description(view.ColDes(1)); if (description.Length() > aDescription.MaxLength()) { User::Leave(KErrOverflow); } aDescription.Zero(); aDescription=description; CleanupStack::PopAndDestroy(&view); }
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 }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ 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; }
// ----------------------------------------------------------------------------- // 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::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(); } }
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; }
TBool CSCPParamDB :: IsParamValueSharedL(HBufC* aParamValue, const TInt32 aApp) { _SCPDB_LOG(_L("[CSCPParamDB]-> IsParamValueShared >>>")); if(aParamValue == NULL) { return KErrArgument; } RDbView lDBView; CleanupClosePushL(lDBView); HBufC* lSelectQry = HBufC :: NewLC(KSelectAppIDParamValNotIn().Length() + aParamValue->Des().Length() + 50); lSelectQry->Des().Format(KSelectAppIDParamValNotIn, aApp, &aParamValue->Des()); __LEAVE_IF_ERROR(lDBView.Prepare(iParameterDB, TDbQuery(*lSelectQry))); __LEAVE_IF_ERROR(lDBView.EvaluateAll()); TInt lRowCnt(0); TInt lStatus(KErrNone); TRAP(lStatus, lRowCnt = lDBView.CountL()); if(lStatus != KErrNone) { _SCPDB_LOG(_L("[CSCPParamDB]-> ERROR: Unable to determine row count...")); } else { if(lRowCnt > 0) { CleanupStack :: PopAndDestroy(2); return ETrue; } } _SCPDB_LOG(_L("[CSCPParamDB]-> IsParamValueShared <<<")); CleanupStack :: PopAndDestroy(2); return EFalse; }
TInt CSCPParamDB :: GetApplicationIDListL(RArray <TUid>& aIDArray) { _SCPDB_LOG(_L("[CSCPParamDB]-> GetApplicationIDList() >>>")); RDbView lDBView; CleanupClosePushL(lDBView); HBufC* lSelectQry = HBufC :: NewLC(KSelectAll().Length()); lSelectQry->Des().Append(KSelectAll); __LEAVE_IF_ERROR(lDBView.Prepare(iParameterDB, TDbQuery(*lSelectQry))); __LEAVE_IF_ERROR(lDBView.EvaluateAll()); TBool lStatus(EFalse); TInt lRet(KErrNone); TRAP(lRet, lStatus = lDBView.FirstL()); if(lRet == KErrNone && lStatus) { do { lDBView.GetL(); TUid lAppUID = TUid :: Uid(lDBView.ColInt(iColSet->ColNo(KColAppId))); if(aIDArray.Find(lAppUID) == KErrNotFound) { aIDArray.AppendL(lAppUID); } } while(lDBView.NextL()); } _SCPDB_LOG(_L("[CSCPParamDB]-> GetApplicationIDList() >>>")); CleanupStack :: PopAndDestroy(2); return KErrNone; }
// ----------------------------------------------------------------------------- // 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" ) ); }
TInt CSCPParamDB :: GetValueForParameterL(TInt aParamID, TInt32& aValue, TInt32& aApp) { _SCPDB_LOG(_L("[CSCPParamDB]-> GetValueForParameterL >>>")); RDbView lDBView; CleanupClosePushL(lDBView); HBufC* lSelectQry = HBufC :: NewLC(KSelectWhereParamId().Length() + 15); lSelectQry->Des().Format(KSelectWhereParamId, aParamID); __LEAVE_IF_ERROR(lDBView.Prepare(iParameterDB, TDbQuery(*lSelectQry))); __LEAVE_IF_ERROR(lDBView.EvaluateAll()); if( lDBView.FirstL()) { TInt lRowCount = lDBView.CountL(); if(lRowCount == 0) { _SCPDB_LOG(_L("[CSCPParamDB]-> No Rows found for this parameter")); CleanupStack :: PopAndDestroy(2); return KErrNotFound; } else if(lRowCount > 1) { _SCPDB_LOG(_L("[CSCPParamDB]-> ERROR: More than one record matches the criterion. Db is corrupt! Leaving...")); User :: Leave(KErrCorrupt); } lDBView.GetL(); aApp = lDBView.ColInt(iColSet->ColNo(KColAppId)); aValue = lDBView.ColInt(iColSet->ColNo(KColValueInt)); } CleanupStack :: PopAndDestroy(2); _SCPDB_LOG(_L("[CSCPParamDB]-> GetValueForParameterL <<<")); return KErrNone; }
// -------------------------------- // CNSmlRoamTable::GetItemIAPL( TInt aProfileId, TInt aPriority ) // Return IAP for profile id and priority // -------------------------------- // EXPORT_C TUint32 CNSmlRoamTable::GetItemIAPL( TInt aProfileId, TInt aPriority ) { RDbView view; CleanupClosePushL(view); TUint32 uint(0); TBuf<KNSmlMaxSQLLength> sqlBuf; sqlBuf.Format( KSQLSelectUint, aProfileId, aPriority ); view.Prepare(iDatabase, TDbQuery( sqlBuf )); view.EvaluateAll(); if ( view.IsEmptyL() ) { User::Leave( KErrNotFound ); } view.FirstL(); view.GetL(); uint = view.ColUint( iColSet->ColNo( KColIapId )); CleanupStack::PopAndDestroy(); //view return uint; }
// --------------------------------------------------------------------------- // 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::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(); }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ 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 }
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(); }
// -------------------------------- // CNSmlRoamTable::IsNewItemL( RDbView& aView, CNSmlRoamItem& aItem) // Checks if whether IAP is new for profile id and priority // -------------------------------- // TBool CNSmlRoamTable::IsNewItemL( RDbView& aView, CNSmlRoamItem& aItem) { TBuf<KNSmlMaxSQLLength> sqlBuf; sqlBuf.Format( KSQLSelectUint, aItem.iProfileId, aItem.iPriority ); aView.Prepare(iDatabase, TDbQuery( sqlBuf )); aView.EvaluateAll(); return aView.IsEmptyL(); }
// -------------------------------- // CNSmlRoamTable::IsNewItemL( RDbView& aView, TInt aProfileId) // Checks if whether profile has IAPs // -------------------------------- // TBool CNSmlRoamTable::IsNewItemL( RDbView& aView, TInt aProfileId) { TBuf<KNSmlMaxSQLLength> sqlBuf; sqlBuf.Format(KSQLMultiQuery, aProfileId); aView.Prepare(iDatabase, TDbQuery( sqlBuf )); aView.EvaluateAll(); return aView.IsEmptyL(); }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ 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 CAlmSettingsSession::ProcessDataL(void) { TInt func=Message().Function(); _LIT(KSQL,"select id,name,cid,value from settings where cid=%u and name='%S'"); RDbView view; TBuf<128> sql; TUint32 cid=CategoryL(Message().Ptr0()); HBufC8* param1=ValueLC(Message().Ptr1()); TPtrC name((const TUint16*)param1->Ptr(),param1->Length()/2); sql.Format(KSQL,cid,&name); User::LeaveIfError(view.Prepare(iServer.DbL(),TDbQuery(sql),(func==ESettingsServerRequestSet)?RDbView::EUpdatable:RDbView::EReadOnly)); CleanupClosePushL(view); User::LeaveIfError(view.EvaluateAll()); TBool first=view.FirstL(); if(func==ESettingsServerRequestSet) { if(first) view.UpdateL(); else view.InsertL(); CleanupCancelPushL(view); if(!first) { view.SetColL(2,name); view.SetColL(3,cid); } HBufC8* value=ValueLC(Message().Ptr2()); view.SetColL(4,*value); view.PutL(); CleanupStack::Pop(); //view cancel CleanupStack::PopAndDestroy(); //value iServer.Notify(); } else { if(!first) User::Leave(KErrNotFound); view.GetL(); TInt len=view.ColSize(4); if(func==ESettingsServerRequestGetData) { HBufC8* data=HBufC8::NewLC(len); TPtr8 ptr(data->Des()); RDbColReadStream stream; stream.OpenLC(view,4); stream.ReadL(ptr,len); Message().WriteL(Message().Ptr2(),ptr); CleanupStack::PopAndDestroy(2); //stream,data } else { TPckgC<TInt> size(len); Message().WriteL(Message().Ptr2(),size); } } CleanupStack::PopAndDestroy(2); //view,param1 }
// --------------------------------------------------------------------------- // CLbtDbOperationAO::ExecuteSyncQuery // --------------------------------------------------------------------------- // TInt CLbtDbOperationAO::ExecuteSyncQuery( RDbView& aView, TDesC& aQuery) { FUNC_ENTER("CLbtDbOperationAO::ExecuteSyncQuery"); TInt err = aView.Prepare( iDb, TDbQuery(aQuery, EDbCompareFolded),KDbUnlimitedWindow ); // This should evaluate the query fully if ( err == KErrNone ) { err = aView.EvaluateAll(); } return err; }
TInt CSCPParamDB :: GetValuesForParameterL(TInt aParamID, RPointerArray <HBufC>& aParamValues, const TInt32 aApp) { _SCPDB_LOG(_L("[CSCPParamDB]-> GetValueForParameterL >>>")); RDbView lDBView; CleanupClosePushL(lDBView); HBufC* lSelectQry = HBufC :: NewLC(KSelectWhereParamIdAppID().Length() + 40); lSelectQry->Des().Format (KSelectWhereParamIdAppID, aParamID, aApp); __LEAVE_IF_ERROR(lDBView.Prepare(iParameterDB, TDbQuery(*lSelectQry))); __LEAVE_IF_ERROR(lDBView.EvaluateAll()); if (lDBView.FirstL()) { TInt size(0); TInt lRowCount = lDBView.CountL(); if(lRowCount == 0) { _SCPDB_LOG(_L("[CSCPParamDB]-> No Rows found for this parameter")); CleanupStack :: PopAndDestroy(2); return KErrNotFound; } TInt lErr(KErrNone); do { lDBView.GetL(); size = lDBView.ColDes(iColSet->ColNo(KColValueDes)).Size(); if(size) { HBufC* lBuff = HBufC :: NewL(size); TPtr lPtr(lBuff->Des()); lPtr.Copy(lDBView.ColDes(iColSet->ColNo(KColValueDes))); TRAP(lErr, aParamValues.AppendL(lBuff)); if(lErr != KErrNone) { aParamValues.ResetAndDestroy(); User :: Leave(lErr); } } } while(lDBView.NextL()); } CleanupStack :: PopAndDestroy(2); _SCPDB_LOG(_L("[CSCPParamDB]-> GetValuesForParameterL <<<")); return KErrNone; }
/* ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- */ 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 }
/* ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- */ TInt CExPolicy_Server::UpdateStatusL(TBool& aValue, TBool aProtect) { TInt ErrRet(KErrNone); TRAP(ErrRet, DeleteStatusInfoL(); if(aProtect) { iProtectStatus = aValue; } else { iScreenStatus = aValue; } TFileName QueryBuffer; QueryBuffer.Copy(_L("SELECT * FROM ")); QueryBuffer.Append(KtxtStatuslist); iItemsDatabase.Begin(); RDbView Myview; Myview.Prepare(iItemsDatabase,TDbQuery(QueryBuffer)); CleanupClosePushL(Myview); Myview.EvaluateAll(); Myview.FirstL(); Myview.InsertL(); if(iProtectStatus) Myview.SetColL(2,0x100); else Myview.SetColL(2,0x000); if(iScreenStatus) Myview.SetColL(3,0x100); else Myview.SetColL(3,0x000); Myview.PutL(); CleanupStack::PopAndDestroy(1); // Myview iItemsDatabase.Commit(); );
TUint32 CAlmSettingsSession::CategoryL(const TAny* aSrc) { _LIT(KSQL,"select id from categories where name='%S'"); RDbView view; TBuf<128> sql; HBufC8* param0=ValueLC(aSrc); TPtrC name((const TUint16*)param0->Ptr(),param0->Length()/2); sql.Format(KSQL,&name); User::LeaveIfError(view.Prepare(iServer.DbL(),TDbQuery(sql),RDbView::EReadOnly)); CleanupClosePushL(view); User::LeaveIfError(view.EvaluateAll()); if(!view.FirstL()) User::Leave(KErrNotFound); view.GetL(); TUint32 cid=view.ColUint32(1); CleanupStack::PopAndDestroy(2); //view,param1 return cid; }
/** Helper function. Get the next available itemId for the item. Reads all existing ItemIds for the specified DscId, then calculates last+1 or first-1 depending on aPos. Will never return 0 as its reserved to mean not yet persistent. */ TInt CDscDatabase::GetNextItemIdL(TDscPosition aPos, const TUid& aDscId) const { RDbView view; CleanupClosePushL(view); RBuf sqlCmd; CleanupClosePushL(sqlCmd); sqlCmd.CreateL(KSqlQueryAllItemIdsLength); sqlCmd.Format(KSqlQueryAllItemIds, &KItemIdCol, &KItemTable,&KDscIdCol, aDscId, &KItemIdCol ); DebugPrint(sqlCmd); User::LeaveIfError(view.Prepare(iDatabase, sqlCmd)); User::LeaveIfError(view.EvaluateAll()); CleanupStack::PopAndDestroy(&sqlCmd); TInt nextId = 1; //add first item with id=1 and reserve 0 to mean "not yet persistent" if (aPos==ELast && view.LastL()) { //add at ELast: pos =max of itemId+1 view.GetL(); nextId = view.ColInt(1); if(KMaxTInt == nextId) { User::Leave(KErrOverflow); } //increase, make sure to not use 0 as itemid in the database nextId = (-1==nextId) ? (nextId+2) : (nextId+1); } else if (aPos==EFirst && view.FirstL()) { //add at EFirst: pos=min of itemId-1 view.GetL(); nextId = view.ColInt(1); if(KMinTInt == nextId) { User::Leave(KErrUnderflow); } //decrease, but reserve 0 to mean "not yet persistent" nextId = (1==nextId) ? (nextId-2) : (nextId-1); } CleanupStack::PopAndDestroy(&view); return nextId; }
TInt CSCPParamDB :: ListParamsUsedByAppL(RArray <TInt>& aParamIds, const TInt32 aApp) { _SCPDB_LOG(_L("[CSCPParamDB]-> ListParamsUsedByApp() >>>")); RDbView lDBView; CleanupClosePushL(lDBView); HBufC* lSelectQry(NULL); if(aApp == -1) { lSelectQry = HBufC :: NewLC(KSelectAllAscParamID().Length()); lSelectQry->Des().Append(KSelectAllAscParamID); } else { lSelectQry = HBufC :: NewLC(KSelectWhereAppIdByAscParamID().Length() + 15); lSelectQry->Des().Format(KSelectWhereAppIdByAscParamID, aApp); } _SCPDB_LOG(_L("[CSCPParamDB]-> SQL Query: %S"), &lSelectQry->Des()); _SCPDB_LOG(_L("[CSCPParamDB]-> Executing the query...")); __LEAVE_IF_ERROR(lDBView.Prepare(iParameterDB, TDbQuery(lSelectQry->Des()))); __LEAVE_IF_ERROR(lDBView.EvaluateAll()); TInt lErr(KErrNone); TInt lStatus(KErrNone); TRAP(lErr, lStatus = lDBView.FirstL()); _SCPDB_LOG(_L("[CSCPParamDB]-> Fetching values for the column KColParamId")); if(lErr == KErrNone && lStatus) { do { lDBView.GetL(); TInt lPID = lDBView.ColInt(iColSet->ColNo(KColParamId)); if(aParamIds.Find(lPID) == KErrNotFound) { aParamIds.AppendL(lPID); } } while(lDBView.NextL()); } _SCPDB_LOG(_L("[CSCPParamDB]-> Query execution complete...")); CleanupStack :: PopAndDestroy(2); _SCPDB_LOG(_L("[CSCPParamDB]-> ListParamsUsedByApp() <<<")); return KErrNone; }
TInt CSCPParamDB :: ListEntriesL(RArray <TInt32>& aNumCols, RPointerArray <HBufC>& aDesCols, const TInt32 aApp) { _SCPDB_LOG(_L("[CSCPParamDB]-> ListEntries() >>>")); RDbView lDBView; CleanupClosePushL(lDBView); HBufC* lSelectQry(NULL); if(aApp == -1) { lSelectQry = HBufC :: NewLC(KSelectAll().Length() + 50); lSelectQry->Des().Format(KSelectAll); } else { lSelectQry = HBufC :: NewLC(KSelectWhereAppId().Length() + 30); lSelectQry->Des().Format(KSelectWhereAppId, aApp); } __LEAVE_IF_ERROR(lDBView.Prepare(iParameterDB, TDbQuery(*lSelectQry))); __LEAVE_IF_ERROR(lDBView.EvaluateAll()); TInt lRet(KErrNone); TBool lStatus(EFalse); TRAP(lRet, lStatus = lDBView.FirstL()); if(lRet == KErrNone && lStatus) { do { lDBView.GetL(); aNumCols.AppendL(lDBView.ColInt(iColSet->ColNo(KColParamId))); aNumCols.AppendL(lDBView.ColInt(iColSet->ColNo(KColAppId))); aNumCols.AppendL(lDBView.ColInt(iColSet->ColNo(KColValueInt))); TPtrC lValueDes = lDBView.ColDes16(iColSet->ColNo(KColValueDes)); HBufC* lBuff = HBufC :: NewL(lValueDes.Length()); lBuff->Des().Append(lValueDes); aDesCols.AppendL(lBuff); } while(lDBView.NextL()); } _SCPDB_LOG(_L("[CSCPParamDB]-> ListEntries() <<<")); CleanupStack :: PopAndDestroy(2); return KErrNone; }