--- a/bookmarks/BookmarksManager.cpp Wed Sep 22 15:59:07 2010 -0400
+++ b/bookmarks/BookmarksManager.cpp Thu Sep 23 15:31:07 2010 -0400
@@ -157,25 +157,48 @@
// do some checking on parameters
QString updatedTitle = title;
QString updatedUrl = normalizeUrl(URL);
+ int soIndex = 1;
if (title.isEmpty()) {
updatedTitle = "Untitled";
}
if (m_db.isOpen()) {
QSqlQuery query(m_db);
- query.prepare("INSERT INTO bookmarks (title, url, sortIndex)"
- "select :title, :url, ifnull(max(sortIndex)+1,1) from bookmarks");
+ m_db.transaction();
+ if (!query.exec("SELECT count(*) from bookmarks")) {
+ lastErrMsg(query);
+ m_db.rollback();
+ return DATABASEERROR;
+ }
+ if(query.next()) {
+ query.prepare("UPDATE bookmarks SET sortIndex=sortIndex+1 WHERE sortIndex >= :sIndex");
+ query.bindValue(":sIndex", soIndex);
+ if (!query.exec()) {
+ lastErrMsg(query);
+ m_db.rollback();
+ return DATABASEERROR;
+ }
+ }
+ query.prepare("INSERT INTO bookmarks (title, url, sortIndex) "
+ "VALUES (:title, :url, :sIndex)");
query.bindValue(":title", QVariant(updatedTitle));
query.bindValue(":url", QVariant(updatedUrl));
+ query.bindValue(":sIndex", QVariant(soIndex));
if (!query.exec()) {
lastErrMsg(query);
+ m_db.rollback();
return DATABASEERROR;
}
// Note: lastInsertId() is not thread-safe
bookmarkId = query.lastInsertId().toInt();
+ if (!m_db.commit()) {
+ qDebug() << m_db.lastError().text();
+ m_db.rollback();
+ return DATABASEERROR;
+ }
} else {
bookmarkId = FAILURE;
}
- }
+ }
return bookmarkId;
}
@@ -653,6 +676,31 @@
}
/**==============================================================
+ * Description: Finds a bookmark based on a given bookmarkID.
+ * Returns: A pointer to BookmarkFav object or NULL.
+ ===============================================================*/
+QMap<QString, QString> BookmarksManager::findBookmarks(QString atitle)
+{
+ QMap<QString, QString> map;
+
+ if (m_db.isOpen()) {
+ QSqlQuery query(m_db);
+ QString queryStatement = "SELECT url, title FROM bookmarks WHERE title LIKE '%"+atitle+"%' OR url LIKE '%" + atitle + "%'";
+ query.prepare(queryStatement);
+ if(query.exec()) {
+ while (query.next()){
+ QString bookmarkUrl = query.value(0).toString();
+ QString bookmarkTitle = query.value(1).toString();
+ map.insert( bookmarkUrl, bookmarkTitle );
+ }
+ } else {
+ lastErrMsg(query);
+ }
+ }
+ return map;
+}
+
+/**==============================================================
* Description: Prints a last error message from the query.
* Returns: Nothing.
===============================================================*/
--- a/bookmarks/BookmarksManager.h Wed Sep 22 15:59:07 2010 -0400
+++ b/bookmarks/BookmarksManager.h Thu Sep 23 15:31:07 2010 -0400
@@ -25,6 +25,7 @@
#include <QObject>
#include <QSqlDatabase>
#include <QSqlError>
+#include <QMap>
#include "bookmarksapi.h"
class QWidget;
@@ -65,7 +66,8 @@
BookmarkResults *findUntaggedBookmarks();
int reorderBookmark(int bookmarkID, int newIndex);
TagResults* findTagsByBookmark(int bookmarkID);
-
+ QMap<QString, QString> findBookmarks(QString atitle);
+
private:
bool doQuery(QString query);
void createBookmarksSchema();
--- a/bookmarksengine/browsercontentdll/inc/browsercontentdll.h Wed Sep 22 15:59:07 2010 -0400
+++ b/bookmarksengine/browsercontentdll/inc/browsercontentdll.h Thu Sep 23 15:31:07 2010 -0400
@@ -139,6 +139,7 @@
QString fetchSerializedBookmarks();
void fetchSerializedHistory(QVector<QString> &folderVector,QMap<QString,QString> &mymap);
void fetchAllBookmarkTitles(QVector<QString> &title);
+ QMap<QString, QString> findSimilarHistoryItems(QString atitle);
private:
int createDatabase();
--- a/bookmarksengine/browsercontentdll/src/browsercontentdll.cpp Wed Sep 22 15:59:07 2010 -0400
+++ b/bookmarksengine/browsercontentdll/src/browsercontentdll.cpp Thu Sep 23 15:31:07 2010 -0400
@@ -784,3 +784,28 @@
return false;
}
+
+QMap<QString, QString> BrowserContent::findSimilarHistoryItems(QString atitle)
+{
+ BOOKMARKSCLIENT_PRIVATEPTR(BrowserContent);
+ QSqlDatabase db = QSqlDatabase::database(priv->m_connectionName);
+
+ QMap<QString, QString> map;
+
+ if (db.isOpen()){
+ QSqlQuery query(db);
+
+ QString queryStatement = "SELECT url, pageTitle FROM HistoryTable WHERE pageTitle LIKE '%"+atitle+"%' OR url LIKE '%" + atitle + "%'";
+ query.prepare(queryStatement);
+ if(query.exec()) {
+ while (query.next()){
+ QString HistoryUrl = query.value(0).toString();
+ QString HistoryTitle = query.value(1).toString();
+ map.insert( HistoryUrl, HistoryTitle );
+ }
+ } else {
+ QSqlError error = query.lastError();
+ }
+ }
+ return map;
+}