| 62 | } |
| 63 | |
| 64 | bool CHistoryDatabase::addHistoryEntry(const QString &url) |
| 65 | { |
| 66 | if (url.isEmpty()) return false; |
| 67 | |
| 68 | int nUrlId = 0; |
| 69 | // 检查 URL 是否已存在。如果不存在,则增加 |
| 70 | nUrlId = m_UrlDB.GetId(url); |
| 71 | if(0 == nUrlId) { |
| 72 | nUrlId = m_UrlDB.AddUrl(url); |
| 73 | if(0 == nUrlId) |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | // 插入新记录 |
| 78 | QSqlQuery query(GetDatabase()); |
| 79 | query.prepare( |
| 80 | "INSERT INTO history (url, visit_time) " |
| 81 | "VALUES (:url, :visit_time) " |
| 82 | ); |
| 83 | query.bindValue(":url", nUrlId); |
| 84 | QDateTime tm = QDateTime::currentDateTime(); |
| 85 | query.bindValue(":visit_time", tm); |
| 86 | |
| 87 | bool success = query.exec(); |
| 88 | if (!success) { |
| 89 | QString szErr = "Failed to add history: " + query.lastError().text() |
| 90 | + "; Sql: " + query.executedQuery() |
| 91 | + "; url: " + url; |
| 92 | SetError(szErr); |
| 93 | qCritical(log) << GetError(); |
| 94 | } |
| 95 | |
| 96 | return success; |
| 97 | } |
| 98 | |
| 99 | bool CHistoryDatabase::addHistoryEntry(const QString &url, const QString& title, const QDateTime& time) |
| 100 | { |
no test coverage detected