|
GnuCash 2.4.99
|
00001 /******************************************************************** 00002 * gnc-backend-dbi-priv.h: load and save data to SQL via libdbi * 00003 * * 00004 * This program is free software; you can redistribute it and/or * 00005 * modify it under the terms of the GNU General Public License as * 00006 * published by the Free Software Foundation; either version 2 of * 00007 * the License, or (at your option) any later version. * 00008 * * 00009 * This program is distributed in the hope that it will be useful, * 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00012 * GNU General Public License for more details. * 00013 * * 00014 * You should have received a copy of the GNU General Public License* 00015 * along with this program; if not, contact: * 00016 * * 00017 * Free Software Foundation Voice: +1-617-542-5942 * 00018 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * 00019 * Boston, MA 02110-1301, USA gnu@gnu.org * 00020 \********************************************************************/ 00021 00022 /* Private structures and variables for gnc-backend-dbi.c and its unit tests */ 00023 #ifndef GNC_BACKEND_DBI_PRIV_H 00024 #define GNC_BACKEND_DBI_PRIV_H 00025 00026 #include <dbi/dbi.h> 00027 #include "gnc-backend-sql.h" 00028 00037 typedef enum 00038 { 00039 drop = 0, 00040 empty, 00041 backup, 00042 rollback, 00043 drop_backup 00044 } TableOpType; 00045 00052 typedef enum 00053 { 00054 GNC_DBI_PASS = 0, 00055 GNC_DBI_FAIL_SETUP, 00056 GNC_DBI_FAIL_TEST 00057 } GncDbiTestResult; 00058 00059 typedef gchar* (*CREATE_TABLE_DDL_FN)( GncSqlConnection* conn, 00060 const gchar* table_name, 00061 const GList* col_info_list ); 00062 typedef GSList* (*GET_TABLE_LIST_FN)( dbi_conn conn, const gchar* dbname ); 00063 typedef void (*APPEND_COLUMN_DEF_FN)( GString* ddl, GncSqlColumnInfo* info ); 00064 typedef GSList* (*GET_INDEX_LIST_FN)( dbi_conn conn ); 00065 typedef struct 00066 { 00067 CREATE_TABLE_DDL_FN create_table_ddl; 00068 GET_TABLE_LIST_FN get_table_list; 00069 APPEND_COLUMN_DEF_FN append_col_def; 00070 GET_INDEX_LIST_FN get_index_list; 00071 } provider_functions_t; 00072 00073 00074 struct GncDbiBackend_struct 00075 { 00076 GncSqlBackend sql_be; 00077 00078 dbi_conn conn; 00079 00080 /*@ dependent @*/ 00081 QofBook *primary_book; /* The primary, main open book */ 00082 gboolean loading; /* We are performing an initial load */ 00083 gboolean in_query; 00084 gboolean supports_transactions; 00085 gboolean is_pristine_db; // Are we saving to a new pristine db? 00086 gboolean exists; // Does the database exist? 00087 00088 gint obj_total; // Total # of objects (for percentage calculation) 00089 gint operations_done; // Number of operations (save/load) done 00090 // GHashTable* versions; // Version number for each table 00091 }; 00092 00093 typedef struct GncDbiBackend_struct GncDbiBackend; 00094 00095 typedef struct 00096 { 00097 GncSqlConnection base; 00098 00099 /*@ observer @*/ 00100 QofBackend* qbe; 00101 /*@ observer @*/ 00102 dbi_conn conn; 00103 /*@ observer @*/ 00104 provider_functions_t* provider; 00105 gboolean conn_ok; // Used by the error handler routines to flag if the connection is ok to use 00106 gint last_error; // Code of the last error that occurred. This is set in the error callback function 00107 gint error_repeat; // Used in case of transient errors. After such error, another attempt at the 00108 // original call is allowed. error_repeat tracks the number of attempts and can 00109 // be used to prevent infinite loops. 00110 gboolean retry; // Signals the calling function that it should retry (the error handler detected 00111 // transient error and managed to resolve it, but it can't run the original query) 00112 00113 } GncDbiSqlConnection; 00114 00115 #endif //GNC_BACKEND_DBI_PRIV_H
1.7.4