examples/sfexamples/Wikipedia/inc/WikiDb.h

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 
00017 
00018 #ifndef __WIKI_DB_H__
00019 #define __WIKI_DB_H__
00020 
00021 #include <e32std.h>
00022 #include <SqlDb.h>
00023 #include <UTF.h>
00024 
00025 const TInt KMaxCharByCharSqlQueryLen = 1024;
00026 const TInt KMaxCharByCharQueryLen = 128;
00027 const TInt KMaxArticleTextLen = 32768;
00028 const TInt KItemsPerPage = 6;
00029 
00030 #ifdef __WINS__
00031 _LIT(KSqlDbName, "C:\\Wikipedia\\wikipedia.db");
00032 #else
00033 _LIT(KSqlDbName, "e:\\Wikipedia\\wikipedia.db");
00034 #endif
00035 
00036 _LIT8(KSqlDbConfig, "");
00037 _LIT8(KWikiSqlStmtGetArticle, "select content, links from pages where title='%S'");
00038 _LIT8(KWikiSqlStmtJustTitle, "select title from pages where title like '%S%%' order by title");
00039 _LIT8(KWikiSqlStmtTitleOffset, "select title from pages where title like '%S%%' order by title limit -1 offset %D");
00040 
00041 _LIT8(KCountAll, "select sum(count) from countHelper1");
00042 _LIT8(KCountWith1Char, "select count from countHelper1 where prefix='%S'");
00043 _LIT8(KCountWith2Chars, "select sum(count) from countHelper3 where prefix like '%S%%'");
00044 _LIT8(KCountWith3Chars, "select count from countHelper3 where prefix='%S'");
00045 _LIT8(KCountWith4Chars, "select sum(count) from countHelper5 where prefix like '%S%%'");
00046 _LIT8(KCountWith5Chars, "select count from countHelper5 where prefix='%S'");
00047 _LIT8(KCountWithManyChars, "select count(*) from pages where title like '%S%%'");
00048 
00049 _LIT8(KTitleFormat, "<h2>%S</h2>");
00050 _LIT8(KHtmlParagpraph, "<p>");
00051 _LIT8(KLinkFormat, "<a href=\"http://en.wikipedia.org/wiki/%S#%S\">%S</a><br>");
00052 _LIT8(KFullArticleLinkFormat, "<p><a href=\"http://en.wikipedia.org/wiki/%S\">Full article</a><p>");
00053 
00054 enum TRequestCode 
00055         {
00056         ECancel,
00057         ERecordCount,
00058         ERecordCountNext
00059         };
00060 
00061 enum TPageState
00062         {
00063         EInitialise,
00064         EPageUp,
00065         ENextItem
00066         };
00067 
00068 class MWikiCountObserver
00069     {
00070     public:
00071 
00072                 virtual void CountUpdatedL( TInt aError ) = 0;
00073         };
00074 
00075 class CWikiDb : public CActive 
00076         {
00077     public: // Constructor and destructor
00078 
00083                 static CWikiDb* NewL();
00084         
00089                 ~CWikiDb();     
00090 
00091 
00092         private: // Constructors
00093 
00098                 CWikiDb();
00099         
00104                 void ConstructL();
00105         
00106         public:
00107         
00108         // prepares the statements...
00109         void SearchL(const TDesC& aPrefix, MWikiCountObserver* aObserver);
00110         
00111         void PageUpL( const TDesC& aPrefix );
00112         
00117         TBool Next();
00118         
00122         const TInt GetTitle(TPtrC& aTitle);
00123         
00127         const TDesC8& GetArticleContentL();
00128 
00129         
00133         const TDesC8& GetArticleContentL(const TDesC& aTitle);
00134 
00138         const TDesC8& GetArticleContentL(const TDesC8& aTitle);
00139 
00143         void SetCurrentArticleL( const TDesC& aTitle );
00144 
00148         const TDesC8& GetCurrentArticleContentL();
00149         
00150         TBool DoesNextItemExist();
00151         
00152         TInt CurrentPage() { return iCurPage; };
00153         TInt CurrentItem() { return iCurItem; };        
00154         TInt NumRecords() { return iNumRecords; };
00155         
00156         public: // from CActive
00157         void DoCancel();
00158         void RunL();
00159         
00160         private:
00161         void EnsureArticleFormattedL(const TDesC& aTitle);
00162         void EnsureArticleFormattedL(const TDesC8& aTitle);
00163         void ReplaceChar(const TDesC8& aSource, TDes8& aTarget, const TChar& aToReplace, const TChar& aReplacement);
00164         void RunQueryL();
00165         void RunRecCountQueryL();       
00166         void SetPageAndItemL( const TPageState aPageState );
00167         HBufC* EscapeL( const TDesC& aQuery) const;
00168         HBufC8* EscapeL( const TDesC8& aQuery) const;
00169         void StartRecordCountL();
00170         void TraverseRecCountL();
00171 
00172         protected:
00173         
00174         RSqlDatabase iDatabase;
00175         RSqlStatement iStatement;
00176         RSqlStatement iCountStatement;
00177         RBuf8 iQueryBuf;
00178         RBuf8 iCountBuf;
00179         RBuf8 iUtf8Chars;
00180         RBuf8 iArticleText;
00181         HBufC* iCurArticleTitle;
00182         MWikiCountObserver* iObserver;
00183         
00184         protected:
00185         TRequestCode            iRequestCode;
00186         TRequestStatus*         iRequestStatus;
00187         RBuf8                           iRequestTitle;
00188         TPtrC8*                         iRequestBuffer;
00189         
00190         TInt                            iCurItem;
00191         TInt                            iCurPage;
00192         TBool                           iAtNextItem;
00193         TInt                            iNumRecords;
00194         };
00195         
00196 #endif //__WIKI_DB_H__

Generated by  doxygen 1.6.2