// --------------------------------------------------------- // RFavouritesSrvTable::GetExtraDataL // --------------------------------------------------------- // void RFavouritesSrvTable::GetExtraDataL( MStreamBuf& aSink ) { RDbColReadStream rs; rs.OpenLC( *this, iColNoExtraData ); RWriteStream ws( &aSink ); rs.ReadL( ws ); CleanupStack::PopAndDestroy(); // Close rs }
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 }
// --------------------------------------------------------- // RFavouritesSrvTable::GetBrowserDataL // --------------------------------------------------------- // void RFavouritesSrvTable::GetBrowserDataL( MStreamBuf& aSink ) { if ( iColNoBrowserData != KDbNullColNo ) { RDbColReadStream rs; rs.OpenLC( *this, iColNoBrowserData ); RWriteStream ws( &aSink ); rs.ReadL( ws ); CleanupStack::PopAndDestroy(); // Close rs } }
// --------------------------------------------------------- // RFavouritesSrvTable::UrlLC // --------------------------------------------------------- // HBufC* RFavouritesSrvTable::UrlLC() const { // URL is long column. RDbColReadStream stream; TInt len = ColLength( iColNoUrl ); HBufC* buf = HBufC::NewLC( len ); if ( len ) { stream.OpenLC( *this, iColNoUrl ); TPtr ptr = buf->Des(); stream.ReadL( ptr, len ); CleanupStack::PopAndDestroy(); // Close stream } return buf; }
// --------------------------------------------------------------------------- // Read out the text at the current row and at a specific column // --------------------------------------------------------------------------- // HBufC* CMPXHarvesterDatabaseTable::ReadLongTextLC( TInt aColumn ) { TInt len = iView.ColLength( aColumn ); HBufC* buf = HBufC::NewLC(len); TPtr value( buf->Des() ); if ( len>0 ) { RDbColReadStream strm; strm.OpenLC(iView, aColumn ); strm.ReadL( value, len ); strm.Close(); CleanupStack::PopAndDestroy( &strm ); } return buf; }
// ----------------------------------------------------------------------------- // CUpnpTableBean::ReadLongTextColL // (other items were commented in a header). // ----------------------------------------------------------------------------- // HBufC8* CUpnpTableBean::ReadLongTextColL(const RDbRowSet& aRowSet, const TInt aColNo) { // prepare buffer TInt colLen = aRowSet.ColLength(aColNo); HBufC8* tmp = HBufC8::NewLC(colLen); TPtr8 tmpPtr(tmp->Des()); // read RDbColReadStream colReadStream; colReadStream.OpenLC(aRowSet, aColNo); colReadStream.ReadL(tmpPtr, colLen); // as the length of the HBufC can be grater than requested // clean up CleanupStack::PopAndDestroy(&colReadStream); CleanupStack::Pop(tmp); return tmp; }
// --------------------------------------------------------------------------- // CNSmlDmFotaAdapterDb::LongStrValueL() // Returns the value in FW object identified by aObject in column aColumn. // --------------------------------------------------------------------------- // HBufC8* CNSmlDmFotaAdapterDb::LongStrValueL( const TDesC& aColumn, const TNSmlDmFwObjectId aObject ) { DBG_ARGS( _S16("CNSmlDmFotaAdapterDb::LongStrValueL('%S', %d): begin"), &aColumn, aObject ); HBufC8* value = NULL; FetchRowL( aObject ); if ( iView.FirstL() ) { // get value iView.GetL(); RDbColReadStream rStream; rStream.OpenL( iView, iColSet->ColNo( aColumn ) ); CleanupClosePushL( rStream ); TInt length = 0; TRAPD( err, length = rStream.ReadInt32L() ); HBufC* buf = HBufC::NewLC( length ); TPtr bufPtr = buf->Des(); if ( err == KErrNone ) { rStream.ReadL( bufPtr, length ); } // convert to 8-bit value = HBufC8::NewL( bufPtr.Length() ); value->Des().Copy( bufPtr ); CleanupStack::PopAndDestroy( buf ); CleanupStack::PopAndDestroy( &rStream ); } _DBG_FILE("CNSmlDmFotaAdapterDb::LongStrValueL(): end"); return value; }
// --------------------------------------------------------------------------- // CFotaDB::RowToStateL // Extracts db row contents to package state object and aPkgUrl // Returns url in aPkgURL parameter // --------------------------------------------------------------------------- TPackageState CFotaDB::RowToStateL(HBufC8*& aPkgUrl, const RDbView& aView) { TPackageState s; TInt pkgid = aView.ColInt(iColSet->ColNo(KColPkgId)); TInt state = aView.ColInt(iColSet->ColNo(KColState)); TInt result = aView.ColInt(iColSet->ColNo(KColResult)); TSmlProfileId profileid(aView.ColInt(iColSet->ColNo(KColProfileId))); TPtrC pkgname = aView.ColDes(iColSet->ColNo(KColPkgName)); TPtrC version = aView.ColDes(iColSet->ColNo(KColVersion)); TInt smltrycount = aView.ColInt(iColSet->ColNo(KColSmlTryCount)); TInt sessiontype = aView.ColInt(iColSet->ColNo(KColSessionType)); TInt iapid = aView.ColInt(iColSet->ColNo(KColIapId)); TUint pkgsize = aView.ColUint(iColSet->ColNo(KColPkgSize)); TBool updateltr = aView.ColUint8(iColSet->ColNo(KColUpdateLtr)); s.iPkgId = pkgid; s.iPkgName.Copy(pkgname); s.iPkgVersion.Copy(version); s.iProfileId = profileid; s.iResult = result; s.iState = RFotaEngineSession::TState(state); s.iSmlTryCount = smltrycount; s.iSessionType = sessiontype; s.iIapId = iapid; s.iPkgSize = pkgsize; s.iUpdateLtr = updateltr; RDbColReadStream rstream; TInt len = aView.ColLength(iColSet->ColNo(KColPkgUrl)); rstream.OpenLC(aView, iColSet->ColNo(KColPkgUrl)); HBufC* pkgurl = HBufC::NewLC(len); TPtr ptr = pkgurl->Des(); rstream.ReadL(ptr, len); HBufC8* tmp = HBufC8::NewL(pkgurl->Des().Length()); tmp->Des().Copy(pkgurl->Des()); aPkgUrl = tmp; CleanupStack::PopAndDestroy(pkgurl); CleanupStack::PopAndDestroy(&rstream); return s; }
/** @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 ); }
static int read_game(void *ctx, void *buf, int len) { RDbColReadStream *s = (RDbColReadStream*)ctx; TPtr8 p((TUint8*)buf, len); TRAPD(error, s->ReadL(p)); return error == KErrNone; }
static void TblCallTestL() { TheTest.Next(_L("Open()")); TInt err = TheTbl1.Open(TheDb1, KTableName1); TEST2(err, KErrNone); TheTest.Next(_L("ColSetL()")); CDbColSet* colset = TheTbl1.ColSetL(); TInt cnt = colset->Count(); TInt i; for(i=0;i<cnt;++i) { const TDbCol& dbc = (*colset)[i + 1]; TheTest.Printf(_L("%02d, %S\n"), i + 1, &dbc.iName); } delete colset; TheTest.Next(_L("ColDef()")); TDbCol dbcol = TheTbl1.ColDef(1); TheTest.Printf(_L("%S\n"), &dbcol.iName); TheTest.Next(_L("InsertL()/SetColL()/PutL()")); TheTbl1.InsertL(); TheTbl1.SetColL(2, 1); TheTbl1.SetColL(3, 2); TheTbl1.PutL(); TheTbl1.InsertL(); TheTbl1.SetColL(2, 3); TheTbl1.SetColL(3, 4); TheTbl1.PutL(); TheTest.Next(_L("AtRow()/AtBeginning()/AtEnd()")); (void)TheTbl1.AtRow(); (void)TheTbl1.AtBeginning(); (void)TheTbl1.AtEnd(); TheTest.Next(_L("BeginningL()/EndL()")); TheTbl1.BeginningL(); TheTbl1.EndL(); TheTest.Next(_L("FirstL()/LastL()/PreviousL()/PreviousL()")); TBool res = TheTbl1.FirstL(); TEST(res); TheTbl1.GetL(); TInt32 val1 = TheTbl1.ColInt32(1); TInt32 val2 = TheTbl1.ColInt32(2); TInt32 val3 = TheTbl1.ColInt32(3); TEST(val1 == 0); TEST(val2 == 1); TEST(val3 == 2); res = TheTbl1.LastL(); TEST(res); TheTbl1.GetL(); val1 = TheTbl1.ColInt32(1); val2 = TheTbl1.ColInt32(2); val3 = TheTbl1.ColInt32(3); TEST(val1 == 1); TEST(val2 == 3); TEST(val3 == 4); res = TheTbl1.PreviousL(); TEST(res); TheTbl1.GetL(); val1 = TheTbl1.ColInt32(1); val2 = TheTbl1.ColInt32(2); val3 = TheTbl1.ColInt32(3); TEST(val1 == 0); TEST(val2 == 1); TEST(val3 == 2); res = TheTbl1.NextL(); TEST(res); TheTbl1.GetL(); val1 = TheTbl1.ColInt32(1); val2 = TheTbl1.ColInt32(2); val3 = TheTbl1.ColInt32(3); TEST(val1 == 1); TEST(val2 == 3); TEST(val3 == 4); TheTest.Next(_L("UpdateL()")); TheTbl1.UpdateL(); TheTbl1.SetColL(2, 33); TheTbl1.SetColL(3, 44); TheTbl1.PutL(); TheTest.Next(_L("Cancel()")); TheTbl1.UpdateL(); TheTbl1.SetColL(2, 36); TheTbl1.SetColL(3, 47); TheTbl1.Cancel(); TheTest.Next(_L("DeleteL()")); TheTbl1.DeleteL(); TheTest.Next(_L("IsColNull()")); CDbColSet* colset2 = TDBSCUtils::CreateColSetLC(KColumns2); _LIT(KTempTblName, "TempTbl"); err = TheDb1.CreateTable(KTempTblName, *colset2); TEST2(err, KErrNone); CleanupStack::PopAndDestroy(colset2); err = TheTbl2.Open(TheDb1, KTempTblName); TEST2(err, KErrNone); TheTbl2.InsertL(); _LIT8(KTestData, ""); TheTbl2.SetColL(2, KTestData); TheTbl2.PutL(); TheTbl2.Close(); err = TheTbl2.Open(TheDb1, KTempTblName); TEST2(err, KErrNone); res = TheTbl2.FirstL(); TEST(res); TheTbl2.GetL(); res = TheTbl2.IsColNull(2); TEST(res); TheTbl2.Close(); TheTest.Next(_L("ColSize()")); res = TheTbl1.FirstL(); TEST(res); TheTbl1.GetL(); res = TheTbl1.ColSize(1); TEST(res); TheTest.Next(_L("ColLength()")); TInt len = TheTbl1.ColLength(1); TEST(len > 0); TheTbl1.InsertL(); TheTbl1.SetColL(2, 3); TheTbl1.SetColL(3, 4); TheTbl1.PutL(); TheTest.Next(_L("GotoL(TPosition)")); res = TheTbl1.GotoL(RDbRowSet::EFirst); TEST(res); TheTest.Next(_L("Bookmark()/GotoL(TDbBookmark)")); TDbBookmark bkmk = TheTbl1.Bookmark(); res = TheTbl1.NextL(); TEST(res); TheTbl1.GotoL(bkmk); TheTbl1.GetL(); val1 = TheTbl1.ColInt32(1); TEST(val1 == 0); TheTest.Next(_L("CountL()/IsEmptyL()")); cnt = TheTbl1.CountL(); TEST(cnt == 2); res = TheTbl1.IsEmptyL(); TEST(!res); TheTest.Next(_L("MatchL()")); RDbRowConstraint match; CleanupClosePushL(match); err = match.Open(TheTbl1, TDbQuery(_L("ID > 0"))); TEST2(err, KErrNone); res = EFalse; TheTbl1.BeginningL(); while(TheTbl1.NextL()) { if(TheTbl1.MatchL(match)) { res = ETrue; } } CleanupStack::PopAndDestroy(&match); TEST(res); TheTest.Next(_L("FindL()")); res = TheTbl1.FirstL(); TEST(res); err = TheTbl1.FindL(RDbRowSet::EForwards, TDbQuery(_L("ID <> 0"))); TEST(err >= 0); TheTbl1.GetL(); val1 = TheTbl1.ColInt32(1); TEST(val1 > 0); _LIT8(KTestData2, "0123456789"); HBufC8* buf = HBufC8::NewLC(10000); TPtr8 ptr = buf->Des(); for(i=0;i<1000;++i) { ptr += KTestData2(); } TheTest.Next(_L("RDbColReadStream")); err = TheTbl2.Open(TheDb1, KTempTblName); TEST2(err, KErrNone); TheTbl2.InsertL(); TheTbl2.SetColL(2, *buf); TheTbl2.PutL(); TheTbl2.InsertL(); TheTbl2.SetColL(2, KTestData2); TheTbl2.PutL(); res = TheTbl2.PreviousL(); TEST(res); TheTbl2.GetL(); RDbColReadStream rstream; rstream.OpenLC(TheTbl2, 2); ptr.Zero(); rstream.ReadL(ptr, ptr.MaxLength()); CleanupStack::PopAndDestroy(&rstream); TEST(ptr.Length() == ptr.MaxLength()); TheTest.Next(_L("RDbColWriteStream")); TheTbl2.InsertL(); RDbColWriteStream wstream; wstream.OpenLC(TheTbl2, 2); wstream.WriteL(ptr, ptr.Length()); wstream.CommitL(); CleanupStack::PopAndDestroy(&wstream); TheTbl2.PutL(); TheTbl2.Close(); CleanupStack::PopAndDestroy(buf); TheTbl1.Close(); }