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

1194 {
1195 #if HAVE_LIBDBI_R
1196  if (dbi_instance)
1197  {
1198  dbi_shutdown_r (dbi_instance);
1199  dbi_instance = nullptr;
1200  }
1201 #else
1202  dbi_shutdown ();
1203 #endif
1204 }

◆ 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  return;
1100 #endif
1101  gchar *libdir = gnc_path_get_libdir ();
1102  gchar *dir = g_build_filename (libdir, "dbd", nullptr);
1103  g_free (libdir);
1104 #if HAVE_LIBDBI_R
1105  num_drivers = dbi_initialize_r (dir, &dbi_instance);
1106 #else
1107  num_drivers = dbi_initialize (dir);
1108 #endif
1109  g_free (dir);
1110  }
1111  if (num_drivers <= 0)
1112  {
1113  PWARN ("No DBD drivers found\n");
1114  }
1115  else
1116  {
1117  dbi_driver driver = nullptr;
1118  PINFO ("%d DBD drivers found\n", num_drivers);
1119 
1120  do
1121  {
1122 #if HAVE_LIBDBI_R
1123  driver = dbi_driver_list_r (driver, dbi_instance);
1124 #else
1125  driver = dbi_driver_list (driver);
1126 #endif
1127 
1128  if (driver != nullptr)
1129  {
1130  const gchar* name = dbi_driver_get_name (driver);
1131 
1132  PINFO ("Driver: %s\n", name);
1133  if (strcmp (name, "sqlite3") == 0)
1134  {
1135  have_sqlite3_driver = TRUE;
1136  }
1137  else if (strcmp (name, "mysql") == 0)
1138  {
1139  have_mysql_driver = TRUE;
1140  }
1141  else if (strcmp (name, "pgsql") == 0)
1142  {
1143  have_pgsql_driver = TRUE;
1144  }
1145  }
1146  }
1147  while (driver != nullptr);
1148  }
1149 
1150  if (have_sqlite3_driver)
1151  {
1152  const char* name = "GnuCash Libdbi (SQLITE3) Backend";
1153  auto prov = QofBackendProvider_ptr(new QofDbiBackendProvider<DbType::DBI_SQLITE>{name, FILE_URI_TYPE});
1154  qof_backend_register_provider(std::move(prov));
1155  prov = QofBackendProvider_ptr(new QofDbiBackendProvider<DbType::DBI_SQLITE>{name, SQLITE3_URI_TYPE});
1156  qof_backend_register_provider(std::move(prov));
1157  }
1158 
1159  if (have_mysql_driver)
1160  {
1161  const char *name = "GnuCash Libdbi (MYSQL) Backend";
1162  auto prov = QofBackendProvider_ptr(new QofDbiBackendProvider<DbType::DBI_MYSQL>{name, "mysql"});
1163  qof_backend_register_provider(std::move(prov));
1164  }
1165 
1166  if (have_pgsql_driver)
1167  {
1168  const char* name = "GnuCash Libdbi (POSTGRESQL) Backend";
1169  auto prov = QofBackendProvider_ptr(new QofDbiBackendProvider<DbType::DBI_PGSQL>{name, "postgres"});
1170  qof_backend_register_provider(std::move(prov));
1171  }
1172 
1173  /* If needed, set log level to DEBUG so that SQl statements will be put into
1174  the gnucash.trace file. */
1175  /* qof_log_set_level( log_module, QOF_LOG_DEBUG ); */
1176 }
#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:90
#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 1180 of file gnc-backend-dbi.cpp.

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