Fixed Nabi Issues: 53721,53372,53761,53768
[apps/osp/Internet.git] / src / IntBookmarkPresentationModel.cpp
index f200f3e..891723c 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
 //
@@ -91,6 +91,7 @@ void BookmarkPresentationModel::DestroyInstance(void)
 {
        if (__pBookmarkPresentationModel)
        {
+               __pBookmarkPresentationModel->UnInitialize();
                delete __pBookmarkPresentationModel;
                __pBookmarkPresentationModel = null;
        }
@@ -127,9 +128,9 @@ BookmarkPresentationModel::SaveBookmark(BookmarkData& bookmark)
        DateTime dt;
        String bookmarkId;
        String bookmarkTitle = bookmark.GetBookmarkTitle();
-       bookmarkTitle.Replace(L"'", L"''");
+       bookmarkTitle.Replace(L"'", L"\'");
        String bookmarkUrl = bookmark.GetUrl();
-       bookmarkUrl.Replace(L"'", L"''");
+       bookmarkUrl.Replace(L"'", L"\'");
 
        AppLog("BookmarkPresentationModel::SaveBookmark");
 
@@ -715,7 +716,7 @@ BookmarkPresentationModel::GetSearchBookmarkCount(int& searchBookmarkCount, Stri
        String bookmarkTable(BOOKMARK_URL_TABLE);
        result r = E_FAILURE;
        bool nextRowPresent = false;
-       text.Replace(L"'", L"''");
+       text.Replace(L"'", L"\'");
 
        query.Append(L"SELECT COUNT(ID) FROM ");
        query.Append(bookmarkTable);
@@ -725,7 +726,8 @@ BookmarkPresentationModel::GetSearchBookmarkCount(int& searchBookmarkCount, Stri
        query.Append(" OR ");
        query.Append(L"ADDRESS LIKE '%");
        query.Append(text);
-       query.Append("%')");
+       query.Append("%'");
+       query.Append(" ESCAPE '/')");
        query.Append(" AND ADDRESS != ''");
 
        r = BookmarkPresentationModel::ExecuteQuery(query, count);
@@ -740,7 +742,10 @@ BookmarkPresentationModel::GetSearchBookmarkCount(int& searchBookmarkCount, Stri
        }
        searchBookmarkCount = intVal;
 
-       CATCH: return r;
+       CATCH:
+//     text.Replace(L"''", L"'");
+       return r;
+
 }
 
 
@@ -754,13 +759,14 @@ BookmarkPresentationModel::GetSearchFolderCount(int& searchFolderCount, String&
        String bookmarkTable(BOOKMARK_URL_TABLE);
        result r = E_FAILURE;
        bool nextRowPresent = false;
-       text.Replace(L"'", L"''");
+       text.Replace(L"'", L"\'");
 
        query.Append(L"SELECT COUNT(ID) FROM ");
        query.Append(bookmarkTable);
        query.Append(L" WHERE TITLE LIKE '%");
        query.Append(text);
        query.Append("%'");
+       query.Append(" ESCAPE '/'");
        query.Append(" AND ADDRESS = ''");
 
        r = BookmarkPresentationModel::ExecuteQuery(query, count);
@@ -775,7 +781,9 @@ BookmarkPresentationModel::GetSearchFolderCount(int& searchFolderCount, String&
        }
        searchFolderCount = intVal;
 
-       CATCH: return r;
+       CATCH:
+//     text.Replace(L"''", L"'");
+       return r;
 }
 
 
@@ -806,17 +814,17 @@ BookmarkPresentationModel::GetSearchBookmark(int startIndex, int limit, ArrayLis
        String bookmarkTable(BOOKMARK_URL_TABLE);
        result r = E_FAILURE;
 
-       text.Replace(L"'", L"''");
+       text.Replace(L"'", L"\'");
        query.Append(L"SELECT * FROM ");
        query.Append(bookmarkTable);
-       query.Append(L" WHERE (TITLE LIKE '%");
+       query.Append(L" WHERE ((TITLE LIKE '%");
        query.Append(text);
-       query.Append("%')");
+       query.Append("%' ESCAPE '/')");
        query.Append(" OR ");
        query.Append(L"(ADDRESS LIKE '%");
        query.Append(text);
-       query.Append("%')");
-       query.Append(" AND ADDRESS != ''");
+       query.Append("%' ESCAPE '/') )");
+       query.Append(" AND (ADDRESS != '')");
        //Append LIMIT
        if (limit > 0)
        {
@@ -830,14 +838,16 @@ BookmarkPresentationModel::GetSearchBookmark(int startIndex, int limit, ArrayLis
                        query.Append(startIndex);
                }
        }
-
+       AppLog("Query is %ls", query.GetPointer());
        r = BookmarkPresentationModel::ExecuteQuery(query, count);
        TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::GetSearchBookmark query failed  %s",GetErrorMessage(r));
 
        r = CreateBookmarkList(count, pBookmarkList);
        TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::CreateBookmarkList failed  %s",GetErrorMessage(r));
 
-       CATCH: return r;
+       CATCH:
+//     text.Replace(L"''", L"'");
+       return r;
 }
 
 result
@@ -847,7 +857,7 @@ BookmarkPresentationModel::GetSearchFolder(int startIndex, int limit, ArrayList&
        String query;
        String bookmarkTable(BOOKMARK_URL_TABLE);
        result r = E_FAILURE;
-       text.Replace(L"'", L"''");
+       text.Replace(L"'", L"\'");
 
        query.Append(L"SELECT * FROM ");
        query.Append(bookmarkTable);
@@ -855,6 +865,7 @@ BookmarkPresentationModel::GetSearchFolder(int startIndex, int limit, ArrayList&
        query.Append(text);
        //query.Append("%')");
        query.Append("%'");
+       query.Append(" ESCAPE '/'");
        query.Append(" AND ADDRESS = ''");
 
        //Append LIMIT
@@ -877,7 +888,9 @@ BookmarkPresentationModel::GetSearchFolder(int startIndex, int limit, ArrayList&
        r = CreateFolderList(count, pFolderList);
        TryCatch( r == E_SUCCESS,,"BookmarkPresentationModel::CreateBookmarkList failed  %s",GetErrorMessage(r));
 
-       CATCH: return r;
+       CATCH:
+//     text.Replace(L"''", L"'");
+       return r;
 }
 
 result
@@ -1245,6 +1258,22 @@ BookmarkPresentationModel::DoesBookmarkExist(const Tizen::Base::String& Url, boo
        query.Append(bookmarkTable);
        query.Append(" WHERE ADDRESS = '");
        query.Append(Url);
+       if(Url.EndsWith(L"/"))
+       {
+               query.Append("' OR ADDRESS = '");
+               String newUrl = L"";
+               Url.SubString(0,Url.GetLength()-1 ,newUrl);
+               query.Append(newUrl);
+       }
+       else
+       {
+               query.Append("' OR ADDRESS = '");
+               String newUrl = Url;
+//             Url.SubString(0,Url.GetLength()-1 ,newUrl);
+               newUrl.Append(L"/");
+               query.Append(newUrl);
+       }
+
        if(checkParentId == true)
        {
                query.Append(L"' AND PARENT = '");
@@ -1289,6 +1318,24 @@ BookmarkPresentationModel::DeleteBookmark(const Tizen::Base::String& url)
        query.Append(bookmarkTable);
        query.Append(" WHERE ADDRESS = '");
        query.Append(url);
+
+       if(url.EndsWith(L"/"))
+       {
+               query.Append("' OR ADDRESS = '");
+               String newUrl = L"";
+               url.SubString(0,url.GetLength()-1 ,newUrl);
+               query.Append(newUrl);
+       }
+       else
+       {
+               query.Append("' OR ADDRESS = '");
+               String newUrl = url;
+//             Url.SubString(0,Url.GetLength()-1 ,newUrl);
+               newUrl.Append(L"/");
+               query.Append(newUrl);
+
+       }
+
        query.Append(L"'");
 
        r = BookmarkPresentationModel::ExecuteQuery(query, resultCount);