GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-backend-dbi-priv.h
1 /********************************************************************
2  * gnc-backend-dbi-priv.h: load and save data to SQL via libdbi *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License*
15  * along with this program; if not, contact: *
16  * *
17  * Free Software Foundation Voice: +1-617-542-5942 *
18  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19  * Boston, MA 02110-1301, USA [email protected] *
20 \********************************************************************/
21 
22 /* Private structures and variables for gnc-backend-dbi.c and its unit tests */
23 #ifndef GNC_BACKEND_DBI_PRIV_H
24 #define GNC_BACKEND_DBI_PRIV_H
25 
26 #include <dbi/dbi.h>
27 #include "gnc-backend-sql.h"
28 
37 typedef enum
38 {
39  drop = 0,
40  empty,
41  backup,
42  rollback,
43  drop_backup
44 } TableOpType;
45 
52 typedef enum
53 {
54  GNC_DBI_PASS = 0,
55  GNC_DBI_FAIL_SETUP,
56  GNC_DBI_FAIL_TEST
57 } GncDbiTestResult;
58 
59 typedef gchar* (*CREATE_TABLE_DDL_FN) ( GncSqlConnection* conn,
60  const gchar* table_name,
61  const GList* col_info_list );
62 typedef GSList* (*GET_TABLE_LIST_FN) ( dbi_conn conn, const gchar* dbname );
63 typedef void (*APPEND_COLUMN_DEF_FN) ( GString* ddl, GncSqlColumnInfo* info );
64 typedef GSList* (*GET_INDEX_LIST_FN) ( dbi_conn conn );
65 typedef void (*DROP_INDEX_FN) ( dbi_conn conn, const gchar* index );
66 typedef struct
67 {
68  CREATE_TABLE_DDL_FN create_table_ddl;
69  GET_TABLE_LIST_FN get_table_list;
70  APPEND_COLUMN_DEF_FN append_col_def;
71  GET_INDEX_LIST_FN get_index_list;
72  DROP_INDEX_FN drop_index;
74 
75 
77 {
78  GncSqlBackend sql_be;
79 
80  dbi_conn conn;
81 
82  /*@ dependent @*/
83  QofBook *primary_book; /* The primary, main open book */
84  gboolean loading; /* We are performing an initial load */
85  gboolean in_query;
86  gboolean supports_transactions;
87  gboolean is_pristine_db; // Are we saving to a new pristine db?
88  gboolean exists; // Does the database exist?
89 
90  gint obj_total; // Total # of objects (for percentage calculation)
91  gint operations_done; // Number of operations (save/load) done
92 // GHashTable* versions; // Version number for each table
93 };
94 
95 typedef struct GncDbiBackend_struct GncDbiBackend;
96 
97 typedef struct
98 {
99  GncSqlConnection base;
100 
101  /*@ observer @*/
102  QofBackend* qbe;
103  /*@ observer @*/
104  dbi_conn conn;
105  /*@ observer @*/
106  provider_functions_t* provider;
107  gboolean conn_ok; // Used by the error handler routines to flag if the connection is ok to use
108  gint last_error; // Code of the last error that occurred. This is set in the error callback function
109  gint error_repeat; // Used in case of transient errors. After such error, another attempt at the
110  // original call is allowed. error_repeat tracks the number of attempts and can
111  // be used to prevent infinite loops.
112  gboolean retry; // Signals the calling function that it should retry (the error handler detected
113  // transient error and managed to resolve it, but it can't run the original query)
114 
116 
117 #endif //GNC_BACKEND_DBI_PRIV_H
load and save data to SQL