shared: SqliteDbService: Add queryFileType()

This commit is contained in:
Albert S. 2023-01-08 17:37:28 +01:00
parent 363d207ccc
commit 71789b5b56
2 ha cambiato i file con 20 aggiunte e 0 eliminazioni

Vedi File

@ -29,6 +29,22 @@ QVector<SearchResult> SqliteDbService::search(const LooqsQuery &query)
return searcher.search(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) bool SqliteDbService::fileExistsInDatabase(QString path)
{ {
auto query = QSqlQuery(dbFactory->forCurrentThread()); auto query = QSqlQuery(dbFactory->forCurrentThread());

Vedi File

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