GnuCash  4.11-627-g58c1a51897
gnc-sql-connection.hpp
1 /***********************************************************************\
2  * gnc-sql-connection.hpp: Encapsulate a SQL database connection. *
3  * *
4  * Copyright 2016 John Ralls <jralls@ceridwen.us> *
5  * *
6  * This program is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU General Public License as *
8  * published by the Free Software Foundation; either version 2 of *
9  * the License, or (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, contact: *
18  * *
19  * Free Software Foundation Voice: +1-617-542-5942 *
20  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
21  * Boston, MA 02110-1301, USA gnu@gnu.org *
22 \***********************************************************************/
23 
24 #ifndef __GNC_SQL_CONNECTION_HPP__
25 #define __GNC_SQL_CONNECTION_HPP__
26 
27 extern "C"
28 {
29 #include <qof.h>
30 }
31 #include <memory>
32 #include <string>
33 #include <vector>
34 
35 class GncSqlResult;
38 using GncSqlColumnTableEntryPtr = std::shared_ptr<GncSqlColumnTableEntry>;
39 using EntryVec = std::vector<GncSqlColumnTableEntryPtr>;
40 using PairVec = std::vector<std::pair<std::string, std::string>>;
41 struct GncSqlColumnInfo;
42 using ColVec = std::vector<GncSqlColumnInfo>;
43 
48 {
49 public:
50  virtual ~GncSqlStatement() {}
51  virtual const char* to_sql() const = 0;
52  virtual void add_where_cond (QofIdTypeConst, const PairVec&) = 0;
53 };
54 
55 using GncSqlStatementPtr = std::unique_ptr<GncSqlStatement>;
56 
62 {
63 public:
65  virtual ~GncSqlConnection() = default;
66  virtual GncSqlResultPtr execute_select_statement (const GncSqlStatementPtr&)
67  noexcept = 0;
69  virtual int execute_nonselect_statement (const GncSqlStatementPtr&)
70  noexcept = 0;
71  virtual GncSqlStatementPtr create_statement_from_sql (const std::string&)
72  const noexcept = 0;
74  virtual bool does_table_exist (const std::string&) const noexcept = 0;
76  virtual bool begin_transaction () noexcept = 0;
78  virtual bool rollback_transaction () noexcept = 0;
80  virtual bool commit_transaction () noexcept = 0;
82  virtual bool create_table (const std::string&, const ColVec&)
83  const noexcept = 0;
85  virtual bool create_index (const std::string&, const std::string&,
86  const EntryVec&) const noexcept = 0;
88  virtual bool add_columns_to_table (const std::string&, const ColVec&)
89  const noexcept = 0;
90  virtual std::string quote_string (const std::string&)
91  const noexcept = 0;
95  virtual int dberror() const noexcept = 0;
96  virtual void set_error(QofBackendError error, unsigned int repeat,
97  bool retry) noexcept = 0;
98  virtual bool verify() noexcept = 0;
99  virtual bool retry_connection(const char* msg) noexcept = 0;
100 
101 };
102 
103 
104 #endif //__GNC_SQL_CONNECTION_HPP__
information required to create a column in a table.
const gchar * QofIdTypeConst
QofIdTypeConst declaration.
Definition: qofid.h:87
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition: qofbackend.h:57
SQL statement provider.
virtual bool create_index(const std::string &, const std::string &, const EntryVec &) const noexcept=0
Returns TRUE if successful, FALSE if error.
virtual int execute_nonselect_statement(const GncSqlStatementPtr &) noexcept=0
Returns false if error.
virtual int dberror() const noexcept=0
Get the connection error value.
virtual bool commit_transaction() noexcept=0
Returns TRUE if successful, FALSE if error.
virtual bool add_columns_to_table(const std::string &, const ColVec &) const noexcept=0
Returns TRUE if successful, FALSE if error.
virtual bool create_table(const std::string &, const ColVec &) const noexcept=0
Returns TRUE if successful, FALSE if error.
Encapsulate the connection to the database.
Pure virtual class to iterate over a query result set.
virtual bool begin_transaction() noexcept=0
Returns TRUE if successful, false if error.
virtual bool rollback_transaction() noexcept=0
Returns TRUE if successful, FALSE if error.
Contains all of the information required to copy information between an object and the database for a...
virtual bool does_table_exist(const std::string &) const noexcept=0
Returns true if successful.
virtual ~GncSqlConnection()=default
Returns NULL if error.