GnuCash  5.6-150-g038405b370+
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 #include <qof.h>
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 class GncSqlResult;
35 using GncSqlColumnTableEntryPtr = std::shared_ptr<GncSqlColumnTableEntry>;
36 using EntryVec = std::vector<GncSqlColumnTableEntryPtr>;
37 using PairVec = std::vector<std::pair<std::string, std::string>>;
38 struct GncSqlColumnInfo;
39 using ColVec = std::vector<GncSqlColumnInfo>;
40 
45 {
46 public:
47  virtual ~GncSqlStatement() {}
48  virtual const char* to_sql() const = 0;
49  virtual void add_where_cond (QofIdTypeConst, const PairVec&) = 0;
50 };
51 
52 using GncSqlStatementPtr = std::unique_ptr<GncSqlStatement>;
53 
59 {
60 public:
62  virtual ~GncSqlConnection() = default;
63  virtual GncSqlResultPtr execute_select_statement (const GncSqlStatementPtr&)
64  noexcept = 0;
66  virtual int execute_nonselect_statement (const GncSqlStatementPtr&)
67  noexcept = 0;
68  virtual GncSqlStatementPtr create_statement_from_sql (const std::string&)
69  const noexcept = 0;
71  virtual bool does_table_exist (const std::string&) const noexcept = 0;
73  virtual bool begin_transaction () noexcept = 0;
75  virtual bool rollback_transaction () noexcept = 0;
77  virtual bool commit_transaction () noexcept = 0;
79  virtual bool create_table (const std::string&, const ColVec&)
80  const noexcept = 0;
82  virtual bool create_index (const std::string&, const std::string&,
83  const EntryVec&) const noexcept = 0;
85  virtual bool add_columns_to_table (const std::string&, const ColVec&)
86  const noexcept = 0;
87  virtual std::string quote_string (const std::string&)
88  const noexcept = 0;
92  virtual int dberror() const noexcept = 0;
93  virtual void set_error(QofBackendError error, unsigned int repeat,
94  bool retry) noexcept = 0;
95  virtual bool verify() noexcept = 0;
96  virtual bool retry_connection(const char* msg) noexcept = 0;
97 
98 };
99 
100 
101 #endif //__GNC_SQL_CONNECTION_HPP__
information required to create a column in a table.
const gchar * QofIdTypeConst
QofIdTypeConst declaration.
Definition: qofid.h:82
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.