/**
Creates the user added city database table if it doesn't exist
@return KErrNone if succesful, or one of the DBMS Leave codes
@internalTechnology
*/
TInt CTzLocalizationDbAccessor::CreateUserCityTableL()
	{
	//Create the columns for the user aded cities table
	RArray<TDbCol> cityTableCols;
	CleanupClosePushL(cityTableCols);
	cityTableCols.AppendL(TDbCol(KUCTableTzId,			EDbColUint16));
	cityTableCols.AppendL(TDbCol(KUCTableCity,			EDbColText));
	cityTableCols.AppendL(TDbCol(KUCTableGroup,			EDbColUint8));
	cityTableCols.AppendL(TDbCol(KUCTableResourceId,	EDbColUint32));

	// Create the columnset - add the columns
	// Columns MUST be added in the same order they appear in TTzCityColumn
	CDbColSet* userCityColSet = CDbColSet::NewLC();
	TInt numCols = cityTableCols.Count();
	for(TInt i = 0; i < numCols; ++i)
		{
		userCityColSet->AddL(cityTableCols[i]);
		}

	// Create the User City table
	TInt error = iLocalizedTimeZoneDb.CreateTable(KUCTableName,*userCityColSet);
	
	CleanupStack::PopAndDestroy(userCityColSet);
	CleanupStack::PopAndDestroy(); //cityTableCols

	return error;
	}
// -----------------------------------------------------------------------------
// CWPInternetAPDB::CreateTableL
// -----------------------------------------------------------------------------
//  
void CWPInternetAPDB::CreateTableL(RDbDatabase& aDatabase)
    {
    FLOG( _L( "[Provisioning] CWPInternetAPDB::CreateTableL" ) );

    // Create a table definition
    CDbColSet* columns=CDbColSet::NewLC();

    // Add Columns
    TDbCol id(NCol1, EDbColInt32);

    // automatic indexing for items,it is our key field.
    id.iAttributes=id.EAutoIncrement;
    columns->AddL(id);

    columns->AddL(TDbCol(NCol2, EDbColInt32));
    columns->AddL(TDbCol(NCol3, EDbColInt32));
    columns->AddL(TDbCol(NCol4, EDbColText, KOriginatorMaxLength));

    // Create a table
    User::LeaveIfError(aDatabase.CreateTable(KtxtItemlist, *columns) );

    // cleanup the column set
    CleanupStack::PopAndDestroy(columns);
    FLOG( _L( "[Provisioning] CWPInternetAPDB::CreateTableL: done" ) );
    }
void CNSmlDSSettings::CreateDatabaseL(const TDesC& aFullName)
	{
	// 50 is the extra length neede for integer lengths
	HBufC* createProfileTable = HBufC::NewLC( KDSCreateProfilesTable().Length() + 50);
	TPtr profileTablePtr = createProfileTable->Des();

	profileTablePtr.Format(KDSCreateProfilesTable,KNSmlMaxProfileNameLength,KNSmlMaxUsernameLength,KNSmlMaxPasswordLength,KNSmlMaxURLLength,KNSmlMaxServerIdLength,KNSmlMaxHttpAuthUsernameLength,KNSmlMaxHttpAuthPasswordLength, KNSmlDSVisibilityArraySize );

	// 25 is the extra length neede for integer lengths
	HBufC* createAdaptersTable = HBufC::NewLC( KDSCreateAdaptersTable().Length() + 25);
	TPtr adaptersTablePtr = createAdaptersTable->Des();
	adaptersTablePtr.Format(KDSCreateAdaptersTable,KNSmlMaxAdapterDisplayNameLength,KNSmlMaxRemoteNameLength, KNSmlMaxLocalNameLength );

    User::LeaveIfError( iDatabase.Create( this->iRdbSession, aFullName, KNSmlDBMSSecureSOSServerID ) );  
	
	iDatabase.Begin();

	iDatabase.Execute( *createProfileTable );
	iDatabase.Execute( *createAdaptersTable );

	CDbColSet* colSet = CDbColSet::NewLC();
	colSet->AddL(TDbCol(KNSmlVersionColumnMajor(), EDbColUint16));
	colSet->AddL(TDbCol(KNSmlVersionColumnMinor(), EDbColUint16));
	User::LeaveIfError(iDatabase.CreateTable(KNSmlTableVersion(), *colSet));
	CleanupStack::PopAndDestroy(  ); //colset

	RDbTable table;
	User::LeaveIfError(table.Open(iDatabase, KNSmlTableVersion()));
	CleanupClosePushL(table);
	colSet = table.ColSetL();
	CleanupStack::PushL(colSet);
	table.InsertL();
	table.SetColL(colSet->ColNo(KNSmlVersionColumnMajor), KNSmlSettingsCurrentVersionMajor);
	table.SetColL(colSet->ColNo(KNSmlVersionColumnMinor), KNSmlSettingsCurrentVersionMinor);
	table.PutL();
	
	iDatabase.Commit();
	
	CreateHiddenProfilesL();

	TInt keyVal;
	TRAPD (err ,ReadRepositoryL(KNsmlDsCustomProfiles, keyVal));
	if (err == KErrNone && keyVal)
	{
		TBool aRestore = EFalse;
		CreateXMLProfilesL(aRestore);
	}
	iDatabase.Close();
	CleanupStack::PopAndDestroy( 4 ); // createAdaptersTable, createProfileTable, colSet, table
	}
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
void CExPolicy_Server::CreateStatusTableL(RDbDatabase& aDatabase) 
{
	// Create a table definition
	CDbColSet* columns=CDbColSet::NewLC();
	
	// Add Columns
	TDbCol id(NCol0,EDbColInt32);
	id.iAttributes=id.EAutoIncrement;// automatic indexing for items,it is our key field.
	columns->AddL(id);				 
	
	columns->AddL(TDbCol(NStatCol1, EDbColInt32));
	columns->AddL(TDbCol(NStatCol2, EDbColInt32));
	
	User::LeaveIfError(aDatabase.CreateTable(KtxtStatuslist,*columns));
				
	// cleanup the column set
	CleanupStack::PopAndDestroy();
}
// -----------------------------------------------------------------------------
// CWPInternetAPDB::CreateTableL
// -----------------------------------------------------------------------------
//  
void CSCOMOAdapterDb::CreateTableL(RDbDatabase& aDatabase)
    {

    // Create a table definition
    CDbColSet* columns=CDbColSet::NewLC();

    // Add Columns
    TDbCol id(NCol1, EDbColInt32);

    // automatic indexing for items,it is our key field.
    id.iAttributes=id.EAutoIncrement;
    columns->AddL(id);
    columns->AddL(TDbCol(NCol2, EDbColInt32));
    columns->AddL(TDbCol(NCol3, EDbColInt32));
    columns->AddL(TDbCol(NCol4, EDbColText8, 255));
    columns->AddL(TDbCol(NCol5, EDbColText8, 255));
    columns->AddL(TDbCol(NCol6, EDbColText8, 255));
    columns->AddL(TDbCol(NCol7, EDbColInt32));

    //possibility of Panic 

    // Create a table
    TRAPD(err, aDatabase.CreateTable(KTableAMMgmtObject, *columns) );

    if(err!=KErrNone)
    User::Leave(err);

    // cleanup the column set
    CleanupStack::PopAndDestroy(columns);

    }
Beispiel #6
0
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ 
void CScheduleDB::CreateMsgTableL(RDbDatabase& aDatabase) 
	{
	// Create a table definition
	CDbColSet* columns=CDbColSet::NewLC();
	
	// Add Columns
	TDbCol id(NCol0,EDbColInt32);
	id.iAttributes=id.EAutoIncrement;// automatic indexing for items,it is our key field.
	columns->AddL(id);				 
	columns->AddL(TDbCol(NCol3, EDbColText16,255));
	
	// Create a table
	User::LeaveIfError(aDatabase.CreateTable(KtxtItemlist2,*columns));
				
	// cleanup the column set
	CleanupStack::PopAndDestroy();
}
Beispiel #7
0
LOCAL_C void TestTableDDL(const TContext& aContext)
	{
	test.Start(_L("DDL while open"));
	aContext.OpenDbL();
	TInt r=TheTable.Open(TheDatabase,TableName);
	test (r==KErrNone);
	CDbColSet* set=CDbColSet::NewLC();
	set->AddL(TDbCol(Column1,EDbColText));
	r=TheDatabase.CreateTable(TableName2,*set);
	test (r==KErrNone);
	TRAP(r,TheTable.CountL(TheTable.EQuick));
	test (r==KErrNone);
	TheTable.Close();
	r=TheTable.Open(TheDatabase,TableName2);
	test (r==KErrNone);
//
	set->AddL(TDbCol(Column2,EDbColUint32));
	r=TheDatabase.AlterTable(TableName2,*set);
	test (r==KErrNone);
	CleanupStack::PopAndDestroy();		// set
	TRAP(r,TheTable.CountL(TheTable.EQuick));
	test (r==KErrDisconnected);
	TheTable.Reset();
	TRAP(r,TheTable.CountL(TheTable.EQuick));
	test (r==KErrDisconnected);
	TheTable.Close();
	r=TheTable.Open(TheDatabase,TableName2);
	test (r==KErrNone);
//
	CDbKey* key=CDbKey::NewLC();
	key->AddL(Column2());
	r=TheDatabase.CreateIndex(IndexName2,TableName,*key);
	test (r==KErrNone);
	TRAP(r,TheTable.CountL(TheTable.EQuick));
	test (r==KErrNone);
	r=TheDatabase.DropIndex(IndexName2,TableName);
	test (r==KErrNone);
	TRAP(r,TheTable.CountL(TheTable.EQuick));
	test (r==KErrNone);
//
	r=TheDatabase.CreateIndex(IndexName,TableName2,*key);
	test (r==KErrNone);
	CleanupStack::PopAndDestroy();	// key
	TRAP(r,TheTable.CountL(TheTable.EQuick));
	test (r==KErrDisconnected);
	TheTable.Close();
	r=TheTable.Open(TheDatabase,TableName2);
	test (r==KErrNone);
//
	r=TheDatabase.DropIndex(IndexName,TableName2);
	test (r==KErrNone);
	TRAP(r,TheTable.CountL(TheTable.EQuick));
	test (r==KErrDisconnected);
	TheTable.Close();
	r=TheTable.Open(TheDatabase,TableName2);
	test (r==KErrNone);
//
	r=TheDatabase.DropTable(TableName2);
	test (r==KErrNone);
	TRAP(r,TheTable.CountL(TheTable.EQuick));
	test (r==KErrDisconnected);
	TheTable.Close();
	TheDatabase.Close();
	test.End();
	}
Beispiel #8
0
LOCAL_C void DatabaseL()
	{
	test.Start(_L("Adding and dropping tables"));
	DbCreateL();
// ensure the database locking list has been allocated
	TheDatabase.Begin();
	TheDatabase.Commit();
//
	CDbColSet *col=CDbColSet::NewLC();
//
	test.Next(_L("Empty Column Set"));
	__UHEAP_MARK;
	test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
	__UHEAP_MARKEND;
//
	test.Next(_L("Invalid table name"));
	col->AddL(TDbCol(Column1,EDbColInt32));
	__UHEAP_MARK;
	test(TheDatabase.CreateTable(TableNameX,*col)!=KErrNone);
	__UHEAP_MARKEND;
//
	test.Next(_L("Invalid column name"));
	col->AddL(TDbCol(Column2X,EDbColBit));
	__UHEAP_MARK;
	test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
	__UHEAP_MARKEND;
//
	test.Next(_L("Duplicate column name"));
	col->Remove(Column2X);
	col->AddL(TDbCol(Column1Fold,EDbColBit));
	__UHEAP_MARK;
	test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
	__UHEAP_MARKEND;
//
	test.Next(_L("Invalid column type"));
	col->Remove(Column1);
	col->AddL(TDbCol(Column2,TDbColType(-1)));
	__UHEAP_MARK;
	test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
	__UHEAP_MARKEND;
//
	test.Next(_L("Invalid maximum length"));
	col->Remove(Column2);
	col->AddL(TDbCol(Column2,EDbColInt32,0));
	__UHEAP_MARK;
	test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
	__UHEAP_MARKEND;
//
	test.Next(_L("Invalid attributes"));
	col->Remove(Column2);
	TDbCol cc(Column2,EDbColInt32);
	cc.iAttributes=13;
	col->AddL(cc);
	__UHEAP_MARK;
	test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
	__UHEAP_MARKEND;
//
	test.Next(_L("Adding/dropping a table name twice"));
	col->Remove(Column2);
	col->AddL(TDbCol(Column2,EDbColText8));
	__UHEAP_MARK;
	test(TheDatabase.CreateTable(TableName,*col)==KErrNone);
	test(TheDatabase.CreateTable(TableName,*col)==KErrAlreadyExists);
	test(TheDatabase.DropTable(TableNameX)!=KErrNone);
	test(TheDatabase.DropTable(TableName)==KErrNone);
	test(TheDatabase.DropTable(TableName)==KErrNotFound);
	__UHEAP_MARKEND;
//
	test.Next(_L("Adding and dropping indexes"));
	test(TheDatabase.CreateTable(TableName,*col)==KErrNone);
	TheDatabase.Close();
	CDbKey *key=CDbKey::NewLC();
	__UHEAP_MARK;
	DbOpenL();
	test(TheDatabase.CreateIndex(IndexName,TableName,*key)!=KErrNone);
	TheDatabase.Close();
	__UHEAP_MARKEND;
	key->AddL(Column2X());
	__UHEAP_MARK;
	DbOpenL();
	test(TheDatabase.CreateIndex(IndexName,TableName,*key)!=KErrNone);
	TheDatabase.Close();
	__UHEAP_MARKEND;
	key->Clear();
	key->AddL(Column1());
	__UHEAP_MARK;
	DbOpenL();
	test(TheDatabase.CreateIndex(TableNameX,TableName,*key)!=KErrNone);
	TheDatabase.Close();
	__UHEAP_CHECK(0);
	DbOpenL();
	test(TheDatabase.CreateIndex(IndexName,TableNameX,*key)!=KErrNone);
	TheDatabase.Close();
	__UHEAP_MARKEND;
	__UHEAP_MARK;
	DbOpenL();
	test(TheDatabase.CreateIndex(IndexName,TableName,*key)==KErrNone);
	test(TheDatabase.CreateIndex(IndexName,TableName,*key)==KErrAlreadyExists);
	test(TheDatabase.DropIndex(TableNameX,TableName)!=KErrNone);
	test(TheDatabase.DropIndex(IndexName,TableNameX)!=KErrNone);
	test(TheDatabase.DropIndex(IndexName,TableName)==KErrNone);
	test(TheDatabase.DropIndex(IndexName,TableName)==KErrNotFound);
	test(TheDatabase.DropTable(TableName)==KErrNone);
	test(TheDatabase.DropIndex(IndexName,TableName)==KErrNotFound);
	TheDatabase.Close();
	__UHEAP_MARKEND;
//
	test.Next(_L("Allocation failure during DDL"));
	TFailCreateTable fct;
	TFailAlterTable fat;
	TFailDropTable fdt;
	TFailCreateIndex fci;
	TFailDropIndex fdi;
	TheColSet=CDbColSet::NewL();
	TheColSet->AddL(TDbCol(Column1,EDbColUint16));
	TheKey=CDbKey::NewL();
	TheKey->AddL(Column1());
	fct.Test(KClientHeap,KClient);
	WriteTableL();
	TheColSet->AddL(TDbCol(Column2,EDbColText));
	fat.Test(KClientHeap,KClient);
	fci.Test(KClientHeap,KClient);
	fdi.Test(KClientHeap,KClient);
	fdt.Test(KClientHeap,KClient);
//
	test.Next(_L("Allocation failure during server DDL"));
	Connect();
	TheColSet->Remove(Column2);
	fct.Test(KClientHeap,KServer);
	WriteTableL();
	TheColSet->AddL(TDbCol(Column2,EDbColText));
	fat.Test(KClientHeap,KServer);
	fci.Test(KClientHeap,KServer);
	fdi.Test(KClientHeap,KServer);
	fdt.Test(KClientHeap,KServer);
//
	TheColSet->Remove(Column2);
	fct.Test(KServerHeap,KServer);
	WriteTableL();
	TheColSet->AddL(TDbCol(Column2,EDbColText));
	fat.Test(KServerHeap,KServer);
	fci.Test(KServerHeap,KServer);
	fdi.Test(KServerHeap,KServer);
	fdt.Test(KServerHeap,KServer);
	Disconnect();
//
	delete TheColSet;
	delete TheKey;

//
	test.Next(_L("Allocation failure on schema enquiry"));
	DbCreateL();
	test(TheDatabase.CreateTable(TableName,*col)==KErrNone);
	test(TheDatabase.CreateIndex(IndexName,TableName,*key)==KErrNone);
	CleanupStack::PopAndDestroy(2);	// columns set and key
	TheDatabase.Close();
	TFailDatabaseTables t4;
	TFailDatabaseColSet t5;
	TFailDatabaseIndexes t6;
	TFailDatabaseKeys t7;
	t4.Test(KClientHeap,KClient);
	t5.Test(KClientHeap,KClient);
	t6.Test(KClientHeap,KClient);
	t7.Test(KClientHeap,KClient);
//
	test.Next(_L("Allocation failure on server schema enquiry"));
	Connect();
	t4.Test(KClientHeap,KServer);
	t4.Test(KServerHeap,KServer);
	t5.Test(KClientHeap,KServer);
	t5.Test(KServerHeap,KServer);
	t6.Test(KClientHeap,KServer);
	t6.Test(KServerHeap,KServer);
	t7.Test(KClientHeap,KServer);
	t7.Test(KServerHeap,KServer);
	Disconnect();
	test.End();
	}
// ---------------------------------------------------------
// 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
}
// ---------------------------------------------------------
// 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
}
/**
Creates the Cached Zone Table if it doesn't already exist.
@return KErrNone if succesful, or one of the DBMS Leave codes
@internalTechnology
*/
TInt CTzLocalizationDbAccessor::CreateFrequentlyUsedZoneTableL()
	{
	// Create the columns for the cached zones table
	RArray<TDbCol> cachedTableCols;
	CleanupClosePushL(cachedTableCols);
	cachedTableCols.AppendL(TDbCol(KCZTableTzIdCol,			EDbColUint16));
	cachedTableCols.AppendL(TDbCol(KCZTableStdCol, 			EDbColText));
	cachedTableCols.AppendL(TDbCol(KCZTableDSTCol, 			EDbColText));
	cachedTableCols.AppendL(TDbCol(KCZTableShortStdCol, 	EDbColText));
	cachedTableCols.AppendL(TDbCol(KCZTableShortDSTCol, 	EDbColText));
	cachedTableCols.AppendL(TDbCol(KCZTableCityCol, 		EDbColText));
	cachedTableCols.AppendL(TDbCol(KCZTableCityGroupCol, 	EDbColUint8));
	cachedTableCols.AppendL(TDbCol(KCZTableResourceIdCol, 	EDbColUint32));
    cachedTableCols.AppendL(TDbCol(KCZTableCityIndexCol,	EDbColInt32));

	// Create the columnset - add the columns
	// Columns MUST be added in the same order they appear in TTzZoneColumn
	CDbColSet* FrequentlyUsedZoneColSet = CDbColSet::NewLC();
	TInt numCols = cachedTableCols.Count();
	for(TInt i = 0; i < numCols; ++i)
		{
		FrequentlyUsedZoneColSet->AddL(cachedTableCols[i]);
		}

	// Create the Cached Time Zone table
	TInt error = iLocalizedTimeZoneDb.CreateTable(KCZTableName,*FrequentlyUsedZoneColSet);
	User::LeaveIfError(error);

	//Open the newly created table
	PrepareZoneViewL();
	iZoneView.Reset();
	//Populate with initial (blank) data.

	_LIT(KEmptyString," ");

	for (TInt x = 0; x < CTzLocalizedTimeZone::ECachedTimeZones; ++x)
		{
		iZoneMutex.Wait() ;
		CleanupStack::PushL(TCleanupItem(ReleaseMutex,&iZoneMutex));
		// Insert empty row
		iZoneView.InsertL();
		// Fill the table with blank data
		iZoneView.SetColL(ETzZoneId,			0);
		iZoneView.SetColL(ETzZoneStdName,		KEmptyString);
		iZoneView.SetColL(ETzZoneDSTName,		KEmptyString);
		iZoneView.SetColL(ETzZoneShortStdName,	KEmptyString);
		iZoneView.SetColL(ETzZoneShortDSTName,	KEmptyString);
		iZoneView.SetColL(ETzZoneCity,			KEmptyString);
		iZoneView.SetColL(ETzZoneGroupId,		0);
		iZoneView.SetColL(ETzZoneResourceId,	0);
        iZoneView.SetColL(ETzZoneCityIndex,		0);
		iZoneView.PutL(); // Complete insertion
		CleanupStack::Pop() ;
		iZoneMutex.Signal() ;
		}
	
	iZoneView.Close();

	CleanupStack::PopAndDestroy(FrequentlyUsedZoneColSet);
	CleanupStack::PopAndDestroy(&cachedTableCols); //cachedTableCols
	return error;
	}
/**
@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 );
	}
void bases::InnerConstructL(bool aConvertOnly, CCellMap* aCellMap)
{
	CALLSTACKITEM_N(_CL("bases"), _CL("ConstructL"));

	iConvertOnly=aConvertOnly;

	if (!aConvertOnly) {
		Mlogger::ConstructL(AppContextAccess());
		Mlog_base_impl::ConstructL();
		iBBSubSessionNotif->AddNotificationL(KCellIdTuple, ETrue);

		iEvent.iData.SetValue(&iLocation); iEvent.iData.SetOwnsValue(EFalse);

		cell_hash=CGenericIntMap::NewL();
		// initial values
		learning_done=false;
		first_time=GetTime();

		previous_time=previous_day=first_time;
		scale=1.0;

	}
	TInt dbver=0;

	MoveIntoDataDirL(AppContext(), database_file);

	TFileName database_filename_install, database_filename;
	database_filename_install.Format(_L("%S%S"), &AppDir(), &database_file_install);
	database_filename.Format(_L("%S%S"), &DataDir(), &database_file);

	if (BaflUtils::FileExists(Fs(), database_filename_install)) {
		User::LeaveIfError(BaflUtils::CopyFile(Fs(), database_filename_install, database_filename));
		User::LeaveIfError(BaflUtils::DeleteFile(Fs(), database_filename_install));
		Settings().WriteSettingL(SETTING_BASEDB_VERSION, LATEST_DBVER);
		learning_done=true;
	}

	dbver=LATEST_DBVER;
	Settings().GetSettingL(SETTING_BASEDB_VERSION, dbver);

	auto_ptr<CDbColSet> cols(CDbColSet::NewL());

	TInt colno=1;
	cols->AddL(TDbCol(col_id, EDbColUint32)); colno_id=colno++;
	cols->AddL(TDbCol(col_t, EDbColReal64) ); colno_t=colno++;
	cols->AddL(TDbCol(col_f, EDbColUint32) ); colno_f=colno++;
	cols->AddL(TDbCol(col_isbase, EDbColBit) ); colno_isbase=colno++;
	cols->AddL(TDbCol(col_last_seen, EDbColDateTime) ); colno_last_seen=colno++;
	cols->AddL(TDbCol(col_iscurrent, EDbColBit) ); colno_iscurrent=colno++;

	TInt store_exists;
	CC_TRAP(store_exists, store = CPermanentFileStore::OpenL(Fs(), database_filename, EFileRead|EFileWrite));
	if (store_exists!=KErrNone) {
		dbver=LATEST_DBVER;
		Settings().WriteSettingL(SETTING_BASEDB_VERSION, LATEST_DBVER);
	}

	if (dbver<2) {
		cols->AddL(TDbCol(col_cellid, EDbColText)); colno_cellid=colno++;
	}
	cols->AddL(TDbCol(col_merged_to, EDbColUint32)); colno_merged_to=colno++;
	cols->AddL(TDbCol(col_unaged_t, EDbColReal64) ); colno_unaged_t=colno++;
	cols->AddL(TDbCol(col_rescaled, EDbColUint32) ); colno_rescaled=colno++;

	if (store_exists==KErrNone) { 
		db.OpenL(store, store->Root());
		User::LeaveIfError(db.Recover());
		db_open=true;

		RDebug::Print(_L("converting database..."));
		User::LeaveIfError(db.AlterTable(table_cells, *cols));
		RDebug::Print(_L("converting database done."));

		User::LeaveIfError(table.Open(db, table_cells));
		table_open=true;
		// read cells in order
		read_from_database(aConvertOnly, aCellMap);
		
	} else {
		if (aConvertOnly) return;

		// construct database
		store = CPermanentFileStore::ReplaceL(Fs(), database_filename, EFileRead|EFileWrite);
		store->SetTypeL(store->Layout());
		TStreamId id=db.CreateL(store);
		db_open=true;
		store->SetRootL(id);
		store->CommitL();

		User::LeaveIfError(db.CreateTable(table_cells, *cols));

		auto_ptr<CDbKey> idx_key(CDbKey::NewL());
		idx_key->AddL(TDbKeyCol(col_id));
		idx_key->MakeUnique();
		User::LeaveIfError(db.CreateIndex(idx_id, table_cells, *idx_key));
		idx_key->Clear();
		idx_key->AddL(TDbKeyCol(col_t));
		User::LeaveIfError(db.CreateIndex(idx_t, table_cells, *idx_key));

		User::LeaveIfError(table.Open(db, table_cells));
		table_open=true;
		User::LeaveIfError(table.SetIndex(idx_id));

		Settings().WriteSettingL(SETTING_BASEDB_VERSION, LATEST_DBVER);
	}
	if (aConvertOnly) return;

	if (! bases_info) {
		bases_info=new (ELeave) cell_list_node(0, first_time);
		bases_info->id=0;
		bases_info->t=scale;
		bases_info->merged_to=0;
		bases_info->last_seen=first_time;
		update_database(bases_info, false);
	}

	iGraph=CDirectedGraph::NewL(db, _L("GRAPH"));
	iMerged=CMerged::NewL(db, _L("MERGE"));
	iCandidates=CList<TCandidate>::NewL();

	iTimer=CTimeOut::NewL(*this);
	iTimer->Wait(CELL_REFRESH);
}