examples/ForumNokia/DBMS/inc/DBMSEngine.h

00001 /*
00002  * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 #ifndef __BOOKDBENGINE_H__
00031 #define __BOOKDBENGINE_H__
00032 
00033 
00034 #include <e32std.h>
00035 #include <badesca.h>    // CDesCArrayFlat (cannot be forward declarated)
00036 #include <d32dbms.h>    // RDbStoreDatabase
00037 #include <f32file.h>    // RFs
00038 
00039 
00040 // Forward declarations
00041 class CFileStore;
00042 
00043 // Constants
00044 _LIT(KBooksTable, "Books");                /* Name of the one table       */
00045 _LIT(KBooksAuthorCol, "Author");           /* First column                */
00046 _LIT(KBooksTitleCol, "Title");             /* Second column               */
00047 _LIT(KBooksDescriptionCol, "Description"); /* Third column                */
00048 _LIT(KBooksDateCol,"PublishDate");         /* Dynamic optional column     */
00049 _LIT(KBooksIndexName,"BooksIndex");        /* Name of the one index       */
00050 const int KTitleMaxLength = 60;            /* Max length of title column  */
00051 const int KDescriptionMaxLength = 128;     /* Max length of descr. column */
00052 
00053 
00058 const int KBookItemMaxLength = 256;
00059 
00064 _LIT(KSeparator,"|");
00065 
00066 
00099 class CBookDb : public CBase
00100     {
00101 public: // Creation and destruction
00102 
00108     static CBookDb* NewL();
00109 
00115     ~CBookDb();
00116 
00117 
00118 public: // Public API for database operations
00119 
00135     TInt OpenDb(const TFileName& aExistingBookFile);
00136 
00155     TInt CreateDb(const TFileName& aNewBookFile);
00156 
00170     TInt RemoveDb(const TFileName& aExistingBookFile);
00171 
00182     TInt Close();
00183 
00190     TBool IsOpen() const;
00191 
00208     TInt AddBookWithSql(const TDesC& aAuthor,
00209                          const TDesC& aTitle,
00210                          const TDesC& aDescription);
00211 
00228     TInt AddBookWithCppApiL(const TDesC& aAuthor,
00229                             const TDesC& aTitle,
00230                             const TDesC& aDescription);
00231 
00242     CDesCArrayFlat* GetAllBooksL();
00243 
00260     CDesCArrayFlat* GetBooksByKeyL(const TDesC& aColumnName,
00261         const TDesC& aSearchString);
00262 
00277     TInt GetABookFast(const TDesC& aTitle, TDes& aResult);
00278 
00292     TInt RemoveBooks(const TDesC& aTitle, TInt& aResultCount);
00293 
00303     TInt RemoveAllBooks(TInt& aResultCount);
00304 
00305 
00318     TInt UpdateBookTitle(const TDesC& aOldTitleKey, const TDesC& aNewTitle);
00319 
00320 
00321 
00332     CDesCArrayFlat* ColumnNamesAndSizesL();
00333 
00341     TInt HasDateColumn(TBool& aReturnValue);
00342 
00352     TInt AddDateColumn();
00353 
00363     TInt RemoveDateColumn();
00364 
00365 private: // Construction
00366 
00373     void ConstructL();
00374 
00380     CBookDb();
00381 
00382 private: // Helpers
00383 
00384     void CreateBooksTableL();     /* Create the Books table                  */
00385     void CreateBooksIndexL();     /* Create the BooksIndex for Books table   */
00386     void DropBooksTable();       /* Drop Books table (DDL example)          */
00387 
00388 private: // Member data
00389 
00390     RFs              iFsSession;  /* For use of iFileStore                   */
00391     RDbStoreDatabase iBookDb;/* For database operations                 */
00392     CFileStore*      iFileStore;  /* For creating and opening database files */
00393     TBool            iOpen;       /* Flag indicating iBookDb open status*/
00394     };
00395 
00396 #endif // __BOOKDBENGINE_H__
00397 
00398 

Generated by  doxygen 1.6.2