GnuCash c935c2f+
Loading...
Searching...
No Matches
Functions
gnc-backend-dbi.h File Reference

load and save data to SQL via libdbi More...

#include <gmodule.h>

Go to the source code of this file.

Functions

void gnc_module_init_backend_dbi (void)
 Initialization function which can be used when this module is statically linked into the application.
 
void gnc_module_finalize_backend_dbi (void)
 Shutdown function which can be used when this module is statically linked into the application.
 
G_MODULE_EXPORT void qof_backend_module_init (void)
 This is the standardized initialization function of a qof_backend GModule, but compiling this can be disabled by defining GNC_NO_LOADABLE_MODULES.
 
G_MODULE_EXPORT void qof_backend_module_finalize (void)
 

Detailed Description

load and save data to SQL via libdbi

Author
Copyright (c) 2006-2008 Phil Longstaff plong.nosp@m.staf.nosp@m.f@rog.nosp@m.ers..nosp@m.com

This file implements the top-level QofBackend API for saving/ restoring data to/from an SQL database via libdbi

Definition in file gnc-backend-dbi.h.

Function Documentation

◆ gnc_module_finalize_backend_dbi()

void gnc_module_finalize_backend_dbi ( void  )

Shutdown function which can be used when this module is statically linked into the application.

Definition at line 1196 of file gnc-backend-dbi.cpp.

1197{
1198#if HAVE_LIBDBI_R
1199 if (dbi_instance)
1200 {
1201 dbi_shutdown_r (dbi_instance);
1202 dbi_instance = nullptr;
1203 }
1204#else
1205 dbi_shutdown ();
1206#endif
1207}

◆ gnc_module_init_backend_dbi()

void gnc_module_init_backend_dbi ( void  )

Initialization function which can be used when this module is statically linked into the application.

Definition at line 1071 of file gnc-backend-dbi.cpp.

1072{
1073 const char* driver_dir;
1074 int num_drivers;
1075 gboolean have_sqlite3_driver = FALSE;
1076 gboolean have_mysql_driver = FALSE;
1077 gboolean have_pgsql_driver = FALSE;
1078
1079 /* Initialize libdbi and see which drivers are available. Only register qof backends which
1080 have drivers available. */
1081 driver_dir = g_getenv ("GNC_DBD_DIR");
1082 if (driver_dir == nullptr)
1083 {
1084 PINFO ("GNC_DBD_DIR not set: using libdbi built-in default\n");
1085 }
1086
1087 /* dbi_initialize returns -1 in case of errors */
1088#if HAVE_LIBDBI_R
1089 if (dbi_instance)
1090 return;
1091 num_drivers = dbi_initialize_r (driver_dir, &dbi_instance);
1092#else
1093 num_drivers = dbi_initialize (driver_dir);
1094#endif
1095 if (num_drivers <= 0)
1096 {
1097#if HAVE_LIBDBI_R
1098 if (dbi_instance)
1099 {
1100 dbi_shutdown_r (dbi_instance);
1101 dbi_instance = nullptr;
1102 }
1103#endif
1104 gchar *libdir = gnc_path_get_libdir ();
1105 gchar *dir = g_build_filename (libdir, "dbd", nullptr);
1106 g_free (libdir);
1107#if HAVE_LIBDBI_R
1108 num_drivers = dbi_initialize_r (dir, &dbi_instance);
1109#else
1110 num_drivers = dbi_initialize (dir);
1111#endif
1112 g_free (dir);
1113 }
1114 if (num_drivers <= 0)
1115 {
1116 PWARN ("No DBD drivers found\n");
1117 }
1118 else
1119 {
1120 dbi_driver driver = nullptr;
1121 PINFO ("%d DBD drivers found\n", num_drivers);
1122
1123 do
1124 {
1125#if HAVE_LIBDBI_R
1126 driver = dbi_driver_list_r (driver, dbi_instance);
1127#else
1128 driver = dbi_driver_list (driver);
1129#endif
1130
1131 if (driver != nullptr)
1132 {
1133 const gchar* name = dbi_driver_get_name (driver);
1134
1135 PINFO ("Driver: %s\n", name);
1136 if (strcmp (name, "sqlite3") == 0)
1137 {
1138 have_sqlite3_driver = TRUE;
1139 }
1140 else if (strcmp (name, "mysql") == 0)
1141 {
1142 have_mysql_driver = TRUE;
1143 }
1144 else if (strcmp (name, "pgsql") == 0)
1145 {
1146 have_pgsql_driver = TRUE;
1147 }
1148 }
1149 }
1150 while (driver != nullptr);
1151 }
1152
1153 if (have_sqlite3_driver)
1154 {
1155 const char* name = "GnuCash Libdbi (SQLITE3) Backend";
1156 auto prov = QofBackendProvider_ptr(new QofDbiBackendProvider<DbType::DBI_SQLITE>{name, FILE_URI_TYPE});
1157 qof_backend_register_provider(std::move(prov));
1158 prov = QofBackendProvider_ptr(new QofDbiBackendProvider<DbType::DBI_SQLITE>{name, SQLITE3_URI_TYPE});
1159 qof_backend_register_provider(std::move(prov));
1160 }
1161
1162 if (have_mysql_driver)
1163 {
1164 const char *name = "GnuCash Libdbi (MYSQL) Backend";
1165 auto prov = QofBackendProvider_ptr(new QofDbiBackendProvider<DbType::DBI_MYSQL>{name, "mysql"});
1166 qof_backend_register_provider(std::move(prov));
1167 }
1168
1169 if (have_pgsql_driver)
1170 {
1171 const char* name = "GnuCash Libdbi (POSTGRESQL) Backend";
1172 auto prov = QofBackendProvider_ptr(new QofDbiBackendProvider<DbType::DBI_PGSQL>{name, "postgres"});
1173 qof_backend_register_provider(std::move(prov));
1174 }
1175
1176 /* If needed, set log level to DEBUG so that SQl statements will be put into
1177 the gnucash.trace file. */
1178 /* qof_log_set_level( log_module, QOF_LOG_DEBUG ); */
1179}
#define PINFO(format, args...)
Print an informational note.
Definition qoflog.h:256
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250

◆ qof_backend_module_finalize()

G_MODULE_EXPORT void qof_backend_module_finalize ( void  )

Definition at line 1189 of file gnc-backend-dbi.cpp.

1190{
1191 gnc_module_finalize_backend_dbi ();
1192}

◆ qof_backend_module_init()

G_MODULE_EXPORT void qof_backend_module_init ( void  )

This is the standardized initialization function of a qof_backend GModule, but compiling this can be disabled by defining GNC_NO_LOADABLE_MODULES.

Definition at line 1183 of file gnc-backend-dbi.cpp.

1184{
1185 gnc_module_init_backend_dbi ();
1186}