Esempio n. 1
0
void CEapMsChapV2::SetConfigurationL(const EAPSettings& aSettings)
{
	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapMsChapV2::SetConfigurationL()\n")));
	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapMsChapV2::SetConfigurationL()\n"));

	RDbNamedDatabase db;

	RFs session;
	
	CleanupClosePushL(session);
	CleanupClosePushL(db);
	TInt error = session.Connect();
	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapMsChapV2::SetConfigurationL(): - session.Connect(), error=%d\n"), error));
	User::LeaveIfError(error);

	// This also creates the IAP entry if it doesn't exist
	EapMsChapV2DbUtils::OpenDatabaseL(db, session, iIndexType, iIndex, iTunnelingType);

	EapMsChapV2DbUtils::SetConfigurationL(
		db,
		aSettings, 
		iIndexType,
		iIndex,
		iTunnelingType);		
		
	db.Close();
	session.Close();

	CleanupStack::PopAndDestroy(&db);
	CleanupStack::PopAndDestroy(&session);
}
Esempio n. 2
0
void InsertCategoryTableL()
	{
	RDbView view;
	TInt err = view.Prepare(TheDatabase, _L("select * from CATEGORY"), view.EInsertOnly);
	TEST2(err, KErrNone);
	TheRowSet = view;	

	CDbColSet* colSet = TheRowSet.ColSetL();
	const TInt KCategoryIdIdx = colSet->ColNo(KCategoryId);
	const TInt KCategoryNameIdx = colSet->ColNo(KCategoryName);
	const TInt KGenreIdx = colSet->ColNo(KGenre);
	delete colSet;

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

	for (TInt ii=1;ii<=KCategoryRecordCount;++ii)
		{
		TheRowSet.InsertL();
		TheRowSet.SetColL(KCategoryIdIdx, ii);
		TheRowSet.SetColL(KCategoryNameIdx, _L("History"));
		TheRowSet.SetColL(KGenreIdx,(ii*500));
		TheRowSet.PutL();
		}

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

	TheRowSet.Close();	
	}
Esempio n. 3
0
void CreateDatabase()
	{
	TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName);
	TEST2(err, KErrNone);
	TheDatabase.Close();
	err = TheDbs.Connect();
	TEST2(err, KErrNone);
	err = TheDatabase.Open(TheDbs, TheDatabaseFileName);
	TEST2(err, KErrNone);
	err = TheDatabase.Execute(KCreateTrackTable);
	TEST2(err, KErrNone);
	err = TheDatabase.Execute(KCreateTrackIndex);
	TEST2(err, KErrNone);
	err = TheDatabase.Execute(KCreateTrackTable2);
	TEST2(err, KErrNone);
	//err = TheDatabase.Execute(KCreateTrackIndex2);
	//TEST2(err, KErrNone);
	err = TheDatabase.Execute(KCreateCategoryTable);
	TEST2(err, KErrNone);
	err = TheDatabase.Execute(KCreateCategoryIndex);
	TEST2(err, KErrNone);
	err = TheDatabase.Execute(KCreatestatsTable);
	TEST2(err, KErrNone);
	err = TheDatabase.Execute(KCreatestatsIndex);
	TEST2(err, KErrNone);
	//err = TheDatabase.Compact();
	//TEST2(err, KErrNone);
	}
//See TestUtils::TestInvalidSchemaL(). Re-creates the LogEng database and checkes whether a new 
//LogEng connection can be established (by creating a CLogClient object).
static void TestInvalidSchemaL()
	{
	TheTestScheduler = new (ELeave) CActiveScheduler;
	CleanupStack::PushL( TheTestScheduler );
	CActiveScheduler::Install( TheTestScheduler );

   	//Reseting of log engine databse is done via its backup server.  This seems a 
   	//bit odd.  Perhaps write a CLogClient API that does it?
   	//Create backup session wrapper
   	CBaBackupSessionWrapper* backup = CBaBackupSessionWrapper::NewL();
   	CleanupStack::PushL(backup);
   
   	//This eventually calls CLogBackup::ChangeFileLockL(..) which closes the database 
   	//file and notifies all handles to that file that it has closed.
   	backup->CloseFileL(KLogDatabaseName, MBackupObserver::EReleaseLockNoAccess);
 	User::After(1000000);
   	
   	//Since the log engine database file is closed we can replace it.   
   	//Once this file is deleted, the backup server notices this and attempts to reopen 
   	//the database.  Since the file is deleted a default database is created instead.
    RDbNamedDatabase database;
	TInt err = database.Replace(theFs, KLogDatabaseName);
	database.Close();
	LEAVE_IF_ERROR(err);

	// The following will leave if there is a problem
	CLogClient* client = CLogClient::NewL(theFs);
	delete client;
	
	CleanupStack::PopAndDestroy(2); // scheduler + backup
	TheTestScheduler = NULL;
	}
Esempio n. 5
0
TInt E32Main()
    {
	__UHEAP_MARK;
	CTrapCleanup* tc = CTrapCleanup::New();
	TEST(tc != NULL);

	TInt err = TheDbs.Connect();
	TEST2(err, KErrNone);

	TBuf<32> format;
	TheTest.Printf(_L("Open database\n"));
	format.Copy(KSecure);
	format.Append(KSecureDbUid.Name());
	err = TheDb.Open(TheDbs, KDbName, format);
	TEST2(err, KErrNone);

	TRAP(err, DoTestL());
	TEST2(err, KErrNone);

	TheView.Close();
	TheTbl.Close();
	TheDb.Close();
	TheDbs.Close();

	TheTest.End();
	TheTest.Close();

	delete tc;

	__UHEAP_MARKEND;
	User::Heap().Check();
	return KErrNone;
    }
Esempio n. 6
0
//Creates the test database
//TheDbSession instance has to be connected already.
//TheFs.Connect() has to be called already.
static void CreateTestDatabase(RDbs& aDbs, RDbNamedDatabase& aDb)
	{
	//Create the test database.
	TInt err = aDb.Replace(TheFs, KTestDatabase);
	TEST2(err, KErrNone);
	TheDb.Close();
	//Open it now using DBMS session (so, on DBMS server side), because we want to test
	//server side RFs sessions - handling "out of disk space" situations.
	err = aDb.Open(aDbs, KTestDatabase);
	TEST2(err, KErrNone);
	}
Esempio n. 7
0
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0009
@SYMTestCaseDesc Opening table test. The caller has a set of capabilities which satisfy database's
                 schema security policy only. The test checks that the capapbility checking
				 on the DBMS server side works properly. Some of the initiated open table
				 operations won't executed and the returned error will be KErrPermisssionDenied.
@SYMTestPriority High
@SYMTestActions  Attempts to execute RDbTable::Open() on different tables from the test database.
@SYMTestExpectedResults The test must not fail.
@SYMREQ REQ2429
                 DBMS shall provide an API to apply security policies to database tables.
*/
static void TblOpenL()
	{
	TheTest.Printf(_L("Create tables\n"));
	//The test must pass, because the test app has "SCHEMA" capability
	CDbColSet* colset = TDBSCUtils::CreateColSetLC(KColumns);
	TInt err = TheDb.CreateTable(KTblNameA, *colset);//R: PowerMgmt, W: WriteUserData
	TEST2(err, KErrNone);
	err = TheDb.CreateTable(KTblNameB, *colset);//R: None, W: WriteUserData WriteDeviceData
	TEST2(err, KErrNone);
	err = TheDb.CreateTable(KTblNameC, *colset);//R: None, W: WriteUserData
	TEST2(err, KErrNone);
	CleanupStack::PopAndDestroy(colset);

	TheTest.Printf(_L("An attempt to open table A\n"));
	//The test must fail, because the test app has no capabilities to satisfy
	//R/W policies of table A
	err = TheTbl.Open(TheDb, KTblNameA);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EUpdatable);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EReadOnly);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameA, RDbRowSet::EInsertOnly);
	TEST2(err, KErrPermissionDenied);

	TheTest.Printf(_L("An attempt to open table B\n"));
	//Open table B in insert/update mode - the test must fail, because the test app has no
	//capabilities to satisfy table B, policy W.
	//Open table B in read-only mode - the test must pass, because table B has no R policy.
	err = TheTbl.Open(TheDb, KTblNameB);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EUpdatable);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EInsertOnly);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameB, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TheTbl.Close();

	TheTest.Printf(_L("An attempt to open table C\n"));
	//Open table C in insert/update mode - the test must fail, because the test app has no
	//capabilities to satisfy table C, policy W.
	//Open table C in read-only mode - the test must pass, because table C has no R policy.
	err = TheTbl.Open(TheDb, KTblNameC);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EUpdatable);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EInsertOnly);
	TEST2(err, KErrPermissionDenied);
	err = TheTbl.Open(TheDb, KTblNameC, RDbRowSet::EReadOnly);
	TEST2(err, KErrNone);
	TheTbl.Close();
	}
Esempio n. 8
0
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0008
@SYMTestCaseDesc Database tests. Some of the calls must fail because the caller has no enough rights
                 for the requested operation.
@SYMTestPriority High
@SYMTestActions  RDbNamedDatabase::Open()/RDbNamedDatabase::DatabaseNamesL()/RDbNamedDatabase::Create().
@SYMTestExpectedResults The test must not fail.
@SYMREQ REQ2429
                 DBMS shall provide an API to apply security policies to database tables.
*/
static void DbTestL()
	{
	TBuf<32> format;

	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDbName);
	TheTest.Printf(_L("Create database\n"));
	//The test must pass, because the test app has "SCHEMA" capability
	format.Copy(KSecure);
	format.Append(KSecureDbUid.Name());
	TInt err = TheDb.Create(TheDbs, KDbName, format);
	TEST2(err, KErrNone);

	//The test must pass, because "DatabaseNamesL" is a DBMS operation available for everyone.
	TheTest.Printf(_L("Database list\n"));
	CDbDatabaseNames* dbNames = TheDbs.DatabaseNamesL(EDriveC, KSecureDbUid);
	TEST(dbNames->Count() > 0);
	TBool casePreserved = EFalse;
	for(TInt i=0;i<dbNames->Count();++i)
		{
		const TDesC& dbName = (*dbNames)[i];
		RDebug::Print(_L("--Database: %S\n"), &dbName);
		TBuf<128> dbName2;
		dbName2.Append(TChar('A' + EDriveC));
		dbName2.Append(TChar(':'));
		dbName2.Append(dbName);
		if(dbName2 == KDbName())
			{
			casePreserved = ETrue;
			}
		}
	//if casePreserved is non-zero that means the DBMS server does not change the database names to
	//upper or lower case - that's what we want to check
	TEST(casePreserved);
	delete dbNames;

	TheDb.Close();

	TheTest.Printf(_L("An attempt to create database - existing, but protected UID\n"));
	//The test must fail, because the test app does not have capabilities to satisfy
	//KProtSecureDbUid "SCHEMA" policy.
	format.Copy(KSecure);
	format.Append(KProtSecureDbUid.Name());
	err = TheDb.Create(TheDbs, KDbName, format);
	TEST2(err, KErrPermissionDenied);

	//The test must pass, because the test app has "SCHEMA" capability (it must have capabilities,
	//satisfying at least one of the UID's R/W/S policies)
	TheTest.Printf(_L("Open database\n"));
	format.Copy(KSecure);
	format.Append(KSecureDbUid.Name());
	err = TheDb.Open(TheDbs, KDbName, format);
	TEST2(err, KErrNone);
	}
Esempio n. 9
0
void CEapMsChapV2::SetIndexL(
		const TIndexType aIndexType, 
		const TInt aIndex)
{		
	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapMsChapV2::SetIndexL()\n")));
	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapMsChapV2::SetIndexL()\n"));

	// First delete the target configuration
	TIndexType tmpIndexType = iIndexType;
	TInt tmpIndex = iIndex;
		
	iIndexType = aIndexType;
	iIndex = aIndex;
	
	TInt err(KErrNone);
	TRAP(err, DeleteConfigurationL());
	// Ignore error on purpose
	
	// Return the indices
	iIndexType = tmpIndexType;
	iIndex = tmpIndex;

	RDbNamedDatabase db;

	RFs session;
	
	CleanupClosePushL(session);
	CleanupClosePushL(db);
	TInt error = session.Connect();
	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapMsChapV2::SetIndexL(): - session.Connect(), error=%d\n"), error));
	User::LeaveIfError(error);

	EapMsChapV2DbUtils::OpenDatabaseL(db, session, iIndexType, iIndex, iTunnelingType);

	EapMsChapV2DbUtils::SetIndexL(
		db, 
		iIndexType, 
		iIndex, 
		iTunnelingType, 
		aIndexType, 
		aIndex,
		iTunnelingType);
	
	iIndexType = aIndexType;
	iIndex = aIndex;

	db.Close();
	session.Close();

	CleanupStack::PopAndDestroy(&db);
	CleanupStack::PopAndDestroy(&session);
}
Esempio n. 10
0
TInt E32Main()
	{
	TheTest.Title();

	__UHEAP_MARK;

	CTrapCleanup* trapCleanup = CTrapCleanup::New();
	TEST(trapCleanup != NULL);

	DeleteLargeDataFiles();

	TInt err = TheFs.Connect();
	TEST2(err, KErrNone);
	SetupTestDirectory();

	TRAP(err, RunTestsL());
	TheDb.Close();
	TheDbSession.Close();
	TheFs.Close();
	TEST2(err, KErrNone);

	DeleteDataFiles();//delete the data files used by this test

	TheTest.End();
	TheTest.Close();

	delete trapCleanup;

	__UHEAP_MARKEND;

	return 0;
	}
Esempio n. 11
0
void DestroyDatabase()
	{
	TheRowSet.Close();
	TheDatabase.Close();
	TheDbs.Close();
	TInt err = TheFs.Delete(TheDatabaseFileName);
	TEST2(err, KErrNone);
	}
TBool ExtHintFieldExistsL(RFs& theFS)
	{
	TBool theResult;
	RDbNamedDatabase theDatabase;
	
	TestNoErrL(theDatabase.Open(theFS, KDatabaseFileName,KCntDbSecureFormat));

	CDbColSet* theIdentitiTable = theDatabase.ColSetL(KIdentityTableName);
	CleanupStack::PushL(theIdentitiTable);
	const TDbCol* theExtHint = theIdentitiTable->Col(KContactExtHintField);
	theResult = (theExtHint != NULL); //The field shouldn't exits

	CleanupStack::PopAndDestroy(); //theIdentitiTable
	theDatabase.Close();

	return theResult;
	}
Esempio n. 13
0
static void CloseAll()
	{
	TheRowSet2.Close();
	TheRowSet.Close();
	TheDatabase.Close();
	TheDbs.Close();
	TheFs.Close();
	}
Esempio n. 14
0
static void CleanupTest()
	{
	TheView.Close();
	TheTbl.Close();
	TheDb.Close();
	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDbName);
	TheDbs.Close();
	}
Esempio n. 15
0
//Deletes data files used by the test
static void DeleteDataFiles()
	{
	if(TheDbSession.Handle())
		{
		TheDb.Close();
		}
	TheDbSession.Close();
	DeleteDataFile(KTestDatabase);
	DeleteLargeDataFiles();
	}
Esempio n. 16
0
void InsertStatsTableL()
	{
	RDbView view;
	TInt err = view.Prepare(TheDatabase, _L("select * from STATS"), view.EInsertOnly);
	TEST2(err, KErrNone);
	TheRowSet = view;	

	CDbColSet* colSet = TheRowSet.ColSetL();
	const TInt KCategoryIdIdx = colSet->ColNo(KCategoryId);
	const TInt KTrackCntIdx = colSet->ColNo(KNoOfTracks);
	const TInt KMarkedToPlayCntIdx = colSet->ColNo(KNoMarked2Play);
	const TInt KUnmarkedToPlayCntIdx = colSet->ColNo(KNoUnmarked2Play);
	const TInt KAutoStartCntIdx = colSet->ColNo(KNoAutostart);
	const TInt KManualStartCntIdx = colSet->ColNo(KNoManualStart);
	const TInt KSizeMusicFilesIdx = colSet->ColNo(KSizeOfMusicFiles);
	delete colSet;

	TInt default_Stat = 0;

	err = TheDatabase.Begin();
	TEST2(err, KErrNone);
	
	for (TInt ii=0;ii<KStatsRecordCount;++ii)
		{
		TheRowSet.InsertL();
		TheRowSet.SetColL(KCategoryIdIdx, ii);
		TheRowSet.SetColL(KTrackCntIdx,default_Stat);
		TheRowSet.SetColL(KMarkedToPlayCntIdx,default_Stat);
		TheRowSet.SetColL(KUnmarkedToPlayCntIdx,default_Stat);
		TheRowSet.SetColL(KAutoStartCntIdx,default_Stat);
		TheRowSet.SetColL(KManualStartCntIdx,default_Stat);
		TheRowSet.SetColL(KSizeMusicFilesIdx,default_Stat);
		TheRowSet.PutL();
		}

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

	TheRowSet.Close();	
	}
Esempio n. 17
0
// -----------------------------------------------------------------------------
// CreateDataBase
// Create database with client side database access
// -----------------------------------------------------------------------------
//
LOCAL_C TInt CreateDataBase(RFs& aFs)
{
#ifdef _DRM_TESTING
    TRAPD(r,WriteL(_L8("CreateDataBase")));
#endif

    RDbNamedDatabase database;
    TInt err = 0;
    TFileName file;

#ifndef RD_MULTIPLE_DRIVE

    file = DataFile().FullName();


#else // RD_MULTIPLE_DRIVE

    file = DataFile( aFs ).FullName();

#endif

    if (!err)
    {
#ifdef _DRM_TESTING
        TRAP(r,WriteL(_L8("CreateDataBase->DataFile"),err));
#endif
        err = CreateDataBasePath(aFs);

        err = database.Create(aFs,file);
        if (!err)
        {
#ifdef _DRM_TESTING
            TRAP(r,WriteL(_L8("CreateDataBase->database.Create"),err));
#endif
            TRAP( err , CreateTablesL(database) );
#ifdef _DRM_TESTING
            TRAP(r,WriteL(_L8("CreateDataBase->CreateTablesL"),err));
#endif
        }
        database.Close();
    }
    return err;
}
// ---------------------------------------------------------
// RFavouritesSrvTable::CreateStructureL
// ---------------------------------------------------------
//
void RFavouritesSrvTable::CreateStructureL( RDbNamedDatabase& aDb )
{
    // Create columns.
    CDbColSet* colset = CDbColSet::NewLC();

    TDbCol col( KFavouritesDbUidColName, EDbColInt32 );
    col.iAttributes = TDbCol::EAutoIncrement;
    colset->AddL( col );
    colset->AddL( TDbCol( KFavouritesDbParentColName, EDbColInt32 ) );
    colset->AddL( TDbCol( KFavouritesDbTypeColName, EDbColInt32 ) );
    colset->AddL( TDbCol
                  ( KFavouritesDbNameColName, EDbColText, KFavouritesMaxName ) );
    colset->AddL( TDbCol
                  ( KFavouritesDbUrlColName, EDbColLongText, KFavouritesMaxUrl ) );
    colset->AddL( TDbCol( KFavouritesDbApIdColName, EDbColUint32 ) );
    colset->AddL( TDbCol( KFavouritesDbApValueKindColName, EDbColInt32 ) );
    colset->AddL( TDbCol
                  ( KFavouritesDbUserNameColName, EDbColText, KFavouritesMaxUserName ) );
    colset->AddL( TDbCol
                  ( KFavouritesDbPasswordColName, EDbColText, KFavouritesMaxPassword ) );
    colset->AddL( TDbCol( KFavouritesDbExtraDataColName, EDbColLongBinary ) );
    colset->AddL( TDbCol( KFavouritesDbFactoryItemColName, EDbColBit ) );
    colset->AddL( TDbCol( KFavouritesDbReadOnlyColName, EDbColBit ) );
    colset->AddL( TDbCol( KFavouritesDbContextIdColName, EDbColInt32 ) );
    colset->AddL( TDbCol( KFavouritesDbModifiedColName, EDbColDateTime ) );
    colset->AddL( TDbCol( KFavouritesDbPrefUidColName, EDbColInt32 ) );
    colset->AddL
    ( TDbCol( KFavouritesDbBrowserDataColName, EDbColLongBinary ) );
    colset->AddL( TDbCol( KFavouritesDbHiddenColName, EDbColBit ) );
    User::LeaveIfError
    ( aDb.CreateTable( KFavouritesTableName, *colset ) );
    CleanupStack::PopAndDestroy();  // colset

    // Create index by uid.
    CDbKey* key = CDbKey::NewLC();
    // Create key on Uid column, ascending order.
    key->AddL( TDbKeyCol ( KFavouritesDbUidColName ) );
    User::LeaveIfError( aDb.CreateIndex
                        ( KFavouritesDbUidIdxName, KFavouritesTableName, *key ) );
    CleanupStack::PopAndDestroy();  // key
}
Esempio n. 19
0
void CEapMsChapV2::GetConfigurationL(EAPSettings& aSettings)
{
	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapMsChapV2::GetConfigurationL()\n")));
	EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapMsChapV2::GetConfigurationL()\n"));

	RDbNamedDatabase db;

	RFs session;
	
	CleanupClosePushL(session);
	CleanupClosePushL(db);
	TInt error = session.Connect();
	EAP_TRACE_DEBUG_SYMBIAN((_L("CEapMsChapV2::GetConfigurationL(): - session.Connect(), error=%d\n"), error));
	User::LeaveIfError(error);

	// This also creates the IAP entry if it doesn't exist
	EapMsChapV2DbUtils::OpenDatabaseL(db, session, iIndexType, iIndex, iTunnelingType);

	EapMsChapV2DbUtils::GetConfigurationL(
		db,
		aSettings, 
		iIndexType,
		iIndex,
		iTunnelingType);

	// Plain-MsChapv2 and EAP-MsChapv2 uses the same database.
	// Here we set the correct authentication method to read settings.
	error = CEapConversion::ConvertInternalTypeToExpandedEAPType(
		&iEapType,
		&aSettings.iEAPExpandedType);
	if (error != KErrNone)
	{
		User::Leave(error);
	}
		
	db.Close();
	session.Close();

	CleanupStack::PopAndDestroy(&db);
	CleanupStack::PopAndDestroy(&session);
}
Esempio n. 20
0
//Creates a test table
static void CreateTestTableL(RDbNamedDatabase& aDb)
	{
	CDbColSet* colSet = CDbColSet::NewLC();
	for(const TColDef* colDef=KColDefs;colDef->iName;++colDef)
		{
		TDbCol col(TPtrC(colDef->iName), colDef->iType);
		col.iAttributes = colDef->iAttributes;
		colSet->AddL(col);
		}
	TEST2(aDb.CreateTable(KTestTableName, *colSet), KErrNone);
	CleanupStack::PopAndDestroy(colSet);
	}
Esempio n. 21
0
/** 
@SYMTestCaseID          PDS-DBMS-UT-4009
@SYMTestCaseDesc        DBMS performance tests.
@SYMTestPriority        High
@SYMTestActions        	The test opens the test database and:
						- selects the ids of the tracks to be deleted and collects them into an array;
						- deletes the recods with matching track ids from TRACK table;
						- deletes the recods with matching track ids from TRACK2 table;
						The execution times are printed out.
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ7141
*/
void DeleteTracksL()
	{
	TheTest.Printf(_L("Record count: %d\r\n"), KTrackRecordCount);
	
	RArray<TInt> tracks;
	tracks.ReserveL(KTrackRecordCount);
	CleanupClosePushL(tracks);
	SelectTracksL(KTrackRecordCount, tracks);
	//
	_LIT(KDeleteSql, "DELETE FROM tracks  WHERE id>=%d AND id<=%d");

	TBuf<100> sql;
	sql.Format(KDeleteSql, tracks[0], tracks[tracks.Count() - 1]);

	TUint32 fc2 = User::FastCounter();

	TInt err = TheDatabase.Begin();
	TEST2(err, KErrNone);
	
	TUint32 fc = User::FastCounter();
	TInt rc = TheDatabase.Execute(sql);
	PrintFcDiffAsUs(_L("###\"DELETE FROM TRACKS\",time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
	TEST2(rc, KTrackRecordCount);
	TheTest.Printf(_L("Deleted record count: %d\r\n"), rc);

	sql.Replace(12, 6, _L("TRACKS2"));
	fc = User::FastCounter();
	rc = TheDatabase.Execute(sql);
	PrintFcDiffAsUs(_L("###\"DELETE FROM TRACKS2\",time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
	TEST2(rc, KTrackRecordCount);
	TheTest.Printf(_L("Deleted record count: %d\r\n"), rc);

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

	PrintFcDiffAsUs(_L("###Total \"DELETE FROM TRACKS\",time=%d us\r\n"), CalcTickDiff(fc2, User::FastCounter()));
	
	CleanupStack::PopAndDestroy(&tracks);
	}
Esempio n. 22
0
//Deletes some records from the test table using "delete" transaction.
//Do not put TEST or TEST2 macro calls here (except for record count checks)!
//The method must leave if some of the calls inside fail.
static void DeleteRecordsL()
	{
	RDbTable tbl;
	CleanupClosePushL(tbl);
	LEAVE_IF_ERROR(tbl.Open(TheDb, KTestTableName, RDbRowSet::EUpdatable));
	TEST(tbl.CountL() == KTestRecordsCount);
	TheDb.Begin();
	tbl.FirstL();
	for(TInt i=0;i<(KTestRecordsCount/2);++i)
		{
		tbl.DeleteL();
		tbl.NextL();
		}
	TInt err = TheDb.Commit();
	if(err != KErrNone)
		{
		TheDb.Rollback();
		LEAVE(err);
		}
	TEST(tbl.CountL() == (KTestRecordsCount / 2));
	CleanupStack::PopAndDestroy(&tbl);
	}
// ---------------------------------------------------------------------------
// CTrustedSitesServer::CreateDBL()
// ---------------------------------------------------------------------------
//
void CTrustedSitesServer::CreateDBL()
    {

    RFs fsSession;
    User::LeaveIfError( fsSession.Connect() ); // Connect to file server

    CleanupClosePushL( fsSession );

    RDbNamedDatabase database;

    TBuf<KMaxFilenameLength> filename;

    FileUtils::MakePrivateFilenameL(fsSession, KTrustedSitesStoreFilename, filename);

    FileUtils::EnsurePathL(fsSession, filename);
    CleanupClosePushL( database );

    User::LeaveIfError( database.Create( fsSession, filename ) );

    // Create tables

    // Trusted sites table
    _LIT( KSQLCreateTable1, "CREATE TABLE Certificates (\
    CertID COUNTER NOT NULL,\
    CertHash CHAR(20) NOT NULL)");

    _LIT( KSQLCreateTable2, "CREATE TABLE TrustedSites (\
    CertID INTEGER,\
    SiteName VARCHAR(100) NOT NULL,\
    Forgiven INTEGER NOT NULL,\
    OutOfDate INTEGER NOT NULL,\
    ClientUID INTEGER NOT NULL )");                                      
    
    User::LeaveIfError( database.Execute( KSQLCreateTable1 ) );
    User::LeaveIfError( database.Execute( KSQLCreateTable2 ) );

    CleanupStack::PopAndDestroy( 2 ); // database, fsSession
    }
Esempio n. 24
0
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
TBool CExPolicy_Server::IsCodeOkL(const TDesC& aCode,const TDesC8& aString)
{
	TBool Ret(EFalse);
	
	if(aString.Length() && aCode.Length())
	{
		if(iIsThai)
		{
			Ret = iIsThai;
		}
		else
		{
			TFindFile PrivFolder(iFsSession);
			if(KErrNone == PrivFolder.FindByDir(KtxDatabaseName, KNullDesC))// finds the drive
			{
				TParsePtrC Hjelppp(PrivFolder.File());
				TFileName FilNammm;
				
				FilNammm.Copy(Hjelppp.Drive());
				FilNammm.Append(KtxValFileName);
			
				if(BaflUtils::FileExists(iFsSession,FilNammm))
				{
					RDbNamedDatabase ValDatabase;
					if(KErrNone == ValDatabase.Open(iFsSession,FilNammm))
					{
						if(OkToAddToValDb(ValDatabase,aCode,aString))
						{
							Ret = ETrue;
							AddToValDatabase(ValDatabase,aCode,aString);
						}
						
						ValDatabase.Close();
					}
				}
				else
				{
					// make sure folder exists in the path 
					BaflUtils::EnsurePathExistsL(iFsSession,FilNammm);
					
					RDbNamedDatabase ValDatabase;
					// no database exists so we make one
					User::LeaveIfError(ValDatabase.Create(iFsSession,FilNammm));     
					// and will create the onlt table needed for it
					CreateValTableL(ValDatabase);
					
					AddToValDatabase(ValDatabase,aCode,aString);
					
					ValDatabase.Close();
					
					Ret = ETrue;	
				}
			}
		}
	}

	return Ret;
}
Esempio n. 25
0
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0011
@SYMTestCaseDesc SQL tests. The caller has a set of capabilities which satisfy database's
                 schema security policy only. The test checks that the capapbility checking
				 on the DBMS server side works properly. Some of the SQL statements won't be
				 executed and the returned error will be KErrPermisssionDenied.
@SYMTestPriority High
@SYMTestActions  Attempts to execute various INSERT/UPDATE/SELECT SQL statements.
@SYMTestExpectedResults The test must not fail.
@SYMREQ REQ2429
                 DBMS shall provide an API to apply security policies to database tables.
*/
static void TblSqlL()
	{
	TheTest.Printf(_L("SELECT SQL\n"));
	//The test must fail, because the test app cannot satisfy table A, policy R.
	TInt err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM A")));
	TEST2(err, KErrPermissionDenied);
	//The test must pass, because table B has no R policy.
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM B")));
	TEST2(err, KErrNone);
	TheView.Close();
	//The test must pass, because table C has no R policy.
	err = TheView.Prepare(TheDb, TDbQuery(_L("SELECT * FROM C")));
	TEST2(err, KErrNone);
	TheView.Close();

	TheTest.Printf(_L("INSERT/UPDATE SQL\n"));
	//The test must fail, because the test app cannot satisfy table A, policy W.
	err = TheDb.Execute(_L("INSERT INTO A (DATA2) VALUES(45)"));
	TEST2(err, KErrPermissionDenied);
	//The test must fail, because the test app cannot satisfy table B, policy W.
	err = TheDb.Execute(_L("INSERT INTO B (DATA2) VALUES(45)"));
	TEST2(err, KErrPermissionDenied);
	//The test must fail, because the test app cannot satisfy table C, policy W.
	err = TheDb.Execute(_L("INSERT INTO C (DATA2) VALUES(45)"));
	TEST2(err, KErrPermissionDenied);

	//The test must fail, because the test app cannot satisfy table A, policy W.
	err = TheDb.Execute(_L("UPDATE A SET DATA2=56 WHERE ID = 0"));
	TEST2(err, KErrPermissionDenied);
	//The test must fail, because the test app cannot satisfy table B, policy W.
	err = TheDb.Execute(_L("UPDATE B SET DATA2=56 WHERE ID = 0"));
	TEST2(err, KErrPermissionDenied);
	//The test must fail, because the test app cannot satisfy table C, policy W.
	err = TheDb.Execute(_L("UPDATE C SET DATA2=56 WHERE ID = 0"));
	TEST2(err, KErrPermissionDenied);
	}
Esempio n. 26
0
/**
@SYMTestCaseID			SYSLIB-DBMS-CT-3407
@SYMTestCaseDesc		Test for defect DEF103023 - DBMS requires ReadDeviceData and WriteDeviceData capability to read from the db.
 						The current test application has no capabilities at all.
 						"C:TestDB.DB" database is a secure shared database with:
 							- no "READ" polycy (no restrictions apply to the database read operations);
 							- "WRITE" policy with "WriteUserData" capability defined;
 							- "SCHEMA" policy with "NetworkServices" capability defined;
 							- table C has no defined securoty policy, so the database security policy will be used;
 						The current test application should be able to:
 							- begin/commit/rollback a "read-only" transaction;
 						But should fail if:
 							- begin a transaction and try to modify the database within the transaction;
 						This test function asserts the test cases described above.
@SYMTestPriority		High
@SYMTestActions			Test for defect DEF103023 - DBMS requires ReadDeviceData and WriteDeviceData capability to read from the db.
@SYMTestExpectedResults Test must not fail
@SYMDEF					DEF103023
*/
void DEF103023L()
	{
	TheTest.Printf(_L("Begin a transaction. Read-only operations tested\n"));
	TInt err = TheDb.Begin();
	TEST2(err, KErrNone);
	TheTest.Printf(_L("Perform some read-only operations inside the transaction\n"));
	err = TheView.Prepare(TheDb, _L("SELECT * FROM C"));
	TEST2(err, KErrNone);
	err = TheView.EvaluateAll();
	TEST2(err, KErrNone);
	TInt cnt = TheView.CountL();
	TEST(cnt > 0);
	TBool rc = TheView.FirstL();
	TEST(rc);
	TheView.GetL();
	TInt val = TheView.ColInt32(1);
	rc = TheView.LastL();
	TEST(rc);
	rc = TheView.NextL();
	TEST(!rc);
	rc = TheView.PreviousL();
	TEST(rc);
	TheView.BeginningL();
	TheView.EndL();
	TheView.Close();
	TheTest.Printf(_L("Commit a transaction\n"));
	err = TheDb.Commit();
	TEST2(err, KErrNone);
	//
	TheTest.Printf(_L("Begin a transaction. Read-only operations tested\n"));
	err = TheDb.Begin();
	TEST2(err, KErrNone);
	err = TheView.Prepare(TheDb, _L("SELECT * FROM C"));
	TEST2(err, KErrNone);
	err = TheView.EvaluateAll();
	TEST2(err, KErrNone);
	cnt = TheView.CountL();
	TEST(cnt > 0);
	TheView.Close();
	TheTest.Printf(_L("Rollback a transaction\n"));
	TheDb.Rollback();
	//
	TheTest.Printf(_L("Begin a transaction. Tested operations violate the database security\n"));
	err = TheDb.Begin();
	TEST2(err, KErrNone);
	err = TheView.Prepare(TheDb, _L("SELECT * FROM C"));
	TEST2(err, KErrNone);
	err = TheView.EvaluateAll();
	TEST2(err, KErrNone);
	rc = TheView.FirstL();
	TEST(rc);
	TheView.GetL();
	TheTest.Printf(_L("An attempt to update a record within the transaction\n"));
	TRAP(err, TheView.UpdateL());
	TEST2(err, KErrPermissionDenied);
	TheTest.Printf(_L("An attempt to delete a record within the transaction\n"));
	TRAP(err, TheView.DeleteL());
	TEST2(err, KErrPermissionDenied);
	TheTest.Printf(_L("An attempt to insert a record within the transaction\n"));
	TRAP(err, TheView.InsertL());
	TEST2(err, KErrPermissionDenied);
	TheView.Close();
	TheTest.Printf(_L("An attempt to modify the database schema within the transaction\n"));
	err = TheDb.Execute(_L("CREATE TABLE C2(Id INTEGER, Z INTEGER)"));
	TEST2(err, KErrPermissionDenied);
	TheTest.Printf(_L("An attempt to execute an INSERT statement within the transaction\n"));
	err = TheDb.Execute(_L("INSERT INTO C VALUES(100)"));
	TEST2(err, KErrPermissionDenied);
	TheTest.Printf(_L("An attempt to modify the database within the transaction using RDbUpdate\n"));
	RDbUpdate update;
	err = update.Execute(TheDb, _L("INSERT INTO C VALUES(200)"));
	TEST2(err, KErrPermissionDenied);
	update.Close();
	TheTest.Printf(_L("Rollback a transaction\n"));
	TheDb.Rollback();
	}
// ---------------------------------------------------------
// RFavouritesSrvTable::VerifyStructureL
// ---------------------------------------------------------
//
void RFavouritesSrvTable::VerifyStructureL
( RDbNamedDatabase& aDb, TBool aUpgrade )
{
    CDbColSet* colset = aDb.ColSetL( KFavouritesTableName );
    CleanupStack::PushL( colset );

    if (
        colset->ColNo( KFavouritesDbUidColName ) == KDbNullColNo ||
        colset->ColNo( KFavouritesDbParentColName ) == KDbNullColNo ||
        colset->ColNo( KFavouritesDbTypeColName ) == KDbNullColNo ||
        colset->ColNo( KFavouritesDbNameColName ) == KDbNullColNo ||
        colset->ColNo( KFavouritesDbUrlColName ) == KDbNullColNo ||
        colset->ColNo( KFavouritesDbUserNameColName ) == KDbNullColNo ||
        colset->ColNo( KFavouritesDbPasswordColName ) == KDbNullColNo ||
        colset->ColNo( KFavouritesDbApIdColName ) == KDbNullColNo ||
        colset->ColNo( KFavouritesDbApValueKindColName ) == KDbNullColNo ||
        colset->ColNo( KFavouritesDbExtraDataColName ) == KDbNullColNo ||
        colset->ColNo( KFavouritesDbFactoryItemColName ) == KDbNullColNo ||
        colset->ColNo( KFavouritesDbReadOnlyColName ) == KDbNullColNo ||
        colset->ColNo( KFavouritesDbContextIdColName ) == KDbNullColNo
    )
    {
        // Mandatory column is missing, this database is corrupt.
        User::Leave( KErrCorrupt );
    }

    if ( aUpgrade )
    {
        // Check optional columns, upgrade if necessary.
        // If upgrade is not possible, we don't even check those; as the
        // database is still functional without them.

        TInt missingCols( EFalse );

        if ( colset->ColNo( KFavouritesDbModifiedColName ) == KDbNullColNo )
        {
            // Last modification column is missing.
            colset->AddL( TDbCol
                          ( KFavouritesDbModifiedColName, EDbColDateTime ) );
            missingCols = ETrue;
        }

        if ( colset->ColNo( KFavouritesDbPrefUidColName ) == KDbNullColNo )
        {
            // Preferred uid column is missing.
            colset->AddL( TDbCol( KFavouritesDbPrefUidColName, EDbColInt32 ) );
            missingCols = ETrue;
        }

        if ( colset->ColNo( KFavouritesDbBrowserDataColName ) == KDbNullColNo )
        {
            // Preferred uid column is missing.
            colset->AddL
            ( TDbCol( KFavouritesDbBrowserDataColName, EDbColLongBinary ) );
            missingCols = ETrue;
        }
        if( colset->ColNo( KFavouritesDbHiddenColName)  == KDbNullColNo )
        {
            // Preferred uid column is missing.
            colset->AddL
            ( TDbCol( KFavouritesDbHiddenColName, EDbColBit ) );
            missingCols = ETrue;
        }

        if ( missingCols )
        {
            // Some columns are missing, try to add them now.
            // Upgrade error is ignored, database is still functional (except
            // of course the missing columns).
            (void)aDb.AlterTable( KFavouritesTableName, *colset );
        }
    }

    CleanupStack::PopAndDestroy();  // colset
}
Esempio n. 28
0
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);
	}
Esempio n. 29
0
//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();
	}
Esempio n. 30
0
/**
@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, &notes );
		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 );
	}