Skip to content

Commit 474de89

Browse files
committed
Plugins::WebBrowser: modify database
1 parent 30b647b commit 474de89

7 files changed

Lines changed: 24 additions & 21 deletions

File tree

Plugins/WebBrowser/Bookmark/BookmarkDatabase.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515

1616
static Q_LOGGING_CATEGORY(log, "WebBrowser.Bookmark.DB")
1717
static CBookmarkDatabase* g_pDatabase = nullptr;
18-
CBookmarkDatabase* CBookmarkDatabase::Instance(const QSqlDatabase &database)
18+
CBookmarkDatabase* CBookmarkDatabase::Instance(CParameterDatabase *para)
1919
{
2020
if(!g_pDatabase) {
2121
g_pDatabase = new CBookmarkDatabase();
2222
if(g_pDatabase) {
23-
g_pDatabase->SetDatabase(database);
24-
g_pDatabase->OnInitializeDatabase();
23+
bool bRet = g_pDatabase->OpenDatabase(para, "bookmark_connection");
24+
if(!bRet) {
25+
delete g_pDatabase;
26+
g_pDatabase = nullptr;
27+
}
2528
}
2629
}
2730
return g_pDatabase;
@@ -56,9 +59,9 @@ CBookmarkDatabase::~CBookmarkDatabase()
5659

5760
bool CBookmarkDatabase::OnInitializeDatabase()
5861
{
59-
m_UrlDB.SetDatabase(GetDatabase());
62+
m_UrlDB.SetDatabase(GetDatabase(), m_pPara);
6063
m_UrlDB.OnInitializeDatabase();
61-
m_TreeDB.SetDatabase(GetDatabase());
64+
m_TreeDB.SetDatabase(GetDatabase(), m_pPara);
6265
m_TreeDB.OnInitializeDatabase();
6366

6467
if(m_TreeDB.GetNodeCount() == 0) {

Plugins/WebBrowser/Bookmark/BookmarkDatabase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CBookmarkDatabase : public CDatabase
6363
{
6464
Q_OBJECT
6565
public:
66-
static CBookmarkDatabase* Instance(const QSqlDatabase& database);
66+
static CBookmarkDatabase* Instance(CParameterDatabase *para);
6767
static CBookmarkDatabase* Instance();
6868

6969
// 书签操作

Plugins/WebBrowser/DatabaseUrl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ bool CDatabaseUrl::OnInitializeDatabase()
1717
bool success = false;
1818
success = CDatabase::OnInitializeDatabase();
1919
if(!success) return success;
20-
m_iconDB.SetDatabase(GetDatabase());
20+
m_iconDB.SetDatabase(GetDatabase(), m_pPara);
2121
success = m_iconDB.OnInitializeDatabase();
2222
return success;
2323
}
@@ -309,7 +309,7 @@ bool CDatabaseUrl::OnInitializeSqliteDatabase()
309309
// 创建历史记录表
310310
bool success = query.exec(
311311
"CREATE TABLE IF NOT EXISTS url ("
312-
" id INTEGER PRIMARY KEY AUTOINCREMENT,"
312+
" id INTEGER PRIMARY KEY AUTO_INCREMENT,"
313313
" url TEXT UNIQUE NOT NULL,"
314314
" title TEXT,"
315315
" icon INTEGER DEFAULT 0,"
@@ -347,7 +347,7 @@ bool CDatabaseUrl::OnInitializeMySqlDatabase()
347347
" title TEXT,"
348348
" icon INTEGER DEFAULT 0,"
349349
" visit_time DATETIME DEFAULT CURRENT_TIMESTAMP,"
350-
" INDEX idx_url_url (url)"
350+
" UNIQUE KEY idx_url_url (url(255))"
351351
")"
352352
);
353353

Plugins/WebBrowser/FrmWebBrowser.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,6 @@ CFrmWebBrowser::CFrmWebBrowser(CParameterWebBrowser *pPara, bool bMenuBar, QWidg
7979
qDebug(log) << Q_FUNC_INFO;
8080
bool check = false;
8181

82-
m_pHistoryDatabase = CHistoryDatabase::Instance();
83-
84-
QString szDbBookmarks = GetProfile()->persistentStoragePath();
85-
if(!(szDbBookmarks.right(1) == '/' || szDbBookmarks.right(1) == '\\'))
86-
szDbBookmarks += QDir::separator();
87-
szDbBookmarks += "Bookmarks.db";
88-
m_pBookmarkDatabase = CBookmarkDatabase::Instance(m_pHistoryDatabase->GetDatabase());
89-
9082
setWindowIcon(QIcon::fromTheme("web-browser"));
9183

9284
QVBoxLayout* pLayout = new QVBoxLayout(this);
@@ -812,10 +804,15 @@ int CFrmWebBrowser::InitMenu(QMenu *pMenu)
812804
int CFrmWebBrowser::Start()
813805
{
814806
int nRet = 0;
807+
808+
m_pHistoryDatabase = CHistoryDatabase::Instance(&m_pPara->m_Database);
809+
m_pBookmarkDatabase = CBookmarkDatabase::Instance(&m_pPara->m_Database);
810+
815811
if(m_pTab && m_pTab->count() == 0) {
816812
// Add new web view
817813
m_pAddPage->trigger();
818814
}
815+
819816
return nRet;
820817
}
821818

Plugins/WebBrowser/History/HistoryDatabase.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool CHistoryDatabase::OnInitializeDatabase()
7373
bool success = false;
7474
success = CDatabase::OnInitializeDatabase();
7575
if(!success) return false;
76-
m_UrlDB.SetDatabase(GetDatabase());
76+
m_UrlDB.SetDatabase(GetDatabase(), m_pPara);
7777
m_UrlDB.OnInitializeDatabase();
7878
return success;
7979
}
@@ -796,7 +796,9 @@ bool CHistoryDatabase::OnInitializeMySqlDatabase()
796796
);
797797

798798
if (!success) {
799-
qCritical(log) << "Failed to create table:" << query.lastError().text();
799+
qCritical(log) << "Failed to create history table:"
800+
<< query.lastError().text()
801+
<< "Sql:" << query.executedQuery();
800802
return false;
801803
}
802804

Src/Database.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ bool CDatabaseFile::OnInitializeMySqlDatabase()
760760
")";
761761
bool success = query.exec(szSql);
762762
if (!success) {
763-
qCritical(log) << "Failed to create file table:"
763+
qCritical(log) << "Failed to create" << m_szTableName << "table:"
764764
<< m_szTableName << query.lastError().text()
765765
<< "Sql:" << query.executedQuery();
766766
return false;

Src/Database.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
class PLUGIN_EXPORT CDatabase : public QObject
1313
{
1414
Q_OBJECT
15+
1516
public:
1617
explicit CDatabase(QObject *parent = nullptr);
1718
virtual ~CDatabase();
1819

19-
void SetDatabase(QSqlDatabase db, CParameterDatabase* pPara = nullptr);
20+
void SetDatabase(QSqlDatabase db, CParameterDatabase* pPara);
2021
QSqlDatabase GetDatabase() const;
2122

2223
/*!

0 commit comments

Comments
 (0)