mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Merge gda-dev2 branch into trunk.
This introduces the dbi backend and the --enable-dbi configure option. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17444 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
8bc6249efb
commit
9173035d57
25
DBI_STATUS
Normal file
25
DBI_STATUS
Normal file
@ -0,0 +1,25 @@
|
||||
Status of the DBI backend.
|
||||
|
||||
Code for all standard and business objects has been written. The following
|
||||
bugs/issues are known.
|
||||
|
||||
* Initial save performance is better than it used to be, but is still slow.
|
||||
For example, saving my file with ~8000 transactions and ~21000 splits takes
|
||||
13 minutes to an sqlite db.
|
||||
* Foreign key definitions should be used for referential integrity.
|
||||
* (Maybe) Keep an 'old values' table for each main table. When a record is
|
||||
updated, copy the old record to the 'old values' table first to keep track of
|
||||
any changes.
|
||||
* Use prepared statements
|
||||
* Use cursor-based data models when reading from the db for better performance
|
||||
* Write automated tests
|
||||
* Write doxygen comment headers
|
||||
* Don't need a log file
|
||||
* Certain dialogs create an object when opened and update it as they go along.
|
||||
This can result in trying to save invalid objects:
|
||||
- Price editor (new price has no commodity or currency)
|
||||
- New invoice
|
||||
* Need transactions to group updates to multiple objects
|
||||
* Possibly mark commodities that are in the db so that they don't need to be
|
||||
queried every time.
|
||||
* The sqlite db file is *much* larger than the gzipped XML file.
|
149
configure.in
149
configure.in
@ -604,6 +604,55 @@ AC_SUBST(QOF_PREFIX)
|
||||
AC_SUBST(QOF_LIB_DIR)
|
||||
AC_SUBST(QOF_XML_DIR)
|
||||
|
||||
AC_DEFINE(QOF_DISABLE_DEPRECATED,1, [Don't use deprecated qof functions])
|
||||
|
||||
### -----------------------
|
||||
### LIBGDA
|
||||
#AC_ARG_ENABLE(gda,
|
||||
# [AS_HELP_STRING([--enable-gda],[build with the libgda backend])],
|
||||
# [case "${enableval}" in
|
||||
# yes) want_gda=true ;;
|
||||
# no) want_gda=false ;;
|
||||
# *) want_gda=false ;;
|
||||
# esac],
|
||||
# [want_gda=false])
|
||||
#if test x${want_gda} = xtrue
|
||||
#then
|
||||
# PKG_CHECK_MODULES(LIBGDA, libgda-4.0 >= 3.99.2, [GDA_DIR=gda])
|
||||
#fi
|
||||
#AC_SUBST(GDA_DIR)
|
||||
#AC_SUBST(LIBGDA_CFLAGS)
|
||||
#AC_SUBST(LIBGDA_LIBS)
|
||||
|
||||
### ----------------------
|
||||
### LIBDBI
|
||||
AC_ARG_ENABLE(dbi,
|
||||
[AS_HELP_STRING([--enable-dbi],[build with the libdbi backend])],
|
||||
[case "${enableval}" in
|
||||
yes) want_dbi=true ;;
|
||||
no) want_dbi=false ;;
|
||||
*) want_dbi=false ;;
|
||||
esac],
|
||||
[want_dbi=false])
|
||||
if test x${want_dbi} = xtrue
|
||||
then
|
||||
AC_CHECK_HEADERS(dbi/dbi.h)
|
||||
if test "x$ac_cv_header_dbi_dbi_h" != xno; then
|
||||
AC_ARG_WITH( dbi-dbd-dir,
|
||||
[AS_HELP_STRING([--with-dbi-dbd-dir=PATH],[specify location of libdbi drivers @<:@default=/usr/lib/dbd@:>@])],
|
||||
GNC_DBD_DIR="$with_dbi_dbd_dir",
|
||||
GNC_DBD_DIR="/usr/lib/dbd")
|
||||
|
||||
LIBDBI_LIBS=-ldbi
|
||||
DBI_DIR=dbi
|
||||
else
|
||||
AC_MSG_ERROR( Unable to find dbi/dbi.h )
|
||||
fi
|
||||
fi
|
||||
AC_SUBST(LIBDBI_LIBS)
|
||||
AC_SUBST(DBI_DIR)
|
||||
AC_SUBST(GNC_DBD_DIR)
|
||||
|
||||
### --------------------------------------------------------------------------
|
||||
### Variables
|
||||
### Set up all the initial variable values...
|
||||
@ -653,94 +702,6 @@ AC_ARG_ENABLE( ref-counts-dumps,
|
||||
AC_DEFINE(DEBUG_REFERENCE_COUNTING,0,Enable reference count dumps) )
|
||||
|
||||
|
||||
### --------------------------------------------------------------------------
|
||||
### SQL
|
||||
# Check to see if the user wants to have Postgres support
|
||||
#
|
||||
# hack alert ... we should use 'pg_config --includedir' and
|
||||
# 'pg_config --libdir' to find paths; unfortunately pg_config itself
|
||||
# is hard to find :-(
|
||||
|
||||
AC_ARG_ENABLE( sql,
|
||||
[ --enable-sql compile with sql support],
|
||||
[
|
||||
PG_CONFIG=`which pg_config`
|
||||
|
||||
if test "x$PG_CONFIG" = "x" ; then
|
||||
PG_CONFIG="/usr/lib/postgresql/bin/pg_config"
|
||||
fi
|
||||
|
||||
if test "x$enableval" != "xno" ; then
|
||||
|
||||
PGSQL_CFLAGS=`${PG_CONFIG} --includedir`
|
||||
if test "x$PGSQL_CFLAGS" != x; then
|
||||
PGSQL_CFLAGS="-I${PGSQL_CFLAGS}"
|
||||
fi
|
||||
|
||||
AS_SCRUB_INCLUDE(PGSQL_CFLAGS)
|
||||
# XXX Fixme: CPPFLAGS are saved but CFLAGS are altered later on and not restored.
|
||||
saved_CPPFLAGS="${CPPFLAGS}"
|
||||
saved_CFLAGS="${CFLAGS}"
|
||||
CPPFLAGS="${CPPFLAGS} ${PGSQL_CFLAGS}"
|
||||
AC_CHECK_HEADERS(pgsql/libpq-fe.h postgresql/libpq-fe.h libpq-fe.h)
|
||||
if test "x$ac_cv_header_pgsql_libpq_fe_h$ac_cv_header_postgresql_libpq_fe_h$ac_cv_header_libpq_fe_h" = xnonono; then
|
||||
AC_MSG_ERROR([Cannot find PostgreSQL headers; won't build sql backend])
|
||||
else
|
||||
master_dirs="/usr/include /usr/local/include"
|
||||
if test "x$ac_cv_header_pgsql_libpq_fe_h" != xno; then
|
||||
for dir in $master_dirs; do
|
||||
if test -f "$dir/pgsql/libpq-fe.h"; then
|
||||
CFLAGS="${CFLAGS} -I$dir/pgsql"
|
||||
break
|
||||
fi
|
||||
done
|
||||
elif test "x$ac_cv_header_postgresql_libpq_fe_h" != xno; then
|
||||
for dir in $master_dirs; do
|
||||
if test -f "$dir/postgresql/libpq-fe.h"; then
|
||||
CFLAGS="${CFLAGS} -I$dir/postgresql"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
AS_SCRUB_INCLUDE(CFLAGS)
|
||||
|
||||
PGSQL_LIBS=`${PG_CONFIG} --libdir`
|
||||
if test "x$PGSQL_LIBS" != x; then
|
||||
PGSQL_LIBS="-L${PGSQL_LIBS}"
|
||||
fi
|
||||
|
||||
saved_LIBS="$LIBS"
|
||||
LIBS="${PGSQL_LIBS} -lpq $LIBS"
|
||||
AC_MSG_CHECKING(for libpq)
|
||||
AC_TRY_LINK(
|
||||
[
|
||||
#include <libpq-fe.h>
|
||||
],
|
||||
[
|
||||
PQconnectdb("asdf");
|
||||
],
|
||||
[
|
||||
AC_MSG_RESULT(yes)
|
||||
SQL_DIR=postgres
|
||||
],
|
||||
[
|
||||
AC_MSG_ERROR([Cannot find PostgreSQL libraries; will not build sql backend])
|
||||
]
|
||||
)
|
||||
LIBS="$saved_LIBS"
|
||||
fi
|
||||
CPPFLAGS="$saved_CPPFLAGS"
|
||||
CFLAGS="$saved_CFLAGS"
|
||||
fi
|
||||
]
|
||||
)
|
||||
|
||||
AC_SUBST(PGSQL_CFLAGS)
|
||||
AC_SUBST(PGSQL_LIBS)
|
||||
AC_SUBST(SQL_DIR)
|
||||
|
||||
|
||||
### --------------------------------------------------------------------------
|
||||
### RPC has been removed in gnucash 1.9.0
|
||||
|
||||
@ -1497,12 +1458,16 @@ AC_CONFIG_FILES(po/Makefile.in
|
||||
src/app-utils/Makefile
|
||||
src/app-utils/test/Makefile
|
||||
src/backend/Makefile
|
||||
src/backend/dbi/Makefile
|
||||
src/backend/dbi/test/Makefile
|
||||
src/backend/file/Makefile
|
||||
src/backend/file/test/Makefile
|
||||
src/backend/file/test/test-files/Makefile
|
||||
src/backend/file/test/test-files/xml2/Makefile
|
||||
src/backend/postgres/Makefile
|
||||
src/backend/postgres/test/Makefile
|
||||
src/backend/sql/Makefile
|
||||
src/backend/sql/test/Makefile
|
||||
src/bin/Makefile
|
||||
src/bin/overrides/Makefile
|
||||
src/bin/test/Makefile
|
||||
@ -1587,6 +1552,7 @@ AC_CONFIG_FILES(po/Makefile.in
|
||||
src/test-core/Makefile
|
||||
src/business/Makefile
|
||||
src/business/business-core/Makefile
|
||||
src/business/business-core/sql/Makefile
|
||||
src/business/business-core/test/Makefile
|
||||
src/business/business-core/file/Makefile
|
||||
src/business/business-utils/Makefile
|
||||
@ -1611,8 +1577,11 @@ output_qof_prefix=`eval eval eval echo $QOF_PREFIX`
|
||||
output_qof_lib_dir=`eval eval eval echo $QOF_LIB_DIR`
|
||||
output_qof_xml_dir=`eval eval eval echo $QOF_XML_DIR`
|
||||
|
||||
if test x${SQL_DIR} != x; then
|
||||
components="$components sql"
|
||||
if test x${DBI_DIR} != x; then
|
||||
components="$components dbi"
|
||||
fi
|
||||
if test x${GDA_DIR} != x; then
|
||||
components="$components gda"
|
||||
fi
|
||||
if test x${OFX_DIR} != x; then
|
||||
components="$components ofx"
|
||||
|
@ -1052,7 +1052,7 @@ gnc_iso8601_to_timespec_gmt(const char *str)
|
||||
|
||||
/* Timezone format can be +hh or +hhmm or +hh.mm (or -) (or not present) */
|
||||
str += strcspn (str, "+-");
|
||||
if (str)
|
||||
if (*str)
|
||||
{
|
||||
buf[0] = str[0];
|
||||
buf[1] = str[1];
|
||||
|
@ -970,11 +970,11 @@ qof_commit_edit_part2(QofInstance *inst,
|
||||
/* XXX the backend commit code should clear dirty!! */
|
||||
priv->dirty = FALSE;
|
||||
}
|
||||
if (dirty && qof_get_alt_dirty_mode() &&
|
||||
!(priv->infant && priv->do_free)) {
|
||||
qof_collection_mark_dirty(priv->collection);
|
||||
qof_book_mark_dirty(priv->book);
|
||||
}
|
||||
// if (dirty && qof_get_alt_dirty_mode() &&
|
||||
// !(priv->infant && priv->do_free)) {
|
||||
// qof_collection_mark_dirty(priv->collection);
|
||||
// qof_book_mark_dirty(priv->book);
|
||||
// }
|
||||
priv->infant = FALSE;
|
||||
|
||||
if (priv->do_free) {
|
||||
|
@ -63,6 +63,20 @@ qof_backend_register_provider (QofBackendProvider *prov)
|
||||
provider_list = g_slist_append (provider_list, prov);
|
||||
}
|
||||
|
||||
GList*
|
||||
qof_backend_get_registered_access_method_list(void)
|
||||
{
|
||||
GList* list = NULL;
|
||||
GSList* node;
|
||||
|
||||
for( node = provider_list; node != NULL; node = node->next ) {
|
||||
QofBackendProvider *prov = node->data;
|
||||
list = g_list_append( list, (gchar*)prov->access_method );
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
/* hook routines */
|
||||
|
@ -436,5 +436,10 @@ gboolean qof_session_export (QofSession *tmp_session,
|
||||
QofSession *real_session,
|
||||
QofPercentageFunc percentage_func);
|
||||
|
||||
/** Return a list of strings for the registered access methods. The owner is
|
||||
* responsible for freeing the list but not the strings.
|
||||
*/
|
||||
GList* qof_backend_get_registered_access_method_list(void);
|
||||
|
||||
#endif /* QOF_SESSION_H */
|
||||
/** @} */
|
||||
|
@ -9,6 +9,8 @@ EXTRA_DIST = \
|
||||
install-fq-mods.bat \
|
||||
libofx-0.8.3-patch.diff \
|
||||
opensp-1.5.2-patch.diff \
|
||||
libgda-3.1.2-patch.diff \
|
||||
libgda-3.1.2-patch2.diff \
|
||||
pi.sh \
|
||||
Greek-4-5.1.11.isl \
|
||||
reset.sh
|
||||
|
@ -262,6 +262,11 @@ set_default AQBANKING_WITH_QT yes
|
||||
# If set to yes, download Qt from http://www.trolltech.com/developer/downloads/qt/windows,
|
||||
# install it and set QTDIR in custom.sh, like "QTDIR=/c/Qt/4.2.3".
|
||||
|
||||
set_default LIBGDA_URL "http://ftp.acc.umu.se/pub/GNOME/sources/libgda/3.1/libgda-3.1.2.tar.gz"
|
||||
set_default LIBGDA_DIR $GLOBAL_DIR\\libgda
|
||||
set_default LIBGDA_PATCH `pwd`/libgda-3.1.2-patch.diff
|
||||
set_default LIBGDA_PATCH2 `pwd`/libgda-3.1.2-patch2.diff
|
||||
|
||||
set_default DOCBOOK_XSL_URL "$SF_MIRROR/docbook/docbook-xsl-1.72.0.zip"
|
||||
set_default UPDATE_DOCS yes
|
||||
set_default DOCS_REV "HEAD"
|
||||
@ -305,6 +310,7 @@ add_step inst_libofx
|
||||
add_step inst_gwenhywfar
|
||||
add_step inst_ktoblzcheck
|
||||
add_step inst_aqbanking
|
||||
add_step inst_libgda
|
||||
##
|
||||
if [ "$CROSS_COMPILE" != "yes" ]; then
|
||||
add_step inst_inno
|
||||
|
@ -34,6 +34,7 @@ function prepare() {
|
||||
_LIBOFX_UDIR=`unix_path $LIBOFX_DIR`
|
||||
_GWENHYWFAR_UDIR=`unix_path $GWENHYWFAR_DIR`
|
||||
_AQBANKING_UDIR=`unix_path $AQBANKING_DIR`
|
||||
_LIBGDA_UDIR=`unix_path $LIBGDA_DIR`
|
||||
_GNUCASH_UDIR=`unix_path $GNUCASH_DIR`
|
||||
_REPOS_UDIR=`unix_path $REPOS_DIR`
|
||||
_BUILD_UDIR=`unix_path $BUILD_DIR`
|
||||
@ -171,6 +172,14 @@ function dist_aqbanking() {
|
||||
cp -a ${_AQBANKING_UDIR}/share/locale ${DIST_UDIR}/lib
|
||||
}
|
||||
|
||||
function dist_libgda() {
|
||||
setup Libgda
|
||||
cp -a ${_LIBGDA_UDIR}/bin/* ${DIST_UDIR}/bin
|
||||
cp -a ${_LIBGDA_UDIR}/lib/libgda-3.0 ${DIST_UDIR}/lib
|
||||
cp -a ${_LIBGDA_UDIR}/share/libgda-3.0 ${DIST_UDIR}/share
|
||||
cp -a ${_LIBGDA_UDIR}/share/locale ${DIST_UDIR}/lib
|
||||
}
|
||||
|
||||
function dist_gnucash() {
|
||||
setup GnuCash
|
||||
mkdir -p $DIST_UDIR/bin
|
||||
@ -245,6 +254,7 @@ dist_goffice
|
||||
dist_libofx
|
||||
dist_gwenhywfar
|
||||
dist_aqbanking
|
||||
dist_libgda
|
||||
dist_gnucash
|
||||
finish
|
||||
qpopd
|
||||
|
@ -929,6 +929,33 @@ function inst_aqbanking() {
|
||||
fi
|
||||
}
|
||||
|
||||
function inst_libgda() {
|
||||
setup LibGDA
|
||||
_LIBGDA_UDIR=`unix_path ${LIBGDA_DIR}`
|
||||
add_to_env ${_LIBGDA_UDIR}/bin PATH
|
||||
add_to_env ${_LIBGDA_UDIR}/lib/pkgconfig PKG_CONFIG_PATH
|
||||
if quiet ${PKG_CONFIG} --exists libgda-3.0
|
||||
then
|
||||
echo "Libgda already installed. skipping."
|
||||
else
|
||||
wget_unpacked $LIBGDA_URL $DOWNLOAD_DIR $TMP_DIR
|
||||
assert_one_dir $TMP_UDIR/libgda-*
|
||||
qpushd $TMP_UDIR/libgda-*
|
||||
#patch to ignore vfs, as libgda uses depriciated header
|
||||
patch libgda/gda-data-model-dir.c $LIBGDA_PATCH
|
||||
#patch to use g_setenv instead of setenv (bug #510739)
|
||||
patch tools/gda-sql.c $LIBGDA_PATCH2
|
||||
./configure \
|
||||
--prefix=${_LIBGDA_UDIR} \
|
||||
CPPFLAGS="${REGEX_CPPFLAGS} ${GNOME_CPPFLAGS}" \
|
||||
LDFLAGS="${REGEX_LDFLAGS} ${GNOME_LDFLAGS} -lintl"
|
||||
make
|
||||
make install
|
||||
qpopd
|
||||
${PKG_CONFIG} --exists libgda-3.0 || die "Libgda not installed correctly"
|
||||
fi
|
||||
}
|
||||
|
||||
function svn_up() {
|
||||
mkdir -p $_REPOS_UDIR
|
||||
qpushd $REPOS_DIR
|
||||
@ -992,7 +1019,7 @@ function inst_gnucash() {
|
||||
qpushd src/bin
|
||||
rm gnucash
|
||||
make PATH_SEPARATOR=";" \
|
||||
bindir="${_INSTALL_UDIR}/bin:${_INSTALL_UDIR}/lib:${_INSTALL_UDIR}/lib/gnucash:${_GOFFICE_UDIR}/bin:${_LIBGSF_UDIR}/bin:${_PCRE_UDIR}/bin:${_GNOME_UDIR}/bin:${_LIBXML2_UDIR}/bin:${_GUILE_UDIR}/bin:${_REGEX_UDIR}/bin:${_AUTOTOOLS_UDIR}/bin:${AQBANKING_UPATH}:${_LIBOFX_UDIR}/bin:${_OPENSP_UDIR}/bin" \
|
||||
bindir="${_INSTALL_UDIR}/bin:${_INSTALL_UDIR}/lib:${_INSTALL_UDIR}/lib/gnucash:${_GOFFICE_UDIR}/bin:${_LIBGSF_UDIR}/bin:${_PCRE_UDIR}/bin:${_GNOME_UDIR}/bin:${_LIBXML2_UDIR}/bin:${_GUILE_UDIR}/bin:${_REGEX_UDIR}/bin:${_AUTOTOOLS_UDIR}/bin:${AQBANKING_UPATH}:${_LIBOFX_UDIR}/bin:${_OPENSP_UDIR}/bin:${LIBGDA_DIR}/bin" \
|
||||
gnucash
|
||||
qpopd
|
||||
|
||||
@ -1035,7 +1062,7 @@ function make_install() {
|
||||
# Create a startup script that works without the msys shell
|
||||
qpushd $_INSTALL_UDIR/bin
|
||||
echo "setlocal" > gnucash.bat
|
||||
echo "set PATH=${INSTALL_DIR}\\bin;${INSTALL_DIR}\\lib;${INSTALL_DIR}\\lib\\gnucash;${GOFFICE_DIR}\\bin;${LIBGSF_DIR}\\bin;${PCRE_DIR}\\bin;${GNOME_DIR}\\bin;${LIBXML2_DIR}\\bin;${GUILE_DIR}\\bin;${REGEX_DIR}\\bin;${AUTOTOOLS_DIR}\\bin;${AQBANKING_PATH};${LIBOFX_DIR}\\bin;${OPENSP_DIR}\\bin;%PATH%" >> gnucash.bat
|
||||
echo "set PATH=${INSTALL_DIR}\\bin;${INSTALL_DIR}\\lib;${INSTALL_DIR}\\lib\\gnucash;${GOFFICE_DIR}\\bin;${LIBGSF_DIR}\\bin;${PCRE_DIR}\\bin;${GNOME_DIR}\\bin;${LIBXML2_DIR}\\bin;${GUILE_DIR}\\bin;${REGEX_DIR}\\bin;${AUTOTOOLS_DIR}\\bin;${AQBANKING_PATH};${LIBOFX_DIR}\\bin;${OPENSP_DIR}\\bin;${LIBGDA_DIR}\\bin;%PATH%" > gnucash.bat
|
||||
echo "set GUILE_WARN_DEPRECATED=no" >> gnucash.bat
|
||||
echo "set GNC_MODULE_PATH=${INSTALL_DIR}\\lib\\gnucash" >> gnucash.bat
|
||||
echo "set GUILE_LOAD_PATH=${INSTALL_DIR}\\share\\gnucash\\guile-modules;${INSTALL_DIR}\\share\\gnucash\\scm;%GUILE_LOAD_PATH%" >> gnucash.bat
|
||||
|
4
packaging/win32/libgda-3.1.2-patch.diff
Normal file
4
packaging/win32/libgda-3.1.2-patch.diff
Normal file
@ -0,0 +1,4 @@
|
||||
31c31
|
||||
< #include <libgnomevfs/gnome-vfs-mime.h>
|
||||
---
|
||||
> #undef HAVE_GNOMEVFS
|
6
packaging/win32/libgda-3.1.2-patch2.diff
Normal file
6
packaging/win32/libgda-3.1.2-patch2.diff
Normal file
@ -0,0 +1,6 @@
|
||||
880,881c880,881
|
||||
< setenv ("GDA_DATA_MODEL_DUMP_TITLE", "Yes", TRUE);
|
||||
< setenv ("GDA_DATA_MODEL_NULL_AS_EMPTY", "Yes", TRUE);
|
||||
---
|
||||
> g_setenv ("GDA_DATA_MODEL_DUMP_TITLE", "Yes", TRUE);
|
||||
> g_setenv ("GDA_DATA_MODEL_NULL_AS_EMPTY", "Yes", TRUE);
|
@ -1,3 +1,3 @@
|
||||
|
||||
SUBDIRS = file ${SQL_DIR}
|
||||
DIST_SUBDIRS = file postgres
|
||||
SUBDIRS = file sql ${SQL_DIR} ${GDA_DIR} ${DBI_DIR}
|
||||
DIST_SUBDIRS = file sql ${SQL_DIR} ${GDA_DIR} ${DBI_DIR}
|
||||
|
34
src/backend/dbi/Makefile.am
Normal file
34
src/backend/dbi/Makefile.am
Normal file
@ -0,0 +1,34 @@
|
||||
SUBDIRS = . test
|
||||
|
||||
# Now a shared library AND a GModule
|
||||
pkglib_LTLIBRARIES = libgncmod-backend-dbi.la
|
||||
|
||||
|
||||
AM_CFLAGS = \
|
||||
-I.. -I../.. \
|
||||
-DLOCALE_DIR=\""$(datadir)/locale"\" \
|
||||
-I${top_srcdir}/src/backend \
|
||||
-I${top_srcdir}/src/backend/sql \
|
||||
-I${top_srcdir}/src/engine \
|
||||
-I${top_srcdir}/src/core-utils\
|
||||
-I${top_srcdir}/lib/libc\
|
||||
${QOF_CFLAGS} \
|
||||
${GLIB_CFLAGS} \
|
||||
${GCONF_CFLAGS} \
|
||||
${WARN_CFLAGS}
|
||||
|
||||
libgncmod_backend_dbi_la_SOURCES = \
|
||||
gnc-backend-dbi.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
gnc-backend-dbi.h
|
||||
|
||||
libgncmod_backend_dbi_la_LDFLAGS = -module -avoid-version
|
||||
libgncmod_backend_dbi_la_LIBADD = \
|
||||
${GLIB_LIBS} ${GCONF_LIBS} \
|
||||
${top_builddir}/src/backend/sql/libgnc-backend-sql.la \
|
||||
${top_builddir}/src/engine/libgncmod-engine.la \
|
||||
${LIBDBI_LIBS} \
|
||||
${QOF_LIBS}
|
||||
|
||||
INCLUDES = -DG_LOG_DOMAIN=\"gnc.backend.dbi\"
|
1168
src/backend/dbi/gnc-backend-dbi.c
Normal file
1168
src/backend/dbi/gnc-backend-dbi.c
Normal file
File diff suppressed because it is too large
Load Diff
37
src/backend/dbi/gnc-backend-dbi.h
Normal file
37
src/backend/dbi/gnc-backend-dbi.h
Normal file
@ -0,0 +1,37 @@
|
||||
/********************************************************************
|
||||
* gnc-backend-dbi.h: load and save data to SQL via libdbi *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-backend-dbi.h
|
||||
* @brief load and save data to SQL via libdbi
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database via libdbi
|
||||
*/
|
||||
|
||||
#ifndef GNC_BACKEND_DBI_H_
|
||||
#define GNC_BACKEND_DBI_H_
|
||||
|
||||
#include <gmodule.h>
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
qof_backend_module_init(void);
|
||||
|
||||
#endif /* GNC_BACKEND_DBI_H_ */
|
63
src/backend/dbi/gncmod-backend-dbi.c
Normal file
63
src/backend/dbi/gncmod-backend-dbi.c
Normal file
@ -0,0 +1,63 @@
|
||||
/*********************************************************************
|
||||
* gncmod-backend-dbi.c
|
||||
* module definition/initialization for the dbi backend module
|
||||
*
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <gmodule.h>
|
||||
/* #include <glib-gobject.h> */
|
||||
|
||||
#include "gnc-module.h"
|
||||
#include "gnc-module-api.h"
|
||||
|
||||
/* version of the gnc module system interface we require */
|
||||
int gnc_module_system_interface = 0;
|
||||
|
||||
/* module versioning uses libtool semantics. */
|
||||
int gnc_module_current = 0;
|
||||
int gnc_module_revision = 0;
|
||||
int gnc_module_age = 0;
|
||||
|
||||
static GNCModule engine;
|
||||
|
||||
gchar *
|
||||
gnc_module_path(void)
|
||||
{
|
||||
return g_strdup("gnucash/backend/dbi");
|
||||
}
|
||||
|
||||
gchar *
|
||||
gnc_module_description(void)
|
||||
{
|
||||
return g_strdup("The DBI/SQL backend for GnuCash");
|
||||
}
|
||||
|
||||
int
|
||||
gnc_module_init(int refcount)
|
||||
{
|
||||
engine = gnc_module_load("gnucash/engine", 0);
|
||||
if(!engine) return FALSE;
|
||||
|
||||
/* Need to initialize g-type engine for gconf */
|
||||
if (refcount == 0) {
|
||||
g_type_init();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
gnc_module_end(int refcount)
|
||||
{
|
||||
int unload = TRUE;
|
||||
|
||||
if (engine)
|
||||
unload = gnc_module_unload(engine);
|
||||
|
||||
if (refcount == 0)
|
||||
engine = NULL;
|
||||
|
||||
return unload;
|
||||
}
|
50
src/backend/dbi/test/Makefile.am
Normal file
50
src/backend/dbi/test/Makefile.am
Normal file
@ -0,0 +1,50 @@
|
||||
SUBDIRS = .
|
||||
|
||||
TESTS = \
|
||||
test-load-backend \
|
||||
test-dbi-account
|
||||
|
||||
GNC_TEST_DEPS := \
|
||||
--gnc-module-dir ${top_builddir}/src/engine \
|
||||
--guile-load-dir ${top_builddir}/src/engine \
|
||||
--library-dir ${top_builddir}/lib/libqof/qof \
|
||||
--library-dir ${top_builddir}/src/core-utils \
|
||||
--library-dir ${top_builddir}/src/gnc-module \
|
||||
--library-dir ${top_builddir}/src/engine \
|
||||
--library-dir ${top_builddir}/src/backend/gda
|
||||
|
||||
TESTS_ENVIRONMENT := \
|
||||
GNC_ACCOUNT_PATH=${top_srcdir}/accounts/C \
|
||||
SRCDIR=${srcdir} \
|
||||
$(shell ${top_srcdir}/src/gnc-test-env --no-exports ${GNC_TEST_DEPS})
|
||||
|
||||
check_PROGRAMS = \
|
||||
test-load-backend \
|
||||
test-dbi-account
|
||||
|
||||
#noinst_HEADERS = test-file-stuff.h
|
||||
|
||||
LDADD = ${top_builddir}/src/test-core/libgncmod-test.la \
|
||||
${top_builddir}/src/gnc-module/libgnc-module.la \
|
||||
${top_builddir}/src/engine/libgncmod-engine.la \
|
||||
${top_builddir}/src/engine/test-core/libgncmod-test-engine.la \
|
||||
${top_builddir}/src/core-utils/libgnc-core-utils.la \
|
||||
${QOF_LIBS} \
|
||||
${top_builddir}/lib/libc/libc-missing.la
|
||||
|
||||
AM_CFLAGS = \
|
||||
-I${top_srcdir}/lib/libc \
|
||||
-I${top_srcdir}/src \
|
||||
-I${top_srcdir}/src/core-utils \
|
||||
-I${top_srcdir}/src/gnc-module \
|
||||
-I${top_srcdir}/src/test-core \
|
||||
-I${top_srcdir}/src/engine \
|
||||
-I${top_srcdir}/src/engine/test-core \
|
||||
-I${top_srcdir}/src/backend/gda \
|
||||
-I${top_srcdir}/src/backend/qsf \
|
||||
${GLIB_CFLAGS} \
|
||||
${QOF_CFLAGS} \
|
||||
${GUILE_INCS} \
|
||||
${GCONF_CFLAGS}
|
||||
|
||||
INCLUDES = -DG_LOG_DOMAIN=\"gnc.backend.dbi\"
|
45
src/backend/dbi/test/test-load-backend.c
Normal file
45
src/backend/dbi/test/test-load-backend.c
Normal file
@ -0,0 +1,45 @@
|
||||
/***************************************************************************
|
||||
* test-load-backend.c
|
||||
*
|
||||
* Replaces the guile version to test the GModule file backend loading.
|
||||
*
|
||||
* Sun Oct 9 18:58:47 2005
|
||||
* Copyright 2005 Neil Williams
|
||||
* linux@codehelp.co.uk
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "qof.h"
|
||||
#include "cashobjects.h"
|
||||
#include "test-stuff.h"
|
||||
|
||||
#define GNC_LIB_NAME "gncmod-backend-dbi"
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
qof_init();
|
||||
cashobjects_register();
|
||||
do_test(
|
||||
qof_load_backend_library ("../.libs/", GNC_LIB_NAME),
|
||||
" loading gnc-backend-dbi GModule failed");
|
||||
print_test_results();
|
||||
qof_close();
|
||||
exit(get_rv());
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
SUBDIRS = . test
|
||||
|
||||
# Now a shared library AND a GModule
|
||||
lib_LTLIBRARIES = libgnc-backend-file-utils.la
|
||||
pkglib_LTLIBRARIES = libgncmod-backend-file.la
|
||||
lib_LTLIBRARIES = libgnc-backend-xml-utils.la
|
||||
pkglib_LTLIBRARIES = libgncmod-backend-xml.la
|
||||
|
||||
AM_CFLAGS = \
|
||||
-I.. -I../.. \
|
||||
@ -16,7 +16,7 @@ AM_CFLAGS = \
|
||||
${GLIB_CFLAGS} \
|
||||
${GCONF_CFLAGS}
|
||||
|
||||
libgnc_backend_file_utils_la_SOURCES = \
|
||||
libgnc_backend_xml_utils_la_SOURCES = \
|
||||
gnc-account-xml-v2.c \
|
||||
gnc-book-xml-v2.c \
|
||||
gnc-budget-xml-v2.c \
|
||||
@ -39,7 +39,7 @@ libgnc_backend_file_utils_la_SOURCES = \
|
||||
sixtp-utils.c \
|
||||
sixtp.c
|
||||
|
||||
libgncmod_backend_file_la_SOURCES = \
|
||||
libgncmod_backend_xml_la_SOURCES = \
|
||||
gnc-backend-file.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
@ -58,18 +58,18 @@ noinst_HEADERS = \
|
||||
sixtp-stack.h \
|
||||
sixtp-utils.h
|
||||
|
||||
libgnc_backend_file_utils_la_LIBADD = \
|
||||
libgnc_backend_xml_utils_la_LIBADD = \
|
||||
${GLIB_LIBS} ${GCONF_LIBS} ${LIBXML2_LIBS} \
|
||||
${top_builddir}/src/engine/libgncmod-engine.la \
|
||||
${top_builddir}/src/core-utils/libgnc-core-utils.la \
|
||||
${QOF_LIBS}
|
||||
|
||||
libgncmod_backend_file_la_LDFLAGS = -module -avoid-version
|
||||
libgncmod_backend_file_la_LIBADD = \
|
||||
libgncmod_backend_xml_la_LDFLAGS = -module -avoid-version
|
||||
libgncmod_backend_xml_la_LIBADD = \
|
||||
${GLIB_LIBS} ${GCONF_LIBS} ${LIBXML2_LIBS} \
|
||||
${top_builddir}/src/engine/libgncmod-engine.la \
|
||||
${top_builddir}/src/core-utils/libgnc-core-utils.la \
|
||||
libgnc-backend-file-utils.la \
|
||||
libgnc-backend-xml-utils.la \
|
||||
${QOF_LIBS}
|
||||
|
||||
INCLUDES = -DG_LOG_DOMAIN=\"gnc.backend.file\"
|
||||
INCLUDES = -DG_LOG_DOMAIN=\"gnc.backend.xml\"
|
||||
|
@ -219,7 +219,8 @@ account_commodity_handler (xmlNodePtr node, gpointer act_pdata)
|
||||
struct account_pdata *pdata = act_pdata;
|
||||
gnc_commodity *ref;
|
||||
|
||||
ref = dom_tree_to_commodity_ref_no_engine(node, pdata->book);
|
||||
// ref = dom_tree_to_commodity_ref_no_engine(node, pdata->book);
|
||||
ref = dom_tree_to_commodity_ref(node, pdata->book);
|
||||
xaccAccountSetCommodity(pdata->account, ref);
|
||||
|
||||
return TRUE;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/********************************************************************
|
||||
* gnc-backend-file.c: load and save data to files *
|
||||
* gnc-backend-xml.c: load and save data to XML files *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
@ -18,8 +18,8 @@
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-backend-file.c
|
||||
* @brief load and save data to files
|
||||
/** @file gnc-backend-xml.c
|
||||
* @brief load and save data to XML files
|
||||
* @author Copyright (c) 2000 Gnumatic Inc.
|
||||
* @author Copyright (c) 2002 Derek Atkins <warlord@MIT.EDU>
|
||||
* @author Copyright (c) 2003 Linas Vepstas <linas@linas.org>
|
||||
@ -453,6 +453,12 @@ gnc_determine_file_type (const char *path)
|
||||
FILE *t;
|
||||
|
||||
if (!path) { return FALSE; }
|
||||
|
||||
// Since this can be called with "xml:" as a prefix, remove it if it exists
|
||||
if( g_str_has_prefix( path, "xml:" ) ) {
|
||||
path += 4;
|
||||
}
|
||||
|
||||
if (0 == safe_strcmp(path, QOF_STDOUT)) { return FALSE; }
|
||||
t = g_fopen(path, "r");
|
||||
if(!t) { PINFO (" new file"); return TRUE; }
|
||||
@ -462,7 +468,7 @@ gnc_determine_file_type (const char *path)
|
||||
if (sbuf.st_size == 0) { PINFO (" empty file"); return TRUE; }
|
||||
if(gnc_is_xml_data_file_v2(path, NULL)) { return TRUE; }
|
||||
else if(gnc_is_xml_data_file(path)) { return TRUE; }
|
||||
PINFO (" %s is not a gnc file", path);
|
||||
PINFO (" %s is not a gnc XML file", path);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -854,6 +860,11 @@ file_rollback_edit (QofBackend *be, QofInstance *inst)
|
||||
static void
|
||||
file_commit_edit (QofBackend *be, QofInstance *inst)
|
||||
{
|
||||
if (qof_instance_get_dirty(inst) && qof_get_alt_dirty_mode() &&
|
||||
!(qof_instance_get_infant(inst) && qof_instance_get_destroying(inst))) {
|
||||
qof_collection_mark_dirty(qof_instance_get_collection(inst));
|
||||
qof_book_mark_dirty(qof_instance_get_book(inst));
|
||||
}
|
||||
#if BORKEN_FOR_NOW
|
||||
FileBackend *fbe = (FileBackend *) be;
|
||||
QofBook *book = gp;
|
||||
@ -1070,6 +1081,15 @@ qof_backend_module_init(void)
|
||||
prov->provider_free = gnc_provider_free;
|
||||
prov->check_data_type = gnc_determine_file_type;
|
||||
qof_backend_register_provider (prov);
|
||||
|
||||
prov = g_new0 (QofBackendProvider, 1);
|
||||
prov->provider_name = "GnuCash File Backend Version 2";
|
||||
prov->access_method = "xml";
|
||||
prov->partial_book_supported = FALSE;
|
||||
prov->backend_new = gnc_backend_new;
|
||||
prov->provider_free = gnc_provider_free;
|
||||
prov->check_data_type = gnc_determine_file_type;
|
||||
qof_backend_register_provider (prov);
|
||||
}
|
||||
|
||||
/* ========================== END OF FILE ===================== */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/********************************************************************
|
||||
* gnc-backend-file.h: load and save data to files *
|
||||
* gnc-backend-xml.h: load and save data to XML files *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
@ -28,8 +28,8 @@
|
||||
* restoring data to/from an ordinary Unix filesystem file.
|
||||
*/
|
||||
|
||||
#ifndef GNC_BACKEND_FILE_H_
|
||||
#define GNC_BACKEND_FILE_H_
|
||||
#ifndef GNC_BACKEND_XML_H_
|
||||
#define GNC_BACKEND_XML_H_
|
||||
|
||||
#include "qof.h"
|
||||
#include <gmodule.h>
|
||||
@ -59,4 +59,4 @@ typedef struct FileBackend_struct FileBackend;
|
||||
G_MODULE_EXPORT void
|
||||
qof_backend_module_init(void);
|
||||
|
||||
#endif /* GNC_BACKEND_FILE_H_ */
|
||||
#endif /* GNC_BACKEND_XML_H_ */
|
||||
|
@ -787,6 +787,13 @@ tt_act_handler( xmlNodePtr node, gpointer data )
|
||||
pre-7/11/2001-CIT-change SX template Account was parsed [but
|
||||
incorrectly]. */
|
||||
if ( xaccAccountGetCommodity( acc ) == NULL ) {
|
||||
#if 1
|
||||
gnc_commodity_table* table;
|
||||
|
||||
table = gnc_commodity_table_get_table( txd->book );
|
||||
com = gnc_commodity_table_lookup( table,
|
||||
"template", "template" );
|
||||
#else
|
||||
/* FIXME: This should first look in the table of the
|
||||
book, maybe? The right thing happens [WRT file
|
||||
load/save] if we just _new all the time, but it
|
||||
@ -798,6 +805,7 @@ tt_act_handler( xmlNodePtr node, gpointer data )
|
||||
"template", "template",
|
||||
"template", "template",
|
||||
1 );
|
||||
#endif
|
||||
xaccAccountSetCommodity( acc, com );
|
||||
}
|
||||
|
||||
|
65
src/backend/file/gncmod-backend-xml.c
Normal file
65
src/backend/file/gncmod-backend-xml.c
Normal file
@ -0,0 +1,65 @@
|
||||
/*********************************************************************
|
||||
* gncmod-file-backend.c
|
||||
* module definition/initialization for the file backend module
|
||||
*
|
||||
* Copyright (c) 2001 Linux Developers Group, Inc.
|
||||
*********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <gmodule.h>
|
||||
/* #include <glib-gobject.h> */
|
||||
|
||||
#include "gnc-module.h"
|
||||
#include "gnc-module-api.h"
|
||||
|
||||
GNC_MODULE_API_DECL(libgncmod_backend_file)
|
||||
|
||||
/* version of the gnc module system interface we require */
|
||||
int libgnc_backend_file_utils_gnc_module_system_interface = 0;
|
||||
|
||||
/* module versioning uses libtool semantics. */
|
||||
int libgncmod_backend_file_gnc_module_current = 0;
|
||||
int libgncmod_backend_file_gnc_module_revision = 0;
|
||||
int libgncmod_backend_file_gnc_module_age = 0;
|
||||
|
||||
static GNCModule engine;
|
||||
|
||||
|
||||
char *
|
||||
libgncmod_backend_file_gnc_module_path(void)
|
||||
{
|
||||
return g_strdup("gnucash/backend/file");
|
||||
}
|
||||
|
||||
char *
|
||||
libgncmod_backend_file_gnc_module_description(void)
|
||||
{
|
||||
return g_strdup("The binary and XML (v1 and v2) backends for GnuCash");
|
||||
}
|
||||
|
||||
int
|
||||
libgncmod_backend_file_gnc_module_init(int refcount)
|
||||
{
|
||||
engine = gnc_module_load("gnucash/engine", 0);
|
||||
if(!engine) return FALSE;
|
||||
|
||||
/* Need to initialize g-type engine for gconf */
|
||||
if (refcount == 0)
|
||||
g_type_init();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
libgncmod_backend_file_gnc_module_end(int refcount)
|
||||
{
|
||||
int unload = TRUE;
|
||||
|
||||
if (engine)
|
||||
unload = libgnc_backend_file_utils_gnc_module_unload(engine);
|
||||
|
||||
if (refcount == 0)
|
||||
engine = NULL;
|
||||
|
||||
return unload;
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
#
|
||||
SUBDIRS = test-files
|
||||
|
||||
test_date_converting_SOURCES = \
|
||||
@ -27,7 +28,7 @@ test_kvp_frames_SOURCES = \
|
||||
${top_srcdir}/src/backend/file/sixtp-to-dom-parser.c \
|
||||
test-kvp-frames.c
|
||||
|
||||
# the file backend is now a GModule - this test does
|
||||
# the xml backend is now a GModule - this test does
|
||||
# not load it as a module and cannot link to it
|
||||
# and remain portable.
|
||||
|
||||
@ -249,4 +250,4 @@ EXTRA_DIST = \
|
||||
test-real-data.sh \
|
||||
test-xml2-is-file.c
|
||||
|
||||
INCLUDES = -DG_LOG_DOMAIN=\"gnc.backend.file\"
|
||||
INCLUDES = -DG_LOG_DOMAIN=\"gnc.backend.xml\"
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "cashobjects.h"
|
||||
#include "test-stuff.h"
|
||||
|
||||
#define GNC_LIB_NAME "gncmod-backend-file"
|
||||
#define GNC_LIB_NAME "gncmod-backend-xml"
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
@ -38,7 +38,7 @@ int main (int argc, char ** argv)
|
||||
cashobjects_register();
|
||||
do_test(
|
||||
qof_load_backend_library ("../.libs/", GNC_LIB_NAME),
|
||||
" loading gnc-backend-file GModule failed");
|
||||
" loading gnc-backend-xml GModule failed");
|
||||
print_test_results();
|
||||
qof_close();
|
||||
exit(get_rv());
|
||||
|
@ -47,7 +47,7 @@
|
||||
#include "test-engine-stuff.h"
|
||||
#include "test-file-stuff.h"
|
||||
|
||||
#define GNC_LIB_NAME "gncmod-backend-file"
|
||||
#define GNC_LIB_NAME "gncmod-backend-xml"
|
||||
|
||||
static void
|
||||
remove_files_pattern(const char *begining, const char *ending)
|
||||
@ -112,7 +112,7 @@ main (int argc, char ** argv)
|
||||
qof_init();
|
||||
cashobjects_register();
|
||||
do_test(qof_load_backend_library ("../.libs/", GNC_LIB_NAME),
|
||||
" loading gnc-backend-file GModule failed");
|
||||
" loading gnc-backend-xml GModule failed");
|
||||
|
||||
if (!location)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ GNC_TEST_DEPS := \
|
||||
--gnc-module-dir ${top_builddir}/src/gnc-module \
|
||||
--gnc-module-dir ${top_builddir}/src/engine \
|
||||
--guile-load-dir ${top_srcdir}/src/engine \
|
||||
--gnc-module-dir ${top_builddir}/src/backend/file \
|
||||
--gnc-module-dir ${top_builddir}/src/backend/xml \
|
||||
--gnc-module-dir ${top_builddir}/src/backend/postgres
|
||||
|
||||
TESTS_ENVIRONMENT := \
|
||||
|
50
src/backend/sql/Makefile.am
Normal file
50
src/backend/sql/Makefile.am
Normal file
@ -0,0 +1,50 @@
|
||||
SUBDIRS = . test
|
||||
|
||||
# Now a shared library AND a GModule
|
||||
lib_LTLIBRARIES = libgnc-backend-sql.la
|
||||
|
||||
AM_CFLAGS = \
|
||||
-I.. -I../.. \
|
||||
-DLOCALE_DIR=\""$(datadir)/locale"\" \
|
||||
-I${top_srcdir}/src/backend \
|
||||
-I${top_srcdir}/src/engine \
|
||||
-I${top_srcdir}/src/core-utils\
|
||||
-I${top_srcdir}/lib/libc\
|
||||
${QOF_CFLAGS} \
|
||||
${GLIB_CFLAGS} \
|
||||
${LIBGDA_CFLAGS} \
|
||||
${GCONF_CFLAGS} \
|
||||
${WARN_CFLAGS}
|
||||
|
||||
libgnc_backend_sql_la_SOURCES = \
|
||||
gnc-backend-sql.c \
|
||||
gnc-account-sql.c \
|
||||
gnc-book-sql.c \
|
||||
gnc-budget-sql.c \
|
||||
gnc-commodity-sql.c \
|
||||
gnc-lots-sql.c \
|
||||
gnc-price-sql.c \
|
||||
gnc-recurrence-sql.c \
|
||||
gnc-schedxaction-sql.c \
|
||||
gnc-slots-sql.c \
|
||||
gnc-transaction-sql.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
gnc-account-sql.h \
|
||||
gnc-backend-sql.h \
|
||||
gnc-book-sql.h \
|
||||
gnc-budget-sql.h \
|
||||
gnc-commodity-sql.h \
|
||||
gnc-lots-sql.h \
|
||||
gnc-price-sql.h \
|
||||
gnc-recurrence-sql.h \
|
||||
gnc-schedxaction-sql.h \
|
||||
gnc-slots-sql.h \
|
||||
gnc-transaction-sql.h
|
||||
|
||||
libgnc_backend_sql_la_LIBADD = \
|
||||
${GLIB_LIBS} ${GCONF_LIBS} \
|
||||
${top_builddir}/src/engine/libgncmod-engine.la \
|
||||
${QOF_LIBS}
|
||||
|
||||
INCLUDES = -DG_LOG_DOMAIN=\"gnc.backend.sql\"
|
366
src/backend/sql/gnc-account-sql.c
Normal file
366
src/backend/sql/gnc-account-sql.c
Normal file
@ -0,0 +1,366 @@
|
||||
/********************************************************************
|
||||
* gnc-account-sql.c: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-account-sql.c
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL db
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "qof.h"
|
||||
#include "Account.h"
|
||||
#include "AccountP.h"
|
||||
#include "gnc-commodity.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
|
||||
#include "gnc-account-sql.h"
|
||||
#include "gnc-commodity-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
#include "gnc-transaction-sql.h"
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define TABLE_NAME "accounts"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
static gpointer get_parent( gpointer pObject, const QofParam* );
|
||||
static void set_parent( gpointer pObject, gpointer pValue );
|
||||
static void set_parent_guid( gpointer pObject, gpointer pValue );
|
||||
|
||||
#define ACCOUNT_MAX_NAME_LEN 2048
|
||||
#define ACCOUNT_MAX_TYPE_LEN 2048
|
||||
#define ACCOUNT_MAX_CODE_LEN 2048
|
||||
#define ACCOUNT_MAX_DESCRIPTION_LEN 2048
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "name", CT_STRING, ACCOUNT_MAX_NAME_LEN, COL_NNUL, "name" },
|
||||
{ "account_type", CT_STRING, ACCOUNT_MAX_TYPE_LEN, COL_NNUL, NULL, ACCOUNT_TYPE_ },
|
||||
{ "commodity_guid", CT_COMMODITYREF, 0, COL_NNUL, "commodity" },
|
||||
{ "commodity_scu", CT_INT, 0, COL_NNUL, "commodity-scu" },
|
||||
{ "non_std_scu", CT_BOOLEAN, 0, COL_NNUL, "non-std-scu" },
|
||||
{ "parent_guid", CT_GUID, 0, 0, NULL, NULL, get_parent, set_parent },
|
||||
{ "code", CT_STRING, ACCOUNT_MAX_CODE_LEN, 0, "code" },
|
||||
{ "description", CT_STRING, ACCOUNT_MAX_DESCRIPTION_LEN, 0, "description" },
|
||||
{ NULL }
|
||||
};
|
||||
static GncSqlColumnTableEntry parent_col_table[] =
|
||||
{
|
||||
{ "parent_guid", CT_GUID, 0, 0, NULL, NULL, NULL, set_parent_guid },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
Account* pAccount;
|
||||
GUID guid;
|
||||
} account_parent_guid_struct;
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
static gpointer
|
||||
get_parent( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
const Account* pAccount;
|
||||
const Account* pParent;
|
||||
const GUID* parent_guid;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_ACCOUNT(pObject), NULL );
|
||||
|
||||
pAccount = GNC_ACCOUNT(pObject);
|
||||
pParent = gnc_account_get_parent( pAccount );
|
||||
if( pParent == NULL ) {
|
||||
parent_guid = NULL;
|
||||
} else {
|
||||
parent_guid = qof_instance_get_guid( QOF_INSTANCE(pParent) );
|
||||
}
|
||||
|
||||
return (gpointer)parent_guid;
|
||||
}
|
||||
|
||||
static void
|
||||
set_parent( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
Account* pAccount;
|
||||
QofBook* pBook;
|
||||
GUID* guid = (GUID*)pValue;
|
||||
Account* pParent;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_ACCOUNT(pObject) );
|
||||
|
||||
pAccount = GNC_ACCOUNT(pObject);
|
||||
pBook = qof_instance_get_book( QOF_INSTANCE(pAccount) );
|
||||
if( guid != NULL ) {
|
||||
pParent = xaccAccountLookup( guid, pBook );
|
||||
if( pParent != NULL ) {
|
||||
gnc_account_append_child( pParent, pAccount );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_parent_guid( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
account_parent_guid_struct* s = (account_parent_guid_struct*)pObject;
|
||||
GUID* guid = (GUID*)pValue;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
s->guid = *guid;
|
||||
}
|
||||
|
||||
static Account*
|
||||
load_single_account( GncSqlBackend* be, GncSqlRow* row,
|
||||
GList** l_accounts_needing_parents )
|
||||
{
|
||||
const GUID* guid;
|
||||
GUID acc_guid;
|
||||
Account* pAccount;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
g_return_val_if_fail( l_accounts_needing_parents != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
acc_guid = *guid;
|
||||
|
||||
pAccount = xaccAccountLookup( &acc_guid, be->primary_book );
|
||||
if( pAccount == NULL ) {
|
||||
pAccount = xaccMallocAccount( be->primary_book );
|
||||
}
|
||||
xaccAccountBeginEdit( pAccount );
|
||||
gnc_sql_load_object( be, row, GNC_ID_ACCOUNT, pAccount, col_table );
|
||||
xaccAccountCommitEdit( pAccount );
|
||||
|
||||
/* If we don't have a parent, it might be because the parent account hasn't
|
||||
been loaded yet. Remember the account and its parent guid for later. */
|
||||
if( gnc_account_get_parent( pAccount ) == NULL ) {
|
||||
account_parent_guid_struct* s = g_slice_new( account_parent_guid_struct );
|
||||
s->pAccount = pAccount;
|
||||
gnc_sql_load_object( be, row, GNC_ID_ACCOUNT, s, parent_col_table );
|
||||
*l_accounts_needing_parents = g_list_prepend( *l_accounts_needing_parents, s );
|
||||
}
|
||||
|
||||
return pAccount;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_accounts( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt = NULL;
|
||||
GncSqlResult* result;
|
||||
QofBook* pBook;
|
||||
gnc_commodity_table* pTable;
|
||||
int numRows;
|
||||
int r;
|
||||
Account* parent;
|
||||
GList* l_accounts_needing_parents = NULL;
|
||||
GList* list = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
pBook = be->primary_book;
|
||||
pTable = gnc_commodity_table_get_table( pBook );
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
Account* acc;
|
||||
|
||||
while( row != NULL ) {
|
||||
acc = load_single_account( be, row, &l_accounts_needing_parents );
|
||||
if( acc != NULL ) {
|
||||
list = g_list_append( list, acc );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
|
||||
/* While there are items on the list of accounts needing parents,
|
||||
try to see if the parent has now been loaded. Theory says that if
|
||||
items are removed from the front and added to the back if the
|
||||
parent is still not available, then eventually, the list will
|
||||
shrink to size 0. */
|
||||
if( l_accounts_needing_parents != NULL ) {
|
||||
gboolean progress_made = TRUE;
|
||||
|
||||
Account* pParent;
|
||||
GList* elem;
|
||||
|
||||
while( progress_made ) {
|
||||
progress_made = FALSE;
|
||||
for( elem = l_accounts_needing_parents; elem != NULL; elem = g_list_next( elem ) ) {
|
||||
account_parent_guid_struct* s = (account_parent_guid_struct*)elem->data;
|
||||
const gchar* name = xaccAccountGetName( s->pAccount );
|
||||
pParent = xaccAccountLookup( &s->guid, be->primary_book );
|
||||
if( pParent != NULL ) {
|
||||
gnc_account_append_child( pParent, s->pAccount );
|
||||
l_accounts_needing_parents = g_list_delete_link( l_accounts_needing_parents, elem );
|
||||
progress_made = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Any accounts left over must be parented by the root account */
|
||||
for( elem = l_accounts_needing_parents; elem != NULL; elem = g_list_next( elem ) ) {
|
||||
account_parent_guid_struct* s = (account_parent_guid_struct*)elem->data;
|
||||
Account* root;
|
||||
root = gnc_book_get_root_account( pBook );
|
||||
if( root == NULL ) {
|
||||
root = gnc_account_create_root( pBook );
|
||||
}
|
||||
gnc_account_append_child( root, s->pAccount );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_account_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_save_account( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
Account* pAcc = GNC_ACCOUNT(inst);
|
||||
const GUID* guid;
|
||||
gboolean is_infant;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_ACCOUNT(inst) );
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
|
||||
// If there is no commodity yet, this might be because a new account name
|
||||
// has been entered directly into the register and an account window will
|
||||
// be opened. The account info is not complete yet, but the name has been
|
||||
// set, triggering this commit
|
||||
if( xaccAccountGetCommodity( pAcc ) != NULL ) {
|
||||
gint op;
|
||||
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
|
||||
// If not deleting the account, ensure the commodity is in the db
|
||||
if( op != OP_DB_DELETE ) {
|
||||
gnc_sql_save_commodity( be, xaccAccountGetCommodity( pAcc ) );
|
||||
}
|
||||
|
||||
(void)gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_ACCOUNT, pAcc, col_table );
|
||||
|
||||
// Now, commit or delete any slots
|
||||
guid = qof_instance_get_guid( inst );
|
||||
if( !qof_instance_get_destroying(inst) ) {
|
||||
gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
} else {
|
||||
gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
load_account_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
{
|
||||
const GValue* val;
|
||||
GUID guid;
|
||||
const GUID* pGuid;
|
||||
Account* account = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val == NULL ) {
|
||||
pGuid = NULL;
|
||||
} else {
|
||||
string_to_guid( g_value_get_string( val ), &guid );
|
||||
pGuid = &guid;
|
||||
}
|
||||
if( pGuid != NULL ) {
|
||||
account = xaccAccountLookup( pGuid, be->primary_book );
|
||||
}
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, account, NULL );
|
||||
} else {
|
||||
(*setter)( pObject, (const gpointer)account );
|
||||
}
|
||||
}
|
||||
|
||||
static col_type_handler_t account_guid_handler
|
||||
= { load_account_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist };
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_account_handler( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_ACCOUNT,
|
||||
gnc_sql_save_account, /* commit */
|
||||
load_all_accounts, /* initial_load */
|
||||
create_account_tables /* create_tables */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_ACCOUNT, GNC_SQL_BACKEND, &be_data );
|
||||
|
||||
gnc_sql_register_col_type_handler( CT_ACCOUNTREF, &account_guid_handler );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
38
src/backend/sql/gnc-account-sql.h
Normal file
38
src/backend/sql/gnc-account-sql.h
Normal file
@ -0,0 +1,38 @@
|
||||
/********************************************************************
|
||||
* gnc-account-sql.h: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-account-sql.h
|
||||
* @brief load and save accounts data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_ACCOUNT_SQL_H_
|
||||
#define GNC_ACCOUNT_SQL_H_
|
||||
|
||||
#include "qof.h"
|
||||
#include <gmodule.h>
|
||||
|
||||
void gnc_sql_init_account_handler( void );
|
||||
void gnc_sql_save_account( GncSqlBackend* be, QofInstance* inst );
|
||||
|
||||
#endif /* GNC_ACCOUNT_SQL_H_ */
|
2529
src/backend/sql/gnc-backend-sql.c
Normal file
2529
src/backend/sql/gnc-backend-sql.c
Normal file
File diff suppressed because it is too large
Load Diff
592
src/backend/sql/gnc-backend-sql.h
Normal file
592
src/backend/sql/gnc-backend-sql.h
Normal file
@ -0,0 +1,592 @@
|
||||
/********************************************************************
|
||||
* gnc-backend-sql.h: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
|
||||
/**
|
||||
* @defgroup SQLBE SQL Backend Core
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @addtogroup Columns Columns
|
||||
@ingroup SQLBE
|
||||
*/
|
||||
|
||||
/**
|
||||
@}
|
||||
*/
|
||||
|
||||
/** @addtogroup SQLBE
|
||||
@{
|
||||
*/
|
||||
/** @addtogroup SQLBE
|
||||
|
||||
* The SQL backend core is a library which can form the core for a QOF
|
||||
* backend based on an SQL library.
|
||||
|
||||
*/
|
||||
|
||||
/** @file gnc-backend-sql.h
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
@}
|
||||
*/
|
||||
|
||||
#ifndef GNC_BACKEND_SQL_H_
|
||||
#define GNC_BACKEND_SQL_H_
|
||||
|
||||
#include "qof.h"
|
||||
#include "qofbackend-p.h"
|
||||
#include <gmodule.h>
|
||||
|
||||
typedef struct GncSqlConnection GncSqlConnection;
|
||||
|
||||
/**
|
||||
* @struct GncSqlBackend
|
||||
*
|
||||
* Main SQL backend structure.
|
||||
*/
|
||||
struct GncSqlBackend
|
||||
{
|
||||
QofBackend be; /**< QOF backend */
|
||||
GncSqlConnection* conn; /**< SQL connection */
|
||||
QofBook *primary_book; /**< The primary, main open book */
|
||||
gboolean loading; /**< We are performing an initial load */
|
||||
gboolean in_query; /**< We are processing a query */
|
||||
gboolean is_pristine_db; /**< Are we saving to a new pristine db? */
|
||||
gint obj_total; /**< Total # of objects (for percentage calculation) */
|
||||
gint operations_done; /**< Number of operations (save/load) done */
|
||||
GHashTable* versions; /**< Version number for each table */
|
||||
};
|
||||
typedef struct GncSqlBackend GncSqlBackend;
|
||||
|
||||
/**
|
||||
* Initialize the SQL backend.
|
||||
*
|
||||
* @param be SQL backend
|
||||
*/
|
||||
void gnc_sql_init( GncSqlBackend* be );
|
||||
|
||||
/**
|
||||
* Load the contents of an SQL database into a book.
|
||||
*
|
||||
* @param be SQL backend
|
||||
* @param book Book to be loaded
|
||||
*/
|
||||
void gnc_sql_load( GncSqlBackend* be, QofBook *book );
|
||||
|
||||
/**
|
||||
* Save the contents of a book to an SQL database.
|
||||
*
|
||||
* @param be SQL backend
|
||||
* @param book Book to be saved
|
||||
*/
|
||||
void gnc_sql_sync_all( GncSqlBackend* be, QofBook *book );
|
||||
|
||||
/**
|
||||
* An object is about to be edited.
|
||||
*
|
||||
* @param be SQL backend
|
||||
* @param inst Object being edited
|
||||
*/
|
||||
void gnc_sql_begin_edit( GncSqlBackend* be, QofInstance *inst );
|
||||
|
||||
/**
|
||||
* Object editing has been cancelled.
|
||||
*
|
||||
* @param be SQL backend
|
||||
* @param inst Object being edited
|
||||
*/
|
||||
void gnc_sql_rollback_edit( GncSqlBackend* qbe, QofInstance *inst );
|
||||
|
||||
/**
|
||||
* Object editting is complete and the object should be saved.
|
||||
*
|
||||
* @param be SQL backend
|
||||
* @param inst Object being edited
|
||||
*/
|
||||
void gnc_sql_commit_edit( GncSqlBackend* qbe, QofInstance *inst );
|
||||
|
||||
/**
|
||||
*/
|
||||
typedef struct GncSqlColumnTableEntry GncSqlColumnTableEntry;
|
||||
typedef struct GncSqlStatement GncSqlStatement;
|
||||
typedef struct GncSqlResult GncSqlResult;
|
||||
typedef struct GncSqlRow GncSqlRow;
|
||||
|
||||
/**
|
||||
*@struct GncSqlStatement
|
||||
*
|
||||
* Struct which represents an SQL statement. SQL backends must provide a
|
||||
* structure which implements all of the functions.
|
||||
*/
|
||||
struct GncSqlStatement
|
||||
{
|
||||
void (*dispose)( GncSqlStatement* );
|
||||
gchar* (*toSql)( GncSqlStatement* );
|
||||
void (*addWhereCond)( GncSqlStatement*, QofIdTypeConst, gpointer, const GncSqlColumnTableEntry*, GValue* );
|
||||
};
|
||||
#define gnc_sql_statement_dispose(STMT) \
|
||||
(STMT)->dispose(STMT)
|
||||
#define gnc_sql_statement_to_sql(STMT) \
|
||||
(STMT)->toSql(STMT)
|
||||
#define gnc_sql_statement_add_where_cond(STMT,TYPENAME,OBJ,COLDESC,VALUE) \
|
||||
(STMT)->addWhereCond(STMT, TYPENAME, OBJ, COLDESC, VALUE)
|
||||
|
||||
/**
|
||||
* @struct GncSqlConnection
|
||||
*
|
||||
* Struct which represents the connection to an SQL database. SQL backends
|
||||
* must provide a structure which implements all of the functions.
|
||||
*/
|
||||
struct GncSqlConnection
|
||||
{
|
||||
void (*dispose)( GncSqlConnection* );
|
||||
GncSqlResult* (*executeSelectStatement)( GncSqlConnection*, GncSqlStatement* );
|
||||
gint (*executeNonSelectStatement)( GncSqlConnection*, GncSqlStatement* );
|
||||
GncSqlStatement* (*createStatementFromSql)( GncSqlConnection*, gchar* );
|
||||
gboolean (*doesTableExist)( GncSqlConnection*, const gchar* );
|
||||
void (*beginTransaction)( GncSqlConnection* );
|
||||
void (*rollbackTransaction)( GncSqlConnection* );
|
||||
void (*commitTransaction)( GncSqlConnection* );
|
||||
const gchar* (*getColumnTypeName)( GncSqlConnection*, GType, gint size );
|
||||
void (*createTable)( GncSqlConnection*, const gchar*, const GList* );
|
||||
void (*createIndex)( GncSqlConnection*, const gchar*, const gchar*, const GncSqlColumnTableEntry* );
|
||||
gchar* (*quoteString)( const GncSqlConnection*, gchar* );
|
||||
};
|
||||
#define gnc_sql_connection_dispose(CONN) (CONN)->dispose(CONN)
|
||||
#define gnc_sql_connection_execute_select_statement(CONN,STMT) \
|
||||
(CONN)->executeSelectStatement(CONN,STMT)
|
||||
#define gnc_sql_connection_execute_nonselect_statement(CONN,STMT) \
|
||||
(CONN)->executeNonSelectStatement(CONN,STMT)
|
||||
#define gnc_sql_connection_create_statement_from_sql(CONN,SQL) \
|
||||
(CONN)->createStatementFromSql(CONN,SQL)
|
||||
#define gnc_sql_connection_does_table_exist(CONN,NAME) \
|
||||
(CONN)->doesTableExist(CONN,NAME)
|
||||
#define gnc_sql_connection_begin_transaction(CONN) \
|
||||
(CONN)->beginTransaction(CONN)
|
||||
#define gnc_sql_connection_rollback_transaction(CONN) \
|
||||
(CONN)->rollbackTransaction(CONN)
|
||||
#define gnc_sql_connection_commit_transaction(CONN) \
|
||||
(CONN)->commitTransaction(CONN)
|
||||
#define gnc_sql_connection_get_column_type_name(CONN,TYPE,SIZE) \
|
||||
(CONN)->getColumnTypeName(CONN,TYPE,SIZE)
|
||||
#define gnc_sql_connection_create_table(CONN,NAME,COLLIST) \
|
||||
(CONN)->createTable(CONN,NAME,COLLIST)
|
||||
#define gnc_sql_connection_create_index(CONN,INDEXNAME,TABLENAME,COLTABLE) \
|
||||
(CONN)->createIndex(CONN,INDEXNAME,TABLENAME,COLTABLE)
|
||||
#define gnc_sql_connection_quote_string(CONN,STR) \
|
||||
(CONN)->quoteString(CONN,STR)
|
||||
|
||||
/**
|
||||
* @struct GncSqlRow
|
||||
*
|
||||
* Struct used to represent a row in the result of an SQL SELECT statement.
|
||||
* SQL backends must provide a structure which implements all of the functions.
|
||||
*/
|
||||
struct GncSqlRow
|
||||
{
|
||||
const GValue* (*getValueAtColName)( GncSqlRow*, const gchar* );
|
||||
void (*dispose)( GncSqlRow* );
|
||||
};
|
||||
#define gnc_sql_row_get_value_at_col_name(ROW,N) \
|
||||
(ROW)->getValueAtColName(ROW,N)
|
||||
#define gnc_sql_row_dispose(ROW) \
|
||||
(ROW)->dispose(ROW)
|
||||
|
||||
/**
|
||||
* @struct GncSqlResult
|
||||
*
|
||||
* Struct used to represent the result of an SQL SELECT statement. SQL
|
||||
* backends must provide a structure which implements all of the functions.
|
||||
*/
|
||||
struct GncSqlResult
|
||||
{
|
||||
gint (*getNumRows)( GncSqlResult* );
|
||||
GncSqlRow* (*getFirstRow)( GncSqlResult* );
|
||||
GncSqlRow* (*getNextRow)( GncSqlResult* );
|
||||
void (*dispose)( GncSqlResult* );
|
||||
};
|
||||
#define gnc_sql_result_get_num_rows(RESULT) \
|
||||
(RESULT)->getNumRows(RESULT)
|
||||
#define gnc_sql_result_get_first_row(RESULT) \
|
||||
(RESULT)->getFirstRow(RESULT)
|
||||
#define gnc_sql_result_get_next_row(RESULT) \
|
||||
(RESULT)->getNextRow(RESULT)
|
||||
#define gnc_sql_result_dispose(RESULT) \
|
||||
(RESULT)->dispose(RESULT)
|
||||
|
||||
/**
|
||||
* @struct GncSqlObjectBackend
|
||||
*
|
||||
* Struct used to handle a specific engine object type for an SQL backend.
|
||||
* This * handler should be registered with qof_object_register_backend().
|
||||
*
|
||||
* commit() - commit an object to the db
|
||||
* initial_load() - load stuff when new db opened
|
||||
* create_tables() - create any db tables
|
||||
* compile_query() - compile a backend object query
|
||||
* run_query() - run a compiled query
|
||||
* free_query() - free a compiled query
|
||||
* write() - write all objects
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int version; /**< Backend version number */
|
||||
const gchar * type_name; /**< Engine object type name */
|
||||
/** Commit an instance of this object to the database */
|
||||
void (*commit)( GncSqlBackend* be, QofInstance* inst );
|
||||
/** Load all objects of this type from the database */
|
||||
void (*initial_load)( GncSqlBackend* be );
|
||||
/** Create database tables for this object */
|
||||
void (*create_tables)( GncSqlBackend* be );
|
||||
/** Compile a query on these objects */
|
||||
gpointer (*compile_query)( GncSqlBackend* be, QofQuery* pQuery );
|
||||
/** Run a query on these objects */
|
||||
void (*run_query)( GncSqlBackend* be, gpointer pQuery );
|
||||
/** Free a query on these objects */
|
||||
void (*free_query)( GncSqlBackend* be, gpointer pQuery );
|
||||
/** Write all objects of this type to the database */
|
||||
void (*write)( GncSqlBackend* be );
|
||||
} GncSqlObjectBackend;
|
||||
#define GNC_SQL_BACKEND "gnc:sql:1"
|
||||
#define GNC_SQL_BACKEND_VERSION 1
|
||||
|
||||
/**
|
||||
* @struct GncSqlColumnInfo
|
||||
*/
|
||||
typedef struct {
|
||||
const gchar* name; /**< Column name */
|
||||
const gchar* type_name; /**< Column SQL type name */
|
||||
gint size; /**< Column size (string types) */
|
||||
gboolean is_primary_key;
|
||||
gboolean null_allowed;
|
||||
} GncSqlColumnInfo;
|
||||
|
||||
// Type for conversion of db row to object.
|
||||
#define CT_STRING "ct_string"
|
||||
#define CT_GUID "ct_guid"
|
||||
#define CT_INT "ct_int"
|
||||
#define CT_INT64 "ct_int64"
|
||||
#define CT_TIMESPEC "ct_timespec"
|
||||
#define CT_GDATE "ct_gdate"
|
||||
#define CT_NUMERIC "ct_numeric"
|
||||
#define CT_DOUBLE "ct_double"
|
||||
#define CT_BOOLEAN "ct_boolean"
|
||||
#define CT_ACCOUNTREF "ct_accountref"
|
||||
#define CT_COMMODITYREF "ct_commodityref"
|
||||
#define CT_TXREF "ct_txref"
|
||||
#define CT_LOTREF "ct_lotref"
|
||||
|
||||
/**
|
||||
* @struct GncSqlColumnTableEntry
|
||||
*
|
||||
* The GncSqlColumnTableEntry struct contains all of the information
|
||||
* required to copy information between an object and the database.
|
||||
* The database description for an object consists of an array of
|
||||
* GncSqlColumnTableEntry objects, with a final member having col_name == NULL.
|
||||
*/
|
||||
struct GncSqlColumnTableEntry {
|
||||
const gchar* col_name; /**< Column name */
|
||||
const gchar* col_type; /**< Column type */
|
||||
gint size; /**< Column size in bytes, for string columns */
|
||||
#define COL_PKEY 0x01
|
||||
#define COL_NNUL 0x02
|
||||
#define COL_UNIQUE 0x04
|
||||
#define COL_AUTOINC 0x08
|
||||
gint flags; /**< Column flags */
|
||||
const gchar* gobj_param_name; /**< If non-null, g_object param name */
|
||||
const gchar* qof_param_name; /**< If non-null, qof parameter name */
|
||||
QofAccessFunc getter; /**< General access function */
|
||||
QofSetterFunc setter; /**< General setter function */
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
OP_DB_INSERT,
|
||||
OP_DB_UPDATE,
|
||||
OP_DB_DELETE
|
||||
} E_DB_OPERATION;
|
||||
|
||||
typedef void (*GNC_SQL_LOAD_FN)( const GncSqlBackend* be,
|
||||
GncSqlRow* row,
|
||||
QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table );
|
||||
typedef void (*GNC_SQL_ADD_COL_INFO_TO_LIST_FN)( const GncSqlBackend* be,
|
||||
const GncSqlColumnTableEntry* table_row,
|
||||
GList** pList );
|
||||
typedef void (*GNC_SQL_ADD_COLNAME_TO_LIST_FN)( const GncSqlColumnTableEntry* table_row, GList** pList );
|
||||
typedef void (*GNC_SQL_ADD_GVALUE_TO_SLIST_FN)( const GncSqlBackend* be,
|
||||
QofIdTypeConst obj_name, const gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row, GSList** pList );
|
||||
|
||||
typedef struct {
|
||||
GNC_SQL_LOAD_FN load_fn;
|
||||
GNC_SQL_ADD_COL_INFO_TO_LIST_FN add_col_info_to_list_fn;
|
||||
GNC_SQL_ADD_COLNAME_TO_LIST_FN add_colname_to_list_fn;
|
||||
GNC_SQL_ADD_GVALUE_TO_SLIST_FN add_gvalue_to_slist_fn;
|
||||
} col_type_handler_t;
|
||||
|
||||
/**
|
||||
* Returns the QOF access function for a column.
|
||||
*
|
||||
* @param obj_name QOF object type name
|
||||
* @param table_row DB table column
|
||||
* @return Access function
|
||||
*/
|
||||
QofAccessFunc gnc_sql_get_getter( QofIdTypeConst obj_name, const GncSqlColumnTableEntry* table_row );
|
||||
|
||||
/**
|
||||
* Adds a column name to a list. If the column type spans multiple columns,
|
||||
* all of the column names for the pieces are added.
|
||||
*
|
||||
* @param table_row DB table column
|
||||
* @pList List
|
||||
*/
|
||||
void gnc_sql_add_colname_to_list( const GncSqlColumnTableEntry* table_row, GList** pList );
|
||||
|
||||
/**
|
||||
* Performs an operation on the database.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param op Operation type
|
||||
* @param table_name SQL table name
|
||||
* @param obj_name QOF object type name
|
||||
* @param pObject Gnucash object
|
||||
* @param table DB table description
|
||||
* @return TRUE if successful, FALSE if not
|
||||
*/
|
||||
gboolean gnc_sql_do_db_operation( GncSqlBackend* be,
|
||||
E_DB_OPERATION op,
|
||||
const gchar* table_name,
|
||||
QofIdTypeConst obj_name,
|
||||
gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table );
|
||||
|
||||
/**
|
||||
* Execute an SQL SELECT statement.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param statement Statement
|
||||
* @return Results
|
||||
*/
|
||||
GncSqlResult* gnc_sql_execute_select_statement( GncSqlBackend* be, GncSqlStatement* statement );
|
||||
|
||||
/**
|
||||
* Executes an SQL SELECT statement from an SQL char string.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param sql SQL SELECT string
|
||||
* @return Results
|
||||
*/
|
||||
GncSqlResult* gnc_sql_execute_select_sql( const GncSqlBackend* be, gchar* sql );
|
||||
|
||||
/**
|
||||
* Creates a statement from an SQL char string.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param sql SQL char string
|
||||
* @return Statement
|
||||
*/
|
||||
GncSqlStatement* gnc_sql_create_statement_from_sql( const GncSqlBackend* be, gchar* sql );
|
||||
|
||||
/**
|
||||
* Loads a Gnucash object from the database.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param row DB result row
|
||||
* @param obj_name QOF object type name
|
||||
* @param pObject Object to be loaded
|
||||
* @param table DB table description
|
||||
*/
|
||||
void gnc_sql_load_object( const GncSqlBackend* be, GncSqlRow* row,
|
||||
QofIdTypeConst obj_name, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table );
|
||||
|
||||
/**
|
||||
* Checks whether an object is in the database or not.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param table_name DB table name
|
||||
* @param obj_name QOF object type name
|
||||
* @param pObject Object to be checked
|
||||
* @param table DB table description
|
||||
* @return TRUE if the object is in the database, FALSE otherwise
|
||||
*/
|
||||
gboolean gnc_sql_object_is_it_in_db( GncSqlBackend* be,
|
||||
const gchar* table_name,
|
||||
QofIdTypeConst obj_name, const gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table );
|
||||
|
||||
/**
|
||||
* Returns the version number for a DB table.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param table_name Table name
|
||||
* @return Version number, or 0 if the table does not exist
|
||||
*/
|
||||
gint gnc_sql_get_table_version( const GncSqlBackend* be, const gchar* table_name );
|
||||
|
||||
/**
|
||||
* Creates a table in the database
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param table_name Table name
|
||||
* @param table_version Table version
|
||||
* @param col_table DB table description
|
||||
* @return TRUE if successful, FALSE if unsuccessful
|
||||
*/
|
||||
gboolean gnc_sql_create_table( const GncSqlBackend* be, const gchar* table_name,
|
||||
gint table_version, const GncSqlColumnTableEntry* col_table );
|
||||
|
||||
/**
|
||||
* Creates an index in the database
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param index_name Index name
|
||||
* @param table_name Table name
|
||||
* @param col_table Columns that the index should index
|
||||
*/
|
||||
void gnc_sql_create_index( const GncSqlBackend* be, const gchar* index_name,
|
||||
const gchar* table_name, const GncSqlColumnTableEntry* col_table );
|
||||
|
||||
/**
|
||||
* Loads the object guid from a database row. The table must have a column
|
||||
* named "guid" with type CT_GUID.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param row Database row
|
||||
* @return GUID
|
||||
*/
|
||||
const GUID* gnc_sql_load_guid( const GncSqlBackend* be, GncSqlRow* row );
|
||||
|
||||
/**
|
||||
* Loads the transaction guid from a database row. The table must have a column
|
||||
* named "tx_guid" with type CT_GUID.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param row Database row
|
||||
* @return GUID
|
||||
*/
|
||||
const GUID* gnc_sql_load_tx_guid( const GncSqlBackend* be, GncSqlRow* row );
|
||||
|
||||
/**
|
||||
* Creates a basic SELECT statement for a table.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param table_name Table name
|
||||
* @return Statement
|
||||
*/
|
||||
GncSqlStatement* gnc_sql_create_select_statement( const GncSqlBackend* be,
|
||||
const gchar* table_name );
|
||||
|
||||
/**
|
||||
* Registers a column handler for a new column type.
|
||||
*
|
||||
* @param colType Column type
|
||||
* @param handler Column handler
|
||||
*/
|
||||
void gnc_sql_register_col_type_handler( const gchar* colType, const col_type_handler_t* handler );
|
||||
|
||||
/**
|
||||
* Adds a GValue for an object reference GUID to the end of a GSList.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param obj_name QOF object type name
|
||||
* @param pObject Object
|
||||
* @param table_row DB table column description
|
||||
* @param pList List
|
||||
*/
|
||||
void gnc_sql_add_gvalue_objectref_guid_to_slist( const GncSqlBackend* be,
|
||||
QofIdTypeConst obj_name, const gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row, GSList** pList );
|
||||
|
||||
/**
|
||||
* Adds a column info structure for an object reference GUID to the end of a
|
||||
* GList.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
* @param table_row DB table column description
|
||||
* @param pList List
|
||||
*/
|
||||
void gnc_sql_add_objectref_guid_col_info_to_list( const GncSqlBackend* be,
|
||||
const GncSqlColumnTableEntry* table_row, GList** pList );
|
||||
|
||||
/**
|
||||
* Appends the ascii strings for a list of GUIDs to the end of an SQL string.
|
||||
*
|
||||
* @param str SQL string
|
||||
* @param list List of GUIDs
|
||||
* @param maxCount Max # of GUIDs to append
|
||||
* @return Number of GUIDs appended
|
||||
*/
|
||||
guint gnc_sql_append_guid_list_to_sql( GString* str, GList* list, guint maxCount );
|
||||
|
||||
/**
|
||||
* Appends column names for a subtable to the end of a GList.
|
||||
*
|
||||
* @param table_row Main DB column description
|
||||
* @param subtable Sub-column description table
|
||||
* @param pList List
|
||||
*/
|
||||
void gnc_sql_add_subtable_colnames_to_list( const GncSqlColumnTableEntry* table_row,
|
||||
const GncSqlColumnTableEntry* subtable,
|
||||
GList** pList );
|
||||
|
||||
/**
|
||||
* Returns a string corresponding to the SQL representation of a GValue. The
|
||||
* caller must free the string.
|
||||
*
|
||||
* @param conn SQL connection
|
||||
* @param value Value to be converted
|
||||
* @return String
|
||||
*/
|
||||
gchar* gnc_sql_get_sql_value( const GncSqlConnection* conn, const GValue* value );
|
||||
|
||||
/**
|
||||
* Initializes DB table version information.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
*/
|
||||
void gnc_sql_init_version_info( GncSqlBackend* be );
|
||||
|
||||
/**
|
||||
* Finalizes DB table version information.
|
||||
*
|
||||
* @param be SQL backend struct
|
||||
*/
|
||||
void gnc_sql_finalize_version_info( GncSqlBackend* be );
|
||||
|
||||
/**
|
||||
*
|
||||
* Commits a "standard" item to the database. In most cases, a commit of one object vs
|
||||
* another differs only in the table name and column table.
|
||||
*
|
||||
* @param be SQL backend
|
||||
* @param inst Instance
|
||||
* @param tableName SQL table name
|
||||
* @param obj_name QOF object type name
|
||||
* @param col_table Column table
|
||||
*/
|
||||
void gnc_sql_commit_standard_item( GncSqlBackend* be, QofInstance* inst, const gchar* tableName,
|
||||
QofIdTypeConst obj_name, const GncSqlColumnTableEntry* col_table );
|
||||
|
||||
void _retrieve_guid_( gpointer pObject, gpointer pValue );
|
||||
|
||||
#endif /* GNC_BACKEND_SQL_H_ */
|
222
src/backend/sql/gnc-book-sql.c
Normal file
222
src/backend/sql/gnc-book-sql.c
Normal file
@ -0,0 +1,222 @@
|
||||
/********************************************************************
|
||||
* gnc-book-sql.c: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-book-sql.c
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL db
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "qof.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
|
||||
#include "gnc-book-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-book.h"
|
||||
#include "SX-book.h"
|
||||
#include "SX-book-p.h"
|
||||
|
||||
#define BOOK_TABLE "books"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
static gpointer get_root_account_guid( gpointer pObject, const QofParam* );
|
||||
static void set_root_account_guid( gpointer pObject, gpointer pValue );
|
||||
static gpointer get_root_template_guid( gpointer pObject, const QofParam* );
|
||||
static void set_root_template_guid( gpointer pObject, gpointer pValue );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "root_account_guid", CT_GUID, 0, COL_NNUL, NULL, NULL, get_root_account_guid, set_root_account_guid },
|
||||
{ "root_template_guid", CT_GUID, 0, COL_NNUL, NULL, NULL, get_root_template_guid, set_root_template_guid },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
static gpointer
|
||||
get_root_account_guid( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
GNCBook* book = QOF_BOOK(pObject);
|
||||
const Account* root;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( QOF_IS_BOOK(pObject), NULL );
|
||||
|
||||
root = gnc_book_get_root_account( book );
|
||||
return (gpointer)qof_instance_get_guid( QOF_INSTANCE(root) );
|
||||
}
|
||||
|
||||
static void
|
||||
set_root_account_guid( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
GNCBook* book = QOF_BOOK(pObject);
|
||||
const Account* root;
|
||||
GUID* guid = (GUID*)pValue;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( QOF_IS_BOOK(pObject) );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
root = gnc_book_get_root_account( book );
|
||||
qof_instance_set_guid( QOF_INSTANCE(root), guid );
|
||||
}
|
||||
|
||||
static gpointer
|
||||
get_root_template_guid( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
const GNCBook* book = QOF_BOOK(pObject);
|
||||
const Account* root;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( QOF_IS_BOOK(pObject), NULL );
|
||||
|
||||
root = gnc_book_get_template_root( book );
|
||||
return (gpointer)qof_instance_get_guid( QOF_INSTANCE(root) );
|
||||
}
|
||||
|
||||
static void
|
||||
set_root_template_guid( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
GNCBook* book = QOF_BOOK(pObject);
|
||||
GUID* guid = (GUID*)pValue;
|
||||
Account* root;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( QOF_IS_BOOK(pObject) );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
root = gnc_book_get_template_root( book );
|
||||
if( root == NULL ) {
|
||||
root = xaccMallocAccount( book );
|
||||
xaccAccountBeginEdit( root );
|
||||
xaccAccountSetType( root, ACCT_TYPE_ROOT );
|
||||
xaccAccountCommitEdit( root );
|
||||
gnc_book_set_template_root( book, root );
|
||||
}
|
||||
qof_instance_set_guid( QOF_INSTANCE(root), guid );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
load_single_book( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GUID* guid;
|
||||
GUID book_guid;
|
||||
GNCBook* pBook;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
book_guid = *guid;
|
||||
|
||||
pBook = be->primary_book;
|
||||
if( pBook == NULL ) {
|
||||
pBook = gnc_book_new();
|
||||
}
|
||||
|
||||
gnc_sql_load_object( be, row, GNC_ID_BOOK, pBook, col_table );
|
||||
gnc_sql_slots_load( be, QOF_INSTANCE(pBook) );
|
||||
|
||||
qof_instance_mark_clean( QOF_INSTANCE(pBook) );
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_books( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, BOOK_TABLE );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
|
||||
// If there are no rows, try committing the book
|
||||
if( row == NULL ) {
|
||||
gnc_sql_save_book( be, QOF_INSTANCE(be->primary_book) );
|
||||
} else {
|
||||
// Otherwise, load the 1st book.
|
||||
load_single_book( be, row );
|
||||
}
|
||||
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_book_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, BOOK_TABLE );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, BOOK_TABLE, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_save_book( GncSqlBackend* be, QofInstance* inst)
|
||||
{
|
||||
const GUID* guid;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( QOF_IS_BOOK(inst) );
|
||||
|
||||
gnc_sql_commit_standard_item( be, inst, BOOK_TABLE, GNC_ID_BOOK, col_table );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_book_handler( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_BOOK,
|
||||
gnc_sql_save_book, /* commit */
|
||||
load_all_books, /* initial_load */
|
||||
create_book_tables /* create_tables */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_BOOK, GNC_SQL_BACKEND, &be_data );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
38
src/backend/sql/gnc-book-sql.h
Normal file
38
src/backend/sql/gnc-book-sql.h
Normal file
@ -0,0 +1,38 @@
|
||||
/********************************************************************
|
||||
* gnc-book-sql.h: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-book-sql.h
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_BOOK_SQL_H_
|
||||
#define GNC_BOOK_SQL_H_
|
||||
|
||||
#include "qof.h"
|
||||
#include <gmodule.h>
|
||||
|
||||
void gnc_sql_init_book_handler( void );
|
||||
void gnc_sql_save_book( GncSqlBackend* be, QofInstance* inst );
|
||||
|
||||
#endif /* GNC_BOOK_SQL_H_ */
|
203
src/backend/sql/gnc-budget-sql.c
Normal file
203
src/backend/sql/gnc-budget-sql.c
Normal file
@ -0,0 +1,203 @@
|
||||
/********************************************************************
|
||||
* gnc-budget-sql.c: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-budget-sql.c
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL db
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "qof.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
|
||||
#include "Recurrence.h"
|
||||
|
||||
#include "gnc-budget-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
#include "gnc-recurrence-sql.h"
|
||||
|
||||
#include "gnc-budget.h"
|
||||
|
||||
#define BUDGET_TABLE "budgets"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define BUDGET_MAX_NAME_LEN 2048
|
||||
#define BUDGET_MAX_DESCRIPTION_LEN 2048
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "name", CT_STRING, BUDGET_MAX_NAME_LEN, COL_NNUL, "name" },
|
||||
{ "description", CT_STRING, BUDGET_MAX_DESCRIPTION_LEN, 0, "description" },
|
||||
{ "num_periods", CT_INT, 0, COL_NNUL, "num_periods" },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
static GncBudget*
|
||||
load_single_budget( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GUID* guid;
|
||||
GUID budget_guid;
|
||||
GncBudget* pBudget;
|
||||
Recurrence* r;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
budget_guid = *guid;
|
||||
|
||||
pBudget = gnc_budget_lookup( &budget_guid, be->primary_book );
|
||||
if( pBudget == NULL ) {
|
||||
pBudget = gnc_budget_new( be->primary_book );
|
||||
}
|
||||
|
||||
gnc_budget_begin_edit( pBudget );
|
||||
gnc_sql_load_object( be, row, GNC_ID_BUDGET, pBudget, col_table );
|
||||
r = g_new0( Recurrence, 1 );
|
||||
gnc_sql_recurrence_load( be, gnc_budget_get_guid( pBudget ), r );
|
||||
gnc_budget_commit_edit( pBudget );
|
||||
|
||||
return pBudget;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_budgets( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
int r;
|
||||
GList* list = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, BUDGET_TABLE );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
GncBudget* b;
|
||||
|
||||
while( row != NULL ) {
|
||||
b = load_single_budget( be, row );
|
||||
if( b != NULL ) {
|
||||
list = g_list_append( list, b );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_budget_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, BUDGET_TABLE );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, BUDGET_TABLE, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
save_budget( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
GncBudget* pBudget = GNC_BUDGET(inst);
|
||||
const GUID* guid;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_BUDGET(inst) );
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
(void)gnc_sql_do_db_operation( be, op, BUDGET_TABLE, GNC_ID_BUDGET, pBudget, col_table );
|
||||
|
||||
// Now, commit any slots and recurrence
|
||||
guid = qof_instance_get_guid( inst );
|
||||
if( !qof_instance_get_destroying(inst) ) {
|
||||
gnc_sql_recurrence_save( be, guid, gnc_budget_get_recurrence( pBudget ) );
|
||||
gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
} else {
|
||||
gnc_sql_recurrence_delete( be, guid );
|
||||
gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_save_budget( QofInstance* inst, gpointer data )
|
||||
{
|
||||
save_budget( (GncSqlBackend*)data, inst );
|
||||
}
|
||||
|
||||
static void
|
||||
write_budgets( GncSqlBackend* be )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
qof_collection_foreach( qof_book_get_collection( be->primary_book, GNC_ID_BUDGET ),
|
||||
(QofInstanceForeachCB)do_save_budget, be );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_budget_handler( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_BUDGET,
|
||||
save_budget, /* commit */
|
||||
load_all_budgets, /* initial_load */
|
||||
create_budget_tables, /* create_tables */
|
||||
NULL, NULL, NULL,
|
||||
write_budgets /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_BUDGET, GNC_SQL_BACKEND, &be_data );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
37
src/backend/sql/gnc-budget-sql.h
Normal file
37
src/backend/sql/gnc-budget-sql.h
Normal file
@ -0,0 +1,37 @@
|
||||
/********************************************************************
|
||||
* gnc-budget-sql.h: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-budget-sql.h
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_BUDGET_SQL_H_
|
||||
#define GNC_BUDGET_SQL_H_
|
||||
|
||||
#include "qof.h"
|
||||
#include <gmodule.h>
|
||||
|
||||
void gnc_sql_init_budget_handler( void );
|
||||
|
||||
#endif /* GNC_BUDGET_SQL_H_ */
|
261
src/backend/sql/gnc-commodity-sql.c
Normal file
261
src/backend/sql/gnc-commodity-sql.c
Normal file
@ -0,0 +1,261 @@
|
||||
/********************************************************************
|
||||
* gnc-commodity-sql.c: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-commodity-sql.c
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL db
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "qof.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
#include "gnc-commodity.h"
|
||||
|
||||
#include "gnc-commodity-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
static gpointer get_quote_source_name( gpointer pObject, const QofParam* );
|
||||
static void set_quote_source_name( gpointer pObject, gpointer pValue );
|
||||
|
||||
#define COMMODITIES_TABLE "commodities"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
#define COMMODITY_MAX_NAMESPACE_LEN 2048
|
||||
#define COMMODITY_MAX_MNEMONIC_LEN 2048
|
||||
#define COMMODITY_MAX_FULLNAME_LEN 2048
|
||||
#define COMMODITY_MAX_CUSIP_LEN 2048
|
||||
#define COMMODITY_MAX_QUOTESOURCE_LEN 2048
|
||||
#define COMMODITY_MAX_QUOTE_TZ_LEN 2048
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] = {
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "namespace", CT_STRING, COMMODITY_MAX_NAMESPACE_LEN, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)gnc_commodity_get_namespace,
|
||||
(QofSetterFunc)gnc_commodity_set_namespace },
|
||||
{ "mnemonic", CT_STRING, COMMODITY_MAX_MNEMONIC_LEN, COL_NNUL, "mnemonic" },
|
||||
{ "fullname", CT_STRING, COMMODITY_MAX_FULLNAME_LEN, 0, "fullname" },
|
||||
{ "cusip", CT_STRING, COMMODITY_MAX_CUSIP_LEN, 0, "cusip" },
|
||||
{ "fraction", CT_INT, 0, COL_NNUL, "fraction" },
|
||||
{ "quote_flag", CT_BOOLEAN, 0, COL_NNUL, "quote_flag" },
|
||||
{ "quote_source", CT_STRING, COMMODITY_MAX_QUOTESOURCE_LEN, 0, NULL, NULL,
|
||||
get_quote_source_name, set_quote_source_name },
|
||||
{ "quote_tz", CT_STRING, COMMODITY_MAX_QUOTE_TZ_LEN, 0, "quote-tz" },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
static gpointer
|
||||
get_quote_source_name( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
const gnc_commodity* pCommodity = GNC_COMMODITY(pObject);
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_COMMODITY(pObject), NULL );
|
||||
|
||||
return (gpointer)gnc_quote_source_get_internal_name(
|
||||
gnc_commodity_get_quote_source(pCommodity));
|
||||
}
|
||||
|
||||
static void
|
||||
set_quote_source_name( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
gnc_commodity* pCommodity = GNC_COMMODITY(pObject);
|
||||
const gchar* quote_source_name = (const gchar*)pValue;
|
||||
gnc_quote_source* quote_source;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_COMMODITY(pObject) );
|
||||
|
||||
if( pValue == NULL ) return;
|
||||
|
||||
quote_source = gnc_quote_source_lookup_by_internal( quote_source_name );
|
||||
gnc_commodity_set_quote_source( pCommodity, quote_source );
|
||||
}
|
||||
|
||||
static gnc_commodity*
|
||||
load_single_commodity( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
QofBook* pBook = be->primary_book;
|
||||
int col;
|
||||
const GValue* val;
|
||||
gnc_commodity* pCommodity;
|
||||
|
||||
pCommodity = gnc_commodity_new( pBook, NULL, NULL, NULL, NULL, 100 );
|
||||
gnc_commodity_begin_edit( pCommodity );
|
||||
gnc_sql_load_object( be, row, GNC_ID_COMMODITY, pCommodity, col_table );
|
||||
gnc_commodity_commit_edit( pCommodity );
|
||||
|
||||
return pCommodity;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_commodities( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
gnc_commodity_table* pTable;
|
||||
|
||||
pTable = gnc_commodity_table_get_table( be->primary_book );
|
||||
stmt = gnc_sql_create_select_statement( be, COMMODITIES_TABLE );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
int r;
|
||||
gnc_commodity* pCommodity;
|
||||
GList* list = NULL;
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
|
||||
while( row != NULL ) {
|
||||
gnc_commodity* c;
|
||||
|
||||
pCommodity = load_single_commodity( be, row );
|
||||
|
||||
if( pCommodity != NULL ) {
|
||||
GUID guid;
|
||||
|
||||
guid = *qof_instance_get_guid( QOF_INSTANCE(pCommodity) );
|
||||
pCommodity = gnc_commodity_table_insert( pTable, pCommodity );
|
||||
list = g_list_append( list, pCommodity );
|
||||
qof_instance_set_guid( QOF_INSTANCE(pCommodity), &guid );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_commodities_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, COMMODITIES_TABLE );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, COMMODITIES_TABLE, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
commit_commodity( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
const GUID* guid;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_COMMODITY(inst) );
|
||||
|
||||
gnc_sql_commit_standard_item( be, inst, COMMODITIES_TABLE, GNC_ID_COMMODITY, col_table );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_commodity_in_db( GncSqlBackend* be, gnc_commodity* pCommodity )
|
||||
{
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( pCommodity != NULL, FALSE );
|
||||
|
||||
return gnc_sql_object_is_it_in_db( be, COMMODITIES_TABLE, GNC_ID_COMMODITY,
|
||||
pCommodity, col_table );
|
||||
}
|
||||
|
||||
void
|
||||
gnc_sql_save_commodity( GncSqlBackend* be, gnc_commodity* pCommodity )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( pCommodity != NULL );
|
||||
|
||||
if( !is_commodity_in_db( be, pCommodity ) ) {
|
||||
commit_commodity( be, QOF_INSTANCE(pCommodity) );
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_commodity_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
{
|
||||
const GValue* val;
|
||||
GUID guid;
|
||||
const GUID* pGuid;
|
||||
gnc_commodity* commodity = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val == NULL ) {
|
||||
pGuid = NULL;
|
||||
} else {
|
||||
string_to_guid( g_value_get_string( val ), &guid );
|
||||
pGuid = &guid;
|
||||
}
|
||||
if( pGuid != NULL ) {
|
||||
commodity = gnc_commodity_find_commodity_by_guid( pGuid, be->primary_book );
|
||||
}
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, commodity, NULL );
|
||||
} else {
|
||||
(*setter)( pObject, (const gpointer)commodity );
|
||||
}
|
||||
}
|
||||
|
||||
static col_type_handler_t commodity_guid_handler
|
||||
= { load_commodity_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist };
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_commodity_handler( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_COMMODITY,
|
||||
commit_commodity, /* commit */
|
||||
load_all_commodities, /* initial_load */
|
||||
create_commodities_tables /* create_tables */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_COMMODITY, GNC_SQL_BACKEND, &be_data );
|
||||
|
||||
gnc_sql_register_col_type_handler( CT_COMMODITYREF, &commodity_guid_handler );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
38
src/backend/sql/gnc-commodity-sql.h
Normal file
38
src/backend/sql/gnc-commodity-sql.h
Normal file
@ -0,0 +1,38 @@
|
||||
/********************************************************************
|
||||
* gnc-commodity-sql.h: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-commodity-sql.h
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_COMMODITY_SQL_H_
|
||||
#define GNC_COMMODITY_SQL_H_
|
||||
|
||||
#include "qof.h"
|
||||
#include <gmodule.h>
|
||||
|
||||
void gnc_sql_init_commodity_handler( void );
|
||||
void gnc_sql_save_commodity( GncSqlBackend* be, gnc_commodity* pCommodity );
|
||||
|
||||
#endif /* GNC_COMMODITY_SQL_H_ */
|
249
src/backend/sql/gnc-lots-sql.c
Normal file
249
src/backend/sql/gnc-lots-sql.c
Normal file
@ -0,0 +1,249 @@
|
||||
/********************************************************************
|
||||
* gnc-lots-sql.c: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-lots-sql.c
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL db
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "qof.h"
|
||||
#include "gnc-lot.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
|
||||
#include "gnc-lots-sql.h"
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define TABLE_NAME "lots"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
static gpointer get_lot_account( gpointer pObject, const QofParam* param );
|
||||
static void set_lot_account( gpointer pObject, gpointer pValue );
|
||||
static void set_lot_is_closed( gpointer pObject, gboolean value );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "account_guid", CT_GUID, 0, COL_NNUL, NULL, NULL, get_lot_account, set_lot_account },
|
||||
{ "is_closed", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)gnc_lot_is_closed, (QofSetterFunc)set_lot_is_closed },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
static gpointer
|
||||
get_lot_account( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
const GNCLot* lot = GNC_LOT(pObject);
|
||||
const Account* pAccount;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_LOT(pObject), NULL );
|
||||
|
||||
pAccount = gnc_lot_get_account( lot );
|
||||
return (gpointer)qof_instance_get_guid( QOF_INSTANCE(pAccount) );
|
||||
}
|
||||
|
||||
static void
|
||||
set_lot_account( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
GNCLot* lot = GNC_LOT(pObject);
|
||||
QofBook* pBook;
|
||||
GUID* guid = (GUID*)pValue;
|
||||
Account* pAccount;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_LOT(pObject) );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
pBook = qof_instance_get_book( QOF_INSTANCE(lot) );
|
||||
pAccount = xaccAccountLookup( guid, pBook );
|
||||
xaccAccountInsertLot( pAccount, lot );
|
||||
}
|
||||
|
||||
static void
|
||||
set_lot_is_closed( gpointer pObject, gboolean closed )
|
||||
{
|
||||
GNCLot* lot = GNC_LOT(pObject);
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_LOT(pObject) );
|
||||
|
||||
lot->is_closed = closed;
|
||||
}
|
||||
|
||||
static GNCLot*
|
||||
load_single_lot( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
GNCLot* lot;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
lot = gnc_lot_new( be->primary_book );
|
||||
|
||||
gnc_lot_begin_edit( lot );
|
||||
gnc_sql_load_object( be, row, GNC_ID_LOT, lot, col_table );
|
||||
gnc_lot_commit_edit( lot );
|
||||
|
||||
return lot;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_lots( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
int r;
|
||||
GList* list = NULL;
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
GNCLot* lot;
|
||||
|
||||
while( row != NULL ) {
|
||||
lot = load_single_lot( be, row );
|
||||
if( lot != NULL ) {
|
||||
list = g_list_append( list, lot );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_lots_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
static void
|
||||
commit_lot( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_LOT(inst) );
|
||||
|
||||
gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_LOT, col_table );
|
||||
}
|
||||
|
||||
static void
|
||||
do_save_lot( QofInstance* inst, gpointer data )
|
||||
{
|
||||
commit_lot( (GncSqlBackend*)data, inst );
|
||||
}
|
||||
|
||||
static void
|
||||
write_lots( GncSqlBackend* be )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
qof_collection_foreach( qof_book_get_collection( be->primary_book, GNC_ID_LOT ),
|
||||
(QofInstanceForeachCB)do_save_lot, be );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
load_lot_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
{
|
||||
const GValue* val;
|
||||
GUID guid;
|
||||
const GUID* pGuid;
|
||||
GNCLot* lot = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val == NULL ) {
|
||||
pGuid = NULL;
|
||||
} else {
|
||||
string_to_guid( g_value_get_string( val ), &guid );
|
||||
pGuid = &guid;
|
||||
}
|
||||
if( pGuid != NULL ) {
|
||||
lot = gnc_lot_lookup( pGuid, be->primary_book );
|
||||
}
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, lot, NULL );
|
||||
} else {
|
||||
(*setter)( pObject, (const gpointer)lot );
|
||||
}
|
||||
}
|
||||
|
||||
static col_type_handler_t lot_guid_handler
|
||||
= { load_lot_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist };
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_lot_handler( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_LOT,
|
||||
commit_lot, /* commit */
|
||||
load_all_lots, /* initial_load */
|
||||
create_lots_tables, /* create tables */
|
||||
NULL, NULL, NULL,
|
||||
write_lots /* save all */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_LOT, GNC_SQL_BACKEND, &be_data );
|
||||
|
||||
gnc_sql_register_col_type_handler( CT_LOTREF, &lot_guid_handler );
|
||||
}
|
||||
|
||||
/* ========================== END OF FILE ===================== */
|
37
src/backend/sql/gnc-lots-sql.h
Normal file
37
src/backend/sql/gnc-lots-sql.h
Normal file
@ -0,0 +1,37 @@
|
||||
/********************************************************************
|
||||
* gnc-lots-sql.h: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-lots-sql.h
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_LOT_SQL_H_
|
||||
#define GNC_LOT_SQL_H_
|
||||
|
||||
#include "qof.h"
|
||||
#include <gmodule.h>
|
||||
|
||||
void gnc_sql_init_lot_handler( void );
|
||||
|
||||
#endif /* GNC_LOT_SQL_H_ */
|
207
src/backend/sql/gnc-price-sql.c
Normal file
207
src/backend/sql/gnc-price-sql.c
Normal file
@ -0,0 +1,207 @@
|
||||
/********************************************************************
|
||||
* gnc-price-sql.c: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-price-sql.c
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL db
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "qof.h"
|
||||
#include "gnc-pricedb.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
|
||||
#include "gnc-commodity-sql.h"
|
||||
#include "gnc-price-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define TABLE_NAME "prices"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
#define PRICE_MAX_SOURCE_LEN 2048
|
||||
#define PRICE_MAX_TYPE_LEN 2048
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "commodity_guid", CT_COMMODITYREF, 0, COL_NNUL, NULL, PRICE_COMMODITY },
|
||||
{ "currency_guid", CT_COMMODITYREF, 0, COL_NNUL, NULL, PRICE_CURRENCY },
|
||||
{ "date", CT_TIMESPEC, 0, COL_NNUL, NULL, PRICE_DATE },
|
||||
{ "source", CT_STRING, PRICE_MAX_SOURCE_LEN, 0, NULL, PRICE_SOURCE },
|
||||
{ "type", CT_STRING, PRICE_MAX_TYPE_LEN, 0, NULL, PRICE_TYPE },
|
||||
{ "value", CT_NUMERIC, 0, COL_NNUL, NULL, PRICE_VALUE },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
static GNCPrice*
|
||||
load_single_price( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
GNCPrice* pPrice;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
pPrice = gnc_price_create( be->primary_book );
|
||||
|
||||
gnc_price_begin_edit( pPrice );
|
||||
gnc_sql_load_object( be, row, GNC_ID_PRICE, pPrice, col_table );
|
||||
gnc_price_commit_edit( pPrice );
|
||||
|
||||
return pPrice;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_prices( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
QofBook* pBook;
|
||||
GNCPriceDB* pPriceDB;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
pBook = be->primary_book;
|
||||
pPriceDB = gnc_book_get_pricedb( pBook );
|
||||
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
int r;
|
||||
GNCPrice* pPrice;
|
||||
GList* list = NULL;
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
|
||||
while( row != NULL ) {
|
||||
pPrice = load_single_price( be, row );
|
||||
|
||||
if( pPrice != NULL ) {
|
||||
list = g_list_append( list, pPrice );
|
||||
gnc_pricedb_add_price( pPriceDB, pPrice );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_prices_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
static void
|
||||
save_price( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
GNCPrice* pPrice = GNC_PRICE(inst);
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_PRICE(inst) );
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
|
||||
if( op != OP_DB_DELETE ) {
|
||||
/* Ensure commodity and currency are in the db */
|
||||
gnc_sql_save_commodity( be, gnc_price_get_commodity( pPrice ) );
|
||||
gnc_sql_save_commodity( be, gnc_price_get_currency( pPrice ) );
|
||||
}
|
||||
|
||||
(void)gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_PRICE, pPrice, col_table );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
write_price( GNCPrice* p, gpointer data )
|
||||
{
|
||||
GncSqlBackend* be = (GncSqlBackend*)data;
|
||||
|
||||
g_return_val_if_fail( p != NULL, FALSE );
|
||||
g_return_val_if_fail( data != NULL, FALSE );
|
||||
|
||||
save_price( be, QOF_INSTANCE(p) );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
write_prices( GncSqlBackend* be )
|
||||
{
|
||||
GNCPriceDB* priceDB;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
priceDB = gnc_book_get_pricedb( be->primary_book );
|
||||
|
||||
gnc_pricedb_foreach_price( priceDB, write_price, be, TRUE );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_price_handler( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_PRICE,
|
||||
save_price, /* commit */
|
||||
load_all_prices, /* initial_load */
|
||||
create_prices_tables, /* create tables */
|
||||
NULL, NULL, NULL,
|
||||
write_prices /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_PRICE, GNC_SQL_BACKEND, &be_data );
|
||||
}
|
||||
|
||||
/* ========================== END OF FILE ===================== */
|
37
src/backend/sql/gnc-price-sql.h
Normal file
37
src/backend/sql/gnc-price-sql.h
Normal file
@ -0,0 +1,37 @@
|
||||
/********************************************************************
|
||||
* gnc-price-sql.h: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-price-sql.h
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_PRICE_SQL_H_
|
||||
#define GNC_PRICE_SQL_H_
|
||||
|
||||
#include "qof.h"
|
||||
#include <gmodule.h>
|
||||
|
||||
void gnc_sql_init_price_handler( void );
|
||||
|
||||
#endif /* GNC_PRICE_SQL_H_ */
|
342
src/backend/sql/gnc-recurrence-sql.c
Normal file
342
src/backend/sql/gnc-recurrence-sql.c
Normal file
@ -0,0 +1,342 @@
|
||||
/********************************************************************
|
||||
* gnc-recurrence-sql.c: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-recurrence-sql.c
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL db
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "qof.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "Recurrence.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
|
||||
#include "gnc-recurrence-sql.h"
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define TABLE_NAME "recurrences"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
#define BUDGET_MAX_RECURRENCE_PERIOD_TYPE_LEN 2048
|
||||
|
||||
typedef struct {
|
||||
GncSqlBackend* be;
|
||||
const GUID* guid;
|
||||
Recurrence* pRecurrence;
|
||||
} recurrence_info_t;
|
||||
|
||||
static gpointer get_obj_guid( gpointer pObject, const QofParam* param );
|
||||
static void set_obj_guid( gpointer pObject, gpointer pValue );
|
||||
static gint get_recurrence_mult( gpointer pObject );
|
||||
static void set_recurrence_mult( gpointer pObject, gint value );
|
||||
static gpointer get_recurrence_period_type( gpointer pObject, const QofParam* );
|
||||
static void set_recurrence_period_type( gpointer pObject, gpointer pValue );
|
||||
static gpointer get_recurrence_period_start( gpointer pObject, const QofParam* );
|
||||
static void set_recurrence_period_start( gpointer pObject, gpointer pValue );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "obj_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
get_obj_guid, set_obj_guid },
|
||||
{ "recurrence_mult", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_recurrence_mult, (QofSetterFunc)set_recurrence_mult },
|
||||
{ "recurrence_period_type", CT_STRING, BUDGET_MAX_RECURRENCE_PERIOD_TYPE_LEN, COL_NNUL, NULL, NULL,
|
||||
get_recurrence_period_type, set_recurrence_period_type },
|
||||
{ "recurrence_period_start", CT_GDATE, 0, COL_NNUL, NULL, NULL,
|
||||
get_recurrence_period_start, set_recurrence_period_start },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* Special column table because we need to be able to access the table by
|
||||
a column other than the primary key */
|
||||
static const GncSqlColumnTableEntry guid_col_table[] =
|
||||
{
|
||||
{ "obj_guid", CT_GUID, 0, 0, NULL, NULL, get_obj_guid, set_obj_guid },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
static gpointer
|
||||
get_obj_guid( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
return (gpointer)pInfo->guid;
|
||||
}
|
||||
|
||||
static void
|
||||
set_obj_guid( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
// Nowhere to put the GUID
|
||||
}
|
||||
|
||||
static gint
|
||||
get_recurrence_mult( gpointer pObject )
|
||||
{
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, 0 );
|
||||
g_return_val_if_fail( pInfo->pRecurrence != NULL, 0 );
|
||||
|
||||
return pInfo->pRecurrence->mult;
|
||||
}
|
||||
|
||||
static void
|
||||
set_recurrence_mult( gpointer pObject, gint value )
|
||||
{
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pInfo->pRecurrence != NULL );
|
||||
|
||||
pInfo->pRecurrence->mult = value;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
get_recurrence_period_type( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pInfo->pRecurrence != NULL, NULL );
|
||||
|
||||
return (gpointer)recurrencePeriodTypeToString(
|
||||
recurrenceGetPeriodType( pInfo->pRecurrence ) );
|
||||
}
|
||||
|
||||
static void
|
||||
set_recurrence_period_type( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pInfo->pRecurrence != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
pInfo->pRecurrence->ptype = recurrencePeriodTypeFromString( (gchar*)pValue );
|
||||
}
|
||||
|
||||
static gpointer
|
||||
get_recurrence_period_start( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
static GDate date;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pInfo->pRecurrence != NULL, NULL );
|
||||
|
||||
date = recurrenceGetDate( pInfo->pRecurrence );
|
||||
return (gpointer)&date;
|
||||
}
|
||||
|
||||
static void
|
||||
set_recurrence_period_start( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
GDate* date = (GDate*)pValue;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pInfo->pRecurrence != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
pInfo->pRecurrence->start = *date;
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
void
|
||||
gnc_sql_recurrence_save( GncSqlBackend* be, const GUID* guid, const Recurrence* r )
|
||||
{
|
||||
recurrence_info_t recurrence_info;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( guid != NULL );
|
||||
g_return_if_fail( r != NULL );
|
||||
|
||||
gnc_sql_recurrence_delete( be, guid );
|
||||
|
||||
recurrence_info.be = be;
|
||||
recurrence_info.guid = guid;
|
||||
recurrence_info.pRecurrence = (Recurrence*)r;
|
||||
(void)gnc_sql_do_db_operation( be, OP_DB_INSERT, TABLE_NAME,
|
||||
TABLE_NAME, &recurrence_info, col_table );
|
||||
}
|
||||
|
||||
void
|
||||
gnc_sql_recurrence_save_list( GncSqlBackend* be, const GUID* guid, GList* schedule )
|
||||
{
|
||||
recurrence_info_t recurrence_info;
|
||||
GList* l;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( guid != NULL );
|
||||
|
||||
gnc_sql_recurrence_delete( be, guid );
|
||||
|
||||
recurrence_info.be = be;
|
||||
recurrence_info.guid = guid;
|
||||
for( l = schedule; l != NULL; l = g_list_next( l ) ) {
|
||||
recurrence_info.pRecurrence = (Recurrence*)l->data;
|
||||
(void)gnc_sql_do_db_operation( be, OP_DB_INSERT, TABLE_NAME,
|
||||
TABLE_NAME, &recurrence_info, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gnc_sql_recurrence_delete( GncSqlBackend* be, const GUID* guid )
|
||||
{
|
||||
recurrence_info_t recurrence_info;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( guid != NULL );
|
||||
|
||||
recurrence_info.be = be;
|
||||
recurrence_info.guid = guid;
|
||||
(void)gnc_sql_do_db_operation( be, OP_DB_DELETE, TABLE_NAME,
|
||||
TABLE_NAME, &recurrence_info, guid_col_table );
|
||||
}
|
||||
|
||||
static void
|
||||
load_recurrence( GncSqlBackend* be, GncSqlRow* row, Recurrence* r )
|
||||
{
|
||||
recurrence_info_t recurrence_info;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( r != NULL );
|
||||
|
||||
recurrence_info.be = be;
|
||||
recurrence_info.pRecurrence = r;
|
||||
|
||||
gnc_sql_load_object( be, row, TABLE_NAME, &recurrence_info, col_table );
|
||||
}
|
||||
|
||||
static GncSqlResult*
|
||||
gnc_sql_set_recurrences_from_db( GncSqlBackend* be, const GUID* guid )
|
||||
{
|
||||
gchar* buf;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
gchar* field_name;
|
||||
GncSqlStatement* stmt;
|
||||
GError* error = NULL;
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( guid != NULL, NULL );
|
||||
|
||||
guid_to_string_buff( guid, guid_buf );
|
||||
buf = g_strdup_printf( "SELECT * FROM %s WHERE obj_guid='%s'", TABLE_NAME, guid_buf );
|
||||
stmt = gnc_sql_connection_create_statement_from_sql( be->conn, buf );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_sql_recurrence_load( GncSqlBackend* be, const GUID* guid, Recurrence* pRecurrence )
|
||||
{
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( guid != NULL );
|
||||
g_return_if_fail( pRecurrence != NULL );
|
||||
|
||||
result = gnc_sql_set_recurrences_from_db( be, guid );
|
||||
if( result != NULL ) {
|
||||
int numRows = gnc_sql_result_get_num_rows( result );
|
||||
|
||||
if( numRows > 0 ) {
|
||||
if( numRows > 1 ) {
|
||||
g_warning( "More than 1 recurrence found: first one used" );
|
||||
}
|
||||
load_recurrence( be, gnc_sql_result_get_first_row( result ),
|
||||
pRecurrence );
|
||||
} else {
|
||||
g_warning( "No recurrences found" );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gnc_sql_recurrence_load_list( GncSqlBackend* be, const GUID* guid, GList** pSchedule )
|
||||
{
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( guid != NULL );
|
||||
g_return_if_fail( pSchedule != NULL );
|
||||
|
||||
result = gnc_sql_set_recurrences_from_db( be, guid );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
|
||||
while( row != NULL ) {
|
||||
Recurrence* pRecurrence = g_new0( Recurrence, 1 );
|
||||
load_recurrence( be, row, pRecurrence );
|
||||
*pSchedule = g_list_append( *pSchedule, pRecurrence );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_recurrence_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_recurrence_handler( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_ACCOUNT,
|
||||
NULL, /* commit - cannot occur */
|
||||
NULL, /* initial_load - cannot occur */
|
||||
create_recurrence_tables /* create_tables */
|
||||
};
|
||||
|
||||
qof_object_register_backend( TABLE_NAME, GNC_SQL_BACKEND, &be_data );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
43
src/backend/sql/gnc-recurrence-sql.h
Normal file
43
src/backend/sql/gnc-recurrence-sql.h
Normal file
@ -0,0 +1,43 @@
|
||||
/********************************************************************
|
||||
* gnc-recurrence-sql.h: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-recurrence-sql.h
|
||||
* @brief load and save accounts data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_RECURRENCE_SQL_H_
|
||||
#define GNC_RECURRENCE_SQL_H_
|
||||
|
||||
#include "qof.h"
|
||||
#include <gmodule.h>
|
||||
|
||||
void gnc_sql_recurrence_save( GncSqlBackend* be, const GUID* guid, const Recurrence* pRecurrence );
|
||||
void gnc_sql_recurrence_save_list( GncSqlBackend* be, const GUID* guid, GList* schedule );
|
||||
void gnc_sql_recurrence_delete( GncSqlBackend* be, const GUID* guid );
|
||||
void gnc_sql_recurrence_load( GncSqlBackend* be, const GUID* guid, Recurrence* pRecurrence );
|
||||
void gnc_sql_recurrence_load_list( GncSqlBackend* be, const GUID* guid, GList** pSchedule );
|
||||
|
||||
void gnc_sql_init_recurrence_handler( void );
|
||||
|
||||
#endif /* GNC_RECURRENCE_SQL_H_ */
|
312
src/backend/sql/gnc-schedxaction-sql.c
Normal file
312
src/backend/sql/gnc-schedxaction-sql.c
Normal file
@ -0,0 +1,312 @@
|
||||
/********************************************************************
|
||||
* gnc-schedxaction-sql.c: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-schedxaction-sql.c
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL db
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "qof.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
|
||||
#include "gnc-schedxaction-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
|
||||
#include "SchedXaction.h"
|
||||
#include "SX-book.h"
|
||||
#include "Recurrence.h"
|
||||
|
||||
#include "gnc-recurrence-sql.h"
|
||||
|
||||
#define SCHEDXACTION_TABLE "schedxactions"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define SX_MAX_NAME_LEN 2048
|
||||
|
||||
static gboolean get_autocreate( gpointer pObject );
|
||||
static void set_autocreate( gpointer pObject, gboolean value );
|
||||
static gboolean get_autonotify( gpointer pObject );
|
||||
static void set_autonotify( gpointer pObject, gboolean value );
|
||||
static gint get_instance_count( gpointer pObject );
|
||||
static gpointer get_template_act_guid( gpointer pObject, const QofParam* param );
|
||||
static void set_template_act_guid( gpointer pObject, gpointer pValue );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "name", CT_STRING, SX_MAX_NAME_LEN, 0, NULL, GNC_SX_NAME },
|
||||
{ "enabled", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)xaccSchedXactionGetEnabled, (QofSetterFunc)xaccSchedXactionSetEnabled },
|
||||
{ "start_date", CT_GDATE, 0, COL_NNUL, NULL, GNC_SX_START_DATE },
|
||||
{ "last_occur", CT_GDATE, 0, 0, NULL, GNC_SX_LAST_DATE },
|
||||
{ "num_occur", CT_INT, 0, COL_NNUL, NULL, GNC_SX_NUM_OCCUR },
|
||||
{ "rem_occur", CT_INT, 0, COL_NNUL, NULL, GNC_SX_REM_OCCUR },
|
||||
{ "auto_create", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_autocreate, (QofSetterFunc)set_autocreate },
|
||||
{ "auto_notify", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_autonotify, (QofSetterFunc)set_autonotify },
|
||||
{ "adv_creation", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)xaccSchedXactionGetAdvanceCreation,
|
||||
(QofSetterFunc)xaccSchedXactionSetAdvanceCreation },
|
||||
{ "adv_notify", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)xaccSchedXactionGetAdvanceReminder,
|
||||
(QofSetterFunc)xaccSchedXactionSetAdvanceReminder },
|
||||
{ "instance_count", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_instance_count, (QofSetterFunc)gnc_sx_set_instance_count },
|
||||
{ "template_act_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
get_template_act_guid, set_template_act_guid },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
static gboolean
|
||||
get_autocreate( gpointer pObject )
|
||||
{
|
||||
const SchedXaction* pSx = GNC_SX(pObject);
|
||||
gboolean autoCreate;
|
||||
gboolean autoNotify;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_SX(pObject), FALSE );
|
||||
|
||||
xaccSchedXactionGetAutoCreate( pSx, &autoCreate, &autoNotify );
|
||||
return autoCreate;
|
||||
}
|
||||
|
||||
static void
|
||||
set_autocreate( gpointer pObject, gboolean value )
|
||||
{
|
||||
SchedXaction* pSx = GNC_SX(pObject);
|
||||
gboolean autoNotify;
|
||||
gboolean dummy;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_SX(pObject) );
|
||||
|
||||
xaccSchedXactionGetAutoCreate( pSx, &dummy, &autoNotify );
|
||||
xaccSchedXactionSetAutoCreate( pSx, value, autoNotify );
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_autonotify( gpointer pObject )
|
||||
{
|
||||
const SchedXaction* pSx = GNC_SX(pObject);
|
||||
gboolean autoCreate;
|
||||
gboolean autoNotify;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_SX(pObject), FALSE );
|
||||
|
||||
xaccSchedXactionGetAutoCreate( pSx, &autoCreate, &autoNotify );
|
||||
return autoNotify;
|
||||
}
|
||||
|
||||
static void
|
||||
set_autonotify( gpointer pObject, gboolean value )
|
||||
{
|
||||
SchedXaction* pSx = GNC_SX(pObject);
|
||||
gboolean autoCreate;
|
||||
gboolean dummy;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_SX(pObject) );
|
||||
|
||||
xaccSchedXactionGetAutoCreate( pSx, &autoCreate, &dummy );
|
||||
xaccSchedXactionSetAutoCreate( pSx, autoCreate, value );
|
||||
}
|
||||
|
||||
static gint
|
||||
get_instance_count( gpointer pObject )
|
||||
{
|
||||
const SchedXaction* pSx = GNC_SX(pObject);
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_SX(pObject), FALSE );
|
||||
|
||||
return gnc_sx_get_instance_count( pSx, NULL );
|
||||
}
|
||||
|
||||
static gpointer
|
||||
get_template_act_guid( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
const SchedXaction* pSx = GNC_SX(pObject);
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_SX(pObject), NULL );
|
||||
|
||||
return (gpointer)xaccAccountGetGUID( pSx->template_acct );
|
||||
}
|
||||
|
||||
static void
|
||||
set_template_act_guid( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
SchedXaction* pSx = GNC_SX(pObject);
|
||||
QofBook* pBook;
|
||||
GUID* guid = (GUID*)pValue;
|
||||
Account* pAcct;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_SX(pObject) );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
pBook = qof_instance_get_book( QOF_INSTANCE(pSx) );
|
||||
pAcct = xaccAccountLookup( guid, pBook );
|
||||
sx_set_template_account( pSx, pAcct );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static SchedXaction*
|
||||
load_single_sx( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GUID* guid;
|
||||
GUID sx_guid;
|
||||
SchedXaction* pSx;
|
||||
GList* schedule = NULL;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
sx_guid = *guid;
|
||||
|
||||
pSx = xaccSchedXactionMalloc( be->primary_book );
|
||||
|
||||
gnc_sx_begin_edit( pSx );
|
||||
gnc_sql_load_object( be, row, GNC_SX_ID, pSx, col_table );
|
||||
gnc_sql_recurrence_load_list( be, guid, &schedule );
|
||||
gnc_sx_set_schedule( pSx, schedule );
|
||||
gnc_sx_commit_edit( pSx );
|
||||
|
||||
return pSx;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_sxes( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt = NULL;
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, SCHEDXACTION_TABLE );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row;
|
||||
int r;
|
||||
SchedXactions *sxes;
|
||||
GList* list = NULL;
|
||||
sxes = gnc_book_get_schedxactions( be->primary_book );
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while( row != NULL ) {
|
||||
SchedXaction* sx;
|
||||
|
||||
sx = load_single_sx( be, row );
|
||||
if( sx != NULL ) {
|
||||
gnc_sxes_add_sx( sxes, sx );
|
||||
list = g_list_append( list, sx );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_sx_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, SCHEDXACTION_TABLE );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, SCHEDXACTION_TABLE, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_save_schedxaction( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
SchedXaction* pSx;
|
||||
const GUID* guid;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_SX(inst) );
|
||||
|
||||
pSx = GNC_SX(inst);
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
(void)gnc_sql_do_db_operation( be, op, SCHEDXACTION_TABLE, GNC_SX_ID, pSx, col_table );
|
||||
guid = qof_instance_get_guid( inst );
|
||||
gnc_sql_recurrence_save_list( be, guid, gnc_sx_get_schedule( pSx ) );
|
||||
|
||||
// Now, commit any slots
|
||||
if( !qof_instance_get_destroying(inst) ) {
|
||||
gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
} else {
|
||||
gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_schedxaction_handler( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_SCHEDXACTION,
|
||||
gnc_sql_save_schedxaction, /* commit */
|
||||
load_all_sxes, /* initial_load */
|
||||
create_sx_tables /* create_tables */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_SCHEDXACTION, GNC_SQL_BACKEND, &be_data );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
38
src/backend/sql/gnc-schedxaction-sql.h
Normal file
38
src/backend/sql/gnc-schedxaction-sql.h
Normal file
@ -0,0 +1,38 @@
|
||||
/********************************************************************
|
||||
* gnc-schedxaction-sql.h: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-backend-sql.h
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_SCHEDXACTION_SQL_H_
|
||||
#define GNC_SCHEDXACTION_SQL_H_
|
||||
|
||||
#include "qof.h"
|
||||
#include <gmodule.h>
|
||||
|
||||
void gnc_sql_init_schedxaction_handler( void );
|
||||
void gnc_sql_save_schedxaction( GncSqlBackend* be, QofInstance* inst );
|
||||
|
||||
#endif /* GNC_SCHEDXACTION_SQL_H_ */
|
567
src/backend/sql/gnc-slots-sql.c
Normal file
567
src/backend/sql/gnc-slots-sql.c
Normal file
@ -0,0 +1,567 @@
|
||||
/********************************************************************
|
||||
* gnc-slots-sql.c: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-slots-sql.c
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL db
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "qof.h"
|
||||
#include "gnc-engine.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
|
||||
#include "gnc-slots-sql.h"
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define TABLE_NAME "slots"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
typedef struct {
|
||||
GncSqlBackend* be;
|
||||
const GUID* guid;
|
||||
KvpFrame* pKvpFrame;
|
||||
KvpValueType value_type;
|
||||
KvpValue* pKvpValue;
|
||||
GString* path;
|
||||
} slot_info_t;
|
||||
|
||||
static gpointer get_obj_guid( gpointer pObject, const QofParam* param );
|
||||
static void set_obj_guid( gpointer pObject, gpointer pValue );
|
||||
static gpointer get_path( gpointer pObject, const QofParam* param );
|
||||
static void set_path( gpointer pObject, gpointer pValue );
|
||||
static gpointer get_slot_type( gpointer pObject, const QofParam* param );
|
||||
static void set_slot_type( gpointer pObject, gpointer pValue );
|
||||
static gint64 get_int64_val( gpointer pObject, const QofParam* param );
|
||||
static void set_int64_val( gpointer pObject, gint64 pValue );
|
||||
static gpointer get_string_val( gpointer pObject, const QofParam* param );
|
||||
static void set_string_val( gpointer pObject, gpointer pValue );
|
||||
static gpointer get_double_val( gpointer pObject, const QofParam* param );
|
||||
static void set_double_val( gpointer pObject, gpointer pValue );
|
||||
static Timespec get_timespec_val( gpointer pObject, const QofParam* param );
|
||||
static void set_timespec_val( gpointer pObject, Timespec ts );
|
||||
static gpointer get_guid_val( gpointer pObject, const QofParam* param );
|
||||
static void set_guid_val( gpointer pObject, gpointer pValue );
|
||||
static gnc_numeric get_numeric_val( gpointer pObject, const QofParam* param );
|
||||
static void set_numeric_val( gpointer pObject, gnc_numeric value );
|
||||
|
||||
#define SLOT_MAX_PATHNAME_LEN 4096
|
||||
#define SLOT_MAX_STRINGVAL_LEN 4096
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "obj_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
get_obj_guid, set_obj_guid },
|
||||
{ "name", CT_STRING, SLOT_MAX_PATHNAME_LEN, COL_NNUL, NULL, NULL,
|
||||
get_path, set_path },
|
||||
{ "slot_type", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
get_slot_type, set_slot_type, },
|
||||
{ "int64_val", CT_INT64, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_int64_val, (QofSetterFunc)set_int64_val },
|
||||
{ "string_val", CT_STRING, SLOT_MAX_PATHNAME_LEN, 0, NULL, NULL,
|
||||
get_string_val, set_string_val },
|
||||
{ "double_val", CT_DOUBLE, 0, 0, NULL, NULL,
|
||||
get_double_val, set_double_val },
|
||||
{ "timespec_val", CT_TIMESPEC, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_timespec_val, (QofSetterFunc)set_timespec_val },
|
||||
{ "guid_val", CT_GUID, 0, 0, NULL, NULL,
|
||||
get_guid_val, set_guid_val },
|
||||
{ "numeric_val", CT_NUMERIC, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_numeric_val, (QofSetterFunc)set_numeric_val },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* Special column table because we need to be able to access the table by
|
||||
a column other than the primary key */
|
||||
static const GncSqlColumnTableEntry obj_guid_col_table[] =
|
||||
{
|
||||
{ "obj_guid", CT_GUID, 0, 0, NULL, NULL, get_obj_guid, _retrieve_guid_ },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
static gpointer
|
||||
get_obj_guid( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
return (gpointer)pInfo->guid;
|
||||
}
|
||||
|
||||
static void
|
||||
set_obj_guid( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
// Nowhere to put the GUID
|
||||
}
|
||||
|
||||
static gpointer
|
||||
get_path( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
return (gpointer)pInfo->path->str;
|
||||
}
|
||||
|
||||
static void
|
||||
set_path( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
pInfo->path = g_string_new( (gchar*)pValue );
|
||||
}
|
||||
|
||||
static gpointer
|
||||
get_slot_type( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
return (gpointer)kvp_value_get_type( pInfo->pKvpValue );
|
||||
}
|
||||
|
||||
static void
|
||||
set_slot_type( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
pInfo->value_type = (KvpValueType)pValue;
|
||||
}
|
||||
|
||||
static gint64
|
||||
get_int64_val( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, 0 );
|
||||
|
||||
if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_GINT64 ) {
|
||||
return kvp_value_get_gint64( pInfo->pKvpValue );
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_int64_val( gpointer pObject, gint64 value )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
if( pInfo->value_type == KVP_TYPE_GINT64 ) {
|
||||
kvp_frame_set_gint64( pInfo->pKvpFrame, pInfo->path->str, value );
|
||||
}
|
||||
}
|
||||
|
||||
static gpointer
|
||||
get_string_val( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_STRING ) {
|
||||
return (gpointer)kvp_value_get_string( pInfo->pKvpValue );
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_string_val( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
if( pInfo->value_type == KVP_TYPE_STRING && pValue != NULL ) {
|
||||
kvp_frame_set_string( pInfo->pKvpFrame, pInfo->path->str, (const gchar*)pValue );
|
||||
}
|
||||
}
|
||||
|
||||
static gpointer
|
||||
get_double_val( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
static double d_val;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_DOUBLE ) {
|
||||
d_val = kvp_value_get_double( pInfo->pKvpValue );
|
||||
return (gpointer)&d_val;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_double_val( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
if( pInfo->value_type == KVP_TYPE_DOUBLE && pValue != NULL ) {
|
||||
kvp_frame_set_double( pInfo->pKvpFrame, pInfo->path->str, *(double*)pValue );
|
||||
}
|
||||
}
|
||||
|
||||
static Timespec
|
||||
get_timespec_val( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, gnc_dmy2timespec( 1, 1, 1970 ) );
|
||||
|
||||
//if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_TIMESPEC ) {
|
||||
return kvp_value_get_timespec( pInfo->pKvpValue );
|
||||
}
|
||||
|
||||
static void
|
||||
set_timespec_val( gpointer pObject, Timespec ts )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
if( pInfo->value_type == KVP_TYPE_TIMESPEC ) {
|
||||
kvp_frame_set_timespec( pInfo->pKvpFrame, pInfo->path->str, ts );
|
||||
}
|
||||
}
|
||||
|
||||
static gpointer
|
||||
get_guid_val( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_GUID ) {
|
||||
return (gpointer)kvp_value_get_guid( pInfo->pKvpValue );
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_guid_val( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
if( pInfo->value_type == KVP_TYPE_GUID && pValue != NULL ) {
|
||||
kvp_frame_set_guid( pInfo->pKvpFrame, pInfo->path->str, (GUID*)pValue );
|
||||
}
|
||||
}
|
||||
|
||||
static gnc_numeric
|
||||
get_numeric_val( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, gnc_numeric_zero() );
|
||||
|
||||
if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_NUMERIC ) {
|
||||
return kvp_value_get_numeric( pInfo->pKvpValue );
|
||||
} else {
|
||||
return gnc_numeric_zero();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_numeric_val( gpointer pObject, gnc_numeric value )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
if( pInfo->value_type == KVP_TYPE_NUMERIC ) {
|
||||
kvp_frame_set_numeric( pInfo->pKvpFrame, pInfo->path->str, value );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
save_slot( const gchar* key, KvpValue* value, gpointer data )
|
||||
{
|
||||
slot_info_t* pSlot_info = (slot_info_t*)data;
|
||||
gint curlen;
|
||||
|
||||
g_return_if_fail( key != NULL );
|
||||
g_return_if_fail( value != NULL );
|
||||
g_return_if_fail( data != NULL );
|
||||
|
||||
curlen = pSlot_info->path->len;
|
||||
pSlot_info->pKvpValue = value;
|
||||
if( curlen != 0 ) {
|
||||
g_string_append( pSlot_info->path, "/" );
|
||||
}
|
||||
g_string_append( pSlot_info->path, key );
|
||||
|
||||
if( kvp_value_get_type( value ) == KVP_TYPE_FRAME ) {
|
||||
KvpFrame* pKvpFrame = kvp_value_get_frame( value );
|
||||
kvp_frame_for_each_slot( pKvpFrame, save_slot, pSlot_info );
|
||||
} else {
|
||||
(void)gnc_sql_do_db_operation( pSlot_info->be, OP_DB_INSERT, TABLE_NAME,
|
||||
TABLE_NAME, pSlot_info, col_table );
|
||||
}
|
||||
|
||||
g_string_truncate( pSlot_info->path, curlen );
|
||||
}
|
||||
|
||||
void
|
||||
gnc_sql_slots_save( GncSqlBackend* be, const GUID* guid, gboolean is_infant, KvpFrame* pFrame )
|
||||
{
|
||||
slot_info_t slot_info;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( guid != NULL );
|
||||
g_return_if_fail( pFrame != NULL );
|
||||
|
||||
// If this is not saving into a new db, clear out the old saved slots first
|
||||
if( !be->is_pristine_db && !is_infant ) {
|
||||
gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
|
||||
slot_info.be = be;
|
||||
slot_info.guid = guid;
|
||||
slot_info.path = g_string_new( "" );
|
||||
kvp_frame_for_each_slot( pFrame, save_slot, &slot_info );
|
||||
g_string_free( slot_info.path, TRUE );
|
||||
}
|
||||
|
||||
void
|
||||
gnc_sql_slots_delete( GncSqlBackend* be, const GUID* guid )
|
||||
{
|
||||
slot_info_t slot_info;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( guid != NULL );
|
||||
|
||||
slot_info.be = be;
|
||||
slot_info.guid = guid;
|
||||
(void)gnc_sql_do_db_operation( be, OP_DB_DELETE, TABLE_NAME,
|
||||
TABLE_NAME, &slot_info, obj_guid_col_table );
|
||||
}
|
||||
|
||||
static void
|
||||
load_slot( GncSqlBackend* be, GncSqlRow* row, KvpFrame* pFrame )
|
||||
{
|
||||
slot_info_t slot_info;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pFrame != NULL );
|
||||
|
||||
slot_info.be = be;
|
||||
slot_info.pKvpFrame = pFrame;
|
||||
slot_info.path = NULL;
|
||||
|
||||
gnc_sql_load_object( be, row, TABLE_NAME, &slot_info, col_table );
|
||||
|
||||
if( slot_info.path != NULL ) {
|
||||
g_string_free( slot_info.path, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gnc_sql_slots_load( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
gchar* buf;
|
||||
GncSqlResult* result;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
gchar* field_name;
|
||||
GncSqlStatement* stmt;
|
||||
GValue value;
|
||||
const GUID* guid;
|
||||
KvpFrame* pFrame;
|
||||
GError* error = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( inst != NULL );
|
||||
|
||||
guid = qof_instance_get_guid( inst );
|
||||
pFrame = qof_instance_get_slots( inst );
|
||||
guid_to_string_buff( guid, guid_buf );
|
||||
memset( &value, 0, sizeof( value ) );
|
||||
g_value_init( &value, G_TYPE_STRING );
|
||||
g_value_set_string( &value, guid_buf );
|
||||
|
||||
buf = g_strdup_printf( "SELECT * FROM %s WHERE obj_guid='%s'", TABLE_NAME, guid_buf );
|
||||
stmt = gnc_sql_create_statement_from_sql( be, buf );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
|
||||
while( row != NULL ) {
|
||||
load_slot( be, row, pFrame );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
}
|
||||
|
||||
static const GUID*
|
||||
load_obj_guid( const GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
static GUID guid;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
gnc_sql_load_object( be, row, NULL, &guid, obj_guid_col_table );
|
||||
|
||||
return &guid;
|
||||
}
|
||||
|
||||
static void
|
||||
load_slot_for_list_item( GncSqlBackend* be, GncSqlRow* row, QofCollection* coll )
|
||||
{
|
||||
slot_info_t slot_info;
|
||||
const GUID* guid;
|
||||
QofInstance* inst;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( coll != NULL );
|
||||
|
||||
guid = load_obj_guid( be, row );
|
||||
inst = qof_collection_lookup_entity( coll, guid );
|
||||
|
||||
slot_info.be = be;
|
||||
slot_info.pKvpFrame = qof_instance_get_slots( inst );
|
||||
slot_info.path = NULL;
|
||||
|
||||
gnc_sql_load_object( be, row, TABLE_NAME, &slot_info, col_table );
|
||||
|
||||
if( slot_info.path != NULL ) {
|
||||
g_string_free( slot_info.path, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gnc_sql_slots_load_for_list( GncSqlBackend* be, GList* list )
|
||||
{
|
||||
QofCollection* coll;
|
||||
GncSqlStatement* stmt;
|
||||
GString* sql;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
gboolean first_guid = TRUE;
|
||||
GncSqlResult* result;
|
||||
gboolean single_item;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
// Ignore empty list
|
||||
if( list == NULL ) return;
|
||||
|
||||
coll = qof_instance_get_collection( QOF_INSTANCE(list->data) );
|
||||
|
||||
// Create the query for all slots for all items on the list
|
||||
sql = g_string_sized_new( 40+(GUID_ENCODING_LENGTH+3)*g_list_length( list ) );
|
||||
g_string_append_printf( sql, "SELECT * FROM %s WHERE %s ", TABLE_NAME, obj_guid_col_table[0].col_name );
|
||||
if( g_list_length( list ) != 1 ) {
|
||||
g_string_append( sql, "IN (" );
|
||||
single_item = FALSE;
|
||||
} else {
|
||||
g_string_append( sql, "= " );
|
||||
single_item = TRUE;
|
||||
}
|
||||
(void)gnc_sql_append_guid_list_to_sql( sql, list, G_MAXUINT );
|
||||
if( !single_item ) {
|
||||
g_string_append( sql, ")" );
|
||||
}
|
||||
|
||||
// Execute the query and load the slots
|
||||
stmt = gnc_sql_create_statement_from_sql( be, sql->str );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
|
||||
while( row != NULL ) {
|
||||
load_slot_for_list_item( be, row, coll );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
g_string_free( sql, FALSE );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_slots_tables( GncSqlBackend* be )
|
||||
{
|
||||
gboolean ok;
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
#if 0
|
||||
// FIXME: Create index
|
||||
ok = gnc_sql_create_index( be, "slots_guid_index", TABLE_NAME, obj_guid_col_table, &error );
|
||||
if( !ok ) {
|
||||
PERR( "Unable to create index: %s\n", error->message );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_slots_handler( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_ACCOUNT,
|
||||
NULL, /* commit - cannot occur */
|
||||
NULL, /* initial_load - cannot occur */
|
||||
create_slots_tables /* create_tables */
|
||||
};
|
||||
|
||||
qof_object_register_backend( TABLE_NAME, GNC_SQL_BACKEND, &be_data );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
74
src/backend/sql/gnc-slots-sql.h
Normal file
74
src/backend/sql/gnc-slots-sql.h
Normal file
@ -0,0 +1,74 @@
|
||||
/********************************************************************
|
||||
* gnc-slots-sql.h: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-slots-sql.h
|
||||
* @brief load and save accounts data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_SLOTS_SQL_H_
|
||||
#define GNC_SLOTS_SQL_H_
|
||||
|
||||
#include "qof.h"
|
||||
#include <gmodule.h>
|
||||
|
||||
/**
|
||||
* gnc_sql_slots_save - Saves slots for an object to the db.
|
||||
*
|
||||
* @param be SQL backend
|
||||
* @param guid Object guid
|
||||
* @param is_infant Is this an infant object?
|
||||
* @param pFrame Top-level KVP frame
|
||||
*/
|
||||
void gnc_sql_slots_save( GncSqlBackend* be, const GUID* guid,
|
||||
gboolean is_infant, KvpFrame* pFrame );
|
||||
|
||||
/**
|
||||
* gnc_sql_slots_delete - Deletes slots for an object from the db.
|
||||
*
|
||||
* @param be SQL backend
|
||||
* @param guid Object guid
|
||||
*/
|
||||
void gnc_sql_slots_delete( GncSqlBackend* be, const GUID* guid );
|
||||
|
||||
/**
|
||||
* gnc_sql_slots_load - Loads slots for an object from the db.
|
||||
*
|
||||
* @param be SQL backend
|
||||
* @param guid Object guid
|
||||
*/
|
||||
void gnc_sql_slots_load( GncSqlBackend* be, QofInstance* inst );
|
||||
|
||||
/**
|
||||
* gnc_sql_slots_load_for_list - Loads slots for a list of objects from the db.
|
||||
* Loading slots for a list of objects can be faster than loading for one object
|
||||
* at a time because fewer SQL queries are used.
|
||||
*
|
||||
* @param be SQL backend
|
||||
* @param list List of objects
|
||||
*/
|
||||
void gnc_sql_slots_load_for_list( GncSqlBackend* be, GList* list );
|
||||
|
||||
void gnc_sql_init_slots_handler( void );
|
||||
|
||||
#endif /* GNC_SLOTS_SQL_H_ */
|
752
src/backend/sql/gnc-transaction-sql.c
Normal file
752
src/backend/sql/gnc-transaction-sql.c
Normal file
@ -0,0 +1,752 @@
|
||||
/********************************************************************
|
||||
* gnc-transaction-sql.c: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-transaction-sql.c
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL db
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "qof.h"
|
||||
#include "qofquery-p.h"
|
||||
#include "qofquerycore-p.h"
|
||||
|
||||
#include "Account.h"
|
||||
#include "Transaction.h"
|
||||
#include "gnc-lot.h"
|
||||
#include "engine-helpers.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
#include "gnc-transaction-sql.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-commodity-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
|
||||
#include "gnc-engine.h"
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define TRANSACTION_TABLE "transactions"
|
||||
#define TX_TABLE_VERSION 1
|
||||
#define SPLIT_TABLE "splits"
|
||||
#define SPLIT_TABLE_VERSION 1
|
||||
|
||||
typedef struct {
|
||||
GncSqlBackend* be;
|
||||
const GUID* guid;
|
||||
} split_info_t;
|
||||
|
||||
#define TX_MAX_NUM_LEN 2048
|
||||
#define TX_MAX_DESCRIPTION_LEN 2048
|
||||
|
||||
static const GncSqlColumnTableEntry tx_col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "currency_guid", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)xaccTransGetCurrency, (QofSetterFunc)xaccTransSetCurrency },
|
||||
{ "num", CT_STRING, TX_MAX_NUM_LEN, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)xaccTransGetNum, (QofSetterFunc)xaccTransSetNum },
|
||||
{ "post_date", CT_TIMESPEC, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)xaccTransRetDatePostedTS, (QofSetterFunc)gnc_transaction_set_date_posted },
|
||||
{ "enter_date", CT_TIMESPEC, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)xaccTransRetDateEnteredTS, (QofSetterFunc)gnc_transaction_set_date_entered },
|
||||
{ "description", CT_STRING, TX_MAX_DESCRIPTION_LEN, 0, NULL, NULL,
|
||||
(QofAccessFunc)xaccTransGetDescription, (QofSetterFunc)xaccTransSetDescription },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static gpointer get_split_reconcile_state( gpointer pObject, const QofParam* param );
|
||||
static void set_split_reconcile_state( gpointer pObject, gpointer pValue );
|
||||
static void set_split_reconcile_date( gpointer pObject, Timespec ts );
|
||||
static void set_split_lot( gpointer pObject, gpointer pLot );
|
||||
|
||||
#define SPLIT_MAX_MEMO_LEN 2048
|
||||
#define SPLIT_MAX_ACTION_LEN 2048
|
||||
|
||||
static const GncSqlColumnTableEntry split_col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "tx_guid", CT_TXREF, 0, COL_NNUL, NULL, SPLIT_TRANS },
|
||||
{ "account_guid", CT_ACCOUNTREF, 0, COL_NNUL, NULL, SPLIT_ACCOUNT },
|
||||
{ "memo", CT_STRING, SPLIT_MAX_MEMO_LEN, COL_NNUL, NULL, SPLIT_MEMO },
|
||||
{ "action", CT_STRING, SPLIT_MAX_ACTION_LEN, COL_NNUL, NULL, SPLIT_ACTION },
|
||||
{ "reconcile_state", CT_STRING, 1, COL_NNUL, NULL, NULL,
|
||||
get_split_reconcile_state, set_split_reconcile_state },
|
||||
{ "reconcile_date", CT_TIMESPEC, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)xaccSplitRetDateReconciledTS, (QofSetterFunc)set_split_reconcile_date },
|
||||
{ "value", CT_NUMERIC, 0, COL_NNUL, NULL, SPLIT_VALUE },
|
||||
{ "quantity", CT_NUMERIC, 0, COL_NNUL, NULL, SPLIT_AMOUNT },
|
||||
{ "lot_guid", CT_LOTREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)xaccSplitGetLot, set_split_lot },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static const GncSqlColumnTableEntry guid_col_table[] =
|
||||
{
|
||||
{ "tx_guid", CT_GUID, 0, 0, "guid" },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static void retrieve_numeric_value( gpointer pObject, gnc_numeric value );
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
static gpointer
|
||||
get_split_reconcile_state( gpointer pObject, const QofParam* param )
|
||||
{
|
||||
const Split* pSplit = GNC_SPLIT(pObject);
|
||||
static gchar c[2];
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_SPLIT(pObject), NULL );
|
||||
|
||||
c[0] = xaccSplitGetReconcile( pSplit );
|
||||
c[1] = '\0';
|
||||
return (gpointer)c;
|
||||
}
|
||||
|
||||
static void
|
||||
set_split_reconcile_state( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
Split* pSplit = GNC_SPLIT(pObject);
|
||||
const gchar* s = (const gchar*)pValue;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_SPLIT(pObject) );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
xaccSplitSetReconcile( pSplit, s[0] );
|
||||
}
|
||||
|
||||
static void
|
||||
set_split_reconcile_date( gpointer pObject, Timespec ts )
|
||||
{
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_SPLIT(pObject) );
|
||||
|
||||
xaccSplitSetDateReconciledTS( GNC_SPLIT(pObject), &ts );
|
||||
}
|
||||
|
||||
static void
|
||||
retrieve_numeric_value( gpointer pObject, gnc_numeric value )
|
||||
{
|
||||
gnc_numeric* pResult = (gnc_numeric*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
*pResult = value;
|
||||
}
|
||||
|
||||
static void
|
||||
set_split_lot( gpointer pObject, gpointer pLot )
|
||||
{
|
||||
GNCLot* lot;
|
||||
Split* split;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_SPLIT(pObject) );
|
||||
|
||||
if( pLot == NULL ) return;
|
||||
|
||||
g_return_if_fail( GNC_IS_LOT(pLot) );
|
||||
|
||||
split = GNC_SPLIT(pObject);
|
||||
lot = GNC_LOT(pLot);
|
||||
gnc_lot_add_split( lot, split );
|
||||
}
|
||||
|
||||
// Table to retrieve just the quantity
|
||||
static GncSqlColumnTableEntry quantity_table[] =
|
||||
{
|
||||
{ "quantity", CT_NUMERIC, 0, COL_NNUL, NULL, NULL, NULL, (QofSetterFunc)retrieve_numeric_value },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static gnc_numeric
|
||||
get_gnc_numeric_from_row( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
gnc_numeric val = gnc_numeric_zero();
|
||||
|
||||
g_return_val_if_fail( be != NULL, val );
|
||||
g_return_val_if_fail( row != NULL, val );
|
||||
|
||||
gnc_sql_load_object( be, row, NULL, &val, quantity_table );
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static Split*
|
||||
load_single_split( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GUID* guid;
|
||||
GUID split_guid;
|
||||
Split* pSplit;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
split_guid = *guid;
|
||||
|
||||
pSplit = xaccSplitLookup( &split_guid, be->primary_book );
|
||||
if( pSplit == NULL ) {
|
||||
pSplit = xaccMallocSplit( be->primary_book );
|
||||
}
|
||||
|
||||
/* If the split is dirty, don't overwrite it */
|
||||
if( !qof_instance_is_dirty( QOF_INSTANCE(pSplit) ) ) {
|
||||
gnc_sql_load_object( be, row, GNC_ID_SPLIT, pSplit, split_col_table );
|
||||
}
|
||||
|
||||
g_assert( pSplit == xaccSplitLookup( &split_guid, be->primary_book ) );
|
||||
|
||||
return pSplit;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_splits_for_tx( GncSqlBackend* be, const GUID* tx_guid )
|
||||
{
|
||||
GncSqlResult* result;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
GncSqlStatement* stmt;
|
||||
GValue value;
|
||||
gchar* buf;
|
||||
GError* error = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( tx_guid != NULL );
|
||||
|
||||
guid_to_string_buff( tx_guid, guid_buf );
|
||||
memset( &value, 0, sizeof( GValue ) );
|
||||
g_value_init( &value, G_TYPE_STRING );
|
||||
g_value_set_string( &value, guid_buf );
|
||||
|
||||
buf = g_strdup_printf( "SELECT * FROM %s WHERE tx_guid='%s'", SPLIT_TABLE, guid_buf );
|
||||
stmt = gnc_sql_create_statement_from_sql( be, buf );
|
||||
g_free( buf );
|
||||
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
int r;
|
||||
GList* list = NULL;
|
||||
GncSqlRow* row;
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while( row != NULL ) {
|
||||
Split* s;
|
||||
|
||||
s = load_single_split( be, row );
|
||||
if( s != NULL ) {
|
||||
list = g_list_append( list, s );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
load_splits_for_tx_list( GncSqlBackend* be, GList* list )
|
||||
{
|
||||
GString* sql;
|
||||
QofCollection* col;
|
||||
GncSqlResult* result;
|
||||
gboolean first_guid = TRUE;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
if( list == NULL ) return;
|
||||
|
||||
sql = g_string_sized_new( 40+(GUID_ENCODING_LENGTH+3)*g_list_length( list ) );
|
||||
g_string_append_printf( sql, "SELECT * FROM %s WHERE %s IN (", SPLIT_TABLE, guid_col_table[0].col_name );
|
||||
(void)gnc_sql_append_guid_list_to_sql( sql, list, G_MAXUINT );
|
||||
g_string_append( sql, ")" );
|
||||
|
||||
// Execute the query and load the splits
|
||||
result = gnc_sql_execute_select_sql( be, sql->str );
|
||||
if( result != NULL ) {
|
||||
GList* list = NULL;
|
||||
GncSqlRow* row;
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while( row != NULL ) {
|
||||
Split* s;
|
||||
s = load_single_split( be, row );
|
||||
if( s != NULL ) {
|
||||
list = g_list_append( list, s );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
g_string_free( sql, FALSE );
|
||||
}
|
||||
|
||||
static Transaction*
|
||||
load_single_tx( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GUID* guid;
|
||||
GUID tx_guid;
|
||||
Transaction* pTx;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
tx_guid = *guid;
|
||||
|
||||
pTx = xaccTransLookup( &tx_guid, be->primary_book );
|
||||
if( pTx == NULL ) {
|
||||
pTx = xaccMallocTransaction( be->primary_book );
|
||||
}
|
||||
xaccTransBeginEdit( pTx );
|
||||
gnc_sql_load_object( be, row, GNC_ID_TRANS, pTx, tx_col_table );
|
||||
|
||||
g_assert( pTx == xaccTransLookup( &tx_guid, be->primary_book ) );
|
||||
|
||||
return pTx;
|
||||
}
|
||||
|
||||
static void
|
||||
query_transactions( GncSqlBackend* be, GncSqlStatement* stmt )
|
||||
{
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( stmt != NULL );
|
||||
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
if( result != NULL ) {
|
||||
GList* tx_list = NULL;
|
||||
GList* node;
|
||||
GncSqlRow* row;
|
||||
Transaction* tx;
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while( row != NULL ) {
|
||||
tx = load_single_tx( be, row );
|
||||
if( tx != NULL ) {
|
||||
tx_list = g_list_append( tx_list, tx );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( tx_list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, tx_list );
|
||||
load_splits_for_tx_list( be, tx_list );
|
||||
}
|
||||
|
||||
// Commit all of the transactions
|
||||
for( node = tx_list; node != NULL; node = node->next ) {
|
||||
Transaction* pTx = GNC_TRANSACTION(node->data);
|
||||
xaccTransCommitEdit( pTx );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
load_tx_by_guid( GncSqlBackend* be, GUID* tx_guid )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
gchar* sql;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( tx_guid != NULL );
|
||||
|
||||
guid_to_string_buff( tx_guid, guid_buf );
|
||||
sql = g_strdup_printf( "SELECT * FROM %s WHERE guid = %s", TRANSACTION_TABLE, guid_buf );
|
||||
stmt = gnc_sql_create_statement_from_sql( be, sql );
|
||||
query_transactions( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
load_all_tx( GncSqlBackend* be )
|
||||
{
|
||||
gchar* sql;
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
sql = g_strdup_printf( "SELECT * FROM %s", TRANSACTION_TABLE );
|
||||
stmt = gnc_sql_create_statement_from_sql( be, sql );
|
||||
query_transactions( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_transaction_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TRANSACTION_TABLE );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TRANSACTION_TABLE, TX_TABLE_VERSION, tx_col_table );
|
||||
}
|
||||
|
||||
version = gnc_sql_get_table_version( be, SPLIT_TABLE );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, SPLIT_TABLE, SPLIT_TABLE_VERSION, split_col_table );
|
||||
}
|
||||
}
|
||||
/* ================================================================= */
|
||||
static void
|
||||
delete_split_slots_cb( gpointer data, gpointer user_data )
|
||||
{
|
||||
split_info_t* split_info = (split_info_t*)user_data;
|
||||
Split* pSplit = GNC_SPLIT(data);
|
||||
|
||||
g_return_if_fail( data != NULL );
|
||||
g_return_if_fail( GNC_IS_SPLIT(data) );
|
||||
g_return_if_fail( user_data != NULL );
|
||||
|
||||
gnc_sql_slots_delete( split_info->be,
|
||||
qof_instance_get_guid( QOF_INSTANCE(pSplit) ) );
|
||||
}
|
||||
|
||||
static void
|
||||
delete_splits( GncSqlBackend* be, Transaction* pTx )
|
||||
{
|
||||
split_info_t split_info;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( pTx != NULL );
|
||||
|
||||
(void)gnc_sql_do_db_operation( be, OP_DB_DELETE, SPLIT_TABLE,
|
||||
SPLIT_TABLE, pTx, guid_col_table );
|
||||
split_info.be = be;
|
||||
|
||||
g_list_foreach( xaccTransGetSplitList( pTx ), delete_split_slots_cb, &split_info );
|
||||
}
|
||||
|
||||
static void
|
||||
commit_split( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
(void)gnc_sql_do_db_operation( be, op, SPLIT_TABLE, GNC_ID_SPLIT, inst, split_col_table );
|
||||
gnc_sql_slots_save( be,
|
||||
qof_instance_get_guid( inst ),
|
||||
is_infant,
|
||||
qof_instance_get_slots( inst ) );
|
||||
}
|
||||
|
||||
static void
|
||||
save_split_cb( gpointer data, gpointer user_data )
|
||||
{
|
||||
split_info_t* split_info = (split_info_t*)user_data;
|
||||
Split* pSplit = GNC_SPLIT(data);
|
||||
|
||||
g_return_if_fail( data != NULL );
|
||||
g_return_if_fail( GNC_IS_SPLIT(data) );
|
||||
g_return_if_fail( user_data != NULL );
|
||||
|
||||
commit_split( split_info->be, QOF_INSTANCE(pSplit) );
|
||||
}
|
||||
|
||||
static void
|
||||
save_splits( GncSqlBackend* be, const GUID* tx_guid, SplitList* pSplitList )
|
||||
{
|
||||
split_info_t split_info;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( tx_guid != NULL );
|
||||
g_return_if_fail( pSplitList != NULL );
|
||||
|
||||
split_info.be = be;
|
||||
split_info.guid = tx_guid;
|
||||
g_list_foreach( pSplitList, save_split_cb, &split_info );
|
||||
}
|
||||
|
||||
static void
|
||||
save_transaction( GncSqlBackend* be, Transaction* pTx, gboolean do_save_splits )
|
||||
{
|
||||
const GUID* guid;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
QofInstance* inst;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( pTx != NULL );
|
||||
|
||||
inst = QOF_INSTANCE(pTx);
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
|
||||
if( op != OP_DB_DELETE ) {
|
||||
// Ensure the commodity is in the db
|
||||
gnc_sql_save_commodity( be, xaccTransGetCurrency( pTx ) );
|
||||
}
|
||||
|
||||
(void)gnc_sql_do_db_operation( be, op, TRANSACTION_TABLE, GNC_ID_TRANS, pTx, tx_col_table );
|
||||
|
||||
// Commit slots and splits
|
||||
guid = qof_instance_get_guid( inst );
|
||||
if( !qof_instance_get_destroying(inst) ) {
|
||||
gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
if( do_save_splits ) {
|
||||
save_splits( be, guid, xaccTransGetSplitList( pTx ) );
|
||||
}
|
||||
} else {
|
||||
gnc_sql_slots_delete( be, guid );
|
||||
delete_splits( be, pTx );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gnc_sql_save_transaction( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_TRANS(inst) );
|
||||
|
||||
save_transaction( be, GNC_TRANS(inst), TRUE );
|
||||
}
|
||||
|
||||
static void
|
||||
commit_transaction( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_TRANS(inst) );
|
||||
|
||||
save_transaction( be, GNC_TRANS(inst), FALSE );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static const GUID*
|
||||
get_guid_from_query( QofQuery* pQuery )
|
||||
{
|
||||
GList* pOrTerms;
|
||||
GList* pAndTerms;
|
||||
GList* andTerm;
|
||||
QofQueryTerm* pTerm;
|
||||
QofQueryPredData* pPredData;
|
||||
GSList* pParamPath;
|
||||
|
||||
g_return_val_if_fail( pQuery != NULL, NULL );
|
||||
|
||||
pOrTerms = qof_query_get_terms( pQuery );
|
||||
pAndTerms = (GList*)pOrTerms->data;
|
||||
andTerm = pAndTerms->next;
|
||||
pTerm = (QofQueryTerm*)andTerm->data;
|
||||
|
||||
pPredData = qof_query_term_get_pred_data( pTerm );
|
||||
pParamPath = qof_query_term_get_param_path( pTerm );
|
||||
|
||||
if( strcmp( pPredData->type_name, "guid" ) == 0 ) {
|
||||
query_guid_t pData = (query_guid_t)pPredData;
|
||||
return pData->guids->data;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static gpointer
|
||||
compile_split_query( GncSqlBackend* be, QofQuery* pQuery )
|
||||
{
|
||||
GString* sql;
|
||||
const GUID* acct_guid;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
GncSqlResult* result;
|
||||
gchar* buf;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( pQuery != NULL, NULL );
|
||||
|
||||
acct_guid = get_guid_from_query( pQuery );
|
||||
guid_to_string_buff( acct_guid, guid_buf );
|
||||
sql = g_string_new( "" );
|
||||
g_string_printf( sql, "SELECT DISTINCT tx_guid FROM %s WHERE account_guid='%s'", SPLIT_TABLE, guid_buf );
|
||||
result = gnc_sql_execute_select_sql( be, sql->str );
|
||||
if( result != NULL ) {
|
||||
int numRows;
|
||||
int r;
|
||||
GncSqlRow* row;
|
||||
|
||||
numRows = gnc_sql_result_get_num_rows( result );
|
||||
sql = g_string_sized_new( 40+(GUID_ENCODING_LENGTH+3)*numRows );
|
||||
|
||||
if( numRows != 1 ) {
|
||||
g_string_printf( sql, "SELECT * FROM %s WHERE guid IN (", TRANSACTION_TABLE );
|
||||
} else {
|
||||
g_string_printf( sql, "SELECT * FROM %s WHERE guid =", TRANSACTION_TABLE );
|
||||
}
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
for( r = 0; row != NULL; r++ ) {
|
||||
const GUID* guid;
|
||||
|
||||
guid = gnc_sql_load_tx_guid( be, row );
|
||||
guid_to_string_buff( guid, guid_buf );
|
||||
if( r != 0 ) {
|
||||
g_string_append( sql, "," );
|
||||
}
|
||||
g_string_append( sql, "'" );
|
||||
g_string_append( sql, guid_buf );
|
||||
g_string_append( sql, "'" );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( numRows != 1 ) {
|
||||
g_string_append( sql, ")" );
|
||||
}
|
||||
}
|
||||
|
||||
buf = sql->str;
|
||||
g_string_free( sql, FALSE );
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void
|
||||
run_split_query( GncSqlBackend* be, gpointer pQuery )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
gchar* sql;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( pQuery != NULL );
|
||||
|
||||
sql = (gchar*)pQuery;
|
||||
|
||||
stmt = gnc_sql_create_statement_from_sql( be, sql );
|
||||
query_transactions( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
}
|
||||
|
||||
static void
|
||||
free_split_query( GncSqlBackend* be, gpointer pQuery )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( pQuery != NULL );
|
||||
|
||||
g_free( pQuery );
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
static void
|
||||
load_tx_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
{
|
||||
const GValue* val;
|
||||
GUID guid;
|
||||
const GUID* pGuid;
|
||||
Transaction* tx = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val == NULL ) {
|
||||
pGuid = NULL;
|
||||
} else {
|
||||
string_to_guid( g_value_get_string( val ), &guid );
|
||||
pGuid = &guid;
|
||||
}
|
||||
if( pGuid != NULL ) {
|
||||
tx = xaccTransLookup( pGuid, be->primary_book );
|
||||
}
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, tx, NULL );
|
||||
} else {
|
||||
(*setter)( pObject, (const gpointer)tx );
|
||||
}
|
||||
}
|
||||
|
||||
static col_type_handler_t tx_guid_handler
|
||||
= { load_tx_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist };
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_transaction_handler( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data_tx =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_TRANS,
|
||||
commit_transaction, /* commit */
|
||||
load_all_tx, /* initial_load */
|
||||
create_transaction_tables /* create tables */
|
||||
};
|
||||
static GncSqlObjectBackend be_data_split =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_SPLIT,
|
||||
commit_split, /* commit */
|
||||
NULL, /* initial_load */
|
||||
NULL, /* create tables */
|
||||
compile_split_query,
|
||||
run_split_query,
|
||||
free_split_query
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_TRANS, GNC_SQL_BACKEND, &be_data_tx );
|
||||
qof_object_register_backend( GNC_ID_SPLIT, GNC_SQL_BACKEND, &be_data_split );
|
||||
|
||||
gnc_sql_register_col_type_handler( CT_TXREF, &tx_guid_handler );
|
||||
}
|
||||
|
||||
/* ========================== END OF FILE ===================== */
|
51
src/backend/sql/gnc-transaction-sql.h
Normal file
51
src/backend/sql/gnc-transaction-sql.h
Normal file
@ -0,0 +1,51 @@
|
||||
/********************************************************************
|
||||
* gnc-transaction-sql.h: load and save data to SQL *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/** @file gnc-transaction-sql.h
|
||||
* @brief load and save data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_TRANSACTION_SQL_H_
|
||||
#define GNC_TRANSACTION_SQL_H_
|
||||
|
||||
#include "qof.h"
|
||||
#include <gmodule.h>
|
||||
|
||||
void gnc_sql_init_transaction_handler( void );
|
||||
void gnc_sql_transaction_commit_splits( GncSqlBackend* be, Transaction* pTx );
|
||||
void gnc_sql_save_transaction( GncSqlBackend* be, QofInstance* inst );
|
||||
void gnc_sql_get_account_balances( GncSqlBackend* be, Account* pAccount,
|
||||
gnc_numeric* start_balance,
|
||||
gnc_numeric* cleared_balance,
|
||||
gnc_numeric* reconciled_balance );
|
||||
|
||||
typedef struct {
|
||||
Account* acct;
|
||||
gnc_numeric start_balance;
|
||||
gnc_numeric cleared_balance;
|
||||
gnc_numeric reconciled_balance;
|
||||
} acct_balances_t;
|
||||
GList* gnc_sql_get_account_balances_for_list( GncSqlBackend* be, GList* list );
|
||||
|
||||
#endif /* GNC_TRANSACTION_SQL_H_ */
|
61
src/backend/sql/test/Makefile.am
Normal file
61
src/backend/sql/test/Makefile.am
Normal file
@ -0,0 +1,61 @@
|
||||
SUBDIRS = .
|
||||
|
||||
test_column_types_SOURCES = \
|
||||
${top_srcdir}/src/backend/sql/gnc-backend-sql.c \
|
||||
${top_srcdir}/src/backend/sql/gnc-account-sql.c \
|
||||
${top_srcdir}/src/backend/sql/gnc-book-sql.c \
|
||||
${top_srcdir}/src/backend/sql/gnc-budget-sql.c \
|
||||
${top_srcdir}/src/backend/sql/gnc-commodity-sql.c \
|
||||
${top_srcdir}/src/backend/sql/gnc-lots-sql.c \
|
||||
${top_srcdir}/src/backend/sql/gnc-price-sql.c \
|
||||
${top_srcdir}/src/backend/sql/gnc-recurrence-sql.c \
|
||||
${top_srcdir}/src/backend/sql/gnc-schedxaction-sql.c \
|
||||
${top_srcdir}/src/backend/sql/gnc-slots-sql.c \
|
||||
${top_srcdir}/src/backend/sql/gnc-transaction-sql.c \
|
||||
test-column-types.c
|
||||
|
||||
TESTS = \
|
||||
test-column-types
|
||||
|
||||
GNC_TEST_DEPS := \
|
||||
--gnc-module-dir ${top_builddir}/src/engine \
|
||||
--guile-load-dir ${top_builddir}/src/engine \
|
||||
--library-dir ${top_builddir}/lib/libqof/qof \
|
||||
--library-dir ${top_builddir}/src/core-utils \
|
||||
--library-dir ${top_builddir}/src/gnc-module \
|
||||
--library-dir ${top_builddir}/src/engine \
|
||||
--library-dir ${top_builddir}/src/backend/sql
|
||||
|
||||
TESTS_ENVIRONMENT := \
|
||||
GNC_ACCOUNT_PATH=${top_srcdir}/accounts/C \
|
||||
SRCDIR=${srcdir} \
|
||||
$(shell ${top_srcdir}/src/gnc-test-env --no-exports ${GNC_TEST_DEPS})
|
||||
|
||||
check_PROGRAMS = \
|
||||
test-column-types
|
||||
|
||||
#noinst_HEADERS = test-file-stuff.h
|
||||
|
||||
LDADD = ${top_builddir}/src/test-core/libgncmod-test.la \
|
||||
${top_builddir}/src/gnc-module/libgnc-module.la \
|
||||
${top_builddir}/src/engine/libgncmod-engine.la \
|
||||
${top_builddir}/src/engine/test-core/libgncmod-test-engine.la \
|
||||
${top_builddir}/src/core-utils/libgnc-core-utils.la \
|
||||
${QOF_LIBS} \
|
||||
${top_builddir}/lib/libc/libc-missing.la
|
||||
|
||||
AM_CFLAGS = \
|
||||
-I${top_srcdir}/lib/libc \
|
||||
-I${top_srcdir}/src \
|
||||
-I${top_srcdir}/src/core-utils \
|
||||
-I${top_srcdir}/src/gnc-module \
|
||||
-I${top_srcdir}/src/test-core \
|
||||
-I${top_srcdir}/src/engine \
|
||||
-I${top_srcdir}/src/engine/test-core \
|
||||
-I${top_srcdir}/src/backend/sql \
|
||||
${GLIB_CFLAGS} \
|
||||
${QOF_CFLAGS} \
|
||||
${GUILE_INCS} \
|
||||
${GCONF_CFLAGS}
|
||||
|
||||
INCLUDES = -DG_LOG_DOMAIN=\"gnc.backend.sql\"
|
46
src/backend/sql/test/test-column-types.c
Normal file
46
src/backend/sql/test/test-column-types.c
Normal file
@ -0,0 +1,46 @@
|
||||
/***************************************************************************
|
||||
* test-column-types.c
|
||||
*
|
||||
* Tests the basic SQL column types
|
||||
*
|
||||
* Copyright 2008 Phil Longstaff
|
||||
* plongstaff@rogers.com
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "qof.h"
|
||||
#include "cashobjects.h"
|
||||
#include "test-stuff.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
qof_init();
|
||||
cashobjects_register();
|
||||
gnc_sql_init( NULL );
|
||||
/* do_test(
|
||||
qof_load_backend_library ("../.libs/", GNC_LIB_NAME),
|
||||
" loading gnc-backend-gda GModule failed");
|
||||
*/
|
||||
print_test_results();
|
||||
qof_close();
|
||||
exit( get_rv() );
|
||||
}
|
@ -32,6 +32,7 @@ gnucash: gnucash.in ${top_builddir}/config.status Makefile
|
||||
rm -f $@.tmp
|
||||
sed < $< > $@.tmp \
|
||||
-e 's#@-BIN_DIR-@#${bindir}#g' \
|
||||
-e 's#@-GNC_DBD_DIR-@#${GNC_DBD_DIR}#g' \
|
||||
-e 's#@-GNC_GUILE_MODULE_DIR-@#${GNC_SHAREDIR}/guile-modules#g' \
|
||||
-e 's#@-GNC_SCM_INSTALL_DIR-@#${GNC_SCM_INSTALL_DIR}#g' \
|
||||
-e 's#@-GNC_LIB_INSTALLDIR-@#${libdir}#' \
|
||||
@ -40,10 +41,11 @@ gnucash: gnucash.in ${top_builddir}/config.status Makefile
|
||||
mv $@.tmp $@
|
||||
chmod u+x $@
|
||||
|
||||
gnucash-valgrind: gnucash-valgrind.in ${top_builddir}/config.status Makefile
|
||||
gnucash-gdb: gnucash-gdb.in ${top_builddir}/config.status Makefile
|
||||
rm -f $@.tmp
|
||||
sed < $< > $@.tmp \
|
||||
-e 's#@-BIN_DIR-@#${bindir}#g' \
|
||||
-e 's#@-GNC_DBD_DIR-@#${GNC_DBD_DIR}#g' \
|
||||
-e 's#@-GNC_GUILE_MODULE_DIR-@#${GNC_SHAREDIR}/guile-modules#g' \
|
||||
-e 's#@-GNC_SCM_INSTALL_DIR-@#${GNC_SCM_INSTALL_DIR}#g' \
|
||||
-e 's#@-GNC_LIB_INSTALLDIR-@#${libdir}#' \
|
||||
@ -52,7 +54,20 @@ gnucash-valgrind: gnucash-valgrind.in ${top_builddir}/config.status Makefile
|
||||
mv $@.tmp $@
|
||||
chmod u+x $@
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES) gnucash gnucash-valgrind
|
||||
gnucash-valgrind: gnucash-valgrind.in ${top_builddir}/config.status Makefile
|
||||
rm -f $@.tmp
|
||||
sed < $< > $@.tmp \
|
||||
-e 's#@-BIN_DIR-@#${bindir}#g' \
|
||||
-e 's#@-GNC_DBD_DIR-@#${GNC_DBD_DIR}#g' \
|
||||
-e 's#@-GNC_GUILE_MODULE_DIR-@#${GNC_SHAREDIR}/guile-modules#g' \
|
||||
-e 's#@-GNC_SCM_INSTALL_DIR-@#${GNC_SCM_INSTALL_DIR}#g' \
|
||||
-e 's#@-GNC_LIB_INSTALLDIR-@#${libdir}#' \
|
||||
-e 's#@-GNC_PKGLIB_INSTALLDIR-@#${pkglibdir}#g' \
|
||||
-e "s#@-TOP_SRC_DIR-@#`pwd`/${top_srcdir}#g"
|
||||
mv $@.tmp $@
|
||||
chmod u+x $@
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES) gnucash gnucash-valgrind gnucash-gdb
|
||||
|
||||
# We handle gnucash scripts in a somewhat unexpected way, but we do
|
||||
# this so that a user who doesn't necessarily have the right
|
||||
@ -71,13 +86,13 @@ CLEANFILES = $(BUILT_SOURCES) gnucash gnucash-valgrind
|
||||
# by these top-level "common" scripts.
|
||||
gnc_common_scripts = gnucash-env gnucash-make-guids
|
||||
|
||||
bin_SCRIPTS = ${gnc_common_scripts} update-gnucash-gconf gnucash gnucash-valgrind
|
||||
bin_SCRIPTS = ${gnc_common_scripts} update-gnucash-gconf gnucash gnucash-valgrind gnucash-gdb
|
||||
|
||||
# if you change gncoverridedir, make sure you change ./overrides/Makefile.am too.
|
||||
gncoverridesdir = ${GNC_LIBEXECDIR}/overrides
|
||||
|
||||
EXTRA_DIST = generate-gnc-script update-gnucash-gconf.in \
|
||||
gnucash.in gnucash-valgrind.in
|
||||
gnucash.in gnucash-valgrind.in gnucash-gdb.in
|
||||
|
||||
## Gnucash scripts -- real code is in overrides, these just get you there.
|
||||
${gnc_common_scripts}: generate-gnc-script ${top_builddir}/config.status
|
||||
|
32
src/bin/gnucash-gdb.in
Normal file
32
src/bin/gnucash-gdb.in
Normal file
@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
PATH="@-BIN_DIR-@:${PATH}"
|
||||
export PATH
|
||||
|
||||
GUILE_WARN_DEPRECATED="no"
|
||||
export GUILE_WARN_DEPRECATED
|
||||
|
||||
GNC_MODULE_PATH="@-GNC_PKGLIB_INSTALLDIR-@:${GNC_MODULE_PATH}"
|
||||
|
||||
EXTRA_PATH="${EXTRA_PATH}:@-GNC_GUILE_MODULE_DIR-@"
|
||||
EXTRA_PATH="${EXTRA_PATH}:@-GNC_SCM_INSTALL_DIR-@"
|
||||
GUILE_LOAD_PATH="${EXTRA_PATH}:${GUILE_LOAD_PATH}"
|
||||
|
||||
EXTRA_LIBS="${GNC_MODULE_PATH}"
|
||||
EXTRA_LIBS="${EXTRA_LIBS}:@-GNC_LIB_INSTALLDIR-@"
|
||||
EXTRA_LIBS="${EXTRA_LIBS}:@-GNC_PKGLIB_INSTALLDIR-@"
|
||||
|
||||
LD_LIBRARY_PATH="${EXTRA_LIBS}:${LD_LIBRARY_PATH}"
|
||||
TOP_SRC_DIR="@-TOP_SRC_DIR-@"
|
||||
GNC_DBD_DIR="@-GNC_DBD_DIR-@"
|
||||
|
||||
export GNC_MODULE_PATH
|
||||
export GUILE_LOAD_PATH
|
||||
export LD_LIBRARY_PATH
|
||||
export GNC_DBD_DIR
|
||||
|
||||
#
|
||||
# Other potentially useful options, particularly for valgrind-2.x:
|
||||
# --tool=memcheck --trace-children=yes
|
||||
#
|
||||
exec gdb gnucash-bin "$@"
|
@ -18,10 +18,12 @@ EXTRA_LIBS="${EXTRA_LIBS}:@-GNC_PKGLIB_INSTALLDIR-@"
|
||||
|
||||
LD_LIBRARY_PATH="${EXTRA_LIBS}:${LD_LIBRARY_PATH}"
|
||||
TOP_SRC_DIR="@-TOP_SRC_DIR-@"
|
||||
GNC_DBD_DIR="@-GNC_DBD_DIR-@"
|
||||
|
||||
export GNC_MODULE_PATH
|
||||
export GUILE_LOAD_PATH
|
||||
export LD_LIBRARY_PATH
|
||||
export GNC_DBD_DIR
|
||||
|
||||
#
|
||||
# Other potentially useful options, particularly for valgrind-2.x:
|
||||
@ -29,8 +31,12 @@ export LD_LIBRARY_PATH
|
||||
#
|
||||
exec valgrind -v \
|
||||
--suppressions=${TOP_SRC_DIR}/src/valgrind-gnucash.supp \
|
||||
--suppressions=${TOP_SRC_DIR}/src/valgrind-glib.supp \
|
||||
--suppressions=${TOP_SRC_DIR}/src/valgrind-libfontconfig.supp \
|
||||
--suppressions=${TOP_SRC_DIR}/src/valgrind-libgda.supp \
|
||||
--suppressions=${TOP_SRC_DIR}/src/valgrind-libguile.supp \
|
||||
--num-callers=25 \
|
||||
--error-limit=no \
|
||||
--tool=callgrind \
|
||||
--instr-atstart=no \
|
||||
--collect-atstart=no \
|
||||
--tool=memcheck \
|
||||
--leak-check=full \
|
||||
gnucash-bin "$@"
|
||||
|
@ -18,10 +18,12 @@ EXTRA_LIBS="${EXTRA_LIBS}@-PATH_SEPARATOR-@@-GNC_PKGLIB_INSTALLDIR-@"
|
||||
|
||||
LD_LIBRARY_PATH="${EXTRA_LIBS}@-PATH_SEPARATOR-@${LD_LIBRARY_PATH}"
|
||||
DYLD_LIBRARY_PATH="${EXTRA_LIBS}@-PATH_SEPARATOR-@${DYLD_LIBRARY_PATH}"
|
||||
GNC_DBD_DIR="@-GNC_DBD_DIR-@"
|
||||
|
||||
export GNC_MODULE_PATH
|
||||
export GUILE_LOAD_PATH
|
||||
export LD_LIBRARY_PATH
|
||||
export DYLD_LIBRARY_PATH
|
||||
export GNC_DBD_DIR
|
||||
|
||||
exec gnucash-bin "$@"
|
||||
|
@ -1,4 +1,4 @@
|
||||
SUBDIRS = . test file
|
||||
SUBDIRS = . sql test file
|
||||
|
||||
pkglib_LTLIBRARIES = libgncmod-business-core.la
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
SUBDIRS = .
|
||||
|
||||
pkglib_LTLIBRARIES = libgncmod-business-backend-file.la
|
||||
pkglib_LTLIBRARIES = libgncmod-business-backend-xml.la
|
||||
|
||||
AM_CFLAGS = \
|
||||
-I${top_srcdir}/src \
|
||||
@ -13,8 +13,8 @@ AM_CFLAGS = \
|
||||
${QOF_CFLAGS} \
|
||||
${GLIB_CFLAGS}
|
||||
|
||||
libgncmod_business_backend_file_la_SOURCES = \
|
||||
gncmod-business-backend-file.c \
|
||||
libgncmod_business_backend_xml_la_SOURCES = \
|
||||
gncmod-business-backend-xml.c \
|
||||
gnc-address-xml-v2.c \
|
||||
gnc-bill-term-xml-v2.c \
|
||||
gnc-customer-xml-v2.c \
|
||||
@ -41,11 +41,11 @@ noinst_HEADERS = \
|
||||
gnc-vendor-xml-v2.h \
|
||||
xml-helpers.h
|
||||
|
||||
libgncmod_business_backend_file_la_LDFLAGS = -module -avoid-version
|
||||
libgncmod_business_backend_xml_la_LDFLAGS = -module -avoid-version
|
||||
|
||||
libgncmod_business_backend_file_la_LIBADD = \
|
||||
libgncmod_business_backend_xml_la_LIBADD = \
|
||||
${top_builddir}/src/business/business-core/libgncmod-business-core.la \
|
||||
${top_builddir}/src/backend/file/libgnc-backend-file-utils.la \
|
||||
${top_builddir}/src/backend/file/libgnc-backend-xml-utils.la \
|
||||
${top_builddir}/src/engine/libgncmod-engine.la \
|
||||
${top_builddir}/src/gnc-module/libgnc-module.la \
|
||||
${LIBXML2_LIBS} \
|
||||
|
112
src/business/business-core/file/gncmod-business-backend-xml.c
Normal file
112
src/business/business-core/file/gncmod-business-backend-xml.c
Normal file
@ -0,0 +1,112 @@
|
||||
/*********************************************************************
|
||||
* gncmod-business-backend-file.c
|
||||
* module definition/initialization for the file backend module
|
||||
*
|
||||
* Copyright (c) 2002 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, contact:
|
||||
*
|
||||
* Free Software Foundation Voice: +1-617-542-5942
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
*
|
||||
*********************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
#include <gmodule.h>
|
||||
|
||||
#include "gnc-module.h"
|
||||
#include "gnc-module-api.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "io-gncxml-v2.h"
|
||||
|
||||
#include "gnc-address-xml-v2.h"
|
||||
#include "gnc-bill-term-xml-v2.h"
|
||||
#include "gnc-customer-xml-v2.h"
|
||||
#include "gnc-employee-xml-v2.h"
|
||||
#include "gnc-entry-xml-v2.h"
|
||||
#include "gnc-invoice-xml-v2.h"
|
||||
#include "gnc-job-xml-v2.h"
|
||||
#include "gnc-order-xml-v2.h"
|
||||
#include "gnc-owner-xml-v2.h"
|
||||
#include "gnc-tax-table-xml-v2.h"
|
||||
#include "gnc-vendor-xml-v2.h"
|
||||
|
||||
GNC_MODULE_API_DECL(libgncmod_business_backend_xml)
|
||||
|
||||
/* version of the gnc module system interface we require */
|
||||
int libgncmod_business_backend_xml_gnc_module_system_interface = 0;
|
||||
|
||||
/* module versioning uses libtool semantics. */
|
||||
int libgncmod_business_backend_xml_gnc_module_current = 0;
|
||||
int libgncmod_business_backend_xml_gnc_module_revision = 0;
|
||||
int libgncmod_business_backend_xml_gnc_module_age = 0;
|
||||
|
||||
static GNCModule bus_core;
|
||||
static GNCModule file;
|
||||
|
||||
|
||||
char *
|
||||
libgncmod_business_backend_xml_gnc_module_path(void)
|
||||
{
|
||||
return g_strdup("gnucash/business-core-xml");
|
||||
}
|
||||
|
||||
char *
|
||||
libgncmod_business_backend_xml_gnc_module_description(void)
|
||||
{
|
||||
return g_strdup("The XML (v2) parsers for GnuCash business objects");
|
||||
}
|
||||
|
||||
int
|
||||
libgncmod_business_backend_xml_gnc_module_init(int refcount)
|
||||
{
|
||||
if(!gnc_engine_is_initialized()) { return FALSE; }
|
||||
|
||||
bus_core = gnc_module_load("gnucash/business-core", 0);
|
||||
if(!bus_core) return FALSE;
|
||||
|
||||
if (refcount == 0) {
|
||||
/* Initialize our pointers into the backend subsystem */
|
||||
gnc_address_xml_initialize ();
|
||||
gnc_billterm_xml_initialize ();
|
||||
gnc_customer_xml_initialize ();
|
||||
gnc_employee_xml_initialize ();
|
||||
gnc_entry_xml_initialize ();
|
||||
gnc_invoice_xml_initialize ();
|
||||
gnc_job_xml_initialize ();
|
||||
gnc_order_xml_initialize ();
|
||||
gnc_owner_xml_initialize ();
|
||||
gnc_taxtable_xml_initialize ();
|
||||
gnc_vendor_xml_initialize ();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
libgncmod_business_backend_xml_gnc_module_end(int refcount)
|
||||
{
|
||||
int unload = TRUE;
|
||||
|
||||
if (bus_core)
|
||||
unload = gnc_module_unload(bus_core);
|
||||
|
||||
if (refcount == 0) {
|
||||
bus_core = NULL;
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
return unload;
|
||||
}
|
@ -127,7 +127,7 @@ qofAddressSetOwner(GncAddress *addr, QofInstance *ent)
|
||||
}
|
||||
|
||||
static QofInstance*
|
||||
qofAddressGetOwner(GncAddress *addr)
|
||||
qofAddressGetOwner(const GncAddress *addr)
|
||||
{
|
||||
|
||||
if(!addr) { return NULL; }
|
||||
@ -135,7 +135,7 @@ qofAddressGetOwner(GncAddress *addr)
|
||||
}
|
||||
|
||||
GncAddress *
|
||||
gncCloneAddress (GncAddress *from, QofInstance *new_parent, QofBook *book)
|
||||
gncCloneAddress (const GncAddress *from, QofInstance *new_parent, QofBook *book)
|
||||
{
|
||||
GncAddress *addr;
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
gboolean gncAddressRegister (void);
|
||||
|
||||
/** Make a copy of the address, setting the parent to 'new_parent' */
|
||||
GncAddress * gncCloneAddress (GncAddress *from, QofInstance *new_parent, QofBook *book);
|
||||
GncAddress * gncCloneAddress (const GncAddress *from, QofInstance *new_parent, QofBook *book);
|
||||
|
||||
|
||||
#endif /* GNC_ADDRESSP_H_ */
|
||||
|
@ -367,7 +367,9 @@ void gncBillTermSetParent (GncBillTerm *term, GncBillTerm *parent)
|
||||
if (parent)
|
||||
gncBillTermAddChild(parent, term);
|
||||
term->refcount = 0;
|
||||
if( parent != NULL ) {
|
||||
gncBillTermMakeInvisible (term);
|
||||
}
|
||||
gncBillTermCommitEdit (term);
|
||||
}
|
||||
|
||||
@ -467,19 +469,19 @@ GList * gncBillTermGetTerms (QofBook *book)
|
||||
return bi->terms;
|
||||
}
|
||||
|
||||
const char *gncBillTermGetName (GncBillTerm *term)
|
||||
const char *gncBillTermGetName (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) return NULL;
|
||||
return term->name;
|
||||
}
|
||||
|
||||
const char *gncBillTermGetDescription (GncBillTerm *term)
|
||||
const char *gncBillTermGetDescription (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) return NULL;
|
||||
return term->desc;
|
||||
}
|
||||
|
||||
GncBillTermType gncBillTermGetType (GncBillTerm *term)
|
||||
GncBillTermType gncBillTermGetType (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) return 0;
|
||||
return term->type;
|
||||
@ -489,37 +491,37 @@ GncBillTermType gncBillTermGetType (GncBillTerm *term)
|
||||
AS_STRING_FUNC(GncBillTermType, ENUM_TERMS_TYPE)
|
||||
|
||||
static
|
||||
const char* qofBillTermGetType (GncBillTerm *term)
|
||||
const char* qofBillTermGetType (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) { return NULL; }
|
||||
return GncBillTermTypeasString(term->type);
|
||||
}
|
||||
|
||||
gint gncBillTermGetDueDays (GncBillTerm *term)
|
||||
gint gncBillTermGetDueDays (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) return 0;
|
||||
return term->due_days;
|
||||
}
|
||||
|
||||
gint gncBillTermGetDiscountDays (GncBillTerm *term)
|
||||
gint gncBillTermGetDiscountDays (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) return 0;
|
||||
return term->disc_days;
|
||||
}
|
||||
|
||||
gnc_numeric gncBillTermGetDiscount (GncBillTerm *term)
|
||||
gnc_numeric gncBillTermGetDiscount (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) return gnc_numeric_zero ();
|
||||
return term->discount;
|
||||
}
|
||||
|
||||
gint gncBillTermGetCutoff (GncBillTerm *term)
|
||||
gint gncBillTermGetCutoff (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) return 0;
|
||||
return term->cutoff;
|
||||
}
|
||||
|
||||
static GncBillTerm *gncBillTermCopy (GncBillTerm *term)
|
||||
static GncBillTerm *gncBillTermCopy (const GncBillTerm *term)
|
||||
{
|
||||
GncBillTerm *t;
|
||||
|
||||
@ -557,25 +559,25 @@ GncBillTerm *gncBillTermReturnChild (GncBillTerm *term, gboolean make_new)
|
||||
return child;
|
||||
}
|
||||
|
||||
GncBillTerm *gncBillTermGetParent (GncBillTerm *term)
|
||||
GncBillTerm *gncBillTermGetParent (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) return NULL;
|
||||
return term->parent;
|
||||
}
|
||||
|
||||
gint64 gncBillTermGetRefcount (GncBillTerm *term)
|
||||
gint64 gncBillTermGetRefcount (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) return 0;
|
||||
return term->refcount;
|
||||
}
|
||||
|
||||
gboolean gncBillTermGetInvisible (GncBillTerm *term)
|
||||
gboolean gncBillTermGetInvisible (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) return FALSE;
|
||||
return term->invisible;
|
||||
}
|
||||
|
||||
int gncBillTermCompare (GncBillTerm *a, GncBillTerm *b)
|
||||
int gncBillTermCompare (const GncBillTerm *a, const GncBillTerm *b)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -589,7 +591,7 @@ int gncBillTermCompare (GncBillTerm *a, GncBillTerm *b)
|
||||
return safe_strcmp (a->desc, b->desc);
|
||||
}
|
||||
|
||||
gboolean gncBillTermIsDirty (GncBillTerm *term)
|
||||
gboolean gncBillTermIsDirty (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) return FALSE;
|
||||
return qof_instance_get_dirty_flag(term);
|
||||
@ -605,7 +607,7 @@ gboolean gncBillTermIsDirty (GncBillTerm *term)
|
||||
* XXX explain this, the logic is totally opaque to me.
|
||||
*/
|
||||
static void
|
||||
compute_monthyear (GncBillTerm *term, Timespec post_date,
|
||||
compute_monthyear (const GncBillTerm *term, Timespec post_date,
|
||||
int *month, int *year)
|
||||
{
|
||||
int iday, imonth, iyear;
|
||||
@ -638,7 +640,7 @@ compute_monthyear (GncBillTerm *term, Timespec post_date,
|
||||
/* XXX explain this, the logic is totally opaque to me. */
|
||||
|
||||
static Timespec
|
||||
compute_time (GncBillTerm *term, Timespec post_date, int days)
|
||||
compute_time (const GncBillTerm *term, Timespec post_date, int days)
|
||||
{
|
||||
Timespec res = post_date;
|
||||
int day, month, year;
|
||||
@ -659,7 +661,7 @@ compute_time (GncBillTerm *term, Timespec post_date, int days)
|
||||
}
|
||||
|
||||
Timespec
|
||||
gncBillTermComputeDueDate (GncBillTerm *term, Timespec post_date)
|
||||
gncBillTermComputeDueDate (const GncBillTerm *term, Timespec post_date)
|
||||
{
|
||||
Timespec res = post_date;
|
||||
if (!term) return res;
|
||||
@ -668,7 +670,7 @@ gncBillTermComputeDueDate (GncBillTerm *term, Timespec post_date)
|
||||
}
|
||||
|
||||
Timespec
|
||||
gncBillTermComputeDiscountDate (GncBillTerm *term, Timespec post_date)
|
||||
gncBillTermComputeDiscountDate (const GncBillTerm *term, Timespec post_date)
|
||||
{
|
||||
Timespec res = post_date;
|
||||
if (!term) return res;
|
||||
|
@ -124,30 +124,30 @@ void gncBillTermSetCutoff (GncBillTerm *term, gint cutoff);
|
||||
GncBillTerm *gncBillTermLookupByName (QofBook *book, const char *name);
|
||||
GList * gncBillTermGetTerms (QofBook *book);
|
||||
|
||||
const char *gncBillTermGetName (GncBillTerm *term);
|
||||
const char *gncBillTermGetDescription (GncBillTerm *term);
|
||||
GncBillTermType gncBillTermGetType (GncBillTerm *term);
|
||||
gint gncBillTermGetDueDays (GncBillTerm *term);
|
||||
gint gncBillTermGetDiscountDays (GncBillTerm *term);
|
||||
gnc_numeric gncBillTermGetDiscount (GncBillTerm *term);
|
||||
gint gncBillTermGetCutoff (GncBillTerm *term);
|
||||
const char *gncBillTermGetName (const GncBillTerm *term);
|
||||
const char *gncBillTermGetDescription (const GncBillTerm *term);
|
||||
GncBillTermType gncBillTermGetType (const GncBillTerm *term);
|
||||
gint gncBillTermGetDueDays (const GncBillTerm *term);
|
||||
gint gncBillTermGetDiscountDays (const GncBillTerm *term);
|
||||
gnc_numeric gncBillTermGetDiscount (const GncBillTerm *term);
|
||||
gint gncBillTermGetCutoff (const GncBillTerm *term);
|
||||
|
||||
gboolean gncBillTermIsDirty (GncBillTerm *term);
|
||||
gboolean gncBillTermIsDirty (const GncBillTerm *term);
|
||||
|
||||
GncBillTerm *gncBillTermGetParent (GncBillTerm *term);
|
||||
GncBillTerm *gncBillTermGetParent (const GncBillTerm *term);
|
||||
GncBillTerm *gncBillTermReturnChild (GncBillTerm *term, gboolean make_new);
|
||||
#define gncBillTermGetChild(t) gncBillTermReturnChild((t),FALSE)
|
||||
gint64 gncBillTermGetRefcount (GncBillTerm *term);
|
||||
gint64 gncBillTermGetRefcount (const GncBillTerm *term);
|
||||
/** @} */
|
||||
|
||||
int gncBillTermCompare (GncBillTerm *a, GncBillTerm *b);
|
||||
int gncBillTermCompare (const GncBillTerm *a, const GncBillTerm *b);
|
||||
|
||||
/********************************************************/
|
||||
/* functions to compute dates from Bill Terms */
|
||||
|
||||
/* Compute the due date and discount dates from the post date */
|
||||
Timespec gncBillTermComputeDueDate (GncBillTerm *term, Timespec post_date);
|
||||
Timespec gncBillTermComputeDiscountDate (GncBillTerm *term, Timespec post_date);
|
||||
Timespec gncBillTermComputeDueDate (const GncBillTerm *term, Timespec post_date);
|
||||
Timespec gncBillTermComputeDiscountDate (const GncBillTerm *term, Timespec post_date);
|
||||
|
||||
/* deprecated */
|
||||
#define gncBillTermGetGUID(x) qof_instance_get_guid (QOF_INSTANCE(x))
|
||||
|
@ -38,7 +38,7 @@ void gncBillTermSetChild (GncBillTerm *term, GncBillTerm *child);
|
||||
void gncBillTermSetRefcount (GncBillTerm *term, gint64 refcount);
|
||||
void gncBillTermMakeInvisible (GncBillTerm *term);
|
||||
|
||||
gboolean gncBillTermGetInvisible (GncBillTerm *term);
|
||||
gboolean gncBillTermGetInvisible (const GncBillTerm *term);
|
||||
|
||||
/** The gncCloneBillTerm() routine makes a copy of the indicated
|
||||
* bill term, placing it in the indicated book. It copies
|
||||
|
@ -418,19 +418,19 @@ void gncCustomerCommitEdit (GncCustomer *cust)
|
||||
/* ============================================================== */
|
||||
/* Get Functions */
|
||||
|
||||
const char * gncCustomerGetID (GncCustomer *cust)
|
||||
const char * gncCustomerGetID (const GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return NULL;
|
||||
return cust->id;
|
||||
}
|
||||
|
||||
const char * gncCustomerGetName (GncCustomer *cust)
|
||||
const char * gncCustomerGetName (const GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return NULL;
|
||||
return cust->name;
|
||||
}
|
||||
|
||||
GncAddress * gncCustomerGetAddr (GncCustomer *cust)
|
||||
GncAddress * gncCustomerGetAddr (const GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return NULL;
|
||||
return cust->addr;
|
||||
@ -470,67 +470,67 @@ qofCustomerSetShipAddr (GncCustomer *cust, QofInstance *ship_addr_ent)
|
||||
gncCustomerCommitEdit(cust);
|
||||
}
|
||||
|
||||
GncAddress * gncCustomerGetShipAddr (GncCustomer *cust)
|
||||
GncAddress * gncCustomerGetShipAddr (const GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return NULL;
|
||||
return cust->shipaddr;
|
||||
}
|
||||
|
||||
const char * gncCustomerGetNotes (GncCustomer *cust)
|
||||
const char * gncCustomerGetNotes (const GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return NULL;
|
||||
return cust->notes;
|
||||
}
|
||||
|
||||
GncBillTerm * gncCustomerGetTerms (GncCustomer *cust)
|
||||
GncBillTerm * gncCustomerGetTerms (const GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return NULL;
|
||||
return cust->terms;
|
||||
}
|
||||
|
||||
GncTaxIncluded gncCustomerGetTaxIncluded (GncCustomer *cust)
|
||||
GncTaxIncluded gncCustomerGetTaxIncluded (const GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return GNC_TAXINCLUDED_USEGLOBAL;
|
||||
return cust->taxincluded;
|
||||
}
|
||||
|
||||
gnc_commodity * gncCustomerGetCurrency (GncCustomer *cust)
|
||||
gnc_commodity * gncCustomerGetCurrency (const GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return NULL;
|
||||
return cust->currency;
|
||||
}
|
||||
|
||||
gboolean gncCustomerGetActive (GncCustomer *cust)
|
||||
gboolean gncCustomerGetActive (const GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return FALSE;
|
||||
return cust->active;
|
||||
}
|
||||
|
||||
gnc_numeric gncCustomerGetDiscount (GncCustomer *cust)
|
||||
gnc_numeric gncCustomerGetDiscount (const GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return gnc_numeric_zero();
|
||||
return cust->discount;
|
||||
}
|
||||
|
||||
gnc_numeric gncCustomerGetCredit (GncCustomer *cust)
|
||||
gnc_numeric gncCustomerGetCredit (const GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return gnc_numeric_zero();
|
||||
return cust->credit;
|
||||
}
|
||||
|
||||
gboolean gncCustomerGetTaxTableOverride (GncCustomer *customer)
|
||||
gboolean gncCustomerGetTaxTableOverride (const GncCustomer *customer)
|
||||
{
|
||||
if (!customer) return FALSE;
|
||||
return customer->taxtable_override;
|
||||
}
|
||||
|
||||
GncTaxTable* gncCustomerGetTaxTable (GncCustomer *customer)
|
||||
GncTaxTable* gncCustomerGetTaxTable (const GncCustomer *customer)
|
||||
{
|
||||
if (!customer) return NULL;
|
||||
return customer->taxtable;
|
||||
}
|
||||
|
||||
GList * gncCustomerGetJoblist (GncCustomer *cust, gboolean show_all)
|
||||
GList * gncCustomerGetJoblist (const GncCustomer *cust, gboolean show_all)
|
||||
{
|
||||
if (!cust) return NULL;
|
||||
|
||||
@ -557,7 +557,7 @@ gboolean gncCustomerIsDirty (GncCustomer *cust)
|
||||
|
||||
/* Other functions */
|
||||
|
||||
int gncCustomerCompare (GncCustomer *a, GncCustomer *b)
|
||||
int gncCustomerCompare (const GncCustomer *a, const GncCustomer *b)
|
||||
{
|
||||
if (!a && !b) return 0;
|
||||
if (!a && b) return 1;
|
||||
|
@ -118,26 +118,26 @@ void gncCustomerRemoveJob (GncCustomer *customer, GncJob *job);
|
||||
#define gncCustomerLookup(book,guid) \
|
||||
QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_CUSTOMER, GncCustomer)
|
||||
|
||||
const char * gncCustomerGetID (GncCustomer *customer);
|
||||
const char * gncCustomerGetName (GncCustomer *customer);
|
||||
GncAddress * gncCustomerGetAddr (GncCustomer *customer);
|
||||
GncAddress * gncCustomerGetShipAddr (GncCustomer *customer);
|
||||
const char * gncCustomerGetNotes (GncCustomer *customer);
|
||||
GncBillTerm * gncCustomerGetTerms (GncCustomer *customer);
|
||||
GncTaxIncluded gncCustomerGetTaxIncluded (GncCustomer *customer);
|
||||
gboolean gncCustomerGetActive (GncCustomer *customer);
|
||||
gnc_numeric gncCustomerGetDiscount (GncCustomer *customer);
|
||||
gnc_numeric gncCustomerGetCredit (GncCustomer *customer);
|
||||
gnc_commodity * gncCustomerGetCurrency (GncCustomer *customer);
|
||||
const char * gncCustomerGetID (const GncCustomer *customer);
|
||||
const char * gncCustomerGetName (const GncCustomer *customer);
|
||||
GncAddress * gncCustomerGetAddr (const GncCustomer *customer);
|
||||
GncAddress * gncCustomerGetShipAddr (const GncCustomer *customer);
|
||||
const char * gncCustomerGetNotes (const GncCustomer *customer);
|
||||
GncBillTerm * gncCustomerGetTerms (const GncCustomer *customer);
|
||||
GncTaxIncluded gncCustomerGetTaxIncluded (const GncCustomer *customer);
|
||||
gboolean gncCustomerGetActive (const GncCustomer *customer);
|
||||
gnc_numeric gncCustomerGetDiscount (const GncCustomer *customer);
|
||||
gnc_numeric gncCustomerGetCredit (const GncCustomer *customer);
|
||||
gnc_commodity * gncCustomerGetCurrency (const GncCustomer *customer);
|
||||
|
||||
gboolean gncCustomerGetTaxTableOverride (GncCustomer *customer);
|
||||
GncTaxTable* gncCustomerGetTaxTable (GncCustomer *customer);
|
||||
gboolean gncCustomerGetTaxTableOverride (const GncCustomer *customer);
|
||||
GncTaxTable* gncCustomerGetTaxTable (const GncCustomer *customer);
|
||||
|
||||
GList * gncCustomerGetJoblist (GncCustomer *customer, gboolean show_all);
|
||||
GList * gncCustomerGetJoblist (const GncCustomer *customer, gboolean show_all);
|
||||
/** @} */
|
||||
|
||||
gboolean gncCustomerIsDirty (GncCustomer *customer);
|
||||
int gncCustomerCompare (GncCustomer *a, GncCustomer *b);
|
||||
int gncCustomerCompare (const GncCustomer *a, const GncCustomer *b);
|
||||
|
||||
#define CUSTOMER_ID "id"
|
||||
#define CUSTOMER_NAME "name"
|
||||
|
@ -299,67 +299,67 @@ qofEmployeeSetAddr (GncEmployee *employee, QofInstance *addr_ent)
|
||||
|
||||
/* ============================================================== */
|
||||
/* Get Functions */
|
||||
const char * gncEmployeeGetID (GncEmployee *employee)
|
||||
const char * gncEmployeeGetID (const GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return NULL;
|
||||
return employee->id;
|
||||
}
|
||||
|
||||
const char * gncEmployeeGetUsername (GncEmployee *employee)
|
||||
const char * gncEmployeeGetUsername (const GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return NULL;
|
||||
return employee->username;
|
||||
}
|
||||
|
||||
GncAddress * gncEmployeeGetAddr (GncEmployee *employee)
|
||||
GncAddress * gncEmployeeGetAddr (const GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return NULL;
|
||||
return employee->addr;
|
||||
}
|
||||
|
||||
const char * gncEmployeeGetLanguage (GncEmployee *employee)
|
||||
const char * gncEmployeeGetLanguage (const GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return NULL;
|
||||
return employee->language;
|
||||
}
|
||||
|
||||
const char * gncEmployeeGetAcl (GncEmployee *employee)
|
||||
const char * gncEmployeeGetAcl (const GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return NULL;
|
||||
return employee->acl;
|
||||
}
|
||||
|
||||
gnc_numeric gncEmployeeGetWorkday (GncEmployee *employee)
|
||||
gnc_numeric gncEmployeeGetWorkday (const GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return gnc_numeric_zero();
|
||||
return employee->workday;
|
||||
}
|
||||
|
||||
gnc_numeric gncEmployeeGetRate (GncEmployee *employee)
|
||||
gnc_numeric gncEmployeeGetRate (const GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return gnc_numeric_zero();
|
||||
return employee->rate;
|
||||
}
|
||||
|
||||
gnc_commodity * gncEmployeeGetCurrency (GncEmployee *employee)
|
||||
gnc_commodity * gncEmployeeGetCurrency (const GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return NULL;
|
||||
return employee->currency;
|
||||
}
|
||||
|
||||
gboolean gncEmployeeGetActive (GncEmployee *employee)
|
||||
gboolean gncEmployeeGetActive (const GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return FALSE;
|
||||
return employee->active;
|
||||
}
|
||||
|
||||
Account * gncEmployeeGetCCard (GncEmployee *employee)
|
||||
Account * gncEmployeeGetCCard (const GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return NULL;
|
||||
return employee->ccard_acc;
|
||||
}
|
||||
|
||||
gboolean gncEmployeeIsDirty (GncEmployee *employee)
|
||||
gboolean gncEmployeeIsDirty (const GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return FALSE;
|
||||
return (qof_instance_get_dirty_flag(employee)
|
||||
@ -399,7 +399,7 @@ void gncEmployeeCommitEdit (GncEmployee *employee)
|
||||
/* ============================================================== */
|
||||
/* Other functions */
|
||||
|
||||
int gncEmployeeCompare (GncEmployee *a, GncEmployee *b)
|
||||
int gncEmployeeCompare (const GncEmployee *a, const GncEmployee *b)
|
||||
{
|
||||
if (!a && !b) return 0;
|
||||
if (!a && b) return 1;
|
||||
|
@ -59,7 +59,7 @@ GncEmployee *gncEmployeeCreate (QofBook *book);
|
||||
void gncEmployeeDestroy (GncEmployee *employee);
|
||||
void gncEmployeeBeginEdit (GncEmployee *employee);
|
||||
void gncEmployeeCommitEdit (GncEmployee *employee);
|
||||
int gncEmployeeCompare (GncEmployee *a, GncEmployee *b);
|
||||
int gncEmployeeCompare (const GncEmployee *a, const GncEmployee *b);
|
||||
/** @} */
|
||||
|
||||
/** @name Set Functions
|
||||
@ -80,16 +80,16 @@ void qofEmployeeSetAddr (GncEmployee *employee, QofInstance *addr_ent);
|
||||
/** @name Get Functions
|
||||
@{ */
|
||||
QofBook * gncEmployeeGetBook (GncEmployee *employee);
|
||||
const char * gncEmployeeGetID (GncEmployee *employee);
|
||||
const char * gncEmployeeGetUsername (GncEmployee *employee);
|
||||
GncAddress * gncEmployeeGetAddr (GncEmployee *employee);
|
||||
const char * gncEmployeeGetLanguage (GncEmployee *employee);
|
||||
const char * gncEmployeeGetAcl (GncEmployee *employee);
|
||||
gnc_numeric gncEmployeeGetWorkday (GncEmployee *employee);
|
||||
gnc_numeric gncEmployeeGetRate (GncEmployee *employee);
|
||||
gnc_commodity * gncEmployeeGetCurrency (GncEmployee *employee);
|
||||
gboolean gncEmployeeGetActive (GncEmployee *employee);
|
||||
Account * gncEmployeeGetCCard (GncEmployee *employee);
|
||||
const char * gncEmployeeGetID (const GncEmployee *employee);
|
||||
const char * gncEmployeeGetUsername (const GncEmployee *employee);
|
||||
GncAddress * gncEmployeeGetAddr (const GncEmployee *employee);
|
||||
const char * gncEmployeeGetLanguage (const GncEmployee *employee);
|
||||
const char * gncEmployeeGetAcl (const GncEmployee *employee);
|
||||
gnc_numeric gncEmployeeGetWorkday (const GncEmployee *employee);
|
||||
gnc_numeric gncEmployeeGetRate (const GncEmployee *employee);
|
||||
gnc_commodity * gncEmployeeGetCurrency (const GncEmployee *employee);
|
||||
gboolean gncEmployeeGetActive (const GncEmployee *employee);
|
||||
Account * gncEmployeeGetCCard (const GncEmployee *employee);
|
||||
/** @} */
|
||||
|
||||
|
||||
@ -102,7 +102,7 @@ Account * gncEmployeeGetCCard (GncEmployee *employee);
|
||||
#define gncEmployeeLookup(book,guid) \
|
||||
QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_EMPLOYEE, GncEmployee)
|
||||
|
||||
gboolean gncEmployeeIsDirty (GncEmployee *employee);
|
||||
gboolean gncEmployeeIsDirty (const GncEmployee *employee);
|
||||
|
||||
#define EMPLOYEE_ID "id"
|
||||
#define EMPLOYEE_USERNAME "username"
|
||||
|
@ -658,39 +658,39 @@ void gncEntryCopy (const GncEntry *src, GncEntry *dest)
|
||||
/* ================================================================ */
|
||||
/* Get Functions */
|
||||
|
||||
Timespec gncEntryGetDate (GncEntry *entry)
|
||||
Timespec gncEntryGetDate (const GncEntry *entry)
|
||||
{
|
||||
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
||||
if (!entry) return ts;
|
||||
return entry->date;
|
||||
}
|
||||
|
||||
Timespec gncEntryGetDateEntered (GncEntry *entry)
|
||||
Timespec gncEntryGetDateEntered (const GncEntry *entry)
|
||||
{
|
||||
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
||||
if (!entry) return ts;
|
||||
return entry->date_entered;
|
||||
}
|
||||
|
||||
const char * gncEntryGetDescription (GncEntry *entry)
|
||||
const char * gncEntryGetDescription (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->desc;
|
||||
}
|
||||
|
||||
const char * gncEntryGetAction (GncEntry *entry)
|
||||
const char * gncEntryGetAction (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->action;
|
||||
}
|
||||
|
||||
const char * gncEntryGetNotes (GncEntry *entry)
|
||||
const char * gncEntryGetNotes (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->notes;
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryGetQuantity (GncEntry *entry)
|
||||
gnc_numeric gncEntryGetQuantity (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
return entry->quantity;
|
||||
@ -698,37 +698,37 @@ gnc_numeric gncEntryGetQuantity (GncEntry *entry)
|
||||
|
||||
/* Customer Invoice */
|
||||
|
||||
Account * gncEntryGetInvAccount (GncEntry *entry)
|
||||
Account * gncEntryGetInvAccount (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->i_account;
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryGetInvPrice (GncEntry *entry)
|
||||
gnc_numeric gncEntryGetInvPrice (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
return entry->i_price;
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryGetInvDiscount (GncEntry *entry)
|
||||
gnc_numeric gncEntryGetInvDiscount (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
return entry->i_discount;
|
||||
}
|
||||
|
||||
GncAmountType gncEntryGetInvDiscountType (GncEntry *entry)
|
||||
GncAmountType gncEntryGetInvDiscountType (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return 0;
|
||||
return entry->i_disc_type;
|
||||
}
|
||||
|
||||
GncDiscountHow gncEntryGetInvDiscountHow (GncEntry *entry)
|
||||
GncDiscountHow gncEntryGetInvDiscountHow (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return 0;
|
||||
return entry->i_disc_how;
|
||||
}
|
||||
|
||||
char* qofEntryGetInvDiscType (GncEntry *entry)
|
||||
char* qofEntryGetInvDiscType (const GncEntry *entry)
|
||||
{
|
||||
char *type_string;
|
||||
|
||||
@ -737,7 +737,7 @@ char* qofEntryGetInvDiscType (GncEntry *entry)
|
||||
return type_string;
|
||||
}
|
||||
|
||||
char* qofEntryGetInvDiscHow (GncEntry *entry)
|
||||
char* qofEntryGetInvDiscHow (const GncEntry *entry)
|
||||
{
|
||||
char *type_string;
|
||||
|
||||
@ -746,19 +746,19 @@ char* qofEntryGetInvDiscHow (GncEntry *entry)
|
||||
return type_string;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetInvTaxable (GncEntry *entry)
|
||||
gboolean gncEntryGetInvTaxable (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->i_taxable;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetInvTaxIncluded (GncEntry *entry)
|
||||
gboolean gncEntryGetInvTaxIncluded (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->i_taxincluded;
|
||||
}
|
||||
|
||||
GncTaxTable * gncEntryGetInvTaxTable (GncEntry *entry)
|
||||
GncTaxTable * gncEntryGetInvTaxTable (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->i_tax_table;
|
||||
@ -766,37 +766,37 @@ GncTaxTable * gncEntryGetInvTaxTable (GncEntry *entry)
|
||||
|
||||
/* vendor bills */
|
||||
|
||||
Account * gncEntryGetBillAccount (GncEntry *entry)
|
||||
Account * gncEntryGetBillAccount (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->b_account;
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryGetBillPrice (GncEntry *entry)
|
||||
gnc_numeric gncEntryGetBillPrice (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
return entry->b_price;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetBillTaxable (GncEntry *entry)
|
||||
gboolean gncEntryGetBillTaxable (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->b_taxable;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetBillTaxIncluded (GncEntry *entry)
|
||||
gboolean gncEntryGetBillTaxIncluded (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->b_taxincluded;
|
||||
}
|
||||
|
||||
GncTaxTable * gncEntryGetBillTaxTable (GncEntry *entry)
|
||||
GncTaxTable * gncEntryGetBillTaxTable (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->b_tax_table;
|
||||
}
|
||||
|
||||
gboolean gncEntryGetBillable (GncEntry *entry)
|
||||
gboolean gncEntryGetBillable (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return entry->billable;
|
||||
@ -808,25 +808,25 @@ GncOwner * gncEntryGetBillTo (GncEntry *entry)
|
||||
return &entry->billto;
|
||||
}
|
||||
|
||||
GncEntryPaymentType gncEntryGetBillPayment (GncEntry* entry)
|
||||
GncEntryPaymentType gncEntryGetBillPayment (const GncEntry* entry)
|
||||
{
|
||||
if (!entry) return 0;
|
||||
return entry->b_payment;
|
||||
}
|
||||
|
||||
GncInvoice * gncEntryGetInvoice (GncEntry *entry)
|
||||
GncInvoice * gncEntryGetInvoice (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->invoice;
|
||||
}
|
||||
|
||||
GncInvoice * gncEntryGetBill (GncEntry *entry)
|
||||
GncInvoice * gncEntryGetBill (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->bill;
|
||||
}
|
||||
|
||||
GncOrder * gncEntryGetOrder (GncEntry *entry)
|
||||
GncOrder * gncEntryGetOrder (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->order;
|
||||
@ -867,7 +867,7 @@ GncOrder * gncEntryGetOrder (GncEntry *entry)
|
||||
* to let a consumer know how much they saved.
|
||||
*/
|
||||
void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
|
||||
GncTaxTable *tax_table, gboolean tax_included,
|
||||
const GncTaxTable *tax_table, gboolean tax_included,
|
||||
gnc_numeric discount, GncAmountType discount_type,
|
||||
GncDiscountHow discount_how, int SCU,
|
||||
gnc_numeric *value, gnc_numeric *discount_value,
|
||||
@ -1044,7 +1044,7 @@ void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
|
||||
}
|
||||
|
||||
static int
|
||||
get_entry_commodity_denom (GncEntry *entry)
|
||||
get_entry_commodity_denom (const GncEntry *entry)
|
||||
{
|
||||
gnc_commodity *c;
|
||||
if (!entry)
|
||||
@ -1178,7 +1178,7 @@ gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry, gboolean is_inv)
|
||||
}
|
||||
|
||||
/* XXXX this exsitnace of this routine is just wrong */
|
||||
gboolean gncEntryIsOpen (GncEntry *entry)
|
||||
gboolean gncEntryIsOpen (const GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return (qof_instance_get_editlevel(entry) > 0);
|
||||
@ -1211,7 +1211,7 @@ void gncEntryCommitEdit (GncEntry *entry)
|
||||
gncEntryOnDone, entry_free);
|
||||
}
|
||||
|
||||
int gncEntryCompare (GncEntry *a, GncEntry *b)
|
||||
int gncEntryCompare (const GncEntry *a, const GncEntry *b)
|
||||
{
|
||||
int compare;
|
||||
|
||||
|
@ -135,39 +135,39 @@ void gncEntrySetBillPayment (GncEntry *entry, GncEntryPaymentType type);
|
||||
/* GET FUNCTIONS */
|
||||
/** @name Generic (shared) data
|
||||
@{ */
|
||||
Timespec gncEntryGetDate (GncEntry *entry);
|
||||
Timespec gncEntryGetDateEntered (GncEntry *entry);
|
||||
const char * gncEntryGetDescription (GncEntry *entry);
|
||||
const char * gncEntryGetAction (GncEntry *entry);
|
||||
const char * gncEntryGetNotes (GncEntry *notes);
|
||||
gnc_numeric gncEntryGetQuantity (GncEntry *entry);
|
||||
Timespec gncEntryGetDate (const GncEntry *entry);
|
||||
Timespec gncEntryGetDateEntered (const GncEntry *entry);
|
||||
const char * gncEntryGetDescription (const GncEntry *entry);
|
||||
const char * gncEntryGetAction (const GncEntry *entry);
|
||||
const char * gncEntryGetNotes (const GncEntry *notes);
|
||||
gnc_numeric gncEntryGetQuantity (const GncEntry *entry);
|
||||
/** @} */
|
||||
|
||||
/** @name Customer Invoices
|
||||
@{ */
|
||||
Account * gncEntryGetInvAccount (GncEntry *entry);
|
||||
gnc_numeric gncEntryGetInvPrice (GncEntry *entry);
|
||||
gnc_numeric gncEntryGetInvDiscount (GncEntry *entry);
|
||||
GncAmountType gncEntryGetInvDiscountType (GncEntry *entry);
|
||||
GncDiscountHow gncEntryGetInvDiscountHow (GncEntry *entry);
|
||||
char* qofEntryGetInvDiscType (GncEntry *entry);
|
||||
char* qofEntryGetInvDiscHow (GncEntry *entry);
|
||||
gboolean gncEntryGetInvTaxable (GncEntry *entry);
|
||||
gboolean gncEntryGetInvTaxIncluded (GncEntry *entry);
|
||||
GncTaxTable * gncEntryGetInvTaxTable (GncEntry *entry);
|
||||
Account * gncEntryGetInvAccount (const GncEntry *entry);
|
||||
gnc_numeric gncEntryGetInvPrice (const GncEntry *entry);
|
||||
gnc_numeric gncEntryGetInvDiscount (const GncEntry *entry);
|
||||
GncAmountType gncEntryGetInvDiscountType (const GncEntry *entry);
|
||||
GncDiscountHow gncEntryGetInvDiscountHow (const GncEntry *entry);
|
||||
char* qofEntryGetInvDiscType (const GncEntry *entry);
|
||||
char* qofEntryGetInvDiscHow (const GncEntry *entry);
|
||||
gboolean gncEntryGetInvTaxable (const GncEntry *entry);
|
||||
gboolean gncEntryGetInvTaxIncluded (const GncEntry *entry);
|
||||
GncTaxTable * gncEntryGetInvTaxTable (const GncEntry *entry);
|
||||
/** @} */
|
||||
|
||||
/** @name Vendor Bills (and Employee Expenses)
|
||||
@{ */
|
||||
Account * gncEntryGetBillAccount (GncEntry *entry);
|
||||
gnc_numeric gncEntryGetBillPrice (GncEntry *entry);
|
||||
gboolean gncEntryGetBillTaxable (GncEntry *entry);
|
||||
gboolean gncEntryGetBillTaxIncluded (GncEntry *entry);
|
||||
GncTaxTable * gncEntryGetBillTaxTable (GncEntry *entry);
|
||||
gboolean gncEntryGetBillable (GncEntry *entry);
|
||||
Account * gncEntryGetBillAccount (const GncEntry *entry);
|
||||
gnc_numeric gncEntryGetBillPrice (const GncEntry *entry);
|
||||
gboolean gncEntryGetBillTaxable (const GncEntry *entry);
|
||||
gboolean gncEntryGetBillTaxIncluded (const GncEntry *entry);
|
||||
GncTaxTable * gncEntryGetBillTaxTable (const GncEntry *entry);
|
||||
gboolean gncEntryGetBillable (const GncEntry *entry);
|
||||
GncOwner *gncEntryGetBillTo (GncEntry *entry);
|
||||
|
||||
GncEntryPaymentType gncEntryGetBillPayment (GncEntry* entry);
|
||||
GncEntryPaymentType gncEntryGetBillPayment (const GncEntry* entry);
|
||||
/** @} */
|
||||
|
||||
void gncEntryCopy (const GncEntry *src, GncEntry *dest);
|
||||
@ -201,7 +201,7 @@ void gncEntryGetValue (GncEntry *entry, gboolean is_inv, gnc_numeric *value,
|
||||
GList **tax_values);
|
||||
|
||||
void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
|
||||
GncTaxTable *tax_table, gboolean tax_included,
|
||||
const GncTaxTable *tax_table, gboolean tax_included,
|
||||
gnc_numeric discount, GncAmountType discount_type,
|
||||
GncDiscountHow discount_how, int SCU,
|
||||
/* return values */
|
||||
@ -210,9 +210,9 @@ void gncEntryComputeValue (gnc_numeric qty, gnc_numeric price,
|
||||
|
||||
/** @} */
|
||||
|
||||
GncOrder * gncEntryGetOrder (GncEntry *entry);
|
||||
GncInvoice * gncEntryGetInvoice (GncEntry *entry);
|
||||
GncInvoice * gncEntryGetBill (GncEntry *entry);
|
||||
GncOrder * gncEntryGetOrder (const GncEntry *entry);
|
||||
GncInvoice * gncEntryGetInvoice (const GncEntry *entry);
|
||||
GncInvoice * gncEntryGetBill (const GncEntry *entry);
|
||||
|
||||
/** Return a pointer to the instance gncEntry that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
@ -223,10 +223,10 @@ GncInvoice * gncEntryGetBill (GncEntry *entry);
|
||||
#define gncEntryLookup(book,guid) \
|
||||
QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_ENTRY, GncEntry)
|
||||
|
||||
gboolean gncEntryIsOpen (GncEntry *entry);
|
||||
gboolean gncEntryIsOpen (const GncEntry *entry);
|
||||
void gncEntryBeginEdit (GncEntry *entry);
|
||||
void gncEntryCommitEdit (GncEntry *entry);
|
||||
int gncEntryCompare (GncEntry *a, GncEntry *b);
|
||||
int gncEntryCompare (const GncEntry *a, const GncEntry *b);
|
||||
|
||||
#define ENTRY_DATE "date"
|
||||
#define ENTRY_DATE_ENTERED "date-entered"
|
||||
|
@ -469,7 +469,7 @@ void gncInvoiceSortEntries (GncInvoice *invoice)
|
||||
/* ================================================================== */
|
||||
/* Get Functions */
|
||||
|
||||
const char * gncInvoiceGetID (GncInvoice *invoice)
|
||||
const char * gncInvoiceGetID (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return NULL;
|
||||
return invoice->id;
|
||||
@ -501,21 +501,21 @@ qofInvoiceGetBillTo (GncInvoice *invoice)
|
||||
return QOF_INSTANCE(billto);
|
||||
}
|
||||
|
||||
Timespec gncInvoiceGetDateOpened (GncInvoice *invoice)
|
||||
Timespec gncInvoiceGetDateOpened (const GncInvoice *invoice)
|
||||
{
|
||||
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
||||
if (!invoice) return ts;
|
||||
return invoice->date_opened;
|
||||
}
|
||||
|
||||
Timespec gncInvoiceGetDatePosted (GncInvoice *invoice)
|
||||
Timespec gncInvoiceGetDatePosted (const GncInvoice *invoice)
|
||||
{
|
||||
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
||||
if (!invoice) return ts;
|
||||
return invoice->date_posted;
|
||||
}
|
||||
|
||||
Timespec gncInvoiceGetDateDue (GncInvoice *invoice)
|
||||
Timespec gncInvoiceGetDateDue (const GncInvoice *invoice)
|
||||
{
|
||||
Transaction *txn;
|
||||
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
||||
@ -525,19 +525,19 @@ Timespec gncInvoiceGetDateDue (GncInvoice *invoice)
|
||||
return xaccTransRetDateDueTS (txn);
|
||||
}
|
||||
|
||||
GncBillTerm * gncInvoiceGetTerms (GncInvoice *invoice)
|
||||
GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return 0;
|
||||
if (!invoice) return NULL;
|
||||
return invoice->terms;
|
||||
}
|
||||
|
||||
const char * gncInvoiceGetBillingID (GncInvoice *invoice)
|
||||
const char * gncInvoiceGetBillingID (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return 0;
|
||||
if (!invoice) return NULL;
|
||||
return invoice->billing_id;
|
||||
}
|
||||
|
||||
const char * gncInvoiceGetNotes (GncInvoice *invoice)
|
||||
const char * gncInvoiceGetNotes (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return NULL;
|
||||
return invoice->notes;
|
||||
@ -629,7 +629,7 @@ const char * gncInvoiceGetType (GncInvoice *invoice)
|
||||
}
|
||||
}
|
||||
|
||||
gnc_commodity * gncInvoiceGetCurrency (GncInvoice *invoice)
|
||||
gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return NULL;
|
||||
return invoice->currency;
|
||||
@ -641,32 +641,32 @@ GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice)
|
||||
return &invoice->billto;
|
||||
}
|
||||
|
||||
GNCLot * gncInvoiceGetPostedLot (GncInvoice *invoice)
|
||||
GNCLot * gncInvoiceGetPostedLot (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return NULL;
|
||||
return invoice->posted_lot;
|
||||
}
|
||||
|
||||
Transaction * gncInvoiceGetPostedTxn (GncInvoice *invoice)
|
||||
Transaction * gncInvoiceGetPostedTxn (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return NULL;
|
||||
return invoice->posted_txn;
|
||||
}
|
||||
|
||||
Account * gncInvoiceGetPostedAcc (GncInvoice *invoice)
|
||||
Account * gncInvoiceGetPostedAcc (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return NULL;
|
||||
return invoice->posted_acc;
|
||||
}
|
||||
|
||||
gboolean gncInvoiceGetActive (GncInvoice *invoice)
|
||||
gboolean gncInvoiceGetActive (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return FALSE;
|
||||
return invoice->active;
|
||||
}
|
||||
|
||||
|
||||
gnc_numeric gncInvoiceGetToChargeAmount (GncInvoice *invoice)
|
||||
gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return gnc_numeric_zero();
|
||||
return invoice->to_charge_amount;
|
||||
@ -724,7 +724,7 @@ qofInvoiceSetEntries(GncInvoice *invoice, QofCollection *entry_coll)
|
||||
}
|
||||
|
||||
static GncJob*
|
||||
qofInvoiceGetJob (GncInvoice *invoice)
|
||||
qofInvoiceGetJob (const GncInvoice *invoice)
|
||||
{
|
||||
if(!invoice) { return NULL; }
|
||||
return invoice->job;
|
||||
@ -806,7 +806,7 @@ gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn)
|
||||
}
|
||||
|
||||
GncInvoice *
|
||||
gncInvoiceGetInvoiceFromTxn (Transaction *txn)
|
||||
gncInvoiceGetInvoiceFromTxn (const Transaction *txn)
|
||||
{
|
||||
KvpFrame *kvp;
|
||||
KvpValue *value;
|
||||
@ -1454,20 +1454,20 @@ gncOwnerApplyPayment (GncOwner *owner, GncInvoice* invoice,
|
||||
return txn;
|
||||
}
|
||||
|
||||
static gboolean gncInvoiceDateExists (Timespec *date)
|
||||
static gboolean gncInvoiceDateExists (const Timespec *date)
|
||||
{
|
||||
g_return_val_if_fail (date, FALSE);
|
||||
if (date->tv_sec || date->tv_nsec) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean gncInvoiceIsPosted (GncInvoice *invoice)
|
||||
gboolean gncInvoiceIsPosted (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return FALSE;
|
||||
return gncInvoiceDateExists (&(invoice->date_posted));
|
||||
}
|
||||
|
||||
gboolean gncInvoiceIsPaid (GncInvoice *invoice)
|
||||
gboolean gncInvoiceIsPaid (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return FALSE;
|
||||
if (!invoice->posted_lot) return FALSE;
|
||||
@ -1501,7 +1501,7 @@ void gncInvoiceCommitEdit (GncInvoice *invoice)
|
||||
gncInvoiceOnDone, invoice_free);
|
||||
}
|
||||
|
||||
int gncInvoiceCompare (GncInvoice *a, GncInvoice *b)
|
||||
int gncInvoiceCompare (const GncInvoice *a, const GncInvoice *b)
|
||||
{
|
||||
int compare;
|
||||
|
||||
|
@ -97,23 +97,23 @@ void gncInvoiceSortEntries (GncInvoice *invoice);
|
||||
|
||||
/** @name Get Functions
|
||||
@{ */
|
||||
const char * gncInvoiceGetID (GncInvoice *invoice);
|
||||
const char * gncInvoiceGetID (const GncInvoice *invoice);
|
||||
GncOwner * gncInvoiceGetOwner (GncInvoice *invoice);
|
||||
Timespec gncInvoiceGetDateOpened (GncInvoice *invoice);
|
||||
Timespec gncInvoiceGetDatePosted (GncInvoice *invoice);
|
||||
Timespec gncInvoiceGetDateDue (GncInvoice *invoice);
|
||||
GncBillTerm * gncInvoiceGetTerms (GncInvoice *invoice);
|
||||
const char * gncInvoiceGetBillingID (GncInvoice *invoice);
|
||||
const char * gncInvoiceGetNotes (GncInvoice *invoice);
|
||||
Timespec gncInvoiceGetDateOpened (const GncInvoice *invoice);
|
||||
Timespec gncInvoiceGetDatePosted (const GncInvoice *invoice);
|
||||
Timespec gncInvoiceGetDateDue (const GncInvoice *invoice);
|
||||
GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice);
|
||||
const char * gncInvoiceGetBillingID (const GncInvoice *invoice);
|
||||
const char * gncInvoiceGetNotes (const GncInvoice *invoice);
|
||||
const char * gncInvoiceGetType (GncInvoice *invoice);
|
||||
gnc_commodity * gncInvoiceGetCurrency (GncInvoice *invoice);
|
||||
gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice);
|
||||
GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice);
|
||||
gnc_numeric gncInvoiceGetToChargeAmount (GncInvoice *invoice);
|
||||
gboolean gncInvoiceGetActive (GncInvoice *invoice);
|
||||
gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice);
|
||||
gboolean gncInvoiceGetActive (const GncInvoice *invoice);
|
||||
|
||||
GNCLot * gncInvoiceGetPostedLot (GncInvoice *invoice);
|
||||
Transaction * gncInvoiceGetPostedTxn (GncInvoice *invoice);
|
||||
Account * gncInvoiceGetPostedAcc (GncInvoice *invoice);
|
||||
GNCLot * gncInvoiceGetPostedLot (const GncInvoice *invoice);
|
||||
Transaction * gncInvoiceGetPostedTxn (const GncInvoice *invoice);
|
||||
Account * gncInvoiceGetPostedAcc (const GncInvoice *invoice);
|
||||
/** @} */
|
||||
|
||||
/** return the "total" amount of the invoice */
|
||||
@ -165,7 +165,7 @@ gncOwnerApplyPayment (GncOwner *owner, GncInvoice *invoice,
|
||||
|
||||
|
||||
/** Given a transaction, find and return the Invoice */
|
||||
GncInvoice * gncInvoiceGetInvoiceFromTxn (Transaction *txn);
|
||||
GncInvoice * gncInvoiceGetInvoiceFromTxn (const Transaction *txn);
|
||||
|
||||
/** Given a LOT, find and return the Invoice attached to the lot */
|
||||
GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot);
|
||||
@ -181,9 +181,9 @@ GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot);
|
||||
|
||||
void gncInvoiceBeginEdit (GncInvoice *invoice);
|
||||
void gncInvoiceCommitEdit (GncInvoice *invoice);
|
||||
int gncInvoiceCompare (GncInvoice *a, GncInvoice *b);
|
||||
gboolean gncInvoiceIsPosted (GncInvoice *invoice);
|
||||
gboolean gncInvoiceIsPaid (GncInvoice *invoice);
|
||||
int gncInvoiceCompare (const GncInvoice *a, const GncInvoice *b);
|
||||
gboolean gncInvoiceIsPosted (const GncInvoice *invoice);
|
||||
gboolean gncInvoiceIsPaid (const GncInvoice *invoice);
|
||||
|
||||
#define INVOICE_ID "id"
|
||||
#define INVOICE_OWNER "owner"
|
||||
|
@ -307,19 +307,19 @@ void gncJobCommitEdit (GncJob *job)
|
||||
/* ================================================================== */
|
||||
/* Get Functions */
|
||||
|
||||
const char * gncJobGetID (GncJob *job)
|
||||
const char * gncJobGetID (const GncJob *job)
|
||||
{
|
||||
if (!job) return NULL;
|
||||
return job->id;
|
||||
}
|
||||
|
||||
const char * gncJobGetName (GncJob *job)
|
||||
const char * gncJobGetName (const GncJob *job)
|
||||
{
|
||||
if (!job) return NULL;
|
||||
return job->name;
|
||||
}
|
||||
|
||||
const char * gncJobGetReference (GncJob *job)
|
||||
const char * gncJobGetReference (const GncJob *job)
|
||||
{
|
||||
if (!job) return NULL;
|
||||
return job->desc;
|
||||
@ -331,7 +331,7 @@ GncOwner * gncJobGetOwner (GncJob *job)
|
||||
return &(job->owner);
|
||||
}
|
||||
|
||||
gboolean gncJobGetActive (GncJob *job)
|
||||
gboolean gncJobGetActive (const GncJob *job)
|
||||
{
|
||||
if (!job) return FALSE;
|
||||
return job->active;
|
||||
|
@ -76,13 +76,13 @@ void gncJobCommitEdit (GncJob *job);
|
||||
@{
|
||||
*/
|
||||
|
||||
const char * gncJobGetID (GncJob *job);
|
||||
const char * gncJobGetName (GncJob *job);
|
||||
const char * gncJobGetReference (GncJob *job);
|
||||
const char * gncJobGetID (const GncJob *job);
|
||||
const char * gncJobGetName (const GncJob *job);
|
||||
const char * gncJobGetReference (const GncJob *job);
|
||||
GncOwner * gncJobGetOwner (GncJob *job);
|
||||
|
||||
/** @} */
|
||||
gboolean gncJobGetActive (GncJob *job);
|
||||
gboolean gncJobGetActive (const GncJob *job);
|
||||
|
||||
/** Return a pointer to the instance gncJob that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
|
@ -293,7 +293,7 @@ void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry)
|
||||
|
||||
/* Get Functions */
|
||||
|
||||
const char * gncOrderGetID (GncOrder *order)
|
||||
const char * gncOrderGetID (const GncOrder *order)
|
||||
{
|
||||
if (!order) return NULL;
|
||||
return order->id;
|
||||
@ -305,33 +305,33 @@ GncOwner * gncOrderGetOwner (GncOrder *order)
|
||||
return &order->owner;
|
||||
}
|
||||
|
||||
Timespec gncOrderGetDateOpened (GncOrder *order)
|
||||
Timespec gncOrderGetDateOpened (const GncOrder *order)
|
||||
{
|
||||
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
||||
if (!order) return ts;
|
||||
return order->opened;
|
||||
}
|
||||
|
||||
Timespec gncOrderGetDateClosed (GncOrder *order)
|
||||
Timespec gncOrderGetDateClosed (const GncOrder *order)
|
||||
{
|
||||
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
||||
if (!order) return ts;
|
||||
return order->closed;
|
||||
}
|
||||
|
||||
const char * gncOrderGetNotes (GncOrder *order)
|
||||
const char * gncOrderGetNotes (const GncOrder *order)
|
||||
{
|
||||
if (!order) return NULL;
|
||||
return order->notes;
|
||||
}
|
||||
|
||||
const char * gncOrderGetReference (GncOrder *order)
|
||||
const char * gncOrderGetReference (const GncOrder *order)
|
||||
{
|
||||
if (!order) return NULL;
|
||||
return order->reference;
|
||||
}
|
||||
|
||||
gboolean gncOrderGetActive (GncOrder *order)
|
||||
gboolean gncOrderGetActive (const GncOrder *order)
|
||||
{
|
||||
if (!order) return FALSE;
|
||||
return order->active;
|
||||
@ -344,7 +344,7 @@ GList * gncOrderGetEntries (GncOrder *order)
|
||||
return order->entries;
|
||||
}
|
||||
|
||||
gboolean gncOrderIsClosed (GncOrder *order)
|
||||
gboolean gncOrderIsClosed (const GncOrder *order)
|
||||
{
|
||||
if (!order) return FALSE;
|
||||
if (order->closed.tv_sec || order->closed.tv_nsec) return TRUE;
|
||||
@ -378,7 +378,7 @@ void gncOrderCommitEdit (GncOrder *order)
|
||||
gncOrderOnDone, order_free);
|
||||
}
|
||||
|
||||
int gncOrderCompare (GncOrder *a, GncOrder *b)
|
||||
int gncOrderCompare (const GncOrder *a, const GncOrder *b)
|
||||
{
|
||||
int compare;
|
||||
|
||||
|
@ -78,22 +78,22 @@ void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry);
|
||||
|
||||
/* Get Functions */
|
||||
|
||||
const char * gncOrderGetID (GncOrder *order);
|
||||
const char * gncOrderGetID (const GncOrder *order);
|
||||
GncOwner * gncOrderGetOwner (GncOrder *order);
|
||||
Timespec gncOrderGetDateOpened (GncOrder *order);
|
||||
Timespec gncOrderGetDateClosed (GncOrder *order);
|
||||
const char * gncOrderGetNotes (GncOrder *order);
|
||||
const char * gncOrderGetReference (GncOrder *order);
|
||||
gboolean gncOrderGetActive (GncOrder *order);
|
||||
Timespec gncOrderGetDateOpened (const GncOrder *order);
|
||||
Timespec gncOrderGetDateClosed (const GncOrder *order);
|
||||
const char * gncOrderGetNotes (const GncOrder *order);
|
||||
const char * gncOrderGetReference (const GncOrder *order);
|
||||
gboolean gncOrderGetActive (const GncOrder *order);
|
||||
|
||||
/* Get the list Entries */
|
||||
GList * gncOrderGetEntries (GncOrder *order);
|
||||
|
||||
void gncOrderBeginEdit (GncOrder *order);
|
||||
void gncOrderCommitEdit (GncOrder *order);
|
||||
int gncOrderCompare (GncOrder *a, GncOrder *b);
|
||||
int gncOrderCompare (const GncOrder *a, const GncOrder *b);
|
||||
|
||||
gboolean gncOrderIsClosed (GncOrder *order);
|
||||
gboolean gncOrderIsClosed (const GncOrder *order);
|
||||
|
||||
/** Return a pointer to the instance gncOrder that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
|
@ -103,7 +103,7 @@ GncOwnerType gncOwnerGetType (const GncOwner *owner)
|
||||
}
|
||||
|
||||
QofIdType
|
||||
qofOwnerGetType(GncOwner *owner)
|
||||
qofOwnerGetType(const GncOwner *owner)
|
||||
{
|
||||
QofIdType type;
|
||||
|
||||
@ -139,7 +139,7 @@ qofOwnerGetType(GncOwner *owner)
|
||||
}
|
||||
|
||||
QofInstance*
|
||||
qofOwnerGetOwner (GncOwner *owner)
|
||||
qofOwnerGetOwner (const GncOwner *owner)
|
||||
{
|
||||
QofInstance *ent;
|
||||
|
||||
@ -234,7 +234,7 @@ GncEmployee * gncOwnerGetEmployee (const GncOwner *owner)
|
||||
return owner->owner.employee;
|
||||
}
|
||||
|
||||
gnc_commodity * gncOwnerGetCurrency (GncOwner *owner)
|
||||
gnc_commodity * gncOwnerGetCurrency (const GncOwner *owner)
|
||||
{
|
||||
if (!owner) return NULL;
|
||||
switch (owner->type) {
|
||||
@ -297,7 +297,7 @@ gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b)
|
||||
return (a->owner.undefined == b->owner.undefined);
|
||||
}
|
||||
|
||||
const char * gncOwnerGetName (GncOwner *owner)
|
||||
const char * gncOwnerGetName (const GncOwner *owner)
|
||||
{
|
||||
if (!owner) return NULL;
|
||||
switch (owner->type) {
|
||||
@ -316,7 +316,7 @@ const char * gncOwnerGetName (GncOwner *owner)
|
||||
}
|
||||
}
|
||||
|
||||
const GUID * gncOwnerGetGUID (GncOwner *owner)
|
||||
const GUID * gncOwnerGetGUID (const GncOwner *owner)
|
||||
{
|
||||
if (!owner) return NULL;
|
||||
|
||||
@ -393,7 +393,7 @@ const GUID * gncOwnerGetEndGUID (GncOwner *owner)
|
||||
return gncOwnerGetGUID (owner);
|
||||
}
|
||||
|
||||
void gncOwnerAttachToLot (GncOwner *owner, GNCLot *lot)
|
||||
void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot)
|
||||
{
|
||||
KvpFrame *kvp;
|
||||
KvpValue *value;
|
||||
@ -458,7 +458,7 @@ gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner)
|
||||
return (owner->owner.undefined != NULL);
|
||||
}
|
||||
|
||||
gboolean gncOwnerIsValid (GncOwner *owner)
|
||||
gboolean gncOwnerIsValid (const GncOwner *owner)
|
||||
{
|
||||
if (!owner) return FALSE;
|
||||
return (owner->owner.undefined != NULL);
|
||||
|
@ -61,9 +61,9 @@ to QOF as they can be used by objects like GncInvoice.
|
||||
@{
|
||||
*/
|
||||
/** return the type for the collection. */
|
||||
QofIdType qofOwnerGetType(GncOwner *owner);
|
||||
QofIdType qofOwnerGetType(const GncOwner *owner);
|
||||
/** return the owner itself as an entity. */
|
||||
QofInstance* qofOwnerGetOwner (GncOwner *owner);
|
||||
QofInstance* qofOwnerGetOwner (const GncOwner *owner);
|
||||
/** set the owner from the entity. */
|
||||
void qofOwnerSetEntity (GncOwner *owner, QofInstance *ent);
|
||||
|
||||
@ -112,14 +112,14 @@ void gncOwnerCopy (const GncOwner *src, GncOwner *dest);
|
||||
gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b);
|
||||
int gncOwnerCompare (const GncOwner *a, const GncOwner *b);
|
||||
|
||||
const char * gncOwnerGetName (GncOwner *owner);
|
||||
gnc_commodity * gncOwnerGetCurrency (GncOwner *owner);
|
||||
const char * gncOwnerGetName (const GncOwner *owner);
|
||||
gnc_commodity * gncOwnerGetCurrency (const GncOwner *owner);
|
||||
|
||||
/** Get the GUID of the immediate owner */
|
||||
const GUID * gncOwnerGetGUID (GncOwner *owner);
|
||||
const GUID * gncOwnerGetGUID (const GncOwner *owner);
|
||||
GUID gncOwnerRetGUID (GncOwner *owner);
|
||||
|
||||
gboolean gncOwnerIsValid (GncOwner *owner);
|
||||
gboolean gncOwnerIsValid (const GncOwner *owner);
|
||||
|
||||
/**
|
||||
* Get the "parent" Owner or GUID thereof. The "parent" owner
|
||||
@ -129,7 +129,7 @@ GncOwner * gncOwnerGetEndOwner (GncOwner *owner);
|
||||
const GUID * gncOwnerGetEndGUID (GncOwner *owner);
|
||||
|
||||
/** attach an owner to a lot */
|
||||
void gncOwnerAttachToLot (GncOwner *owner, GNCLot *lot);
|
||||
void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot);
|
||||
|
||||
/** Get the owner from the lot. If an owner is found in the lot,
|
||||
* fill in "owner" and return TRUE. Otherwise return FALSE.
|
||||
|
@ -66,7 +66,7 @@ struct _book_info
|
||||
GList * tables; /* visible tables */
|
||||
};
|
||||
|
||||
static GncTaxTableEntry * CloneTaxEntry (GncTaxTableEntry*, QofBook *);
|
||||
static GncTaxTableEntry * CloneTaxEntry (const GncTaxTableEntry*, QofBook *);
|
||||
|
||||
static QofLogModule log_module = GNC_MOD_BUSINESS;
|
||||
|
||||
@ -194,7 +194,7 @@ gncTaxTableAddChild (GncTaxTable *table, GncTaxTable *child)
|
||||
}
|
||||
|
||||
static inline void
|
||||
gncTaxTableRemoveChild (GncTaxTable *table, GncTaxTable *child)
|
||||
gncTaxTableRemoveChild (GncTaxTable *table, const GncTaxTable *child)
|
||||
{
|
||||
g_return_if_fail(table);
|
||||
g_return_if_fail(child);
|
||||
@ -291,7 +291,7 @@ gncCloneTaxTable (GncTaxTable *from, QofBook *book)
|
||||
}
|
||||
|
||||
GncTaxTable *
|
||||
gncTaxTableObtainTwin (GncTaxTable *from, QofBook *book)
|
||||
gncTaxTableObtainTwin (const GncTaxTable *from, QofBook *book)
|
||||
{
|
||||
GncTaxTable *table;
|
||||
if (!from) return NULL;
|
||||
@ -370,7 +370,7 @@ void gncTaxTableEntryDestroy (GncTaxTableEntry *entry)
|
||||
* we set it above, when cloning the table).
|
||||
*/
|
||||
static GncTaxTableEntry *
|
||||
CloneTaxEntry (GncTaxTableEntry*from, QofBook *book)
|
||||
CloneTaxEntry (const GncTaxTableEntry*from, QofBook *book)
|
||||
{
|
||||
QofInstance *acc;
|
||||
GncTaxTableEntry *entry;
|
||||
@ -575,13 +575,13 @@ GList * gncTaxTableGetTables (QofBook *book)
|
||||
return bi->tables;
|
||||
}
|
||||
|
||||
const char *gncTaxTableGetName (GncTaxTable *table)
|
||||
const char *gncTaxTableGetName (const GncTaxTable *table)
|
||||
{
|
||||
if (!table) return NULL;
|
||||
return table->name;
|
||||
}
|
||||
|
||||
static GncTaxTableEntry *gncTaxTableEntryCopy (GncTaxTableEntry *entry)
|
||||
static GncTaxTableEntry *gncTaxTableEntryCopy (const GncTaxTableEntry *entry)
|
||||
{
|
||||
GncTaxTableEntry *e;
|
||||
if (!entry) return NULL;
|
||||
@ -594,7 +594,7 @@ static GncTaxTableEntry *gncTaxTableEntryCopy (GncTaxTableEntry *entry)
|
||||
return e;
|
||||
}
|
||||
|
||||
static GncTaxTable *gncTaxTableCopy (GncTaxTable *table)
|
||||
static GncTaxTable *gncTaxTableCopy (const GncTaxTable *table)
|
||||
{
|
||||
GncTaxTable *t;
|
||||
GList *list;
|
||||
@ -626,56 +626,62 @@ GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new)
|
||||
return child;
|
||||
}
|
||||
|
||||
GncTaxTable *gncTaxTableGetParent (GncTaxTable *table)
|
||||
GncTaxTable *gncTaxTableGetParent (const GncTaxTable *table)
|
||||
{
|
||||
if (!table) return NULL;
|
||||
return table->parent;
|
||||
}
|
||||
|
||||
GList *gncTaxTableGetEntries (GncTaxTable *table)
|
||||
GList *gncTaxTableGetEntries (const GncTaxTable *table)
|
||||
{
|
||||
if (!table) return NULL;
|
||||
return table->entries;
|
||||
}
|
||||
|
||||
gint64 gncTaxTableGetRefcount (GncTaxTable *table)
|
||||
gint64 gncTaxTableGetRefcount (const GncTaxTable *table)
|
||||
{
|
||||
if (!table) return 0;
|
||||
return table->refcount;
|
||||
}
|
||||
|
||||
Timespec gncTaxTableLastModified (GncTaxTable *table)
|
||||
Timespec gncTaxTableLastModified (const GncTaxTable *table)
|
||||
{
|
||||
Timespec ts = { 0 , 0 };
|
||||
if (!table) return ts;
|
||||
return table->modtime;
|
||||
}
|
||||
|
||||
gboolean gncTaxTableGetInvisible (GncTaxTable *table)
|
||||
gboolean gncTaxTableGetInvisible (const GncTaxTable *table)
|
||||
{
|
||||
if (!table) return FALSE;
|
||||
return table->invisible;
|
||||
}
|
||||
|
||||
Account * gncTaxTableEntryGetAccount (GncTaxTableEntry *entry)
|
||||
Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->account;
|
||||
}
|
||||
|
||||
GncAmountType gncTaxTableEntryGetType (GncTaxTableEntry *entry)
|
||||
GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry)
|
||||
{
|
||||
if (!entry) return 0;
|
||||
return entry->type;
|
||||
}
|
||||
|
||||
gnc_numeric gncTaxTableEntryGetAmount (GncTaxTableEntry *entry)
|
||||
gnc_numeric gncTaxTableEntryGetAmount (const GncTaxTableEntry *entry)
|
||||
{
|
||||
if (!entry) return gnc_numeric_zero();
|
||||
return entry->amount;
|
||||
}
|
||||
|
||||
int gncTaxTableEntryCompare (GncTaxTableEntry *a, GncTaxTableEntry *b)
|
||||
GncTaxTable* gncTaxTableEntryGetTable( const GncTaxTableEntry* entry )
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->table;
|
||||
}
|
||||
|
||||
int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *b)
|
||||
{
|
||||
char *name_a, *name_b;
|
||||
int retval;
|
||||
@ -696,7 +702,7 @@ int gncTaxTableEntryCompare (GncTaxTableEntry *a, GncTaxTableEntry *b)
|
||||
return gnc_numeric_compare (a->amount, b->amount);
|
||||
}
|
||||
|
||||
int gncTaxTableCompare (GncTaxTable *a, GncTaxTable *b)
|
||||
int gncTaxTableCompare (const GncTaxTable *a, const GncTaxTable *b)
|
||||
{
|
||||
if (!a && !b) return 0;
|
||||
if (!a) return -1;
|
||||
|
@ -149,21 +149,21 @@ GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name);
|
||||
|
||||
GList * gncTaxTableGetTables (QofBook *book);
|
||||
|
||||
const char *gncTaxTableGetName (GncTaxTable *table);
|
||||
GncTaxTable *gncTaxTableGetParent (GncTaxTable *table);
|
||||
const char *gncTaxTableGetName (const GncTaxTable *table);
|
||||
GncTaxTable *gncTaxTableGetParent (const GncTaxTable *table);
|
||||
GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new);
|
||||
#define gncTaxTableGetChild(t) gncTaxTableReturnChild((t),FALSE)
|
||||
GList *gncTaxTableGetEntries (GncTaxTable *table);
|
||||
gint64 gncTaxTableGetRefcount (GncTaxTable *table);
|
||||
Timespec gncTaxTableLastModified (GncTaxTable *table);
|
||||
GList *gncTaxTableGetEntries (const GncTaxTable *table);
|
||||
gint64 gncTaxTableGetRefcount (const GncTaxTable *table);
|
||||
Timespec gncTaxTableLastModified (const GncTaxTable *table);
|
||||
|
||||
Account * gncTaxTableEntryGetAccount (GncTaxTableEntry *entry);
|
||||
GncAmountType gncTaxTableEntryGetType (GncTaxTableEntry *entry);
|
||||
gnc_numeric gncTaxTableEntryGetAmount (GncTaxTableEntry *entry);
|
||||
Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry);
|
||||
GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry);
|
||||
gnc_numeric gncTaxTableEntryGetAmount (const GncTaxTableEntry *entry);
|
||||
/** @} */
|
||||
|
||||
int gncTaxTableCompare (GncTaxTable *a, GncTaxTable *b);
|
||||
int gncTaxTableEntryCompare (GncTaxTableEntry *a, GncTaxTableEntry *b);
|
||||
int gncTaxTableCompare (const GncTaxTable *a, const GncTaxTable *b);
|
||||
int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *b);
|
||||
|
||||
/************************************************/
|
||||
|
||||
|
@ -38,7 +38,7 @@ void gncTaxTableSetChild (GncTaxTable *table, GncTaxTable *child);
|
||||
void gncTaxTableSetRefcount (GncTaxTable *table, gint64 refcount);
|
||||
void gncTaxTableMakeInvisible (GncTaxTable *table);
|
||||
|
||||
gboolean gncTaxTableGetInvisible (GncTaxTable *table);
|
||||
gboolean gncTaxTableGetInvisible (const GncTaxTable *table);
|
||||
|
||||
/** The gncCloneTaxTable() routine makes a copy of the indicated
|
||||
* tax table, placing it in the indicated book. It copies
|
||||
@ -61,7 +61,9 @@ GncTaxTable * gncCloneTaxTable (GncTaxTable *from, QofBook *book);
|
||||
* it from the other Get routines, which work in fundamentally
|
||||
* different ways.
|
||||
*/
|
||||
GncTaxTable * gncTaxTableObtainTwin (GncTaxTable *from, QofBook *book);
|
||||
GncTaxTable * gncTaxTableObtainTwin (const GncTaxTable *from, QofBook *book);
|
||||
|
||||
GncTaxTable* gncTaxTableEntryGetTable( const GncTaxTableEntry* entry );
|
||||
|
||||
#define gncTaxTableSetGUID(E,G) qof_instance_set_guid(QOF_INSTANCE(E),(G))
|
||||
|
||||
|
@ -346,68 +346,68 @@ qofVendorSetTaxIncluded(GncVendor *vendor, const char* type_string)
|
||||
/* ============================================================== */
|
||||
/* Get Functions */
|
||||
|
||||
const char * gncVendorGetID (GncVendor *vendor)
|
||||
const char * gncVendorGetID (const GncVendor *vendor)
|
||||
{
|
||||
if (!vendor) return NULL;
|
||||
return vendor->id;
|
||||
}
|
||||
|
||||
const char * gncVendorGetName (GncVendor *vendor)
|
||||
const char * gncVendorGetName (const GncVendor *vendor)
|
||||
{
|
||||
if (!vendor) return NULL;
|
||||
return vendor->name;
|
||||
}
|
||||
|
||||
GncAddress * gncVendorGetAddr (GncVendor *vendor)
|
||||
GncAddress * gncVendorGetAddr (const GncVendor *vendor)
|
||||
{
|
||||
if (!vendor) return NULL;
|
||||
return vendor->addr;
|
||||
}
|
||||
|
||||
const char * gncVendorGetNotes (GncVendor *vendor)
|
||||
const char * gncVendorGetNotes (const GncVendor *vendor)
|
||||
{
|
||||
if (!vendor) return NULL;
|
||||
return vendor->notes;
|
||||
}
|
||||
|
||||
GncBillTerm * gncVendorGetTerms (GncVendor *vendor)
|
||||
GncBillTerm * gncVendorGetTerms (const GncVendor *vendor)
|
||||
{
|
||||
if (!vendor) return 0;
|
||||
return vendor->terms;
|
||||
}
|
||||
|
||||
GncTaxIncluded gncVendorGetTaxIncluded (GncVendor *vendor)
|
||||
GncTaxIncluded gncVendorGetTaxIncluded (const GncVendor *vendor)
|
||||
{
|
||||
if (!vendor) return GNC_TAXINCLUDED_USEGLOBAL;
|
||||
return vendor->taxincluded;
|
||||
}
|
||||
|
||||
gnc_commodity * gncVendorGetCurrency (GncVendor *vendor)
|
||||
gnc_commodity * gncVendorGetCurrency (const GncVendor *vendor)
|
||||
{
|
||||
if (!vendor) return NULL;
|
||||
return vendor->currency;
|
||||
}
|
||||
|
||||
gboolean gncVendorGetActive (GncVendor *vendor)
|
||||
gboolean gncVendorGetActive (const GncVendor *vendor)
|
||||
{
|
||||
if (!vendor) return FALSE;
|
||||
return vendor->active;
|
||||
}
|
||||
|
||||
gboolean gncVendorGetTaxTableOverride (GncVendor *vendor)
|
||||
gboolean gncVendorGetTaxTableOverride (const GncVendor *vendor)
|
||||
{
|
||||
if (!vendor) return FALSE;
|
||||
return vendor->taxtable_override;
|
||||
}
|
||||
|
||||
GncTaxTable* gncVendorGetTaxTable (GncVendor *vendor)
|
||||
GncTaxTable* gncVendorGetTaxTable (const GncVendor *vendor)
|
||||
{
|
||||
if (!vendor) return NULL;
|
||||
return vendor->taxtable;
|
||||
}
|
||||
|
||||
static const char*
|
||||
qofVendorGetTaxIncluded(GncVendor *vendor)
|
||||
qofVendorGetTaxIncluded(const GncVendor *vendor)
|
||||
{
|
||||
return gncTaxIncludedTypeToString(vendor->taxincluded);
|
||||
}
|
||||
@ -475,7 +475,7 @@ void gncVendorCommitEdit (GncVendor *vendor)
|
||||
/* ============================================================== */
|
||||
/* Other functions */
|
||||
|
||||
int gncVendorCompare (GncVendor *a, GncVendor *b)
|
||||
int gncVendorCompare (const GncVendor *a, const GncVendor *b)
|
||||
{
|
||||
if (!a && !b) return 0;
|
||||
if (!a && b) return 1;
|
||||
@ -484,7 +484,7 @@ int gncVendorCompare (GncVendor *a, GncVendor *b)
|
||||
return(strcmp(a->name, b->name));
|
||||
}
|
||||
|
||||
GList * gncVendorGetJoblist (GncVendor *vendor, gboolean show_all)
|
||||
GList * gncVendorGetJoblist (const GncVendor *vendor, gboolean show_all)
|
||||
{
|
||||
if (!vendor) return NULL;
|
||||
|
||||
@ -501,7 +501,7 @@ GList * gncVendorGetJoblist (GncVendor *vendor, gboolean show_all)
|
||||
}
|
||||
}
|
||||
|
||||
gboolean gncVendorIsDirty (GncVendor *vendor)
|
||||
gboolean gncVendorIsDirty (const GncVendor *vendor)
|
||||
{
|
||||
if (!vendor) return FALSE;
|
||||
return (qof_instance_get_dirty_flag(vendor)
|
||||
|
@ -86,25 +86,25 @@ void gncVendorCommitEdit (GncVendor *vendor);
|
||||
@{
|
||||
*/
|
||||
|
||||
const char * gncVendorGetID (GncVendor *vendor);
|
||||
const char * gncVendorGetName (GncVendor *vendor);
|
||||
GncAddress * gncVendorGetAddr (GncVendor *vendor);
|
||||
const char * gncVendorGetNotes (GncVendor *vendor);
|
||||
GncBillTerm * gncVendorGetTerms (GncVendor *vendor);
|
||||
GncTaxIncluded gncVendorGetTaxIncluded (GncVendor *vendor);
|
||||
gnc_commodity * gncVendorGetCurrency (GncVendor *vendor);
|
||||
gboolean gncVendorGetActive (GncVendor *vendor);
|
||||
const char * gncVendorGetID (const GncVendor *vendor);
|
||||
const char * gncVendorGetName (const GncVendor *vendor);
|
||||
GncAddress * gncVendorGetAddr (const GncVendor *vendor);
|
||||
const char * gncVendorGetNotes (const GncVendor *vendor);
|
||||
GncBillTerm * gncVendorGetTerms (const GncVendor *vendor);
|
||||
GncTaxIncluded gncVendorGetTaxIncluded (const GncVendor *vendor);
|
||||
gnc_commodity * gncVendorGetCurrency (const GncVendor *vendor);
|
||||
gboolean gncVendorGetActive (const GncVendor *vendor);
|
||||
|
||||
gboolean gncVendorGetTaxTableOverride (GncVendor *vendor);
|
||||
GncTaxTable* gncVendorGetTaxTable (GncVendor *vendor);
|
||||
gboolean gncVendorGetTaxTableOverride (const GncVendor *vendor);
|
||||
GncTaxTable* gncVendorGetTaxTable (const GncVendor *vendor);
|
||||
|
||||
/** @} */
|
||||
/** XXX should be renamed to RetJobList to be consistent with
|
||||
* other usage, since caller must free the copied list
|
||||
*/
|
||||
GList * gncVendorGetJoblist (GncVendor *vendor, gboolean show_all);
|
||||
gboolean gncVendorIsDirty (GncVendor *vendor);
|
||||
int gncVendorCompare (GncVendor *a, GncVendor *b);
|
||||
GList * gncVendorGetJoblist (const GncVendor *vendor, gboolean show_all);
|
||||
gboolean gncVendorIsDirty (const GncVendor *vendor);
|
||||
int gncVendorCompare (const GncVendor *a, const GncVendor *b);
|
||||
|
||||
/** Return a pointer to the instance gncVendor that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
|
54
src/business/business-core/sql/Makefile.am
Normal file
54
src/business/business-core/sql/Makefile.am
Normal file
@ -0,0 +1,54 @@
|
||||
SUBDIRS = .
|
||||
|
||||
pkglib_LTLIBRARIES = libgncmod-business-backend-sql.la
|
||||
|
||||
AM_CFLAGS = \
|
||||
-I${top_srcdir}/src \
|
||||
-I${top_srcdir}/src/backend \
|
||||
-I${top_srcdir}/src/backend/sql \
|
||||
-I${top_srcdir}/src/engine \
|
||||
-I${top_srcdir}/src/gnc-module \
|
||||
-I${top_srcdir}/src/business/business-core \
|
||||
${QOF_CFLAGS} \
|
||||
${GLIB_CFLAGS} \
|
||||
${LIBGDA_CFLAGS}
|
||||
|
||||
libgncmod_business_backend_sql_la_SOURCES = \
|
||||
gncmod-business-backend-sql.c \
|
||||
gnc-address-sql.c \
|
||||
gnc-bill-term-sql.c \
|
||||
gnc-customer-sql.c \
|
||||
gnc-employee-sql.c \
|
||||
gnc-entry-sql.c \
|
||||
gnc-invoice-sql.c \
|
||||
gnc-job-sql.c \
|
||||
gnc-order-sql.c \
|
||||
gnc-owner-sql.c \
|
||||
gnc-tax-table-sql.c \
|
||||
gnc-vendor-sql.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
gnc-address-sql.h \
|
||||
gnc-bill-term-sql.h \
|
||||
gnc-customer-sql.h \
|
||||
gnc-employee-sql.h \
|
||||
gnc-entry-sql.h \
|
||||
gnc-invoice-sql.h \
|
||||
gnc-job-sql.h \
|
||||
gnc-order-sql.h \
|
||||
gnc-owner-sql.h \
|
||||
gnc-tax-table-sql.h \
|
||||
gnc-vendor-sql.h
|
||||
|
||||
libgncmod_business_backend_sql_la_LDFLAGS = -module -avoid-version
|
||||
|
||||
libgncmod_business_backend_sql_la_LIBADD = \
|
||||
${top_builddir}/src/business/business-core/libgncmod-business-core.la \
|
||||
${top_builddir}/src/backend/sql/libgnc-backend-sql.la \
|
||||
${top_builddir}/src/engine/libgncmod-engine.la \
|
||||
${top_builddir}/src/gnc-module/libgnc-module.la \
|
||||
${QOF_LIBS} \
|
||||
${GLIB_LIBS} \
|
||||
${LIBGDA_LIBS}
|
||||
|
||||
INCLUDES = -DG_LOG_DOMAIN=\"gnc.backend.sql\"
|
212
src/business/business-core/sql/gnc-address-sql.c
Normal file
212
src/business/business-core/sql/gnc-address-sql.c
Normal file
@ -0,0 +1,212 @@
|
||||
/********************************************************************\
|
||||
* gnc-address-sql.c -- address sql backend implementation *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/** @file gnc-address-sql.c
|
||||
* @brief load and save address data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gnc-engine.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
#include "gnc-address-sql.h"
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define ADDRESS_MAX_NAME_LEN 1024
|
||||
#define ADDRESS_MAX_ADDRESS_LINE_LEN 1024
|
||||
#define ADDRESS_MAX_PHONE_LEN 128
|
||||
#define ADDRESS_MAX_FAX_LEN 128
|
||||
#define ADDRESS_MAX_EMAIL_LEN 256
|
||||
|
||||
static GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "name", CT_STRING, ADDRESS_MAX_NAME_LEN, COL_NNUL, NULL, ADDRESS_NAME },
|
||||
{ "addr1", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_ONE },
|
||||
{ "addr2", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_TWO },
|
||||
{ "addr3", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_THREE },
|
||||
{ "addr4", CT_STRING, ADDRESS_MAX_ADDRESS_LINE_LEN, COL_NNUL, NULL, ADDRESS_FOUR },
|
||||
{ "phone", CT_STRING, ADDRESS_MAX_PHONE_LEN, COL_NNUL, NULL, ADDRESS_PHONE },
|
||||
{ "fax", CT_STRING, ADDRESS_MAX_FAX_LEN, COL_NNUL, NULL, ADDRESS_FAX },
|
||||
{ "email", CT_STRING, ADDRESS_MAX_EMAIL_LEN, COL_NNUL, NULL, ADDRESS_EMAIL },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
typedef void (*AddressSetterFunc)( gpointer, GncAddress* );
|
||||
typedef GncAddress* (*AddressGetterFunc)( const gpointer );
|
||||
|
||||
static void
|
||||
load_address( const GncSqlBackend* be, GncSqlRow* row,
|
||||
QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
{
|
||||
const GValue* val;
|
||||
gchar* buf;
|
||||
GncAddress* addr;
|
||||
AddressSetterFunc a_setter = (AddressSetterFunc)setter;
|
||||
const GncSqlColumnTableEntry* subtable;
|
||||
const gchar* s;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
addr = gncAddressCreate( be->primary_book, NULL );
|
||||
for( subtable = col_table; subtable->col_name != NULL; subtable++ ) {
|
||||
buf = g_strdup_printf( "%s_%s", table_row->col_name, subtable->col_name );
|
||||
val = gnc_sql_row_get_value_at_col_name( row, buf );
|
||||
g_free( buf );
|
||||
if( val == NULL ) {
|
||||
s = NULL;
|
||||
} else {
|
||||
s = g_value_get_string( val );
|
||||
}
|
||||
if( subtable->gobj_param_name != NULL ) {
|
||||
g_object_set( addr, subtable->gobj_param_name, s, NULL );
|
||||
} else {
|
||||
if( subtable->qof_param_name != NULL ) {
|
||||
setter = qof_class_get_parameter_setter( GNC_ID_ADDRESS, subtable->qof_param_name );
|
||||
} else {
|
||||
setter = subtable->setter;
|
||||
}
|
||||
(*setter)( addr, (const gpointer)s );
|
||||
}
|
||||
}
|
||||
(*a_setter)( pObject, addr );
|
||||
}
|
||||
|
||||
static void
|
||||
add_address_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry* table_row,
|
||||
GList** pList )
|
||||
{
|
||||
GncSqlColumnInfo* info;
|
||||
gchar* buf;
|
||||
const GncSqlColumnTableEntry* subtable_row;
|
||||
const gchar* type;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
g_return_if_fail( pList != NULL );
|
||||
|
||||
for( subtable_row = col_table; subtable_row->col_name != NULL; subtable_row++ ) {
|
||||
buf = g_strdup_printf( "%s_%s", table_row->col_name, subtable_row->col_name );
|
||||
info = g_new0( GncSqlColumnInfo, 1 );
|
||||
info->name = buf;
|
||||
info->type_name = gnc_sql_connection_get_column_type_name( be->conn,
|
||||
G_TYPE_STRING, subtable_row->size );
|
||||
info->is_primary_key = (table_row->flags & COL_PKEY) ? TRUE : FALSE;
|
||||
info->size = subtable_row->size;
|
||||
info->null_allowed = (table_row->flags & COL_NNUL) ? FALSE : TRUE;
|
||||
*pList = g_list_append( *pList, info );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
add_address_colname_to_list( const GncSqlColumnTableEntry* table_row, GList** pList )
|
||||
{
|
||||
gnc_sql_add_subtable_colnames_to_list( table_row, col_table, pList );
|
||||
}
|
||||
|
||||
static void
|
||||
get_gvalue_address( const GncSqlBackend* be, QofIdTypeConst obj_name, const gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row, GValue* value )
|
||||
{
|
||||
AddressGetterFunc getter;
|
||||
GncAddress* addr;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( obj_name != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
g_return_if_fail( value != NULL );
|
||||
|
||||
memset( value, 0, sizeof( GValue ) );
|
||||
|
||||
getter = (AddressGetterFunc)gnc_sql_get_getter( obj_name, table_row );
|
||||
addr = (*getter)( pObject );
|
||||
g_value_init( value, gnc_address_get_type() );
|
||||
g_value_set_object( value, addr );
|
||||
}
|
||||
|
||||
static void
|
||||
add_gvalue_address_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
const gpointer pObject, const GncSqlColumnTableEntry* table_row, GSList** pList )
|
||||
{
|
||||
GValue value;
|
||||
GValue* subfield_value;
|
||||
GncAddress* addr;
|
||||
gchar* s;
|
||||
QofAccessFunc getter;
|
||||
const GncSqlColumnTableEntry* subtable_row;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( obj_name != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
memset( &value, 0, sizeof( GValue ) );
|
||||
get_gvalue_address( be, obj_name, pObject, table_row, &value );
|
||||
|
||||
if( G_VALUE_TYPE(&value) != 0 ) {
|
||||
addr = g_value_get_object( &value );
|
||||
for( subtable_row = col_table; subtable_row->col_name != NULL; subtable_row++ ) {
|
||||
subfield_value = g_new0( GValue, 1 );
|
||||
if( subtable_row->gobj_param_name != NULL ) {
|
||||
g_object_get( addr, subtable_row->gobj_param_name, &s, NULL );
|
||||
} else {
|
||||
getter = gnc_sql_get_getter( GNC_ID_ADDRESS, subtable_row );
|
||||
s = (gchar*)(*getter)( addr, NULL );
|
||||
}
|
||||
g_value_init( subfield_value, G_TYPE_STRING );
|
||||
if( s ) {
|
||||
g_value_set_string( subfield_value, s );
|
||||
} else {
|
||||
g_value_set_string( subfield_value, "NULL" );
|
||||
}
|
||||
(*pList) = g_slist_append( (*pList), subfield_value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static col_type_handler_t address_handler
|
||||
= { load_address,
|
||||
add_address_col_info_to_list,
|
||||
add_address_colname_to_list,
|
||||
add_gvalue_address_to_slist };
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_address_sql_initialize( void )
|
||||
{
|
||||
gnc_sql_register_col_type_handler( CT_ADDRESS, &address_handler );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
38
src/business/business-core/sql/gnc-address-sql.h
Normal file
38
src/business/business-core/sql/gnc-address-sql.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* gnc-address-sql.h -- Address SQL header
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, contact:
|
||||
*
|
||||
* Free Software Foundation Voice: +1-617-542-5942
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
*/
|
||||
|
||||
/** @file gnc-address-sql.h
|
||||
* @brief load and save address data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_ADDRESS_SQL_H
|
||||
#define GNC_ADDRESS_SQL_H
|
||||
|
||||
#include "gncAddress.h"
|
||||
|
||||
#define CT_ADDRESS "address"
|
||||
|
||||
void gnc_address_sql_initialize( void );
|
||||
|
||||
#endif /* GNC_ADDRESS_SQL_H */
|
242
src/business/business-core/sql/gnc-bill-term-sql.c
Normal file
242
src/business/business-core/sql/gnc-bill-term-sql.c
Normal file
@ -0,0 +1,242 @@
|
||||
/********************************************************************\
|
||||
* gnc-bill-term-sql.c -- billing term sql backend *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/** @file gnc-bill-term-sql.c
|
||||
* @brief load and save address data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
|
||||
#include "gncBillTermP.h"
|
||||
#include "gncInvoice.h"
|
||||
#include "gnc-bill-term-sql.h"
|
||||
#include "qof.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ID_BILLTERM
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define MAX_NAME_LEN 2048
|
||||
#define MAX_DESCRIPTION_LEN 2048
|
||||
#define MAX_TYPE_LEN 2048
|
||||
|
||||
static void set_invisible( gpointer data, gboolean value );
|
||||
|
||||
#define TABLE_NAME "billterms"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
static GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, NULL, GNC_BILLTERM_NAME },
|
||||
{ "description", CT_STRING, MAX_DESCRIPTION_LEN, COL_NNUL, NULL, GNC_BILLTERM_DESC },
|
||||
{ "refcount", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)gncBillTermGetRefcount, (QofSetterFunc)gncBillTermSetRefcount },
|
||||
{ "invisible", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)gncBillTermGetInvisible, (QofSetterFunc)set_invisible },
|
||||
{ "parent", CT_BILLTERMREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncBillTermGetParent, (QofSetterFunc)gncBillTermSetParent },
|
||||
{ "child", CT_BILLTERMREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncBillTermReturnChild, (QofSetterFunc)gncBillTermSetChild },
|
||||
{ "type", CT_STRING, MAX_TYPE_LEN, COL_NNUL, NULL, GNC_BILLTERM_TYPE },
|
||||
{ "duedays", CT_INT, 0, 0, 0, GNC_BILLTERM_DUEDAYS },
|
||||
{ "discountdays", CT_INT, 0, 0, 0, GNC_BILLTERM_DISCDAYS },
|
||||
{ "discount", CT_NUMERIC, 0, 0, 0, GNC_BILLTERM_DISCOUNT },
|
||||
{ "cutoff", CT_INT, 0, 0, 0, GNC_BILLTERM_CUTOFF },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static void
|
||||
set_invisible( gpointer data, gboolean value )
|
||||
{
|
||||
GncBillTerm* term = GNC_BILLTERM(data);
|
||||
|
||||
g_return_if_fail( term != NULL );
|
||||
|
||||
if( value ) {
|
||||
gncBillTermMakeInvisible( term );
|
||||
}
|
||||
}
|
||||
|
||||
static GncBillTerm*
|
||||
load_single_billterm( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GUID* guid;
|
||||
GncBillTerm* pBillTerm;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
pBillTerm = gncBillTermLookup( be->primary_book, guid );
|
||||
if( pBillTerm == NULL ) {
|
||||
pBillTerm = gncBillTermCreate( be->primary_book );
|
||||
}
|
||||
gnc_sql_load_object( be, row, GNC_ID_BILLTERM, pBillTerm, col_table );
|
||||
qof_instance_mark_clean( QOF_INSTANCE(pBillTerm) );
|
||||
|
||||
return pBillTerm;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_billterms( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
QofBook* pBook;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
pBook = be->primary_book;
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row;
|
||||
GList* list = NULL;
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while( row != NULL ) {
|
||||
GncBillTerm* pBillTerm = load_single_billterm( be, row );
|
||||
if( pBillTerm != NULL ) {
|
||||
list = g_list_append( list, pBillTerm );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
do_save_billterm( QofInstance* inst, gpointer p2 )
|
||||
{
|
||||
gnc_sql_save_billterm( (GncSqlBackend*)p2, inst );
|
||||
}
|
||||
|
||||
static void
|
||||
write_billterms( GncSqlBackend* be )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
qof_object_foreach( GNC_ID_BILLTERM, be->primary_book, do_save_billterm, (gpointer)be );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_billterm_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_save_billterm( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_BILLTERM(inst) );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_BILLTERM, col_table );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
load_billterm_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
{
|
||||
const GValue* val;
|
||||
GUID guid;
|
||||
const GUID* pGuid;
|
||||
GncBillTerm* term = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val == NULL || !G_VALUE_HOLDS_STRING( val ) || g_value_get_string( val ) == NULL ) {
|
||||
pGuid = NULL;
|
||||
} else {
|
||||
string_to_guid( g_value_get_string( val ), &guid );
|
||||
pGuid = &guid;
|
||||
}
|
||||
if( pGuid != NULL ) {
|
||||
term = gncBillTermLookup( be->primary_book, pGuid );
|
||||
}
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, term, NULL );
|
||||
} else {
|
||||
(*setter)( pObject, (const gpointer)term );
|
||||
}
|
||||
}
|
||||
|
||||
static col_type_handler_t billterm_guid_handler
|
||||
= { load_billterm_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist };
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_billterm_sql_initialize( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_BILLTERM,
|
||||
gnc_sql_save_billterm, /* commit */
|
||||
load_all_billterms, /* initial_load */
|
||||
create_billterm_tables, /* create_tables */
|
||||
NULL, NULL, NULL,
|
||||
write_billterms /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_BILLTERM, GNC_SQL_BACKEND, &be_data );
|
||||
|
||||
gnc_sql_register_col_type_handler( CT_BILLTERMREF, &billterm_guid_handler );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
40
src/business/business-core/sql/gnc-bill-term-sql.h
Normal file
40
src/business/business-core/sql/gnc-bill-term-sql.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* gnc-bill-term-sql.h -- billing term sql backend
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, contact:
|
||||
*
|
||||
* Free Software Foundation Voice: +1-617-542-5942
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
*/
|
||||
|
||||
/** @file gnc-bill-term-sql.h
|
||||
* @brief load and save accounts data to SQL
|
||||
* @author Copyright (c) 2006-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_BILLTERM_SQL_H
|
||||
#define GNC_BILLTERM_SQL_H
|
||||
|
||||
#include "gncBillTerm.h"
|
||||
|
||||
#define CT_BILLTERMREF "billterm"
|
||||
|
||||
void gnc_billterm_sql_initialize( void );
|
||||
void gnc_sql_save_billterm( GncSqlBackend* be, QofInstance* inst );
|
||||
|
||||
#endif /* GNC_BILLTERM_SQL_H */
|
216
src/business/business-core/sql/gnc-customer-sql.c
Normal file
216
src/business/business-core/sql/gnc-customer-sql.c
Normal file
@ -0,0 +1,216 @@
|
||||
/********************************************************************\
|
||||
* gnc-customer-sql.c -- customer sql backend *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/** @file gnc-customer-sql.c
|
||||
* @brief load and save address data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
|
||||
#include "gncBillTermP.h"
|
||||
#include "gncCustomerP.h"
|
||||
#include "gncTaxTableP.h"
|
||||
#include "gnc-customer-sql.h"
|
||||
#include "gnc-address-sql.h"
|
||||
#include "gnc-bill-term-sql.h"
|
||||
#include "gnc-tax-table-sql.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ID_CUSTOMER
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define TABLE_NAME "customers"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
#define MAX_NAME_LEN 2048
|
||||
#define MAX_ID_LEN 2048
|
||||
#define MAX_NOTES_LEN 2048
|
||||
|
||||
static GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, NULL, CUSTOMER_NAME },
|
||||
{ "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, CUSTOMER_ID },
|
||||
{ "notes", CT_STRING, MAX_NOTES_LEN, COL_NNUL, NULL, CUSTOMER_NOTES },
|
||||
{ "active", CT_BOOLEAN, 0, COL_NNUL, NULL, QOF_PARAM_ACTIVE },
|
||||
{ "discount", CT_NUMERIC, 0, COL_NNUL, NULL, CUSTOMER_DISCOUNT },
|
||||
{ "credit", CT_NUMERIC, 0, COL_NNUL, NULL, CUSTOMER_CREDIT },
|
||||
{ "currency", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)gncCustomerGetCurrency, (QofSetterFunc)gncCustomerSetCurrency },
|
||||
{ "tax_override", CT_BOOLEAN, 0, COL_NNUL, NULL, CUSTOMER_TT_OVER },
|
||||
{ "addr", CT_ADDRESS, 0, 0, NULL, CUSTOMER_ADDR },
|
||||
{ "shipaddr", CT_ADDRESS, 0, 0, NULL, CUSTOMER_SHIPADDR },
|
||||
{ "terms", CT_BILLTERMREF, 0, 0, NULL, CUSTOMER_TERMS },
|
||||
{ "tax_included", CT_INT, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncCustomerGetTaxIncluded, (QofSetterFunc)gncCustomerSetTaxIncluded },
|
||||
{ "taxtable", CT_TAXTABLEREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncCustomerGetTaxTable, (QofSetterFunc)gncCustomerSetTaxTable },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static GncCustomer*
|
||||
load_single_customer( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GUID* guid;
|
||||
GncCustomer* pCustomer;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
pCustomer = gncCustomerLookup( be->primary_book, guid );
|
||||
if( pCustomer == NULL ) {
|
||||
pCustomer = gncCustomerCreate( be->primary_book );
|
||||
}
|
||||
gnc_sql_load_object( be, row, GNC_ID_CUSTOMER, pCustomer, col_table );
|
||||
qof_instance_mark_clean( QOF_INSTANCE(pCustomer) );
|
||||
|
||||
return pCustomer;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_customers( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
QofBook* pBook;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
pBook = be->primary_book;
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GList* list = NULL;
|
||||
GncSqlRow* row;
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while( row != NULL ) {
|
||||
GncCustomer* pCustomer = load_single_customer( be, row );
|
||||
if( pCustomer != NULL ) {
|
||||
list = g_list_append( list, pCustomer );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_customer_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
save_customer( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_CUSTOMER(inst) );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_CUSTOMER, col_table );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static gboolean
|
||||
customer_should_be_saved( GncCustomer *customer )
|
||||
{
|
||||
const char *id;
|
||||
|
||||
g_return_val_if_fail( customer != NULL, FALSE );
|
||||
|
||||
/* Make sure this is a valid customer before we save it -- should have an ID */
|
||||
id = gncCustomerGetID( customer );
|
||||
if( id == NULL || *id == '\0' ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
write_single_customer( QofInstance *term_p, gpointer be_p )
|
||||
{
|
||||
GncSqlBackend* be = (GncSqlBackend*)be_p;
|
||||
|
||||
g_return_if_fail( term_p != NULL );
|
||||
g_return_if_fail( GNC_IS_CUSTOMER(term_p) );
|
||||
g_return_if_fail( be_p != NULL );
|
||||
|
||||
if( customer_should_be_saved( GNC_CUSTOMER(term_p) ) ) {
|
||||
save_customer( be, term_p );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
write_customers( GncSqlBackend* be )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
qof_object_foreach( GNC_ID_CUSTOMER, be->primary_book, write_single_customer, (gpointer)be );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_customer_sql_initialize( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_CUSTOMER,
|
||||
save_customer, /* commit */
|
||||
load_all_customers, /* initial_load */
|
||||
create_customer_tables, /* create_tables */
|
||||
NULL, NULL, NULL,
|
||||
write_customers /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_CUSTOMER, GNC_SQL_BACKEND, &be_data );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
35
src/business/business-core/sql/gnc-customer-sql.h
Normal file
35
src/business/business-core/sql/gnc-customer-sql.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* gnc-customer-sql.h -- customer sql backend
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, contact:
|
||||
*
|
||||
* Free Software Foundation Voice: +1-617-542-5942
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
*/
|
||||
|
||||
/** @file gnc-customer-sql.h
|
||||
* @brief load and save customer data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_CUSTOMER_SQL_H
|
||||
#define GNC_CUSTOMER_SQL_H
|
||||
|
||||
void gnc_customer_sql_initialize( void );
|
||||
|
||||
#endif /* GNC_CUSTOMER_SQL_H */
|
240
src/business/business-core/sql/gnc-employee-sql.c
Normal file
240
src/business/business-core/sql/gnc-employee-sql.c
Normal file
@ -0,0 +1,240 @@
|
||||
/********************************************************************\
|
||||
* gnc-employee-sql.c -- employee sql implementation *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/** @file gnc-employee-sql.c
|
||||
* @brief load and save address data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gnc-commodity.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
#include "gnc-commodity-sql.h"
|
||||
|
||||
#include "gncEmployeeP.h"
|
||||
#include "gnc-employee-sql.h"
|
||||
#include "gnc-address-sql.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ID_EMPLOYEE
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define MAX_USERNAME_LEN 2048
|
||||
#define MAX_ID_LEN 2048
|
||||
#define MAX_LANGUAGE_LEN 2048
|
||||
#define MAX_ACL_LEN 2048
|
||||
|
||||
#define TABLE_NAME "employees"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
static GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "username", CT_STRING, MAX_USERNAME_LEN, COL_NNUL, NULL, EMPLOYEE_USERNAME },
|
||||
{ "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, EMPLOYEE_ID },
|
||||
{ "language", CT_STRING, MAX_LANGUAGE_LEN, COL_NNUL, NULL, EMPLOYEE_LANGUAGE },
|
||||
{ "acl", CT_STRING, MAX_ACL_LEN, COL_NNUL, NULL, EMPLOYEE_ACL },
|
||||
{ "active", CT_BOOLEAN, 0, COL_NNUL, NULL, QOF_PARAM_ACTIVE },
|
||||
{ "currency", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)gncEmployeeGetCurrency, (QofSetterFunc)gncEmployeeSetCurrency },
|
||||
{ "ccard_guid", CT_ACCOUNTREF, 0, 0, NULL, EMPLOYEE_CC },
|
||||
{ "workday", CT_NUMERIC, 0, COL_NNUL, NULL, EMPLOYEE_WORKDAY },
|
||||
{ "rate", CT_NUMERIC, 0, COL_NNUL, NULL, EMPLOYEE_RATE },
|
||||
{ "addr", CT_ADDRESS, 0, 0, NULL, EMPLOYEE_ADDR },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static GncEmployee*
|
||||
load_single_employee( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GUID* guid;
|
||||
GncEmployee* pEmployee;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
pEmployee = gncEmployeeLookup( be->primary_book, guid );
|
||||
if( pEmployee == NULL ) {
|
||||
pEmployee = gncEmployeeCreate( be->primary_book );
|
||||
}
|
||||
gnc_sql_load_object( be, row, GNC_ID_EMPLOYEE, pEmployee, col_table );
|
||||
qof_instance_mark_clean( QOF_INSTANCE(pEmployee) );
|
||||
|
||||
return pEmployee;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_employees( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
QofBook* pBook;
|
||||
gnc_commodity_table* pTable;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
pBook = be->primary_book;
|
||||
pTable = gnc_commodity_table_get_table( pBook );
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row;
|
||||
GList* list = NULL;
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while( row != NULL ) {
|
||||
GncEmployee* pEmployee = load_single_employee( be, row );
|
||||
if( pEmployee != NULL ) {
|
||||
list = g_list_append( list, pEmployee );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_employee_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
save_employee( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
GncEmployee* emp;
|
||||
const GUID* guid;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_EMPLOYEE(inst) );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
emp = GNC_EMPLOYEE(inst);
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
if( op != OP_DB_DELETE ) {
|
||||
// Ensure the commodity is in the db
|
||||
gnc_sql_save_commodity( be, gncEmployeeGetCurrency( emp ) );
|
||||
}
|
||||
|
||||
(void)gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_EMPLOYEE, emp, col_table );
|
||||
|
||||
// Now, commit or delete any slots
|
||||
guid = qof_instance_get_guid( inst );
|
||||
if( !qof_instance_get_destroying(inst) ) {
|
||||
gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
} else {
|
||||
gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static gboolean
|
||||
employee_should_be_saved( GncEmployee *employee )
|
||||
{
|
||||
const char *id;
|
||||
|
||||
g_return_val_if_fail( employee != NULL, FALSE );
|
||||
|
||||
/* make sure this is a valid employee before we save it -- should have an ID */
|
||||
id = gncEmployeeGetID( employee );
|
||||
if( id == NULL || *id == '\0' ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
static void
|
||||
write_single_employee( QofInstance *term_p, gpointer be_p )
|
||||
{
|
||||
GncSqlBackend* be = (GncSqlBackend*)be_p;
|
||||
|
||||
g_return_if_fail( term_p != NULL );
|
||||
g_return_if_fail( GNC_IS_EMPLOYEE(term_p) );
|
||||
g_return_if_fail( be_p != NULL );
|
||||
|
||||
if( employee_should_be_saved( GNC_EMPLOYEE(term_p) ) ) {
|
||||
save_employee( be, term_p );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
write_employees( GncSqlBackend* be )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
qof_object_foreach( GNC_ID_EMPLOYEE, be->primary_book, write_single_employee, (gpointer)be );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_employee_sql_initialize( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_EMPLOYEE,
|
||||
save_employee, /* commit */
|
||||
load_all_employees, /* initial_load */
|
||||
create_employee_tables, /* create_tables */
|
||||
NULL, NULL, NULL,
|
||||
write_employees /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_EMPLOYEE, GNC_SQL_BACKEND, &be_data );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
35
src/business/business-core/sql/gnc-employee-sql.h
Normal file
35
src/business/business-core/sql/gnc-employee-sql.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* gnc-employee-sql.h -- employee sql backend
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, contact:
|
||||
*
|
||||
* Free Software Foundation Voice: +1-617-542-5942
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
*/
|
||||
|
||||
/** @file gnc-employee-sql.h
|
||||
* @brief load and save employee data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_EMPLOYEE_SQL_H
|
||||
#define GNC_EMPLOYEE_SQL_H
|
||||
|
||||
void gnc_employee_sql_initialize( void );
|
||||
|
||||
#endif /* GNC_EMPLOYEE_SQL_H */
|
223
src/business/business-core/sql/gnc-entry-sql.c
Normal file
223
src/business/business-core/sql/gnc-entry-sql.c
Normal file
@ -0,0 +1,223 @@
|
||||
/********************************************************************\
|
||||
* gnc-entry-sql.c -- entry sql backend *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/** @file gnc-entry-sql.c
|
||||
* @brief load and save address data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
|
||||
#include "gncEntryP.h"
|
||||
#include "gncOrderP.h"
|
||||
#include "gncInvoiceP.h"
|
||||
#include "gncTaxTableP.h"
|
||||
#include "gnc-bill-term-sql.h"
|
||||
#include "gnc-entry-sql.h"
|
||||
#include "gnc-invoice-sql.h"
|
||||
#include "gnc-order-sql.h"
|
||||
#include "gnc-owner-sql.h"
|
||||
#include "gnc-tax-table-sql.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ID_ENTRY
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define TABLE_NAME "entries"
|
||||
#define TABLE_VERSION 1
|
||||
#define MAX_DESCRIPTION_LEN 2048
|
||||
#define MAX_ACTION_LEN 2048
|
||||
#define MAX_NOTES_LEN 2048
|
||||
#define MAX_DISCTYPE_LEN 2048
|
||||
#define MAX_DISCHOW_LEN 2048
|
||||
|
||||
static GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "date", CT_TIMESPEC, 0, COL_NNUL, NULL, ENTRY_DATE },
|
||||
{ "entered", CT_TIMESPEC, 0, COL_NNUL, NULL, ENTRY_DATE_ENTERED },
|
||||
{ "description", CT_STRING, MAX_DESCRIPTION_LEN, 0, NULL, ENTRY_DESC },
|
||||
{ "action", CT_STRING, MAX_ACTION_LEN, 0, NULL, ENTRY_ACTION },
|
||||
{ "notes", CT_STRING, MAX_NOTES_LEN, 0, NULL, ENTRY_NOTES },
|
||||
{ "quantity", CT_NUMERIC, 0, 0, NULL, ENTRY_QTY },
|
||||
{ "i_acct", CT_ACCOUNTREF, 0, 0, NULL, ENTRY_IACCT },
|
||||
{ "i_price", CT_NUMERIC, 0, 0, NULL, ENTRY_IPRICE },
|
||||
{ "i_discount", CT_NUMERIC, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncEntryGetInvDiscount, (QofSetterFunc)gncEntrySetInvDiscount },
|
||||
{ "invoice", CT_INVOICEREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncEntryGetInvoice, (QofSetterFunc)gncEntrySetInvoice },
|
||||
{ "i_disc_type", CT_STRING, MAX_DISCTYPE_LEN, 0, NULL, ENTRY_INV_DISC_TYPE },
|
||||
{ "i_disc_how", CT_STRING, MAX_DISCHOW_LEN, 0, NULL, ENTRY_INV_DISC_HOW },
|
||||
{ "i_taxable", CT_BOOLEAN, 0, 0, NULL, ENTRY_INV_TAXABLE },
|
||||
{ "i_taxincluded", CT_BOOLEAN, 0, 0, NULL, ENTRY_INV_TAX_INC },
|
||||
{ "i_taxtable", CT_TAXTABLEREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncEntryGetInvTaxTable, (QofSetterFunc)gncEntrySetInvTaxTable },
|
||||
{ "b_acct", CT_ACCOUNTREF, 0, 0, NULL, ENTRY_BACCT },
|
||||
{ "b_price", CT_NUMERIC, 0, 0, NULL, ENTRY_BPRICE },
|
||||
{ "bill", CT_INVOICEREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncEntryGetBill, (QofSetterFunc)gncEntrySetBill },
|
||||
{ "b_taxable", CT_BOOLEAN, 0, 0, NULL, ENTRY_BILL_TAXABLE },
|
||||
{ "b_taxincluded", CT_BOOLEAN, 0, 0, NULL, ENTRY_BILL_TAX_INC },
|
||||
{ "b_taxtable", CT_TAXTABLEREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncEntryGetBillTaxTable, (QofSetterFunc)gncEntrySetBillTaxTable },
|
||||
{ "b_paytype", CT_INT, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncEntryGetBillPayment, (QofSetterFunc)gncEntrySetBillPayment },
|
||||
{ "billable", CT_BOOLEAN, 0, 0, NULL, ENTRY_BILLABLE },
|
||||
{ "billto", CT_OWNERREF, 0, 0, NULL, ENTRY_BILLTO },
|
||||
{ "order_guid", CT_ORDERREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncEntryGetOrder, (QofSetterFunc)gncEntrySetOrder },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static GncEntry*
|
||||
load_single_entry( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GUID* guid;
|
||||
GncEntry* pEntry;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
pEntry = gncEntryLookup( be->primary_book, guid );
|
||||
if( pEntry == NULL ) {
|
||||
pEntry = gncEntryCreate( be->primary_book );
|
||||
}
|
||||
gnc_sql_load_object( be, row, GNC_ID_ENTRY, pEntry, col_table );
|
||||
qof_instance_mark_clean( QOF_INSTANCE(pEntry) );
|
||||
|
||||
return pEntry;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_entries( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
QofBook* pBook;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
pBook = be->primary_book;
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row;
|
||||
GList* list = NULL;
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while( row != NULL ) {
|
||||
GncEntry* pEntry = load_single_entry( be, row );
|
||||
if( pEntry != NULL ) {
|
||||
list = g_list_append( list, pEntry );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_entry_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
save_entry( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_ENTRY(inst) );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_ENTRY, col_table );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
write_single_entry( QofInstance *term_p, gpointer be_p )
|
||||
{
|
||||
GncSqlBackend* be = (GncSqlBackend*)be_p;
|
||||
GncEntry* entry = GNC_ENTRY(term_p);
|
||||
|
||||
g_return_if_fail( term_p != NULL );
|
||||
g_return_if_fail( GNC_IS_ENTRY(term_p) );
|
||||
g_return_if_fail( be_p != NULL );
|
||||
|
||||
/* Only save if attached */
|
||||
if( gncEntryGetOrder( entry ) != NULL || gncEntryGetInvoice( entry ) != NULL ||
|
||||
gncEntryGetBill( entry ) != NULL ) {
|
||||
save_entry( be, term_p );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
write_entries( GncSqlBackend* be )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
qof_object_foreach( GNC_ID_ENTRY, be->primary_book, write_single_entry, (gpointer)be );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_entry_sql_initialize( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_ENTRY,
|
||||
save_entry, /* commit */
|
||||
load_all_entries, /* initial_load */
|
||||
create_entry_tables, /* create_tables */
|
||||
NULL, NULL, NULL,
|
||||
write_entries /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_ENTRY, GNC_SQL_BACKEND, &be_data );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
35
src/business/business-core/sql/gnc-entry-sql.h
Normal file
35
src/business/business-core/sql/gnc-entry-sql.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* gnc-entry-sql.h -- entry sql backend
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, contact:
|
||||
*
|
||||
* Free Software Foundation Voice: +1-617-542-5942
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
*/
|
||||
|
||||
/** @file gnc-entry-sql.h
|
||||
* @brief load and save entry data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_ENTRY_SQL_H
|
||||
#define GNC_ENTRY_SQL_H
|
||||
|
||||
void gnc_entry_sql_initialize( void );
|
||||
|
||||
#endif /* GNC_ENTRY_SQL_H */
|
288
src/business/business-core/sql/gnc-invoice-sql.c
Normal file
288
src/business/business-core/sql/gnc-invoice-sql.c
Normal file
@ -0,0 +1,288 @@
|
||||
/********************************************************************\
|
||||
* gnc-invoice-sql.c - invoice sql backend *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/** @file gnc-invoice-sql.c
|
||||
* @brief load and save address data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gnc-commodity.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
#include "gnc-commodity-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
|
||||
#include "gncBillTermP.h"
|
||||
#include "gncInvoiceP.h"
|
||||
#include "gnc-invoice-sql.h"
|
||||
#include "gnc-owner-sql.h"
|
||||
#include "gnc-bill-term-sql.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ID_INVOICE
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define TABLE_NAME "invoices"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
#define MAX_ID_LEN 2048
|
||||
#define MAX_NOTES_LEN 2048
|
||||
#define MAX_BILLING_ID_LEN 2048
|
||||
|
||||
static GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, INVOICE_ID },
|
||||
{ "date_opened", CT_TIMESPEC, 0, COL_NNUL, NULL, INVOICE_OPENED },
|
||||
{ "date_posted", CT_TIMESPEC, 0, 0, NULL, INVOICE_POSTED },
|
||||
{ "notes", CT_STRING, MAX_NOTES_LEN, COL_NNUL, NULL, INVOICE_NOTES },
|
||||
{ "active", CT_BOOLEAN, 0, COL_NNUL, NULL, QOF_PARAM_ACTIVE },
|
||||
{ "currency", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)gncInvoiceGetCurrency, (QofSetterFunc)gncInvoiceSetCurrency },
|
||||
{ "owner", CT_OWNERREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncInvoiceGetOwner, (QofSetterFunc)gncInvoiceSetOwner },
|
||||
{ "terms", CT_BILLTERMREF, 0, 0, NULL, INVOICE_TERMS },
|
||||
{ "billing_id", CT_STRING, MAX_BILLING_ID_LEN, 0, NULL, INVOICE_BILLINGID },
|
||||
{ "post_txn", CT_TXREF, 0, 0, NULL, INVOICE_POST_TXN },
|
||||
{ "post_lot", CT_LOTREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncInvoiceGetPostedLot, (QofSetterFunc)gncInvoiceSetPostedLot },
|
||||
{ "post_acc", CT_ACCOUNTREF, 0, 0, NULL, INVOICE_ACC },
|
||||
{ "billto", CT_OWNERREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncInvoiceGetBillTo, (QofSetterFunc)gncInvoiceSetBillTo },
|
||||
{ "charge_amt", CT_NUMERIC, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)gncInvoiceGetToChargeAmount, (QofSetterFunc)gncInvoiceSetToChargeAmount },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static GncInvoice*
|
||||
load_single_invoice( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GUID* guid;
|
||||
GncInvoice* pInvoice;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
pInvoice = gncInvoiceLookup( be->primary_book, guid );
|
||||
if( pInvoice == NULL ) {
|
||||
pInvoice = gncInvoiceCreate( be->primary_book );
|
||||
}
|
||||
gnc_sql_load_object( be, row, GNC_ID_INVOICE, pInvoice, col_table );
|
||||
qof_instance_mark_clean( QOF_INSTANCE(pInvoice) );
|
||||
|
||||
return pInvoice;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_invoices( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
QofBook* pBook;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
pBook = be->primary_book;
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row;
|
||||
GList* list = NULL;
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while( row != NULL ) {
|
||||
GncInvoice* pInvoice = load_single_invoice( be, row );
|
||||
if( pInvoice != NULL ) {
|
||||
list = g_list_append( list, pInvoice );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_invoice_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
save_invoice( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
const GUID* guid;
|
||||
GncInvoice* invoice;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_INVOICE(inst) );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
invoice = GNC_INVOICE(inst);
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
if( op != OP_DB_DELETE ) {
|
||||
// Ensure the commodity is in the db
|
||||
gnc_sql_save_commodity( be, gncInvoiceGetCurrency( invoice ) );
|
||||
}
|
||||
|
||||
(void)gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_INVOICE, inst, col_table );
|
||||
|
||||
// Now, commit or delete any slots
|
||||
guid = qof_instance_get_guid( inst );
|
||||
if( !qof_instance_get_destroying(inst) ) {
|
||||
gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
} else {
|
||||
gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static gboolean
|
||||
invoice_should_be_saved( GncInvoice *invoice )
|
||||
{
|
||||
const char *id;
|
||||
|
||||
g_return_val_if_fail( invoice != NULL, FALSE );
|
||||
|
||||
/* make sure this is a valid invoice before we save it -- should have an ID */
|
||||
id = gncInvoiceGetID( invoice );
|
||||
if( id == NULL || *id == '\0' ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
write_single_invoice( QofInstance *term_p, gpointer be_p )
|
||||
{
|
||||
GncSqlBackend* be = (GncSqlBackend*)be_p;
|
||||
|
||||
g_return_if_fail( term_p != NULL );
|
||||
g_return_if_fail( GNC_IS_INVOICE(term_p) );
|
||||
g_return_if_fail( be_p != NULL );
|
||||
|
||||
if( invoice_should_be_saved( GNC_INVOICE(term_p) ) ) {
|
||||
save_invoice( be, term_p );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
write_invoices( GncSqlBackend* be )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
qof_object_foreach( GNC_ID_INVOICE, be->primary_book, write_single_invoice, (gpointer)be );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
load_invoice_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
{
|
||||
const GValue* val;
|
||||
GUID guid;
|
||||
const GUID* pGuid;
|
||||
GncInvoice* invoice = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val == NULL || !G_VALUE_HOLDS_STRING( val ) || g_value_get_string( val ) == NULL ) {
|
||||
pGuid = NULL;
|
||||
} else {
|
||||
string_to_guid( g_value_get_string( val ), &guid );
|
||||
pGuid = &guid;
|
||||
}
|
||||
if( pGuid != NULL ) {
|
||||
invoice = gncInvoiceLookup( be->primary_book, pGuid );
|
||||
}
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, invoice, NULL );
|
||||
} else {
|
||||
(*setter)( pObject, (const gpointer)invoice );
|
||||
}
|
||||
}
|
||||
|
||||
static col_type_handler_t invoice_guid_handler
|
||||
= { load_invoice_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist };
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_invoice_sql_initialize( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_INVOICE,
|
||||
save_invoice, /* commit */
|
||||
load_all_invoices, /* initial_load */
|
||||
create_invoice_tables, /* create_tables */
|
||||
NULL, NULL, NULL,
|
||||
write_invoices /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_INVOICE, GNC_SQL_BACKEND, &be_data );
|
||||
|
||||
gnc_sql_register_col_type_handler( CT_INVOICEREF, &invoice_guid_handler );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
37
src/business/business-core/sql/gnc-invoice-sql.h
Normal file
37
src/business/business-core/sql/gnc-invoice-sql.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* gnc-invoice-sql.h -- invoice sql backend
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, contact:
|
||||
*
|
||||
* Free Software Foundation Voice: +1-617-542-5942
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
*/
|
||||
|
||||
/** @file gnc-invoice-sql.h
|
||||
* @brief load and save invoice data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_INVOICE_SQL_H
|
||||
#define GNC_INVOICE_SQL_H
|
||||
|
||||
#define CT_INVOICEREF "invoice"
|
||||
|
||||
void gnc_invoice_sql_initialize( void );
|
||||
|
||||
#endif /* GNC_INVOICE_SQL_H */
|
203
src/business/business-core/sql/gnc-job-sql.c
Normal file
203
src/business/business-core/sql/gnc-job-sql.c
Normal file
@ -0,0 +1,203 @@
|
||||
/********************************************************************\
|
||||
* gnc-job-sql.c -- job sql backend *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/** @file gnc-job-sql.c
|
||||
* @brief load and save address data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
#include "gnc-slots-sql.h"
|
||||
|
||||
#include "gncJobP.h"
|
||||
#include "gnc-job-sql.h"
|
||||
#include "gnc-owner-sql.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ID_JOB
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define TABLE_NAME "jobs"
|
||||
#define TABLE_VERSION 1
|
||||
|
||||
#define MAX_ID_LEN 2048
|
||||
#define MAX_NAME_LEN 2048
|
||||
#define MAX_REFERENCE_LEN 2048
|
||||
|
||||
static GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "id", CT_STRING, MAX_ID_LEN, COL_NNUL, NULL, JOB_ID },
|
||||
{ "name", CT_STRING, MAX_NAME_LEN, COL_NNUL, NULL, JOB_NAME },
|
||||
{ "reference", CT_STRING, MAX_REFERENCE_LEN, COL_NNUL, NULL, JOB_REFERENCE },
|
||||
{ "active", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)gncJobGetActive, (QofSetterFunc)gncJobSetActive },
|
||||
{ "owner", CT_OWNERREF, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)gncJobGetOwner, (QofSetterFunc)gncJobSetOwner },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static GncJob*
|
||||
load_single_job( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GUID* guid;
|
||||
GncJob* pJob;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
pJob = gncJobLookup( be->primary_book, guid );
|
||||
if( pJob == NULL ) {
|
||||
pJob = gncJobCreate( be->primary_book );
|
||||
}
|
||||
gnc_sql_load_object( be, row, GNC_ID_JOB, pJob, col_table );
|
||||
qof_instance_mark_clean( QOF_INSTANCE(pJob) );
|
||||
|
||||
return pJob;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_jobs( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
QofBook* pBook;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
pBook = be->primary_book;
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row;
|
||||
GList* list = NULL;
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while( row != NULL ) {
|
||||
GncJob* pJob = load_single_job( be, row );
|
||||
if( pJob != NULL ) {
|
||||
list = g_list_append( list, pJob );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_job_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
save_job( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
g_return_if_fail( inst != NULL );
|
||||
g_return_if_fail( GNC_IS_JOB(inst) );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_JOB, col_table );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static gboolean
|
||||
job_should_be_saved( GncJob *job )
|
||||
{
|
||||
const char *id;
|
||||
|
||||
g_return_val_if_fail( job != NULL, FALSE );
|
||||
|
||||
/* make sure this is a valid job before we save it -- should have an ID */
|
||||
id = gncJobGetID( job );
|
||||
if( id == NULL || *id == '\0' ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
write_single_job( QofInstance *term_p, gpointer be_p )
|
||||
{
|
||||
GncSqlBackend* be = (GncSqlBackend*)be_p;
|
||||
|
||||
g_return_if_fail( term_p != NULL );
|
||||
g_return_if_fail( GNC_IS_JOB(term_p) );
|
||||
g_return_if_fail( be_p != NULL );
|
||||
|
||||
if( job_should_be_saved( GNC_JOB(term_p) ) ) {
|
||||
save_job( be, term_p );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
write_jobs( GncSqlBackend* be )
|
||||
{
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
qof_object_foreach( GNC_ID_JOB, be->primary_book, write_single_job, (gpointer)be );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_job_sql_initialize( void )
|
||||
{
|
||||
static GncSqlObjectBackend be_data =
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_JOB,
|
||||
save_job, /* commit */
|
||||
load_all_jobs, /* initial_load */
|
||||
create_job_tables, /* create_tables */
|
||||
NULL, NULL, NULL,
|
||||
write_jobs /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_JOB, GNC_SQL_BACKEND, &be_data );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
35
src/business/business-core/sql/gnc-job-sql.h
Normal file
35
src/business/business-core/sql/gnc-job-sql.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* gnc-job-sql.h -- job sql backend
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, contact:
|
||||
*
|
||||
* Free Software Foundation Voice: +1-617-542-5942
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
*/
|
||||
|
||||
/** @file gnc-job-sql.h
|
||||
* @brief load and save job data to SQL
|
||||
* @author Copyright (c) 2007-2008 Phil Longstaff <plongstaff@rogers.com>
|
||||
*
|
||||
* This file implements the top-level QofBackend API for saving/
|
||||
* restoring data to/from an SQL database
|
||||
*/
|
||||
|
||||
#ifndef GNC_JOB_SQL_H
|
||||
#define GNC_JOB_SQL_H
|
||||
|
||||
void gnc_job_sql_initialize( void );
|
||||
|
||||
#endif /* GNC_JOB_SQL_H */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user