GnuCash de0bfde+
Loading...
Searching...
No Matches
QofDbiBackendProvider< Type > Class Template Reference
Inheritance diagram for QofDbiBackendProvider< Type >:
QofBackendProvider

Public Member Functions

 QofDbiBackendProvider (const char *name, const char *type)
 QofDbiBackendProvider (QofDbiBackendProvider &)=delete
QofDbiBackendProvider operator= (QofDbiBackendProvider &)=delete
 QofDbiBackendProvider (QofDbiBackendProvider &&)=delete
QofDbiBackendProvider operator= (QofDbiBackendProvider &&)=delete
QofBackend * create_backend (void)
 Return a new, fully initialized backend.
bool type_check (const char *type)
 Distinguish two providers with same access method.
bool type_check (const char *uri)
 Distinguish two providers with same access method.
Public Member Functions inherited from QofBackendProvider
 QofBackendProvider (const char *name, const char *type)
 QofBackendProvider (QofBackendProvider &)=delete
 QofBackendProvider (QofBackendProvider &&)=delete

Additional Inherited Members

Data Fields inherited from QofBackendProvider
const char * provider_name
 Some arbitrary name given for this particular backend provider.
const char * access_method
 The access method that this provider provides, for example, file:// http:// postgres:// or sqlite://, but without the :// at the end.

Detailed Description

template<DbType Type>
class QofDbiBackendProvider< Type >

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

Constructor & Destructor Documentation

◆ QofDbiBackendProvider()

template<DbType Type>
QofDbiBackendProvider< Type >::QofDbiBackendProvider ( const char * name,
const char * type )
inline

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

100 :
101 QofBackendProvider {name, type} {}

Member Function Documentation

◆ create_backend()

template<DbType Type>
QofBackend * QofDbiBackendProvider< Type >::create_backend ( void )
inlinevirtual

Return a new, fully initialized backend.

If the backend supports configuration, all configuration options should be initialised to usable values here.

Implements QofBackendProvider.

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

108 {
109 return new GncDbiBackend<Type>(nullptr, nullptr);
110 }

◆ type_check() [1/2]

template<DbType Type>
bool QofDbiBackendProvider< Type >::type_check ( const char * )
inlinevirtual

Distinguish two providers with same access method.

More than 1 backend can be registered under the same access_method, so each one is passed the path to the data (e.g. a file) and should return TRUE only:

  1. if the backend recognises the type as one that it can load and write or
  2. if the path contains no data but can be used (e.g. a new session).

    Note
    If the backend can cope with more than one type, the backend should not try to store or cache the sub-type for this data. It is sufficient only to return TRUE if any ONE of the supported types match the incoming data. The backend should not assume that returning TRUE will mean that the data will naturally follow.

Implements QofBackendProvider.

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

111{ return true; }

◆ type_check() [2/2]

bool QofDbiBackendProvider< DbType::DBI_SQLITE >::type_check ( const char * )
virtual

Distinguish two providers with same access method.

More than 1 backend can be registered under the same access_method, so each one is passed the path to the data (e.g. a file) and should return TRUE only:

  1. if the backend recognises the type as one that it can load and write or
  2. if the path contains no data but can be used (e.g. a new session).

    Note
    If the backend can cope with more than one type, the backend should not try to store or cache the sub-type for this data. It is sufficient only to return TRUE if any ONE of the supported types match the incoming data. The backend should not assume that returning TRUE will mean that the data will naturally follow.

Implements QofBackendProvider.

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

1034{
1035 FILE* f;
1036 gchar buf[51]{};
1038 gint status;
1039 gchar* filename;
1040
1041 // BAD if the path is null
1042 g_return_val_if_fail (uri != nullptr, FALSE);
1043
1045 f = g_fopen (filename, "r");
1046 g_free (filename);
1047
1048 // OK if the file doesn't exist - new file
1049 if (f == nullptr)
1050 {
1051 PINFO ("doesn't exist (errno=%d) -> DBI", errno);
1052 return TRUE;
1053 }
1054
1055 // OK if file has the correct header
1056 chars_read = fread (buf, sizeof (buf) - 1, 1, f);
1057 status = fclose (f);
1058 if (status < 0)
1059 {
1060 PERR ("Error in fclose(): %d\n", errno);
1061 }
1062 if (g_str_has_prefix (buf, "SQLite format 3"))
1063 {
1064 PINFO ("has SQLite format string -> DBI");
1065 return TRUE;
1066 }
1067 PINFO ("exists, does not have SQLite format string -> not DBI");
1068
1069 // Otherwise, BAD
1070 return FALSE;
1071}
#define PINFO(format, args...)
Print an informational note.
Definition qoflog.h:256
#define PERR(format, args...)
Log a serious error.
Definition qoflog.h:244
gchar * gnc_uri_get_path(const gchar *uri)
Extracts the path part from a uri.

The documentation for this class was generated from the following file: