|
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 #if !defined(__D32DBAS_H__) |
|
17 #define __D32DBAS_H__ |
|
18 #if !defined(__D32DBMS_H__) |
|
19 #include <d32dbms.h> |
|
20 #endif |
|
21 |
|
22 // other classes referenced |
|
23 class RFs; |
|
24 class CDbContext; |
|
25 |
|
26 // classes defined |
|
27 class TTextOps; |
|
28 class TDbBlob; |
|
29 class TDbCell; |
|
30 class TDbColumnC; |
|
31 class TDbColumn; |
|
32 class RDbRow; |
|
33 class CDbObject; |
|
34 class CDbRowConstraint; |
|
35 class CDbCursor; |
|
36 class CDbNotifier; |
|
37 class CDbIncremental; |
|
38 class CDbSyncIncremental; |
|
39 class CDbAsyncIncremental; |
|
40 class CDbDatabase; |
|
41 class CDbSource; |
|
42 class TDbDriver; |
|
43 class TDbFormat; |
|
44 |
|
45 /** |
|
46 @internalComponent |
|
47 */ |
|
48 const TInt KDbMaxFormatName=32; |
|
49 const TInt KDbMaxDatabaseName=KMaxFileName; |
|
50 |
|
51 /** |
|
52 @internalComponent |
|
53 */ |
|
54 const TInt KDbMaxInlineBlobSize=255; |
|
55 |
|
56 /** |
|
57 @internalComponent |
|
58 */ |
|
59 typedef TUint32 TDbBlobId; |
|
60 |
|
61 /** |
|
62 @internalComponent |
|
63 */ |
|
64 const TDbBlobId KDbNullBlobId=0; |
|
65 |
|
66 /** |
|
67 @internalComponent |
|
68 */ |
|
69 class Dbms |
|
70 { |
|
71 public: |
|
72 IMPORT_C static void Panic(const TDesC& aCategory,TInt aCode); |
|
73 }; |
|
74 |
|
75 /** |
|
76 @internalComponent |
|
77 */ |
|
78 class TTextOps |
|
79 { |
|
80 public: |
|
81 IMPORT_C static const TTextOps& Ops(TDbTextComparison aType=EDbCompareNormal); |
|
82 // |
|
83 inline TUint Fold(TUint aChar) const; |
|
84 IMPORT_C TInt Compare(const TDesC8& aLeft,const TDesC8& aRight) const; |
|
85 IMPORT_C TInt Compare(const TDesC16& aLeft,const TDesC16& aRight) const; |
|
86 inline TInt Compare(const TText8* aLeftPtr,TInt aLeftLen,const TText8* aRightPtr,TInt aRightLen) const; |
|
87 inline TInt Compare(const TText16* aLeftPtr,TInt aLeftLen,const TText16* aRightPtr,TInt aRightLen) const; |
|
88 inline TInt Match(const TDesC8& aDes,const TDesC8& aPattern) const; |
|
89 inline TInt Match(const TDesC16& aDes,const TDesC16& aPattern) const; |
|
90 IMPORT_C TInt Match(const TText8* aPtr,TInt aLen,const TText8* aPatternPtr,TInt aPatternLen) const; |
|
91 IMPORT_C TInt Match(const TText16* aPtr,TInt aLen,const TText16* aPatternPtr,TInt aPatternLen) const; |
|
92 IMPORT_C TInt Find(const TDesC8& aDes,const TDesC8& aSub) const; |
|
93 IMPORT_C TInt Find(const TDesC16& aDes,const TDesC16& aSub) const; |
|
94 IMPORT_C TInt Find(const TText8* aPtr,TInt aLen,const TText8* aSubPtr,TInt aSubLen) const; |
|
95 IMPORT_C TInt Find(const TText16* aPtr,TInt aLen,const TText16* aSubPtr,TInt aSubLen) const; |
|
96 TInt Order(const TDesC16& aLeft, const TDesC16& aRight) const; |
|
97 inline TInt Order(const TText16* aLeftPtr, TInt aLeftLen, const TText16* aRightPtr, TInt aRightLen) const; |
|
98 public: |
|
99 TUint (*iFold)(TUint aChar); |
|
100 TInt (*iCompare8)(const TText8*,TInt,const TText8*,TInt); |
|
101 TInt (*iMatch8)(const TDesC8&,const TDesC8&); |
|
102 TInt (*iFind8)(const TDesC8&,const TText8*,TInt); |
|
103 TInt (*iCompare16)(const TText16*,TInt,const TText16*,TInt); |
|
104 TInt (*iMatch16)(const TDesC16&,const TDesC16&); |
|
105 TInt (*iFind16)(const TDesC16&,const TText16*,TInt); |
|
106 TInt (*iOrder16)(const TText16*, TInt, const TText16*, TInt); |
|
107 }; |
|
108 |
|
109 /** |
|
110 @internalComponent |
|
111 */ |
|
112 class TDbBlob |
|
113 { |
|
114 public: |
|
115 inline TDbBlob(); |
|
116 inline TDbBlob(TDbBlobId anId,TInt aSize=KDbUndefinedLength); |
|
117 inline TDbBlob(const TUint8* aPtr,TInt aSize); |
|
118 inline TUint8* InlineBuffer(); |
|
119 inline void SetId(TDbBlobId anId); |
|
120 inline void SetSize(TInt aSize); |
|
121 // |
|
122 inline TBool IsInline() const; |
|
123 inline TInt Size() const; |
|
124 inline const TUint8* Data() const; |
|
125 inline TPtrC8 PtrC8() const; |
|
126 inline TPtrC16 PtrC16() const; |
|
127 inline TDbBlobId Id() const; |
|
128 // |
|
129 inline TInt CellSize() const; |
|
130 static inline TInt InlineSize(TInt aSize); |
|
131 static inline TInt RefSize(); |
|
132 private: |
|
133 TDbBlobId iId; |
|
134 TInt iSize; |
|
135 TUint8 iInline[KDbMaxInlineBlobSize]; |
|
136 }; |
|
137 |
|
138 /** |
|
139 @internalComponent |
|
140 */ |
|
141 class TDbCell |
|
142 { |
|
143 public: |
|
144 static inline TInt Size(TInt aLength); |
|
145 inline TInt Size() const; // total cell size |
|
146 inline TDbCell* Next(); // pointer to next cell |
|
147 inline const TDbCell* Next() const; // pointer to next cell |
|
148 inline TInt Length() const; // data size |
|
149 inline void SetLength(TInt aLength); |
|
150 inline TAny* Data(); // data pointer |
|
151 inline const TAny* Data() const; // data pointer |
|
152 private: |
|
153 TInt iLength; |
|
154 TUint8 iBuf[1]; |
|
155 }; |
|
156 |
|
157 /** |
|
158 @internalComponent |
|
159 */ |
|
160 class TDbColumnC |
|
161 { |
|
162 friend class TDbColumn; |
|
163 public: |
|
164 inline TDbColumnC(const RDbRow& aRow,TDbColNo aCol); |
|
165 inline TDbColumnC(const TDbColumn& aCol); |
|
166 inline TInt Size() const; |
|
167 inline TBool IsNull() const; |
|
168 inline TInt8 Int8() const; |
|
169 inline TInt16 Int16() const; |
|
170 inline TInt32 Int32() const; |
|
171 inline const TInt64& Int64() const; |
|
172 inline TUint8 Uint8() const; |
|
173 inline TUint16 Uint16() const; |
|
174 inline TUint32 Uint32() const; |
|
175 inline TReal32 Real32() const; |
|
176 inline const TReal64& Real64() const; |
|
177 inline TPtrC8 PtrC8() const; |
|
178 inline TPtrC16 PtrC16() const; |
|
179 inline const TTime& Time() const; |
|
180 inline const TDbBlob& Blob() const; |
|
181 private: |
|
182 const TDbCell* iCell; |
|
183 }; |
|
184 |
|
185 /** |
|
186 @internalComponent |
|
187 */ |
|
188 class TDbColumn |
|
189 { |
|
190 friend class TDbColumnC; |
|
191 public: |
|
192 inline TDbColumn(); |
|
193 inline TDbColumn(RDbRow& aRow,TDbColNo aCol); |
|
194 inline void SetNull(); |
|
195 inline void SetL(TInt32 aValue); |
|
196 IMPORT_C void SetL(TUint32 aValue); |
|
197 IMPORT_C void SetL(TInt64 aValue); |
|
198 IMPORT_C void SetL(TReal32 aValue) __SOFTFP; |
|
199 IMPORT_C void SetL(TReal64 aValue) __SOFTFP; |
|
200 IMPORT_C void SetL(const TDesC8& aValue); |
|
201 IMPORT_C void SetL(const TDesC16& aValue); |
|
202 inline void SetL(const TTime& aValue); |
|
203 IMPORT_C void SetBlobL(TDbBlobId aBlobId,TInt aSize=KDbUndefinedLength); |
|
204 IMPORT_C void SetBlobL(const TUint8* aData,TInt aSize); |
|
205 // |
|
206 IMPORT_C TDbBlob& InitBlobL(); |
|
207 IMPORT_C void CommitBlob(const TDbBlob& aBlob); |
|
208 // |
|
209 inline void SetL(const TDbCell* aCell); |
|
210 inline void SetL(const TDbColumnC& aColumn); |
|
211 private: |
|
212 inline RDbRow& Row() const; |
|
213 IMPORT_C void SetL(const TAny* aPtr,TInt aSize); |
|
214 private: |
|
215 RDbRow* iRow; |
|
216 TDbColNo iColumn; |
|
217 }; |
|
218 |
|
219 /** |
|
220 @internalComponent |
|
221 */ |
|
222 class RDbRow |
|
223 { |
|
224 friend class TDbColumn; |
|
225 public: |
|
226 IMPORT_C RDbRow(); |
|
227 inline RDbRow(TAny* aBuf,TInt aMaxSize); |
|
228 inline RDbRow(TAny* aBuf,TInt aSize,TInt aMaxSize); |
|
229 inline void Open(TAny* aBuf,TInt aMaxSize); |
|
230 IMPORT_C void Open(TAny* aBuf,TInt aSize,TInt aMaxSize); |
|
231 IMPORT_C void CreateL(TInt aMaxSize); |
|
232 void PushL(); |
|
233 IMPORT_C void Close(); |
|
234 inline void Reset(); |
|
235 // |
|
236 inline TDbCell* First(); |
|
237 inline const TDbCell* First() const; |
|
238 inline const TDbCell* Last() const; |
|
239 inline const TDbCell* End() const; |
|
240 IMPORT_C void SetSize(TInt aSize); |
|
241 inline TInt Size() const; |
|
242 inline TInt MaxSize() const; |
|
243 IMPORT_C void GrowL(TInt aMaxSize); |
|
244 // for use by data sources |
|
245 static inline TInt Diff(const TDbCell* aBegin,const TDbCell* aEnd); |
|
246 IMPORT_C const TDbCell* ColCell(TDbColNo aCol) const; |
|
247 private: |
|
248 IMPORT_C TAny* SetColumnWidthL(TDbColNo aCol,TInt aWidth); |
|
249 TDbCell* Column(TDbColNo aCol) const; |
|
250 TInt ReallocL(TInt aMaxSize); |
|
251 void ExtendL(TInt aAdjust); // change the row buffer length |
|
252 // |
|
253 inline TBool Owned() const; |
|
254 inline TInt Column() const; |
|
255 inline void SetCache(TDbCell* aCell,TInt aColumn); |
|
256 private: |
|
257 enum {EOwned=0x80000000}; |
|
258 enum {EGranularity=0x100}; |
|
259 private: |
|
260 TDbCell* iFirst; // first column |
|
261 TDbCell* iLast; // pointer past last cell |
|
262 TDbCell* iEnd; // pointer past end of available buffer |
|
263 TDbCell* iCell; // cached cell pointer |
|
264 TUint iColumn; // cached column number/ownership flag |
|
265 }; |
|
266 |
|
267 |
|
268 /** |
|
269 @internalComponent |
|
270 */ |
|
271 class CDbObject : public CBase |
|
272 { |
|
273 friend class CDbContext; |
|
274 public: |
|
275 static void Destroy(CDbObject* aObject); // context-safe deletion |
|
276 CDbObject* Attach(CDbObject* aObject); |
|
277 inline const CDbContext* Context() const; |
|
278 // |
|
279 void PushL(); |
|
280 protected: |
|
281 inline CDbObject() {} |
|
282 private: |
|
283 CDbContext* iContext; |
|
284 }; |
|
285 |
|
286 /** |
|
287 @internalComponent |
|
288 */ |
|
289 class CDbRowConstraint : public CDbObject |
|
290 { |
|
291 protected: |
|
292 CDbRowConstraint() {} |
|
293 }; |
|
294 |
|
295 /** |
|
296 @internalComponent |
|
297 */ |
|
298 class CDbCursor : public CDbObject |
|
299 { |
|
300 public: |
|
301 enum TInsert {EClear,ECopy}; |
|
302 protected: |
|
303 CDbCursor() {} |
|
304 public: |
|
305 // Pure virtual |
|
306 virtual void Reset() =0; |
|
307 virtual TBool EvaluateL()=0; |
|
308 TInt Evaluate(); |
|
309 // virtual void Evaluate(TRequestStatus& aStatus)=0; |
|
310 virtual TBool Unevaluated()=0; |
|
311 // |
|
312 virtual void SetIndexL(const TDesC* anIndex)=0; |
|
313 virtual TBool SeekL(const TDbLookupKey& aKey,RDbTable::TComparison aComparison) =0; |
|
314 CDbRowConstraint* ConstraintL(const TDbQuery& aCriteria); |
|
315 virtual TBool MatchL(CDbRowConstraint& aConstraint) =0; |
|
316 IMPORT_C virtual TInt FindL(RDbRowSet::TDirection aDirection,const TDbQuery& aCriteria); |
|
317 // |
|
318 virtual TBool AtBeginning()=0; |
|
319 virtual TBool AtEnd()=0; |
|
320 virtual TBool AtRow()=0; |
|
321 IMPORT_C virtual TInt CountL(RDbRowSet::TAccuracy aAccuracy); |
|
322 virtual TBool GotoL(RDbRowSet::TPosition aPosition)=0; |
|
323 virtual void Bookmark(TDbBookmark::TMark& aMark) =0; |
|
324 virtual void GotoL(const TDbBookmark::TMark& aMark) =0; |
|
325 virtual void GetL()=0; |
|
326 virtual void InsertL(TInsert aClearRow)=0; |
|
327 virtual void UpdateL()=0; |
|
328 virtual void Cancel()=0; |
|
329 virtual void PutL()=0; |
|
330 virtual void DeleteL()=0; |
|
331 // column validation |
|
332 virtual TInt ColumnCount()=0; |
|
333 IMPORT_C virtual void ColumnsL(CDbColSet& aColSet); |
|
334 virtual void ColumnDef(TDbCol& aCol,TDbColNo aColNo)=0; |
|
335 virtual TDbColType ColumnType(TDbColNo aCol)=0; |
|
336 // Column Accessors |
|
337 virtual TDbColumnC ColumnC(TDbColNo aCol)=0; // non-writeable column |
|
338 virtual TDbColumn Column(TDbColNo aCol)=0; // writeable column |
|
339 virtual void SetNullL(TDbColNo aCol)=0; |
|
340 virtual TInt ColumnSize(TDbColNo aCol)=0; |
|
341 // Optimized whole row access for server |
|
342 virtual RDbRow* RowBuffer() =0; |
|
343 // Blob functions |
|
344 virtual MStreamBuf* ColumnSourceL(TDbColNo aCol)=0; |
|
345 virtual MStreamBuf* ColumnSinkL(TDbColNo aCol)=0; |
|
346 private: |
|
347 virtual CDbRowConstraint* OpenConstraintL(const TDbQuery& aCriteria) =0; |
|
348 // Reserved virtuals |
|
349 IMPORT_C virtual void Reserved_1(); |
|
350 IMPORT_C virtual void Reserved_2(); |
|
351 }; |
|
352 |
|
353 /** |
|
354 @internalComponent |
|
355 */ |
|
356 class CDbIncremental : public CDbObject |
|
357 { |
|
358 protected: |
|
359 CDbIncremental() {} |
|
360 public: |
|
361 virtual TBool NextL(TInt& aStep) =0; |
|
362 // virtual void Next(TPckgBuf<TInt>& aStep,TRequestStatus& aStatus) =0; |
|
363 }; |
|
364 |
|
365 /** |
|
366 @internalComponent |
|
367 */ |
|
368 class CDbSyncIncremental : public CDbIncremental |
|
369 { |
|
370 protected: |
|
371 CDbSyncIncremental() {} |
|
372 private: |
|
373 // IMPORT_C void Next(TPckgBuf<TInt>& aStep,TRequestStatus& aStatus); |
|
374 }; |
|
375 |
|
376 /** |
|
377 @internalComponent |
|
378 */ |
|
379 class CDbAsyncIncremental : public CDbIncremental |
|
380 { |
|
381 protected: |
|
382 CDbAsyncIncremental() {} |
|
383 private: |
|
384 IMPORT_C TBool NextL(TInt& aStep); |
|
385 }; |
|
386 |
|
387 /** |
|
388 @internalComponent |
|
389 */ |
|
390 class CDbDatabase : public CDbObject |
|
391 { |
|
392 protected: |
|
393 CDbDatabase() {} |
|
394 public: |
|
395 enum TUtility {EStats=1,ECompact,ERecover}; |
|
396 enum TProperty {EUpdateStats=-EStats,ECompactable=-ECompact,EIsDamaged=-ERecover, |
|
397 EInTransaction=0,ESize,EUsage}; |
|
398 public: |
|
399 // Pure virtual |
|
400 virtual TInt Destroy()=0; |
|
401 virtual TInt Begin()=0; |
|
402 virtual TInt Commit()=0; |
|
403 virtual void Rollback()=0; |
|
404 virtual TInt Property(TProperty aProperty) =0; |
|
405 virtual void CreateTableL(const TDesC& aName,const CDbColSet& aColSet,const CDbKey* aPrimaryKey)=0; |
|
406 CDbNotifier* NotifierL(); |
|
407 CDbIncremental* UtilityL(TUtility aType,TInt& aStep); |
|
408 CDbIncremental* DropTableL(const TDesC& aTable,TInt& aStep); |
|
409 CDbIncremental* AlterTableL(const TDesC& aTable,const CDbColSet& aNewDef,TInt& aStep); |
|
410 CDbIncremental* CreateIndexL(const TDesC& aName,const TDesC& aTable,const CDbKey& aKey,TInt& aStep); |
|
411 CDbIncremental* DropIndexL(const TDesC& aName,const TDesC& aTable,TInt& aStep); |
|
412 CDbIncremental* ExecuteL(const TDesC& aSql,TDbTextComparison aComparison,TInt& aInit); |
|
413 CDbCursor* ViewL(const TDbQuery& aQuery,const TDbWindow& aWindow,RDbRowSet::TAccess anAccess); |
|
414 CDbCursor* TableL(const TDesC& aName,RDbRowSet::TAccess anAccess); |
|
415 virtual void TablesL(CDbTableNames& aNames)=0; |
|
416 virtual void ColumnsL(CDbColSet& aColSet,const TDesC& aName)=0; |
|
417 virtual void IndexesL(CDbIndexNames& aNames,const TDesC& aTable)=0; |
|
418 virtual void KeysL(CDbKey& aKey,const TDesC& aName,const TDesC& aTable)=0; |
|
419 private: |
|
420 virtual CDbNotifier* OpenNotifierL() =0; |
|
421 virtual CDbIncremental* OpenUtilityL(TUtility aType,TInt& aStep) =0; |
|
422 virtual CDbIncremental* OpenDropTableL(const TDesC& aTable,TInt& aStep) =0; |
|
423 virtual CDbIncremental* OpenAlterTableL(const TDesC& aTable,const CDbColSet& aNewDef,TInt& aStep) =0; |
|
424 virtual CDbIncremental* OpenCreateIndexL(const TDesC& aName,const TDesC& aTable,const CDbKey& aKey,TInt& aStep) =0; |
|
425 virtual CDbIncremental* OpenDropIndexL(const TDesC& aName,const TDesC& aTable,TInt& aStep) =0; |
|
426 virtual CDbCursor* PrepareViewL(const TDbQuery& aQuery,const TDbWindow& aWindow,RDbRowSet::TAccess anAccess) =0; |
|
427 virtual CDbCursor* OpenTableL(const TDesC& aName,RDbRowSet::TAccess anAccess) =0; |
|
428 virtual CDbIncremental* OpenExecuteL(const TDesC& aSql,TDbTextComparison aComparison,TInt& aInit) =0; |
|
429 // Reserved virtuals |
|
430 IMPORT_C virtual void Reserved_1(); |
|
431 IMPORT_C virtual void Reserved_2(); |
|
432 }; |
|
433 |
|
434 /** |
|
435 @internalComponent |
|
436 */ |
|
437 class CDbNotifier : public CDbObject |
|
438 { |
|
439 public: |
|
440 enum TType {EUnlock=-1,EChange=-2}; |
|
441 protected: |
|
442 CDbNotifier() {} |
|
443 public: |
|
444 // pure virtual |
|
445 // virtual void Notify(TType aEvent,TRequestStatus& aStatus) =0; |
|
446 virtual void Cancel() =0; |
|
447 }; |
|
448 |
|
449 |
|
450 /** |
|
451 CDbSource class declaration - SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version |
|
452 @internalComponent |
|
453 */ |
|
454 class CDbSource : public CDbObject |
|
455 { |
|
456 protected: |
|
457 CDbSource() |
|
458 { |
|
459 } |
|
460 public: |
|
461 CDbDatabase* OpenL(); |
|
462 virtual CDbDatabase* AuthenticateL() = 0; |
|
463 CDbNotifier* NotifierL(); |
|
464 private: |
|
465 virtual CDbNotifier* OpenNotifierL() =0; |
|
466 }; |
|
467 |
|
468 |
|
469 /** |
|
470 @internalComponent |
|
471 */ |
|
472 class TDbDriver |
|
473 { |
|
474 public: |
|
475 TInt iCount; |
|
476 const TDbFormat* iFormats; |
|
477 }; |
|
478 |
|
479 /** |
|
480 @internalComponent |
|
481 */ |
|
482 class TDbFormat |
|
483 { |
|
484 public: |
|
485 enum TCreate {ECreate,EReplace}; |
|
486 enum TOpen {EReadWrite,EReadOnly}; |
|
487 typedef CDbDatabase* (*FCreateL)(RFs& aFs, const TDesC& aName, TCreate aMode, |
|
488 const TUidType& aType); |
|
489 typedef CDbSource* (*FOpenL)(RFs& aFs,const TDesC& aName,TOpen aMode); |
|
490 public: |
|
491 const TText* iName; |
|
492 FCreateL CreateL; |
|
493 FOpenL OpenL; |
|
494 TInt32 iUid[KMaxCheckedUid]; |
|
495 }; |
|
496 |
|
497 /** |
|
498 @internalComponent |
|
499 */ |
|
500 #define KDbmsDriverUidValue KDbmsDriverUidValue16 |
|
501 #define KDbmsDriverUid KDbmsDriverUid16 |
|
502 |
|
503 /** |
|
504 @internalComponent |
|
505 */ |
|
506 const TInt32 KDbmsDriverUidValue8=0x10000EBC; |
|
507 const TUid KDbmsDriverUid8={KDbmsDriverUidValue8}; |
|
508 const TInt32 KDbmsDriverUidValue16=0x10003B0F; |
|
509 const TUid KDbmsDriverUid16={KDbmsDriverUidValue16}; |
|
510 |
|
511 #include "D32DBAS.INL" |
|
512 #endif |