Select Git revision
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
database.h 9.37 KiB
/****************************************************************************
* Copyright (C) 2017-2018 Savoir-faire Linux *
* Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#pragma once
// Std
#include <memory>
#include <string>
#include <stdexcept>
// Qt
#include <qobject.h>
#include <QtSql/QSqlQuery>
namespace lrc
{
/**
* @brief Class that communicates with the database.
* @note not thread safe.
*/
class Database : public QObject {
Q_OBJECT
public:
/**
* Create a database on the user system.
* @exception QueryError database query error.
*/
Database();
~Database();
/**
* A structure wich contains result(s) returned by a database query.
*/
struct Result {
int nbrOfCols = -1; ///< store the number of columns returned.
/**
* if nbrOfCols equals three and if the size of payloads equals six,
* means two rows of data over three columns.
*/
std::vector<std::string> payloads; ///< store the values.
};
/**
* Generic database query exception.
* details() returns more information, could be empty.
*/
class QueryError : public std::runtime_error {
public:
explicit QueryError(const QSqlQuery& query);
virtual std::string details() { return {}; }