Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3472556
  • 博文数量: 1450
  • 博客积分: 11163
  • 博客等级: 上将
  • 技术积分: 11101
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-25 14:40
文章分类

全部博文(1450)

文章存档

2017年(5)

2014年(2)

2013年(3)

2012年(35)

2011年(39)

2010年(88)

2009年(395)

2008年(382)

2007年(241)

2006年(246)

2005年(14)

分类: C/C++

2009-07-15 18:10:06

这段代码比较简单,主要说明下面向个成员函数:

//因为SYMBIAN的数据库是由文件实现的,也就是用一个文件来实现数据库。该变量用于连接文件服务器
RFs              iFsSession;  /* For use of iFileStore                   */

//该成员变量用于对数据库的操作,如创建数据库,删除数据库,创建表等等
RDbStoreDatabase iBookDb;/* For database operations                 */

//该成员变量用于创建或删除文件。即对文件的操作由该变量完成。
CFileStore*      iFileStore;  /* For creating and opening database files */



废话不多说了,看看代码吧:

DBMSEngine.h

/*
 * Copyright � 2008 Nokia Corporation.
 */

#ifndef __BOOKDBENGINE_H__
#define __BOOKDBENGINE_H__


#include
#include    // CDesCArrayFlat (cannot be forward declarated)
#include    // RDbStoreDatabase
#include    // RFs


// Forward declarations
class CFileStore;

// Constants
_LIT(KBooksTable, "Books");                /* Name of the one table       */
_LIT(KBooksAuthorCol, "Author");           /* First column                */
_LIT(KBooksTitleCol, "Title");             /* Second column               */
_LIT(KBooksDescriptionCol, "Description"); /* Third column                */
_LIT(KBooksDateCol,"PublishDate");         /* Dynamic optional column     */
_LIT(KBooksIndexName,"BooksIndex");        /* Name of the one index       */
const int KTitleMaxLength = 60;            /* Max length of title column  */
const int KDescriptionMaxLength = 128;     /* Max length of descr. column */


/**
 *  Maximum length of individual item in CDesCArrayFlat (see GetAllBooksL &
 *  GetBooksByKeyL methods).
 */
const int KBookItemMaxLength = 256;

/**
 *  Separator within individual CDesCArrayFlat item. Each item has format
 *  ||<Description></div><div> */</div><div>_LIT(KSeparator,"|");</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>/**</div><div> * Class:       CBookDb</div><div> *</div><div> * Description: An instance of class CBookDb provides simple Book</div><div> *              database access: creating & manipulating Book database</div><div> *              files and database entries (books).</div><div> *</div><div> * Database definition:</div><div> *</div><div> *              The Book contains one table as follows:</div><div> *</div><div> *              Table name: Books</div><div> *                 Column:       Type:          Max length:</div><div> *                 ------        -----          -----------</div><div> *                 Author        EDbColText     50  (using default)</div><div> *                 Title         EDbColText     60  (see KTitleMaxLength)</div><div> *                 Description   EDbColLongText 128 (see KDescriptionMaxLength)</div><div> *    In run time: PublishDate   EDbColDateTime</div><div> *</div><div> *              Note that underlying database allows description to be up to</div><div> *              2GB long, but this engine limits the size to 128 unicode</div><div> *              characters.</div><div> *              The PublishDate does not exist, when the database is created.</div><div> *              It can be added on the fly (see AddDateColumnL method).</div><div> *</div><div> *              There is also index for Books table with name "BooksIndex". It</div><div> *              consists of two columns:</div><div> *</div><div> *                   Author, Title</div><div> *</div><div> *              Index provides quick find.</div><div> */</div><div>class CBookDb : public CBase</div><div>    {</div><div>public: // Creation and destruction</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    NewL</div><div>     *</div><div>     * Description: Get instance of a CBookDb object.</div><div>     */</div><div>    static CBookDb* NewL();</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    ~CBookDb</div><div>     *</div><div>     * Description: Destroy the object.</div><div>     */</div><div>    ~CBookDb();</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>public: // Public API for database operations</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    OpenDbL</div><div>     *</div><div>     * Description: Open existing Book database in exclusive</div><div>     *              (non-shared) mode.</div><div>     *</div><div>     * Param:       aExistingBookFile is full path to Book</div><div>     *              database file.</div><div>     *</div><div>     * Return:      KErrNone, if no error. KErrNotFound, if the file does</div><div>     *              not exist.</div><div>     *</div><div>     * Leaves:      With one of the system wide error codes, if the file</div><div>     *              is not a correct database file.</div><div>     */</div><div>    TInt OpenDb(const TFileName& aExistingBookFile);</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    CreateDbL</div><div>     *</div><div>     * Description: Creates and opens a new Book database. Creates a</div><div>     *              database file, table structure and an index. The database</div><div>     *              will be open in exclusive (non-shareable) mode. The</div><div>     *              database must be closed, when not used any more. If the</div><div>     *              database exists, it is replaced.</div><div>     *</div><div>     * Param:       aNewBookFile Name of the new database file. Is  a full</div><div>     *              path (incl. the filename). Operations following this call</div><div>     *              are performed to the new database file.</div><div>     *</div><div>     * Return:      returns always KErrNone</div><div>     *</div><div>     * Leaves:      If the file cannot be created or database initialized.</div><div>     *              Leaves with system wide error codes.</div><div>     */</div><div>    TInt CreateDb(const TFileName& aNewBookFile);</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    RemoveDbL</div><div>     *</div><div>     * Description: Removes Book database. Closes any open database,</div><div>     *              before dropping the database.</div><div>     *</div><div>     * Param:       aExistingBookFile is full path to Book</div><div>     *              database file.</div><div>     *</div><div>     * Leaves:      If the file file is not a valid database file or the</div><div>     *              database does not containt Books table, the method</div><div>     *              leaves with system wide error codes.</div><div>     */</div><div>    TInt RemoveDb(const TFileName& aExistingBookFile);</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    Close</div><div>     *</div><div>     * Description: Closes the database opened with either OpenDbL or</div><div>     *              CreateDbL. It is safe to close the database even if it</div><div>     *              is closed.</div><div>     *</div><div>     * Return:      KErrNone, if no error. KErrNotFound, if the file does</div><div>     *              not exist.</div><div>     */</div><div>    TInt Close();</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    IsOpen</div><div>     *</div><div>     * Description: Return status, whether the database is open and ready</div><div>     *              for operations.</div><div>     */</div><div>    TBool IsOpen() const;</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    AddBookWithSql</div><div>     *</div><div>     * Description: Adds a new book to Books table. The book is inserted using</div><div>     *              SQL and RDbView.</div><div>     *</div><div>     * Param:       aAuthor Author of the book. Must be shorter than</div><div>     *              the default max text length in Book API (=50). Must not be</div><div>     *              empty.</div><div>     *</div><div>     * Param:       aTitle Title of the book. Must be shorter than</div><div>     *              KTitleMaxLength. Must not be empty.</div><div>     *</div><div>     * Param:       aDescription Description of the book. It must not be longer</div><div>     *              than KDescriptionMaxLength. Must not be empty.</div><div>     */</div><div>    TInt AddBookWithSql(const TDesC& aAuthor,</div><div>                         const TDesC& aTitle,</div><div>                         const TDesC& aDescription);</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    AddBookWithCppApiL</div><div>     *</div><div>     * Description: Adds a new book to Books table. The book is inserted using</div><div>     *              RDbTable API.</div><div>     *</div><div>     * Param:       aAuthor Author of the book. Must be shorter than</div><div>     *              the default max text length in Book API (=50). Must not be</div><div>     *              empty.</div><div>     *</div><div>     * Param:       aTitle Title of the book. Must be shorter than</div><div>     *              KTitleMaxLength. Must not be empty.</div><div>     *</div><div>     * Param:       aDescription Description of the book. It must not be longer</div><div>     *              than KDescriptionMaxLength. Must not be empty.</div><div>     */</div><div>    TInt AddBookWithCppApiL(const TDesC& aAuthor,</div><div>                            const TDesC& aTitle,</div><div>                            const TDesC& aDescription);</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    GetAllBooksL</div><div>     *</div><div>     * Description: Retrieve all books from database.</div><div>     *</div><div>     * Returns:     Array of books. Each array item is represented as follows:</div><div>     *                  <Author>|<Title>|<Description></div><div>     *              Maximum length of each item is KBookItemMaxLength</div><div>     *              Caller takes ownership of the array.</div><div>     */</div><div>    CDesCArrayFlat* GetAllBooksL();</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    GetBooksByKeyL</div><div>     *</div><div>     * Description: Retrieve books from database, which match given column</div><div>     *              and search pattern. Implementation uses SQL.</div><div>     *</div><div>     * Param:       aColumnName Name of the column to apply the search pattern.</div><div>     *              Must be either KBooksAuthorCol or KBooksTitleCol</div><div>     *</div><div>     * Param:       aSearchString Search pattern used to restrict results to.</div><div>     *</div><div>     * Returns:     Array of books. Each array item is represented as follows:</div><div>     *                  <Author>|<Title>|<Description></div><div>     *              Maximum length of each item is KBookItemMaxLength</div><div>     *              Caller takes ownership of the array.</div><div>     */</div><div>    CDesCArrayFlat* GetBooksByKeyL(const TDesC& aColumnName,</div><div>        const TDesC& aSearchString);</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    GetABookFast</div><div>     *</div><div>     * Description: Retrieves book information for given book name. This method</div><div>     *              uses index to find first occurrence of the book.</div><div>     *              Implementation uses exact match.</div><div>     *</div><div>     * Param:       aTitle is name of the book to search for.</div><div>     *</div><div>     * Param:       aResult If there is a matching book, the complete book info</div><div>     *              is written to aResult. It is in the following format:</div><div>     *                  <Author>|<Title>|<Description></div><div>     *              Length of the given descriptor must be KBookItemMaxLength</div><div>     */</div><div>    TInt GetABookFast(const TDesC& aTitle, TDes& aResult);</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    RemoveBooks</div><div>     *</div><div>     * Description: Deletes book(s) from database.</div><div>     *</div><div>     * Param:       aTitle is name of the book to delete. It can contain</div><div>     *              wildcard characters (% for single char, * for zero or</div><div>     *              multiple chars).</div><div>     *</div><div>     * Param:       aResultCount will contain number of deleted books.</div><div>     *</div><div>     * Returns:     KErrNone or one of the system wide error codes.</div><div>     */</div><div>    TInt RemoveBooks(const TDesC& aTitle, TInt& aResultCount);</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    RemoveAllBooksL</div><div>     *</div><div>     * Description: Deletes all books from database.</div><div>     *</div><div>     * Param:       aResultCount will contain number of deleted books.</div><div>     *</div><div>     * Returns:     KErrNone or one of the system wide error codes.</div><div>     */</div><div>    TInt RemoveAllBooks(TInt& aResultCount);</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    UpdateBookTitle</div><div>     *</div><div>     * Description: Changes the title for a book (or books, if there are</div><div>     *              multiple books with the name aOldTitleKey).</div><div>     *</div><div>     * Param:       aOldTitleKey Book title used for getting books for update.</div><div>     *</div><div>     * Param:       aNewTitle New title for the book(s).</div><div>     *</div><div>     * Returns:     KErrNone or one of the system wide error codes.</div><div>     */</div><div>    TInt UpdateBookTitle(const TDesC& aOldTitleKey, const TDesC& aNewTitle);</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    ColumnNamesAndSizes</div><div>     *</div><div>     * Description: Get array of colum names in the Books table. The result</div><div>     *              array includes also the size of the textual columns.</div><div>     *              This is here just to demonstrate iterating column names</div><div>     *              from a table.</div><div>     *</div><div>     * Returns:     Array of column names. Caller takes ownership.</div><div>     */</div><div>    CDesCArrayFlat* ColumnNamesAndSizesL();</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    HasDateColumn</div><div>     *</div><div>     * Description: Tests whether the Books table has date column.</div><div>     *</div><div>     * Returns:     KErrNone or one of the system wide error codes.</div><div>     */</div><div>    TInt HasDateColumn(TBool& aReturnValue);</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    AddDateColumn</div><div>     *</div><div>     * Description: Adds date column to Books table. This here just to</div><div>     *              demonstrate how to alter table definition.</div><div>     *              This fails, if the date column already exists.</div><div>     *</div><div>     * Returns:     KErrNone or one of the system wide error codes.</div><div>     */</div><div>    TInt AddDateColumn();</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    RemoveDateColumn</div><div>     *</div><div>     * Description: Removes date column from Books table. This here just to</div><div>     *              demonstrate how to alter table definition.</div><div>     *              This fails, if the date column does not exist.</div><div>     *</div><div>     * Returns:     KErrNone or one of the system wide error codes.</div><div>     */</div><div>    TInt RemoveDateColumn();</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>private: // Construction</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    ConstructL</div><div>     *</div><div>     * Description: Perform the second phase construction of a CBookDb</div><div>     *              object</div><div>     */</div><div>    void ConstructL();</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    /**</div><div>     * Function:    CBookDb</div><div>     *</div><div>     * Description: Perform the first phase of two phase construction.</div><div>     */</div><div>    CBookDb();</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>private: // Helpers</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    void CreateBooksTableL();     /* Create the Books table                  */</div><div>    void CreateBooksIndexL();     /* Create the BooksIndex for Books table   */</div><div>    void DropBooksTable();       /* Drop Books table (DDL example)          */</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>private: // Member data</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div>    RFs              iFsSession;  /* For use of iFileStore                   */</div><div>    RDbStoreDatabase iBookDb;/* For database operations                 */</div><div>    CFileStore*      iFileStore;  /* For creating and opening database files */</div><div>    TBool            iOpen;       /* Flag indicating iBookDb open status*/</div><div>    };</div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">DBMSEngine.cpp</span></font></div><div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">/*</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> * Copyright � 2008 Nokia Corporation.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> */</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">#include <badesca.h>    // CDesCArrayFlat</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">#include <s32file.h>    // CFileStore & CPermanentFileStore</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">#include <bautils.h>    // file helpers</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">#include <eikenv.h></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">#include "DBMSEngine.h"</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Implementation specific constants</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">const int KCustomSqlMaxLength = 256;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">const int KArrayGranularity = 5;     // for CDesCArrayFlat</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::NewL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Create instance of the Book database engine.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">CBookDb* CBookDb::NewL() </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CBookDb* tmp = new (ELeave)CBookDb();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PushL(tmp);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    tmp->ConstructL();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::Pop();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return tmp;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::~CBookDb()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Destructor of the Book database engine. Release resources.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">CBookDb::~CBookDb()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    Close();  // Just in case, if the user does not close this explicitely</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    iFsSession.Close();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::ConstructL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Second phase construction. Leaves, if RFs session cannot be created.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">void CBookDb::ConstructL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt err = iFsSession.Connect();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(err)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        User::Leave(err);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::CBookDb()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Constructor</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">CBookDb::CBookDb()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    iOpen = EFalse;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::OpenDbL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Open existing Book database for exclusive access.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::OpenDb(const TFileName& aExistingBookFile)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    Close();</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(!BaflUtils::FileExists(iFsSession, aExistingBookFile))</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">            return KErrNotFound;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TRAPD(error, </span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">iFileStore = CPermanentFileStore::OpenL(iFsSession, aExistingBookFile, </span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">EFileRead|EFileWrite);</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">iFileStore->SetTypeL(iFileStore->Layout());/* Set file store type*/</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">iBookDb.OpenL(iFileStore,iFileStore->Root())</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(error!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return error;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    iOpen = ETrue;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return KErrNone;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::CreateDbL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Create a new database. The database will be in exclusive access mode.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::CreateDb(const TFileName& aNewBookFile)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    Close();</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Create empty database file.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TRAPD(error,</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">iFileStore = CPermanentFileStore::ReplaceL(iFsSession, aNewBookFile, </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">EFileRead|EFileWrite);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">iFileStore->SetTypeL(iFileStore->Layout());// Set file store type</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TStreamId id = iBookDb.CreateL(iFileStore);// Create stream object</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">iFileStore->SetRootL(id);// Keep database id as root of store</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">iFileStore->CommitL();// Complete creation by commiting</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Create Book tables and indexes</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">CreateBooksTableL();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">CreateBooksIndexL();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(error!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return error;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    iOpen = ETrue;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return KErrNone;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::RemoveDb()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// First remove the Books table. Then remove the database file.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::RemoveDb(const TFileName& aExistingBookFile)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    Close();</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(!BaflUtils::FileExists(iFsSession, aExistingBookFile))</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">            return KErrNotFound;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // It is enough to delete the database file directly. Because this example</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // demonstrates DDL statements, it first opens and drops the Books table.</span></font></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt error = OpenDb(aExistingBookFile);</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">if(error!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return error;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    DropBooksTable();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    Close();</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    iFsSession.Delete(aExistingBookFile);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return KErrNone;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::Close()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Close the database.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::Close()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    iBookDb.Close();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(iFileStore)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        delete iFileStore;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        iFileStore = NULL;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    iOpen = EFalse;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return KErrNone;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::IsOpen()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Return open status of the database.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TBool CBookDb::IsOpen() const</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return iOpen;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::CreateBooksTableL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Creates Books table. Leaves, if the table cannot be created.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">void CBookDb::CreateBooksTableL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Specify columns for Books table</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TDbCol authorCol(KBooksAuthorCol, EDbColText);   // Using default length</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TDbCol titleCol(KBooksTitleCol, EDbColText, KTitleMaxLength);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    titleCol.iAttributes = TDbCol::ENotNull;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TDbCol descriptionCol(KBooksDescriptionCol, EDbColLongText); // Stream Data</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Add the columns to column set</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CDbColSet* bookColSet = CDbColSet::NewLC();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    bookColSet->AddL(authorCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    bookColSet->AddL(titleCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    bookColSet->AddL(descriptionCol);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Create the Books table</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    User::LeaveIfError(iBookDb.CreateTable(KBooksTable,</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        *bookColSet));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PopAndDestroy(bookColSet);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::CreateBooksIndexL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Creates an index for Books table. Leaves, if the index cannot be created.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">void CBookDb::CreateBooksIndexL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Create index consisting of two columns</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TDbKeyCol authorCol(KBooksAuthorCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TDbKeyCol titleCol(KBooksTitleCol);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CDbKey* index = CDbKey::NewLC();   // create index key set</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    index->AddL(titleCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    index->AddL(authorCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    User::LeaveIfError(iBookDb.CreateIndex(</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        KBooksIndexName, KBooksTable, *index));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PopAndDestroy(index);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::DropBooksTable()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Drop the Books table incrementally. Uses RDbIncremental and DDL statement.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">void CBookDb::DropBooksTable()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    _LIT(KDropTable, "DROP TABLE ");</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Sql: DROP TABLE Books</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBuf<KCustomSqlMaxLength> sqlStr;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KDropTable);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksTable);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    RDbIncremental incOp;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt incStep = 0xFFFF;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Initialise Execution</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt incStat = incOp.Execute(iBookDb, sqlStr, incStep);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    while (incStep>0 && incStat==KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        incStat = incOp.Next(incStep); // Do the work</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    incOp.Close();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::AddBookWithSqlL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Add a book to database using RDbView and SQL</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::AddBookWithSql(const TDesC& aAuthor,</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">                         const TDesC& aTitle,</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">                         const TDesC& aDescription)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(aAuthor.Length()==0 || aTitle.Length()==0 || aDescription.Length()==0)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        return KErrGeneral;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KSelect, "SELECT ");</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KFrom, " FROM ");</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KOrderBy, " ORDER BY ");</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KDot, ", ");</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Sql: SELECT Author, Title, Description FROM Books ORDER BY Title, Author</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBuf<KCustomSqlMaxLength> sqlStr;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KSelect);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksAuthorCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KDot);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksTitleCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KDot);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksDescriptionCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KFrom);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksTable);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KOrderBy);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksTitleCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KDot);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksAuthorCol);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    RDbView view;    // Create a view on the database</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt error;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    error = view.Prepare(iBookDb, TDbQuery(sqlStr, EDbCompareFolded));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(error!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return error;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    error = view.EvaluateAll();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(error!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return error;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    RDbColWriteStream writeStream;  // Use stream to insert the description</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TRAP(error,</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">view.InsertL();  // Insert a row. Column order matches sql select statement</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">view.SetColL(1, aAuthor);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">   </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">view.SetColL(2, aTitle);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">writeStream.OpenL(view, 3);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">writeStream.WriteL(aDescription);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(error!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return error;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    writeStream.Close();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TRAP(error, view.PutL()); // Complete insertion</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">if(error!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return error;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    } </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    view.Close();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return KErrNone;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::AddBookWithCppApiL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Add a book to database using RDbTable API</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::AddBookWithCppApiL(const TDesC& aAuthor,</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">                            const TDesC& aTitle,</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">                            const TDesC& aDescription)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(aAuthor.Length()==0 || aTitle.Length()==0 || aDescription.Length()==0)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        return KErrGeneral;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Create an updateable database table object</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    RDbTable table;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt err = table.Open(iBookDb, KBooksTable, table.EUpdatable);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(err!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return err;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">CDbColSet* booksColSet = table.ColSetL();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PushL(booksColSet);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    table.Reset();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    RDbColWriteStream writeStream;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TRAPD(error,</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">table.InsertL();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">       </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">table.SetColL(booksColSet->ColNo(KBooksAuthorCol), aAuthor); // col = 1</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">table.SetColL(booksColSet->ColNo(KBooksTitleCol), aTitle);   // col = 2</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Use a stream for the long text column</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">writeStream.OpenL(table, booksColSet->ColNo(KBooksDescriptionCol));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">writeStream.WriteL(aDescription);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">);</span></font></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">if(error!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return error;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }   </span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">writeStream.Close();</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TRAP(err, table.PutL());    // Complete changes (the insertion)</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">if(err!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return err;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }   </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PopAndDestroy(booksColSet);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    table.Close();</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return KErrNone;</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::GetAllBooksL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Get array of all books in database. Format of each array item is:</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//      <Author>|<Title>|<Description></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">CDesCArrayFlat* CBookDb::GetAllBooksL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TPtrC author, title;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBuf<KDescriptionMaxLength> description;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBuf<KBookItemMaxLength> rowText;</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    RDbTable table;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt err = table.Open(iBookDb, KBooksTable, table.EReadOnly);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    User::LeaveIfError(err);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CDesCArrayFlat* resultArray =</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        new (ELeave)CDesC16ArrayFlat(KArrayGranularity);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PushL(resultArray);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    table.Reset();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CDbColSet* colSet = table.ColSetL();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PushL(colSet);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    for (table.FirstL(); table.AtRow(); table.NextL())</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        description.Zero();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        rowText.Zero();</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        table.GetL();</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        author.Set(table.ColDes(colSet->ColNo(KBooksAuthorCol)));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        title.Set(table.ColDes(colSet->ColNo(KBooksTitleCol)));</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        TDbColNo descrColNo = colSet->ColNo(KBooksDescriptionCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        RDbColReadStream readStream;       // A stream object for long columns</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        readStream.OpenLC(table,descrColNo);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        readStream.ReadL(description, table.ColLength(descrColNo));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        readStream.Close();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        CleanupStack::Pop(); //readStream</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        rowText.Append(author);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        rowText.Append(KSeparator);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        rowText.Append(title);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        rowText.Append(KSeparator);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        rowText.Append(description);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        resultArray->AppendL(rowText); // Copy rowText to resultArray</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PopAndDestroy(colSet);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::Pop(resultArray);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    table.Close();</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return resultArray;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::GetABookFast()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Get a book using index. Format of the result is:</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//      <Author>|<Title>|<Description></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::GetABookFast(const TDesC& aTitle, TDes& aResult)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt err = KErrNone;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBuf<KDescriptionMaxLength> description; // Only 128 first characters read</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    RDbTable rowset;</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TDbSeekKey seekKey(aTitle); // Initialize one-column seek key</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Open view to "Books" table. Use index to browse the table.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    err = rowset.Open(iBookDb, KBooksTable, rowset.EReadOnly);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(err!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return err;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    err = rowset.SetIndex(KBooksIndexName);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(err!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return err;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Query colum numbers for author, title, and description</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CDbColSet* colSet=NULL;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TRAP(err, colSet = rowset.ColSetL());</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(err!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return err;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt authorColumnNo = colSet->ColNo(KBooksAuthorCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt titleColumnNo = colSet->ColNo(KBooksTitleCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt descrColumnNo = colSet->ColNo(KBooksDescriptionCol);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Search the index for aTitle</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBool isTitle = false;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TRAP(err, isTitle = rowset.SeekL(seekKey));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(isTitle)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        RDbColReadStream readStream;     // A stream object for long columns</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        TRAPD(error, </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">rowset.GetL();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">readStream.OpenL(rowset,descrColumnNo);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">readStream.ReadL(description, rowset.ColLength(descrColumnNo));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        if(error!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return error;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        readStream.Close();</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        aResult.Zero();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        aResult.Append(rowset.ColDes(authorColumnNo));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        aResult.Append(KSeparator);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        aResult.Append(rowset.ColDes(titleColumnNo));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        aResult.Append(KSeparator);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        aResult.Append(description);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        err = KErrNone;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    else</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        err = KErrNotFound;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    rowset.Close();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return err;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::GetBooksByKeyL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Get array of books from database according to column name and a search</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// pattern. Format of each array item is:</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//      <Author>|<Title>|<Description></span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">CDesCArrayFlat* CBookDb::GetBooksByKeyL(const TDesC& aColumnName,</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    const TDesC& aSearchString)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TPtrC author, title;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBuf<KDescriptionMaxLength> description;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBuf<KBookItemMaxLength> rowText;</span></font></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KSelect, "SELECT ");</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KFrom, " FROM ");</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KWhere, " WHERE ");</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KLike, " LIKE '");</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KOrderBy, "' ORDER BY ");</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KDot, ", ");</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Sql: SELECT Author, Title, Description FROM Books</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    //      WHERE "aColumnName LIKE aSearchString"</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    //      ORDER BY Title, Author</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBuf<KCustomSqlMaxLength> sqlStr;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KSelect);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksAuthorCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KDot);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksTitleCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KDot);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksDescriptionCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KFrom);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksTable);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KWhere);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(aColumnName);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KLike);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(aSearchString);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KOrderBy);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksTitleCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KDot);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksAuthorCol);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CDesCArrayFlat* resultArray =</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        new (ELeave)CDesC16ArrayFlat(KArrayGranularity);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PushL(resultArray);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Create a view on the database</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    RDbView view;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    User::LeaveIfError(</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        view.Prepare(iBookDb, TDbQuery(sqlStr), view.EReadOnly));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    User::LeaveIfError(view.EvaluateAll());</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CDbColSet* colSet = view.ColSetL();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PushL(colSet);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Append each result row to array</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    for (view.FirstL(); view.AtRow(); view.NextL())</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        description.Zero();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        rowText.Zero();</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        view.GetL();</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        author.Set(view.ColDes(colSet->ColNo(KBooksAuthorCol)));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        title.Set(view.ColDes(colSet->ColNo(KBooksTitleCol)));</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        TDbColNo descrColNo = colSet->ColNo(KBooksDescriptionCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        RDbColReadStream readStream;       // A stream object for long columns</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        readStream.OpenLC(view, descrColNo);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        readStream.ReadL(description, view.ColLength(descrColNo));</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        readStream.Close();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        CleanupStack::Pop(); //readStream</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        rowText.Append(author);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        rowText.Append(KSeparator);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        rowText.Append(title);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        rowText.Append(KSeparator);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        rowText.Append(description);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        resultArray->AppendL(rowText);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PopAndDestroy(colSet);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    view.Close();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::Pop(resultArray);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return resultArray;</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::RemoveBooks()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Delete a book using title pattern and RDbUpdate (DML)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::RemoveBooks(const TDesC& aTitle, TInt& aResultCount)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    RDbUpdate updOp;</span></font></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KDeleteFrom, "DELETE FROM ");</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KWhere, " WHERE ");</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KLike, " LIKE '");</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">_LIT(KDot, "'");</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Sql: DELETE FROM Books WHERE Title LIKE 'aTitle'</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBuf<KCustomSqlMaxLength> sqlStr;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KDeleteFrom);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksTable);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KWhere);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksTitleCol);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KLike);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(aTitle);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KDot);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Initialize execution and perform the first step.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Note: Execute() returns 0 (=KErrNone), but it does not affect database</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    //       until Next() is called.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt incStat = updOp.Execute(iBookDb, sqlStr, EDbCompareFolded);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    incStat = updOp.Next(); // This will leave, if Execute() failed.</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    while( incStat == 1 ) // Just in case, if the operation has more steps</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        incStat = updOp.Next();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    aResultCount = updOp.RowCount();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    updOp.Close();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return incStat; // KErrNone or system wide error code</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::RemoveAllBooks()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Delete books using asynchronous API. (RDbUpdate and DML)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// This implementation is still synchronous, because it uses</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// User::WaitForRequest. Normally asynchronous functionality should be hidden</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// into active object and client callback interfaces.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::RemoveAllBooks(TInt& aResultCount)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    _LIT(KDeleteFrom, "DELETE FROM ");</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Sql: DELETE FROM Books</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBuf<KCustomSqlMaxLength> sqlStr;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KDeleteFrom);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KBooksTable);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    RDbUpdate updOp;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TRequestStatus incStat(1);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt updStat = updOp.Execute(iBookDb, sqlStr, EDbCompareFolded);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    while (updStat==KErrNone && incStat ==1)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        updOp.Next(incStat);           // Start async operation. It returns</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">                                       // immediately.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        User::WaitForRequest(incStat); // For simplicity wait completion here.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    aResultCount = updOp.RowCount();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    updOp.Close();</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(updStat!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        return updStat;       // System wide error code</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    else</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        return incStat.Int(); // KErrNone or system wide error code</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::UpdateBookTitle()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Update book title using SQL UPDATE.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::UpdateBookTitle(const TDesC& aOldTitleKey,</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    const TDesC& aNewTitle)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    _LIT(KSQLUpdateStart, "UPDATE Books SET Title = '");</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    _LIT(KSQLUpdateMiddle, "' WHERE Title = '");</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    _LIT(KSQLUpdateEnd, "'");</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBuf<KCustomSqlMaxLength> sqlStr;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KSQLUpdateStart);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(aNewTitle);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KSQLUpdateMiddle);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(aOldTitleKey);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    sqlStr.Append(KSQLUpdateEnd);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return iBookDb.Execute(sqlStr);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::ColumnNamesAndSizesL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Get array of column names and sizes of the Books table.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">CDesCArrayFlat* CBookDb::ColumnNamesAndSizesL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    RDbTable booksTable;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TBuf<32> columnNameAndSize;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    _LIT(KDelimiter, ": ");</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    _LIT(KNoSize,"No size");</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Open the Books table.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt err = booksTable.Open(iBookDb, KBooksTable, booksTable.EReadOnly);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    User::LeaveIfError(err);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupClosePushL(booksTable);  // Remember to pop and close</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CDesCArrayFlat* resultArray =</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        new (ELeave)CDesC16ArrayFlat(KArrayGranularity);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PushL(resultArray);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Iterate through the colums of Books table. Extract the column name and</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // column size (size only for text columns).�</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Note: Description column is long text. Database limits its size</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    //       only by hardware. If size is queried, it is -1</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CDbColSet* colSet = booksTable.ColSetL();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PushL(colSet);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TDbColSetIter colIter(*colSet);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    while(colIter)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        columnNameAndSize.Zero();</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        columnNameAndSize.Append(colIter->iName);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        columnNameAndSize.Append(KDelimiter);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        if(colIter->iType == EDbColText)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">            columnNameAndSize.AppendNum(colIter->iMaxLength);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        else</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">            columnNameAndSize.Append(KNoSize);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        resultArray->AppendL(columnNameAndSize);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        colIter++;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PopAndDestroy(colSet);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::Pop(resultArray);</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Pop the booksTable from cleanup stack and close it.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CleanupStack::PopAndDestroy();</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return resultArray;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::HasDateColumnL()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Tests wheter the Books table has date column</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::HasDateColumn(TBool& aReturnValue)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    RDbTable booksTable;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    aReturnValue = EFalse;</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Open the Books table.</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TInt err = booksTable.Open(iBookDb, KBooksTable, booksTable.EReadOnly);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(err!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return err;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // Iterate through the colums of Books table. Check whether there is</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    // a 'PublishDate' column</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    CDbColSet* colSet=NULL;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TRAP(err, colSet = booksTable.ColSetL());</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    if(err!=KErrNone)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;"> </span></font></span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">return err;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    TDbColSetIter colIter(*colSet);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    while(colIter)</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        if( (colIter->iName).Compare(KBooksDateCol) == 0) // 0 = equal</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">            {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">            aReturnValue = ETrue;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">            break;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">            }</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        colIter++;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">        }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return KErrNone;</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::AddDateColumn()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Adds date column to Books table (DDL).</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::AddDateColumn()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    _LIT(KSqlAddDate, "ALTER TABLE Books ADD PublishDate DATE");</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return iBookDb.Execute(KSqlAddDate);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// CBookDb::RemoveDateColumn()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">//</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// Removes date column from Books table (DDL).</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">// ---------------------------------------------------------------------------</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">TInt CBookDb::RemoveDateColumn()</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    {</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    _LIT(KSqlRemoveDate, "ALTER TABLE Books DROP PublishDate");</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    return iBookDb.Execute(KSqlRemoveDate);</span></font></div><div><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 13px;">    }</span></font></div><div><br></div></div> </div> <!-- <div class="Blog_con3_1">管理员在2009年8月13日编辑了该文章文章。</div> --> <div class="Blog_con2_1 Blog_con3_2"> <div> <!--<img src="/image/default/tu_8.png">--> <!-- JiaThis Button BEGIN --> <div class="bdsharebuttonbox"><A class=bds_more href="#" data-cmd="more"></A><A class=bds_qzone title=分享到QQ空间 href="#" data-cmd="qzone"></A><A class=bds_tsina title=分享到新浪微博 href="#" data-cmd="tsina"></A><A class=bds_tqq title=分享到腾讯微博 href="#" data-cmd="tqq"></A><A class=bds_renren title=分享到人人网 href="#" data-cmd="renren"></A><A class=bds_weixin title=分享到微信 href="#" data-cmd="weixin"></A></div> <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> <!-- JiaThis Button END --> </div> 阅读(422) | 评论(0) | 转发(0) | <div class="HT_line3"></div> </div> <div class="Blog_con3_3"> <div><span id='digg_num'>0</span><a href="javascript:void(0)" id='digg' bid='2086251' url='/blog/digg.html' ></a></div> <p>上一篇:<a href="/uid-618047-id-2086250.html">symbian 数据库操作</a></p> <p>下一篇:<a href="/uid-618047-id-2086254.html">symbian 在Dialog中显示Listbox</a></p> </div> </div> <!-- <div class="Blog_con3_4 Blog_con3_5"> <div class="Blog_tit2 Blog_tit7">热门推荐</div> <ul> <li><a href="" title="" target='blank' ></a></li> </ul> </div> --> </div> </div> <div class="Blog_right1_7" id='replyList'> <div class="Blog_tit3">给主人留下些什么吧!~~</div> <!--暂无内容--> <!-- 评论分页--> <div class="Blog_right1_6 Blog_right1_12"> </div> <!-- 评论分页--> <div class="Blog_right1_10" style="display:none"> <div class="Blog_tit3">评论热议</div> <!--未登录 --> <div class="Blog_right1_8"> <div class="nologin_con1"> 请登录后评论。 <p><a href="http://account.chinaunix.net/login" onclick="link(this)">登录</a> <a href="http://account.chinaunix.net/register?url=http%3a%2f%2fblog.chinaunix.net">注册</a></p> </div> </div> </div> <div style="text-align:center;margin-top:10px;"> <script type="text/javascript" smua="d=p&s=b&u=u3118759&w=960&h=90" src="//www.nkscdn.com/smu0/o.js"></script> </div> </div> </div> </div> <input type='hidden' id='report_url' value='/blog/ViewReport.html' /> <script type="text/javascript"> //测试字符串的长度 一个汉字算2个字节 function mb_strlen(str) { var len=str.length; var totalCount=0; for(var i=0;i<len;i++) { var c = str.charCodeAt(i); if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) { totalCount++; }else{ totalCount+=2; } } return totalCount; } /* var Util = {}; Util.calWbText = function (text, max){ if(max === undefined) max = 500; var cLen=0; var matcher = text.match(/[^\x00-\xff]/g), wlen = (matcher && matcher.length) || 0; //匹配url链接正则 http://*** var pattern = /http:\/\/([\w-]+\.)+[\w-]+(\/*[\w-\.\/\?%&=][^\s^\u4e00-\u9fa5]*)?/gi; //匹配的数据存入数组 var arrPt = new Array(); var i = 0; while((result = pattern.exec(text)) != null){ arrPt[i] = result[0]; i++; } //替换掉原文本中的链接 for(var j = 0;j<arrPt.length;j++){ text = text.replace(arrPt[j],""); } //减掉链接所占的长度 return Math.floor((max*2 - text.length - wlen)/2 - 12*i); }; */ var allowComment = '0'; //举报弹出层 function showJuBao(url, cid){ $.cover(false); asyncbox.open({ id : 'report_thickbox', url : url, title : '举报违规', width : 378, height : 240, scroll : 'no', data : { 'cid' : cid, 'idtype' : 2 , 'blogurl' : window.location.href }, callback : function(action){ if(action == 'close'){ $.cover(false); } } }); } $(function(){ //创建管理员删除的弹出层 $('#admin_article_del').click(function(){ $.cover(false); asyncbox.open({ id : 'class_thickbox', html : '<div class="HT_layer3_1"><ul><li class="HT_li1">操作原因:<select class="HT_sel7" id="del_type" name="del_type"><option value="广告文章">广告文章</option><option value="违规内容">违规内容</option><option value="标题不明">标题不明</option><option value="文不对题">文不对题</option></select></li><li class="HT_li1" ><input class="HT_btn4" id="admin_delete" type="button" /></li></ul></div>', title : '选择类型', width : 300, height : 150, scroll : 'no', callback : function(action){ if(action == 'close'){ $.cover(false); } } }); }); $('#admin_delete').live('click' , function(){ ///blog/logicdel/id/3480184/url/%252Fblog%252Findex.html.html var type = $('#del_type').val(); var url = '/blog/logicdel/id/2086251/url/%252Fuid%252F618047.html.html'; window.location.href= url + '?type=' + type; }); //顶 js中暂未添加&过滤 $('#digg').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $('#digg').attr('bid'); var url = $('#digg').attr('url'); var digg_str = $.cookie('digg_id'); if(digg_str != null) { var arr= new Array(); //定义一数组 arr = digg_str.split(","); //字符分割 for( i=0 ; i < arr.length ; i++ ) { if(bid == arr[i]) { showErrorMsg('已经赞过该文章', '消息提示'); return false; } } } $.ajax({ type:"POST", url:url, data: { 'bid' : bid }, dataType: 'json', success:function(msg){ if(msg.error == 0) { var num = parseInt($('#digg_num').html(),10); num += 1; $('#digg_num').html(num); $('#digg').die(); if(digg_str == null) { $.cookie('digg_id', bid, {expires: 30 , path: '/'}); } else { $.cookie('digg_id', digg_str + ',' + bid, {expires: 30 , path: '/'}); } showSucceedMsg('谢谢' , '消息提示'); } else if(msg.error == 1) { //showErrorMsg(msg.error_content , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); } else if(msg.error == 2) { showErrorMsg(msg.error_content , '消息提示'); } } }); }); //举报弹出层 /*$('.box_report').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var url = $('#report_url').val(); var cid = $(this).attr('cid'); $.cover(false); asyncbox.open({ id : 'report_thickbox', url : url, title : '举报违规', width : 378, height : 240, scroll : 'no', data : { 'cid' : cid, 'idtype' : 2 }, callback : function(action){ if(action == 'close'){ $.cover(false); } } }); });*/ //评论相关代码 //点击回复显示评论框 $('.Blog_a10').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } if(allowComment == 1) { showErrorMsg('该博文不允许评论' , '消息提示'); return false; } var tid = $(this).attr('toid');//留言作者id var bid = $(this).attr('bid');//blogid var cid = $(this).attr('cid');//留言id var tname = $(this).attr('tname'); var tpl = '<div class="Blog_right1_9">'; tpl += '<div class="div2">'; tpl += '<textarea name="" cols="" rows="" class="Blog_ar1_1" id="rmsg">文明上网,理性发言...</textarea>'; tpl += '</div>'; tpl += '<div class="div3">'; tpl += '<div class="div3_2"><a href="javascript:void(0);" class="Blog_a11" id="quota_sbumit" url="/Comment/PostComment.html" tid="'+tid+'" bid="'+bid+'" cid="'+cid+'" tname="'+tname+'" ></a><a href="javascript:void(0)" id="qx_comment" class="Blog_a12"></a></div>'; tpl += '<div class="div3_1"><a href="javascript:void(0);" id="mface"><span></span>表情</a></div>'; tpl += '<div class="clear"></div>'; tpl += '</div>'; tpl += '</div>'; $('.z_move_comment').html(''); $(this).parents('.Blog_right1_8').find('.z_move_comment').html(tpl).show(); }); //引用的评论提交 $('#quota_sbumit').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $(this).attr('bid'); var tid = $(this).attr('tid');//被引用人的id var qid = $(this).attr('cid');//引用的id var url = $(this).attr('url'); var text = $('#rmsg').val(); var tname = $(this).attr('tname'); if(text == '' || text=='文明上网,理性发言...') { showErrorMsg('评论内容不能为空!' , '消息提示'); return false; } else { if(mb_strlen(text) > 1000){ showErrorMsg('评论内容不能超过500个汉字' , '消息提示'); return false; } } $.ajax({ type: "post", url: url , data: {'bid': bid , 'to' : tid , 'qid' : qid , 'text': text , 'tname' : tname }, dataType: 'json', success: function(data){ if(data.code == 1){ var tpl = '<div class="Blog_right1_8">'; tpl+= '<div class="Blog_right_img1"><a href="' +data.info.url+ '" >' + data.info.header + '</a></div>'; tpl+= '<div class="Blog_right_font1">'; tpl+= '<p class="Blog_p5"><span><a href="' +data.info.url+ '" >' + data.info.username + '</a></span>' + data.info.dateline + '</p>'; tpl+= '<p class="Blog_p7"><a href="' + data.info.quota.url + '">' + data.info.quota.username + '</a>:'+ data.info.quota.content + '</p>'; tpl+= '<p class="Blog_p8">' + data.info.content + '</p><span class="span_text1"><a href="javascript:void(0);" class="Blog_a10" toid=' + data.info.fuid + ' bid=' + data.info.bid + ' cid=' + data.info.cid + ' tname = ' + data.info.username + ' >回复</a> |  <a class="comment_del_mark" style="cursor:pointer" url="' + data.info.delurl + '" >删除</a> |  <a href="javascript:showJuBao(\'/blog/ViewReport.html\','+data.info.cid+')" class="box_report" cid="' + data.info.cid + '" >举报</a></span></div>'; tpl+= '<div class="z_move_comment" style="display:none"></div>'; tpl+= '<div class="Blog_line1"></div></div>'; $('#replyList .Blog_right1_8:first').before(tpl); $('.z_move_comment').html('').hide(); } else if(data.code == -1){ //showErrorMsg(data.info , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); } }, error: function(){//请求出错处理 } }); }); //底部发表评论 $('#submitmsg').click(function(){ if(allowComment == 1) { showErrorMsg('该博文不允许评论' , '消息提示'); return false; } var bid = $(this).attr('bid'); var toid = $(this).attr('toid'); var text = $('#reply').val(); var url = $(this).attr('url'); if(text == '' || text=='文明上网,理性发言...') { showErrorMsg('评论内容不能为空!' , '消息提示'); return false; } else { if(mb_strlen(text) > 1000){ showErrorMsg('评论内容不能超过500个汉字' , '消息提示'); return false; } } $.ajax({ type: "post", url: url , data: {'bid': bid , 'to' : toid ,'text': text}, dataType: 'json', success: function(data){ if(data.code == 1) { var tpl = '<div class="Blog_right1_8">'; tpl += '<div class="Blog_right_img1"><a href="' +data.info.url+ '" >' + data.info.header + '</a></div>'; tpl += '<div class="Blog_right_font1">'; tpl += '<p class="Blog_p5"><span><a href="' +data.info.url+ '" >' + data.info.username + '</a></span>' + data.info.dateline + '</p>'; tpl += '<p class="Blog_p6">' + data.info.content + '</p>'; tpl += '<div class="div1"><a href="javascript:void(0);" class="Blog_a10" toid=' + data.info.fuid + ' bid=' + data.info.bid + ' cid=' + data.info.cid + '>回复</a> |  <a class="comment_del_mark" style="cursor:pointer" url="' + data.info.delurl + '">删除</a> |  <a href="javascript:showJuBao(\'/blog/ViewReport.html\','+data.info.cid+')" class="box_report" cid="' + data.info.cid + '">举报</a></div>'; tpl += '<div class="z_move_comment" style="display:none"></div>'; tpl += '</div><div class="Blog_line1"></div></div>'; $('.Blog_tit3:first').after(tpl); $('#reply').val('文明上网,理性发言...'); } else if(data.code == -1) { showErrorMsg(data.info , '消息提示'); } }, error: function(){//请求出错处理 } }); }); //底部评论重置 $('#reset_comment').click(function(){ $('#reply').val('文明上网,理性发言...'); }); //取消回复 $('#qx_comment').live('click' , function(){ $('.z_move_comment').html('').hide(); }); $('#rmsg, #reply').live({ focus:function(){ if($(this).val() == '文明上网,理性发言...'){ $(this).val(''); } }, blur:function(){ if($(this).val() == ''){ $(this).val('文明上网,理性发言...'); } } }); //删除留言确认 $('.comment_del_mark').live('click' , function(){ var url = $(this).attr('url'); asyncbox.confirm('删除留言','确认', function(action){ if(action == 'ok') { location.href = url; } }); }); //删除时间确认 $('.del_article_id').click(function(){ var delurl = $(this).attr('delurl'); asyncbox.confirm('删除文章','确认', function(action){ if(action == 'ok') { location.href = delurl; } }); }); /* //字数限制 $('#rmsg, #reply').live('keyup', function(){ var id = $(this).attr('id'); var left = Util.calWbText($(this).val(), 500); var eid = '#errmsg'; if(id == 'reply') eid = '#rerrmsg'; if (left >= 0) $(eid).html('您还可以输入<span>' + left + '</span>字'); else $(eid).html('<font color="red">您已超出<span>' + Math.abs(left) + '</span>字 </font>'); }); */ //加载表情 $('#face').qqFace({id : 'facebox1', assign : 'reply', path : '/image/qqface/'}); $('#mface').qqFace({id : 'facebox', assign : 'rmsg', path:'/image/qqface/'}); /* $('#class_one_id').change(function(){ alert(123213); var id = parseInt($(this).val() , 10); if(id == 0) return false; $('.hidden_son_class span').each(function( index , dom ){ if( dom.attr('cid') == id ) { } }); }); */ //转载文章 var turn_url = "/blog/viewClassPart.html"; $('#repost_bar').click(function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var id = $(this).attr('bid'); asyncbox.open({ id : 'turn_class_thickbox', url : turn_url, title : '转载文章', width : 330, height : 131, scroll : 'no', data : { 'id' : id }, callback : function(action){ if(action == 'close'){ $.cover(false); } } }); }); /* //转发文章 $('#repost_bar').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $(this).attr('bid'); var url = $(this).attr('url'); asyncbox.confirm('转载文章','确认', function(action){ if(action == 'ok'){ $.ajax({ type:"POST", url:url, data: { 'bid' : bid }, dataType: 'json', success:function(msg){ if(msg.error == 0){ showSucceedMsg('转发成功!', '消息提示'); }else if(msg.error == 1){ //location.href = '/index.php?r=site/login'; showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); }else{ showErrorMsg(msg.error_content, '消息提示'); } } }); } }); }); */ }); </script> <!--该部分应该放在输出代码块的后面才起作用 --> <script type="text/javascript"> SyntaxHighlighter.autoloader( 'applescript /highlight/scripts/shBrushAppleScript.js', 'actionscript3 as3 /highlight/scripts/shBrushAS3.js', 'bash shell /highlight/scripts/shBrushBash.js', 'coldfusion cf /highlight/scripts/shBrushColdFusion.js', 'cpp c /highlight/scripts/shBrushCpp.js', 'c# c-sharp csharp /highlight/scripts/shBrushCSharp.js', 'css /highlight/scripts/shBrushCss.js', 'delphi pascal /highlight/scripts/shBrushDelphi.js', 'diff patch pas /highlight/scripts/shBrushDiff.js', 'erl erlang /highlight/scripts/shBrushErlang.js', 'groovy /highlight/scripts/shBrushGroovy.js', 'java /highlight/scripts/shBrushJava.js', 'jfx javafx /highlight/scripts/shBrushJavaFX.js', 'js jscript javascript /highlight/scripts/shBrushJScript.js', 'perl pl /highlight/scripts/shBrushPerl.js', 'php /highlight/scripts/shBrushPhp.js', 'text plain /highlight/scripts/shBrushPlain.js', 'py python /highlight/scripts/shBrushPython.js', 'ruby rails ror rb /highlight/scripts/shBrushRuby.js', 'scala /highlight/scripts/shBrushScala.js', 'sql /highlight/scripts/shBrushSql.js', 'vb vbnet /highlight/scripts/shBrushVb.js', 'xml xhtml xslt html /highlight/scripts/shBrushXml.js' ); SyntaxHighlighter.all(); function code_hide(id){ var code = document.getElementById(id).style.display; if(code == 'none'){ document.getElementById(id).style.display = 'block'; }else{ document.getElementById(id).style.display = 'none'; } } </script> <!--回顶部js2011.12.30--> <script language="javascript"> lastScrollY=0; function heartBeat(){ var diffY; if (document.documentElement && document.documentElement.scrollTop) diffY = document.documentElement.scrollTop; else if (document.body) diffY = document.body.scrollTop else {/*Netscape stuff*/} percent=.1*(diffY-lastScrollY); if(percent>0)percent=Math.ceil(percent); else percent=Math.floor(percent); document.getElementById("full").style.top=parseInt(document.getElementById("full").style.top)+percent+"px"; lastScrollY=lastScrollY+percent; if(lastScrollY<200) { document.getElementById("full").style.display="none"; } else { document.getElementById("full").style.display="block"; } } var gkuan=document.body.clientWidth; var ks=(gkuan-960)/2-30; suspendcode="<div id=\"full\" style='right:-30px;POSITION:absolute;TOP:500px;z-index:100;width:26px; height:86px;cursor:pointer;'><a href=\"javascript:void(0)\" onclick=\"window.scrollTo(0,0);\"><img src=\"\/image\/top.png\" /></a></div>" document.write(suspendcode); window.setInterval("heartBeat()",1); </script> <!-- footer --> <div class="Blog_footer" style='clear:both'> <div><a href="http://www.chinaunix.net/about/index.shtml" target="_blank" rel="nofollow">关于我们</a> | <a href="http://www.it168.com/bottomfile/it168.shtml" target="_blank" rel="nofollow">关于IT168</a> | <a href="http://www.chinaunix.net/about/connect.html" target="_blank" rel="nofollow">联系方式</a> | <a href="http://www.chinaunix.net/about/service.html" target="_blank" rel="nofollow">广告合作</a> | <a href="http://www.it168.com//bottomfile/flgw/fl.htm" target="_blank" rel="nofollow">法律声明</a> | <a href="http://account.chinaunix.net/register?url=http%3a%2f%2fblog.chinaunix.net" target="_blank" rel="nofollow">免费注册</a> <p>Copyright 2001-2010 ChinaUnix.net All Rights Reserved 北京皓辰网域网络信息技术有限公司. 版权所有 </p> <div>感谢所有关心和支持过ChinaUnix的朋友们 <p><a href="http://beian.miit.gov.cn/">16024965号-6 </a></p> </div> </div> </div> </div> <script language="javascript"> //全局错误提示弹出框 function showErrorMsg(content, title, url){ var url = url || ''; var title = title || '消息提示'; var html = ''; html += '<div class="HT_layer3_1 HT_layer3_2"><ul><li><p><span class="login_span1"></span>' + content + '</p></li>'; if(url == '' || url.length == 0){ html += '<li class="HT_li1"><input type="button" class="HT_btn2" onclick=\'close_windows("error_msg")\'></li>'; } else { html += '<li class="HT_li1"><input type="button" class="login_btn1" onclick="location.href=\'' + url + '\'"></li>'; } html += '</ul></div>'; $.cover(true); asyncbox.open({ id: 'error_msg', title : title, html : html, 'callback' : function(action){ if(action == 'close'){ $.cover(false); } } }); } //全局正确提示 function showSucceedMsg(content, title , url ){ var url = url || ''; var title = title || '消息提示'; var html = ''; html += '<div class="HT_layer3_1 HT_layer3_2"><ul><li><p><span class="login_span2"></span>' + content + '</p></li>'; if(url == '' || url.length == 0){ html += '<li class="HT_li1"><input type="button" class="HT_btn2" onclick=\'close_windows("error_msg")\'></li>'; } else { html += '<li class="HT_li1"><input type="button" class="HT_btn2" onclick="location.href=\'' + url + '\'"></li>'; } html += '</ul></div>'; $.cover(true); asyncbox.open({ id: 'error_msg', title : title, html : html, 'callback' : function(action){ if(action == 'close'){ $.cover(false); } } }); } //关闭指定id的窗口 function close_windows(id){ $.cover(false); $.close(id); } //公告 var tID; var tn; // 高度 var nStopTime = 5000; // 不同行间滚动时间隔的时间,值越小,移动越快 var nSpeed = 50; // 滚动时,向上移动一像素间隔的时间,值越小,移动越快 var isMove = true; var nHeight = 25; var nS = 0; var nNewsCount = 3; /** * n 用于表示是否为第一次运行 **/ function moveT(n) { clearTimeout(tID) var noticev2 = document.getElementById("noticev2") nS = nSpeed; // 只在第一次调用时运行,初始化环境(有没有参数) if (n) { // 设置行高 noticev2.style.lineHeight = nHeight + "px"; // 初始化显示位置 tn = 0; // 刚进入时在第一行停止时间 nS = nStopTime; } // 判断鼠标是否指向层 if (isMove) { // 向上移动一像素 tn--; // 如果移动到最下面一行了,则移到顶行 if (Math.abs(tn) == nNewsCount * nHeight) { tn = 0; } // 设置位置 noticev2.style.marginTop = tn + "px"; // 完整显示一行时,停止一段时间 if (tn % nHeight == 0) { nS = nStopTime; } } tID = setTimeout("moveT()", nS); } moveT(1); // 此处可以传入任何参数 </script> <script type="text/javascript"> // var _gaq = _gaq || []; // _gaq.push(['_setAccount', 'UA-20237423-2']); // _gaq.push(['_setDomainName', '.chinaunix.net']); // _gaq.push(['_trackPageview']); // // (function() { // var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; // ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; // var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); // })(); </script> <script type="text/javascript"> var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://"); document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F0ee5e8cdc4d43389b3d1bfd76e83216b' type='text/javascript'%3E%3C/script%3E")); function link(t){ var href= $(t).attr('href'); href+="?url="+encodeURIComponent(location.href); $(t).attr('href',href); //setCookie("returnOutUrl", location.href, 60, "/"); } </script> <script type="text/javascript" src="/js/jquery.qqFace.js"></script> </body> </html>