Fixed Nabi Issues
[apps/osp/Internet.git] / src / IntHistoryPresentationModel.cpp
index fa15b99..cabc82f 100644 (file)
@@ -2,7 +2,7 @@
 
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
-// Licensed under the Flora License, Version 1.0 (the License);
+// Licensed under the Flora License, Version 1.1 (the License);
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
@@ -70,6 +70,7 @@ void HistoryPresentationModel::DestroyInstance(void)
 {
        if (__pHistoryPresentationModel)
        {
+               __pHistoryPresentationModel->UnInitialize();
                delete __pHistoryPresentationModel;
                __pHistoryPresentationModel = null;
        }
@@ -77,7 +78,7 @@ void HistoryPresentationModel::DestroyInstance(void)
 
 HistoryPresentationModel::HistoryPresentationModel(void)
 {
-
+       __pDataList = null;
 }
 
 HistoryPresentationModel::~HistoryPresentationModel(void)
@@ -99,6 +100,7 @@ result
 HistoryPresentationModel::Construct(void)
 {
        result r = E_SUCCESS;
+       DB_FILE_PATH = L"/opt/usr/dbspace/.browser-history.db";
        r = PresentationModelBase::Initialize();
        TryCatch( !IsFailed(r),,"Failed to initialize HistoryPresentationModel Model %s",GetErrorMessage(r));
 
@@ -123,7 +125,7 @@ HistoryPresentationModel::SaveHistory(History& history)
        ArrayList* pMostVisitedSites = null;
        bool isAlreadyExist = false;
        bool isEligibleForMostVisitedSites = true;
-       int i;
+       int count;
        String thumbnailPath;
        int todaysCount = 0;
        DateTime todayStart;
@@ -141,9 +143,14 @@ HistoryPresentationModel::SaveHistory(History& history)
        for(int count = 0; count < todaysCount; count++)
        {
                History *pHistoryItem  = dynamic_cast<History*>(pTodaysList->GetAt(count));
+               //AppLog("HistoryPresentationModel::saveHistory pHistoryItem id is %ls",pHistoryItem->GetHistoryId().GetPointer());
+               AppLog("SaveHistory pHistoryItem url is %ls",pHistoryItem->GetHistoryUrl().GetPointer());
+               AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
+
                if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
                {
                        history.SetHistoryId(pHistoryItem->GetHistoryId());
+                       AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
                        break;
                }
        }
@@ -159,11 +166,12 @@ HistoryPresentationModel::SaveHistory(History& history)
        PresentationModelBase::GetCurrentDateTime(date);
        GetMostVisitedSites(*pMostVisitedSites);
        GetUrlCount(historyUrl, urlCount);
-       for (i = 0; i < pMostVisitedSites->GetCount(); i++)
+       for (count = 0; count < pMostVisitedSites->GetCount(); count++)
        {
-               History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
+               History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(count));
                if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
                {
+                       AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
                        isAlreadyExist = true;
                        break;
                }
@@ -196,14 +204,34 @@ HistoryPresentationModel::SaveHistory(History& history)
        delete pMostVisitedSites;
        pMostVisitedSites = NULL ;
 
+       String pFavArray;
+       ByteBuffer* pFavBuffer = history.GetFavIconBuffer();
+       if(pFavBuffer != null)
+       {
+               AppLog("Buffer found");
+               pFavBuffer->Flip();
+
+               wchar_t value;
+
+               AppLog("BookmarkPresentationModel::SaveBookmark 0 ");
+
+               while(pFavBuffer->HasRemaining())
+               {
+                       pFavBuffer->GetWchar(value);
+                       pFavArray.Append(value);
+               }
+       }
+
        if (history.GetHistoryId() == "")
        {
+               AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
+
+               columnNames.Append(L"ADDRESS, ");
                columnNames.Append(L"TITLE, ");
-               columnNames.Append(L"URL, ");
-               columnNames.Append(L"VISITED_TIME, ");
-               columnNames.Append(L"ICON_PATH, ");
-               columnNames.Append(L"FAVICON_ID, ");
-               columnNames.Append(L"THUMBNAIL_PATH");
+               columnNames.Append(L"VISITDATE, ");
+               columnNames.Append(L"FAVICON, ");
+               columnNames.Append(L"FAVICON_W, ");
+               columnNames.Append(L"FAVICON_H");
 
                query.Append(L"INSERT INTO ");
                query.Append(historyTable);
@@ -212,63 +240,287 @@ HistoryPresentationModel::SaveHistory(History& history)
                query.Append(") ");
                query.Append("VALUES(");
                query.Append("'");
-               query.Append(historyTitle);
+               query.Append(historyUrl);
                query.Append("'");
                query.Append(", ");
                query.Append("'");
-               query.Append(historyUrl);
+               query.Append(historyTitle);
                query.Append("', ");
                query.Append("DateTime(");
                query.Append("'");
                query.Append(GetStringFromDate(date));
-               query.Append("'), ");
-               query.Append("'");
-               query.Append(history.GetHistoryIconPath());
-               query.Append("'");
-               query.Append(", ");
-               query.Append("'");
-               query.Append(history.GetFaviconId());
+               query.Append(")', ");
                query.Append("'");
+               query.Append(pFavArray);
+               query.Append("', ");
+               query.Append(history.GetFavIconWidth());
                query.Append(", ");
-               query.Append("'");
-               query.Append(thumbnailPath);
-               query.Append("'");
+               query.Append(history.GetFavIconHeight());
                query.Append(")");
        }
        else
        {
                query.Append(L"UPDATE ");
                query.Append(historyTable);
-               query.Append(" SET TITLE = ");
+               query.Append(" SET ADDRESS = ");
                query.Append("'");
-               query.Append(historyTitle);
+               query.Append(historyUrl);
                query.Append("'");
-               query.Append(", URL = ");
+               query.Append(", TITLE = ");
                query.Append("'");
-               query.Append(historyUrl);
+               query.Append(historyTitle);
                query.Append("'");
                query.Append(", VISITED_TIME = ");
                query.Append("DateTime(");
                query.Append("'");
                query.Append(GetStringFromDate(date));
                query.Append("')");
-               query.Append(", ICON_PATH = ");
-               query.Append("'");
-               query.Append(history.GetHistoryIconPath());
+               query.Append("', ");
                query.Append("'");
+               query.Append(pFavArray);
+               query.Append("', ");
+               query.Append(history.GetFavIconWidth());
                query.Append(", ");
+               query.Append(history.GetFavIconHeight());
+               query.Append(" WHERE ID = ");
+               query.Append(history.GetHistoryId());
+
+       }
+
+       AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
+
+       r = PresentationModelBase::ExecuteQuery(query, resultCount);
+       if (r == E_SUCCESS)
+       {
+               AppLog("HistoryPresentationModel::SaveHistory result is success");
+       }
+       else
+       {
+               AppLog("HistoryPresentationModel::SaveHistory result is failure");
+       }
+       TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed  %s",GetErrorMessage(r));
+
+       r = PresentationModelBase::CommitDb();
+
+       r = GetLastInsertedId(historyTable, rowId);
+       if (IsFailed(r))
+       {
+               AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
+               return r;
+       }
+       if (rowId < 0)
+               return E_FAILURE;
+
+       historyId.Append(rowId);
+       if (historyId.GetLength() < 0)
+       {
+               return E_FAILURE;
+       }
+       //Set the generated ID to History
+       history.SetHistoryId(historyId);
+
+       CATCH: return r;
+}
+
+void HistoryPresentationModel::UpdateHistoryFavIcon(History& history, Tizen::Graphics::Bitmap& favIconImage)
+{
+       result r = E_FAILURE;
+       String historyTable(HISTORY_DATA_TABLE);
+       String query;
+       String columnNames;
+       int resultCount = -1;
+
+       Image* pImage = null;
+       pImage = new Image();
+       pImage->Construct();
+
+       Tizen::Base::ByteBuffer* pFavBuffer = pImage->EncodeToBufferN(favIconImage, IMG_FORMAT_PNG);
+       // added because conversion may fail
+       if(GetLastResult() != E_SUCCESS)
+               return;
+       delete pFavBuffer;
+       history.SetFavIconBitmap(favIconImage);
+
+       delete pImage;
+
+       query.Append(L"UPDATE ");
+       query.Append(historyTable);
+       query.Append(" SET FAVICON = ");
+       query.Append("?");
+       query.Append(", FAVICON_W = ");
+       query.Append("?");
+       query.Append(", FAVICON_H = ");
+       query.Append("?");
+       query.Append(" WHERE ID = ");
+       query.Append("?");
+
+       AppLog("query is %ls", query.GetPointer());
+
+       r = PresentationModelBase::ExecuteUpdateHistoryFavIconQuery(query, resultCount, history);
+       if (r == E_SUCCESS)
+       {
+               AppLog("HistoryPresentationModel::SaveHistory result is success");
+       }
+       else
+       {
+               AppLog("HistoryPresentationModel::SaveHistory result is failure");
+       }
+       r = PresentationModelBase::CommitDb();
+
+}
+
+result
+HistoryPresentationModel::SaveTempHistory(History& history)
+{
+       AppLog("HistoryPresentationModel::saveHistory");
+       result r = E_FAILURE;
+       String historyTable(HISTORY_DATA_TABLE);
+       String query;
+       String columnNames;
+       String attachment;
+       int resultCount = -1;
+       int rowId = -1;
+       DateTime date;
+       String historyId;
+       int urlCount = 0;
+       ArrayList* pMostVisitedSites = null;
+       bool isAlreadyExist = false;
+       bool isEligibleForMostVisitedSites = true;
+       int i;
+       String thumbnailPath;
+       int todaysCount = 0;
+       DateTime todayStart;
+       DateTime todayEnd;
+       SystemTime::GetCurrentTime(todayStart);
+       SystemTime::GetCurrentTime(todayEnd);
+       todayStart.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 0,0,0);
+       todayEnd.SetValue(todayStart.GetYear(), todayStart.GetMonth(), todayStart.GetDay(), 23,59,59);
+
+       ArrayList* pTodaysList = new(std::nothrow) ArrayList();
+       pTodaysList->Construct();
+       GetHistoryCountWithTimeRange(todayStart, todayEnd, todaysCount);
+       GetHistoryWithTimeRange(todayStart, todayEnd, 0, todaysCount, *pTodaysList);
+
+       for(int count = 0; count < todaysCount; count++)
+       {
+               History *pHistoryItem  = dynamic_cast<History*>(pTodaysList->GetAt(count));
+               AppLog("SaveHistory history url is %ls",history.GetHistoryUrl().GetPointer());
+
+               if(pHistoryItem != null && pHistoryItem->GetHistoryUrl().CompareTo(history.GetHistoryUrl()) == 0)
+               {
+                       history.SetHistoryId(pHistoryItem->GetHistoryId());
+                       AppLog("HistoryPresentationModel::saveHistory pHistoryItem history is %ls",pHistoryItem->GetHistoryId().GetPointer());
+                       break;
+               }
+       }
+
+       if (pTodaysList)
+       {
+               pTodaysList->RemoveAll();
+               delete pTodaysList;
+       }
+
+       pMostVisitedSites = new(std::nothrow) ArrayList();
+       pMostVisitedSites->Construct();
+       String historyTitle = history.GetHistoryTitle();
+       historyTitle.Replace(L"'", L"''");
+
+       String historyUrl = history.GetHistoryUrl();
+       historyUrl.Replace(L"'", L"''");
+
+       PresentationModelBase::GetCurrentDateTime(date);
+       GetMostVisitedSites(*pMostVisitedSites);
+       GetUrlCount(historyUrl, urlCount);
+       for (i = 0; i < pMostVisitedSites->GetCount(); i++)
+       {
+               History* pHistory = static_cast< History* >(pMostVisitedSites->GetAt(i));
+               if (pHistory != null && pHistory->GetHistoryUrl().CompareTo(historyUrl) == 0)
+               {
+                       AppLog("HistoryPresentationModel::saveHistory isalreadyexist true");
+                       isAlreadyExist = true;
+                       break;
+               }
+               if ( pHistory != null &&  urlCount >= pHistory->GetVisitedCount())
+               {
+                       isEligibleForMostVisitedSites = true;
+               }
+               else
+               {
+                       isEligibleForMostVisitedSites = false;
+               }
+       }
+
+       if (pMostVisitedSites->GetCount() < 9 || (isAlreadyExist == false && isEligibleForMostVisitedSites == true && history.GetThumbnail() != null))
+       {
+               AppLog("HistoryPresentationModel::SaveHistory coming here");
+
+               thumbnailPath = GenerateFileName();
+               AppLog("generating file path and url %ls, %ls",thumbnailPath.GetPointer(),historyUrl.GetPointer());
+               Image* pImage = new(std::nothrow) Image();
+               pImage->Construct();
+               result r = pImage->EncodeToFile(*history.GetThumbnail(), IMG_FORMAT_JPG, thumbnailPath, true);
+               delete pImage;
+               if(IsFailed(r))
+               {
+                       AppLogDebug("PresentationModelBase::saveHistory -(%s)\n", GetErrorMessage(r));
+                       return r;
+               }
+       }
+       delete pMostVisitedSites;
+       pMostVisitedSites = NULL ;
+
+       if (history.GetHistoryId() == "")
+       {
+               AppLog("HistoryPresentationModel::saveHistory GetHistoryId is blank");
+
+               columnNames.Append(L"ADDRESS, ");
+               columnNames.Append(L"TITLE, ");
+               columnNames.Append(L"VISITDATE, ");
+               columnNames.Append(L"FAVICON, ");
+               columnNames.Append(L"FAVICON_W, ");
+               columnNames.Append(L"FAVICON_H");
+
+               query.Append(L"INSERT INTO ");
+               query.Append(historyTable);
+               query.Append("(");
+               query.Append(columnNames);
+               query.Append(") ");
+               query.Append("VALUES");
+               query.Append(" (?,?,?,?,?,?)");
+       }
+       else
+       {
+               query.Append(L"UPDATE ");
+               query.Append(historyTable);
+               query.Append(" SET ADDRESS = ");
                query.Append("'");
-               query.Append(history.GetFaviconId());
+               query.Append(historyUrl);
                query.Append("'");
-               query.Append(", ");
+               query.Append(", TITLE = ");
                query.Append("'");
-               query.Append(thumbnailPath);
+               query.Append(historyTitle);
+               query.Append("'");
+               query.Append(", VISITED_TIME = ");
+               query.Append("DateTime(");
+               query.Append("'");
+               query.Append(GetStringFromDate(date));
+               query.Append("')");
                query.Append("'");
                query.Append(" WHERE ID = ");
                query.Append(history.GetHistoryId());
        }
 
-       r = PresentationModelBase::ExecuteQuery(query, resultCount);
+       AppLog("HistoryPresentationModel::SaveHistory query is %S",query.GetPointer());
+
+       r = PresentationModelBase::ExecuteHistoryQuery(query, resultCount, history);
+       if (r == E_SUCCESS)
+       {
+               AppLog("HistoryPresentationModel::SaveHistory result is success");
+       }
+       else
+       {
+               AppLog("HistoryPresentationModel::SaveHistory result is failure");
+       }
        TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::SaveHistory query failed  %s",GetErrorMessage(r));
 
        r = PresentationModelBase::CommitDb();
@@ -290,8 +542,16 @@ HistoryPresentationModel::SaveHistory(History& history)
        //Set the generated ID to History
        history.SetHistoryId(historyId);
 
+       if(__pDataList)
+       {
+               delete __pDataList;
+               __pDataList = null;
+       }
+
        CATCH: return r;
+
 }
+
 result
 HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
 {
@@ -328,6 +588,12 @@ HistoryPresentationModel::DeleteMultipleHistory(ArrayList* pHistoryIdList)
 
        r = PresentationModelBase::CommitDb();
 
+       if(__pDataList)
+       {
+               delete __pDataList;
+               __pDataList = null;
+       }
+
        CATCH: return r;
 }
 
@@ -354,6 +620,12 @@ HistoryPresentationModel::DeleteHistory(const int historyId)
 
        r = PresentationModelBase::CommitDb();
 
+       if(__pDataList)
+       {
+               delete __pDataList;
+               __pDataList = null;
+       }
+
        CATCH: return r;
 }
 
@@ -367,7 +639,7 @@ HistoryPresentationModel::DeleteHistory(String& historyUrl)
 
        query.Append(L"DELETE FROM ");
        query.Append(historyTable);
-       query.Append(" WHERE URL = '");
+       query.Append(" WHERE ADDRESS = '");
        query.Append(historyUrl);
        query.Append("'");
 
@@ -376,6 +648,12 @@ HistoryPresentationModel::DeleteHistory(String& historyUrl)
 
        r = PresentationModelBase::CommitDb();
 
+       if(__pDataList)
+       {
+               delete __pDataList;
+               __pDataList = null;
+       }
+
        CATCH: return r;
 }
 
@@ -435,45 +713,51 @@ HistoryPresentationModel::GetHistoryCount(int& historyCount)
 result
 HistoryPresentationModel::GetHistoryCountWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime, int& historyCount)
 {
+       int count = 0;
+       result r = E_SUCCESS;
 
-       int count = -1;
-       int intVal = -1;
-       String query;
-       String historyTable(HISTORY_DATA_TABLE);
-       result r = E_FAILURE;
-       bool nextRowPresent = false;
+       if(__pDataList != null)
+       {
+               delete __pDataList;
+               __pDataList = null;
+       }
 
-       query.Append(L"SELECT COUNT(ID) FROM ");
-       query.Append(historyTable);
-       query.Append(" WHERE VISITED_TIME >= ");
-       query.Append("DateTime(");
-       query.Append("'");
-       query.Append(GetStringFromDate(startTime));
-       query.Append("')");
-       query.Append(" AND VISITED_TIME <= ");
-       query.Append("DateTime(");
-       query.Append("'");
-       query.Append(GetStringFromDate(endTime));
-       query.Append("')");
+       //if(__pDataList == null)
+       //{
+               __pDataList = new(std::nothrow) ArrayList();
+               __pDataList->Construct();
 
-       r = PresentationModelBase::ExecuteQuery(query, count);
-       TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryCountWithTimeRange query failed %s",GetErrorMessage(r));
+               r = GetHistoryCount(count);
+               if(IsFailed(r))
+               {
+                       return r;
+               }
+               if(count > 0)
+               {
+                       r = GetHistory(0, count, *__pDataList);
+                       if (IsFailed(r))
+                       {
+                               delete __pDataList;
+                               __pDataList = null;
+                               return r;
+                       }
+               }
+       //}
+       //else
+       //{
+               count = __pDataList->GetCount();
+       //}
 
-       r = PresentationModelBase::DbIsNextRowPresent(nextRowPresent);
-       if (IsFailed(r))
-               return r;
-       if (nextRowPresent == true)
+       for (int counter = 0 ; counter < count; counter++)
        {
-               r = PresentationModelBase::GetColumn(0, intVal);
-               if (IsFailed(r))
+               History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
+               AppLog("vinayhistorytimecomparison %d, %d",pHistory->GetVisitedTime().CompareTo(startTime),pHistory->GetVisitedTime().CompareTo(endTime));
+               if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
                {
-                       AppLogDebug("Error:PresentationModelBase::DbGetColumn:%s", GetErrorMessage(r));
-                       return r;
+                       historyCount++;
                }
        }
-       historyCount = intVal;
-
-       CATCH: return r;
+       return r;
 }
 
 result
@@ -485,43 +769,9 @@ HistoryPresentationModel::GetHistory(const int startIndex,const int limit, Array
        String historyTable(HISTORY_DATA_TABLE);
        result r = E_FAILURE;
 
-       query.Append(L"SELECT");
-       query.Append(historyTable);
-       query.Append(L".*, ");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L".ID ");
-       query.Append(L"FROM ");
-       query.Append(historyTable);
-       query.Append(L", ");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L" WHERE ");
+       query.Append(L"SELECT * from ");
        query.Append(historyTable);
-       query.Append(L".URL ");
-       query.Append(L"IN");
-       query.Append(L"(");
-       query.Append(L"SELECT");
-       query.Append(historyTable);
-       query.Append(L".URL ");
-       query.Append(L"FROM ");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L" LEFT JOIN ");
-       query.Append(historyTable);
-       query.Append(L"ON");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L".URL = ");
-       query.Append(historyTable);
-       query.Append(L".URL ");
-       query.Append(" ORDER BY");
-       query.Append(historyTable);
-       query.Append(L".VISITED_TIME DESC");
-       query.Append(")");
-       query.Append(" GROUP BY ");
-       query.Append(historyTable);
-       query.Append(L".URL ");
-       query.Append(" ORDER BY");
-       query.Append(L"COUNT(");
-       query.Append(historyTable);
-       query.Append(L".URL) DESC ");
+       query.Append(" ORDER BY VISITDATE DESC");
 
 
        //Append LIMIT
@@ -568,6 +818,7 @@ HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& history
        bool nextRowPresent = false;
        Image image;
        Bitmap* pThumnailBitmap = null;
+       ByteBuffer *pFavIconBuffer;
 
        image.Construct();
        if (historyCount < 1)
@@ -592,118 +843,100 @@ HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& history
 
                                        switch (columnCount)
                                        {
-                                               case HISTORY_ID:
-                                                       r = PresentationModelBase::GetColumn(columnCount, intVal);
-                                                       if (!IsFailed(r))
+                                       case HISTORY_ID:
+                                               r = PresentationModelBase::GetColumn(columnCount, intVal);
+                                               if (!IsFailed(r))
+                                               {
+                                                       if (intVal > 0)
                                                        {
-                                                               if (intVal > 0)
+                                                               historyId.Clear();
+                                                               historyId.Append(intVal);
+                                                               if (historyId.GetLength() > 0)
                                                                {
-                                                                       historyId.Clear();
-                                                                       historyId.Append(intVal);
-                                                                       if (historyId.GetLength() > 0)
-                                                                       {
-                                                                               pHistory->SetHistoryId(historyId);
-                                                                       }
+                                                                       pHistory->SetHistoryId(historyId);
                                                                }
-
-                                                       }
-                                                       break;
-
-                                               case HISTORY_TITLE:
-                                                       r = PresentationModelBase::GetColumn(columnCount, stringVal);
-                                                       if (!IsFailed(r))
-                                                       {
-                                                               pHistory->SetHistoryTitle(stringVal);
-                                                       }
-                                                       break;
-
-                                               case HISTORY_URL:
-                                                       r = PresentationModelBase::GetColumn(columnCount, stringVal);
-                                                       if (!IsFailed(r))
-                                                       {
-                                                               pHistory->SetHistoryUrl(stringVal);
                                                        }
-                                                       break;
 
-                                               case HISTORY_VISITED_TIME:
-                                                       r = PresentationModelBase::GetColumn(columnCount, dateVal);
-                                                       if (!IsFailed(r))
-                                                       {
-                                                               visitedTime = dateVal;
-                                                               pHistory->SetVisitedTime(visitedTime);
-                                                       }
-                                                       break;
+                                               }
+                                               break;
+                                       case HISTORY_URL:
+                                               r = PresentationModelBase::GetColumn(columnCount, stringVal);
+                                               if (!IsFailed(r))
+                                               {
+                                                       pHistory->SetHistoryUrl(stringVal);
+                                               }
+                                               break;
+                                       case HISTORY_TITLE:
+                                               r = PresentationModelBase::GetColumn(columnCount, stringVal);
+                                               if (!IsFailed(r))
+                                               {
+                                                       pHistory->SetHistoryTitle(stringVal);
+                                               }
+                                               break;
+
+                                       case HISTORY_VISITED_TIME:
+                                               r = PresentationModelBase::GetColumn(columnCount, dateVal);
+                                               if (!IsFailed(r))
+                                               {
+                                                       visitedTime = dateVal;
+                                                       pHistory->SetVisitedTime(visitedTime);
+                                               }
+                                               break;
+
+                                       case HISTORY_FAVICON:
+                                       {
+                                               pFavIconBuffer = new ByteBuffer();
+                                               r = PresentationModelBase::GetColumn(columnCount, *pFavIconBuffer);
+                                               if (!IsFailed(r) && pFavIconBuffer->GetCapacity() > 0)
+                                               {
+                                                       pHistory->SetFavIconBuffer(*pFavIconBuffer);
+                                               }
+                                       }
+                                       break;
+                                       case HISTORY_FAVICON_LENGTH:
+                                       {
 
-                                               case HISTORY_ICON_PATH:
-                                                       r = PresentationModelBase::GetColumn(columnCount, stringVal);
-                                                       if (!IsFailed(r))
+                                       }
+                                       break;
+                                       case HISTORY_FAVICON_W:
+                                       {
+                                               r = PresentationModelBase::GetColumn(columnCount, intVal);
+                                               if (!IsFailed(r))
+                                               {
+                                                       if (intVal > 0)
                                                        {
-                                                               iconPath = stringVal;
-                                                               pHistory->SetIconPath(iconPath);
+                                                               pHistory->SetFavIconWidth(intVal);
                                                        }
-                                                       break;
-
-                                               case HISTORY_FAVICONID:
-
-                                                       r = PresentationModelBase::GetColumn(columnCount, intVal);
-                                                       if (!IsFailed(r))
-                                                       {
-                                                               if (intVal >= 0)
-                                                               {
-                                                                       faviconId.Clear();
-                                                                       faviconId.Append(intVal);
-                                                                       if (faviconId.GetLength() > 0)
-                                                                       {
-                                                                               pHistory->SetFaviconId(faviconId);
-                                                                       }
-                                                               }
-                                                       }
-                                                       break;
-                                               case HISTORY_THUMBNAIL:
-                                                       r = PresentationModelBase::GetColumn(columnCount, stringVal);
-                                                       if (!IsFailed(r))
+                                               }
+                                       }
+                                       break;
+                                       case HISTORY_FAVICON_H:
+                                       {
+                                               r = PresentationModelBase::GetColumn(columnCount, intVal);
+                                               if (!IsFailed(r))
+                                               {
+                                                       if (intVal > 0)
                                                        {
-
-                                                               thumbnailPath = stringVal;
-                                                               pThumnailBitmap = image.DecodeN(thumbnailPath, BITMAP_PIXEL_FORMAT_RGB565);
-                                                               if (pThumnailBitmap != null)
-                                                               {
-                                                                       pHistory->SetThumbnail(pThumnailBitmap);
-                                                                       pHistory->SetThumbnailPath(thumbnailPath);
-                                                               }
+                                                               pHistory->SetFavIconHeight(intVal);
                                                        }
-                                                       break;
-                                               case HISTORY_BOOKMARK_ID:
-                                                       r = PresentationModelBase::GetColumn(columnCount, intVal);
-                                                       if (!IsFailed(r))
-                                                       {
-                                                               if (intVal > 0)
-                                                               {
-                                                                       bookmarkId.Clear();
-                                                                       bookmarkId.Append(intVal);
-                                                                       if (bookmarkId.GetLength() > 0)
-                                                                       {
-                                                                               pHistory->SetBookmarkId(bookmarkId);
-                                                                       }
-                                                               }
+                                               }
+                                       }
+                                       break;
 
-                                                       }
-                                                       break;
-                                               case HISTORY_VISITED_COUNT:
-                                                       r = PresentationModelBase::GetColumn(columnCount, intVal);
-                                                       if (!IsFailed(r))
+                                       case HISTORY_VISITED_COUNT:
+                                               r = PresentationModelBase::GetColumn(columnCount, intVal);
+                                               if (!IsFailed(r))
+                                               {
+                                                       if (intVal > 0)
                                                        {
-                                                               if (intVal > 0)
-                                                               {
-                                                                       pHistory->SetVisitedCount(intVal);
-
-                                                               }
+                                                               pHistory->SetVisitedCount(intVal);
 
                                                        }
-                                                       break;
+                                               }
+                                               break;
 
-                                               default:
-                                                       break;
+                                       default:
+                                               break;
                                        }
 
                                }
@@ -723,6 +956,9 @@ HistoryPresentationModel::CreateHistoryList(int historyCount, ArrayList& history
 result
 HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit, ArrayList& pHistoryList, String& text)
 {
+       DateTime endTime;
+       SystemTime::GetCurrentTime(endTime);
+
        text.Replace(L"'", L"''");
 
        int count = -1;
@@ -732,49 +968,49 @@ HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit,
 
        query.Append(L"SELECT ");
        query.Append(historyTable);
-       query.Append(L".*, ");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L".ID ");
+       query.Append(L".* ");
        query.Append(L"FROM ");
        query.Append(historyTable);
-       query.Append(L" LEFT JOIN ");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L" ON ");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L".URL = ");
-       query.Append(historyTable);
-       query.Append(L".URL ");
        query.Append(L" WHERE (");
        query.Append(historyTable);
        query.Append(L".TITLE LIKE '%");
        query.Append(text);
-       query.Append("%')");
+       query.Append("%' ESCAPE '/')");
        query.Append(" OR ");
        query.Append(L"(");
        query.Append(historyTable);
-       query.Append(L".URL LIKE '%");
+       query.Append(L".ADDRESS LIKE '%");
        query.Append(text);
-       query.Append("%')");
-       query.Append(" ORDER BY VISITED_TIME DESC");
+       query.Append("%' ESCAPE '/')");
+       query.Append(" ORDER BY VISITDATE DESC");
 
-       //Append LIMIT
-       if (limit > 0)
-       {
-               query.Append(" LIMIT ");
-               query.Append(limit);
 
-               //Append OFFESET
-               if (startIndex >= 0)
+       r = HistoryPresentationModel::ExecuteQuery(query, count);
+//     TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
+
+       ArrayList pAllSearchList;
+
+       r = CreateHistoryList(count, pAllSearchList);
+
+       int itemsFoundIndex = -1;
+       for (int counter = 0 ; counter < count; counter++)
+       {
+               History *pHistory = dynamic_cast<History*>(pAllSearchList.GetAt(counter));
+               if(pHistory != null && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
                {
-                       query.Append(" OFFSET ");
-                       query.Append(startIndex);
+                       itemsFoundIndex++;
+                       if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
+                       {
+                               pHistoryList.Add(*pHistory);
+                       }
+                       else if(itemsFoundIndex > (limit + startIndex))
+                       {
+                               break;
+                       }
                }
        }
 
-       r = HistoryPresentationModel::ExecuteQuery(query, count);
-       TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
 
-       r = CreateHistoryList(count, pHistoryList);
        if (IsFailed(r))
        {
                AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
@@ -785,107 +1021,106 @@ HistoryPresentationModel::GetSearchHistory(const int startIndex,const int limit,
 result
 HistoryPresentationModel::GetSearchHistoryCount(int& historyCount, String& text)
 {
+       DateTime endTime;
+       SystemTime::GetCurrentTime(endTime);
+       text.Replace(L"'", L"''");
+
        int count = -1;
-       int intVal = -1;
        String query;
        String historyTable(HISTORY_DATA_TABLE);
        result r = E_FAILURE;
-       bool nextRowPresent = false;
 
-       text.Replace(L"'", L"''");
-       query.Append(L"SELECT COUNT(ID) FROM ");
+       query.Append(L"SELECT ");
        query.Append(historyTable);
-       query.Append(L" WHERE (TITLE LIKE '%");
+       query.Append(L".* ");
+       query.Append(L"FROM ");
+       query.Append(historyTable);
+       query.Append(L" WHERE (");
+       query.Append(historyTable);
+       query.Append(L".TITLE LIKE '%");
        query.Append(text);
-       query.Append("%')");
+       query.Append("%'ESCAPE '/')");
        query.Append(" OR ");
-       query.Append(L"(URL LIKE '%");
+       query.Append(L"(");
+       query.Append(historyTable);
+       query.Append(L".ADDRESS LIKE '%");
        query.Append(text);
-       query.Append("%')");
+       query.Append("%' ESCAPE '/')");
+       query.Append(" ORDER BY VISITDATE DESC");
 
        r = HistoryPresentationModel::ExecuteQuery(query, count);
-       TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistoryCount query failed %s",GetErrorMessage(r));
+//     TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchHistory query failed %s",GetErrorMessage(r));
 
-       r = HistoryPresentationModel::DbIsNextRowPresent(nextRowPresent);
-       if (IsFailed(r) != null)
-               return r;
-       if (nextRowPresent == true)
+       ArrayList pAllSearchList;
+
+       r = CreateHistoryList(count, pAllSearchList);
+
+       historyCount = 0;
+       for (int counter = 0 ; counter < count; counter++)
        {
-               r = HistoryPresentationModel::GetColumn(0, intVal);
-               if (IsFailed(r) != null)
+               History *pHistory = dynamic_cast<History*>(pAllSearchList.GetAt(counter));
+               if(pHistory != null && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
                {
-                       AppLogDebug("Error:HistoryPresentationModel::DbGetColumn:%s", GetErrorMessage(r));
-                       return r;
+                       historyCount++;
                }
        }
-       historyCount = intVal;
 
+
+       if (IsFailed(r))
+       {
+               AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
+       }
        CATCH: return r;
 }
 
 result
 HistoryPresentationModel::GetHistoryWithTimeRange(Tizen::Base::DateTime& startTime, Tizen::Base::DateTime& endTime,const int startIndex,const int limit, ArrayList& pHistoryList)
 {
-       int count = -1;
-       String query;
-       String historyTable(HISTORY_DATA_TABLE);
-       result r = E_FAILURE;
-
-       query.Append(L"SELECT ");
-       query.Append(historyTable);
-       query.Append(L".*, ");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L".ID ");
-       query.Append(L"FROM ");
-       query.Append(historyTable);
-       query.Append(L" LEFT JOIN ");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L" ON ");
-       query.Append(BOOKMARK_URL_TABLE);
-       query.Append(L".URL = ");
-       query.Append(historyTable);
-       query.Append(L".URL ");
-       query.Append(" WHERE ");
-       query.Append(historyTable);
-       query.Append(L".VISITED_TIME >= ");
-       query.Append("DateTime(");
-       query.Append("'");
-       query.Append(GetStringFromDate(startTime));
-       query.Append("')");
-       query.Append(" AND ");
-       query.Append(historyTable);
-       query.Append(L".VISITED_TIME <= ");
-       query.Append("DateTime(");
-       query.Append("'");
-       query.Append(GetStringFromDate(endTime));
-       query.Append("')");
-       query.Append(" ORDER BY VISITED_TIME DESC");
-
-       //Append LIMIT
-       if (limit > 0)
+       int count = 0;
+       result r = E_SUCCESS;
+       if(__pDataList == null)
        {
-               query.Append(" LIMIT ");
-               query.Append(limit);
+               __pDataList = new(std::nothrow) ArrayList();
+               __pDataList->Construct();
 
-               //Append OFFESET
-               if (startIndex >= 0)
+               r = GetHistoryCount(count);
+               if(IsFailed(r))
                {
-                       query.Append(" OFFSET ");
-                       query.Append(startIndex);
+                       return r;
+               }
+               if(count > 0)
+               {
+                       r = GetHistory(0, count, *__pDataList);
+                       if(IsFailed(r))
+                       {
+                               delete __pDataList;
+                               __pDataList = null;
+                               return r;
+                       }
                }
        }
-
-       r = HistoryPresentationModel::ExecuteQuery(query, count);
-       AppLog("the count is %d",count);
-       TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetHistoryWithTimeRange query failed %s",GetErrorMessage(r));
-
-       r = CreateHistoryList(count, pHistoryList);
-       if (IsFailed(r))
+       else
        {
-               AppLogDebug("Error:CreateNoteList:failed:%s", GetErrorMessage(r));
+               count = __pDataList->GetCount();
        }
-
-       CATCH: return r;
+       int itemsFoundIndex = -1;
+       for (int counter = 0 ; counter < count; counter++)
+       {
+               History *pHistory = dynamic_cast<History*>(__pDataList->GetAt(counter));
+               if(pHistory != null && pHistory->GetVisitedTime().CompareTo(startTime) > 0 && pHistory->GetVisitedTime().CompareTo(endTime) < 0)
+               {
+                       itemsFoundIndex++;
+                       if(itemsFoundIndex >= startIndex && itemsFoundIndex < (limit + startIndex))
+                       {
+                               pHistoryList.Add(*pHistory);
+                       }
+                       else if(itemsFoundIndex > (limit + startIndex))
+                       {
+                               break;
+                       }
+               }
+       }
+       return r;
 }
 
 result
@@ -899,7 +1134,7 @@ HistoryPresentationModel::GetMostVisitedSites(ArrayList& pHistoryList)
 
 
        //query = L"SELECT *, COUNT(URL) AS NOS FROM HistoryData GROUP BY URL ORDER BY NOS DESC";
-       query = L"SELECT HistoryData.*, Bookmark.ID, COUNT(HistoryData.URL) AS NOS FROM HistoryData LEFT JOIN Bookmark ON Bookmark.URL = HistoryData.URL WHERE HistoryData.URL != '' GROUP BY HistoryData.URL ORDER BY NOS DESC";
+       query = L"SELECT History.*, COUNT(History.ADDRESS) AS NOS FROM History WHERE History.ADDRESS != '' GROUP BY History.ADDRESS ORDER BY NOS DESC";
 
        r = HistoryPresentationModel::ExecuteQuery(query, count);
        AppLog("the count is %d",count);
@@ -924,9 +1159,9 @@ HistoryPresentationModel::GetUrlCount(const String& Url, int& historyCount)
        result r = E_FAILURE;
        bool nextRowPresent = false;
 
-       query.Append(L"SELECT COUNT(URL) FROM ");
+       query.Append(L"SELECT COUNT(ADDRESS) FROM ");
        query.Append(historyTable);
-       query.Append(L" WHERE URL = ");
+       query.Append(L" WHERE ADDRESS = ");
        query.Append("'");
        query.Append(Url);
        query.Append("'");