mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-09-03 20:53:02 -05:00
document the bacekn functions a bit more, document the error codes.
add dialogs to create a new database, if it didn't exist before git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3594 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
+26
-24
@@ -3,14 +3,14 @@
|
||||
* Backend.h
|
||||
*
|
||||
* FUNCTION:
|
||||
* Pseudo-object defining how the engine can interact with different
|
||||
* back-ends (which may be SQL databases, or network interfaces to
|
||||
* remote gnucash servers. In theory, file-io should be a type of
|
||||
* backend).
|
||||
* The 'backend' is a pseudo-object providing an interface between the
|
||||
* engine and a persistant data store (e.g. a server, a database, or
|
||||
* a file). There are no backend functions that are 'public' to
|
||||
* users of the engine. The backend can, however, report errors to
|
||||
* the GUI & other front-end users. This file defines these errors.
|
||||
*
|
||||
* The callbacks will be called at the appropriate times during
|
||||
* a book session to allow the backend to store the data as needed.
|
||||
*
|
||||
* HISTORY:
|
||||
* Copyright (c) 2000, 2001 Linas Vepstas (linas@linas.org)
|
||||
*/
|
||||
|
||||
#ifndef __XACC_BACKEND_H__
|
||||
@@ -24,32 +24,34 @@ typedef enum {
|
||||
ERR_BACKEND_NO_BACKEND, /* Backend * pointer was null the err routine */
|
||||
/* or no backend handler (ENOSYS) */
|
||||
ERR_BACKEND_LOCKED, /* in use by another user (ETXTBSY) */
|
||||
ERR_BACKEND_NO_SUCH_DB, /* the named database doesn't exist */
|
||||
ERR_BACKEND_MISC, /* undetermined error */
|
||||
|
||||
/* fileio errors */
|
||||
ERR_FILEIO_FILE_BAD_READ,
|
||||
ERR_FILEIO_FILE_EMPTY,
|
||||
ERR_FILEIO_FILE_LOCKED,
|
||||
ERR_FILEIO_FILE_NOT_FOUND,
|
||||
ERR_FILEIO_FILE_TOO_NEW,
|
||||
ERR_FILEIO_FILE_TOO_OLD,
|
||||
ERR_FILEIO_ALLOC,
|
||||
ERR_FILEIO_MISC, /* unknown weird error */
|
||||
ERR_FILEIO_FILE_BAD_READ, /* read failed or file prematurely truncated */
|
||||
ERR_FILEIO_FILE_EMPTY, /* file exists, is readable, but is empty */
|
||||
ERR_FILEIO_FILE_LOCKERR, /* mangled locks (unspecified error) */
|
||||
ERR_FILEIO_FILE_NOT_FOUND, /* not found / no such file */
|
||||
ERR_FILEIO_FILE_TOO_NEW, /* file version newer than what we can read */
|
||||
ERR_FILEIO_FILE_TOO_OLD, /* file version so old we can't read it */
|
||||
ERR_FILEIO_ALLOC, /* ?? */
|
||||
ERR_FILEIO_MISC, /* unknown weird error */
|
||||
|
||||
/* network errors */
|
||||
ERR_NETIO_NO_CONNECTION, /* network failure */
|
||||
ERR_NETIO_NO_CONNECTION, /* network failure, can't connect to server */
|
||||
ERR_NETIO_SHORT_READ, /* not enough bytes received */
|
||||
ERR_NETIO_WRONG_CONTENT_TYPE, /* wrong kind of server, wrong data served */
|
||||
ERR_NETIO_NOT_GNCXML,
|
||||
ERR_NETIO_NOT_GNCXML, /* whatever it is, we can't parse it. */
|
||||
|
||||
/* database errors */
|
||||
ERR_SQL_BUSY, /* single-mode access doesn't allow other users */
|
||||
ERR_SQL_CANT_CONNECT, /* network failure */
|
||||
ERR_SQL_SEND_QUERY_FAILED,
|
||||
ERR_SQL_FINISH_QUERY_FAILED,
|
||||
ERR_SQL_GET_RESULT_FAILED,
|
||||
ERR_SQL_CORRUPT_DB,
|
||||
ERR_SQL_MISSING_DATA, /* database doesn't contain expected data */
|
||||
ERR_SQL_BAD_LOCATION, /* can't parse url */
|
||||
ERR_SQL_CANT_CONNECT, /* bad dbname/login/passwd or network failure */
|
||||
ERR_SQL_SEND_QUERY_FAILED, /* can't send to database */
|
||||
ERR_SQL_FINISH_QUERY_FAILED, /* can't finish out sent request */
|
||||
ERR_SQL_GET_RESULT_FAILED, /* can't read response from the db. */
|
||||
ERR_SQL_CORRUPT_DB, /* data in db is corrupt */
|
||||
ERR_SQL_MISSING_DATA, /* database doesn't contain expected data */
|
||||
|
||||
} GNCBackendError;
|
||||
|
||||
|
||||
|
||||
+24
-15
@@ -5,7 +5,7 @@
|
||||
* FUNCTION:
|
||||
* Pseudo-object defining how the engine can interact with different
|
||||
* back-ends (which may be SQL databases, or network interfaces to
|
||||
* remote gnucash servers. In theory, file-io should be a type of
|
||||
* remote GnuCash servers. In theory, file-io should be a type of
|
||||
* backend).
|
||||
*
|
||||
* The callbacks will be called at the appropriate times during
|
||||
@@ -35,19 +35,27 @@ typedef struct _backend Backend;
|
||||
* the actual network connection.
|
||||
*
|
||||
* The 'ignore_lock' argument indicates whether the single-user
|
||||
* lock on the backend should be cleared. The typical gui sequence
|
||||
* leading to this is: (1) gui attempts to open the backend
|
||||
* lock on the backend should be cleared. The typical GUI sequence
|
||||
* leading to this is: (1) GUI attempts to open the backend
|
||||
* by calling this routine with FALSE==ignore_lock. (2) If backend
|
||||
* error'ed BACKEND_LOCK, then GUI asks user what to do. (3) if user
|
||||
* answers 'break & enter' then this routine is called again with
|
||||
* TURE==ignore_lock.
|
||||
* TRUE==ignore_lock.
|
||||
*
|
||||
* The 'create_if_nonexistent' argument indicates whether this
|
||||
* routine should create a new 'database', if it doesn't already
|
||||
* exist. For example, for a file-backend, this would create the
|
||||
* file, if it didn't already exist. For an SQL backend, this
|
||||
* would create the database (the schema) if it didn't already
|
||||
* exist. This flag is used to implement the 'SaveAs' GUI, where
|
||||
* the user requests to save data to a new backend.
|
||||
*
|
||||
* The book_load() routine should return at least an account tree,
|
||||
* and all currencies. It does not have to return any transactions
|
||||
* whatsoever, as these are obtained at a later stage when a user
|
||||
* opens a register, resulting in a query being sent to the backend.
|
||||
*
|
||||
* (Its OK to send over transactinos at this point, but one should
|
||||
* (Its OK to send over transactions at this point, but one should
|
||||
* be careful of the network load; also, its possible that whatever
|
||||
* is sent is not what the user wanted anyway, which is why its
|
||||
* better to wait for the query).
|
||||
@@ -55,19 +63,19 @@ typedef struct _backend Backend;
|
||||
* The trans_commit_edit() routine takes two transaction arguments:
|
||||
* the first is the proposed new transaction; the second is the
|
||||
* 'original' transaction. The second argument is here for
|
||||
* convencience; it had better be substantially equivalent to
|
||||
* convenience; it had better be substantially equivalent to
|
||||
* the argument for the trans_begin_edit() callback. (It doesn't
|
||||
* have to be identical, it can be a clone).
|
||||
*
|
||||
* The run_query() callback takes a gnucash query object.
|
||||
* For an sql backend, the contents of the query object need to
|
||||
* be turned into a corresponsing sql query statement, and sent
|
||||
* The run_query() callback takes a GnuCash query object.
|
||||
* For an SQL backend, the contents of the query object need to
|
||||
* be turned into a corresponding SQL query statement, and sent
|
||||
* to the database for evaluation. The database will return a
|
||||
* set of splits and transactions, and this callback needs
|
||||
* to poke these into the account-group heirarchy held by the
|
||||
* to poke these into the account-group hierarchy held by the
|
||||
* query object.
|
||||
*
|
||||
* For a network-communications backend, esentially the same is
|
||||
* For a network-communications backend, essentially the same is
|
||||
* done, except that this routine would convert the query to wire
|
||||
* protocol, get an answer from the remote server, and push that
|
||||
* into the account-group object.
|
||||
@@ -75,8 +83,8 @@ typedef struct _backend Backend;
|
||||
* Note a peculiar design decision we've used here. The query
|
||||
* callback has returned a list of splits; these could be returned
|
||||
* directly to the caller. They are not. By poking them into the
|
||||
* existing account heirarchy, we are essentially building a local
|
||||
* cache of the split data. This will allow the gnucash client to
|
||||
* existing account hierarchy, we are essentially building a local
|
||||
* cache of the split data. This will allow the GnuCash client to
|
||||
* continue functioning even when disconnected from the server:
|
||||
* this is because it will have its local cache of data to work from.
|
||||
*
|
||||
@@ -94,14 +102,15 @@ typedef struct _backend Backend;
|
||||
* needed to update an existing transaction. It might pull new
|
||||
* currencies (??))
|
||||
*
|
||||
* The last_err member indicates the last error that occured.
|
||||
* The last_err member indicates the last error that occurred.
|
||||
* It should probably be implemented as an array (actually,
|
||||
* a stack) of all the errors that have occurred.
|
||||
*/
|
||||
|
||||
struct _backend
|
||||
{
|
||||
void (*book_begin) (GNCBook *, const char *book_id, int ignore_lock);
|
||||
void (*book_begin) (GNCBook *, const char *book_id,
|
||||
gboolean ignore_lock, gboolean create_if_nonexistent);
|
||||
AccountGroup * (*book_load) (Backend *);
|
||||
void (*book_end) (Backend *);
|
||||
int (*account_begin_edit) (Backend *, Account *);
|
||||
|
||||
@@ -63,7 +63,7 @@ struct _gnc_book
|
||||
*/
|
||||
char *book_id;
|
||||
|
||||
/* if book_begin failed, this records the failure reason
|
||||
/* if any book subroutine failed, this records the failure reason
|
||||
* (file not found, etc).
|
||||
* This is a 'stack' that is one deep.
|
||||
* FIXME: This is a hack. I'm trying to move us away from static
|
||||
@@ -301,7 +301,8 @@ gnc_book_begin_file (GNCBook *book, const char * filefrag,
|
||||
/* ============================================================== */
|
||||
|
||||
gboolean
|
||||
gnc_book_begin (GNCBook *book, const char * book_id, gboolean ignore_lock)
|
||||
gnc_book_begin (GNCBook *book, const char * book_id,
|
||||
gboolean ignore_lock, gboolean create_if_nonexistent)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -394,7 +395,9 @@ gnc_book_begin (GNCBook *book, const char * book_id, gboolean ignore_lock)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// book->backend = pgendNew ();
|
||||
/* For the postgres backend, do the equivalent of
|
||||
* the statically loaded
|
||||
* book->backend = pgendNew (); */
|
||||
pg_new = dlsym (dll_handle, "pgendNew");
|
||||
dll_err = dlerror();
|
||||
if (dll_err)
|
||||
@@ -416,7 +419,9 @@ gnc_book_begin (GNCBook *book, const char * book_id, gboolean ignore_lock)
|
||||
{
|
||||
GNCBackendError err;
|
||||
|
||||
(book->backend->book_begin)(book, book->book_id, ignore_lock);
|
||||
(book->backend->book_begin)(book, book->book_id, ignore_lock,
|
||||
create_if_nonexistent);
|
||||
|
||||
err = xaccBackendGetError(book->backend);
|
||||
if (ERR_BACKEND_NO_ERR != err)
|
||||
{
|
||||
|
||||
+18
-11
@@ -67,26 +67,33 @@ void gnc_book_destroy (GNCBook *book);
|
||||
|
||||
/* The gnc_book_begin () method begins a new book. It takes as an argument
|
||||
* the book id. The book id must be a string in the form of a URI/URL.
|
||||
* In the current implementation, only the file URI type is fully
|
||||
* supported, (with others in various stages of prototyping).
|
||||
* A file URI is of the form
|
||||
* In the current implementation, the following URL's are supported
|
||||
* -- File URI of the form
|
||||
* "file:/home/somewhere/somedir/file.xac"
|
||||
* The path part must be a valid path. The file-part must be a valid
|
||||
* xacc/gnucash-format file. Paths may be relative or absolute. If the
|
||||
* path is relative; that is, if the argument is
|
||||
* "file:somefile.xac"
|
||||
* then a sequence of search paths are checked for a file of this name.
|
||||
* The path part must be a valid path. The file-part must be
|
||||
* a valid old-style-xacc or new-style-gnucash-format file. Paths
|
||||
* may be relative or absolute. If the path is relative; that is,
|
||||
* if the argument is "file:somefile.xac" then a sequence of
|
||||
* search paths are checked for a file of this name.
|
||||
*
|
||||
* -- Postgres URI of the form
|
||||
* "postgres://hostname.com/dbname"
|
||||
* See the sql subdirectory for more info.
|
||||
*
|
||||
* The 'ignore_lock' argument, if set to TRUE, will cause this routine
|
||||
* to ignore any file locks that it finds. If set to FALSE, then
|
||||
* file locks will be tested and obeyed.
|
||||
*
|
||||
* If the file exists, can be opened and read, and a lock can be obtained
|
||||
* then a lock will be obtained and the function returns TRUE. Otherwise
|
||||
* the function returns FALSE.
|
||||
* then a lock will be obtained and the function returns TRUE.
|
||||
*
|
||||
* If the file/database doesn't exist, and the create_if_nonexistent
|
||||
* flag is set to TRUE, then the database is created.
|
||||
*
|
||||
* Otherwise the function returns FALSE.
|
||||
*/
|
||||
gboolean gnc_book_begin (GNCBook *book, const char * book_id,
|
||||
gboolean ignore_lock);
|
||||
gboolean ignore_lock, gboolean create_if_nonexistent);
|
||||
|
||||
|
||||
/* The gnc_book_load() method loads the data associated with the book.
|
||||
|
||||
Reference in New Issue
Block a user