mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Re-indentation of source code, first try, only in the libqof directory so far.
This also strips trailing whitespaces from lines where they existed. This re-indentation was done using astyle-1.23 using the following options: astyle --indent=spaces=4 --brackets=break --pad-oper git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18319 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
49d62ad506
commit
c5077e259f
@ -45,7 +45,8 @@ gchar *qof_formatted_time_to_utf8(const gchar *locale_string);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
QOF_WIN32_PICTURE_DATE,
|
||||
QOF_WIN32_PICTURE_TIME,
|
||||
QOF_WIN32_PICTURE_DATETIME
|
||||
|
@ -91,7 +91,8 @@ static QofLogModule log_module = QOF_MOD_ENGINE;
|
||||
const char*
|
||||
gnc_date_dateformat_to_string(QofDateFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
switch (format)
|
||||
{
|
||||
case QOF_DATE_FORMAT_US:
|
||||
return "us";
|
||||
case QOF_DATE_FORMAT_UK:
|
||||
@ -141,7 +142,8 @@ gnc_date_string_to_dateformat(const char* fmt_str, QofDateFormat *format)
|
||||
const char*
|
||||
gnc_date_monthformat_to_string(GNCDateMonthFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
switch (format)
|
||||
{
|
||||
case GNCDATE_MONTH_NUMBER:
|
||||
return "number";
|
||||
case GNCDATE_MONTH_ABBREV:
|
||||
@ -269,7 +271,8 @@ timespecCanonicalDayTime(Timespec t)
|
||||
|
||||
int gnc_date_my_last_mday (int month, int year)
|
||||
{
|
||||
static int last_day_of_month[2][12] = {
|
||||
static int last_day_of_month[2][12] =
|
||||
{
|
||||
/* non leap */ {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
|
||||
/* leap */ {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
|
||||
};
|
||||
@ -354,7 +357,8 @@ void qof_date_format_set(QofDateFormat df)
|
||||
*/
|
||||
const gchar *qof_date_format_get_string(QofDateFormat df)
|
||||
{
|
||||
switch(df) {
|
||||
switch (df)
|
||||
{
|
||||
case QOF_DATE_FORMAT_US:
|
||||
return "%m/%d/%y";
|
||||
case QOF_DATE_FORMAT_UK:
|
||||
@ -382,7 +386,8 @@ Globals: dateFormat
|
||||
*/
|
||||
const gchar *qof_date_text_format_get_string(QofDateFormat df)
|
||||
{
|
||||
switch(df) {
|
||||
switch (df)
|
||||
{
|
||||
case QOF_DATE_FORMAT_US:
|
||||
return "%b %d, %y";
|
||||
case QOF_DATE_FORMAT_UK:
|
||||
@ -625,13 +630,17 @@ qof_scan_date_internal (const char *buff, int *day, int *month, int *year,
|
||||
|
||||
if (which_format == QOF_DATE_FORMAT_UTC)
|
||||
{
|
||||
if(strptime(buff, QOF_UTC_DATE_FORMAT, &utc)) {
|
||||
if (strptime(buff, QOF_UTC_DATE_FORMAT, &utc))
|
||||
{
|
||||
*day = utc.tm_mday;
|
||||
*month = utc.tm_mon + 1;
|
||||
*year = utc.tm_year + 1900;
|
||||
return TRUE;
|
||||
}
|
||||
else { return FALSE; }
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
dupe = g_strdup (buff);
|
||||
|
||||
@ -641,13 +650,16 @@ qof_scan_date_internal (const char *buff, int *day, int *month, int *year,
|
||||
third_field = NULL;
|
||||
|
||||
/* Use strtok to find delimiters */
|
||||
if (tmp) {
|
||||
if (tmp)
|
||||
{
|
||||
static char *delims = ".,-+/\\()년월年月 ";
|
||||
|
||||
first_field = strtok (tmp, delims);
|
||||
if (first_field) {
|
||||
if (first_field)
|
||||
{
|
||||
second_field = strtok (NULL, delims);
|
||||
if (second_field) {
|
||||
if (second_field)
|
||||
{
|
||||
third_field = strtok (NULL, delims);
|
||||
}
|
||||
}
|
||||
@ -672,66 +684,91 @@ qof_scan_date_internal (const char *buff, int *day, int *month, int *year,
|
||||
memset(&thetime, -1, sizeof(struct tm));
|
||||
strptime (buff, GNC_D_FMT, &thetime);
|
||||
|
||||
if (third_field) {
|
||||
if (third_field)
|
||||
{
|
||||
/* Easy. All three values were parsed. */
|
||||
iyear = thetime.tm_year + 1900;
|
||||
iday = thetime.tm_mday;
|
||||
imonth = thetime.tm_mon + 1;
|
||||
} else if (second_field) {
|
||||
}
|
||||
else if (second_field)
|
||||
{
|
||||
/* Hard. Two values parsed. Figure out the ordering. */
|
||||
if (thetime.tm_year == -1) {
|
||||
if (thetime.tm_year == -1)
|
||||
{
|
||||
/* %m-%d or %d-%m. Don't care. Already parsed correctly. */
|
||||
iday = thetime.tm_mday;
|
||||
imonth = thetime.tm_mon + 1;
|
||||
} else if (thetime.tm_mon != -1) {
|
||||
}
|
||||
else if (thetime.tm_mon != -1)
|
||||
{
|
||||
/* Must be %Y-%m-%d. Reparse as %m-%d.*/
|
||||
imonth = atoi(first_field);
|
||||
iday = atoi(second_field);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Must be %Y-%d-%m. Reparse as %d-%m. */
|
||||
iday = atoi(first_field);
|
||||
imonth = atoi(second_field);
|
||||
}
|
||||
} else if (first_field) {
|
||||
}
|
||||
else if (first_field)
|
||||
{
|
||||
iday = atoi(first_field);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QOF_DATE_FORMAT_UK:
|
||||
case QOF_DATE_FORMAT_CE:
|
||||
if (third_field) {
|
||||
if (third_field)
|
||||
{
|
||||
iday = atoi(first_field);
|
||||
imonth = atoi(second_field);
|
||||
iyear = atoi(third_field);
|
||||
} else if (second_field) {
|
||||
}
|
||||
else if (second_field)
|
||||
{
|
||||
iday = atoi(first_field);
|
||||
imonth = atoi(second_field);
|
||||
} else if (first_field) {
|
||||
}
|
||||
else if (first_field)
|
||||
{
|
||||
iday = atoi(first_field);
|
||||
}
|
||||
break;
|
||||
case QOF_DATE_FORMAT_ISO:
|
||||
if (third_field) {
|
||||
if (third_field)
|
||||
{
|
||||
iyear = atoi(first_field);
|
||||
imonth = atoi(second_field);
|
||||
iday = atoi(third_field);
|
||||
} else if (second_field) {
|
||||
}
|
||||
else if (second_field)
|
||||
{
|
||||
imonth = atoi(first_field);
|
||||
iday = atoi(second_field);
|
||||
} else if (first_field) {
|
||||
}
|
||||
else if (first_field)
|
||||
{
|
||||
iday = atoi(first_field);
|
||||
}
|
||||
break;
|
||||
case QOF_DATE_FORMAT_US:
|
||||
default:
|
||||
if (third_field) {
|
||||
if (third_field)
|
||||
{
|
||||
imonth = atoi(first_field);
|
||||
iday = atoi(second_field);
|
||||
iyear = atoi(third_field);
|
||||
} else if (second_field) {
|
||||
}
|
||||
else if (second_field)
|
||||
{
|
||||
imonth = atoi(first_field);
|
||||
iday = atoi(second_field);
|
||||
} else if (first_field) {
|
||||
}
|
||||
else if (first_field)
|
||||
{
|
||||
iday = atoi(first_field);
|
||||
}
|
||||
break;
|
||||
@ -761,7 +798,9 @@ qof_scan_date_internal (const char *buff, int *day, int *month, int *year,
|
||||
}
|
||||
if ((12 < imonth) && (12 >= iday))
|
||||
{
|
||||
int tmp = imonth; imonth = iday; iday = tmp;
|
||||
int tmp = imonth;
|
||||
imonth = iday;
|
||||
iday = tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -849,7 +888,8 @@ qof_time_format_from_utf8(const gchar *utf8_format)
|
||||
|
||||
retval = g_locale_from_utf8(utf8_format, -1, NULL, NULL, &error);
|
||||
|
||||
if (!retval) {
|
||||
if (!retval)
|
||||
{
|
||||
g_warning("Could not convert format '%s' from UTF-8: %s", utf8_format,
|
||||
error->message);
|
||||
g_error_free(error);
|
||||
@ -865,7 +905,8 @@ qof_formatted_time_to_utf8(const gchar *locale_string)
|
||||
|
||||
retval = g_locale_to_utf8(locale_string, -1, NULL, NULL, &error);
|
||||
|
||||
if (!retval) {
|
||||
if (!retval)
|
||||
{
|
||||
g_warning("Could not convert '%s' to UTF-8: %s", locale_string,
|
||||
error->message);
|
||||
g_error_free(error);
|
||||
@ -888,7 +929,8 @@ qof_format_time(const gchar *format, const struct tm *tm)
|
||||
return NULL;
|
||||
|
||||
tmpbufsize = MAX(128, strlen(locale_format) * 2);
|
||||
while (TRUE) {
|
||||
while (TRUE)
|
||||
{
|
||||
tmpbuf = g_malloc(tmpbufsize);
|
||||
|
||||
/* Set the first byte to something other than '\0', to be able to
|
||||
@ -897,18 +939,22 @@ qof_format_time(const gchar *format, const struct tm *tm)
|
||||
tmpbuf[0] = '\1';
|
||||
tmplen = strftime(tmpbuf, tmpbufsize, locale_format, tm);
|
||||
|
||||
if (tmplen == 0 && tmpbuf[0] != '\0') {
|
||||
if (tmplen == 0 && tmpbuf[0] != '\0')
|
||||
{
|
||||
g_free(tmpbuf);
|
||||
tmpbufsize *= 2;
|
||||
|
||||
if (tmpbufsize > 65536) {
|
||||
if (tmpbufsize > 65536)
|
||||
{
|
||||
g_warning("Maximum buffer size for qof_format_time "
|
||||
"exceeded: giving up");
|
||||
g_free(locale_format);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -932,14 +978,16 @@ qof_strftime(gchar *buf, gsize max, const gchar *format, const struct tm *tm)
|
||||
g_return_val_if_fail(tm, 0);
|
||||
|
||||
convbuf = qof_format_time(format, tm);
|
||||
if (!convbuf) {
|
||||
if (!convbuf)
|
||||
{
|
||||
buf[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
convlen = strlen(convbuf);
|
||||
|
||||
if (max <= convlen) {
|
||||
if (max <= convlen)
|
||||
{
|
||||
/* Ensure only whole characters are copied into the buffer. */
|
||||
gchar *end = g_utf8_find_prev_char(convbuf, convbuf + max);
|
||||
g_assert(end != NULL);
|
||||
@ -947,7 +995,9 @@ qof_strftime(gchar *buf, gsize max, const gchar *format, const struct tm *tm)
|
||||
|
||||
/* Return 0 because the buffer isn't large enough. */
|
||||
retval = 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = convlen;
|
||||
}
|
||||
|
||||
@ -1026,16 +1076,56 @@ gnc_iso8601_to_timespec_gmt(const char *str)
|
||||
if (!str) return ts;
|
||||
dupe = g_strdup(str);
|
||||
stm.tm_year = atoi(str) - 1900;
|
||||
str = strchr (str, '-'); if (str) { str++; } else { return ts; }
|
||||
str = strchr (str, '-');
|
||||
if (str)
|
||||
{
|
||||
str++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ts;
|
||||
}
|
||||
stm.tm_mon = atoi(str) - 1;
|
||||
str = strchr (str, '-'); if (str) { str++; } else { return ts; }
|
||||
str = strchr (str, '-');
|
||||
if (str)
|
||||
{
|
||||
str++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ts;
|
||||
}
|
||||
stm.tm_mday = atoi(str);
|
||||
|
||||
str = strchr (str, ' '); if (str) { str++; } else { return ts; }
|
||||
str = strchr (str, ' ');
|
||||
if (str)
|
||||
{
|
||||
str++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ts;
|
||||
}
|
||||
stm.tm_hour = atoi(str);
|
||||
str = strchr (str, ':'); if (str) { str++; } else { return ts; }
|
||||
str = strchr (str, ':');
|
||||
if (str)
|
||||
{
|
||||
str++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ts;
|
||||
}
|
||||
stm.tm_min = atoi(str);
|
||||
str = strchr (str, ':'); if (str) { str++; } else { return ts; }
|
||||
str = strchr (str, ':');
|
||||
if (str)
|
||||
{
|
||||
str++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ts;
|
||||
}
|
||||
stm.tm_sec = atoi (str);
|
||||
|
||||
/* The decimal point, optionally present ... */
|
||||
@ -1066,7 +1156,14 @@ gnc_iso8601_to_timespec_gmt(const char *str)
|
||||
{
|
||||
int cyn;
|
||||
/* copy sign from hour part */
|
||||
if ('+' == buf[0]) { cyn = -1; } else { cyn = +1; }
|
||||
if ('+' == buf[0])
|
||||
{
|
||||
cyn = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
cyn = +1;
|
||||
}
|
||||
buf[0] = str[0];
|
||||
buf[1] = str[1];
|
||||
buf[2] = str[2];
|
||||
@ -1144,7 +1241,8 @@ gnc_iso8601_to_timespec_gmt(const char *str)
|
||||
stm.tm_min -= (tz % 3600) / 60;
|
||||
stm.tm_isdst = tmp_tm.tm_isdst;
|
||||
ts.tv_sec = mktime (&stm);
|
||||
if(ts.tv_sec < 0) {
|
||||
if (ts.tv_sec < 0)
|
||||
{
|
||||
PWARN (" mktime failed to adjust calculated time:"
|
||||
" tm_hour=%d tm_year=%d tm_min=%d tm_sec=%d tm_isdst=%d",
|
||||
stm.tm_hour, stm.tm_year, stm.tm_min,
|
||||
@ -1179,7 +1277,11 @@ gnc_timespec_to_iso8601_buff (Timespec ts, char * buff)
|
||||
* in the glibc 2.1.3 printf (where %+02d fails to zero-pad).
|
||||
*/
|
||||
cyn = '-';
|
||||
if (0>secs) { cyn = '+'; secs = -secs; }
|
||||
if (0 > secs)
|
||||
{
|
||||
cyn = '+';
|
||||
secs = -secs;
|
||||
}
|
||||
|
||||
tz_hour = secs / 3600;
|
||||
tz_min = (secs % 3600) / 60;
|
||||
@ -1264,7 +1366,11 @@ gnc_dmy2timespec_internal (int day, int month, int year, gboolean start_of_day)
|
||||
{
|
||||
era = year / 32;
|
||||
year %= 32;
|
||||
if (0 > year) { year += 32; era -= 1; }
|
||||
if (0 > year)
|
||||
{
|
||||
year += 32;
|
||||
era -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
date.tm_year = year;
|
||||
|
@ -110,7 +110,8 @@ by qof_date_text_format_get_string */
|
||||
* This is how to format the month, as a number, an abbreviated string,
|
||||
* or the full name.
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
GNCDATE_MONTH_NUMBER,
|
||||
GNCDATE_MONTH_ABBREV,
|
||||
GNCDATE_MONTH_NAME
|
||||
|
@ -299,19 +299,25 @@ gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
if ((a.denom < 0) && (b.denom < 0)) {
|
||||
if ((a.denom < 0) && (b.denom < 0))
|
||||
{
|
||||
l = mult128 (a.num, -a.denom);
|
||||
r = mult128 (b.num, -b.denom);
|
||||
return equal128 (l, r);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* BUG: One of the numbers has a reciprocal denom, and the other
|
||||
does not. I just don't know to handle this case in any
|
||||
reasonably overflow-proof yet simple way. So, this funtion
|
||||
will simply get it wrong whenever the three multiplies
|
||||
overflow 64-bits. -CAS */
|
||||
if (a.denom < 0) {
|
||||
if (a.denom < 0)
|
||||
{
|
||||
return ((a.num * -a.denom * b.denom) == b.num);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return (a.num == (b.num * a.denom * -b.denom));
|
||||
}
|
||||
}
|
||||
@ -328,7 +334,8 @@ gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
|
||||
|
||||
int
|
||||
gnc_numeric_same(gnc_numeric a, gnc_numeric b, gint64 denom,
|
||||
gint how) {
|
||||
gint how)
|
||||
{
|
||||
gnc_numeric aconv, bconv;
|
||||
|
||||
aconv = gnc_numeric_convert(a, denom, how);
|
||||
@ -357,18 +364,22 @@ gnc_numeric_add(gnc_numeric a, gnc_numeric b,
|
||||
if ((denom == GNC_DENOM_AUTO) &&
|
||||
(how & GNC_NUMERIC_DENOM_MASK) == GNC_HOW_DENOM_FIXED)
|
||||
{
|
||||
if(a.denom == b.denom) {
|
||||
if (a.denom == b.denom)
|
||||
{
|
||||
denom = a.denom;
|
||||
}
|
||||
else if(b.num == 0) {
|
||||
else if (b.num == 0)
|
||||
{
|
||||
denom = a.denom;
|
||||
b.denom = a.denom;
|
||||
}
|
||||
else if(a.num == 0) {
|
||||
else if (a.num == 0)
|
||||
{
|
||||
denom = b.denom;
|
||||
a.denom = b.denom;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return gnc_numeric_error(GNC_ERROR_DENOM_DIFF);
|
||||
}
|
||||
}
|
||||
@ -460,22 +471,28 @@ gnc_numeric_mul(gnc_numeric a, gnc_numeric b,
|
||||
gnc_numeric product, result;
|
||||
qofint128 bignume, bigdeno;
|
||||
|
||||
if(gnc_numeric_check(a) || gnc_numeric_check(b)) {
|
||||
if (gnc_numeric_check(a) || gnc_numeric_check(b))
|
||||
{
|
||||
return gnc_numeric_error(GNC_ERROR_ARG);
|
||||
}
|
||||
|
||||
if ((denom == GNC_DENOM_AUTO) &&
|
||||
(how & GNC_NUMERIC_DENOM_MASK) == GNC_HOW_DENOM_FIXED) {
|
||||
if(a.denom == b.denom) {
|
||||
(how & GNC_NUMERIC_DENOM_MASK) == GNC_HOW_DENOM_FIXED)
|
||||
{
|
||||
if (a.denom == b.denom)
|
||||
{
|
||||
denom = a.denom;
|
||||
}
|
||||
else if(b.num == 0) {
|
||||
else if (b.num == 0)
|
||||
{
|
||||
denom = a.denom;
|
||||
}
|
||||
else if(a.num == 0) {
|
||||
else if (a.num == 0)
|
||||
{
|
||||
denom = b.denom;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return gnc_numeric_error(GNC_ERROR_DENOM_DIFF);
|
||||
}
|
||||
}
|
||||
@ -487,12 +504,14 @@ gnc_numeric_mul(gnc_numeric a, gnc_numeric b,
|
||||
how = how & GNC_NUMERIC_RND_MASK;
|
||||
}
|
||||
|
||||
if(a.denom < 0) {
|
||||
if (a.denom < 0)
|
||||
{
|
||||
a.num *= -a.denom; /* BUG: overflow not handled. */
|
||||
a.denom = 1;
|
||||
}
|
||||
|
||||
if(b.denom < 0) {
|
||||
if (b.denom < 0)
|
||||
{
|
||||
b.num *= -b.denom; /* BUG: overflow not handled. */
|
||||
b.denom = 1;
|
||||
}
|
||||
@ -557,7 +576,8 @@ gnc_numeric_mul(gnc_numeric a, gnc_numeric b,
|
||||
}
|
||||
|
||||
#if 0 /* currently, product denom won't ever be zero */
|
||||
if(product.denom < 0) {
|
||||
if (product.denom < 0)
|
||||
{
|
||||
product.num = -product.num;
|
||||
product.denom = -product.denom;
|
||||
}
|
||||
@ -706,8 +726,10 @@ dive_done:
|
||||
********************************************************************/
|
||||
|
||||
gnc_numeric
|
||||
gnc_numeric_neg(gnc_numeric a) {
|
||||
if(gnc_numeric_check(a)) {
|
||||
gnc_numeric_neg(gnc_numeric a)
|
||||
{
|
||||
if (gnc_numeric_check(a))
|
||||
{
|
||||
return gnc_numeric_error(GNC_ERROR_ARG);
|
||||
}
|
||||
return gnc_numeric_create(- a.num, a.denom);
|
||||
@ -721,7 +743,8 @@ gnc_numeric_neg(gnc_numeric a) {
|
||||
gnc_numeric
|
||||
gnc_numeric_abs(gnc_numeric a)
|
||||
{
|
||||
if(gnc_numeric_check(a)) {
|
||||
if (gnc_numeric_check(a))
|
||||
{
|
||||
return gnc_numeric_error(GNC_ERROR_ARG);
|
||||
}
|
||||
return gnc_numeric_create(ABS(a.num), a.denom);
|
||||
@ -748,7 +771,8 @@ gnc_numeric_convert(gnc_numeric in, gint64 denom, gint how)
|
||||
temp.num = 0;
|
||||
temp.denom = 0;
|
||||
|
||||
if(gnc_numeric_check(in)) {
|
||||
if (gnc_numeric_check(in))
|
||||
{
|
||||
return gnc_numeric_error(GNC_ERROR_ARG);
|
||||
}
|
||||
|
||||
@ -768,20 +792,24 @@ gnc_numeric_convert(gnc_numeric in, gint64 denom, gint how)
|
||||
break;
|
||||
|
||||
case GNC_HOW_DENOM_FIXED:
|
||||
if(in.denom != denom) {
|
||||
if (in.denom != denom)
|
||||
{
|
||||
return gnc_numeric_error(GNC_ERROR_DENOM_DIFF);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return in;
|
||||
}
|
||||
break;
|
||||
|
||||
case GNC_HOW_DENOM_SIGFIG:
|
||||
ratio = fabs(gnc_numeric_to_double(in));
|
||||
if(ratio < 10e-20) {
|
||||
if (ratio < 10e-20)
|
||||
{
|
||||
logratio = 0;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
logratio = log10(ratio);
|
||||
logratio = ((logratio > 0.0) ?
|
||||
(floor(logratio) + 1.0) : (ceil(logratio)));
|
||||
@ -791,10 +819,12 @@ gnc_numeric_convert(gnc_numeric in, gint64 denom, gint how)
|
||||
if (fabs(sigfigs - logratio) > 18)
|
||||
return gnc_numeric_error(GNC_ERROR_OVERFLOW);
|
||||
|
||||
if(sigfigs-logratio >= 0) {
|
||||
if (sigfigs - logratio >= 0)
|
||||
{
|
||||
denom = (gint64)(pow(10, sigfigs - logratio));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
denom = -((gint64)(pow(10, logratio - sigfigs)));
|
||||
}
|
||||
|
||||
@ -805,17 +835,20 @@ gnc_numeric_convert(gnc_numeric in, gint64 denom, gint how)
|
||||
}
|
||||
|
||||
/* Make sure we need to do the work */
|
||||
if(in.denom == denom) {
|
||||
if (in.denom == denom)
|
||||
{
|
||||
return in;
|
||||
}
|
||||
if(in.num == 0) {
|
||||
if (in.num == 0)
|
||||
{
|
||||
out.num = 0;
|
||||
out.denom = denom;
|
||||
return out;
|
||||
}
|
||||
|
||||
/* If the denominator of the input value is negative, get rid of that. */
|
||||
if(in.denom < 0) {
|
||||
if (in.denom < 0)
|
||||
{
|
||||
in.num = in.num * (- in.denom); /* BUG: overflow not handled. */
|
||||
in.denom = 1;
|
||||
}
|
||||
@ -869,13 +902,15 @@ gnc_numeric_convert(gnc_numeric in, gint64 denom, gint how)
|
||||
switch (how & GNC_NUMERIC_RND_MASK)
|
||||
{
|
||||
case GNC_HOW_RND_FLOOR:
|
||||
if(sign < 0) {
|
||||
if (sign < 0)
|
||||
{
|
||||
out.num = out.num + 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case GNC_HOW_RND_CEIL:
|
||||
if(sign > 0) {
|
||||
if (sign > 0)
|
||||
{
|
||||
out.num = out.num + 1;
|
||||
}
|
||||
break;
|
||||
@ -1005,7 +1040,8 @@ gnc_numeric_reduce(gnc_numeric in)
|
||||
}
|
||||
|
||||
/* The strategy is to use Euclid's algorithm */
|
||||
while (denom > 0) {
|
||||
while (denom > 0)
|
||||
{
|
||||
t = num % denom;
|
||||
num = denom;
|
||||
denom = t;
|
||||
@ -1123,19 +1159,23 @@ double_to_gnc_numeric(double in, gint64 denom, gint how)
|
||||
|
||||
if ((denom == GNC_DENOM_AUTO) && (how & GNC_HOW_DENOM_SIGFIG))
|
||||
{
|
||||
if(fabs(in) < 10e-20) {
|
||||
if (fabs(in) < 10e-20)
|
||||
{
|
||||
logval = 0;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
logval = log10(fabs(in));
|
||||
logval = ((logval > 0.0) ?
|
||||
(floor(logval) + 1.0) : (ceil(logval)));
|
||||
}
|
||||
sigfigs = GNC_HOW_GET_SIGFIGS(how);
|
||||
if(sigfigs-logval >= 0) {
|
||||
if (sigfigs - logval >= 0)
|
||||
{
|
||||
denom = (gint64)(pow(10, sigfigs - logval));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
denom = -((gint64)(pow(10, logval - sigfigs)));
|
||||
}
|
||||
|
||||
@ -1148,7 +1188,8 @@ double_to_gnc_numeric(double in, gint64 denom, gint how)
|
||||
int_part = int_part * denom;
|
||||
frac_part = frac_part * (double)denom;
|
||||
|
||||
switch(how & GNC_NUMERIC_RND_MASK) {
|
||||
switch (how & GNC_NUMERIC_RND_MASK)
|
||||
{
|
||||
case GNC_HOW_RND_FLOOR:
|
||||
frac_int = (gint64)floor(frac_part);
|
||||
break;
|
||||
@ -1168,7 +1209,8 @@ double_to_gnc_numeric(double in, gint64 denom, gint how)
|
||||
|
||||
case GNC_HOW_RND_NEVER:
|
||||
frac_int = (gint64)floor(frac_part);
|
||||
if(frac_part != (double) frac_int) {
|
||||
if (frac_part != (double) frac_int)
|
||||
{
|
||||
/* signal an error */
|
||||
}
|
||||
break;
|
||||
@ -1223,7 +1265,8 @@ gnc_numeric_add_with_error(gnc_numeric a, gnc_numeric b,
|
||||
gnc_numeric err = gnc_numeric_sub(sum, exact, GNC_DENOM_AUTO,
|
||||
GNC_HOW_DENOM_REDUCE);
|
||||
|
||||
if(error) {
|
||||
if (error)
|
||||
{
|
||||
*error = err;
|
||||
}
|
||||
return sum;
|
||||
@ -1243,7 +1286,8 @@ gnc_numeric_sub_with_error(gnc_numeric a, gnc_numeric b,
|
||||
GNC_HOW_DENOM_REDUCE);
|
||||
gnc_numeric err = gnc_numeric_sub(diff, exact, GNC_DENOM_AUTO,
|
||||
GNC_HOW_DENOM_REDUCE);
|
||||
if(error) {
|
||||
if (error)
|
||||
{
|
||||
*error = err;
|
||||
}
|
||||
return diff;
|
||||
@ -1264,7 +1308,8 @@ gnc_numeric_mul_with_error(gnc_numeric a, gnc_numeric b,
|
||||
GNC_HOW_DENOM_REDUCE);
|
||||
gnc_numeric err = gnc_numeric_sub(prod, exact, GNC_DENOM_AUTO,
|
||||
GNC_HOW_DENOM_REDUCE);
|
||||
if(error) {
|
||||
if (error)
|
||||
{
|
||||
*error = err;
|
||||
}
|
||||
return prod;
|
||||
@ -1285,7 +1330,8 @@ gnc_numeric_div_with_error(gnc_numeric a, gnc_numeric b,
|
||||
GNC_HOW_DENOM_REDUCE);
|
||||
gnc_numeric err = gnc_numeric_sub(quot, exact,
|
||||
GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
|
||||
if(error) {
|
||||
if (error)
|
||||
{
|
||||
*error = err;
|
||||
}
|
||||
return quot;
|
||||
@ -1335,7 +1381,8 @@ string_to_gnc_numeric(const gchar* str, gnc_numeric *n)
|
||||
#ifdef GNC_DEPRECATED
|
||||
/* must use "<" here because %n's effects aren't well defined */
|
||||
if (sscanf(str, " " QOF_SCANF_LLD "/" QOF_SCANF_LLD "%n",
|
||||
&tmpnum, &tmpdenom, &num_read) < 2) {
|
||||
&tmpnum, &tmpdenom, &num_read) < 2)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
#else
|
||||
@ -1376,7 +1423,8 @@ gnc_numeric_get_type( void )
|
||||
{
|
||||
static GType type = 0;
|
||||
|
||||
if( type == 0 ) {
|
||||
if ( type == 0 )
|
||||
{
|
||||
type = g_boxed_type_register_static( "gnc_numeric",
|
||||
gnc_numeric_boxed_copy_func,
|
||||
gnc_numeric_boxed_free_func );
|
||||
@ -1394,12 +1442,14 @@ static char *
|
||||
gnc_numeric_print(gnc_numeric in)
|
||||
{
|
||||
char * retval;
|
||||
if(gnc_numeric_check(in)) {
|
||||
if (gnc_numeric_check(in))
|
||||
{
|
||||
retval = g_strdup_printf("<ERROR> [%" G_GINT64_FORMAT " / %" G_GINT64_FORMAT "]",
|
||||
in.num,
|
||||
in.denom);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
retval = g_strdup_printf("[%" G_GINT64_FORMAT " / %" G_GINT64_FORMAT "]",
|
||||
in.num,
|
||||
in.denom);
|
||||
|
@ -129,7 +129,8 @@ typedef struct _gnc_numeric gnc_numeric;
|
||||
*
|
||||
* Possible rounding instructions are:
|
||||
*/
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
/** Round toward -infinity */
|
||||
GNC_HOW_RND_FLOOR = 0x01,
|
||||
|
||||
@ -166,7 +167,8 @@ enum {
|
||||
};
|
||||
|
||||
/** How to compute a denominator, or'ed into the "how" field. */
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
/** Use any denominator which gives an exactly correct ratio of
|
||||
* numerator to denominator. Use EXACT when you do not wish to
|
||||
* lose any information in the result but also do not want to
|
||||
@ -205,7 +207,8 @@ enum {
|
||||
#define GNC_HOW_GET_SIGFIGS( a ) ( (( a ) & 0xff00 ) >> 8)
|
||||
|
||||
/** Error codes */
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
GNC_ERROR_OK = 0, /**< No error */
|
||||
GNC_ERROR_ARG = -1, /**< Argument is not a valid number */
|
||||
GNC_ERROR_OVERFLOW = -2, /**< Intermediate result overflow */
|
||||
@ -240,7 +243,8 @@ typedef enum {
|
||||
*/
|
||||
/** Make a gnc_numeric from numerator and denominator */
|
||||
static inline
|
||||
gnc_numeric gnc_numeric_create(gint64 num, gint64 denom) {
|
||||
gnc_numeric gnc_numeric_create(gint64 num, gint64 denom)
|
||||
{
|
||||
gnc_numeric out;
|
||||
out.num = num;
|
||||
out.denom = denom;
|
||||
@ -249,7 +253,10 @@ gnc_numeric gnc_numeric_create(gint64 num, gint64 denom) {
|
||||
|
||||
/** create a zero-value gnc_numeric */
|
||||
static inline
|
||||
gnc_numeric gnc_numeric_zero(void) { return gnc_numeric_create(0, 1); }
|
||||
gnc_numeric gnc_numeric_zero(void)
|
||||
{
|
||||
return gnc_numeric_create(0, 1);
|
||||
}
|
||||
|
||||
/** Convert a floating-point number to a gnc_numeric.
|
||||
* Both 'denom' and 'how' are used as in arithmetic,
|
||||
@ -275,10 +282,16 @@ gnc_numeric gnc_numeric_error(GNCNumericErrorCode error_code);
|
||||
*/
|
||||
/** Return numerator */
|
||||
static inline
|
||||
gint64 gnc_numeric_num(gnc_numeric a) { return a.num; }
|
||||
gint64 gnc_numeric_num(gnc_numeric a)
|
||||
{
|
||||
return a.num;
|
||||
}
|
||||
/** Return denominator */
|
||||
static inline
|
||||
gint64 gnc_numeric_denom(gnc_numeric a) { return a.denom; }
|
||||
gint64 gnc_numeric_denom(gnc_numeric a)
|
||||
{
|
||||
return a.denom;
|
||||
}
|
||||
|
||||
/** Convert numeric to floating-point value. */
|
||||
gdouble gnc_numeric_to_double(gnc_numeric in);
|
||||
@ -379,7 +392,8 @@ gnc_numeric gnc_numeric_abs(gnc_numeric a);
|
||||
* GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER);
|
||||
*/
|
||||
static inline
|
||||
gnc_numeric gnc_numeric_add_fixed(gnc_numeric a, gnc_numeric b) {
|
||||
gnc_numeric gnc_numeric_add_fixed(gnc_numeric a, gnc_numeric b)
|
||||
{
|
||||
return gnc_numeric_add(a, b, GNC_DENOM_AUTO,
|
||||
GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER);
|
||||
}
|
||||
@ -389,7 +403,8 @@ gnc_numeric gnc_numeric_add_fixed(gnc_numeric a, gnc_numeric b) {
|
||||
* GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER);
|
||||
*/
|
||||
static inline
|
||||
gnc_numeric gnc_numeric_sub_fixed(gnc_numeric a, gnc_numeric b) {
|
||||
gnc_numeric gnc_numeric_sub_fixed(gnc_numeric a, gnc_numeric b)
|
||||
{
|
||||
return gnc_numeric_sub(a, b, GNC_DENOM_AUTO,
|
||||
GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER);
|
||||
}
|
||||
|
@ -154,7 +154,8 @@ guid_null(void)
|
||||
static int null_inited = 0;
|
||||
static GUID null_guid;
|
||||
|
||||
if (!null_inited) {
|
||||
if (!null_inited)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < GUID_DATA_SIZE; i++)
|
||||
@ -303,7 +304,8 @@ init_from_dir(const char *dirname, unsigned int max_files)
|
||||
total += sizeof(stats);
|
||||
|
||||
max_files--;
|
||||
} while (max_files > 0);
|
||||
}
|
||||
while (max_files > 0);
|
||||
|
||||
g_dir_close(dir);
|
||||
|
||||
@ -641,7 +643,8 @@ guid_to_string(const GUID * guid)
|
||||
gchar *string;
|
||||
|
||||
string = g_static_private_get (&guid_buffer_key);
|
||||
if (string == NULL) {
|
||||
if (string == NULL)
|
||||
{
|
||||
string = malloc(GUID_ENCODING_LENGTH + 1);
|
||||
g_static_private_set (&guid_buffer_key, string, g_free);
|
||||
}
|
||||
@ -717,7 +720,8 @@ guid_hash_to_guint (gconstpointer ptr)
|
||||
guint hash = 0;
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; i < sizeof(guint); i++, j++) {
|
||||
for (i = 0, j = 0; i < sizeof(guint); i++, j++)
|
||||
{
|
||||
if (j == GUID_DATA_SIZE) j = 0;
|
||||
|
||||
hash <<= 4;
|
||||
@ -777,7 +781,8 @@ gnc_guid_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
|
||||
if (G_UNLIKELY (type == 0)) {
|
||||
if (G_UNLIKELY (type == 0))
|
||||
{
|
||||
type = g_boxed_type_register_static ("GUID",
|
||||
(GBoxedCopyFunc)guid_copy,
|
||||
(GBoxedFreeFunc)guid_free);
|
||||
|
@ -33,7 +33,8 @@
|
||||
#ifndef GNC_KVP_UTIL_H
|
||||
#define GNC_KVP_UTIL_H
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
gpointer key;
|
||||
gpointer value;
|
||||
} GHashTableKVPair;
|
||||
|
@ -51,7 +51,8 @@ typedef struct
|
||||
struct _KvpValue
|
||||
{
|
||||
KvpValueType type;
|
||||
union {
|
||||
union
|
||||
{
|
||||
gint64 int64;
|
||||
double dbl;
|
||||
gnc_numeric numeric;
|
||||
@ -252,7 +253,10 @@ kvp_frame_get_frame_slash_trash (KvpFrame *frame, char *key_path)
|
||||
while (key)
|
||||
{
|
||||
key ++;
|
||||
while ('/' == *key) { key++; }
|
||||
while ('/' == *key)
|
||||
{
|
||||
key++;
|
||||
}
|
||||
if (0x0 == *key) break; /* trailing slash */
|
||||
next = strchr (key, '/');
|
||||
if (next) *next = 0x0;
|
||||
@ -282,7 +286,10 @@ kvp_frame_get_frame_or_null_slash_trash (const KvpFrame *frame, char *key_path)
|
||||
while (key)
|
||||
{
|
||||
key ++;
|
||||
while ('/' == *key) { key++; }
|
||||
while ('/' == *key)
|
||||
{
|
||||
key++;
|
||||
}
|
||||
if (0x0 == *key) break; /* trailing slash */
|
||||
next = strchr (key, '/');
|
||||
if (next) *next = 0x0;
|
||||
@ -702,7 +709,8 @@ kvp_frame_set_slot_path (KvpFrame *frame,
|
||||
g_return_if_fail (*next_key != '\0');
|
||||
|
||||
value = kvp_frame_get_slot (frame, key);
|
||||
if (!value) {
|
||||
if (!value)
|
||||
{
|
||||
KvpFrame *new_frame = kvp_frame_new ();
|
||||
KvpValue *frame_value = kvp_value_new_frame (new_frame);
|
||||
|
||||
@ -803,11 +811,20 @@ decode (char *enc)
|
||||
|
||||
do
|
||||
{
|
||||
++w; ++p;
|
||||
++w;
|
||||
++p;
|
||||
*w = *p;
|
||||
if (0x0 == *p) { p = 0; break; }
|
||||
if ('%' == *p) { break; }
|
||||
} while (*p);
|
||||
if (0x0 == *p)
|
||||
{
|
||||
p = 0;
|
||||
break;
|
||||
}
|
||||
if ('%' == *p)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (*p);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1285,10 +1302,12 @@ gint64
|
||||
kvp_value_get_gint64(const KvpValue * value)
|
||||
{
|
||||
if (!value) return 0;
|
||||
if(value->type == KVP_TYPE_GINT64) {
|
||||
if (value->type == KVP_TYPE_GINT64)
|
||||
{
|
||||
return value->value.int64;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -1297,10 +1316,12 @@ double
|
||||
kvp_value_get_double(const KvpValue * value)
|
||||
{
|
||||
if (!value) return 0.0;
|
||||
if(value->type == KVP_TYPE_DOUBLE) {
|
||||
if (value->type == KVP_TYPE_DOUBLE)
|
||||
{
|
||||
return value->value.dbl;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
@ -1309,10 +1330,12 @@ gnc_numeric
|
||||
kvp_value_get_numeric(const KvpValue * value)
|
||||
{
|
||||
if (!value) return gnc_numeric_zero ();
|
||||
if(value->type == KVP_TYPE_NUMERIC) {
|
||||
if (value->type == KVP_TYPE_NUMERIC)
|
||||
{
|
||||
return value->value.numeric;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return gnc_numeric_zero ();
|
||||
}
|
||||
}
|
||||
@ -1321,10 +1344,12 @@ char *
|
||||
kvp_value_get_string(const KvpValue * value)
|
||||
{
|
||||
if (!value) return NULL;
|
||||
if(value->type == KVP_TYPE_STRING) {
|
||||
if (value->type == KVP_TYPE_STRING)
|
||||
{
|
||||
return value->value.str;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -1333,10 +1358,12 @@ GUID *
|
||||
kvp_value_get_guid(const KvpValue * value)
|
||||
{
|
||||
if (!value) return NULL;
|
||||
if(value->type == KVP_TYPE_GUID) {
|
||||
if (value->type == KVP_TYPE_GUID)
|
||||
{
|
||||
return value->value.guid;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -1344,7 +1371,9 @@ kvp_value_get_guid(const KvpValue * value)
|
||||
Timespec
|
||||
kvp_value_get_timespec(const KvpValue * value)
|
||||
{
|
||||
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
||||
Timespec ts;
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 0;
|
||||
if (!value) return ts;
|
||||
if (value->type == KVP_TYPE_TIMESPEC)
|
||||
return value->value.timespec;
|
||||
@ -1362,12 +1391,14 @@ kvp_value_get_binary(const KvpValue * value, guint64 * size_return)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(value->type == KVP_TYPE_BINARY) {
|
||||
if (value->type == KVP_TYPE_BINARY)
|
||||
{
|
||||
if (size_return)
|
||||
*size_return = value->value.binary.datasize;
|
||||
return value->value.binary.data;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (size_return)
|
||||
*size_return = 0;
|
||||
return NULL;
|
||||
@ -1378,10 +1409,12 @@ GList *
|
||||
kvp_value_get_glist(const KvpValue * value)
|
||||
{
|
||||
if (!value) return NULL;
|
||||
if(value->type == KVP_TYPE_GLIST) {
|
||||
if (value->type == KVP_TYPE_GLIST)
|
||||
{
|
||||
return value->value.list;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -1390,10 +1423,12 @@ KvpFrame *
|
||||
kvp_value_get_frame(const KvpValue * value)
|
||||
{
|
||||
if (!value) return NULL;
|
||||
if(value->type == KVP_TYPE_FRAME) {
|
||||
if (value->type == KVP_TYPE_FRAME)
|
||||
{
|
||||
return value->value.frame;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -1429,7 +1464,8 @@ kvp_value_copy(const KvpValue * value)
|
||||
{
|
||||
if (!value) return NULL;
|
||||
|
||||
switch(value->type) {
|
||||
switch (value->type)
|
||||
{
|
||||
case KVP_TYPE_GINT64:
|
||||
return kvp_value_new_gint64(value->value.int64);
|
||||
break;
|
||||
@ -1496,7 +1532,8 @@ kvp_value_compare(const KvpValue * kva, const KvpValue * kvb)
|
||||
if (kva->type < kvb->type) return -1;
|
||||
if (kva->type > kvb->type) return 1;
|
||||
|
||||
switch(kva->type) {
|
||||
switch (kva->type)
|
||||
{
|
||||
case KVP_TYPE_GINT64:
|
||||
if (kva->value.int64 < kvb->value.int64) return -1;
|
||||
if (kva->value.int64 > kvb->value.int64) return 1;
|
||||
@ -1537,7 +1574,8 @@ kvp_value_compare(const KvpValue * kva, const KvpValue * kvb)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
gint compare;
|
||||
KvpFrame *other_frame;
|
||||
} kvp_frame_cmp_status;
|
||||
@ -1546,13 +1584,17 @@ static void
|
||||
kvp_frame_compare_helper(const char *key, KvpValue * val, gpointer data)
|
||||
{
|
||||
kvp_frame_cmp_status *status = (kvp_frame_cmp_status *) data;
|
||||
if(status->compare == 0) {
|
||||
if (status->compare == 0)
|
||||
{
|
||||
KvpFrame *other_frame = status->other_frame;
|
||||
KvpValue *other_val = kvp_frame_get_slot(other_frame, key);
|
||||
|
||||
if(other_val) {
|
||||
if (other_val)
|
||||
{
|
||||
status->compare = kvp_value_compare(val, other_val);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
status->compare = 1;
|
||||
}
|
||||
}
|
||||
@ -1706,7 +1748,8 @@ kvp_value_to_bare_string(const KvpValue *val)
|
||||
KvpFrame *frame;
|
||||
|
||||
frame = kvp_value_get_frame(val);
|
||||
if (frame->hash) {
|
||||
if (frame->hash)
|
||||
{
|
||||
tmp1 = g_strdup("");
|
||||
g_hash_table_foreach(frame->hash, kvp_frame_to_bare_string_helper, &tmp1);
|
||||
}
|
||||
|
@ -85,7 +85,8 @@ typedef struct _KvpValue KvpValue;
|
||||
* An alternative might be to make kvp values inherit from the
|
||||
* core g_types (i.e. add new core g_types) ??
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
KVP_TYPE_GINT64 = 1, /**< QOF_TYPE_INT64 gint64 */
|
||||
KVP_TYPE_DOUBLE, /**< QOF_TYPE_DOUBLE gdouble */
|
||||
KVP_TYPE_NUMERIC, /**< QOF_TYPE_NUMERIC */
|
||||
@ -373,7 +374,8 @@ KvpValue * kvp_frame_get_value(const KvpFrame *frame, const gchar *path);
|
||||
* @return The KvpFrame at the specified path, or NULL if it doesn't
|
||||
* exist.
|
||||
*/
|
||||
/*@ dependent @*/ KvpFrame * kvp_frame_get_frame(const KvpFrame *frame, const gchar *path);
|
||||
/*@ dependent @*/
|
||||
KvpFrame * kvp_frame_get_frame(const KvpFrame *frame, const gchar *path);
|
||||
|
||||
/** This routine returns the last frame of the path.
|
||||
* If the frame path doesn't exist, it is created.
|
||||
@ -641,7 +643,8 @@ GList * kvp_value_get_glist(const KvpValue * value);
|
||||
|
||||
/** Value accessor. This one is non-copying -- the caller can modify
|
||||
* the value directly. */
|
||||
/*@ dependent @*/ KvpFrame * kvp_value_get_frame(const KvpValue * value);
|
||||
/*@ dependent @*/
|
||||
KvpFrame * kvp_value_get_frame(const KvpValue * value);
|
||||
Timespec kvp_value_get_timespec(const KvpValue * value);
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,8 @@ qof_time_format_from_utf8(const gchar *utf8_format)
|
||||
retval = g_malloc((count + 1) * sizeof(gchar));
|
||||
count = wcstombs(retval, utf16_format, count + 1);
|
||||
g_free(utf16_format);
|
||||
if (count <= 0) {
|
||||
if (count <= 0)
|
||||
{
|
||||
g_free(retval);
|
||||
return NULL;
|
||||
}
|
||||
@ -73,7 +74,8 @@ qof_formatted_time_to_utf8(const gchar *locale_string)
|
||||
/* malloc and convert */
|
||||
utf16_string = g_malloc((count + 1) * sizeof(gunichar2));
|
||||
count = mbstowcs(utf16_string, locale_string, count + 1);
|
||||
if (count <= 0) {
|
||||
if (count <= 0)
|
||||
{
|
||||
g_free(utf16_string);
|
||||
return NULL;
|
||||
}
|
||||
@ -90,7 +92,8 @@ qof_win32_get_time_format(QofWin32Picture picture)
|
||||
gchar *locale_string, *format;
|
||||
gchar *tmp1, *tmp2;
|
||||
|
||||
switch (picture) {
|
||||
switch (picture)
|
||||
{
|
||||
case QOF_WIN32_PICTURE_DATE:
|
||||
locale_string = get_win32_locale_string(LOCALE_SSHORTDATE);
|
||||
break;
|
||||
@ -113,7 +116,8 @@ qof_win32_get_time_format(QofWin32Picture picture)
|
||||
picture_to_format = g_hash_table_new_full(g_str_hash, g_str_equal,
|
||||
NULL, g_free);
|
||||
format = g_hash_table_lookup(picture_to_format, locale_string);
|
||||
if (!format) {
|
||||
if (!format)
|
||||
{
|
||||
format = translate_win32_picture(locale_string);
|
||||
g_hash_table_insert(picture_to_format, g_strdup(locale_string), format);
|
||||
}
|
||||
|
@ -241,12 +241,14 @@
|
||||
struct QofBackendProvider_s
|
||||
{
|
||||
/** Some arbitrary name given for this particular backend provider */
|
||||
/*@ observer @*/ const char * provider_name;
|
||||
/*@ observer @*/
|
||||
const char * provider_name;
|
||||
|
||||
/** The access method that this provider provides, for example,
|
||||
* file:// http:// postgres:// or sqlite://, but without the :// at the end
|
||||
*/
|
||||
/*@ observer @*/ const char * access_method;
|
||||
/*@ observer @*/
|
||||
const char * access_method;
|
||||
|
||||
/** \brief Partial QofBook handler
|
||||
|
||||
@ -277,13 +279,15 @@ struct QofBackendProvider_s
|
||||
types match the incoming data. The backend should not assume that
|
||||
returning TRUE will mean that the data will naturally follow.
|
||||
*/
|
||||
/*@ null @*/ gboolean (*check_data_type) (const char*);
|
||||
/*@ null @*/
|
||||
gboolean (*check_data_type) (const char*);
|
||||
|
||||
/** Free this structure, unregister this backend handler. */
|
||||
void (*provider_free) (/*@ only @*/ QofBackendProvider *);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
LOAD_TYPE_INITIAL_LOAD,
|
||||
LOAD_TYPE_LOAD_ALL
|
||||
} QofBackendLoadType;
|
||||
@ -310,7 +314,8 @@ struct QofBackend_s
|
||||
|
||||
void (*sync) (QofBackend *, /*@ dependent @*/ QofBook *);
|
||||
void (*load_config) (QofBackend *, KvpFrame *);
|
||||
/*@ observer @*/ KvpFrame* (*get_config) (QofBackend *);
|
||||
/*@ observer @*/
|
||||
KvpFrame* (*get_config) (QofBackend *);
|
||||
gint64 (*counter) (QofBackend *, const char *counter_name);
|
||||
|
||||
gboolean (*events_pending) (QofBackend *);
|
||||
|
@ -75,7 +75,8 @@ qof_backend_set_message (QofBackend *be, const char *format, ...)
|
||||
/* If there's already something here, free it */
|
||||
if (be->error_msg) g_free(be->error_msg);
|
||||
|
||||
if (!format) {
|
||||
if (!format)
|
||||
{
|
||||
be->error_msg = NULL;
|
||||
return;
|
||||
}
|
||||
@ -156,23 +157,41 @@ qof_backend_destroy(QofBackend *be)
|
||||
void
|
||||
qof_backend_run_begin(QofBackend *be, QofInstance *inst)
|
||||
{
|
||||
if(!be || !inst) { return; }
|
||||
if(!be->begin) { return; }
|
||||
if (!be || !inst)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!be->begin)
|
||||
{
|
||||
return;
|
||||
}
|
||||
(be->begin) (be, inst);
|
||||
}
|
||||
|
||||
gboolean
|
||||
qof_backend_begin_exists(const QofBackend *be)
|
||||
{
|
||||
if(be->begin) { return TRUE; }
|
||||
else { return FALSE; }
|
||||
if (be->begin)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
qof_backend_run_commit(QofBackend *be, QofInstance *inst)
|
||||
{
|
||||
if(!be || !inst) { return; }
|
||||
if(!be->commit) { return; }
|
||||
if (!be || !inst)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!be->commit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
(be->commit) (be, inst);
|
||||
}
|
||||
|
||||
@ -181,7 +200,8 @@ qof_backend_run_commit(QofBackend *be, QofInstance *inst)
|
||||
void qof_backend_prepare_frame(QofBackend *be)
|
||||
{
|
||||
g_return_if_fail(be);
|
||||
if(!kvp_frame_is_empty(be->backend_configuration)) {
|
||||
if (!kvp_frame_is_empty(be->backend_configuration))
|
||||
{
|
||||
kvp_frame_delete(be->backend_configuration);
|
||||
be->backend_configuration = kvp_frame_new();
|
||||
}
|
||||
@ -200,32 +220,50 @@ void qof_backend_prepare_option(QofBackend *be, const QofBackendOption *option)
|
||||
value = NULL;
|
||||
switch (option->type)
|
||||
{
|
||||
case KVP_TYPE_GINT64 : {
|
||||
case KVP_TYPE_GINT64 :
|
||||
{
|
||||
value = kvp_value_new_gint64(*(gint64*)option->value);
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_DOUBLE : {
|
||||
case KVP_TYPE_DOUBLE :
|
||||
{
|
||||
value = kvp_value_new_double(*(double*)option->value);
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_NUMERIC : {
|
||||
case KVP_TYPE_NUMERIC :
|
||||
{
|
||||
value = kvp_value_new_numeric(*(gnc_numeric*)option->value);
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_STRING : {
|
||||
case KVP_TYPE_STRING :
|
||||
{
|
||||
value = kvp_value_new_string((const char*)option->value);
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_GUID : { break; } /* unsupported */
|
||||
case KVP_TYPE_TIMESPEC : {
|
||||
case KVP_TYPE_GUID :
|
||||
{
|
||||
break; /* unsupported */
|
||||
}
|
||||
case KVP_TYPE_TIMESPEC :
|
||||
{
|
||||
value = kvp_value_new_timespec(*(Timespec*)option->value);
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_BINARY : { break; } /* unsupported */
|
||||
case KVP_TYPE_GLIST : { break; } /* unsupported */
|
||||
case KVP_TYPE_FRAME : { break; } /* unsupported */
|
||||
case KVP_TYPE_BINARY :
|
||||
{
|
||||
break; /* unsupported */
|
||||
}
|
||||
if(value) {
|
||||
case KVP_TYPE_GLIST :
|
||||
{
|
||||
break; /* unsupported */
|
||||
}
|
||||
case KVP_TYPE_FRAME :
|
||||
{
|
||||
break; /* unsupported */
|
||||
}
|
||||
}
|
||||
if (value)
|
||||
{
|
||||
temp = g_strdup_printf("/%s", option->option_name);
|
||||
kvp_frame_set_value(be->backend_configuration, temp, value);
|
||||
g_free(temp);
|
||||
@ -247,7 +285,8 @@ KvpFrame* qof_backend_complete_frame(QofBackend *be)
|
||||
return be->backend_configuration;
|
||||
}
|
||||
|
||||
struct config_iterate {
|
||||
struct config_iterate
|
||||
{
|
||||
QofBackendOptionCB fcn;
|
||||
gpointer data;
|
||||
gint count;
|
||||
@ -271,44 +310,74 @@ config_foreach_cb (const char *key, KvpValue *value, gpointer data)
|
||||
|
||||
g_return_if_fail(key || value || data);
|
||||
helper = (struct config_iterate*)data;
|
||||
if(!helper->recursive) { PERR (" no parent frame"); return; }
|
||||
if (!helper->recursive)
|
||||
{
|
||||
PERR (" no parent frame");
|
||||
return;
|
||||
}
|
||||
// skip the presets.
|
||||
if(0 == safe_strcmp(key, QOF_CONFIG_DESC)) { return; }
|
||||
if(0 == safe_strcmp(key, QOF_CONFIG_TIP)) { return; }
|
||||
if (0 == safe_strcmp(key, QOF_CONFIG_DESC))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(key, QOF_CONFIG_TIP))
|
||||
{
|
||||
return;
|
||||
}
|
||||
ENTER (" key=%s", key);
|
||||
option.option_name = key;
|
||||
option.type = kvp_value_get_type(value);
|
||||
if(!option.type) { return; }
|
||||
if (!option.type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (option.type)
|
||||
{ /* set the KvpFrame value into the option */
|
||||
case KVP_TYPE_GINT64 : {
|
||||
case KVP_TYPE_GINT64 :
|
||||
{
|
||||
int64 = kvp_value_get_gint64(value);
|
||||
option.value = (gpointer) & int64;
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_DOUBLE : {
|
||||
case KVP_TYPE_DOUBLE :
|
||||
{
|
||||
db = kvp_value_get_double(value);
|
||||
option.value = (gpointer) & db;
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_NUMERIC : {
|
||||
case KVP_TYPE_NUMERIC :
|
||||
{
|
||||
num = kvp_value_get_numeric(value);
|
||||
option.value = (gpointer) & num;
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_STRING : {
|
||||
case KVP_TYPE_STRING :
|
||||
{
|
||||
option.value = (gpointer)kvp_value_get_string(value);
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_TIMESPEC : {
|
||||
case KVP_TYPE_TIMESPEC :
|
||||
{
|
||||
ts = kvp_value_get_timespec(value);
|
||||
option.value = (gpointer) & ts;
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_GUID : { break; } /* unsupported */
|
||||
case KVP_TYPE_BINARY : { break; } /* unsupported */
|
||||
case KVP_TYPE_GLIST : { break; } /* unsupported */
|
||||
case KVP_TYPE_FRAME : { break; } /* unsupported */
|
||||
case KVP_TYPE_GUID :
|
||||
{
|
||||
break; /* unsupported */
|
||||
}
|
||||
case KVP_TYPE_BINARY :
|
||||
{
|
||||
break; /* unsupported */
|
||||
}
|
||||
case KVP_TYPE_GLIST :
|
||||
{
|
||||
break; /* unsupported */
|
||||
}
|
||||
case KVP_TYPE_FRAME :
|
||||
{
|
||||
break; /* unsupported */
|
||||
}
|
||||
}
|
||||
parent = g_strdup_printf("/%s/%s", QOF_CONFIG_DESC, key);
|
||||
option.description = kvp_frame_get_string(helper->recursive, parent);
|
||||
@ -321,35 +390,52 @@ config_foreach_cb (const char *key, KvpValue *value, gpointer data)
|
||||
helper->fcn (&option, helper->data);
|
||||
switch (option.type)
|
||||
{ /* set the option value into the KvpFrame */
|
||||
case KVP_TYPE_GINT64 : {
|
||||
case KVP_TYPE_GINT64 :
|
||||
{
|
||||
kvp_frame_set_gint64(helper->recursive, key,
|
||||
(*(gint64*)option.value));
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_DOUBLE : {
|
||||
case KVP_TYPE_DOUBLE :
|
||||
{
|
||||
kvp_frame_set_double(helper->recursive, key,
|
||||
(*(double*)option.value));
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_NUMERIC : {
|
||||
case KVP_TYPE_NUMERIC :
|
||||
{
|
||||
kvp_frame_set_numeric(helper->recursive, key,
|
||||
(*(gnc_numeric*)option.value));
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_STRING : {
|
||||
case KVP_TYPE_STRING :
|
||||
{
|
||||
kvp_frame_set_string(helper->recursive, key,
|
||||
(gchar*)option.value);
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_TIMESPEC : {
|
||||
case KVP_TYPE_TIMESPEC :
|
||||
{
|
||||
kvp_frame_set_timespec(helper->recursive, key,
|
||||
(*(Timespec*)option.value));
|
||||
break;
|
||||
}
|
||||
case KVP_TYPE_GUID : { break; } /* unsupported */
|
||||
case KVP_TYPE_BINARY : { break; } /* unsupported */
|
||||
case KVP_TYPE_GLIST : { break; } /* unsupported */
|
||||
case KVP_TYPE_FRAME : { break; } /* unsupported */
|
||||
case KVP_TYPE_GUID :
|
||||
{
|
||||
break; /* unsupported */
|
||||
}
|
||||
case KVP_TYPE_BINARY :
|
||||
{
|
||||
break; /* unsupported */
|
||||
}
|
||||
case KVP_TYPE_GLIST :
|
||||
{
|
||||
break; /* unsupported */
|
||||
}
|
||||
case KVP_TYPE_FRAME :
|
||||
{
|
||||
break; /* unsupported */
|
||||
}
|
||||
}
|
||||
LEAVE (" ");
|
||||
}
|
||||
@ -358,7 +444,10 @@ void qof_backend_option_foreach(KvpFrame *config, QofBackendOptionCB cb, gpointe
|
||||
{
|
||||
struct config_iterate helper;
|
||||
|
||||
if(!config || !cb) { return; }
|
||||
if (!config || !cb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ENTER (" ");
|
||||
helper.fcn = cb;
|
||||
helper.count = 1;
|
||||
@ -371,25 +460,46 @@ void qof_backend_option_foreach(KvpFrame *config, QofBackendOptionCB cb, gpointe
|
||||
void
|
||||
qof_backend_load_config(QofBackend *be, KvpFrame *config)
|
||||
{
|
||||
if(!be || !config) { return; }
|
||||
if(!be->load_config) { return; }
|
||||
if (!be || !config)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!be->load_config)
|
||||
{
|
||||
return;
|
||||
}
|
||||
(be->load_config) (be, config);
|
||||
}
|
||||
|
||||
KvpFrame*
|
||||
qof_backend_get_config(QofBackend *be)
|
||||
{
|
||||
if(!be) { return NULL; }
|
||||
if(!be->get_config) { return NULL; }
|
||||
if (!be)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (!be->get_config)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return (be->get_config) (be);
|
||||
}
|
||||
|
||||
gboolean
|
||||
qof_backend_commit_exists(const QofBackend *be)
|
||||
{
|
||||
if(!be) { return FALSE; }
|
||||
if(be->commit) { return TRUE; }
|
||||
else { return FALSE; }
|
||||
if (!be)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (be->commit)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -403,7 +513,8 @@ qof_load_backend_library (const char *directory, const char* module_name)
|
||||
fullpath = g_module_build_path(directory, module_name);
|
||||
backend = g_module_open(fullpath, G_MODULE_BIND_LAZY);
|
||||
g_free(fullpath);
|
||||
if (!backend) {
|
||||
if (!backend)
|
||||
{
|
||||
g_message ("%s: %s\n", PACKAGE, g_module_error ());
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -52,7 +52,8 @@
|
||||
* \warning (GnuCash) If you modify QofBackendError, please update
|
||||
* src/engine/gw-engine-spec.scm
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
ERR_BACKEND_NO_ERR = 0,
|
||||
ERR_BACKEND_NO_HANDLER, /**< no backend handler found for this access method (ENOSYS) */
|
||||
ERR_BACKEND_NO_BACKEND, /**< Backend * pointer was unexpectedly null */
|
||||
@ -202,7 +203,8 @@ backend is fully configured and ready for use.
|
||||
*/
|
||||
|
||||
/** A single Backend Configuration Option. */
|
||||
typedef struct QofBackendOption_s {
|
||||
typedef struct QofBackendOption_s
|
||||
{
|
||||
KvpValueType type; /**< Only GINT64, DOUBLE, NUMERIC, STRING and TIMESPEC supported. */
|
||||
const gchar *option_name; /**< non-translated, key. */
|
||||
const gchar *description; /**< translatable description. */
|
||||
|
@ -182,7 +182,8 @@ qof_book_mark_saved (QofBook *book)
|
||||
qof_instance_set_dirty_flag(book, FALSE);
|
||||
book->dirty_time = 0;
|
||||
qof_object_mark_clean (book);
|
||||
if (was_dirty) {
|
||||
if (was_dirty)
|
||||
{
|
||||
if (book->dirty_cb)
|
||||
book->dirty_cb(book, FALSE, book->dirty_data);
|
||||
}
|
||||
@ -196,7 +197,8 @@ void qof_book_mark_dirty (QofBook *book)
|
||||
|
||||
was_dirty = qof_instance_get_dirty_flag(book);
|
||||
qof_instance_set_dirty_flag(book, TRUE);
|
||||
if (!was_dirty) {
|
||||
if (!was_dirty)
|
||||
{
|
||||
book->dirty_time = time(NULL);
|
||||
if (book->dirty_cb)
|
||||
book->dirty_cb(book, TRUE, book->dirty_data);
|
||||
@ -301,7 +303,8 @@ qof_book_get_collection (const QofBook *book, QofIdType entity_type)
|
||||
if (!book || !entity_type) return NULL;
|
||||
|
||||
col = g_hash_table_lookup (book->hash_of_collections, entity_type);
|
||||
if (!col) {
|
||||
if (!col)
|
||||
{
|
||||
col = qof_collection_new (entity_type);
|
||||
g_hash_table_insert(
|
||||
book->hash_of_collections,
|
||||
@ -310,7 +313,8 @@ qof_book_get_collection (const QofBook *book, QofIdType entity_type)
|
||||
return col;
|
||||
}
|
||||
|
||||
struct _iterate {
|
||||
struct _iterate
|
||||
{
|
||||
QofCollectionForeachCB fn;
|
||||
gpointer data;
|
||||
};
|
||||
@ -343,25 +347,37 @@ qof_book_foreach_collection (const QofBook *book,
|
||||
|
||||
void qof_book_mark_closed (QofBook *book)
|
||||
{
|
||||
if(!book) { return; }
|
||||
if (!book)
|
||||
{
|
||||
return;
|
||||
}
|
||||
book->book_open = 'n';
|
||||
}
|
||||
|
||||
gchar qof_book_get_open_marker(const QofBook *book)
|
||||
{
|
||||
if(!book) { return 'n'; }
|
||||
if (!book)
|
||||
{
|
||||
return 'n';
|
||||
}
|
||||
return book->book_open;
|
||||
}
|
||||
|
||||
gint32 qof_book_get_version (const QofBook *book)
|
||||
{
|
||||
if(!book) { return -1; }
|
||||
if (!book)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return book->version;
|
||||
}
|
||||
|
||||
void qof_book_set_version (QofBook *book, gint32 version)
|
||||
{
|
||||
if(!book && version < 0) { return; }
|
||||
if (!book && version < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
book->version = version;
|
||||
}
|
||||
|
||||
@ -373,12 +389,14 @@ qof_book_get_counter (const QofBook *book, const char *counter_name)
|
||||
KvpValue *value;
|
||||
gint64 counter;
|
||||
|
||||
if (!book) {
|
||||
if (!book)
|
||||
{
|
||||
PWARN ("No book!!!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!counter_name || *counter_name == '\0') {
|
||||
if (!counter_name || *counter_name == '\0')
|
||||
{
|
||||
PWARN ("Invalid counter name.");
|
||||
return -1;
|
||||
}
|
||||
@ -391,16 +409,20 @@ qof_book_get_counter (const QofBook *book, const char *counter_name)
|
||||
/* If not, then use the KVP in the book */
|
||||
kvp = qof_book_get_slots (book);
|
||||
|
||||
if (!kvp) {
|
||||
if (!kvp)
|
||||
{
|
||||
PWARN ("Book has no KVP_Frame");
|
||||
return -1;
|
||||
}
|
||||
|
||||
value = kvp_frame_get_slot_path (kvp, "counters", counter_name, NULL);
|
||||
if (value) {
|
||||
if (value)
|
||||
{
|
||||
/* found it */
|
||||
counter = kvp_value_get_gint64 (value);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* New counter */
|
||||
counter = 0;
|
||||
}
|
||||
@ -420,7 +442,8 @@ qof_book_get_counter (const QofBook *book, const char *counter_name)
|
||||
/* QofObject function implementation and registration */
|
||||
gboolean qof_book_register (void)
|
||||
{
|
||||
static QofParam params[] = {
|
||||
static QofParam params[] =
|
||||
{
|
||||
{ QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_entity_get_guid, NULL },
|
||||
{ QOF_PARAM_KVP, QOF_TYPE_KVP, (QofAccessFunc)qof_instance_get_slots, NULL },
|
||||
{ NULL },
|
||||
|
@ -175,7 +175,8 @@ void qof_book_mark_closed (QofBook *book);
|
||||
* a non-NULL value. (Unless the system malloc failed (out of
|
||||
* memory) in which case what happens??).
|
||||
*/
|
||||
/*@ dependent @*/ QofCollection * qof_book_get_collection (const QofBook *, QofIdType);
|
||||
/*@ dependent @*/
|
||||
QofCollection * qof_book_get_collection (const QofBook *, QofIdType);
|
||||
|
||||
/** Invoke the indicated callback on each collection in the book. */
|
||||
typedef void (*QofCollectionForeachCB) (QofCollection *, gpointer user_data);
|
||||
|
@ -28,7 +28,8 @@
|
||||
static QofLogModule log_module = QOF_MOD_MERGE;
|
||||
|
||||
/* private rule iteration struct */
|
||||
struct QofBookMergeRuleIterate {
|
||||
struct QofBookMergeRuleIterate
|
||||
{
|
||||
QofBookMergeRuleForeachCB fcn;
|
||||
QofBookMergeData *data;
|
||||
QofBookMergeRule *rule;
|
||||
@ -52,16 +53,23 @@ qof_book_merge_update_rule(QofBookMergeRule *currentRule, gboolean match, gint w
|
||||
gboolean absolute;
|
||||
|
||||
absolute = currentRule->mergeAbsolute;
|
||||
if(absolute && match && currentRule->mergeResult == MERGE_UNDEF) {
|
||||
if (absolute && match && currentRule->mergeResult == MERGE_UNDEF)
|
||||
{
|
||||
currentRule->mergeResult = MERGE_ABSOLUTE;
|
||||
}
|
||||
if(absolute && !match) { currentRule->mergeResult = MERGE_UPDATE; }
|
||||
if(!absolute && match &¤tRule->mergeResult == MERGE_UNDEF) {
|
||||
if (absolute && !match)
|
||||
{
|
||||
currentRule->mergeResult = MERGE_UPDATE;
|
||||
}
|
||||
if (!absolute && match && currentRule->mergeResult == MERGE_UNDEF)
|
||||
{
|
||||
currentRule->mergeResult = MERGE_DUPLICATE;
|
||||
}
|
||||
if(!absolute && !match) {
|
||||
if (!absolute && !match)
|
||||
{
|
||||
currentRule->difference += weight;
|
||||
if(currentRule->mergeResult == MERGE_DUPLICATE) {
|
||||
if (currentRule->mergeResult == MERGE_DUPLICATE)
|
||||
{
|
||||
currentRule->mergeResult = MERGE_REPORT;
|
||||
}
|
||||
}
|
||||
@ -79,7 +87,10 @@ collect_reference_cb (QofInstance *ent, gpointer user_data)
|
||||
struct collect_list_s *s;
|
||||
|
||||
s = (struct collect_list_s*)user_data;
|
||||
if(!ent || !s) { return; }
|
||||
if (!ent || !s)
|
||||
{
|
||||
return;
|
||||
}
|
||||
s->linkedEntList = g_slist_prepend(s->linkedEntList, ent);
|
||||
}
|
||||
|
||||
@ -121,112 +132,169 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
|
||||
kvpImport = kvp_frame_new();
|
||||
kvpTarget = kvp_frame_new();
|
||||
mergeError = FALSE;
|
||||
while(paramList != NULL) {
|
||||
while (paramList != NULL)
|
||||
{
|
||||
mergeMatch = FALSE;
|
||||
knowntype = FALSE;
|
||||
qtparam = paramList->data;
|
||||
mergeParamName = qtparam->param_name;
|
||||
g_return_val_if_fail(mergeParamName != NULL, -1);
|
||||
mergeType = qtparam->param_type;
|
||||
if(safe_strcmp(mergeType, QOF_TYPE_STRING) == 0) {
|
||||
if (safe_strcmp(mergeType, QOF_TYPE_STRING) == 0)
|
||||
{
|
||||
stringImport = qtparam->param_getfcn(mergeEnt, qtparam);
|
||||
stringTarget = qtparam->param_getfcn(targetEnt, qtparam);
|
||||
/* very strict string matches may need to be relaxed. */
|
||||
if(stringImport == NULL) { stringImport = ""; }
|
||||
if(stringTarget == NULL) { stringTarget = ""; }
|
||||
if(safe_strcmp(stringImport,stringTarget) == 0) { mergeMatch = TRUE; }
|
||||
if (stringImport == NULL)
|
||||
{
|
||||
stringImport = "";
|
||||
}
|
||||
if (stringTarget == NULL)
|
||||
{
|
||||
stringTarget = "";
|
||||
}
|
||||
if (safe_strcmp(stringImport, stringTarget) == 0)
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
/* Give special weight to a string match */
|
||||
currentRule = qof_book_merge_update_rule(currentRule,
|
||||
mergeMatch, QOF_STRING_WEIGHT);
|
||||
stringImport = stringTarget = NULL;
|
||||
knowntype = TRUE;
|
||||
}
|
||||
if(safe_strcmp(mergeType, QOF_TYPE_DATE) == 0) {
|
||||
if (safe_strcmp(mergeType, QOF_TYPE_DATE) == 0)
|
||||
{
|
||||
date_getter = (Timespec (*)(QofInstance*, QofParam*))qtparam->param_getfcn;
|
||||
tsImport = date_getter(mergeEnt, qtparam);
|
||||
tsTarget = date_getter(targetEnt, qtparam);
|
||||
if(timespec_cmp(&tsImport, &tsTarget) == 0) { mergeMatch = TRUE; }
|
||||
if (timespec_cmp(&tsImport, &tsTarget) == 0)
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
currentRule = qof_book_merge_update_rule(currentRule,
|
||||
mergeMatch, DEFAULT_MERGE_WEIGHT);
|
||||
knowntype = TRUE;
|
||||
}
|
||||
if ((safe_strcmp(mergeType, QOF_TYPE_NUMERIC) == 0) ||
|
||||
(safe_strcmp(mergeType, QOF_TYPE_DEBCRED) == 0)) {
|
||||
(safe_strcmp(mergeType, QOF_TYPE_DEBCRED) == 0))
|
||||
{
|
||||
numeric_getter = (gnc_numeric (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
|
||||
numericImport = numeric_getter(mergeEnt, qtparam);
|
||||
numericTarget = numeric_getter(targetEnt, qtparam);
|
||||
if(gnc_numeric_compare (numericImport, numericTarget) == 0) { mergeMatch = TRUE; }
|
||||
if (gnc_numeric_compare (numericImport, numericTarget) == 0)
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
currentRule = qof_book_merge_update_rule(currentRule,
|
||||
mergeMatch, DEFAULT_MERGE_WEIGHT);
|
||||
knowntype = TRUE;
|
||||
}
|
||||
if(safe_strcmp(mergeType, QOF_TYPE_GUID) == 0) {
|
||||
if (safe_strcmp(mergeType, QOF_TYPE_GUID) == 0)
|
||||
{
|
||||
guidImport = qtparam->param_getfcn(mergeEnt, qtparam);
|
||||
guidTarget = qtparam->param_getfcn(targetEnt, qtparam);
|
||||
if(guid_compare(guidImport, guidTarget) == 0) { mergeMatch = TRUE; }
|
||||
if (guid_compare(guidImport, guidTarget) == 0)
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
currentRule = qof_book_merge_update_rule(currentRule,
|
||||
mergeMatch, DEFAULT_MERGE_WEIGHT);
|
||||
knowntype = TRUE;
|
||||
}
|
||||
if(safe_strcmp(mergeType, QOF_TYPE_INT32) == 0) {
|
||||
if (safe_strcmp(mergeType, QOF_TYPE_INT32) == 0)
|
||||
{
|
||||
int32_getter = (gint32 (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
|
||||
i32Import = int32_getter(mergeEnt, qtparam);
|
||||
i32Target = int32_getter(targetEnt, qtparam);
|
||||
if(i32Target == i32Import) { mergeMatch = TRUE; }
|
||||
if (i32Target == i32Import)
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
currentRule = qof_book_merge_update_rule(currentRule,
|
||||
mergeMatch, DEFAULT_MERGE_WEIGHT);
|
||||
knowntype = TRUE;
|
||||
}
|
||||
if(safe_strcmp(mergeType, QOF_TYPE_INT64) == 0) {
|
||||
if (safe_strcmp(mergeType, QOF_TYPE_INT64) == 0)
|
||||
{
|
||||
int64_getter = (gint64 (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
|
||||
i64Import = int64_getter(mergeEnt, qtparam);
|
||||
i64Target = int64_getter(targetEnt, qtparam);
|
||||
if(i64Target == i64Import) { mergeMatch = TRUE; }
|
||||
if (i64Target == i64Import)
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
currentRule = qof_book_merge_update_rule(currentRule,
|
||||
mergeMatch, DEFAULT_MERGE_WEIGHT);
|
||||
knowntype = TRUE;
|
||||
}
|
||||
if(safe_strcmp(mergeType, QOF_TYPE_DOUBLE) == 0) {
|
||||
if (safe_strcmp(mergeType, QOF_TYPE_DOUBLE) == 0)
|
||||
{
|
||||
double_getter = (double (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
|
||||
doubleImport = double_getter(mergeEnt, qtparam);
|
||||
doubleTarget = double_getter(mergeEnt, qtparam);
|
||||
if(doubleImport == doubleTarget) { mergeMatch = TRUE; }
|
||||
if (doubleImport == doubleTarget)
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
currentRule = qof_book_merge_update_rule(currentRule,
|
||||
mergeMatch, DEFAULT_MERGE_WEIGHT);
|
||||
knowntype = TRUE;
|
||||
}
|
||||
if(safe_strcmp(mergeType, QOF_TYPE_BOOLEAN) == 0){
|
||||
if (safe_strcmp(mergeType, QOF_TYPE_BOOLEAN) == 0)
|
||||
{
|
||||
boolean_getter = (gboolean (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
|
||||
booleanImport = boolean_getter(mergeEnt, qtparam);
|
||||
booleanTarget = boolean_getter(targetEnt, qtparam);
|
||||
if(booleanImport != FALSE && booleanImport != TRUE) { booleanImport = FALSE; }
|
||||
if(booleanTarget != FALSE && booleanTarget != TRUE) { booleanTarget = FALSE; }
|
||||
if(booleanImport == booleanTarget) { mergeMatch = TRUE; }
|
||||
if (booleanImport != FALSE && booleanImport != TRUE)
|
||||
{
|
||||
booleanImport = FALSE;
|
||||
}
|
||||
if (booleanTarget != FALSE && booleanTarget != TRUE)
|
||||
{
|
||||
booleanTarget = FALSE;
|
||||
}
|
||||
if (booleanImport == booleanTarget)
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
currentRule = qof_book_merge_update_rule(currentRule,
|
||||
mergeMatch, DEFAULT_MERGE_WEIGHT);
|
||||
knowntype = TRUE;
|
||||
}
|
||||
if(safe_strcmp(mergeType, QOF_TYPE_KVP) == 0) {
|
||||
if (safe_strcmp(mergeType, QOF_TYPE_KVP) == 0)
|
||||
{
|
||||
kvpImport = kvp_frame_copy(qtparam->param_getfcn(mergeEnt, qtparam));
|
||||
kvpTarget = kvp_frame_copy(qtparam->param_getfcn(targetEnt, qtparam));
|
||||
if(kvp_frame_compare(kvpImport, kvpTarget) == 0) { mergeMatch = TRUE; }
|
||||
if (kvp_frame_compare(kvpImport, kvpTarget) == 0)
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
currentRule = qof_book_merge_update_rule(currentRule,
|
||||
mergeMatch, DEFAULT_MERGE_WEIGHT);
|
||||
knowntype = TRUE;
|
||||
}
|
||||
if(safe_strcmp(mergeType, QOF_TYPE_CHAR) == 0) {
|
||||
if (safe_strcmp(mergeType, QOF_TYPE_CHAR) == 0)
|
||||
{
|
||||
char_getter = (gchar (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
|
||||
charImport = char_getter(mergeEnt, qtparam);
|
||||
charTarget = char_getter(targetEnt, qtparam);
|
||||
if(charImport == charTarget) { mergeMatch = TRUE; }
|
||||
if (charImport == charTarget)
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
currentRule = qof_book_merge_update_rule(currentRule,
|
||||
mergeMatch, DEFAULT_MERGE_WEIGHT);
|
||||
knowntype = TRUE;
|
||||
}
|
||||
/* No object should have QofSetterFunc defined for the book,
|
||||
but just to be safe, do nothing. */
|
||||
if(safe_strcmp(mergeType, QOF_ID_BOOK) == 0) { knowntype= TRUE; }
|
||||
if(safe_strcmp(mergeType, QOF_TYPE_COLLECT) == 0) {
|
||||
if (safe_strcmp(mergeType, QOF_ID_BOOK) == 0)
|
||||
{
|
||||
knowntype = TRUE;
|
||||
}
|
||||
if (safe_strcmp(mergeType, QOF_TYPE_COLLECT) == 0)
|
||||
{
|
||||
struct collect_list_s s;
|
||||
s.linkedEntList = NULL;
|
||||
mergeColl = qtparam->param_getfcn(mergeEnt, qtparam);
|
||||
@ -235,20 +303,26 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
|
||||
qof_collection_foreach(mergeColl, collect_reference_cb, &s);
|
||||
currentRule->linkedEntList = g_slist_copy(s.linkedEntList);
|
||||
if (0 == qof_collection_compare(mergeColl, targetColl))
|
||||
{ mergeMatch = TRUE; }
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
currentRule = qof_book_merge_update_rule(currentRule,
|
||||
mergeMatch, DEFAULT_MERGE_WEIGHT);
|
||||
knowntype = TRUE;
|
||||
}
|
||||
if(safe_strcmp(mergeType, QOF_TYPE_CHOICE) ==0) {
|
||||
if (safe_strcmp(mergeType, QOF_TYPE_CHOICE) == 0)
|
||||
{
|
||||
referenceEnt = qtparam->param_getfcn(mergeEnt, qtparam);
|
||||
currentRule->linkedEntList =
|
||||
g_slist_prepend(currentRule->linkedEntList, referenceEnt);
|
||||
if (referenceEnt == qtparam->param_getfcn(targetEnt, qtparam))
|
||||
{ mergeMatch = TRUE; }
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
knowntype = TRUE;
|
||||
}
|
||||
if(knowntype == FALSE) {
|
||||
if (knowntype == FALSE)
|
||||
{
|
||||
referenceEnt = qtparam->param_getfcn(mergeEnt, qtparam);
|
||||
|
||||
// XXX gncOwner is na object that could be returned, but does not have QofInstance
|
||||
@ -256,11 +330,14 @@ qof_book_merge_compare(QofBookMergeData *mergeData )
|
||||
referenceEnt = NULL;
|
||||
|
||||
if ((referenceEnt != NULL)
|
||||
&&(safe_strcmp(referenceEnt->e_type, mergeType) == 0)) {
|
||||
&& (safe_strcmp(referenceEnt->e_type, mergeType) == 0))
|
||||
{
|
||||
currentRule->linkedEntList =
|
||||
g_slist_prepend(currentRule->linkedEntList, referenceEnt);
|
||||
if (referenceEnt == qtparam->param_getfcn(targetEnt, qtparam))
|
||||
{ mergeMatch = TRUE; }
|
||||
{
|
||||
mergeMatch = TRUE;
|
||||
}
|
||||
currentRule = qof_book_merge_update_rule(currentRule,
|
||||
mergeMatch, DEFAULT_MERGE_WEIGHT);
|
||||
}
|
||||
@ -306,9 +383,11 @@ qof_book_merge_commit_foreach (QofBookMergeRuleForeachCB cb,
|
||||
iter.fcn = cb;
|
||||
subList = NULL;
|
||||
iter.ruleList = NULL;
|
||||
for (node = mergeData->mergeList; node != NULL; node = node->next) {
|
||||
for (node = mergeData->mergeList; node != NULL; node = node->next)
|
||||
{
|
||||
currentRule = node->data;
|
||||
if(currentRule->mergeResult == mergeResult) {
|
||||
if (currentRule->mergeResult == mergeResult)
|
||||
{
|
||||
subList = g_list_prepend(subList, currentRule);
|
||||
}
|
||||
}
|
||||
@ -348,7 +427,10 @@ qof_book_merge_rule_cmp(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
QofBookMergeRule *ra = (QofBookMergeRule *) a;
|
||||
QofBookMergeRule *rb = (QofBookMergeRule *) b;
|
||||
if (ra->difference == rb->difference) { return TRUE; }
|
||||
if (ra->difference == rb->difference)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else return FALSE;
|
||||
}
|
||||
|
||||
@ -363,13 +445,22 @@ qof_book_merge_orphan_check(double difference, QofBookMergeRule *mergeRule,
|
||||
|
||||
g_return_if_fail(mergeRule != NULL);
|
||||
g_return_if_fail(mergeData != NULL);
|
||||
if(g_hash_table_size(mergeData->target_table) == 0) { return; }
|
||||
if (g_hash_table_size(mergeData->target_table) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
rule = (QofBookMergeRule*)g_hash_table_lookup(mergeData->target_table,
|
||||
mergeRule->targetEnt);
|
||||
/* If NULL, no match was found. */
|
||||
if(rule == NULL) { return; }
|
||||
if (rule == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
/* Only orphan if this is a better match than already exists. */
|
||||
if(difference >= rule->difference) { return; }
|
||||
if (difference >= rule->difference)
|
||||
{
|
||||
return;
|
||||
}
|
||||
rule->targetEnt = NULL;
|
||||
rule->mergeResult = MERGE_UNDEF;
|
||||
mergeData->orphan_list = g_slist_append(mergeData->orphan_list, rule);
|
||||
@ -392,11 +483,13 @@ qof_book_merge_match_orphans(QofBookMergeData *mergeData)
|
||||
is used recursively until empty. */
|
||||
orphans = mergeData->orphan_list;
|
||||
targets = g_slist_copy(mergeData->targetList);
|
||||
while(orphans != NULL) {
|
||||
while (orphans != NULL)
|
||||
{
|
||||
rule = orphans->data;
|
||||
g_return_if_fail(rule != NULL);
|
||||
difference = g_slist_length(mergeData->mergeObjectParams);
|
||||
if(rule->targetEnt == NULL) {
|
||||
if (rule->targetEnt == NULL)
|
||||
{
|
||||
rule->mergeResult = MERGE_NEW;
|
||||
rule->difference = 0;
|
||||
mergeData->mergeList = g_list_prepend(mergeData->mergeList, rule);
|
||||
@ -405,7 +498,8 @@ qof_book_merge_match_orphans(QofBookMergeData *mergeData)
|
||||
}
|
||||
mergeData->currentRule = rule;
|
||||
g_return_if_fail(qof_book_merge_compare(mergeData) != -1);
|
||||
if(difference > mergeData->currentRule->difference) {
|
||||
if (difference > mergeData->currentRule->difference)
|
||||
{
|
||||
best_matchEnt = currentRule->targetEnt;
|
||||
difference = currentRule->difference;
|
||||
rule = currentRule;
|
||||
@ -442,7 +536,8 @@ qof_book_merge_foreach_type_target ( QofObject* merge_obj, gpointer user_data)
|
||||
currentRule = mergeData->currentRule;
|
||||
g_return_if_fail(currentRule != NULL);
|
||||
g_return_if_fail(merge_obj != NULL);
|
||||
if(safe_strcmp(merge_obj->e_type, currentRule->importEnt->e_type) == 0) {
|
||||
if (safe_strcmp(merge_obj->e_type, currentRule->importEnt->e_type) == 0)
|
||||
{
|
||||
qof_object_foreach(currentRule->importEnt->e_type, mergeData->targetBook,
|
||||
qof_book_merge_foreach_target, user_data);
|
||||
}
|
||||
@ -480,7 +575,8 @@ qof_book_merge_foreach ( QofInstance* mergeEnt, gpointer user_data)
|
||||
targetEnt = best_matchEnt = NULL;
|
||||
targetEnt = qof_collection_lookup_entity (
|
||||
qof_book_get_collection (mergeData->targetBook, mergeEnt->e_type), g);
|
||||
if( targetEnt != NULL) {
|
||||
if ( targetEnt != NULL)
|
||||
{
|
||||
mergeRule->mergeAbsolute = TRUE;
|
||||
mergeRule->targetEnt = targetEnt;
|
||||
g_return_if_fail(qof_book_merge_compare(mergeData) != -1);
|
||||
@ -492,17 +588,20 @@ qof_book_merge_foreach ( QofInstance* mergeEnt, gpointer user_data)
|
||||
g_slist_free(mergeData->targetList);
|
||||
mergeData->targetList = NULL;
|
||||
qof_object_foreach_type(qof_book_merge_foreach_type_target, mergeData);
|
||||
if(g_slist_length(mergeData->targetList) == 0) {
|
||||
if (g_slist_length(mergeData->targetList) == 0)
|
||||
{
|
||||
mergeRule->mergeResult = MERGE_NEW;
|
||||
}
|
||||
difference = g_slist_length(mergeRule->mergeParam);
|
||||
c = g_slist_copy(mergeData->targetList);
|
||||
while(c != NULL) {
|
||||
while (c != NULL)
|
||||
{
|
||||
mergeRule->targetEnt = c->data;
|
||||
currentRule = mergeRule;
|
||||
/* compare two entities and sum the differences */
|
||||
g_return_if_fail(qof_book_merge_compare(mergeData) != -1);
|
||||
if(mergeRule->difference == 0) {
|
||||
if (mergeRule->difference == 0)
|
||||
{
|
||||
/* check if this is a better match than one already assigned */
|
||||
best_matchEnt = mergeRule->targetEnt;
|
||||
mergeRule->mergeResult = MERGE_DUPLICATE;
|
||||
@ -513,7 +612,8 @@ qof_book_merge_foreach ( QofInstance* mergeEnt, gpointer user_data)
|
||||
/* exact match, return */
|
||||
return;
|
||||
}
|
||||
if(difference > mergeRule->difference) {
|
||||
if (difference > mergeRule->difference)
|
||||
{
|
||||
/* The chosen targetEnt determines the parenting of any child object */
|
||||
/* check if this is a better match than one already assigned */
|
||||
best_matchEnt = mergeRule->targetEnt;
|
||||
@ -527,7 +627,8 @@ qof_book_merge_foreach ( QofInstance* mergeEnt, gpointer user_data)
|
||||
c = g_slist_next(c);
|
||||
}
|
||||
g_slist_free(c);
|
||||
if(best_matchEnt != NULL ) {
|
||||
if (best_matchEnt != NULL )
|
||||
{
|
||||
mergeRule->targetEnt = best_matchEnt;
|
||||
mergeRule->difference = difference;
|
||||
/* Set this entity in the target_table in case a better match can be made
|
||||
@ -537,7 +638,8 @@ qof_book_merge_foreach ( QofInstance* mergeEnt, gpointer user_data)
|
||||
g_return_if_fail(qof_book_merge_compare(mergeData) != -1);
|
||||
mergeRule->linkedEntList = g_slist_copy(currentRule->linkedEntList);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
mergeRule->targetEnt = NULL;
|
||||
mergeRule->difference = 0;
|
||||
mergeRule->mergeResult = MERGE_NEW;
|
||||
@ -558,7 +660,8 @@ qof_book_merge_foreach_param( QofParam* param, gpointer user_data)
|
||||
g_return_if_fail(user_data != NULL);
|
||||
mergeData = (QofBookMergeData*)user_data;
|
||||
g_return_if_fail(param != NULL);
|
||||
if((param->param_getfcn != NULL)&&(param->param_setfcn != NULL)) {
|
||||
if ((param->param_getfcn != NULL) && (param->param_setfcn != NULL))
|
||||
{
|
||||
mergeData->mergeObjectParams = g_slist_append(mergeData->mergeObjectParams, param);
|
||||
}
|
||||
}
|
||||
@ -572,7 +675,8 @@ qof_book_merge_foreach_type ( QofObject* merge_obj, gpointer user_data)
|
||||
mergeData = (QofBookMergeData*)user_data;
|
||||
g_return_if_fail((merge_obj != NULL));
|
||||
/* Skip unsupported objects */
|
||||
if((merge_obj->create == NULL)||(merge_obj->foreach == NULL)){
|
||||
if ((merge_obj->create == NULL) || (merge_obj->foreach == NULL))
|
||||
{
|
||||
DEBUG (" merge_obj QOF support failed %s", merge_obj->e_type);
|
||||
return;
|
||||
}
|
||||
@ -632,9 +736,11 @@ qof_book_merge_map_entity(const QofBookMergeData *mergeData, const QofInstance*
|
||||
QofBookMergeRule *currentRule;
|
||||
GList *node;
|
||||
|
||||
for (node = mergeData->mergeList; node != NULL; node = node->next) {
|
||||
for (node = mergeData->mergeList; node != NULL; node = node->next)
|
||||
{
|
||||
currentRule = node->data;
|
||||
if (currentRule->importEnt == importEnt) {
|
||||
if (currentRule->importEnt == importEnt)
|
||||
{
|
||||
return currentRule->targetEnt;
|
||||
}
|
||||
}
|
||||
@ -642,7 +748,8 @@ qof_book_merge_map_entity(const QofBookMergeData *mergeData, const QofInstance*
|
||||
return NULL;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofBookMergeData *mergeData;
|
||||
QofCollection *mapped_coll;
|
||||
} QofBookMergeMapCollectionIterate;
|
||||
@ -718,7 +825,8 @@ qof_book_merge_commit_rule_loop(QofBookMergeData *mergeData,
|
||||
2. by best_matchEnt and difference or
|
||||
3. by MERGE_NEW.
|
||||
*/
|
||||
while(rule->mergeParam != NULL) {
|
||||
while (rule->mergeParam != NULL)
|
||||
{
|
||||
registered_type = FALSE;
|
||||
g_return_if_fail(rule->mergeParam->data);
|
||||
cm_param = rule->mergeParam->data;
|
||||
@ -727,75 +835,116 @@ qof_book_merge_commit_rule_loop(QofBookMergeData *mergeData,
|
||||
DEBUG ("qof_book_merge_commit_rule_loop param: Merge Type: %s, Param Name: %s",
|
||||
rule->mergeType, cm_param->param_name);
|
||||
|
||||
if(safe_strcmp(rule->mergeType, QOF_TYPE_STRING) == 0) {
|
||||
if (safe_strcmp(rule->mergeType, QOF_TYPE_STRING) == 0)
|
||||
{
|
||||
cm_string = cm_param->param_getfcn(rule->importEnt, cm_param);
|
||||
string_setter = (void(*)(QofInstance*, const gchar*))cm_param->param_setfcn;
|
||||
if(string_setter != NULL) { string_setter(rule->targetEnt, cm_string); }
|
||||
if (string_setter != NULL)
|
||||
{
|
||||
string_setter(rule->targetEnt, cm_string);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(rule->mergeType, QOF_TYPE_DATE) == 0) {
|
||||
if (safe_strcmp(rule->mergeType, QOF_TYPE_DATE) == 0)
|
||||
{
|
||||
date_getter = (Timespec (*)(QofInstance*, QofParam*))cm_param->param_getfcn;
|
||||
cm_date = date_getter(rule->importEnt, cm_param);
|
||||
date_setter = (void(*)(QofInstance*, Timespec))cm_param->param_setfcn;
|
||||
if(date_setter != NULL) { date_setter(rule->targetEnt, cm_date); }
|
||||
if (date_setter != NULL)
|
||||
{
|
||||
date_setter(rule->targetEnt, cm_date);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if ((safe_strcmp(rule->mergeType, QOF_TYPE_NUMERIC) == 0) ||
|
||||
(safe_strcmp(rule->mergeType, QOF_TYPE_DEBCRED) == 0)) {
|
||||
(safe_strcmp(rule->mergeType, QOF_TYPE_DEBCRED) == 0))
|
||||
{
|
||||
numeric_getter = (gnc_numeric (*)(QofInstance*, QofParam*))cm_param->param_getfcn;
|
||||
cm_numeric = numeric_getter(rule->importEnt, cm_param);
|
||||
numeric_setter = (void(*)(QofInstance*, gnc_numeric))cm_param->param_setfcn;
|
||||
if(numeric_setter != NULL) { numeric_setter(rule->targetEnt, cm_numeric); }
|
||||
if (numeric_setter != NULL)
|
||||
{
|
||||
numeric_setter(rule->targetEnt, cm_numeric);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(rule->mergeType, QOF_TYPE_GUID) == 0) {
|
||||
if (safe_strcmp(rule->mergeType, QOF_TYPE_GUID) == 0)
|
||||
{
|
||||
cm_guid = cm_param->param_getfcn(rule->importEnt, cm_param);
|
||||
guid_setter = (void(*)(QofInstance*, const GUID*))cm_param->param_setfcn;
|
||||
if(guid_setter != NULL) { guid_setter(rule->targetEnt, cm_guid); }
|
||||
if (guid_setter != NULL)
|
||||
{
|
||||
guid_setter(rule->targetEnt, cm_guid);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(rule->mergeType, QOF_TYPE_INT32) == 0) {
|
||||
if (safe_strcmp(rule->mergeType, QOF_TYPE_INT32) == 0)
|
||||
{
|
||||
int32_getter = (gint32 (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
|
||||
cm_i32 = int32_getter(rule->importEnt, cm_param);
|
||||
i32_setter = (void(*)(QofInstance*, gint32))cm_param->param_setfcn;
|
||||
if(i32_setter != NULL) { i32_setter(rule->targetEnt, cm_i32); }
|
||||
if (i32_setter != NULL)
|
||||
{
|
||||
i32_setter(rule->targetEnt, cm_i32);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(rule->mergeType, QOF_TYPE_INT64) == 0) {
|
||||
if (safe_strcmp(rule->mergeType, QOF_TYPE_INT64) == 0)
|
||||
{
|
||||
int64_getter = (gint64 (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
|
||||
cm_i64 = int64_getter(rule->importEnt, cm_param);
|
||||
i64_setter = (void(*)(QofInstance*, gint64))cm_param->param_setfcn;
|
||||
if(i64_setter != NULL) { i64_setter(rule->targetEnt, cm_i64); }
|
||||
if (i64_setter != NULL)
|
||||
{
|
||||
i64_setter(rule->targetEnt, cm_i64);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(rule->mergeType, QOF_TYPE_DOUBLE) == 0) {
|
||||
if (safe_strcmp(rule->mergeType, QOF_TYPE_DOUBLE) == 0)
|
||||
{
|
||||
double_getter = (double (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
|
||||
cm_double = double_getter(rule->importEnt, cm_param);
|
||||
double_setter = (void(*)(QofInstance*, double))cm_param->param_setfcn;
|
||||
if(double_setter != NULL) { double_setter(rule->targetEnt, cm_double); }
|
||||
if (double_setter != NULL)
|
||||
{
|
||||
double_setter(rule->targetEnt, cm_double);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(rule->mergeType, QOF_TYPE_BOOLEAN) == 0){
|
||||
if (safe_strcmp(rule->mergeType, QOF_TYPE_BOOLEAN) == 0)
|
||||
{
|
||||
boolean_getter = (gboolean (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
|
||||
cm_boolean = boolean_getter(rule->importEnt, cm_param);
|
||||
boolean_setter = (void(*)(QofInstance*, gboolean))cm_param->param_setfcn;
|
||||
if(boolean_setter != NULL) { boolean_setter(rule->targetEnt, cm_boolean); }
|
||||
if (boolean_setter != NULL)
|
||||
{
|
||||
boolean_setter(rule->targetEnt, cm_boolean);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(rule->mergeType, QOF_TYPE_KVP) == 0) {
|
||||
if (safe_strcmp(rule->mergeType, QOF_TYPE_KVP) == 0)
|
||||
{
|
||||
cm_kvp = kvp_frame_copy(cm_param->param_getfcn(rule->importEnt, cm_param));
|
||||
kvp_frame_setter = (void(*)(QofInstance*, KvpFrame*))cm_param->param_setfcn;
|
||||
if(kvp_frame_setter != NULL) { kvp_frame_setter(rule->targetEnt, cm_kvp); }
|
||||
if (kvp_frame_setter != NULL)
|
||||
{
|
||||
kvp_frame_setter(rule->targetEnt, cm_kvp);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(rule->mergeType, QOF_TYPE_CHAR) == 0) {
|
||||
if (safe_strcmp(rule->mergeType, QOF_TYPE_CHAR) == 0)
|
||||
{
|
||||
char_getter = (gchar (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
|
||||
cm_char = char_getter(rule->importEnt, cm_param);
|
||||
char_setter = (void(*)(QofInstance*, gchar))cm_param->param_setfcn;
|
||||
if(char_setter != NULL) { char_setter(rule->targetEnt, cm_char); }
|
||||
if (char_setter != NULL)
|
||||
{
|
||||
char_setter(rule->targetEnt, cm_char);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(rule->mergeType, QOF_TYPE_COLLECT) == 0) {
|
||||
if (safe_strcmp(rule->mergeType, QOF_TYPE_COLLECT) == 0)
|
||||
{
|
||||
cm_coll = cm_param->param_getfcn(rule->importEnt, cm_param);
|
||||
|
||||
/* Created mapped collection */
|
||||
@ -805,10 +954,14 @@ qof_book_merge_commit_rule_loop(QofBookMergeData *mergeData,
|
||||
qof_collection_foreach(cm_coll, qof_book_merge_map_collection_cb, &mapped_coll_iter);
|
||||
|
||||
collection_setter = (void(*)(QofInstance*, QofCollection*))cm_param->param_setfcn;
|
||||
if(collection_setter != NULL) { collection_setter(rule->targetEnt, mapped_coll); }
|
||||
if (collection_setter != NULL)
|
||||
{
|
||||
collection_setter(rule->targetEnt, mapped_coll);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(rule->mergeType, QOF_TYPE_CHOICE) == 0) {
|
||||
if (safe_strcmp(rule->mergeType, QOF_TYPE_CHOICE) == 0)
|
||||
{
|
||||
referenceEnt = cm_param->param_getfcn(rule->importEnt, cm_param);
|
||||
referenceEnt = qof_book_merge_map_entity(mergeData, referenceEnt);
|
||||
reference_setter = (void(*)(QofInstance*, QofInstance*))cm_param->param_setfcn;
|
||||
@ -818,7 +971,8 @@ qof_book_merge_commit_rule_loop(QofBookMergeData *mergeData,
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(registered_type == FALSE) {
|
||||
if (registered_type == FALSE)
|
||||
{
|
||||
referenceEnt = cm_param->param_getfcn(rule->importEnt, cm_param);
|
||||
|
||||
// XXX gncOwner is an object that could be returned, but does not have QofInstance
|
||||
@ -827,7 +981,8 @@ qof_book_merge_commit_rule_loop(QofBookMergeData *mergeData,
|
||||
|
||||
referenceEnt = qof_book_merge_map_entity(mergeData, referenceEnt);
|
||||
|
||||
if(referenceEnt) {
|
||||
if (referenceEnt)
|
||||
{
|
||||
reference_setter = (void(*)(QofInstance*, QofInstance*))cm_param->param_setfcn;
|
||||
if (reference_setter != NULL)
|
||||
{
|
||||
@ -864,13 +1019,16 @@ qof_book_merge_init( QofBook *importBook, QofBook *targetBook)
|
||||
mergeData->currentRule = currentRule;
|
||||
qof_object_foreach_type(qof_book_merge_foreach_type, mergeData);
|
||||
g_return_val_if_fail(mergeData->mergeObjectParams, NULL);
|
||||
if(mergeData->orphan_list != NULL) {
|
||||
if (mergeData->orphan_list != NULL)
|
||||
{
|
||||
qof_book_merge_match_orphans(mergeData);
|
||||
}
|
||||
|
||||
for (node = mergeData->mergeList; node != NULL; node = node->next) {
|
||||
for (node = mergeData->mergeList; node != NULL; node = node->next)
|
||||
{
|
||||
currentRule = node->data;
|
||||
if(currentRule->mergeResult == MERGE_INVALID) {
|
||||
if (currentRule->mergeResult == MERGE_INVALID)
|
||||
{
|
||||
mergeData->abort = TRUE;
|
||||
return(NULL);
|
||||
}
|
||||
@ -886,12 +1044,14 @@ qof_book_merge_abort (QofBookMergeData *mergeData)
|
||||
QofBookMergeRule *currentRule;
|
||||
|
||||
g_return_if_fail(mergeData != NULL);
|
||||
while(mergeData->mergeList != NULL) {
|
||||
while (mergeData->mergeList != NULL)
|
||||
{
|
||||
currentRule = mergeData->mergeList->data;
|
||||
g_slist_free(currentRule->linkedEntList);
|
||||
g_slist_free(currentRule->mergeParam);
|
||||
g_free(mergeData->mergeList->data);
|
||||
if(currentRule) {
|
||||
if (currentRule)
|
||||
{
|
||||
g_slist_free(currentRule->linkedEntList);
|
||||
g_slist_free(currentRule->mergeParam);
|
||||
g_free(currentRule);
|
||||
@ -901,7 +1061,10 @@ qof_book_merge_abort (QofBookMergeData *mergeData)
|
||||
g_list_free(mergeData->mergeList);
|
||||
g_slist_free(mergeData->mergeObjectParams);
|
||||
g_slist_free(mergeData->targetList);
|
||||
if(mergeData->orphan_list != NULL) { g_slist_free(mergeData->orphan_list); }
|
||||
if (mergeData->orphan_list != NULL)
|
||||
{
|
||||
g_slist_free(mergeData->orphan_list);
|
||||
}
|
||||
g_hash_table_destroy(mergeData->target_table);
|
||||
g_free(mergeData);
|
||||
}
|
||||
@ -939,12 +1102,17 @@ qof_book_merge_param_as_string(QofParam *qtparam, QofInstance *qtEnt)
|
||||
|
||||
param_string = NULL;
|
||||
paramType = qtparam->param_type;
|
||||
if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_STRING) == 0)
|
||||
{
|
||||
param_string = g_strdup(qtparam->param_getfcn(qtEnt, qtparam));
|
||||
if(param_string == NULL) { param_string = ""; }
|
||||
if (param_string == NULL)
|
||||
{
|
||||
param_string = "";
|
||||
}
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_DATE) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_DATE) == 0)
|
||||
{
|
||||
date_getter = (Timespec (*)(QofInstance*, QofParam*))qtparam->param_getfcn;
|
||||
param_ts = date_getter(qtEnt, qtparam);
|
||||
param_t = timespecToTime_t(param_ts);
|
||||
@ -953,47 +1121,63 @@ qof_book_merge_param_as_string(QofParam *qtparam, QofInstance *qtEnt)
|
||||
return param_string;
|
||||
}
|
||||
if ((safe_strcmp(paramType, QOF_TYPE_NUMERIC) == 0) ||
|
||||
(safe_strcmp(paramType, QOF_TYPE_DEBCRED) == 0)) {
|
||||
(safe_strcmp(paramType, QOF_TYPE_DEBCRED) == 0))
|
||||
{
|
||||
numeric_getter = (gnc_numeric (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
|
||||
param_numeric = numeric_getter(qtEnt, qtparam);
|
||||
param_string = g_strdup(gnc_numeric_to_string(param_numeric));
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_GUID) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_GUID) == 0)
|
||||
{
|
||||
param_guid = qtparam->param_getfcn(qtEnt, qtparam);
|
||||
guid_to_string_buff(param_guid, param_sa);
|
||||
param_string = g_strdup(param_sa);
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_INT32) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_INT32) == 0)
|
||||
{
|
||||
int32_getter = (gint32 (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
|
||||
param_i32 = int32_getter(qtEnt, qtparam);
|
||||
param_string = g_strdup_printf("%d", param_i32);
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_INT64) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_INT64) == 0)
|
||||
{
|
||||
int64_getter = (gint64 (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
|
||||
param_i64 = int64_getter(qtEnt, qtparam);
|
||||
param_string = g_strdup_printf("%" G_GINT64_FORMAT, param_i64);
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_DOUBLE) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_DOUBLE) == 0)
|
||||
{
|
||||
double_getter = (double (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
|
||||
param_double = double_getter(qtEnt, qtparam);
|
||||
param_string = g_strdup_printf("%f", param_double);
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_BOOLEAN) == 0){
|
||||
if (safe_strcmp(paramType, QOF_TYPE_BOOLEAN) == 0)
|
||||
{
|
||||
boolean_getter = (gboolean (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
|
||||
param_boolean = boolean_getter(qtEnt, qtparam);
|
||||
/* Boolean values need to be lowercase for QSF validation. */
|
||||
if(param_boolean == TRUE) { param_string = g_strdup("true"); }
|
||||
else { param_string = g_strdup("false"); }
|
||||
if (param_boolean == TRUE)
|
||||
{
|
||||
param_string = g_strdup("true");
|
||||
}
|
||||
else
|
||||
{
|
||||
param_string = g_strdup("false");
|
||||
}
|
||||
return param_string;
|
||||
}
|
||||
/* "kvp" contains repeating values, cannot be a single string for the frame. */
|
||||
if(safe_strcmp(paramType, QOF_TYPE_KVP) == 0) { return param_string; }
|
||||
if(safe_strcmp(paramType, QOF_TYPE_CHAR) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_KVP) == 0)
|
||||
{
|
||||
return param_string;
|
||||
}
|
||||
if (safe_strcmp(paramType, QOF_TYPE_CHAR) == 0)
|
||||
{
|
||||
char_getter = (gchar (*)(QofInstance*, QofParam*)) qtparam->param_getfcn;
|
||||
param_char = char_getter(qtEnt, qtparam);
|
||||
param_string = g_strdup_printf("%c", param_char);
|
||||
@ -1029,9 +1213,13 @@ qof_book_merge_update_result (QofBookMergeData *mergeData,
|
||||
{
|
||||
tag = MERGE_NEW;
|
||||
}
|
||||
if(resolved->updated == FALSE) { resolved->mergeResult = tag; }
|
||||
if (resolved->updated == FALSE)
|
||||
{
|
||||
resolved->mergeResult = tag;
|
||||
}
|
||||
resolved->updated = TRUE;
|
||||
if(tag >= MERGE_INVALID) {
|
||||
if (tag >= MERGE_INVALID)
|
||||
{
|
||||
mergeData->abort = TRUE;
|
||||
mergeData->currentRule = resolved;
|
||||
return NULL;
|
||||
@ -1054,15 +1242,18 @@ qof_book_merge_commit(QofBookMergeData *mergeData )
|
||||
if (mergeData->abort == TRUE) return -13;
|
||||
check = g_list_copy(mergeData->mergeList);
|
||||
g_return_val_if_fail(check != NULL, -14);
|
||||
for (node = check; node != NULL; node = node->next) {
|
||||
for (node = check; node != NULL; node = node->next)
|
||||
{
|
||||
currentRule = node->data;
|
||||
|
||||
if(currentRule->mergeResult == MERGE_INVALID) {
|
||||
if (currentRule->mergeResult == MERGE_INVALID)
|
||||
{
|
||||
qof_book_merge_abort(mergeData);
|
||||
g_list_free(check);
|
||||
return(-2);
|
||||
}
|
||||
if(currentRule->mergeResult == MERGE_REPORT) {
|
||||
if (currentRule->mergeResult == MERGE_REPORT)
|
||||
{
|
||||
g_list_free(check);
|
||||
return 1;
|
||||
}
|
||||
@ -1077,7 +1268,8 @@ qof_book_merge_commit(QofBookMergeData *mergeData )
|
||||
|
||||
/* Placeholder for QofObject merge_helper_cb - all objects
|
||||
and all parameters set */
|
||||
while(mergeData->mergeList != NULL) {
|
||||
while (mergeData->mergeList != NULL)
|
||||
{
|
||||
currentRule = mergeData->mergeList->data;
|
||||
g_slist_free(currentRule->mergeParam);
|
||||
g_slist_free(currentRule->linkedEntList);
|
||||
@ -1086,7 +1278,10 @@ qof_book_merge_commit(QofBookMergeData *mergeData )
|
||||
g_list_free(mergeData->mergeList);
|
||||
g_slist_free(mergeData->mergeObjectParams);
|
||||
g_slist_free(mergeData->targetList);
|
||||
if(mergeData->orphan_list != NULL) { g_slist_free(mergeData->orphan_list); }
|
||||
if (mergeData->orphan_list != NULL)
|
||||
{
|
||||
g_slist_free(mergeData->orphan_list);
|
||||
}
|
||||
g_hash_table_destroy(mergeData->target_table);
|
||||
g_free(mergeData);
|
||||
|
||||
@ -1113,9 +1308,11 @@ qof_book_merge_rule_foreach (QofBookMergeData *mergeData,
|
||||
iter.data = mergeData;
|
||||
matching_rules = NULL;
|
||||
iter.ruleList = NULL;
|
||||
for (node = mergeData->mergeList; node != NULL; node = node->next) {
|
||||
for (node = mergeData->mergeList; node != NULL; node = node->next)
|
||||
{
|
||||
currentRule = node->data;
|
||||
if(currentRule->mergeResult == mergeResult) {
|
||||
if (currentRule->mergeResult == mergeResult)
|
||||
{
|
||||
matching_rules = g_list_prepend(matching_rules, currentRule);
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,8 @@ data is missing, amended or added, the data is labelled \a MERGE_UPDATE.
|
||||
ignored. Aborting the dialogue/process (by the user or in a program crash) at
|
||||
any point before the final commit leaves the existing book completely untouched.
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
MERGE_UNDEF, /**< default value before comparison is made. */
|
||||
MERGE_ABSOLUTE, /**< GUID exact match, no new data - \b ignore */
|
||||
MERGE_NEW, /**< import object does \b not exist in the target
|
||||
|
@ -37,7 +37,10 @@ static gboolean qof_choice_is_initialized(void)
|
||||
{
|
||||
qof_choice_table = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
}
|
||||
if(!qof_choice_table) { return FALSE; }
|
||||
if (!qof_choice_table)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -47,10 +50,16 @@ gboolean qof_object_is_choice(QofIdTypeConst type)
|
||||
|
||||
value = NULL;
|
||||
check = NULL;
|
||||
if(!qof_choice_is_initialized()) { return FALSE; }
|
||||
if (!qof_choice_is_initialized())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
g_return_val_if_fail(type != NULL, FALSE);
|
||||
value = g_hash_table_lookup(qof_choice_table, type);
|
||||
if((GHashTable*)value) { return TRUE; }
|
||||
if ((GHashTable*)value)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
DEBUG (" QOF_TYPE_CHOICE setup failed for %s\n", type);
|
||||
return FALSE;
|
||||
}
|
||||
@ -111,6 +120,9 @@ gboolean qof_choice_check(const char* choice_obj,
|
||||
param_table = g_hash_table_lookup(qof_choice_table, choice_obj);
|
||||
choices = g_hash_table_lookup(param_table, param_name);
|
||||
result = g_list_find(choices, choice);
|
||||
if(!result) { return FALSE; }
|
||||
if (!result)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -199,7 +199,8 @@ qof_class_get_parameter_type (QofIdTypeConst obj_name,
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
struct class_iterate {
|
||||
struct class_iterate
|
||||
{
|
||||
QofClassForeachCB fcn;
|
||||
gpointer data;
|
||||
};
|
||||
@ -229,7 +230,8 @@ qof_class_foreach (QofClassForeachCB cb, gpointer user_data)
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
struct parm_iterate {
|
||||
struct parm_iterate
|
||||
{
|
||||
QofParamForeachCB fcn;
|
||||
gpointer data;
|
||||
};
|
||||
@ -272,19 +274,58 @@ find_reference_param_cb(QofParam *param, gpointer user_data)
|
||||
struct param_ref_list *b;
|
||||
|
||||
b = (struct param_ref_list*)user_data;
|
||||
if((param->param_getfcn == NULL)||(param->param_setfcn == NULL)) { return; }
|
||||
if(0 == safe_strcmp(param->param_type, QOF_TYPE_STRING)) { return; }
|
||||
if(0 == safe_strcmp(param->param_type, QOF_TYPE_NUMERIC)) { return; }
|
||||
if(0 == safe_strcmp(param->param_type, QOF_TYPE_DATE)) { return; }
|
||||
if(0 == safe_strcmp(param->param_type, QOF_TYPE_CHAR)) { return; }
|
||||
if(0 == safe_strcmp(param->param_type, QOF_TYPE_DEBCRED)) { return; }
|
||||
if(0 == safe_strcmp(param->param_type, QOF_TYPE_GUID)) { return; }
|
||||
if(0 == safe_strcmp(param->param_type, QOF_TYPE_INT32)) { return; }
|
||||
if(0 == safe_strcmp(param->param_type, QOF_TYPE_INT64)) { return; }
|
||||
if(0 == safe_strcmp(param->param_type, QOF_TYPE_DOUBLE)) { return; }
|
||||
if(0 == safe_strcmp(param->param_type, QOF_TYPE_KVP)) { return; }
|
||||
if(0 == safe_strcmp(param->param_type, QOF_TYPE_BOOLEAN)) { return; }
|
||||
if(0 == safe_strcmp(param->param_type, QOF_ID_BOOK)) { return; }
|
||||
if ((param->param_getfcn == NULL) || (param->param_setfcn == NULL))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(param->param_type, QOF_TYPE_STRING))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(param->param_type, QOF_TYPE_NUMERIC))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(param->param_type, QOF_TYPE_DATE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(param->param_type, QOF_TYPE_CHAR))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(param->param_type, QOF_TYPE_DEBCRED))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(param->param_type, QOF_TYPE_GUID))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(param->param_type, QOF_TYPE_INT32))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(param->param_type, QOF_TYPE_INT64))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(param->param_type, QOF_TYPE_DOUBLE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(param->param_type, QOF_TYPE_KVP))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(param->param_type, QOF_TYPE_BOOLEAN))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 == safe_strcmp(param->param_type, QOF_ID_BOOK))
|
||||
{
|
||||
return;
|
||||
}
|
||||
b->list = g_list_append(b->list, param);
|
||||
}
|
||||
|
||||
|
@ -123,11 +123,14 @@ qof_event_unregister_handler (gint handler_id)
|
||||
/* safety -- clear the handler in case we're running events now */
|
||||
hi->handler = NULL;
|
||||
|
||||
if (handler_run_level == 0) {
|
||||
if (handler_run_level == 0)
|
||||
{
|
||||
handlers = g_list_remove_link (handlers, node);
|
||||
g_list_free_1 (node);
|
||||
g_free (hi);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
pending_deletes++;
|
||||
}
|
||||
|
||||
@ -177,7 +180,8 @@ qof_event_generate_internal (QofInstance *entity, QofEventId event_id,
|
||||
|
||||
switch (event_id)
|
||||
{
|
||||
case QOF_EVENT_NONE: {
|
||||
case QOF_EVENT_NONE:
|
||||
{
|
||||
/* if none, don't log, just return. */
|
||||
return;
|
||||
}
|
||||
|
@ -120,8 +120,7 @@ qof_gobject_getter (gpointer data, QofParam *getter)
|
||||
str = g_value_get_string (&gval);
|
||||
return (gpointer) str;
|
||||
}
|
||||
else
|
||||
if (G_IS_PARAM_SPEC_INT(gps))
|
||||
else if (G_IS_PARAM_SPEC_INT(gps))
|
||||
{
|
||||
long ival;
|
||||
|
||||
@ -132,8 +131,7 @@ qof_gobject_getter (gpointer data, QofParam *getter)
|
||||
ival = g_value_get_int (&gval);
|
||||
return (gpointer) ival;
|
||||
}
|
||||
else
|
||||
if (G_IS_PARAM_SPEC_UINT(gps))
|
||||
else if (G_IS_PARAM_SPEC_UINT(gps))
|
||||
{
|
||||
long ival;
|
||||
GValue gval = {G_TYPE_INVALID};
|
||||
@ -143,8 +141,7 @@ qof_gobject_getter (gpointer data, QofParam *getter)
|
||||
ival = g_value_get_uint (&gval);
|
||||
return (gpointer) ival;
|
||||
}
|
||||
else
|
||||
if (G_IS_PARAM_SPEC_BOOLEAN(gps))
|
||||
else if (G_IS_PARAM_SPEC_BOOLEAN(gps))
|
||||
{
|
||||
gboolean ival;
|
||||
|
||||
@ -181,8 +178,7 @@ qof_gobject_double_getter (gpointer data, QofParam *getter)
|
||||
fval = g_value_get_float (&gval);
|
||||
return fval;
|
||||
}
|
||||
else
|
||||
if (G_IS_PARAM_SPEC_DOUBLE(gps))
|
||||
else if (G_IS_PARAM_SPEC_DOUBLE(gps))
|
||||
{
|
||||
GValue gval = {G_TYPE_INVALID};
|
||||
g_value_init (&gval, G_TYPE_DOUBLE);
|
||||
@ -252,41 +248,35 @@ qof_gobject_register (QofType e_type, GObjectClass *obclass)
|
||||
qpar->param_type = QOF_TYPE_INT32;
|
||||
j++;
|
||||
}
|
||||
else
|
||||
if ((G_IS_PARAM_SPEC_INT64(gparam)) ||
|
||||
else if ((G_IS_PARAM_SPEC_INT64(gparam)) ||
|
||||
(G_IS_PARAM_SPEC_UINT64(gparam)))
|
||||
{
|
||||
qpar->param_type = QOF_TYPE_INT64;
|
||||
j++;
|
||||
}
|
||||
else
|
||||
if (G_IS_PARAM_SPEC_BOOLEAN(gparam))
|
||||
else if (G_IS_PARAM_SPEC_BOOLEAN(gparam))
|
||||
{
|
||||
qpar->param_type = QOF_TYPE_BOOLEAN;
|
||||
j++;
|
||||
}
|
||||
else
|
||||
if (G_IS_PARAM_SPEC_STRING(gparam))
|
||||
else if (G_IS_PARAM_SPEC_STRING(gparam))
|
||||
{
|
||||
qpar->param_type = QOF_TYPE_STRING;
|
||||
j++;
|
||||
}
|
||||
else
|
||||
if ((G_IS_PARAM_SPEC_POINTER(gparam)) ||
|
||||
else if ((G_IS_PARAM_SPEC_POINTER(gparam)) ||
|
||||
(G_IS_PARAM_SPEC_OBJECT(gparam)))
|
||||
{
|
||||
/* No-op, silently ignore. Someday we should handle this ... */
|
||||
}
|
||||
else
|
||||
if ((G_IS_PARAM_SPEC_FLOAT(gparam)) ||
|
||||
else if ((G_IS_PARAM_SPEC_FLOAT(gparam)) ||
|
||||
(G_IS_PARAM_SPEC_DOUBLE(gparam)))
|
||||
{
|
||||
qpar->param_getfcn = (QofAccessFunc) qof_gobject_double_getter;
|
||||
qpar->param_type = QOF_TYPE_DOUBLE;
|
||||
j++;
|
||||
}
|
||||
else
|
||||
if (G_IS_PARAM_SPEC_CHAR(gparam))
|
||||
else if (G_IS_PARAM_SPEC_CHAR(gparam))
|
||||
{
|
||||
qpar->param_type = QOF_TYPE_CHAR;
|
||||
j++;
|
||||
|
@ -165,12 +165,21 @@ qof_collection_add_entity (QofCollection *coll, QofInstance *ent)
|
||||
const GUID *guid;
|
||||
|
||||
e = NULL;
|
||||
if (!coll || !ent) { return FALSE; }
|
||||
if (!coll || !ent)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
guid = qof_instance_get_guid(ent);
|
||||
if (guid_equal(guid, guid_null())) { return FALSE; }
|
||||
if (guid_equal(guid, guid_null()))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
g_return_val_if_fail (coll->e_type == ent->e_type, FALSE);
|
||||
e = qof_collection_lookup_entity(coll, guid);
|
||||
if ( e != NULL ) { return FALSE; }
|
||||
if ( e != NULL )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
g_hash_table_insert (coll->hash_of_entities, (gpointer)guid, ent);
|
||||
if (!qof_alt_dirty_mode)
|
||||
qof_collection_mark_dirty(coll);
|
||||
@ -189,7 +198,10 @@ collection_merge_cb (QofInstance *ent, gpointer data)
|
||||
gboolean
|
||||
qof_collection_merge (QofCollection *target, QofCollection *merge)
|
||||
{
|
||||
if(!target || !merge) { return FALSE; }
|
||||
if (!target || !merge)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
g_return_val_if_fail (target->e_type == merge->e_type, FALSE);
|
||||
qof_collection_foreach(merge, collection_merge_cb, target);
|
||||
return TRUE;
|
||||
@ -205,9 +217,15 @@ collection_compare_cb (QofInstance *ent, gpointer user_data)
|
||||
|
||||
e = NULL;
|
||||
target = (QofCollection*)user_data;
|
||||
if (!target || !ent) { return; }
|
||||
if (!target || !ent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
value = *(gint*)qof_collection_get_data(target);
|
||||
if (value != 0) { return; }
|
||||
if (value != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
guid = qof_instance_get_guid(ent);
|
||||
if (guid_equal(guid, guid_null()))
|
||||
{
|
||||
@ -233,15 +251,31 @@ qof_collection_compare (QofCollection *target, QofCollection *merge)
|
||||
gint value;
|
||||
|
||||
value = 0;
|
||||
if (!target && !merge) { return 0; }
|
||||
if (target == merge) { return 0; }
|
||||
if (!target && merge) { return -1; }
|
||||
if (target && !merge) { return 1; }
|
||||
if(target->e_type != merge->e_type) { return -1; }
|
||||
if (!target && !merge)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (target == merge)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!target && merge)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (target && !merge)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (target->e_type != merge->e_type)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
qof_collection_set_data(target, &value);
|
||||
qof_collection_foreach(merge, collection_compare_cb, target);
|
||||
value = *(gint*)qof_collection_get_data(target);
|
||||
if(value == 0) {
|
||||
if (value == 0)
|
||||
{
|
||||
qof_collection_set_data(merge, &value);
|
||||
qof_collection_foreach(target, collection_compare_cb, merge);
|
||||
value = *(gint*)qof_collection_get_data(merge);
|
||||
@ -298,13 +332,19 @@ qof_collection_is_dirty (const QofCollection *col)
|
||||
void
|
||||
qof_collection_mark_clean (QofCollection *col)
|
||||
{
|
||||
if (col) { col->is_dirty = FALSE; }
|
||||
if (col)
|
||||
{
|
||||
col->is_dirty = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
qof_collection_mark_dirty (QofCollection *col)
|
||||
{
|
||||
if (col) { col->is_dirty = TRUE; }
|
||||
if (col)
|
||||
{
|
||||
col->is_dirty = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -326,12 +366,16 @@ qof_collection_get_data (const QofCollection *col)
|
||||
void
|
||||
qof_collection_set_data (QofCollection *col, gpointer user_data)
|
||||
{
|
||||
if (col) { col->data = user_data; }
|
||||
if (col)
|
||||
{
|
||||
col->data = user_data;
|
||||
}
|
||||
}
|
||||
|
||||
/* =============================================================== */
|
||||
|
||||
struct _iterate {
|
||||
struct _iterate
|
||||
{
|
||||
QofInstanceForeachCB fcn;
|
||||
gpointer data;
|
||||
};
|
||||
|
@ -168,7 +168,8 @@ void qof_collection_destroy (QofCollection *col);
|
||||
QofIdType qof_collection_get_type (const QofCollection *);
|
||||
|
||||
/** Find the entity going only from its guid */
|
||||
/*@ dependent @*/ QofInstance * qof_collection_lookup_entity (const QofCollection *, const GUID *);
|
||||
/*@ dependent @*/
|
||||
QofInstance * qof_collection_lookup_entity (const QofCollection *, const GUID *);
|
||||
|
||||
/** Callback type for qof_collection_foreach */
|
||||
typedef void (*QofInstanceForeachCB) (QofInstance *, gpointer user_data);
|
||||
|
@ -40,11 +40,13 @@ static QofLogModule log_module = QOF_MOD_ENGINE;
|
||||
|
||||
/* ========================================================== */
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_TYPE,
|
||||
PROP_GUID,
|
||||
@ -291,21 +293,24 @@ qof_instance_init_data (QofInstance *inst, QofIdType type, QofBook *book)
|
||||
* OK, it might eliminate programming errors. */
|
||||
|
||||
col_type = qof_collection_get_type(col);
|
||||
if (safe_strcmp(col_type, type)) {
|
||||
if (safe_strcmp(col_type, type))
|
||||
{
|
||||
PERR ("attempt to insert \"%s\" into \"%s\"", type, col_type);
|
||||
return;
|
||||
}
|
||||
priv = GET_PRIVATE(inst);
|
||||
inst->e_type = CACHE_INSERT (type);
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
guid_new(&priv->guid);
|
||||
|
||||
if (NULL == qof_collection_lookup_entity (col, &priv->guid))
|
||||
break;
|
||||
|
||||
PWARN("duplicate id created, trying again");
|
||||
} while(1);
|
||||
}
|
||||
while (1);
|
||||
|
||||
priv->collection = col;
|
||||
|
||||
@ -358,7 +363,8 @@ qof_instance_get_property (GObject *object,
|
||||
inst = QOF_INSTANCE(object);
|
||||
priv = GET_PRIVATE(inst);
|
||||
|
||||
switch (prop_id) {
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_GUID:
|
||||
g_value_set_boxed(value, &priv->guid);
|
||||
break;
|
||||
@ -416,7 +422,8 @@ qof_instance_set_property (GObject *object,
|
||||
inst = QOF_INSTANCE(object);
|
||||
priv = GET_PRIVATE(inst);
|
||||
|
||||
switch (prop_id) {
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_GUID:
|
||||
qof_instance_set_guid(inst, g_value_get_boxed(value));
|
||||
break;
|
||||
@ -582,7 +589,8 @@ qof_instance_set_slots (QofInstance *inst, KvpFrame *frm)
|
||||
if (!inst) return;
|
||||
|
||||
priv = GET_PRIVATE(inst);
|
||||
if (inst->kvp_data && (inst->kvp_data != frm)) {
|
||||
if (inst->kvp_data && (inst->kvp_data != frm))
|
||||
{
|
||||
kvp_frame_delete(inst->kvp_data);
|
||||
}
|
||||
|
||||
@ -593,7 +601,8 @@ qof_instance_set_slots (QofInstance *inst, KvpFrame *frm)
|
||||
Timespec
|
||||
qof_instance_get_last_update (const QofInstance *inst)
|
||||
{
|
||||
if (!inst) {
|
||||
if (!inst)
|
||||
{
|
||||
Timespec ts = {0, -1};
|
||||
return ts;
|
||||
}
|
||||
@ -698,7 +707,8 @@ qof_instance_print_dirty (const QofInstance *inst, gpointer dummy)
|
||||
QofInstancePrivate *priv;
|
||||
|
||||
priv = GET_PRIVATE(inst);
|
||||
if (priv->dirty) {
|
||||
if (priv->dirty)
|
||||
{
|
||||
printf("%s instance %s is dirty.\n", inst->e_type,
|
||||
guid_to_string(&priv->guid));
|
||||
}
|
||||
@ -710,13 +720,19 @@ qof_instance_get_dirty (QofInstance *inst)
|
||||
QofInstancePrivate *priv;
|
||||
QofCollection *coll;
|
||||
|
||||
if (!inst) { return FALSE; }
|
||||
if (!inst)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
priv = GET_PRIVATE(inst);
|
||||
if (qof_get_alt_dirty_mode())
|
||||
return priv->dirty;
|
||||
coll = priv->collection;
|
||||
if(qof_collection_is_dirty(coll)) { return priv->dirty; }
|
||||
if (qof_collection_is_dirty(coll))
|
||||
{
|
||||
return priv->dirty;
|
||||
}
|
||||
priv->dirty = FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
@ -729,7 +745,8 @@ qof_instance_set_dirty(QofInstance* inst)
|
||||
|
||||
priv = GET_PRIVATE(inst);
|
||||
priv->dirty = TRUE;
|
||||
if (!qof_get_alt_dirty_mode()) {
|
||||
if (!qof_get_alt_dirty_mode())
|
||||
{
|
||||
coll = priv->collection;
|
||||
qof_collection_mark_dirty(coll);
|
||||
}
|
||||
@ -808,15 +825,24 @@ qof_instance_copy_version_check (gpointer to, gconstpointer from)
|
||||
|
||||
guint32 qof_instance_get_idata (gconstpointer inst)
|
||||
{
|
||||
if(!inst) { return 0; }
|
||||
if (!inst)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
g_return_val_if_fail(QOF_IS_INSTANCE(inst), 0);
|
||||
return GET_PRIVATE(inst)->idata;
|
||||
}
|
||||
|
||||
void qof_instance_set_idata(gpointer inst, guint32 idata)
|
||||
{
|
||||
if(!inst) { return; }
|
||||
if(idata < 0) { return; }
|
||||
if (!inst)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (idata < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
g_return_if_fail(QOF_IS_INSTANCE(inst));
|
||||
GET_PRIVATE(inst)->idata = idata;
|
||||
}
|
||||
@ -920,14 +946,17 @@ gboolean qof_commit_edit (QofInstance *inst)
|
||||
if (0 < priv->editlevel) return FALSE;
|
||||
|
||||
#if 0
|
||||
if ((0 == priv->editlevel) && priv->dirty) {
|
||||
if ((0 == priv->editlevel) && priv->dirty)
|
||||
{
|
||||
be = qof_book_get_backend(priv->book);
|
||||
if (be && qof_backend_commit_exists(be)) {
|
||||
if (be && qof_backend_commit_exists(be))
|
||||
{
|
||||
qof_backend_run_commit(be, inst);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (0 > priv->editlevel) {
|
||||
if (0 > priv->editlevel)
|
||||
{
|
||||
PERR ("unbalanced call - resetting (was %d)", priv->editlevel);
|
||||
priv->editlevel = 0;
|
||||
}
|
||||
@ -949,17 +978,21 @@ qof_commit_edit_part2(QofInstance *inst,
|
||||
|
||||
/* See if there's a backend. If there is, invoke it. */
|
||||
be = qof_book_get_backend(priv->book);
|
||||
if (be && qof_backend_commit_exists(be)) {
|
||||
if (be && qof_backend_commit_exists(be))
|
||||
{
|
||||
QofBackendError errcode;
|
||||
|
||||
/* clear errors */
|
||||
do {
|
||||
do
|
||||
{
|
||||
errcode = qof_backend_get_error(be);
|
||||
} while (ERR_BACKEND_NO_ERR != errcode);
|
||||
}
|
||||
while (ERR_BACKEND_NO_ERR != errcode);
|
||||
|
||||
qof_backend_run_commit(be, inst);
|
||||
errcode = qof_backend_get_error(be);
|
||||
if (ERR_BACKEND_NO_ERR != errcode) {
|
||||
if (ERR_BACKEND_NO_ERR != errcode)
|
||||
{
|
||||
/* XXX Should perform a rollback here */
|
||||
priv->do_free = FALSE;
|
||||
|
||||
@ -979,7 +1012,8 @@ qof_commit_edit_part2(QofInstance *inst,
|
||||
// }
|
||||
priv->infant = FALSE;
|
||||
|
||||
if (priv->do_free) {
|
||||
if (priv->do_free)
|
||||
{
|
||||
if (on_free)
|
||||
on_free(inst);
|
||||
return TRUE;
|
||||
|
@ -87,7 +87,8 @@ GType qof_instance_get_type(void);
|
||||
void qof_instance_init_data (QofInstance *, QofIdType, QofBook *);
|
||||
|
||||
/** Return the book pointer */
|
||||
/*@ dependent @*/ QofBook *qof_instance_get_book (gconstpointer);
|
||||
/*@ dependent @*/
|
||||
QofBook *qof_instance_get_book (gconstpointer);
|
||||
|
||||
/** Set the book pointer */
|
||||
void qof_instance_set_book (gconstpointer inst, QofBook *book);
|
||||
@ -99,14 +100,17 @@ void qof_instance_copy_book (gpointer ptr1, gconstpointer ptr2);
|
||||
gboolean qof_instance_books_equal (gconstpointer ptr1, gconstpointer ptr2);
|
||||
|
||||
/** Return the GUID of this instance */
|
||||
/*@ dependent @*/ const GUID * qof_instance_get_guid (gconstpointer);
|
||||
/*@ dependent @*/
|
||||
const GUID * qof_instance_get_guid (gconstpointer);
|
||||
|
||||
/** \deprecated Use qof_instance_get_guid instead.
|
||||
* Works like qof_instance_get_guid, but returns NULL on NULL */
|
||||
/*@ dependent @*/ const GUID * qof_entity_get_guid (gconstpointer);
|
||||
/*@ dependent @*/
|
||||
const GUID * qof_entity_get_guid (gconstpointer);
|
||||
|
||||
/** Return the collection this instance belongs to */
|
||||
/*@ dependent @*/ QofCollection* qof_instance_get_collection (gconstpointer inst);
|
||||
/*@ dependent @*/
|
||||
QofCollection* qof_instance_get_collection (gconstpointer inst);
|
||||
|
||||
/** Set the GUID of this instance */
|
||||
void qof_instance_set_guid (gpointer inst, const GUID *guid);
|
||||
@ -125,7 +129,8 @@ gint qof_instance_guid_compare(const gconstpointer ptr1, const gconstpointer ptr
|
||||
//void qof_instance_set_e_type (QofInstance *ent, QofIdType e_type);
|
||||
|
||||
/** Return the pointer to the kvp_data */
|
||||
/*@ dependent @*/ KvpFrame* qof_instance_get_slots (const QofInstance *);
|
||||
/*@ dependent @*/
|
||||
KvpFrame* qof_instance_get_slots (const QofInstance *);
|
||||
|
||||
/** Return the last time this instance was modified. If QofInstances
|
||||
* are used with the QofObject storage backends, then the instance
|
||||
|
@ -77,7 +77,11 @@ qof_log_dedent(void)
|
||||
void
|
||||
qof_log_set_file(FILE *outfile)
|
||||
{
|
||||
if (!outfile) { fout = stderr; return; }
|
||||
if (!outfile)
|
||||
{
|
||||
fout = stderr;
|
||||
return;
|
||||
}
|
||||
fout = outfile;
|
||||
}
|
||||
|
||||
@ -192,7 +196,10 @@ qof_log_shutdown (void)
|
||||
void
|
||||
qof_log_set_level(QofLogModule log_module, QofLogLevel level)
|
||||
{
|
||||
if (!log_module || level == 0) { return; }
|
||||
if (!log_module || level == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!log_table)
|
||||
{
|
||||
log_table = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
@ -206,7 +213,10 @@ qof_log_prettify (const char *name)
|
||||
gchar *p, *buffer;
|
||||
gint length;
|
||||
|
||||
if (!name) { return ""; }
|
||||
if (!name)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
buffer = g_strndup(name, QOF_LOG_MAX_CHARS - 1);
|
||||
length = strlen(buffer);
|
||||
p = g_strstr_len(buffer, length, "(");
|
||||
@ -215,7 +225,10 @@ qof_log_prettify (const char *name)
|
||||
*(p + 1) = ')';
|
||||
*(p + 2) = 0x0;
|
||||
}
|
||||
else { strcpy (&buffer[QOF_LOG_MAX_CHARS - 6], "...()"); }
|
||||
else
|
||||
{
|
||||
strcpy (&buffer[QOF_LOG_MAX_CHARS - 6], "...()");
|
||||
}
|
||||
if (function_buffer)
|
||||
g_free(function_buffer);
|
||||
function_buffer = g_strdup(buffer);
|
||||
@ -371,13 +384,27 @@ qof_log_level_to_string(QofLogLevel log_level)
|
||||
gchar *level_str = "unknw";
|
||||
switch (log_level)
|
||||
{
|
||||
case G_LOG_LEVEL_ERROR: level_str = "ERROR"; break;
|
||||
case G_LOG_LEVEL_CRITICAL:level_str = "CRIT"; break;
|
||||
case G_LOG_LEVEL_WARNING: level_str = "WARN"; break;
|
||||
case G_LOG_LEVEL_MESSAGE: level_str = "MESSG"; break;
|
||||
case G_LOG_LEVEL_INFO: level_str = "INFO"; break;
|
||||
case G_LOG_LEVEL_DEBUG: level_str = "DEBUG"; break;
|
||||
default: level_str = "OTHER"; break;
|
||||
case G_LOG_LEVEL_ERROR:
|
||||
level_str = "ERROR";
|
||||
break;
|
||||
case G_LOG_LEVEL_CRITICAL:
|
||||
level_str = "CRIT";
|
||||
break;
|
||||
case G_LOG_LEVEL_WARNING:
|
||||
level_str = "WARN";
|
||||
break;
|
||||
case G_LOG_LEVEL_MESSAGE:
|
||||
level_str = "MESSG";
|
||||
break;
|
||||
case G_LOG_LEVEL_INFO:
|
||||
level_str = "INFO";
|
||||
break;
|
||||
case G_LOG_LEVEL_DEBUG:
|
||||
level_str = "DEBUG";
|
||||
break;
|
||||
default:
|
||||
level_str = "OTHER";
|
||||
break;
|
||||
}
|
||||
return level_str;
|
||||
}
|
||||
@ -395,13 +422,15 @@ qof_log_level_from_string(const gchar *str)
|
||||
}
|
||||
|
||||
static
|
||||
struct timeval qof_clock[NUM_CLOCKS] = {
|
||||
struct timeval qof_clock[NUM_CLOCKS] =
|
||||
{
|
||||
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
|
||||
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
|
||||
};
|
||||
|
||||
static
|
||||
struct timeval qof_clock_total[NUM_CLOCKS] = {
|
||||
struct timeval qof_clock_total[NUM_CLOCKS] =
|
||||
{
|
||||
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
|
||||
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
|
||||
};
|
||||
|
@ -401,7 +401,8 @@ int main ()
|
||||
|
||||
d = 0x2ae79964d3ae1d04ULL;
|
||||
|
||||
for (i=0; i<20; i++) {
|
||||
for (i = 0; i < 20; i++)
|
||||
{
|
||||
|
||||
quot = div128 (n, d);
|
||||
printf ("%d result = %" G_GINT64_MODIFIER "x %" G_GINT64_MODIFIER "x\n",
|
||||
|
@ -32,7 +32,8 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
guint64 hi;
|
||||
guint64 lo;
|
||||
short isneg; /**< sign-bit -- T if number is negative */
|
||||
|
@ -60,7 +60,8 @@ void qof_object_book_begin (QofBook *book)
|
||||
|
||||
if (!book) return;
|
||||
ENTER (" ");
|
||||
for (l = object_modules; l; l = l->next) {
|
||||
for (l = object_modules; l; l = l->next)
|
||||
{
|
||||
QofObject *obj = l->data;
|
||||
if (obj->book_begin)
|
||||
obj->book_begin (book);
|
||||
@ -77,7 +78,8 @@ void qof_object_book_end (QofBook *book)
|
||||
|
||||
if (!book) return;
|
||||
ENTER (" ");
|
||||
for (l = object_modules; l; l = l->next) {
|
||||
for (l = object_modules; l; l = l->next)
|
||||
{
|
||||
QofObject *obj = l->data;
|
||||
if (obj->book_end)
|
||||
obj->book_end (book);
|
||||
@ -131,7 +133,8 @@ void qof_object_foreach_type (QofForeachTypeCB cb, gpointer user_data)
|
||||
|
||||
if (!cb) return;
|
||||
|
||||
for (l = object_modules; l; l = l->next) {
|
||||
for (l = object_modules; l; l = l->next)
|
||||
{
|
||||
QofObject *obj = l->data;
|
||||
(cb) (obj, user_data);
|
||||
}
|
||||
@ -143,7 +146,8 @@ qof_object_compliance (QofIdTypeConst type_name, gboolean warn)
|
||||
const QofObject *obj;
|
||||
|
||||
obj = qof_object_lookup(type_name);
|
||||
if((obj->create == NULL)||(obj->foreach == NULL)){
|
||||
if ((obj->create == NULL) || (obj->foreach == NULL))
|
||||
{
|
||||
if (warn)
|
||||
{
|
||||
PINFO (" Object type %s is not fully QOF compliant", obj->e_type);
|
||||
@ -161,7 +165,10 @@ qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
|
||||
QofCollection *col;
|
||||
const QofObject *obj;
|
||||
|
||||
if (!book || !type_name) { return; }
|
||||
if (!book || !type_name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PINFO ("type=%s", type_name);
|
||||
|
||||
obj = qof_object_lookup (type_name);
|
||||
@ -171,7 +178,10 @@ qof_object_foreach (QofIdTypeConst type_name, QofBook *book,
|
||||
return;
|
||||
}
|
||||
col = qof_book_get_collection (book, obj->e_type);
|
||||
if (!obj) { return; }
|
||||
if (!obj)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (obj->foreach)
|
||||
{
|
||||
obj->foreach (col, cb, user_data);
|
||||
@ -255,7 +265,8 @@ gboolean qof_object_register (const QofObject *object)
|
||||
return FALSE;
|
||||
|
||||
/* Now initialize all the known books */
|
||||
if (object->book_begin && book_list) {
|
||||
if (object->book_begin && book_list)
|
||||
{
|
||||
GList *node;
|
||||
for (node = book_list; node; node = node->next)
|
||||
object->book_begin (node->data);
|
||||
@ -273,7 +284,8 @@ const QofObject * qof_object_lookup (QofIdTypeConst name)
|
||||
|
||||
if (!name) return NULL;
|
||||
|
||||
for (iter = object_modules; iter; iter = iter->next) {
|
||||
for (iter = object_modules; iter; iter = iter->next)
|
||||
{
|
||||
obj = iter->data;
|
||||
if (!safe_strcmp (obj->e_type, name))
|
||||
return obj;
|
||||
@ -296,7 +308,8 @@ gboolean qof_object_register_backend (QofIdTypeConst type_name,
|
||||
ht = g_hash_table_lookup (backend_data, backend_name);
|
||||
|
||||
/* If it doesn't already exist, create a new table for this backend */
|
||||
if (!ht) {
|
||||
if (!ht)
|
||||
{
|
||||
ht = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_hash_table_insert (backend_data, (char *)backend_name, ht);
|
||||
}
|
||||
@ -323,7 +336,8 @@ gpointer qof_object_lookup_backend (QofIdTypeConst type_name,
|
||||
return g_hash_table_lookup (ht, (char *)type_name);
|
||||
}
|
||||
|
||||
struct foreach_data {
|
||||
struct foreach_data
|
||||
{
|
||||
QofForeachBackendTypeCB cb;
|
||||
gpointer user_data;
|
||||
};
|
||||
|
@ -167,7 +167,8 @@ gboolean qof_object_register_backend (QofIdTypeConst type_name,
|
||||
const char *backend_name,
|
||||
gpointer be_data);
|
||||
|
||||
/*@ dependent @*/ gpointer qof_object_lookup_backend (QofIdTypeConst type_name,
|
||||
/*@ dependent @*/
|
||||
gpointer qof_object_lookup_backend (QofIdTypeConst type_name,
|
||||
const char *backend_name);
|
||||
|
||||
void qof_object_foreach_backend (const char *backend_name,
|
||||
|
@ -229,18 +229,30 @@ SIMPLE_PRED_HANDLER (qof_query_pred_boolean_from_xml,
|
||||
|
||||
/* =============================================================== */
|
||||
|
||||
static void wrap_new_gint64(KvpValue **v, gint64 value) {
|
||||
*v = kvp_value_new_gint64 (value); }
|
||||
static void wrap_new_double(KvpValue **v, double value) {
|
||||
*v = kvp_value_new_double (value); }
|
||||
static void wrap_new_numeric(KvpValue **v, gnc_numeric value) {
|
||||
*v = kvp_value_new_gnc_numeric (value); }
|
||||
static void wrap_new_string(KvpValue **v, const char * value) {
|
||||
*v = kvp_value_new_string (value); }
|
||||
static void wrap_new_guid(KvpValue **v, const GUID * value) {
|
||||
*v = kvp_value_new_guid (value); }
|
||||
static void wrap_new_timespec(KvpValue **v, Timespec value) {
|
||||
*v = kvp_value_new_timespec (value); }
|
||||
static void wrap_new_gint64(KvpValue **v, gint64 value)
|
||||
{
|
||||
*v = kvp_value_new_gint64 (value);
|
||||
}
|
||||
static void wrap_new_double(KvpValue **v, double value)
|
||||
{
|
||||
*v = kvp_value_new_double (value);
|
||||
}
|
||||
static void wrap_new_numeric(KvpValue **v, gnc_numeric value)
|
||||
{
|
||||
*v = kvp_value_new_gnc_numeric (value);
|
||||
}
|
||||
static void wrap_new_string(KvpValue **v, const char * value)
|
||||
{
|
||||
*v = kvp_value_new_string (value);
|
||||
}
|
||||
static void wrap_new_guid(KvpValue **v, const GUID * value)
|
||||
{
|
||||
*v = kvp_value_new_guid (value);
|
||||
}
|
||||
static void wrap_new_timespec(KvpValue **v, Timespec value)
|
||||
{
|
||||
*v = kvp_value_new_timespec (value);
|
||||
}
|
||||
|
||||
|
||||
static QofQueryPredData *
|
||||
@ -412,7 +424,10 @@ qof_query_pred_date_from_xml (xmlNodePtr root)
|
||||
|
||||
how = QOF_COMPARE_EQUAL;
|
||||
sm = QOF_DATE_MATCH_DAY;
|
||||
date = (Timespec){0,0};
|
||||
date = (Timespec)
|
||||
{
|
||||
0, 0
|
||||
};
|
||||
|
||||
for (node = xp; node; node = node->next)
|
||||
{
|
||||
@ -515,58 +530,47 @@ qof_query_term_from_xml (QofQuery *q, xmlNodePtr root)
|
||||
qof_query_destroy (qt);
|
||||
return;
|
||||
}
|
||||
else
|
||||
if (0 == strcmp (node->name, "qofquery:param-path"))
|
||||
else if (0 == strcmp (node->name, "qofquery:param-path"))
|
||||
{
|
||||
path = qof_query_param_path_from_xml (node);
|
||||
}
|
||||
else
|
||||
if (0 == strcmp (node->name, "qofquery:pred-string"))
|
||||
else if (0 == strcmp (node->name, "qofquery:pred-string"))
|
||||
{
|
||||
pred = qof_query_pred_string_from_xml (node);
|
||||
}
|
||||
else
|
||||
if (0 == strcmp (node->name, "qofquery:pred-date"))
|
||||
else if (0 == strcmp (node->name, "qofquery:pred-date"))
|
||||
{
|
||||
pred = qof_query_pred_date_from_xml (node);
|
||||
}
|
||||
else
|
||||
if (0 == strcmp (node->name, "qofquery:pred-numeric"))
|
||||
else if (0 == strcmp (node->name, "qofquery:pred-numeric"))
|
||||
{
|
||||
pred = qof_query_pred_numeric_from_xml (node);
|
||||
}
|
||||
else
|
||||
if (0 == strcmp (node->name, "qofquery:pred-int32"))
|
||||
else if (0 == strcmp (node->name, "qofquery:pred-int32"))
|
||||
{
|
||||
pred = qof_query_pred_int32_from_xml (node);
|
||||
}
|
||||
else
|
||||
if (0 == strcmp (node->name, "qofquery:pred-int64"))
|
||||
else if (0 == strcmp (node->name, "qofquery:pred-int64"))
|
||||
{
|
||||
pred = qof_query_pred_int64_from_xml (node);
|
||||
}
|
||||
else
|
||||
if (0 == strcmp (node->name, "qofquery:pred-double"))
|
||||
else if (0 == strcmp (node->name, "qofquery:pred-double"))
|
||||
{
|
||||
pred = qof_query_pred_double_from_xml (node);
|
||||
}
|
||||
else
|
||||
if (0 == strcmp (node->name, "qofquery:pred-boolean"))
|
||||
else if (0 == strcmp (node->name, "qofquery:pred-boolean"))
|
||||
{
|
||||
pred = qof_query_pred_boolean_from_xml (node);
|
||||
}
|
||||
else
|
||||
if (0 == strcmp (node->name, "qofquery:pred-char"))
|
||||
else if (0 == strcmp (node->name, "qofquery:pred-char"))
|
||||
{
|
||||
pred = qof_query_pred_char_from_xml (node);
|
||||
}
|
||||
else
|
||||
if (0 == strcmp (node->name, "qofquery:pred-guid"))
|
||||
else if (0 == strcmp (node->name, "qofquery:pred-guid"))
|
||||
{
|
||||
pred = qof_query_pred_guid_from_xml (node);
|
||||
}
|
||||
else
|
||||
if (0 == strcmp (node->name, "qofquery:pred-kvp"))
|
||||
else if (0 == strcmp (node->name, "qofquery:pred-kvp"))
|
||||
{
|
||||
pred = qof_query_pred_kvp_from_xml (node);
|
||||
}
|
||||
@ -656,8 +660,7 @@ qof_query_from_xml (xmlNodePtr root)
|
||||
{
|
||||
qof_query_or_terms_from_xml (q, node);
|
||||
}
|
||||
else
|
||||
if (0 == strcmp (node->name, "qofquery:sort-list"))
|
||||
else if (0 == strcmp (node->name, "qofquery:sort-list"))
|
||||
{
|
||||
// XXX unfinished I'm bored
|
||||
}
|
||||
@ -687,7 +690,8 @@ int main (int argc, char * argv[])
|
||||
qof_query_init();
|
||||
qof_object_initialize ();
|
||||
|
||||
static QofParam params[] = {
|
||||
static QofParam params[] =
|
||||
{
|
||||
{ "adate", QOF_TYPE_DATE, NULL, NULL},
|
||||
{ "aint", QOF_TYPE_INT32, NULL, NULL},
|
||||
{ "aint64", QOF_TYPE_INT64, NULL, NULL},
|
||||
|
@ -43,10 +43,13 @@ int qof_query_get_max_results (const QofQuery *q);
|
||||
* Note that you should NOT modify this list in any way. It belongs
|
||||
* to the query.
|
||||
*/
|
||||
/*@ dependent @*/ GList * qof_query_get_terms (const QofQuery *q);
|
||||
/*@ dependent @*/
|
||||
GList * qof_query_get_terms (const QofQuery *q);
|
||||
|
||||
/*@ dependent @*/ GSList * qof_query_term_get_param_path (const QofQueryTerm *queryterm);
|
||||
/*@ dependent @*/ QofQueryPredData *qof_query_term_get_pred_data (const QofQueryTerm *queryterm);
|
||||
/*@ dependent @*/
|
||||
GSList * qof_query_term_get_param_path (const QofQueryTerm *queryterm);
|
||||
/*@ dependent @*/
|
||||
QofQueryPredData *qof_query_term_get_pred_data (const QofQueryTerm *queryterm);
|
||||
gboolean qof_query_term_is_inverted (const QofQueryTerm *queryterm);
|
||||
|
||||
|
||||
@ -58,7 +61,8 @@ gboolean qof_query_term_is_inverted (const QofQueryTerm *queryterm);
|
||||
void qof_query_get_sorts (QofQuery *q, QofQuerySort **primary,
|
||||
QofQuerySort **secondary, QofQuerySort **tertiary);
|
||||
|
||||
/*@ dependent @*/ GSList * qof_query_sort_get_param_path (const QofQuerySort *querysort);
|
||||
/*@ dependent @*/
|
||||
GSList * qof_query_sort_get_param_path (const QofQuerySort *querysort);
|
||||
gint qof_query_sort_get_sort_options (const QofQuerySort *querysort);
|
||||
gboolean qof_query_sort_get_increasing (const QofQuerySort *querysort);
|
||||
|
||||
|
@ -550,7 +550,8 @@ int main (int argc, char * argv[])
|
||||
qof_query_init();
|
||||
qof_object_initialize ();
|
||||
|
||||
static QofParam params[] = {
|
||||
static QofParam params[] =
|
||||
{
|
||||
{ "adate", QOF_TYPE_DATE, NULL, NULL},
|
||||
{ "aint", QOF_TYPE_INT32, NULL, NULL},
|
||||
{ "aint64", QOF_TYPE_INT64, NULL, NULL},
|
||||
|
@ -117,7 +117,8 @@ static void query_init (QofQuery *q, QofQueryTerm *initial_term)
|
||||
GList *and = NULL;
|
||||
GHashTable *ht;
|
||||
|
||||
if (initial_term) {
|
||||
if (initial_term)
|
||||
{
|
||||
or = g_list_alloc ();
|
||||
and = g_list_alloc ();
|
||||
and->data = initial_term;
|
||||
@ -396,7 +397,10 @@ check_object (const QofQuery *q, gpointer object)
|
||||
/* XXX: Don't know how to do this conversion -- do we care? */
|
||||
}
|
||||
}
|
||||
if (and_terms_ok) { return 1; }
|
||||
if (and_terms_ok)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* If there are no terms, assume a "match any" applies.
|
||||
@ -462,7 +466,11 @@ compile_sort (QofQuerySort *sort, QofIdType obj)
|
||||
sort->obj_cmp = NULL;
|
||||
|
||||
/* An empty param_list implies "no sort" */
|
||||
if (!sort->param_list) { LEAVE (" "); return; }
|
||||
if (!sort->param_list)
|
||||
{
|
||||
LEAVE (" ");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Walk the parameter list of obtain the parameter functions */
|
||||
sort->param_fcns = compile_params (sort->param_list, obj, &resObj);
|
||||
@ -499,8 +507,10 @@ static void compile_terms (QofQuery *q)
|
||||
/* Find the specific functions for this Query. Note that the
|
||||
* Query's search_for should now be set to the new type.
|
||||
*/
|
||||
for (or_ptr = q->terms; or_ptr; or_ptr = or_ptr->next) {
|
||||
for (and_ptr = or_ptr->data; and_ptr; and_ptr = and_ptr->next) {
|
||||
for (or_ptr = q->terms; or_ptr; or_ptr = or_ptr->next)
|
||||
{
|
||||
for (and_ptr = or_ptr->data; and_ptr; and_ptr = and_ptr->next)
|
||||
{
|
||||
QofQueryTerm *qt = and_ptr->data;
|
||||
const QofParam *resObj = NULL;
|
||||
|
||||
@ -530,11 +540,13 @@ static void compile_terms (QofQuery *q)
|
||||
q->defaultSort = qof_class_get_default_sort (q->search_for);
|
||||
|
||||
/* Now compile the backend instances */
|
||||
for (node = q->books; node; node = node->next) {
|
||||
for (node = q->books; node; node = node->next)
|
||||
{
|
||||
QofBook *book = node->data;
|
||||
QofBackend *be = book->backend;
|
||||
|
||||
if (be && be->compile_query) {
|
||||
if (be && be->compile_query)
|
||||
{
|
||||
gpointer result = (be->compile_query)(be, q);
|
||||
if (result)
|
||||
g_hash_table_insert (q->be_compiled, book, result);
|
||||
@ -549,7 +561,8 @@ static void check_item_cb (gpointer object, gpointer user_data)
|
||||
|
||||
if (!object || !ql) return;
|
||||
|
||||
if (check_object (ql->query, object)) {
|
||||
if (check_object (ql->query, object))
|
||||
{
|
||||
ql->list = g_list_prepend (ql->list, object);
|
||||
ql->count++;
|
||||
}
|
||||
@ -558,7 +571,8 @@ static void check_item_cb (gpointer object, gpointer user_data)
|
||||
|
||||
static int param_list_cmp (const GSList *l1, const GSList *l2)
|
||||
{
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Check the easy stuff */
|
||||
@ -582,7 +596,8 @@ static GList * merge_books (GList *l1, GList *l2)
|
||||
|
||||
res = g_list_copy (l1);
|
||||
|
||||
for (node = l2; node; node = node->next) {
|
||||
for (node = l2; node; node = node->next)
|
||||
{
|
||||
if (g_list_index (res, node->data) == -1)
|
||||
res = g_list_prepend (res, node->data);
|
||||
}
|
||||
@ -662,16 +677,22 @@ void qof_query_purge_terms (QofQuery *q, GSList *param_list)
|
||||
|
||||
if (!q || !param_list) return;
|
||||
|
||||
for (or = q->terms; or; or = or->next) {
|
||||
for (and = or->data; and; and = and->next) {
|
||||
for (or = q->terms; or; or = or->next)
|
||||
{
|
||||
for (and = or->data; and; and = and->next)
|
||||
{
|
||||
qt = and->data;
|
||||
if (!param_list_cmp (qt->param_list, param_list)) {
|
||||
if (g_list_length (or->data) == 1) {
|
||||
if (!param_list_cmp (qt->param_list, param_list))
|
||||
{
|
||||
if (g_list_length (or->data) == 1)
|
||||
{
|
||||
q->terms = g_list_remove_link (q->terms, or);
|
||||
g_list_free_1 (or);
|
||||
or = q->terms;
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
or->data = g_list_remove_link (or->data, and);
|
||||
g_list_free_1 (and);
|
||||
and = or->data;
|
||||
@ -873,7 +894,8 @@ void qof_query_search_for (QofQuery *q, QofIdTypeConst obj_type)
|
||||
if (!q || !obj_type)
|
||||
return;
|
||||
|
||||
if (safe_strcmp (q->search_for, obj_type)) {
|
||||
if (safe_strcmp (q->search_for, obj_type))
|
||||
{
|
||||
q->search_for = (QofIdType) obj_type;
|
||||
q->changed = 1;
|
||||
}
|
||||
@ -913,8 +935,10 @@ gboolean qof_query_has_term_type (QofQuery *q, GSList *term_param)
|
||||
if (!q || !term_param)
|
||||
return FALSE;
|
||||
|
||||
for(or = q->terms; or; or = or->next) {
|
||||
for(and = or->data; and; and = and->next) {
|
||||
for (or = q->terms; or; or = or->next)
|
||||
{
|
||||
for (and = or->data; and; and = and->next)
|
||||
{
|
||||
QofQueryTerm *qt = and->data;
|
||||
if (!param_list_cmp (term_param, qt->param_list))
|
||||
return TRUE;
|
||||
@ -933,8 +957,10 @@ GSList * qof_query_get_term_type (QofQuery *q, GSList *term_param)
|
||||
if (!q || !term_param)
|
||||
return FALSE;
|
||||
|
||||
for(or = q->terms; or; or = or->next) {
|
||||
for(and = or->data; and; and = and->next) {
|
||||
for (or = q->terms; or; or = or->next)
|
||||
{
|
||||
for (and = or->data; and; and = and->next)
|
||||
{
|
||||
QofQueryTerm *qt = and->data;
|
||||
if (!param_list_cmp (term_param, qt->param_list))
|
||||
results = g_slist_append(results, qt->pdata);
|
||||
@ -1018,7 +1044,8 @@ QofQuery * qof_query_invert (QofQuery *q)
|
||||
|
||||
aterms = g_list_nth_data(q->terms, 0);
|
||||
new_oterm = NULL;
|
||||
for(cur=aterms; cur; cur=cur->next) {
|
||||
for (cur = aterms; cur; cur = cur->next)
|
||||
{
|
||||
qt = copy_query_term(cur->data);
|
||||
qt->invert = !(qt->invert);
|
||||
new_oterm = g_list_append(NULL, qt);
|
||||
@ -1478,7 +1505,8 @@ qof_query_print (QofQuery * query)
|
||||
|
||||
ENTER (" ");
|
||||
|
||||
if (!query) {
|
||||
if (!query)
|
||||
{
|
||||
LEAVE("query is (null)");
|
||||
return;
|
||||
}
|
||||
|
@ -85,7 +85,8 @@ probably optimize.
|
||||
typedef struct _QofQuery QofQuery;
|
||||
|
||||
/** Query Term Operators, for combining Query Terms */
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
QOF_QUERY_AND = 1,
|
||||
QOF_QUERY_OR,
|
||||
QOF_QUERY_NAND,
|
||||
@ -371,7 +372,8 @@ gboolean qof_query_equal (const QofQuery *q1, const QofQuery *q2);
|
||||
void qof_query_print (QofQuery *query);
|
||||
|
||||
/** Return the type of data we're querying for */
|
||||
/*@ dependent @*/ QofIdType qof_query_get_search_for (const QofQuery *q);
|
||||
/*@ dependent @*/
|
||||
QofIdType qof_query_get_search_for (const QofQuery *q);
|
||||
|
||||
/** Return the list of books we're using */
|
||||
GList * qof_query_get_books (QofQuery *q);
|
||||
|
@ -62,7 +62,8 @@ gboolean qof_query_core_predicate_equal (const QofQueryPredData *p1, const QofQu
|
||||
* Query.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofQueryPredData pd;
|
||||
QofStringMatch options;
|
||||
gboolean is_regex;
|
||||
@ -70,64 +71,75 @@ typedef struct {
|
||||
regex_t compiled;
|
||||
} query_string_def, *query_string_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofQueryPredData pd;
|
||||
QofDateMatch options;
|
||||
Timespec date;
|
||||
} query_date_def, *query_date_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofQueryPredData pd;
|
||||
QofNumericMatch options;
|
||||
gnc_numeric amount;
|
||||
} query_numeric_def, *query_numeric_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofQueryPredData pd;
|
||||
QofGuidMatch options;
|
||||
GList * guids;
|
||||
} query_guid_def, *query_guid_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofQueryPredData pd;
|
||||
gint32 val;
|
||||
} query_int32_def, *query_int32_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofQueryPredData pd;
|
||||
gint64 val;
|
||||
} query_int64_def, *query_int64_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofQueryPredData pd;
|
||||
double val;
|
||||
} query_double_def, *query_double_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofQueryPredData pd;
|
||||
gboolean val;
|
||||
} query_boolean_def, *query_boolean_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofQueryPredData pd;
|
||||
QofCharMatch options;
|
||||
gchar * char_list;
|
||||
} query_char_def, *query_char_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofQueryPredData pd;
|
||||
GSList * path;
|
||||
KvpValue * value;
|
||||
} query_kvp_def, *query_kvp_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofQueryPredData pd;
|
||||
QofGuidMatch options;
|
||||
QofCollection *coll;
|
||||
GList *guids;
|
||||
} query_coll_def, *query_coll_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
QofQueryPredData pd;
|
||||
QofGuidMatch options;
|
||||
const GUID *guid;
|
||||
|
@ -142,21 +142,27 @@ string_match_predicate (gpointer object,
|
||||
|
||||
if (!s) s = "";
|
||||
|
||||
if (pdata->is_regex) {
|
||||
if (pdata->is_regex)
|
||||
{
|
||||
regmatch_t match;
|
||||
if (!regexec (&pdata->compiled, s, 1, &match, 0))
|
||||
ret = 1;
|
||||
|
||||
} else if (pdata->options == QOF_STRING_MATCH_CASEINSENSITIVE) {
|
||||
}
|
||||
else if (pdata->options == QOF_STRING_MATCH_CASEINSENSITIVE)
|
||||
{
|
||||
if (qof_utf8_substr_nocase (s, pdata->matchstring))
|
||||
ret = 1;
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strstr (s, pdata->matchstring))
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
switch (pd->how) {
|
||||
switch (pd->how)
|
||||
{
|
||||
case QOF_COMPARE_EQUAL:
|
||||
return ret;
|
||||
case QOF_COMPARE_NEQ:
|
||||
@ -267,14 +273,16 @@ qof_query_string_predicate (QofQueryCompare how,
|
||||
pdata->options = options;
|
||||
pdata->matchstring = g_strdup (str);
|
||||
|
||||
if (is_regex) {
|
||||
if (is_regex)
|
||||
{
|
||||
int rc;
|
||||
int flags = REG_EXTENDED;
|
||||
if (options == QOF_STRING_MATCH_CASEINSENSITIVE)
|
||||
flags |= REG_ICASE;
|
||||
|
||||
rc = regcomp(&pdata->compiled, str, flags);
|
||||
if (rc) {
|
||||
if (rc)
|
||||
{
|
||||
g_free(pdata->matchstring);
|
||||
g_free(pdata);
|
||||
return NULL;
|
||||
@ -301,7 +309,8 @@ static int
|
||||
date_compare (Timespec ta, Timespec tb, QofDateMatch options)
|
||||
{
|
||||
|
||||
if (options == QOF_DATE_MATCH_DAY) {
|
||||
if (options == QOF_DATE_MATCH_DAY)
|
||||
{
|
||||
ta = timespecCanonicalDayTime (ta);
|
||||
tb = timespecCanonicalDayTime (tb);
|
||||
}
|
||||
@ -332,7 +341,8 @@ date_match_predicate (gpointer object, QofParam *getter,
|
||||
objtime = ((query_date_getter)getter->param_getfcn) (object, getter);
|
||||
compare = date_compare (objtime, pdata->date, pdata->options);
|
||||
|
||||
switch (pd->how) {
|
||||
switch (pd->how)
|
||||
{
|
||||
case QOF_COMPARE_LT:
|
||||
return (compare < 0);
|
||||
case QOF_COMPARE_LTE:
|
||||
@ -444,7 +454,8 @@ numeric_match_predicate (gpointer object, QofParam *getter,
|
||||
|
||||
obj_val = ((query_numeric_getter)getter->param_getfcn) (object, getter);
|
||||
|
||||
switch (pdata->options) {
|
||||
switch (pdata->options)
|
||||
{
|
||||
case QOF_NUMERIC_MATCH_CREDIT:
|
||||
if (gnc_numeric_positive_p (obj_val)) return 0;
|
||||
break;
|
||||
@ -457,7 +468,8 @@ numeric_match_predicate (gpointer object, QofParam *getter,
|
||||
|
||||
/* Amounts are considered to be 'equal' if they match to
|
||||
* four decimal places. (epsilon=1/10000) */
|
||||
if (pd->how == QOF_COMPARE_EQUAL || pd->how == QOF_COMPARE_NEQ) {
|
||||
if (pd->how == QOF_COMPARE_EQUAL || pd->how == QOF_COMPARE_NEQ)
|
||||
{
|
||||
gnc_numeric cmp_val = gnc_numeric_create (1, 10000);
|
||||
compare =
|
||||
(gnc_numeric_compare (gnc_numeric_abs
|
||||
@ -465,10 +477,12 @@ numeric_match_predicate (gpointer object, QofParam *getter,
|
||||
gnc_numeric_abs (pdata->amount),
|
||||
100000, GNC_HOW_RND_ROUND)),
|
||||
cmp_val) < 0);
|
||||
} else
|
||||
}
|
||||
else
|
||||
compare = gnc_numeric_compare (gnc_numeric_abs (obj_val), pdata->amount);
|
||||
|
||||
switch (pd->how) {
|
||||
switch (pd->how)
|
||||
{
|
||||
case QOF_COMPARE_LT:
|
||||
return (compare < 0);
|
||||
case QOF_COMPARE_LTE:
|
||||
@ -570,7 +584,8 @@ guid_match_predicate (gpointer object, QofParam *getter,
|
||||
|
||||
VERIFY_PREDICATE (query_guid_type);
|
||||
|
||||
switch (pdata->options) {
|
||||
switch (pdata->options)
|
||||
{
|
||||
|
||||
case QOF_GUID_MATCH_ALL:
|
||||
/* object is a GList of objects; param_getfcn must be called on each one.
|
||||
@ -651,7 +666,8 @@ guid_match_predicate (gpointer object, QofParam *getter,
|
||||
}
|
||||
}
|
||||
|
||||
switch (pdata->options) {
|
||||
switch (pdata->options)
|
||||
{
|
||||
case QOF_GUID_MATCH_ANY:
|
||||
case QOF_GUID_MATCH_LIST_ANY:
|
||||
return (node != NULL);
|
||||
@ -745,7 +761,8 @@ int32_match_predicate (gpointer object, QofParam *getter,
|
||||
|
||||
val = ((query_int32_getter)getter->param_getfcn) (object, getter);
|
||||
|
||||
switch (pd->how) {
|
||||
switch (pd->how)
|
||||
{
|
||||
case QOF_COMPARE_LT:
|
||||
return (val < pdata->val);
|
||||
case QOF_COMPARE_LTE:
|
||||
@ -836,7 +853,8 @@ int64_match_predicate (gpointer object, QofParam *getter,
|
||||
|
||||
val = ((query_int64_getter)getter->param_getfcn) (object, getter);
|
||||
|
||||
switch (pd->how) {
|
||||
switch (pd->how)
|
||||
{
|
||||
case QOF_COMPARE_LT:
|
||||
return (val < pdata->val);
|
||||
case QOF_COMPARE_LTE:
|
||||
@ -927,7 +945,8 @@ double_match_predicate (gpointer object, QofParam *getter,
|
||||
|
||||
val = ((query_double_getter)getter->param_getfcn) (object, getter);
|
||||
|
||||
switch (pd->how) {
|
||||
switch (pd->how)
|
||||
{
|
||||
case QOF_COMPARE_LT:
|
||||
return (val < pdata->val);
|
||||
case QOF_COMPARE_LTE:
|
||||
@ -1017,7 +1036,8 @@ boolean_match_predicate (gpointer object, QofParam *getter,
|
||||
|
||||
val = ((query_boolean_getter)getter->param_getfcn) (object, getter);
|
||||
|
||||
switch (pd->how) {
|
||||
switch (pd->how)
|
||||
{
|
||||
case QOF_COMPARE_EQUAL:
|
||||
return (val == pdata->val);
|
||||
case QOF_COMPARE_NEQ:
|
||||
@ -1100,7 +1120,8 @@ char_match_predicate (gpointer object, QofParam *getter,
|
||||
|
||||
c = ((query_char_getter)getter->param_getfcn) (object, getter);
|
||||
|
||||
switch (pdata->options) {
|
||||
switch (pdata->options)
|
||||
{
|
||||
case QOF_CHAR_MATCH_ANY:
|
||||
if (strchr (pdata->char_list, c)) return 1;
|
||||
return 0;
|
||||
@ -1303,7 +1324,11 @@ qof_query_kvp_predicate_path (QofQueryCompare how,
|
||||
{
|
||||
spath = g_slist_append (spath, p);
|
||||
p = strchr (p, '/');
|
||||
if (p) { *p = 0; p++; }
|
||||
if (p)
|
||||
{
|
||||
*p = 0;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
pd = qof_query_kvp_predicate (how, spath, value);
|
||||
@ -1327,66 +1352,80 @@ collect_match_predicate (gpointer object, QofParam *getter,
|
||||
VERIFY_PREDICATE (query_collect_type);
|
||||
coll = ((query_collect_getter)getter->param_getfcn) (object, getter);
|
||||
guid = NULL;
|
||||
switch(pdata->options) {
|
||||
case QOF_GUID_MATCH_ALL : {
|
||||
switch (pdata->options)
|
||||
{
|
||||
case QOF_GUID_MATCH_ALL :
|
||||
{
|
||||
for (node = pdata->guids; node; node = node->next)
|
||||
{
|
||||
for (o_list = object; o_list; o_list = o_list->next)
|
||||
{
|
||||
guid = ((query_guid_getter)getter->param_getfcn)
|
||||
(o_list->data, getter);
|
||||
if (guid_equal (node->data, guid)) {
|
||||
if (guid_equal (node->data, guid))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (o_list == NULL) {
|
||||
if (o_list == NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QOF_GUID_MATCH_LIST_ANY : {
|
||||
case QOF_GUID_MATCH_LIST_ANY :
|
||||
{
|
||||
o_list = ((query_glist_getter)getter->param_getfcn) (object, getter);
|
||||
for (node = o_list; node; node = node->next)
|
||||
{
|
||||
for (node2 = pdata->guids; node2; node2 = node2->next)
|
||||
{
|
||||
if (guid_equal (node->data, node2->data)) {
|
||||
if (guid_equal (node->data, node2->data))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (node2 != NULL) {
|
||||
if (node2 != NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_list_free(o_list);
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
default :
|
||||
{
|
||||
guid = ((query_guid_getter)getter->param_getfcn) (object, getter);
|
||||
for (node = pdata->guids; node; node = node->next)
|
||||
{
|
||||
if (guid_equal (node->data, guid)) {
|
||||
if (guid_equal (node->data, guid))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (pdata->options) {
|
||||
switch (pdata->options)
|
||||
{
|
||||
case QOF_GUID_MATCH_ANY :
|
||||
case QOF_GUID_MATCH_LIST_ANY : {
|
||||
case QOF_GUID_MATCH_LIST_ANY :
|
||||
{
|
||||
return (node != NULL);
|
||||
break;
|
||||
}
|
||||
case QOF_GUID_MATCH_NONE :
|
||||
case QOF_GUID_MATCH_ALL : {
|
||||
case QOF_GUID_MATCH_ALL :
|
||||
{
|
||||
return (node == NULL);
|
||||
break;
|
||||
}
|
||||
case QOF_GUID_MATCH_NULL : {
|
||||
case QOF_GUID_MATCH_NULL :
|
||||
{
|
||||
return ((guid == NULL) || guid_equal(guid, guid_null()));
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
default :
|
||||
{
|
||||
PWARN ("bad match type");
|
||||
return 0;
|
||||
}
|
||||
@ -1442,7 +1481,10 @@ collect_predicate_equal (const QofQueryPredData *p1, const QofQueryPredData *p2)
|
||||
gint result;
|
||||
|
||||
result = qof_collection_compare(pd1->coll, pd2->coll);
|
||||
if(result == 0) { return TRUE; }
|
||||
if (result == 0)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -1467,7 +1509,10 @@ qof_query_collect_predicate (QofGuidMatch options, QofCollection *coll)
|
||||
pdata->pd.type_name = query_collect_type;
|
||||
pdata->options = options;
|
||||
qof_collection_foreach(coll, query_collect_cb, pdata);
|
||||
if (NULL == pdata->guids) { return NULL; }
|
||||
if (NULL == pdata->guids)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return ((QofQueryPredData*)pdata);
|
||||
}
|
||||
|
||||
@ -1483,7 +1528,8 @@ choice_match_predicate (gpointer object, QofParam *getter,
|
||||
|
||||
VERIFY_PREDICATE (query_choice_type);
|
||||
|
||||
switch (pdata->options) {
|
||||
switch (pdata->options)
|
||||
{
|
||||
|
||||
case QOF_GUID_MATCH_ALL:
|
||||
/* object is a GList of objects; param_getfcn must be called on each one.
|
||||
@ -1553,7 +1599,8 @@ choice_match_predicate (gpointer object, QofParam *getter,
|
||||
}
|
||||
}
|
||||
|
||||
switch (pdata->options) {
|
||||
switch (pdata->options)
|
||||
{
|
||||
case QOF_GUID_MATCH_ANY:
|
||||
case QOF_GUID_MATCH_LIST_ANY:
|
||||
return (node != NULL);
|
||||
|
@ -47,7 +47,8 @@ typedef struct _QofQueryPredData QofQueryPredData;
|
||||
/** Standard Query comparitors, for how to compare objects in a predicate.
|
||||
* Note that not all core types implement all comparitors
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
QOF_COMPARE_LT = 1,
|
||||
QOF_COMPARE_LTE,
|
||||
QOF_COMPARE_EQUAL,
|
||||
@ -60,7 +61,8 @@ typedef enum {
|
||||
* Each core query type defines it's set of optional "comparitor qualifiers".
|
||||
*/
|
||||
/* Comparisons for QOF_TYPE_STRING */
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
QOF_STRING_MATCH_NORMAL = 1,
|
||||
QOF_STRING_MATCH_CASEINSENSITIVE
|
||||
} QofStringMatch;
|
||||
@ -72,7 +74,8 @@ typedef enum {
|
||||
* down to the second.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
QOF_DATE_MATCH_NORMAL = 1,
|
||||
QOF_DATE_MATCH_DAY
|
||||
} QofDateMatch;
|
||||
@ -89,14 +92,16 @@ typedef enum {
|
||||
* debit' predicate is equivalent to (amount <= 0) && (abs(amount) 'op' value)
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
QOF_NUMERIC_MATCH_DEBIT = 1,
|
||||
QOF_NUMERIC_MATCH_CREDIT,
|
||||
QOF_NUMERIC_MATCH_ANY
|
||||
} QofNumericMatch;
|
||||
|
||||
/* Comparisons for QOF_TYPE_GUID */
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
/** These expect a single object and expect the
|
||||
* QofAccessFunc returns GUID* */
|
||||
QOF_GUID_MATCH_ANY = 1,
|
||||
@ -118,7 +123,8 @@ typedef enum {
|
||||
* Match 'NONE' is equivalent to
|
||||
* (value != char1) && (value != char2) && etc.
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
QOF_CHAR_MATCH_ANY = 1,
|
||||
QOF_CHAR_MATCH_NONE
|
||||
} QofCharMatch;
|
||||
@ -128,7 +134,8 @@ typedef enum {
|
||||
*/
|
||||
|
||||
/** Head of Predicate Data structures. All PData must start like this. */
|
||||
struct _QofQueryPredData {
|
||||
struct _QofQueryPredData
|
||||
{
|
||||
QofType type_name; /* QOF_TYPE_* */
|
||||
QofQueryCompare how;
|
||||
};
|
||||
|
@ -52,7 +52,10 @@ entity_set_reference_cb(QofInstance *ent, gpointer user_data)
|
||||
book_ref_list = g_list_next(book_ref_list);
|
||||
continue;
|
||||
}
|
||||
if(qof_object_is_choice(ent->e_type)) { type = ref->choice_type; }
|
||||
if (qof_object_is_choice(ent->e_type))
|
||||
{
|
||||
type = ref->choice_type;
|
||||
}
|
||||
type = ref->param->param_type;
|
||||
coll = qof_book_get_collection(partial_book, type);
|
||||
reference = qof_collection_lookup_entity(coll, ref->ref_guid);
|
||||
@ -80,11 +83,15 @@ entity_set_reference_cb(QofInstance *ent, gpointer user_data)
|
||||
qof_collection_get_type(temp_col));
|
||||
guid_to_string_buff(ref->ref_guid, cm_sa);
|
||||
reference = qof_collection_lookup_entity(coll, ref->ref_guid);
|
||||
if(reference) {
|
||||
if (reference)
|
||||
{
|
||||
qof_collection_add_entity(temp_col, reference);
|
||||
qof_begin_edit((QofInstance*)ent);
|
||||
qof_begin_edit((QofInstance*)reference);
|
||||
if(collect_setter) { collect_setter(ent, temp_col); }
|
||||
if (collect_setter)
|
||||
{
|
||||
collect_setter(ent, temp_col);
|
||||
}
|
||||
qof_commit_edit((QofInstance*)ent);
|
||||
qof_commit_edit((QofInstance*)reference);
|
||||
qof_collection_destroy(temp_col);
|
||||
@ -96,7 +103,10 @@ entity_set_reference_cb(QofInstance *ent, gpointer user_data)
|
||||
reference = qof_collection_lookup_entity(coll, ref->ref_guid);
|
||||
qof_begin_edit((QofInstance*)ent);
|
||||
qof_begin_edit((QofInstance*)reference);
|
||||
if(choice_setter) { choice_setter(ent, reference); }
|
||||
if (choice_setter)
|
||||
{
|
||||
choice_setter(ent, reference);
|
||||
}
|
||||
qof_commit_edit((QofInstance*)ent);
|
||||
qof_commit_edit((QofInstance*)reference);
|
||||
}
|
||||
@ -124,7 +134,10 @@ create_reference(QofInstance *ent, const QofParam *param)
|
||||
|
||||
g_return_val_if_fail(ent, NULL);
|
||||
ref_ent = QOF_INSTANCE(param->param_getfcn(ent, param));
|
||||
if(!ref_ent) { return NULL; }
|
||||
if (!ref_ent)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
reference = g_new0(QofInstanceReference, 1);
|
||||
reference->type = ent->e_type;
|
||||
reference->ref_guid = g_new(GUID, 1);
|
||||
@ -137,7 +150,8 @@ create_reference(QofInstance *ent, const QofParam *param)
|
||||
cm_guid = qof_instance_get_guid(ref_ent);
|
||||
guid_to_string_buff(cm_guid, cm_sa);
|
||||
cm_string = g_strdup(cm_sa);
|
||||
if(TRUE == string_to_guid(cm_string, reference->ref_guid)) {
|
||||
if (TRUE == string_to_guid(cm_string, reference->ref_guid))
|
||||
{
|
||||
g_free(cm_string);
|
||||
return reference;
|
||||
}
|
||||
|
@ -102,7 +102,8 @@ It is used by the entity copy functions and by the QSF backend.
|
||||
Creates a GList stored in the Book hashtable to contain
|
||||
repeated references for a single entity.
|
||||
*/
|
||||
typedef struct qof_instance_reference {
|
||||
typedef struct qof_instance_reference
|
||||
{
|
||||
QofIdType choice_type;/**< Used when the reference is a QOF_TYPE_CHOICE type
|
||||
- stores the actual type of the reference from the list of available choices. */
|
||||
QofIdType type; /**< The type of the original entity -
|
||||
|
@ -69,7 +69,8 @@ qof_backend_get_registered_access_method_list(void)
|
||||
GList* list = NULL;
|
||||
GSList* node;
|
||||
|
||||
for( node = provider_list; node != NULL; node = node->next ) {
|
||||
for ( node = provider_list; node != NULL; node = node->next )
|
||||
{
|
||||
QofBackendProvider *prov = node->data;
|
||||
list = g_list_append( list, (gchar*)prov->access_method );
|
||||
}
|
||||
@ -86,7 +87,8 @@ qof_session_add_close_hook (GFunc fn, gpointer data)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
if (session_closed_hooks == NULL) {
|
||||
if (session_closed_hooks == NULL)
|
||||
{
|
||||
session_closed_hooks = malloc(sizeof(GHookList)); /* LEAKED */
|
||||
g_hook_list_init (session_closed_hooks, sizeof(GHook));
|
||||
}
|
||||
@ -110,7 +112,8 @@ qof_session_call_close_hooks (QofSession *session)
|
||||
return;
|
||||
|
||||
hook = g_hook_first_valid (session_closed_hooks, FALSE);
|
||||
while (hook) {
|
||||
while (hook)
|
||||
{
|
||||
fn = (GFunc)hook->func;
|
||||
fn(session, hook->data);
|
||||
hook = g_hook_next_valid (session_closed_hooks, hook, FALSE);
|
||||
@ -135,7 +138,8 @@ qof_session_clear_error (QofSession *session)
|
||||
do
|
||||
{
|
||||
err = qof_backend_get_error (session->backend);
|
||||
} while (ERR_BACKEND_NO_ERR != err);
|
||||
}
|
||||
while (ERR_BACKEND_NO_ERR != err);
|
||||
}
|
||||
}
|
||||
|
||||
@ -333,7 +337,8 @@ qof_session_ensure_all_data_loaded (QofSession *session)
|
||||
|
||||
/* =============================================================== */
|
||||
|
||||
typedef struct qof_instance_copy_data {
|
||||
typedef struct qof_instance_copy_data
|
||||
{
|
||||
QofInstance *from;
|
||||
QofInstance *to;
|
||||
QofParam *param;
|
||||
@ -350,7 +355,8 @@ qof_book_set_partial(QofBook *book)
|
||||
|
||||
partial =
|
||||
(gboolean)GPOINTER_TO_INT(qof_book_get_data(book, PARTIAL_QOFBOOK));
|
||||
if(!partial) {
|
||||
if (!partial)
|
||||
{
|
||||
qof_book_set_data(book, PARTIAL_QOFBOOK, GINT_TO_POINTER(TRUE));
|
||||
}
|
||||
}
|
||||
@ -377,11 +383,13 @@ qof_instance_param_cb(QofParam *param, gpointer data)
|
||||
qecd = (QofInstanceCopyData*)data;
|
||||
g_return_if_fail(param != NULL);
|
||||
/* KVP doesn't need a set routine to be copied. */
|
||||
if(0 == safe_strcmp(param->param_type, QOF_TYPE_KVP)) {
|
||||
if (0 == safe_strcmp(param->param_type, QOF_TYPE_KVP))
|
||||
{
|
||||
qecd->param_list = g_slist_prepend(qecd->param_list, param);
|
||||
return;
|
||||
}
|
||||
if((param->param_getfcn != NULL)&&(param->param_setfcn != NULL)) {
|
||||
if ((param->param_getfcn != NULL) && (param->param_setfcn != NULL))
|
||||
{
|
||||
qecd->param_list = g_slist_prepend(qecd->param_list, param);
|
||||
}
|
||||
}
|
||||
@ -409,7 +417,8 @@ col_ref_cb (QofInstance* ref_ent, gpointer user_data)
|
||||
cm_guid = qof_entity_get_guid(ref_ent);
|
||||
guid_to_string_buff(cm_guid, cm_sa);
|
||||
cm_string = g_strdup(cm_sa);
|
||||
if(TRUE == string_to_guid(cm_string, ref->ref_guid)) {
|
||||
if (TRUE == string_to_guid(cm_string, ref->ref_guid))
|
||||
{
|
||||
g_free(cm_string);
|
||||
qof_session_update_reference_list(qecd->new_session, ref);
|
||||
}
|
||||
@ -457,67 +466,104 @@ qof_instance_foreach_copy(gpointer data, gpointer user_data)
|
||||
cm_param = (QofParam*) data;
|
||||
g_return_if_fail(cm_param != NULL);
|
||||
context->param = cm_param;
|
||||
if(safe_strcmp(cm_param->param_type, QOF_TYPE_STRING) == 0) {
|
||||
if (safe_strcmp(cm_param->param_type, QOF_TYPE_STRING) == 0)
|
||||
{
|
||||
cm_string = (gchar*)cm_param->param_getfcn(importEnt, cm_param);
|
||||
if(cm_string) {
|
||||
if (cm_string)
|
||||
{
|
||||
string_setter = (void(*)(QofInstance*, const char*))cm_param->param_setfcn;
|
||||
if(string_setter != NULL) { string_setter(targetEnt, cm_string); }
|
||||
if (string_setter != NULL)
|
||||
{
|
||||
string_setter(targetEnt, cm_string);
|
||||
}
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(cm_param->param_type, QOF_TYPE_DATE) == 0) {
|
||||
if (safe_strcmp(cm_param->param_type, QOF_TYPE_DATE) == 0)
|
||||
{
|
||||
date_getter = (Timespec (*)(QofInstance*, QofParam*))cm_param->param_getfcn;
|
||||
cm_date = date_getter(importEnt, cm_param);
|
||||
date_setter = (void(*)(QofInstance*, Timespec))cm_param->param_setfcn;
|
||||
if(date_setter != NULL) { date_setter(targetEnt, cm_date); }
|
||||
if (date_setter != NULL)
|
||||
{
|
||||
date_setter(targetEnt, cm_date);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if ((safe_strcmp(cm_param->param_type, QOF_TYPE_NUMERIC) == 0) ||
|
||||
(safe_strcmp(cm_param->param_type, QOF_TYPE_DEBCRED) == 0)) {
|
||||
(safe_strcmp(cm_param->param_type, QOF_TYPE_DEBCRED) == 0))
|
||||
{
|
||||
numeric_getter = (gnc_numeric (*)(QofInstance*, QofParam*))cm_param->param_getfcn;
|
||||
cm_numeric = numeric_getter(importEnt, cm_param);
|
||||
numeric_setter = (void(*)(QofInstance*, gnc_numeric))cm_param->param_setfcn;
|
||||
if(numeric_setter != NULL) { numeric_setter(targetEnt, cm_numeric); }
|
||||
if (numeric_setter != NULL)
|
||||
{
|
||||
numeric_setter(targetEnt, cm_numeric);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(cm_param->param_type, QOF_TYPE_GUID) == 0) {
|
||||
if (safe_strcmp(cm_param->param_type, QOF_TYPE_GUID) == 0)
|
||||
{
|
||||
cm_guid = (const GUID*)cm_param->param_getfcn(importEnt, cm_param);
|
||||
guid_setter = (void(*)(QofInstance*, const GUID*))cm_param->param_setfcn;
|
||||
if(guid_setter != NULL) { guid_setter(targetEnt, cm_guid); }
|
||||
if (guid_setter != NULL)
|
||||
{
|
||||
guid_setter(targetEnt, cm_guid);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(cm_param->param_type, QOF_TYPE_INT32) == 0) {
|
||||
if (safe_strcmp(cm_param->param_type, QOF_TYPE_INT32) == 0)
|
||||
{
|
||||
int32_getter = (gint32 (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
|
||||
cm_i32 = int32_getter(importEnt, cm_param);
|
||||
i32_setter = (void(*)(QofInstance*, gint32))cm_param->param_setfcn;
|
||||
if(i32_setter != NULL) { i32_setter(targetEnt, cm_i32); }
|
||||
if (i32_setter != NULL)
|
||||
{
|
||||
i32_setter(targetEnt, cm_i32);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(cm_param->param_type, QOF_TYPE_INT64) == 0) {
|
||||
if (safe_strcmp(cm_param->param_type, QOF_TYPE_INT64) == 0)
|
||||
{
|
||||
int64_getter = (gint64 (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
|
||||
cm_i64 = int64_getter(importEnt, cm_param);
|
||||
i64_setter = (void(*)(QofInstance*, gint64))cm_param->param_setfcn;
|
||||
if(i64_setter != NULL) { i64_setter(targetEnt, cm_i64); }
|
||||
if (i64_setter != NULL)
|
||||
{
|
||||
i64_setter(targetEnt, cm_i64);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(cm_param->param_type, QOF_TYPE_DOUBLE) == 0) {
|
||||
if (safe_strcmp(cm_param->param_type, QOF_TYPE_DOUBLE) == 0)
|
||||
{
|
||||
double_getter = (double (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
|
||||
cm_double = double_getter(importEnt, cm_param);
|
||||
double_setter = (void(*)(QofInstance*, double))cm_param->param_setfcn;
|
||||
if(double_setter != NULL) { double_setter(targetEnt, cm_double); }
|
||||
if (double_setter != NULL)
|
||||
{
|
||||
double_setter(targetEnt, cm_double);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(cm_param->param_type, QOF_TYPE_BOOLEAN) == 0){
|
||||
if (safe_strcmp(cm_param->param_type, QOF_TYPE_BOOLEAN) == 0)
|
||||
{
|
||||
boolean_getter = (gboolean (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
|
||||
cm_boolean = boolean_getter(importEnt, cm_param);
|
||||
boolean_setter = (void(*)(QofInstance*, gboolean))cm_param->param_setfcn;
|
||||
if(boolean_setter != NULL) { boolean_setter(targetEnt, cm_boolean); }
|
||||
if (boolean_setter != NULL)
|
||||
{
|
||||
boolean_setter(targetEnt, cm_boolean);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(cm_param->param_type, QOF_TYPE_KVP) == 0) {
|
||||
if (safe_strcmp(cm_param->param_type, QOF_TYPE_KVP) == 0)
|
||||
{
|
||||
cm_kvp = (KvpFrame*)cm_param->param_getfcn(importEnt, cm_param);
|
||||
kvp_frame_setter = (void(*)(QofInstance*, KvpFrame*))cm_param->param_setfcn;
|
||||
if(kvp_frame_setter != NULL) { kvp_frame_setter(targetEnt, cm_kvp); }
|
||||
if (kvp_frame_setter != NULL)
|
||||
{
|
||||
kvp_frame_setter(targetEnt, cm_kvp);
|
||||
}
|
||||
else
|
||||
{
|
||||
QofInstance *target_inst;
|
||||
@ -528,13 +574,18 @@ qof_instance_foreach_copy(gpointer data, gpointer user_data)
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(cm_param->param_type, QOF_TYPE_CHAR) == 0) {
|
||||
if (safe_strcmp(cm_param->param_type, QOF_TYPE_CHAR) == 0)
|
||||
{
|
||||
cm_char = (gchar*)cm_param->param_getfcn(importEnt, cm_param);
|
||||
char_setter = (void(*)(QofInstance*, char*))cm_param->param_setfcn;
|
||||
if(char_setter != NULL) { char_setter(targetEnt, cm_char); }
|
||||
if (char_setter != NULL)
|
||||
{
|
||||
char_setter(targetEnt, cm_char);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(cm_param->param_type, QOF_TYPE_COLLECT) == 0) {
|
||||
if (safe_strcmp(cm_param->param_type, QOF_TYPE_COLLECT) == 0)
|
||||
{
|
||||
cm_col = (QofCollection*)cm_param->param_getfcn(importEnt, cm_param);
|
||||
if (cm_col)
|
||||
{
|
||||
@ -543,12 +594,14 @@ qof_instance_foreach_copy(gpointer data, gpointer user_data)
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(registered_type == FALSE) {
|
||||
if (registered_type == FALSE)
|
||||
{
|
||||
/* referenceEnt = QOF_INSTANCE(cm_param->param_getfcn(importEnt, cm_param));
|
||||
if(!referenceEnt) { return; }
|
||||
if(!referenceEnt->e_type) { return; }*/
|
||||
reference = qof_instance_get_reference_from(importEnt, cm_param);
|
||||
if(reference) {
|
||||
if (reference)
|
||||
{
|
||||
qof_session_update_reference_list(context->new_session, reference);
|
||||
}
|
||||
}
|
||||
@ -571,7 +624,10 @@ qof_instance_guid_match(QofSession *new_session, QofInstance *original)
|
||||
type = g_strdup(original->e_type);
|
||||
coll = qof_book_get_collection(targetBook, type);
|
||||
copy = qof_collection_lookup_entity(coll, g);
|
||||
if(copy) { return TRUE; }
|
||||
if (copy)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -588,7 +644,10 @@ qof_instance_list_foreach(gpointer data, gpointer user_data)
|
||||
original = QOF_INSTANCE(data);
|
||||
g_return_if_fail(user_data != NULL);
|
||||
qecd = (QofInstanceCopyData*)user_data;
|
||||
if(qof_instance_guid_match(qecd->new_session, original)) { return; }
|
||||
if (qof_instance_guid_match(qecd->new_session, original))
|
||||
{
|
||||
return;
|
||||
}
|
||||
qecd->from = original;
|
||||
if (!qof_object_compliance(original->e_type, FALSE))
|
||||
{
|
||||
@ -606,7 +665,8 @@ qof_instance_list_foreach(gpointer data, gpointer user_data)
|
||||
qecd->to = inst;
|
||||
g = qof_instance_get_guid(original);
|
||||
qof_instance_set_guid(qecd->to, g);
|
||||
if(qecd->param_list != NULL) {
|
||||
if (qecd->param_list != NULL)
|
||||
{
|
||||
g_slist_free(qecd->param_list);
|
||||
qecd->param_list = NULL;
|
||||
}
|
||||
@ -633,7 +693,10 @@ qof_instance_coll_foreach(QofInstance *original, gpointer user_data)
|
||||
g = qof_instance_get_guid(original);
|
||||
coll = qof_book_get_collection(targetBook, original->e_type);
|
||||
copy = qof_collection_lookup_entity(coll, g);
|
||||
if(copy) { qecd->error = TRUE; }
|
||||
if (copy)
|
||||
{
|
||||
qecd->error = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -648,7 +711,10 @@ qof_instance_coll_copy(QofInstance *original, gpointer user_data)
|
||||
g_return_if_fail(user_data != NULL);
|
||||
qecd = (QofInstanceCopyData*)user_data;
|
||||
book = qof_session_get_book(qecd->new_session);
|
||||
if(!qof_object_compliance(original->e_type, TRUE)) { return; }
|
||||
if (!qof_object_compliance(original->e_type, TRUE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
inst = (QofInstance*)qof_object_new_instance(original->e_type, book);
|
||||
qecd->to = inst;
|
||||
qecd->from = original;
|
||||
@ -666,9 +732,18 @@ qof_instance_copy_to_session(QofSession* new_session, QofInstance* original)
|
||||
QofInstance *inst;
|
||||
QofBook *book;
|
||||
|
||||
if(!new_session || !original) { return FALSE; }
|
||||
if(qof_instance_guid_match(new_session, original)) { return FALSE; }
|
||||
if(!qof_object_compliance(original->e_type, TRUE)) { return FALSE; }
|
||||
if (!new_session || !original)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (qof_instance_guid_match(new_session, original))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (!qof_object_compliance(original->e_type, TRUE))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
qof_event_suspend();
|
||||
qecd.param_list = NULL;
|
||||
book = qof_session_get_book(new_session);
|
||||
@ -681,7 +756,10 @@ qof_instance_copy_to_session(QofSession* new_session, QofInstance* original)
|
||||
qof_begin_edit(inst);
|
||||
qof_class_param_foreach(original->e_type, qof_instance_param_cb, &qecd);
|
||||
qof_commit_edit(inst);
|
||||
if(g_slist_length(qecd.param_list) == 0) { return FALSE; }
|
||||
if (g_slist_length(qecd.param_list) == 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
g_slist_foreach(qecd.param_list, qof_instance_foreach_copy, &qecd);
|
||||
g_slist_free(qecd.param_list);
|
||||
qof_event_resume();
|
||||
@ -692,7 +770,10 @@ gboolean qof_instance_copy_list(QofSession *new_session, GList *entity_list)
|
||||
{
|
||||
QofInstanceCopyData *qecd;
|
||||
|
||||
if(!new_session || !entity_list) { return FALSE; }
|
||||
if (!new_session || !entity_list)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
ENTER (" list=%d", g_list_length(entity_list));
|
||||
qecd = g_new0(QofInstanceCopyData, 1);
|
||||
qof_event_suspend();
|
||||
@ -716,7 +797,10 @@ qof_instance_copy_coll(QofSession *new_session, QofCollection *entity_coll)
|
||||
QofInstanceCopyData qecd;
|
||||
|
||||
g_return_val_if_fail(new_session, FALSE);
|
||||
if(!entity_coll) { return FALSE; }
|
||||
if (!entity_coll)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
qof_event_suspend();
|
||||
qecd.param_list = NULL;
|
||||
qecd.new_session = new_session;
|
||||
@ -725,7 +809,10 @@ qof_instance_copy_coll(QofSession *new_session, QofCollection *entity_coll)
|
||||
qof_class_param_foreach(qof_collection_get_type(entity_coll),
|
||||
qof_instance_param_cb, &qecd);
|
||||
qof_collection_foreach(entity_coll, qof_instance_coll_copy, &qecd);
|
||||
if(qecd.param_list != NULL) { g_slist_free(qecd.param_list); }
|
||||
if (qecd.param_list != NULL)
|
||||
{
|
||||
g_slist_free(qecd.param_list);
|
||||
}
|
||||
qof_event_resume();
|
||||
return TRUE;
|
||||
}
|
||||
@ -743,11 +830,18 @@ recurse_collection_cb (QofInstance *ent, gpointer user_data)
|
||||
{
|
||||
struct recurse_s *store;
|
||||
|
||||
if(user_data == NULL) { return; }
|
||||
if (user_data == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
store = (struct recurse_s*)user_data;
|
||||
if(!ent || !store) { return; }
|
||||
if (!ent || !store)
|
||||
{
|
||||
return;
|
||||
}
|
||||
store->success = qof_instance_copy_to_session(store->session, ent);
|
||||
if(store->success) {
|
||||
if (store->success)
|
||||
{
|
||||
store->ent_list = g_list_append(store->ent_list, ent);
|
||||
}
|
||||
}
|
||||
@ -762,28 +856,42 @@ recurse_ent_cb(QofInstance *ent, gpointer user_data)
|
||||
struct recurse_s *store;
|
||||
gboolean success;
|
||||
|
||||
if(user_data == NULL) { return; }
|
||||
if (user_data == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
store = (struct recurse_s*)user_data;
|
||||
session = store->session;
|
||||
success = store->success;
|
||||
ref_list = NULL;
|
||||
child_ent = NULL;
|
||||
ref_list = g_list_copy(store->ref_list);
|
||||
if((!session)||(!ent)) { return; }
|
||||
if ((!session) || (!ent))
|
||||
{
|
||||
return;
|
||||
}
|
||||
ent_list = NULL;
|
||||
child_list = NULL;
|
||||
i = NULL;
|
||||
j = NULL;
|
||||
for (i = ref_list; i != NULL; i = i->next)
|
||||
{
|
||||
if(i->data == NULL) { continue; }
|
||||
if (i->data == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ref_param = (QofParam*)i->data;
|
||||
if(ref_param->param_name == NULL) { continue; }
|
||||
if(0 == safe_strcmp(ref_param->param_type, QOF_TYPE_COLLECT)) {
|
||||
if (ref_param->param_name == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (0 == safe_strcmp(ref_param->param_type, QOF_TYPE_COLLECT))
|
||||
{
|
||||
QofCollection *col;
|
||||
|
||||
col = ref_param->param_getfcn(ent, ref_param);
|
||||
if(col) {
|
||||
if (col)
|
||||
{
|
||||
qof_collection_foreach(col, recurse_collection_cb, store);
|
||||
}
|
||||
continue;
|
||||
@ -792,36 +900,60 @@ recurse_ent_cb(QofInstance *ent, gpointer user_data)
|
||||
if ((ref_ent) && (ref_ent->e_type))
|
||||
{
|
||||
store->success = qof_instance_copy_to_session(session, ref_ent);
|
||||
if(store->success) { ent_list = g_list_append(ent_list, ref_ent); }
|
||||
if (store->success)
|
||||
{
|
||||
ent_list = g_list_append(ent_list, ref_ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = ent_list; i != NULL; i = i->next)
|
||||
{
|
||||
if(i->data == NULL) { continue; }
|
||||
if (i->data == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
child_ent = QOF_INSTANCE(i->data);
|
||||
if(child_ent == NULL) { continue; }
|
||||
if (child_ent == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ref_list = qof_class_get_referenceList(child_ent->e_type);
|
||||
for (j = ref_list; j != NULL; j = j->next)
|
||||
{
|
||||
if(j->data == NULL) { continue; }
|
||||
if (j->data == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ref_param = (QofParam*)j->data;
|
||||
ref_ent = ref_param->param_getfcn(child_ent, ref_param);
|
||||
if (ref_ent != NULL)
|
||||
{
|
||||
success = qof_instance_copy_to_session(session, ref_ent);
|
||||
if(success) { child_list = g_list_append(child_list, ref_ent); }
|
||||
if (success)
|
||||
{
|
||||
child_list = g_list_append(child_list, ref_ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = child_list; i != NULL; i = i->next)
|
||||
{
|
||||
if(i->data == NULL) { continue; }
|
||||
if (i->data == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ref_ent = QOF_INSTANCE(i->data);
|
||||
if(ref_ent == NULL) { continue; }
|
||||
if (ref_ent == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ref_list = qof_class_get_referenceList(ref_ent->e_type);
|
||||
for (j = ref_list; j != NULL; j = j->next)
|
||||
{
|
||||
if(j->data == NULL) { continue; }
|
||||
if (j->data == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ref_param = (QofParam*)j->data;
|
||||
child_ent = ref_param->param_getfcn(ref_ent, ref_param);
|
||||
if (child_ent != NULL)
|
||||
@ -838,14 +970,20 @@ qof_instance_copy_coll_r(QofSession *new_session, QofCollection *coll)
|
||||
struct recurse_s store;
|
||||
gboolean success;
|
||||
|
||||
if((!new_session)||(!coll)) { return FALSE; }
|
||||
if ((!new_session) || (!coll))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
store.session = new_session;
|
||||
success = TRUE;
|
||||
store.success = success;
|
||||
store.ent_list = NULL;
|
||||
store.ref_list = qof_class_get_referenceList(qof_collection_get_type(coll));
|
||||
success = qof_instance_copy_coll(new_session, coll);
|
||||
if(success){ qof_collection_foreach(coll, recurse_ent_cb, &store); }
|
||||
if (success)
|
||||
{
|
||||
qof_collection_foreach(coll, recurse_ent_cb, &store);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -855,15 +993,22 @@ gboolean qof_instance_copy_one_r(QofSession *new_session, QofInstance *ent)
|
||||
QofCollection *coll;
|
||||
gboolean success;
|
||||
|
||||
if((!new_session)||(!ent)) { return FALSE; }
|
||||
if ((!new_session) || (!ent))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
store.session = new_session;
|
||||
success = TRUE;
|
||||
store.success = success;
|
||||
store.ref_list = qof_class_get_referenceList(ent->e_type);
|
||||
success = qof_instance_copy_to_session(new_session, ent);
|
||||
if(success == TRUE) {
|
||||
if (success == TRUE)
|
||||
{
|
||||
coll = qof_book_get_collection(qof_session_get_book(new_session), ent->e_type);
|
||||
if(coll) { qof_collection_foreach(coll, recurse_ent_cb, &store); }
|
||||
if (coll)
|
||||
{
|
||||
qof_collection_foreach(coll, recurse_ent_cb, &store);
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@ -884,7 +1029,8 @@ struct backend_providers
|
||||
and the last entry must be two NULL's.
|
||||
Remember: Use the libdir from the current build environment
|
||||
and use JUST the module name without .so - .so is not portable! */
|
||||
struct backend_providers backend_list[] = {
|
||||
struct backend_providers backend_list[] =
|
||||
{
|
||||
{ QOF_LIB_DIR, QSF_BACKEND_LIB },
|
||||
#ifdef HAVE_DWI
|
||||
{ QOF_LIB_DIR, "libqof_backend_dwi"},
|
||||
@ -911,8 +1057,10 @@ qof_session_load_backend(QofSession * session, const char * access_method)
|
||||
if (!qof_providers_initialized)
|
||||
{
|
||||
libdir_from_env = g_strdup(g_getenv("QOF_LIB_DIR"));
|
||||
for (num = 0; backend_list[num].filename != NULL; num++) {
|
||||
if (libdir_from_env) {
|
||||
for (num = 0; backend_list[num].filename != NULL; num++)
|
||||
{
|
||||
if (libdir_from_env)
|
||||
{
|
||||
if (!(qof_load_backend_library(libdir_from_env,
|
||||
backend_list[num].filename)
|
||||
|| qof_load_backend_library(backend_list[num].libdir,
|
||||
@ -922,9 +1070,12 @@ qof_session_load_backend(QofSession * session, const char * access_method)
|
||||
backend_list[num].filename, libdir_from_env,
|
||||
backend_list[num].libdir);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!qof_load_backend_library(backend_list[num].libdir,
|
||||
backend_list[num].filename)) {
|
||||
backend_list[num].filename))
|
||||
{
|
||||
PWARN (" failed to load %s from %s",
|
||||
backend_list[num].filename, backend_list[num].libdir);
|
||||
}
|
||||
@ -943,9 +1094,11 @@ qof_session_load_backend(QofSession * session, const char * access_method)
|
||||
/* More than one backend could provide this
|
||||
access method, check file type compatibility. */
|
||||
type_check = (gboolean (*)(const char*)) prov->check_data_type;
|
||||
if (type_check) {
|
||||
if (type_check)
|
||||
{
|
||||
prov_type = (type_check)(session->book_id);
|
||||
if (!prov_type) {
|
||||
if (!prov_type)
|
||||
{
|
||||
PINFO(" %s not usable", prov->provider_name);
|
||||
p = p->next;
|
||||
continue;
|
||||
@ -1255,24 +1408,32 @@ qof_session_save (QofSession *session,
|
||||
book_id = g_strdup(session->book_id);
|
||||
if (partial == TRUE)
|
||||
{
|
||||
if(session->backend && session->backend->provider) {
|
||||
if (session->backend && session->backend->provider)
|
||||
{
|
||||
prov = session->backend->provider;
|
||||
if (TRUE == prov->partial_book_supported)
|
||||
{
|
||||
/* if current backend supports partial, leave alone. */
|
||||
change_backend = FALSE;
|
||||
}
|
||||
else { change_backend = TRUE; }
|
||||
else
|
||||
{
|
||||
change_backend = TRUE;
|
||||
}
|
||||
}
|
||||
/* If provider is undefined, assume partial not supported. */
|
||||
else { change_backend = TRUE; }
|
||||
else
|
||||
{
|
||||
change_backend = TRUE;
|
||||
}
|
||||
}
|
||||
if (change_backend == TRUE)
|
||||
{
|
||||
qof_session_destroy_backend(session);
|
||||
if (!qof_providers_initialized)
|
||||
{
|
||||
for (num = 0; backend_list[num].filename != NULL; num++) {
|
||||
for (num = 0; backend_list[num].filename != NULL; num++)
|
||||
{
|
||||
qof_load_backend_library(backend_list[num].libdir,
|
||||
backend_list[num].filename);
|
||||
}
|
||||
@ -1327,7 +1488,8 @@ qof_session_save (QofSession *session,
|
||||
}
|
||||
p = NULL;
|
||||
}
|
||||
if(p) {
|
||||
if (p)
|
||||
{
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
@ -1526,13 +1688,17 @@ qof_session_export (QofSession *tmp_session,
|
||||
return FALSE;
|
||||
|
||||
be->percentage = percentage_func;
|
||||
if (be->export) {
|
||||
if (be->export)
|
||||
{
|
||||
int err;
|
||||
|
||||
(be->export)(be, book);
|
||||
err = qof_backend_get_error(be);
|
||||
|
||||
if (ERR_BACKEND_NO_ERR != err) { return FALSE; }
|
||||
if (ERR_BACKEND_NO_ERR != err)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@ -267,12 +267,24 @@ handle_single_condition (QofSqlQuery *query, sql_condition * cond)
|
||||
/* Get the where-term comparison operator */
|
||||
switch (cond->op)
|
||||
{
|
||||
case SQL_eq: qop = QOF_COMPARE_EQUAL; break;
|
||||
case SQL_gt: qop = QOF_COMPARE_GT; break;
|
||||
case SQL_lt: qop = QOF_COMPARE_LT; break;
|
||||
case SQL_geq: qop = QOF_COMPARE_GTE; break;
|
||||
case SQL_leq: qop = QOF_COMPARE_LTE; break;
|
||||
case SQL_diff: qop = QOF_COMPARE_NEQ; break;
|
||||
case SQL_eq:
|
||||
qop = QOF_COMPARE_EQUAL;
|
||||
break;
|
||||
case SQL_gt:
|
||||
qop = QOF_COMPARE_GT;
|
||||
break;
|
||||
case SQL_lt:
|
||||
qop = QOF_COMPARE_LT;
|
||||
break;
|
||||
case SQL_geq:
|
||||
qop = QOF_COMPARE_GTE;
|
||||
break;
|
||||
case SQL_leq:
|
||||
qop = QOF_COMPARE_LTE;
|
||||
break;
|
||||
case SQL_diff:
|
||||
qop = QOF_COMPARE_NEQ;
|
||||
break;
|
||||
default:
|
||||
/* XXX for string-type queries, we should be able to
|
||||
* support 'IN' for substring search. Also regex. */
|
||||
@ -416,21 +428,18 @@ handle_single_condition (QofSqlQuery *query, sql_condition * cond)
|
||||
string_to_guid (str, &guid);
|
||||
kval = kvp_value_new_guid (&guid);
|
||||
}
|
||||
else
|
||||
if (len == strspn (str, "0123456789"))
|
||||
else if (len == strspn (str, "0123456789"))
|
||||
{
|
||||
kval = kvp_value_new_gint64 (atoll(str));
|
||||
}
|
||||
else
|
||||
if ((p=strchr (str, '.')) &&
|
||||
else if ((p = strchr (str, '.')) &&
|
||||
((len - 1) == (strspn (str, "0123456789") +
|
||||
strspn (p + 1, "0123456789"))))
|
||||
{
|
||||
kval = kvp_value_new_double (atof(str));
|
||||
}
|
||||
|
||||
else
|
||||
if ((p=strchr (str, '/')) &&
|
||||
else if ((p = strchr (str, '/')) &&
|
||||
((len - 1) == (strspn (str, "0123456789") +
|
||||
strspn (p + 1, "0123456789"))))
|
||||
{
|
||||
@ -438,8 +447,7 @@ handle_single_condition (QofSqlQuery *query, sql_condition * cond)
|
||||
string_to_gnc_numeric (str, &num);
|
||||
kval = kvp_value_new_gnc_numeric (num);
|
||||
}
|
||||
else
|
||||
if ((p=strchr (str, '-')) &&
|
||||
else if ((p = strchr (str, '-')) &&
|
||||
(p = strchr (p + 1, '-')) &&
|
||||
(p = strchr (p + 1, ' ')) &&
|
||||
(p = strchr (p + 1, ':')) &&
|
||||
@ -484,8 +492,12 @@ handle_where (QofSqlQuery *query, sql_where *swear)
|
||||
if (NULL == qright) return qleft;
|
||||
switch (swear->d.pair.op)
|
||||
{
|
||||
case SQL_and: qop = QOF_QUERY_AND; break;
|
||||
case SQL_or: qop = QOF_QUERY_OR; break;
|
||||
case SQL_and:
|
||||
qop = QOF_QUERY_AND;
|
||||
break;
|
||||
case SQL_or:
|
||||
qop = QOF_QUERY_OR;
|
||||
break;
|
||||
/* XXX should add support for nand, nor, xor */
|
||||
default:
|
||||
qof_query_destroy (qleft);
|
||||
@ -605,25 +617,38 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
|
||||
|
||||
ENTER (" param=%s param_type=%s type=%s content=%s",
|
||||
param->param_name, param->param_type, type, insert_string);
|
||||
if(safe_strcmp(param->param_type, QOF_TYPE_STRING) == 0) {
|
||||
if (safe_strcmp(param->param_type, QOF_TYPE_STRING) == 0)
|
||||
{
|
||||
string_setter = (void(*)(QofInstance*, const char*))param->param_setfcn;
|
||||
if(string_setter != NULL) { string_setter(ent, insert_string); }
|
||||
if (string_setter != NULL)
|
||||
{
|
||||
string_setter(ent, insert_string);
|
||||
}
|
||||
registered_type = TRUE;
|
||||
}
|
||||
if(safe_strcmp(param->param_type, QOF_TYPE_DATE) == 0) {
|
||||
if (safe_strcmp(param->param_type, QOF_TYPE_DATE) == 0)
|
||||
{
|
||||
date_setter = (void(*)(QofInstance*, Timespec))param->param_setfcn;
|
||||
strptime(insert_string, QOF_UTC_DATE_FORMAT, &query_time);
|
||||
query_time_t = mktime(&query_time);
|
||||
timespecFromTime_t(&cm_date, query_time_t);
|
||||
if(date_setter != NULL) { date_setter(ent, cm_date); }
|
||||
if (date_setter != NULL)
|
||||
{
|
||||
date_setter(ent, cm_date);
|
||||
}
|
||||
}
|
||||
if ((safe_strcmp(param->param_type, QOF_TYPE_NUMERIC) == 0) ||
|
||||
(safe_strcmp(param->param_type, QOF_TYPE_DEBCRED) == 0)) {
|
||||
(safe_strcmp(param->param_type, QOF_TYPE_DEBCRED) == 0))
|
||||
{
|
||||
numeric_setter = (void(*)(QofInstance*, gnc_numeric))param->param_setfcn;
|
||||
string_to_gnc_numeric(insert_string, &cm_numeric);
|
||||
if(numeric_setter != NULL) { numeric_setter(ent, cm_numeric); }
|
||||
if (numeric_setter != NULL)
|
||||
{
|
||||
numeric_setter(ent, cm_numeric);
|
||||
}
|
||||
if(safe_strcmp(param->param_type, QOF_TYPE_GUID) == 0) {
|
||||
}
|
||||
if (safe_strcmp(param->param_type, QOF_TYPE_GUID) == 0)
|
||||
{
|
||||
cm_guid = g_new(GUID, 1);
|
||||
if (TRUE != string_to_guid(insert_string, cm_guid))
|
||||
{
|
||||
@ -642,12 +667,17 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
|
||||
}
|
||||
}*/
|
||||
}
|
||||
if(safe_strcmp(param->param_type, QOF_TYPE_INT32) == 0) {
|
||||
if (safe_strcmp(param->param_type, QOF_TYPE_INT32) == 0)
|
||||
{
|
||||
errno = 0;
|
||||
cm_i32 = (gint32)strtol (insert_string, &tail, 0);
|
||||
if(errno == 0) {
|
||||
if (errno == 0)
|
||||
{
|
||||
i32_setter = (void(*)(QofInstance*, gint32))param->param_setfcn;
|
||||
if(i32_setter != NULL) { i32_setter(ent, cm_i32); }
|
||||
if (i32_setter != NULL)
|
||||
{
|
||||
i32_setter(ent, cm_i32);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -659,12 +689,17 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
|
||||
qof_backend_set_error(backend, ERR_QSF_OVERFLOW);
|
||||
}
|
||||
}
|
||||
if(safe_strcmp(param->param_type, QOF_TYPE_INT64) == 0) {
|
||||
if (safe_strcmp(param->param_type, QOF_TYPE_INT64) == 0)
|
||||
{
|
||||
errno = 0;
|
||||
cm_i64 = strtoll(insert_string, &tail, 0);
|
||||
if(errno == 0) {
|
||||
if (errno == 0)
|
||||
{
|
||||
i64_setter = (void(*)(QofInstance*, gint64))param->param_setfcn;
|
||||
if(i64_setter != NULL) { i64_setter(ent, cm_i64); }
|
||||
if (i64_setter != NULL)
|
||||
{
|
||||
i64_setter(ent, cm_i64);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -676,31 +711,49 @@ qof_sql_insertCB(const QofParam *param, const gchar *insert_string, QofSqlQuery
|
||||
qof_backend_set_error(backend, ERR_QSF_OVERFLOW);
|
||||
}
|
||||
}
|
||||
if(safe_strcmp(param->param_type, QOF_TYPE_DOUBLE) == 0) {
|
||||
if (safe_strcmp(param->param_type, QOF_TYPE_DOUBLE) == 0)
|
||||
{
|
||||
errno = 0;
|
||||
cm_double = strtod(insert_string, &tail);
|
||||
if(errno == 0) {
|
||||
if (errno == 0)
|
||||
{
|
||||
double_setter = (void(*)(QofInstance*, double))param->param_setfcn;
|
||||
if(double_setter != NULL) { double_setter(ent, cm_double); }
|
||||
if (double_setter != NULL)
|
||||
{
|
||||
double_setter(ent, cm_double);
|
||||
}
|
||||
}
|
||||
if(safe_strcmp(param->param_type, QOF_TYPE_BOOLEAN) == 0) {
|
||||
}
|
||||
if (safe_strcmp(param->param_type, QOF_TYPE_BOOLEAN) == 0)
|
||||
{
|
||||
gint b;
|
||||
b = qof_util_bool_to_int(insert_string);
|
||||
if(b == 1) {
|
||||
if (b == 1)
|
||||
{
|
||||
cm_boolean = TRUE;
|
||||
}
|
||||
else { cm_boolean = FALSE; }
|
||||
boolean_setter = (void(*)(QofInstance*, gboolean))param->param_setfcn;
|
||||
if(boolean_setter != NULL) { boolean_setter(ent, cm_boolean); }
|
||||
else
|
||||
{
|
||||
cm_boolean = FALSE;
|
||||
}
|
||||
if(safe_strcmp(param->param_type, QOF_TYPE_KVP) == 0) {
|
||||
boolean_setter = (void(*)(QofInstance*, gboolean))param->param_setfcn;
|
||||
if (boolean_setter != NULL)
|
||||
{
|
||||
boolean_setter(ent, cm_boolean);
|
||||
}
|
||||
}
|
||||
if (safe_strcmp(param->param_type, QOF_TYPE_KVP) == 0)
|
||||
{
|
||||
|
||||
}
|
||||
if(safe_strcmp(param->param_type, QOF_TYPE_CHAR) == 0) {
|
||||
if (safe_strcmp(param->param_type, QOF_TYPE_CHAR) == 0)
|
||||
{
|
||||
cm_char = *insert_string;
|
||||
char_setter = (void(*)(QofInstance*, char))param->param_setfcn;
|
||||
if(char_setter != NULL) { char_setter(ent, cm_char); }
|
||||
if (char_setter != NULL)
|
||||
{
|
||||
char_setter(ent, cm_char);
|
||||
}
|
||||
}
|
||||
LEAVE (" ");
|
||||
}
|
||||
@ -711,15 +764,18 @@ qof_query_set_insert_table(QofSqlQuery *query)
|
||||
sql_insert_statement *sis;
|
||||
sql_table *sis_t;
|
||||
sis = query->parse_result->statement;
|
||||
switch(sis->table->type) {
|
||||
case SQL_simple: {
|
||||
switch (sis->table->type)
|
||||
{
|
||||
case SQL_simple:
|
||||
{
|
||||
sis_t = sis->table;
|
||||
query->single_global_tablename = g_strdup_printf("%s", sis_t->d.simple);
|
||||
qof_query_search_for (query->qof_query, query->single_global_tablename);
|
||||
PINFO (" insert set to table: %s", sis_t->d.simple);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
default:
|
||||
{
|
||||
PWARN ("SQL insert only handles simple statements");
|
||||
}
|
||||
}
|
||||
@ -747,7 +803,11 @@ qof_query_insert(QofSqlQuery *query)
|
||||
value_list = NULL;
|
||||
param_name = NULL;
|
||||
sis = query->parse_result->statement;
|
||||
if (!sis->fields || !sis->values) { LEAVE (" NULL insert statement"); return NULL; }
|
||||
if (!sis->fields || !sis->values)
|
||||
{
|
||||
LEAVE (" NULL insert statement");
|
||||
return NULL;
|
||||
}
|
||||
type = g_strdup(query->single_global_tablename);
|
||||
inst = (QofInstance*)qof_object_new_instance(type, query->book);
|
||||
if (inst == NULL)
|
||||
@ -772,7 +832,8 @@ qof_query_insert(QofSqlQuery *query)
|
||||
param_name = g_strdup_printf("%s", (char*)cur->data);
|
||||
param = qof_class_get_parameter(type, param_name);
|
||||
}
|
||||
if(param && value) {
|
||||
if (param && value)
|
||||
{
|
||||
qof_sql_insertCB(param, value, query);
|
||||
}
|
||||
value_list = g_list_next(value_list);
|
||||
@ -786,11 +847,26 @@ sql_type_as_string(sql_statement_type type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SQL_select : { return "SELECT"; }
|
||||
case SQL_insert : { return "INSERT"; }
|
||||
case SQL_delete : { return "DELETE"; }
|
||||
case SQL_update : { return "UPDATE"; }
|
||||
default : { return "unknown"; }
|
||||
case SQL_select :
|
||||
{
|
||||
return "SELECT";
|
||||
}
|
||||
case SQL_insert :
|
||||
{
|
||||
return "INSERT";
|
||||
}
|
||||
case SQL_delete :
|
||||
{
|
||||
return "DELETE";
|
||||
}
|
||||
case SQL_update :
|
||||
{
|
||||
return "UPDATE";
|
||||
}
|
||||
default :
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -841,7 +917,8 @@ qof_sql_query_parse (QofSqlQuery *query, const char *str)
|
||||
query->single_global_tablename = tables->data;
|
||||
}
|
||||
/* if this is an insert, we're done with the parse. */
|
||||
if(SQL_insert == query->parse_result->type) {
|
||||
if (SQL_insert == query->parse_result->type)
|
||||
{
|
||||
query->qof_query = qof_query_create();
|
||||
qof_query_set_insert_table(query);
|
||||
LEAVE (" insert statement parsed OK");
|
||||
@ -853,7 +930,11 @@ qof_sql_query_parse (QofSqlQuery *query, const char *str)
|
||||
{
|
||||
/* Walk over the where terms, turn them into QOF predicates */
|
||||
query->qof_query = handle_where (query, swear);
|
||||
if (NULL == query->qof_query) { LEAVE (" no query found"); return; }
|
||||
if (NULL == query->qof_query)
|
||||
{
|
||||
LEAVE (" no query found");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -880,7 +961,11 @@ qof_sql_query_run (QofSqlQuery *query, const char *str)
|
||||
if (!query) return NULL;
|
||||
|
||||
qof_sql_query_parse (query, str);
|
||||
if (NULL == query->qof_query) { PINFO (" Null query"); return NULL; }
|
||||
if (NULL == query->qof_query)
|
||||
{
|
||||
PINFO (" Null query");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
qof_query_set_book (query->qof_query, query->book);
|
||||
/* Maybe log this sucker */
|
||||
@ -888,7 +973,8 @@ qof_sql_query_run (QofSqlQuery *query, const char *str)
|
||||
{
|
||||
qof_query_print (query->qof_query);
|
||||
}
|
||||
if(SQL_insert == query->parse_result->type){
|
||||
if (SQL_insert == query->parse_result->type)
|
||||
{
|
||||
results = NULL;
|
||||
results = g_list_append(results, qof_query_insert(query));
|
||||
return results;
|
||||
|
@ -83,17 +83,21 @@ qof_utf8_strcasecmp (const gchar *da, const gchar *db)
|
||||
gint
|
||||
safe_strcmp (const gchar * da, const gchar * db)
|
||||
{
|
||||
if ((da) && (db)) {
|
||||
if ((da) != (db)) {
|
||||
if ((da) && (db))
|
||||
{
|
||||
if ((da) != (db))
|
||||
{
|
||||
gint retval = strcmp ((da), (db));
|
||||
/* if strings differ, return */
|
||||
if (retval) return retval;
|
||||
}
|
||||
} else
|
||||
if ((!(da)) && (db)) {
|
||||
}
|
||||
else if ((!(da)) && (db))
|
||||
{
|
||||
return -1;
|
||||
} else
|
||||
if ((da) && (!(db))) {
|
||||
}
|
||||
else if ((da) && (!(db)))
|
||||
{
|
||||
return +1;
|
||||
}
|
||||
return 0;
|
||||
@ -102,17 +106,21 @@ safe_strcmp (const gchar * da, const gchar * db)
|
||||
gint
|
||||
safe_strcasecmp (const gchar * da, const gchar * db)
|
||||
{
|
||||
if ((da) && (db)) {
|
||||
if ((da) != (db)) {
|
||||
if ((da) && (db))
|
||||
{
|
||||
if ((da) != (db))
|
||||
{
|
||||
gint retval = qof_utf8_strcasecmp ((da), (db));
|
||||
/* if strings differ, return */
|
||||
if (retval) return retval;
|
||||
}
|
||||
} else
|
||||
if ((!(da)) && (db)) {
|
||||
}
|
||||
else if ((!(da)) && (db))
|
||||
{
|
||||
return -1;
|
||||
} else
|
||||
if ((da) && (!(db))) {
|
||||
}
|
||||
else if ((da) && (!(db)))
|
||||
{
|
||||
return +1;
|
||||
}
|
||||
return 0;
|
||||
@ -144,7 +152,8 @@ ultostr (gulong val, gint base)
|
||||
|
||||
/* count digits */
|
||||
places = 0;
|
||||
for (i=0; i<MAX_DIGITS; i++) {
|
||||
for (i = 0; i < MAX_DIGITS; i++)
|
||||
{
|
||||
broke[i] = val;
|
||||
places ++;
|
||||
val /= base;
|
||||
@ -153,17 +162,22 @@ ultostr (gulong val, gint base)
|
||||
|
||||
/* normalize */
|
||||
reval = 0;
|
||||
for (i=places-2; i>=0; i--) {
|
||||
for (i = places - 2; i >= 0; i--)
|
||||
{
|
||||
reval += broke[i+1];
|
||||
reval *= base;
|
||||
broke[i] -= reval;
|
||||
}
|
||||
|
||||
/* print */
|
||||
for (i=0; i<(gint)places; i++) {
|
||||
if (10>broke[i]) {
|
||||
for (i = 0; i < (gint)places; i++)
|
||||
{
|
||||
if (10 > broke[i])
|
||||
{
|
||||
buf[places-1-i] = 0x30 + broke[i]; /* ascii digit zero */
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
buf[places-1-i] = 0x41 - 10 + broke[i]; /* ascii capital A */
|
||||
}
|
||||
}
|
||||
@ -245,22 +259,28 @@ qof_util_bool_to_int (const gchar * val)
|
||||
static GCache * qof_string_cache = NULL;
|
||||
|
||||
#ifdef THESE_CAN_BE_USEFUL_FOR_DEGUGGING
|
||||
static guint g_str_hash_KEY(gconstpointer v) {
|
||||
static guint g_str_hash_KEY(gconstpointer v)
|
||||
{
|
||||
return g_str_hash(v);
|
||||
}
|
||||
static guint g_str_hash_VAL(gconstpointer v) {
|
||||
static guint g_str_hash_VAL(gconstpointer v)
|
||||
{
|
||||
return g_str_hash(v);
|
||||
}
|
||||
static gpointer g_strdup_VAL(gpointer v) {
|
||||
static gpointer g_strdup_VAL(gpointer v)
|
||||
{
|
||||
return g_strdup(v);
|
||||
}
|
||||
static gpointer g_strdup_KEY(gpointer v) {
|
||||
static gpointer g_strdup_KEY(gpointer v)
|
||||
{
|
||||
return g_strdup(v);
|
||||
}
|
||||
static void g_free_VAL(gpointer v) {
|
||||
static void g_free_VAL(gpointer v)
|
||||
{
|
||||
return g_free(v);
|
||||
}
|
||||
static void g_free_KEY(gpointer v) {
|
||||
static void g_free_KEY(gpointer v)
|
||||
{
|
||||
return g_free(v);
|
||||
}
|
||||
static gboolean qof_util_str_equal(gconstpointer v, gconstpointer v2)
|
||||
@ -271,7 +291,8 @@ static gboolean qof_util_str_equal(gconstpointer v, gconstpointer v2)
|
||||
static GCache*
|
||||
qof_util_get_string_cache(void)
|
||||
{
|
||||
if(!qof_string_cache) {
|
||||
if (!qof_string_cache)
|
||||
{
|
||||
qof_string_cache = g_cache_new(
|
||||
(GCacheNewFunc) g_strdup, /* value_new_func */
|
||||
g_free, /* value_destroy_func */
|
||||
@ -327,13 +348,18 @@ qof_util_param_as_string(QofInstance *ent, QofParam *param)
|
||||
param_string = NULL;
|
||||
known_type = FALSE;
|
||||
paramType = param->param_type;
|
||||
if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_STRING) == 0)
|
||||
{
|
||||
param_string = g_strdup(param->param_getfcn(ent, param));
|
||||
if(param_string == NULL) { param_string = ""; }
|
||||
if (param_string == NULL)
|
||||
{
|
||||
param_string = "";
|
||||
}
|
||||
known_type = TRUE;
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_DATE) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_DATE) == 0)
|
||||
{
|
||||
date_getter = (Timespec (*)(QofInstance*, QofParam*))param->param_getfcn;
|
||||
param_ts = date_getter(ent, param);
|
||||
param_t = timespecToTime_t(param_ts);
|
||||
@ -344,52 +370,65 @@ qof_util_param_as_string(QofInstance *ent, QofParam *param)
|
||||
return param_string;
|
||||
}
|
||||
if ((safe_strcmp(paramType, QOF_TYPE_NUMERIC) == 0) ||
|
||||
(safe_strcmp(paramType, QOF_TYPE_DEBCRED) == 0)) {
|
||||
(safe_strcmp(paramType, QOF_TYPE_DEBCRED) == 0))
|
||||
{
|
||||
numeric_getter = (gnc_numeric (*)(QofInstance*, QofParam*)) param->param_getfcn;
|
||||
param_numeric = numeric_getter(ent, param);
|
||||
param_string = g_strdup(gnc_numeric_to_string(param_numeric));
|
||||
known_type = TRUE;
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_GUID) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_GUID) == 0)
|
||||
{
|
||||
param_guid = param->param_getfcn(ent, param);
|
||||
guid_to_string_buff(param_guid, param_sa);
|
||||
param_string = g_strdup(param_sa);
|
||||
known_type = TRUE;
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_INT32) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_INT32) == 0)
|
||||
{
|
||||
int32_getter = (gint32 (*)(QofInstance*, QofParam*)) param->param_getfcn;
|
||||
param_i32 = int32_getter(ent, param);
|
||||
param_string = g_strdup_printf("%d", param_i32);
|
||||
known_type = TRUE;
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_INT64) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_INT64) == 0)
|
||||
{
|
||||
int64_getter = (gint64 (*)(QofInstance*, QofParam*)) param->param_getfcn;
|
||||
param_i64 = int64_getter(ent, param);
|
||||
param_string = g_strdup_printf("%"G_GINT64_FORMAT, param_i64);
|
||||
known_type = TRUE;
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_DOUBLE) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_DOUBLE) == 0)
|
||||
{
|
||||
double_getter = (double (*)(QofInstance*, QofParam*)) param->param_getfcn;
|
||||
param_double = double_getter(ent, param);
|
||||
param_string = g_strdup_printf("%f", param_double);
|
||||
known_type = TRUE;
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_BOOLEAN) == 0){
|
||||
if (safe_strcmp(paramType, QOF_TYPE_BOOLEAN) == 0)
|
||||
{
|
||||
boolean_getter = (gboolean (*)(QofInstance*, QofParam*)) param->param_getfcn;
|
||||
param_boolean = boolean_getter(ent, param);
|
||||
/* Boolean values need to be lowercase for QSF validation. */
|
||||
if(param_boolean == TRUE) { param_string = g_strdup("true"); }
|
||||
else { param_string = g_strdup("false"); }
|
||||
if (param_boolean == TRUE)
|
||||
{
|
||||
param_string = g_strdup("true");
|
||||
}
|
||||
else
|
||||
{
|
||||
param_string = g_strdup("false");
|
||||
}
|
||||
known_type = TRUE;
|
||||
return param_string;
|
||||
}
|
||||
/* "kvp" contains repeating values, cannot be a single string for the frame. */
|
||||
if(safe_strcmp(paramType, QOF_TYPE_KVP) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_KVP) == 0)
|
||||
{
|
||||
KvpFrame *frame = NULL;
|
||||
frame = param->param_getfcn(ent, param);
|
||||
known_type = TRUE;
|
||||
@ -401,7 +440,8 @@ qof_util_param_as_string(QofInstance *ent, QofParam *param)
|
||||
}
|
||||
return param_string;
|
||||
}
|
||||
if(safe_strcmp(paramType, QOF_TYPE_CHAR) == 0) {
|
||||
if (safe_strcmp(paramType, QOF_TYPE_CHAR) == 0)
|
||||
{
|
||||
char_getter = (gchar (*)(QofInstance*, QofParam*)) param->param_getfcn;
|
||||
param_char = char_getter(ent, param);
|
||||
known_type = TRUE;
|
||||
@ -420,7 +460,10 @@ qof_util_param_as_string(QofInstance *ent, QofParam *param)
|
||||
{
|
||||
QofInstance *child = NULL;
|
||||
child = param->param_getfcn(ent, param);
|
||||
if(!child) { return param_string; }
|
||||
if (!child)
|
||||
{
|
||||
return param_string;
|
||||
}
|
||||
known_type = TRUE;
|
||||
return g_strdup(qof_object_printable(child->e_type, child));
|
||||
}
|
||||
@ -433,10 +476,16 @@ qof_util_param_as_string(QofInstance *ent, QofParam *param)
|
||||
be = qof_book_get_backend(book);
|
||||
known_type = TRUE;
|
||||
PINFO (" backend=%p", be);
|
||||
if(!be) { return QOF_PARAM_BOOK; }
|
||||
if (!be)
|
||||
{
|
||||
return QOF_PARAM_BOOK;
|
||||
}
|
||||
param_string = g_strdup(be->fullpath);
|
||||
PINFO (" fullpath=%s", param_string);
|
||||
if(param_string) { return param_string; }
|
||||
if (param_string)
|
||||
{
|
||||
return param_string;
|
||||
}
|
||||
param_guid = qof_book_get_guid(book);
|
||||
guid_to_string_buff(param_guid, param_sa);
|
||||
PINFO (" book GUID=%s", param_sa);
|
||||
@ -447,7 +496,10 @@ qof_util_param_as_string(QofInstance *ent, QofParam *param)
|
||||
{
|
||||
QofInstance *child = NULL;
|
||||
child = param->param_getfcn(ent, param);
|
||||
if(!child) { return param_string; }
|
||||
if (!child)
|
||||
{
|
||||
return param_string;
|
||||
}
|
||||
return g_strdup(qof_object_printable(child->e_type, child));
|
||||
}
|
||||
return g_strdup("");
|
||||
|
Loading…
Reference in New Issue
Block a user