Line data Source code
1 : /********************************************************************
2 : * gnc-slots-sql.h: load and save data to SQL *
3 : * *
4 : * This program is free software; you can redistribute it and/or *
5 : * modify it under the terms of the GNU General Public License as *
6 : * published by the Free Software Foundation; either version 2 of *
7 : * the License, or (at your option) any later version. *
8 : * *
9 : * This program is distributed in the hope that it will be useful, *
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 : * GNU General Public License for more details. *
13 : * *
14 : * You should have received a copy of the GNU General Public License*
15 : * along with this program; if not, contact: *
16 : * *
17 : * Free Software Foundation Voice: +1-617-542-5942 *
18 : * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19 : * Boston, MA 02110-1301, USA gnu@gnu.org *
20 : \********************************************************************/
21 : /** @file gnc-slots-sql.h
22 : * @brief load and save accounts data to SQL
23 : * @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
24 : *
25 : * This file implements the top-level QofBackend API for saving/
26 : * restoring data to/from an SQL database
27 : */
28 :
29 : #ifndef GNC_SLOTS_SQL_H
30 : #define GNC_SLOTS_SQL_H
31 :
32 : #include <glib.h>
33 : #include "guid.h"
34 : #include "qof.h"
35 : #include "gnc-sql-object-backend.hpp"
36 :
37 : /**
38 : * Slots are neither loadable nor committable. Note that the default
39 : * write() implementation is also a no-op.
40 : */
41 : class GncSqlSlotsBackend : public GncSqlObjectBackend
42 : {
43 : public:
44 : GncSqlSlotsBackend();
45 0 : void load_all(GncSqlBackend*) override { return; }
46 : void create_tables(GncSqlBackend*) override;
47 0 : bool commit(GncSqlBackend*, QofInstance*) override { return false; }
48 : };
49 :
50 : /**
51 : * gnc_sql_slots_save - Saves slots for an object to the db.
52 : *
53 : * @param sql_be SQL backend
54 : * @param guid Object guid
55 : * @param is_infant Is this an infant object?
56 : * @param inst The QodInstance owning the slots.
57 : * @return TRUE if successful, FALSE if error
58 : */
59 : gboolean gnc_sql_slots_save (GncSqlBackend* sql_be, const GncGUID* guid,
60 : gboolean is_infant, QofInstance* inst);
61 :
62 : /**
63 : * gnc_sql_slots_delete - Deletes slots for an object from the db.
64 : *
65 : * @param sql_be SQL backend
66 : * @param guid Object guid
67 : * @return TRUE if successful, FALSE if error
68 : */
69 : gboolean gnc_sql_slots_delete (GncSqlBackend* sql_be, const GncGUID* guid);
70 :
71 : /** Loads slots for an object from the db.
72 : *
73 : * @param sql_be SQL backend
74 : */
75 : void gnc_sql_slots_load (GncSqlBackend* sql_be, QofInstance* inst);
76 :
77 : typedef QofInstance* (*BookLookupFn) (const GncGUID* guid,
78 : const QofBook* book);
79 :
80 : /**
81 : * gnc_sql_slots_load_for_sql_subquery - Loads slots for all objects whose guid is
82 : * supplied by a subquery. The subquery should be of the form "SELECT DISTINCT guid FROM ...".
83 : * This is faster than loading for one object at a time because fewer SQL queries * are used.
84 : *
85 : * @param sql_be SQL backend
86 : * @param subquery Subquery SQL string
87 : * @param lookup_fn Lookup function to get the right object from the book
88 : */
89 : void gnc_sql_slots_load_for_sql_subquery (GncSqlBackend* sql_be,
90 : const std::string subquery,
91 : BookLookupFn lookup_fn);
92 :
93 : void gnc_sql_init_slots_handler (void);
94 :
95 : #endif /* GNC_SLOTS_SQL_H */
|