Skip to content
Snippets Groups Projects
Select Git revision
  • 6c0a79eb50deadceeffed1918bb60e19671eba05
  • master default protected
  • release/202005
  • release/202001
  • release/201912
  • release/201911
  • release/releaseWindowsTestOne
  • release/releaseTest
  • release/releaseWindowsTest
  • release/windowsReleaseTest
  • release/201910
  • release/qt/201910
  • release/windows-test/201910
  • release/201908
  • release/201906
  • release/201905
  • release/201904
  • release/201903
  • release/201902
  • release/201901
  • release/201812
  • 1.0.0
  • 0.3.0
  • 0.2.1
  • 0.2.0
  • 0.1.0
26 results

database.h

Blame
  • 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 {}; }