Sayonara Player
Query.h
1 /* Query.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef Query_H
22 #define Query_H
23 
24 #include "Utils/Pimpl.h"
25 
26 #include <QString>
27 #include <QSqlQuery>
28 #include <QVariant>
29 #include <QSqlDatabase>
30 #include <QSqlError>
31 
32 namespace DB
33 {
34  class Module;
35  class Query :
36  public QSqlQuery
37  {
38  PIMPL(Query)
39 
40  private:
41  explicit Query(QSqlDatabase db);
42 
43  public:
44  explicit Query(const Module* module);
45 
46  Query(const QString& connection_name, DbId databaseId);
47  Query(const Query& other);
48 
49  explicit Query(QSqlResult* result) = delete;
50  explicit Query(const QString& query=QString(), const QSqlDatabase& db = QSqlDatabase()) = delete;
51 
52  Query& operator=(const Query& other);
53 
54  virtual ~Query();
55 
56  bool prepare(const QString& query);
57  void bindValue(const QString& placeholder, const QVariant & val, QSql::ParamType paramType = QSql::In);
58  bool exec();
59  void setError(bool b);
60  bool hasError() const;
61 
62  QString getQueryString() const;
63  void showQuery() const;
64  void showError(const QString& err_msg) const;
65 
66 
67  size_t fetchedRows();
68  };
69 }
70 
71 #endif // Query_H
DB::Module
Definition: Module.h:33
DB::Query
Definition: Query.h:37