shared: SqliteDbService: Add queryFileType()

This commit is contained in:
Albert S. 2023-01-08 17:37:28 +01:00
джерело 363d207ccc
коміт 71789b5b56
2 змінених файлів з 20 додано та 0 видалено

@ -29,6 +29,22 @@ QVector<SearchResult> SqliteDbService::search(const LooqsQuery &query)
return searcher.search(query);
}
std::optional<QChar> SqliteDbService::queryFileType(QString absPath)
{
auto query = QSqlQuery(dbFactory->forCurrentThread());
query.prepare("SELECT filetype FROM file WHERE path = ?");
query.addBindValue(absPath);
if(!query.exec())
{
throw LooqsGeneralException("Error while trying to query for file type: " + query.lastError().text());
}
if(!query.next())
{
return {};
}
return query.value(0).toChar();
}
bool SqliteDbService::fileExistsInDatabase(QString path)
{
auto query = QSqlQuery(dbFactory->forCurrentThread());

@ -1,6 +1,8 @@
#ifndef SQLITEDBSERVICE_H
#define SQLITEDBSERVICE_H
#include <QFileInfo>
#include <optional>
#include "databasefactory.h"
#include "utils.h"
#include "pagedata.h"
@ -23,6 +25,8 @@ class SqliteDbService
bool fileExistsInDatabase(QString path);
bool fileExistsInDatabase(QString path, qint64 mtime);
QVector<SearchResult> search(const LooqsQuery &query);
std::optional<QChar> queryFileType(QString absPath);
};
#endif // SQLITEDBSERVICE_H