persistentstorage/dbms/utable/UT_PRJCT.CPP
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "UT_STD.H"
       
    17 
       
    18 // Class HDbColumnMap
       
    19 
       
    20 class HDbColumnMap
       
    21 	{
       
    22 public:
       
    23 	static HDbColumnMap* NewL(const RSqlColumnList& aSelect,const HDbColumnSet& aColumns);
       
    24 	inline const TDbColNo& operator[](TDbColNo aCol) const
       
    25 		{__ASSERT(aCol>0&&aCol<=iCount);return iMap[aCol-1];}
       
    26 	inline TInt Count() const
       
    27 		{return iCount;}
       
    28 private:
       
    29 	TInt iCount;
       
    30 	TDbColNo iMap[1];	// at least one
       
    31 	};
       
    32 
       
    33 HDbColumnMap* HDbColumnMap::NewL(const RSqlColumnList& aSelect,const HDbColumnSet& aColumns)
       
    34 	{
       
    35 	TInt count=aSelect.Count();
       
    36 	HDbColumnMap* self=(HDbColumnMap*)User::AllocLC(_FOFF(HDbColumnMap,iMap[count]));
       
    37 	self->iCount=count;
       
    38 	TDbColNo* pCol=&self->iMap[0];
       
    39 	for (TInt ii=0;ii<count;++ii)
       
    40 		{
       
    41 		TDbColNo col=aColumns.ColNoL(aSelect[ii]);
       
    42 		if (col==KDbNullColNo)
       
    43 			__LEAVE(KErrNotFound);
       
    44 		*pCol++=col;
       
    45 		}
       
    46 	CleanupStack::Pop();
       
    47 	return self;
       
    48 	}
       
    49 
       
    50 // Class CDbProjectStage
       
    51 
       
    52 CDbProjectStage::CDbProjectStage()
       
    53 	{}
       
    54 
       
    55 CDbProjectStage::~CDbProjectStage()
       
    56 	{
       
    57 	delete iMap;
       
    58 	}
       
    59 
       
    60 void CDbProjectStage::ConstructL(const RSqlColumnList& aSelect,const HDbColumnSet& aColumns)
       
    61 //
       
    62 // Build the column map and allocate a row buffer
       
    63 //
       
    64 	{
       
    65 	iMap=HDbColumnMap::NewL(aSelect,aColumns);
       
    66 	}
       
    67 
       
    68 RDbRow* CDbProjectStage::RowBuffer()
       
    69 //
       
    70 // whole-row access cannot be done through a projection
       
    71 //
       
    72 	{
       
    73 	return 0;
       
    74 	}
       
    75 
       
    76 TDbColumn CDbProjectStage::Column(TDbColNo aColNo)
       
    77 	{
       
    78 	return CDbDataStage::Column((*iMap)[aColNo]);
       
    79 	}
       
    80 
       
    81 TInt CDbProjectStage::ColumnCount() const
       
    82 	{
       
    83 	return iMap->Count();
       
    84 	}
       
    85 
       
    86 const TDbColumnDef& CDbProjectStage::ColumnDef(TDbColNo aCol) const
       
    87 	{
       
    88 	return CDbDataStage::ColumnDef((*iMap)[aCol]);
       
    89 	}