void CAppConfig::CheckConfigTableL() { CDbColSet *colSet = NULL; TInt error; TRAP(error, colSet = iDb.ColSetL(KConfigTable)); if (colSet != NULL) { TBool drop = colSet->Count() != 2 || colSet->ColNo(KConfigKeyCol) == KDbNullColNo || colSet->ColNo(KConfigValueCol) == KDbNullColNo ; delete colSet; if (drop) { User::LeaveIfError(iDb.DropTable(KConfigTable)); colSet = NULL; } } if (colSet == NULL) { // Specify columns for config table TDbCol keyCol(KConfigKeyCol, EDbColText, KConfigKeyMaxLength); TDbCol valueCol(KConfigValueCol, EDbColText, KConfigValueMaxLength); keyCol.iAttributes = TDbCol::ENotNull; valueCol.iAttributes = TDbCol::ENotNull; // Add the columns to column set colSet = CDbColSet::NewLC(); colSet->AddL(keyCol); colSet->AddL(valueCol); // Create the Books table User::LeaveIfError(iDb.CreateTable(KConfigTable, *colSet)); CleanupStack::PopAndDestroy(colSet); } CDbKey *idx = NULL; TRAP(error, idx = iDb.KeyL(KConfigIndex, KConfigTable)); if (idx != NULL) { if (!idx->IsUnique()) { iDb.DropIndex(KConfigIndex, KConfigTable); delete idx; idx = NULL; } else { delete idx; } } if (idx == NULL) { TDbKeyCol keyCol(KConfigKeyCol); idx = CDbKey::NewLC(); idx->MakeUnique(); idx->AddL(keyCol); User::LeaveIfError(iDb.CreateIndex(KConfigIndex, KConfigTable, *idx)); CleanupStack::PopAndDestroy(idx); } }
GLDEF_C void ExternalizeL(const CDbKey& aKey,RWriteStream& aStream) { TInt cc=aKey.Count(); aStream.WriteInt32L(cc); for (TInt ii=0;ii<cc;++ii) { const TDbKeyCol& col=aKey[ii]; aStream<<col.iName<<TUint8(col.iOrder)<<TInt32(col.iLength); } aStream<<TUint8(aKey.Comparison())<<TUint8(aKey.IsUnique()); }
// // build a key for the index // void CDbTableDatabase::CInterface::KeysL(CDbKey& aKey,const TDesC& aName,const TDesC& aTable) { const CDbKey& key=Database().SchemaL().FindL(aTable).Indexes().FindL(aName).Key(); TInt max=key.Count(); for (TInt ii=0;ii<max;++ii) aKey.AddL(key[ii]); if (key.IsUnique()) aKey.MakeUnique(); if (key.IsPrimary()) aKey.MakePrimary(); aKey.SetComparison(key.Comparison()); }
void CLogServDatabaseMarshall::CreateIndiciesL() { // Get the array size TResourceReader reader; iResourceInterface.CreateResourceReaderLC(reader, R_LOG_INDEXES); const TInt indexes = reader.ReadInt16(); // Read in the array for(TInt c1 = 0; c1 < indexes; c1++) { const TPtrC name(reader.ReadTPtrC()); const TPtrC table(reader.ReadTPtrC()); // Get the number of keys const TInt keys = reader.ReadInt16(); CDbKey* key = CDbKey::NewLC(); for(TInt c2 = 0; c2 < keys; c2++) { TPtrC col = reader.ReadTPtrC(); TUint order = reader.ReadUint16(); TInt len = reader.ReadInt16(); // Add the key key->AddL(TDbKeyCol(col, len, (TDbKeyCol::TOrder)order)); } // Make key unique if required if (reader.ReadInt8()) key->MakeUnique(); // Set comparison const TDbTextComparison comparison = static_cast<TDbTextComparison>(reader.ReadInt8()); key->SetComparison(comparison); // Create the index User::LeaveIfError(iDatabase.CreateIndex(name, table, *key)); CleanupStack::PopAndDestroy(key); } CleanupStack::PopAndDestroy(); // reader }
GLDEF_C void InternalizeL(CDbKey& aKey,RReadStream& aStream) { __ASSERT(aKey.Count()==0); TDbKeyCol col; TPtr name(col.iName.Des()); TInt cc=aStream.ReadInt32L(); while (--cc>=0) { aStream>>name; TUint8 uInt = aStream.ReadUint8L(); col.iOrder=TDbKeyCol::TOrder(uInt); col.iLength=aStream.ReadInt32L(); aKey.AddL(col); } aKey.SetComparison(TDbTextComparison(aStream.ReadUint8L())); if (aStream.ReadUint8L()) aKey.MakeUnique(); }
// --------------------------------------------------------- // 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 }
void CAppConfig::CheckAutosaveTableL() { CDbColSet *colSet = NULL; TInt error; TRAP(error, colSet = iDb.ColSetL(KAutosaveTable)); if (colSet != NULL) { TBool drop = colSet->Count() != 3 || colSet->ColNo(KAutosaveNameCol) == KDbNullColNo || colSet->ColNo(KAutosaveSaveCol) == KDbNullColNo || colSet->ColNo(KAutosaveDateCol) == KDbNullColNo ; delete colSet; if (drop) { User::LeaveIfError(iDb.DropTable(KAutosaveTable)); colSet = NULL; } } if (colSet == NULL) { // Specify columns for config table TDbCol nameCol(KAutosaveNameCol, EDbColText8, KAutosaveNameMaxLength); TDbCol saveCol(KAutosaveSaveCol, EDbColLongText8); TDbCol dateCol(KAutosaveDateCol, EDbColDateTime); nameCol.iAttributes = TDbCol::ENotNull; saveCol.iAttributes = TDbCol::ENotNull; dateCol.iAttributes = TDbCol::ENotNull; // Add the columns to column set colSet = CDbColSet::NewLC(); colSet->AddL(nameCol); colSet->AddL(saveCol); colSet->AddL(dateCol); // Create the Books table TInt _err = iDb.CreateTable(KAutosaveTable, *colSet); User::LeaveIfError(_err); CleanupStack::PopAndDestroy(colSet); } CDbKey *idx = NULL; TRAP(error, idx = iDb.KeyL(KAutosaveIndex, KAutosaveTable)); if (idx != NULL) { if (!idx->IsUnique()) { iDb.DropIndex(KAutosaveIndex, KAutosaveTable); delete idx; idx = NULL; } else { delete idx; } } if (idx == NULL) { TDbKeyCol keyCol(KAutosaveNameCol); idx = CDbKey::NewLC(); idx->MakeUnique(); idx->AddL(keyCol); User::LeaveIfError(iDb.CreateIndex(KAutosaveIndex, KAutosaveTable, *idx)); CleanupStack::PopAndDestroy(idx); } }