GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions
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
 
QofBackendcreate_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 1030 of file gnc-backend-dbi.cpp.

1031{
1032 FILE* f;
1033 gchar buf[51]{};
1034 G_GNUC_UNUSED size_t chars_read;
1035 gint status;
1036 gchar* filename;
1037
1038 // BAD if the path is null
1039 g_return_val_if_fail (uri != nullptr, FALSE);
1040
1041 filename = gnc_uri_get_path (uri);
1042 f = g_fopen (filename, "r");
1043 g_free (filename);
1044
1045 // OK if the file doesn't exist - new file
1046 if (f == nullptr)
1047 {
1048 PINFO ("doesn't exist (errno=%d) -> DBI", errno);
1049 return TRUE;
1050 }
1051
1052 // OK if file has the correct header
1053 chars_read = fread (buf, sizeof (buf) - 1, 1, f);
1054 status = fclose (f);
1055 if (status < 0)
1056 {
1057 PERR ("Error in fclose(): %d\n", errno);
1058 }
1059 if (g_str_has_prefix (buf, "SQLite format 3"))
1060 {
1061 PINFO ("has SQLite format string -> DBI");
1062 return TRUE;
1063 }
1064 PINFO ("exists, does not have SQLite format string -> not DBI");
1065
1066 // Otherwise, BAD
1067 return FALSE;
1068}
#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: