cplusDBAction 4.2 Copyright addoit GmbH 2009
Exept for
the Insert() container, the keys are created out of the primary keys, thus
avoiding duplicates.
A “key”
always contains the following parts:
Ø
K-@@
(start delimiter)
Ø
PK1 (the primary key value from the database)
Ø
@@ (primary key delimiter, only for tables
with constraint PK)
Ø
PK2 (the constraint primary key value from
the database)
Ø
etc.
(See
example in Picture 12: Indexing Using a Key)
You can
always retrieve the key using the GetIndexKey() method. This is
extremely useful if you want to access a Update() or Delete() container from a
Select() container. Another way of retrieving the key is by calling the ItemKeyAt()
method on the container.
119: std::stringstream
text;
120:
121: // Perform a simple
select on the "DeclarationType" table belonging to the
122: // "m_pDBGenType"
Table Set
123: clsCollDeclarationType* pCollDeclType = clsDeclarationType::Select(m_pDBGenType);
124:
125: if (pCollDeclType !=
NULL)
126: {
127: // Index the items in
the collection using a key
128: // Exceed the max
item count to get an error for the last two items
129: int
itemCount = pCollDeclType->Count();
130: for ( long lIndex = 0; lIndex < itemCount + 2; lIndex++ )
131: {
132: DBString::clsDBString
strKey;
133: strKey
<< DBGlobalDeclaration::C_INDEX_KEY_HEADER << lIndex;
134: clsDeclarationType* pDeclType =
pCollDeclType->Item(strKey);
135:
136: if (pDeclType != NULL)
137: {
138:
text << "Key: " << pDeclType->GetIndexKey() << ",
Item: " <<
139:
pDeclType->DB_DeclarationType() << std::endl;
140: }
141: else
142: {
143:
text << "Key: " << strKey <<
"
not found!" << std::endl;
144: }
145: }
146: }
Picture 12: Indexing Using a Key
Related Topics