// ---------------------------------------------------------
// RFavouritesSrvTable::SetUrlL
// ---------------------------------------------------------
//
void RFavouritesSrvTable::SetUrlL( const TDesC& aUrl )
{
    RDbColWriteStream stream;
    stream.OpenLC( *this, iColNoUrl );
    stream.WriteL( aUrl, aUrl.Length() );
    stream.CommitL();
    CleanupStack::PopAndDestroy();  // stream;
}
Exemple #2
0
// write rows equivalent to TypeText and use its tests
void TestPredicate2::RunL()
	{
	Create(TypeLongText::KType);
	TBuf<1022> fill=_S("abcdefghijklmnopqrstuvqxyz");
	fill.AppendFill('.',fill.MaxLength()-fill.Length());

	for (TInt row=0;row<=TInt(elementsof(TypeText::KValues));++row)
		{
		TheTable.InsertL();
		TheTable.SetColL(1,row);
		if (row>0)
			{
			RDbColWriteStream blob;
			blob.OpenLC(TheTable,2);
			switch (row)
				{
			case 0:
				break;
			case 1: case 2: case 3: case 4: case 5: case 10: case 11:
				blob.WriteL(TPtrC(TypeText::KValues[row-1]));
				break;
			case 6:
				blob.WriteL(fill);
				blob.WriteL(_L("like"));
				break;
			case 7:
				blob.WriteL(_L("like"));
				blob.WriteL(fill);
				break;
			case 8:
				blob.WriteL(fill);
				blob.WriteL(_L("like"));
				blob.WriteL(fill);
				break;
			case 9:
				blob.WriteL(fill);
				blob.WriteL(_L("live"));
				blob.WriteL(fill);
				break;
				}
			blob.CommitL();
			CleanupStack::PopAndDestroy();
			}
		TheTable.PutL();
		}
	TheTable.Close();
	TInt r=TheDatabase.Commit();
	TEST2(r, KErrNone);
	TestViewL(TypeText::KTests,elementsof(TypeText::KTests),elementsof(TypeText::KValues));
	CDbKey& key=*CDbKey::NewLC();
	key.AddL(TDbKeyCol(_L("Test"),120));
	r=TheDatabase.CreateIndex(_L("Key"),_L("Compare"),key);
	TEST2(r, KErrNone);
	CleanupStack::PopAndDestroy();
	TestViewL(TypeText::KTests,elementsof(TypeText::KTests),elementsof(TypeText::KValues));
	r=TheDatabase.Execute(_L("DROP TABLE Compare"));
	TEST2(r, KErrNone);
	}
// ---------------------------------------------------------
// RFavouritesSrvTable::SetExtraDataL
// ---------------------------------------------------------
//
void RFavouritesSrvTable::SetExtraDataL( MStreamBuf& aSource )
{
    RDbColWriteStream ws;
    ws.OpenLC( *this, iColNoExtraData );
    RReadStream rs( &aSource );
    ws.WriteL( rs );
    ws.CommitL();
    CleanupStack::PopAndDestroy();  // Close ws
}
// ---------------------------------------------------------------------------
// CIRNmsLogDb:AddNmsLogStartL()
// adds the NmsLog log entry into data base
// ---------------------------------------------------------------------------
//
void CIRNmsLogDb::AddNmsLogStartL( CIRNmsLogger& aNmsLog )
    {
    IRLOG_DEBUG( "CIRNmsLogDb::AddNmsLogStartL" );
    OpenDbL();
    RDbTable nmsLogtable;
    TInt error=nmsLogtable.Open( iNmsLogDb, KNmsLogTable, nmsLogtable.
        EUpdatable );
    CleanupClosePushL( nmsLogtable );
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    
    //! arrange the presets in incresing order of index
    nmsLogtable.SetIndex( KNmsLogIndex );
    nmsLogtable.Reset();

    //if NmsLog log is greater or equal to than 5
    if ( nmsLogtable.CountL() >= KMaxNoNmsLog )
        {
        //first row is selected
        nmsLogtable.FirstL();
        //the current row is selected
        nmsLogtable.GetL();
        //delete that entry
        nmsLogtable.DeleteL();
        }    
    CleanupStack::PopAndDestroy( &nmsLogtable );
    //Algorithm : else condition need not handle seperatly
    //Algorithm : add NmsLogid and informations like
    //starttime,connectedfrom,NmsLogid,connectiontype,channelid
    //currentnetwork,homenetwork,NmsLogtable 
    //Algorithm: if no. of NmsLog is greater than 5

    _LIT( query, "SELECT * FROM %S" );    
    HBufC* sqlStr=HBufC::NewLC( query().Length() + KNmsLogTable().Length() );
    sqlStr->Des().Format( query, &KNmsLogTable );
    
    // Create a view on the database
    RDbView view;     
    error = view.Prepare( iNmsLogDb, *sqlStr );
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    CleanupStack::PopAndDestroy( sqlStr );     
    CleanupClosePushL( view );
    error = view.EvaluateAll();
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    CDbColSet* columns = view.ColSetL();
    CleanupStack::PushL( columns );
    
    RDbColWriteStream writeStream;
    TRAP( error, //trap start
       // Insert a row. Column order matches sql select statement
        view.InsertL();
        //get index
        view.SetColL( columns->ColNo( KID ), aNmsLog.NmsLogId() );    
        //!open stream
        writeStream.OpenLC( view, columns->ColNo( KNmsLogCol ) );
        aNmsLog.ExternalizeL( writeStream );
        writeStream.CommitL();
        CleanupStack::PopAndDestroy( &writeStream );
         );
void InsertTrackTableL()
	{	
	HBufC* randomDataBuf = HBufC::NewLC(KTestBlobSize);
	TPtr randomData(randomDataBuf->Des());
	FillRandomData(randomData);
	
	RDbView view;
	TInt err = view.Prepare(TheDatabase, _L("select * from TRACKS"), view.EInsertOnly);
	TEST2(err, KErrNone);
	TheRowSet = view;	
	
	CDbColSet* colSet = TheRowSet.ColSetL();
	const TInt KIdIdx = colSet->ColNo(KId);
	const TInt KLastNameIdx = colSet->ColNo(KLastName);
	const TInt KFirstNameIdx = colSet->ColNo(KFirstName);
	const TInt KTitleIdx = colSet->ColNo(KTitle);
	const TInt KDownloadSiteIdx = colSet->ColNo(KDownloadSite);
	const TInt KBandNameIdx = colSet->ColNo(KBandName);
	const TInt KOriginIdx = colSet->ColNo(KOrigin);
	const TInt KAutoStartIdx = colSet->ColNo(KAutoStart);
	const TInt KInitVolumeIdx = colSet->ColNo(KInitVolume);
	const TInt KMarkedToPlayIdx = colSet->ColNo(KMarked2Play);
	const TInt KCategoryIdIdx = colSet->ColNo(KCategoryId);
	//const TInt KMusicFileIdx = colSet->ColNo(KMusicFile);
	delete colSet;
	colSet = NULL;

	err = TheDatabase.Begin();
	TEST2(err, KErrNone);
	
	for (TInt ii=1;ii<=KTrackRecordCount;++ii)
		{
		TheRowSet.InsertL();
		TheRowSet.SetColL(KIdIdx, ii);
		TheRowSet.SetColL(KLastNameIdx, _L("Dummy"));
		TheRowSet.SetColL(KFirstNameIdx,_L("Dummy"));
		TheRowSet.SetColL(KTitleIdx,_L("Dummy"));
		TheRowSet.SetColL(KDownloadSiteIdx,_L("Dummy"));
		TheRowSet.SetColL(KBandNameIdx,_L("Dummy"));
		TheRowSet.SetColL(KOriginIdx,_L("Dummy"));
		TheRowSet.SetColL(KAutoStartIdx,(ii%2));
		TheRowSet.SetColL(KInitVolumeIdx,(ii%2));
		TheRowSet.SetColL(KMarkedToPlayIdx,(ii%2));
		TheRowSet.SetColL(KCategoryIdIdx,(ii%KCategoryRecordCount));

		//RDbColWriteStream musicfile;
		//musicfile.OpenLC(TheRowSet, KMusicFileIdx);
		//musicfile.WriteL(randomData,KTestBlobSize);
		//musicfile.CommitL();
		//CleanupStack::PopAndDestroy(&musicfile);

		TheRowSet.PutL();
		}

	err = TheDatabase.Commit();
	TEST2(err, KErrNone);

	//err = TheDatabase.Compact();
	//TEST2(err, KErrNone);

	TheRowSet.Close();	

	////////////////////////////////////////////////////////////////////////////////////////////////

	err = view.Prepare(TheDatabase, _L("select * from TRACKS2"), view.EInsertOnly);
	TEST2(err, KErrNone);
	TheRowSet = view;	
	
	colSet = TheRowSet.ColSetL();
	const TInt KIdIdx2 = colSet->ColNo(KId);
	const TInt KMusicFileIdx2 = colSet->ColNo(KMusicFile);
	delete colSet;

	err = TheDatabase.Begin();
	TEST2(err, KErrNone);

	for (TInt ii=1;ii<=KTrackRecordCount;++ii)
		{
		TheRowSet.InsertL();
		TheRowSet.SetColL(KIdIdx2, ii);
		
		RDbColWriteStream musicfile;
		musicfile.OpenLC(TheRowSet, KMusicFileIdx2);
		musicfile.WriteL(randomData,KTestBlobSize);
		musicfile.CommitL();
		CleanupStack::PopAndDestroy(&musicfile);
		
		TheRowSet.PutL();
		}

	err = TheDatabase.Commit();
	TEST2(err, KErrNone);

	//err = TheDatabase.Compact();
	//TEST2(err, KErrNone);

	TheRowSet.Close();	

	CleanupStack::PopAndDestroy(randomDataBuf);
	}
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();
	}