examples/ForumNokia/DBMS/inc/DBMSEngine.h

00001 /*
00002  * Copyright © 2008 Nokia Corporation.
00003  */
00004 
00005 #ifndef __BOOKDBENGINE_H__
00006 #define __BOOKDBENGINE_H__
00007 
00008 
00009 #include <e32std.h>
00010 #include <badesca.h>    // CDesCArrayFlat (cannot be forward declarated)
00011 #include <d32dbms.h>    // RDbStoreDatabase
00012 #include <f32file.h>    // RFs
00013 
00014 
00015 // Forward declarations
00016 class CFileStore;
00017 
00018 // Constants
00019 _LIT(KBooksTable, "Books");                /* Name of the one table       */
00020 _LIT(KBooksAuthorCol, "Author");           /* First column                */
00021 _LIT(KBooksTitleCol, "Title");             /* Second column               */
00022 _LIT(KBooksDescriptionCol, "Description"); /* Third column                */
00023 _LIT(KBooksDateCol,"PublishDate");         /* Dynamic optional column     */
00024 _LIT(KBooksIndexName,"BooksIndex");        /* Name of the one index       */
00025 const int KTitleMaxLength = 60;            /* Max length of title column  */
00026 const int KDescriptionMaxLength = 128;     /* Max length of descr. column */
00027 
00028 
00033 const int KBookItemMaxLength = 256;
00034 
00039 _LIT(KSeparator,"|");
00040 
00041 
00074 class CBookDb : public CBase
00075     {
00076 public: // Creation and destruction
00077 
00083     static CBookDb* NewL();
00084 
00090     ~CBookDb();
00091 
00092 
00093 public: // Public API for database operations
00094 
00110     TInt OpenDb(const TFileName& aExistingBookFile);
00111 
00130     TInt CreateDb(const TFileName& aNewBookFile);
00131 
00145     TInt RemoveDb(const TFileName& aExistingBookFile);
00146 
00157     TInt Close();
00158 
00165     TBool IsOpen() const;
00166 
00183     TInt AddBookWithSql(const TDesC& aAuthor,
00184                          const TDesC& aTitle,
00185                          const TDesC& aDescription);
00186 
00203     TInt AddBookWithCppApiL(const TDesC& aAuthor,
00204                             const TDesC& aTitle,
00205                             const TDesC& aDescription);
00206 
00217     CDesCArrayFlat* GetAllBooksL();
00218 
00235     CDesCArrayFlat* GetBooksByKeyL(const TDesC& aColumnName,
00236         const TDesC& aSearchString);
00237 
00252     TInt GetABookFast(const TDesC& aTitle, TDes& aResult);
00253 
00267     TInt RemoveBooks(const TDesC& aTitle, TInt& aResultCount);
00268 
00278     TInt RemoveAllBooks(TInt& aResultCount);
00279 
00280 
00293     TInt UpdateBookTitle(const TDesC& aOldTitleKey, const TDesC& aNewTitle);
00294 
00295 
00296 
00307     CDesCArrayFlat* ColumnNamesAndSizesL();
00308 
00316     TInt HasDateColumn(TBool& aReturnValue);
00317 
00327     TInt AddDateColumn();
00328 
00338     TInt RemoveDateColumn();
00339 
00340 private: // Construction
00341 
00348     void ConstructL();
00349 
00355     CBookDb();
00356 
00357 private: // Helpers
00358 
00359     void CreateBooksTableL();     /* Create the Books table                  */
00360     void CreateBooksIndexL();     /* Create the BooksIndex for Books table   */
00361     void DropBooksTable();       /* Drop Books table (DDL example)          */
00362 
00363 private: // Member data
00364 
00365     RFs              iFsSession;  /* For use of iFileStore                   */
00366     RDbStoreDatabase iBookDb;/* For database operations                 */
00367     CFileStore*      iFileStore;  /* For creating and opening database files */
00368     TBool            iOpen;       /* Flag indicating iBookDb open status*/
00369     };
00370 
00371 #endif // __BOOKDBENGINE_H__
00372 
00373 

Generated by  doxygen 1.6.2