GnuCash  5.6-150-g038405b370+
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. More...
 
void gnc_module_finalize_backend_dbi (void)
 Shutdown function which can be used when this module is statically linked into the application. More...
 
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. More...
 
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 1199 of file gnc-backend-dbi.cpp.

1200 {
1201 #if HAVE_LIBDBI_R
1202  if (dbi_instance)
1203  {
1204  dbi_shutdown_r (dbi_instance);
1205  dbi_instance = nullptr;
1206  }
1207 #else
1208  dbi_shutdown ();
1209 #endif
1210 }

◆ 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 1074 of file gnc-backend-dbi.cpp.

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

◆ 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 1186 of file gnc-backend-dbi.cpp.

1187 {
1189 }
void gnc_module_init_backend_dbi(void)
Initialization function which can be used when this module is statically linked into the application...