1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/dbms/udbms/UD_CLI.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,464 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "UD_STD.H"
1.20 +
1.21 +const TInt KPakArrayGranularity=0x80;
1.22 +
1.23 +// class TDbCol
1.24 +EXPORT_C TDbCol::TDbCol(const TDesC &aName,TDbColType aType)
1.25 + : iType(aType), iAttributes(0), iName(aName)
1.26 + {
1.27 + iMaxLength=(aType==EDbColText8 || aType==EDbColText16)
1.28 + ? KDbDefaultTextColLength : KDbUndefinedLength;
1.29 + }
1.30 +
1.31 +EXPORT_C TDbCol::TDbCol(const TDesC &aName,TDbColType aType,TInt aMaxLength)
1.32 + : iType(aType), iMaxLength(aMaxLength), iAttributes(0), iName(aName)
1.33 +/** Constructs a TDbCol with the given name, optional type and optional maximum
1.34 +length.
1.35 +
1.36 +Note: The iAttributes member is initialised to 0.
1.37 +
1.38 +@param aName The column name.
1.39 +@param aType The column type.
1.40 +@param aMaxLength If present, this specifies a limit on how many characters
1.41 +may be stored in a Text column, or how many bytes can be stored in a Binary
1.42 +column. By default this is set to KDbDefaultTextColLength for Text (but not
1.43 +LongText) columns and KDbUndefinedLength for other columns. */
1.44 + {}
1.45 +
1.46 +// class CDbColSet
1.47 +EXPORT_C CDbColSet::CDbColSet()
1.48 +: iColumns(KPakArrayGranularity)
1.49 +/** Constructs an empty column set. */
1.50 + {}
1.51 +
1.52 +EXPORT_C CDbColSet* CDbColSet::NewL()
1.53 +/** Constructs a new empty column set and returns a pointer to it.
1.54 +
1.55 +@return A pointer to the column set object. */
1.56 + {
1.57 + return new(ELeave) CDbColSet;
1.58 + }
1.59 +
1.60 +EXPORT_C CDbColSet* CDbColSet::NewLC()
1.61 +/** Constructs a new empty column set and returns a pointer to it — placing
1.62 +the pointer onto the cleanup stack. This allows the column set object and
1.63 +allocated resources to be cleaned up if a subsequent leave occurs.
1.64 +
1.65 +@return A pointer to the column set object. */
1.66 + {
1.67 + CDbColSet* cs=NewL();
1.68 + CleanupStack::PushL(cs);
1.69 + return cs;
1.70 + }
1.71 +
1.72 +EXPORT_C CDbColSet::~CDbColSet()
1.73 +/** Frees resources owned by the object. */
1.74 + {}
1.75 +
1.76 +EXPORT_C const TDbCol* CDbColSet::Col(const TDesC &aColName) const
1.77 +/** Returns a named column definition in the set. If such a column does not
1.78 +exist in the set NULL is returned.
1.79 +
1.80 +@param aColName The name of the column to find.
1.81 +@return A pointer to the column definition found, or NULL. */
1.82 + {
1.83 + TDbColNo col=ColNo(aColName);
1.84 + if (col==KDbNullColNo)
1.85 + return NULL;
1.86 + else
1.87 + return &(*this)[col];
1.88 + }
1.89 +
1.90 +EXPORT_C TDbColNo CDbColSet::ColNo(const TDesC &aColName) const
1.91 +/** Returns the ordinal for a particular column name in this column set. If
1.92 +such a column does not exist in the set the special ordinal KDbNullColNo is
1.93 +returned.
1.94 +
1.95 +This function is particularly important when accessing data through a rowset.
1.96 +If the set of columns to be returned by a rowset is not explicitly specified,
1.97 +no assumptions should be made about the ordering of the columns returned.
1.98 +In such a case, in order to access the column data a column ordinal is required,
1.99 +and this can be obtained by using this function on the column set returned
1.100 +by RDbRowSet::ColSetL().
1.101 +
1.102 +@param aColName The name of the column to find.
1.103 +@return The ordinal number of the column. */
1.104 + {
1.105 + TInt pos;
1.106 + TKeyArrayPak key(_FOFF(TDbCol,iName),ECmpFolded);
1.107 + if (iColumns.Find(TDbCol(aColName),key,pos))
1.108 + return KDbNullColNo;
1.109 + else
1.110 + return pos+1;
1.111 + }
1.112 +
1.113 +EXPORT_C CDbColSet& CDbColSet::AddL(const TDbCol& aCol)
1.114 +/** Adds a column to the column set.
1.115 +
1.116 +@param aCol The column to add to the set.
1.117 +@return A reference to this object. */
1.118 + {
1.119 + iColumns.AppendL(aCol,REINTERPRET_CAST(const TUint8*,aCol.iName.Ptr())+aCol.iName.Size()-REINTERPRET_CAST(const TUint8*,&aCol));
1.120 + return *this;
1.121 + }
1.122 +
1.123 +EXPORT_C void CDbColSet::Remove(const TDesC &aColName)
1.124 +/** Removes the named column from the set.
1.125 +
1.126 +@param aColName The name of the column to remove from the set. */
1.127 + {
1.128 + TDbColNo col=ColNo(aColName);
1.129 + __ASSERT_ALWAYS(col!=KDbNullColNo,Panic(EDbInvalidColumn));
1.130 + iColumns.Delete(col-1);
1.131 + }
1.132 +
1.133 +// Class TDbColSetIter
1.134 +EXPORT_C TDbColSetIter::TDbColSetIter(const CDbColSet& aColSet)
1.135 + : iIndex(-1),iArray(&aColSet.iColumns)
1.136 +/** Constructs a column set iterator over a column set. The iterator now
1.137 +references the first column in the set.
1.138 +
1.139 +@param aColSet The column set to iterate over. */
1.140 + {
1.141 + ++(*this);
1.142 + }
1.143 +
1.144 +EXPORT_C TDbColSetIter& TDbColSetIter::operator++()
1.145 +/** Moves the iterator to the next column in the set -- post increment operator.
1.146 +
1.147 +Note that this is implemented in terms of the pre-increment operator, and
1.148 +is less efficient.
1.149 +
1.150 +@param Unused: required for the C++ compiler to resolve the ambiguity with
1.151 +the pre-increment operator.
1.152 +@return A copy of this iterator, referring to the column definition before
1.153 +the increment operation is performed. */
1.154 + {
1.155 + __ASSERT(iIndex<iArray->Count());
1.156 + iColumn=++iIndex<iArray->Count() ? &(*iArray)[iIndex] : 0;
1.157 + return *this;
1.158 + }
1.159 +
1.160 +// class TDbKeyCol
1.161 +EXPORT_C TDbKeyCol::TDbKeyCol(const TDesC& aName,TOrder anOrder)
1.162 + : iOrder(anOrder),iLength(KDbUndefinedLength),iName(aName)
1.163 + {}
1.164 +
1.165 +EXPORT_C TDbKeyCol::TDbKeyCol(const TDesC& aName,TInt aLength,TOrder anOrder)
1.166 + : iOrder(anOrder),iLength(aLength),iName(aName)
1.167 +/** Constructs an object with the given name, ordering and optional truncation
1.168 +length.
1.169 +
1.170 +@param aName The column name.
1.171 +@param aLength If present, this specifies a limit on how many characters of
1.172 +a Text or LongText column are used for the key. This should only be used for
1.173 +the last key column in an index. It is required for keys on LongText columns.
1.174 +@param anOrder The ordering for the key column. By default this is ascending
1.175 +order. */
1.176 + {}
1.177 +
1.178 +// class CDbKey
1.179 +
1.180 +EXPORT_C CDbKey::CDbKey()
1.181 + : iKeys(KPakArrayGranularity)
1.182 +/** Constructs an empty key. It is initialised to non-unique, non-primary and
1.183 +normal text comparison. */
1.184 + {}
1.185 +
1.186 +EXPORT_C CDbKey *CDbKey::NewL()
1.187 +/** Constructs and returns a pointer to a new empty key.
1.188 +
1.189 +@return A pointer to the key object. */
1.190 + {
1.191 + return new(ELeave) CDbKey;
1.192 + }
1.193 +
1.194 +EXPORT_C CDbKey *CDbKey::NewLC()
1.195 +/** Constructs and returns a new empty key and return a pointer to it, leaving
1.196 +a pointer to the key object on the cleanup stack. This allows the key object
1.197 +and allocated resources to be cleaned up if a subsequent leave occurs.
1.198 +
1.199 +@return A pointer to the key object. */
1.200 + {
1.201 + CDbKey* key=NewL();
1.202 + CleanupStack::PushL(key);
1.203 + return key;
1.204 + }
1.205 +
1.206 +EXPORT_C CDbKey::~CDbKey()
1.207 +/** Frees resources owned by the object. */
1.208 + {}
1.209 +
1.210 +EXPORT_C CDbKey& CDbKey::AddL(const TDbKeyCol& aKey)
1.211 +/** Adds a key column to the end of the key.
1.212 +
1.213 +@param aKeyCol The key column to add to the key.
1.214 +@return A reference to this object. */
1.215 + {
1.216 + iKeys.AppendL(aKey,REINTERPRET_CAST(const TUint8*,aKey.iName.Ptr())+aKey.iName.Size()-REINTERPRET_CAST(const TUint8*,&aKey));
1.217 + return *this;
1.218 + }
1.219 +
1.220 +EXPORT_C void CDbKey::Remove(const TDesC& aColName)
1.221 +/** Removes the named column from the key.
1.222 +
1.223 +@param aColName The name of the column to remove from the key. */
1.224 + {
1.225 + TInt pos;
1.226 + TKeyArrayPak key(_FOFF(TDbKeyCol,iName),ECmpFolded);
1.227 + __ASSERT_ALWAYS(!iKeys.Find(TDbKeyCol(aColName),key,pos),Panic(EDbInvalidColumn));
1.228 + iKeys.Delete(pos);
1.229 + }
1.230 +
1.231 +EXPORT_C void CDbKey::Clear()
1.232 +/** Resets the key to its initial empty state. */
1.233 + {
1.234 + iKeys.Reset();
1.235 + iAttributes=0;
1.236 + iComparison=EDbCompareNormal;
1.237 + }
1.238 +
1.239 +// Class TDbLookupKey
1.240 +
1.241 +TDbLookupKey::SColumn& TDbLookupKey::NextKey()
1.242 + {
1.243 + return iKey[iCount++];
1.244 + }
1.245 +
1.246 +void TDbLookupKey::Add(TInt aKey)
1.247 + {
1.248 + SColumn& key=NextKey();
1.249 + key.iType=EDbColInt32;
1.250 + key.iInt32=aKey;
1.251 + }
1.252 +
1.253 +void TDbLookupKey::Add(TUint aKey)
1.254 + {
1.255 + SColumn& key=NextKey();
1.256 + key.iType=EDbColUint32;
1.257 + key.iUint32=aKey;
1.258 + }
1.259 +
1.260 +void TDbLookupKey::Add(TInt64 aKey)
1.261 + {
1.262 + SColumn& key=NextKey();
1.263 + key.iType=EDbColInt64;
1.264 + key.iInt64()=aKey;
1.265 + }
1.266 +
1.267 +void TDbLookupKey::Add(TReal32 aKey) __SOFTFP
1.268 + {
1.269 + SColumn& key=NextKey();
1.270 + key.iType=EDbColReal32;
1.271 + key.iReal32=aKey;
1.272 + }
1.273 +
1.274 +void TDbLookupKey::Add(TReal64 aKey) __SOFTFP
1.275 + {
1.276 + SColumn& key=NextKey();
1.277 + key.iType=EDbColReal64;
1.278 + key.iReal64=aKey;
1.279 + }
1.280 +
1.281 +void TDbLookupKey::Add(TTime aKey)
1.282 + {
1.283 + SColumn& key=NextKey();
1.284 + key.iType=EDbColDateTime;
1.285 + key.iTime()=aKey;
1.286 + }
1.287 +
1.288 +void TDbLookupKey::Add(const TDesC8& aKey)
1.289 + {
1.290 + SColumn& key=NextKey();
1.291 + key.iType=EDbColText8;
1.292 + key.iDes8.iPtr=aKey.Ptr();
1.293 + key.iDes8.iLength=aKey.Length();
1.294 + }
1.295 +
1.296 +void TDbLookupKey::Add(const TDesC16& aKey)
1.297 + {
1.298 + SColumn& key=NextKey();
1.299 + key.iType=EDbColText16;
1.300 + key.iDes16.iPtr=aKey.Ptr();
1.301 + key.iDes16.iLength=aKey.Length();
1.302 + }
1.303 +
1.304 +// Class TDbSeekKey
1.305 +
1.306 +TDbLookupKey& TDbSeekKey::Check()
1.307 + {
1.308 + __ASSERT_ALWAYS(iKey.Count()<iMaxKeys,Panic(EDbTooManyKeys));
1.309 + return iKey;
1.310 + }
1.311 +
1.312 +EXPORT_C TDbSeekKey& TDbSeekKey::Add(TInt aKey)
1.313 +/** Appends a key value for an TInt8, TInt16 or TInt32 column.
1.314 +
1.315 +@param aKey The key value to lookup.
1.316 +@return A reference to this database key value object. */
1.317 + {
1.318 + Check().Add(aKey);
1.319 + return *this;
1.320 + }
1.321 +
1.322 +EXPORT_C TDbSeekKey& TDbSeekKey::Add(TUint aKey)
1.323 +/** Appends a key value for a Bit, TUint8, TUint16 or TUint32 column.
1.324 +
1.325 +@param aKey The key value to lookup.
1.326 +@return A reference to this database key value object. */
1.327 + {
1.328 + Check().Add(aKey);
1.329 + return *this;
1.330 + }
1.331 +
1.332 +EXPORT_C TDbSeekKey& TDbSeekKey::Add(TInt64 aKey)
1.333 +/** Appends a key value for an TInt64 column.
1.334 +
1.335 +@param aKey The key value to lookup.
1.336 +@return A reference to this database key value object. */
1.337 + {
1.338 + Check().Add(aKey);
1.339 + return *this;
1.340 + }
1.341 +
1.342 +EXPORT_C TDbSeekKey& TDbSeekKey::Add(TReal32 aKey) __SOFTFP
1.343 +/** Appends a key value for a TReal32 column.
1.344 +
1.345 +@param aKey The key value to lookup.
1.346 +@return A reference to this database key value object. */
1.347 + {
1.348 + Check().Add(aKey);
1.349 + return *this;
1.350 + }
1.351 +
1.352 +EXPORT_C TDbSeekKey& TDbSeekKey::Add(TReal64 aKey) __SOFTFP
1.353 +/** Appends a key value for a TReal64 column.
1.354 +
1.355 +@param aKey The key value to lookup.
1.356 +@return A reference to this database key value object. */
1.357 + {
1.358 + Check().Add(aKey);
1.359 + return *this;
1.360 + }
1.361 +
1.362 +EXPORT_C TDbSeekKey& TDbSeekKey::Add(TTime aKey)
1.363 +/** Appends a key value for a DateTime column.
1.364 +
1.365 +@param aKey The key value to lookup. TTime may be either local time or universal time.
1.366 +DBMS doesn't interpret the value of TTime, it is left up to the user to decide which should be used.
1.367 +@return A reference to this database key value object. */
1.368 + {
1.369 + Check().Add(aKey);
1.370 + return *this;
1.371 + }
1.372 +
1.373 +EXPORT_C TDbSeekKey& TDbSeekKey::Add(const TDesC8& aKey)
1.374 +/** Appends a key value for a non-Unicode text column.
1.375 +
1.376 +Note that the seek key does not copy the text data contained by the descriptor.
1.377 +This needs to be retained until the seek key is no longer required.
1.378 +
1.379 +@param aKey The key value to lookup.
1.380 +@return A reference to this database key value object. */
1.381 + {
1.382 + Check().Add(aKey);
1.383 + return *this;
1.384 + }
1.385 +
1.386 +EXPORT_C TDbSeekKey& TDbSeekKey::Add(const TDesC16& aKey)
1.387 +/** Appends a key value for a Unicode text column.
1.388 +
1.389 +Note that the seek key does not copy the text data contained by the descriptor.
1.390 +This needs to be retained until the seek key is no longer required.
1.391 +
1.392 +@param aKey The key value to lookup.
1.393 +@return A reference to this database key value object. */
1.394 + {
1.395 + Check().Add(aKey);
1.396 + return *this;
1.397 + }
1.398 +
1.399 +// Class CDbNames
1.400 +
1.401 +inline CDbNames::CDbNames()
1.402 + : iList(KPakArrayGranularity)
1.403 + {}
1.404 +
1.405 +CDbNames* CDbNames::NewLC()
1.406 + {
1.407 + CDbNames* self=new(ELeave) CDbNames;
1.408 + CleanupStack::PushL(self);
1.409 + return self;
1.410 + }
1.411 +
1.412 +CDbNames::~CDbNames()
1.413 + {}
1.414 +
1.415 +EXPORT_C void CDbNames::AddL(const TDesC& aName)
1.416 + {
1.417 + TDbNameC name(aName);
1.418 + iList.AppendL(name,(const TUint8*)name.Ptr()+name.Size()-(const TUint8*)&name);
1.419 + }
1.420 +
1.421 +////////////////////////////////////////////////////////////////////////////////////////////////
1.422 +// Class CDbStrings
1.423 +
1.424 +/**
1.425 +Granularity of CDbStrings array.
1.426 +@internalComponent
1.427 +*/
1.428 +const TInt KPakArrayGranularity2 = KDbMaxStrLen * 2;
1.429 +
1.430 +/**
1.431 +@internalComponent
1.432 +*/
1.433 +inline CDbStrings::CDbStrings() :
1.434 + iList(KPakArrayGranularity2)
1.435 + {
1.436 + }
1.437 +
1.438 +/**
1.439 +Standard phase-one creation method for CDbStrings objects.
1.440 +@return A pointer to the created CDbStrings object.
1.441 +@leave KErrNoMemory - Out of memory.
1.442 +*/
1.443 +CDbStrings* CDbStrings::NewLC()
1.444 + {
1.445 + CDbStrings* self = new(ELeave) CDbStrings;
1.446 + CleanupStack::PushL(self);
1.447 + return self;
1.448 + }
1.449 +
1.450 +/**
1.451 +@internalComponent
1.452 +*/
1.453 +CDbStrings::~CDbStrings()
1.454 + {
1.455 + }
1.456 +
1.457 +/**
1.458 +Adds a string to the array.
1.459 +@param aStr String to be added to the array.
1.460 +@leave KErrNoMemory - Out of memory.
1.461 +@internalComponent
1.462 +*/
1.463 +void CDbStrings::AddL(const TDesC& aStr)
1.464 + {
1.465 + TDbStringC str(aStr);
1.466 + iList.AppendL(str, (const TUint8*)str.Ptr() + str.Size() - (const TUint8*)&str);
1.467 + }