Sayonara Player
Query.h
1 /* Query.h */
2 
3 /* Copyright (C) 2011-2017 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 <QSqlQuery>
25 #include <QString>
26 #include <QVariant>
27 #include <QSqlDatabase>
28 #include <QSqlError>
29 
30 #include "Utils/Pimpl.h"
31 
32 
33 namespace DB
34 {
35  class Module;
36  class Query :
37  public QSqlQuery
38  {
39  PIMPL(Query)
40 
41  private:
42  explicit Query(const QString& query=QString(), const QSqlDatabase& db = QSqlDatabase()) = delete;
43  explicit Query(QSqlResult * result) = delete;
44  explicit Query(QSqlDatabase db);
45 
46  public:
47  explicit Query(const Module* module);
48  Query(const QString& connection_name, DbId db_id);
49  Query(const Query& other);
50  Query& operator=(const Query& other);
51 
52  virtual ~Query();
53 
54  bool prepare(const QString& query);
55  void bindValue(const QString & placeholder, const QVariant & val, QSql::ParamType paramType = QSql::In);
56  bool exec();
57  bool has_error() const;
58 
59  QString get_query_string() const;
60  void show_query() const;
61  void show_error(const QString& err_msg) const;
62 
63  size_t fetched_rows();
64  };
65 }
66 
67 #endif // Query_H
Definition: Module.h:35
Definition: Query.h:36