30 #include "qofquerycore-p.h"
47 typedef gchar *(*QueryToString) (gpointer object,
QofParam * getter);
53 static QueryPredicateCopyFunc qof_query_copy_predicate (
QofType type);
54 static QueryPredDataFree qof_query_predicate_free (
QofType type);
57 typedef const gchar *(*query_string_getter) (gpointer,
QofParam *);
58 static const gchar *query_string_type = QOF_TYPE_STRING;
61 static const gchar *query_time_type = QOF_TYPE_TIME;
64 static const gchar *query_numeric_type = QOF_TYPE_NUMERIC;
66 typedef GList *(*query_glist_getter) (gpointer,
QofParam *);
67 typedef const GUID *(*query_guid_getter) (gpointer,
QofParam *);
68 static const gchar *query_guid_type = QOF_TYPE_GUID;
70 typedef gint32 (*query_int32_getter) (gpointer,
QofParam *);
71 static const gchar *query_int32_type = QOF_TYPE_INT32;
73 typedef gint64 (*query_int64_getter) (gpointer,
QofParam *);
74 static const char *query_int64_type = QOF_TYPE_INT64;
76 typedef double (*query_double_getter) (gpointer,
QofParam *);
77 static const gchar *query_double_type = QOF_TYPE_DOUBLE;
79 typedef gboolean (*query_boolean_getter) (gpointer,
QofParam *);
80 static const gchar *query_boolean_type = QOF_TYPE_BOOLEAN;
82 typedef char (*query_char_getter) (gpointer,
QofParam *);
83 static const char *query_char_type = QOF_TYPE_CHAR;
86 static const gchar *query_kvp_type = QOF_TYPE_KVP;
91 typedef const GUID *(*query_choice_getter) (gpointer,
QofParam *);
95 static gboolean initialized = FALSE;
96 static GHashTable *predTable = NULL;
97 static GHashTable *cmpTable = NULL;
98 static GHashTable *copyTable = NULL;
99 static GHashTable *freeTable = NULL;
100 static GHashTable *toStringTable = NULL;
101 static GHashTable *predEqualTable = NULL;
103 #define COMPARE_ERROR -3
104 #define PREDICATE_ERROR -2
106 #define VERIFY_PDATA(str) { \
107 g_return_if_fail (pd != NULL); \
108 g_return_if_fail (pd->type_name == str || \
109 !safe_strcmp (str, pd->type_name)); \
111 #define VERIFY_PDATA_R(str) { \
112 g_return_val_if_fail (pd != NULL, NULL); \
113 g_return_val_if_fail (pd->type_name == str || \
114 !safe_strcmp (str, pd->type_name), \
117 #define VERIFY_PREDICATE(str) { \
118 g_return_val_if_fail (getter != NULL, PREDICATE_ERROR); \
119 g_return_val_if_fail (getter->param_getfcn != NULL, PREDICATE_ERROR); \
120 g_return_val_if_fail (pd != NULL, PREDICATE_ERROR); \
121 g_return_val_if_fail (pd->type_name == str || \
122 !safe_strcmp (str, pd->type_name), \
132 string_match_predicate (gpointer
object,
139 VERIFY_PREDICATE (query_string_type);
141 s = ((query_string_getter) getter->param_getfcn) (object, getter);
149 if (!regexec (&pdata->compiled, s, 1, &match, 0))
153 else if (pdata->options == QOF_STRING_MATCH_CASEINSENSITIVE)
155 if (strcasestr (s, pdata->matchstring))
161 if (strstr (s, pdata->matchstring))
167 case QOF_COMPARE_EQUAL:
169 case QOF_COMPARE_NEQ:
172 PWARN (
"bad match type: %d", pd->how);
178 string_compare_func (gpointer a, gpointer b, gint options,
181 const gchar *s1, *s2;
182 g_return_val_if_fail (a && b && getter
183 && getter->param_getfcn, COMPARE_ERROR);
185 s1 = ((query_string_getter) getter->param_getfcn) (a, getter);
186 s2 = ((query_string_getter) getter->param_getfcn) (b, getter);
188 if (options == QOF_STRING_MATCH_CASEINSENSITIVE)
199 VERIFY_PDATA (query_string_type);
202 regfree (&pdata->compiled);
204 g_free (pdata->matchstring);
214 VERIFY_PDATA_R (query_string_type);
216 return qof_query_string_predicate (pd->how, pdata->matchstring,
217 pdata->options, pdata->is_regex);
226 if (pd1->options != pd2->options)
228 if (pd1->is_regex != pd2->is_regex)
230 return (
safe_strcmp (pd1->matchstring, pd2->matchstring) == 0);
239 g_return_val_if_fail (str, NULL);
240 g_return_val_if_fail (*str !=
'\0', NULL);
241 g_return_val_if_fail (how == QOF_COMPARE_EQUAL
242 || how == QOF_COMPARE_NEQ, NULL);
245 pdata->pd.type_name = query_string_type;
247 pdata->options = options;
248 pdata->matchstring = g_strdup (str);
252 int flags = REG_EXTENDED;
253 if (options == QOF_STRING_MATCH_CASEINSENSITIVE)
256 regcomp (&pdata->compiled, str, flags);
257 pdata->is_regex = TRUE;
264 string_to_string (gpointer
object,
QofParam * getter)
267 res = ((query_string_getter) getter->param_getfcn) (object, getter);
269 return g_strdup (res);
278 if (options == QOF_DATE_MATCH_DAY)
287 time_match_predicate (gpointer
object,
QofParam * getter,
294 VERIFY_PREDICATE (query_time_type);
296 objtime = ((query_time_getter) getter->param_getfcn) (object, getter);
297 compare = time_compare (objtime, pdata->qt, pdata->options);
302 return (compare < 0);
303 case QOF_COMPARE_LTE:
304 return (compare <= 0);
305 case QOF_COMPARE_EQUAL:
306 return (compare == 0);
308 return (compare > 0);
309 case QOF_COMPARE_GTE:
310 return (compare >= 0);
311 case QOF_COMPARE_NEQ:
312 return (compare != 0);
314 PWARN (
"bad match type: %d", pd->how);
320 time_compare_func (gpointer a, gpointer b, gint options,
325 g_return_val_if_fail (a && b && getter
326 && getter->param_getfcn, COMPARE_ERROR);
328 ta = ((query_time_getter) getter->param_getfcn) (a, getter);
329 tb = ((query_time_getter) getter->param_getfcn) (b, getter);
331 return time_compare (ta, tb, options);
339 VERIFY_PDATA (query_time_type);
349 VERIFY_PDATA_R (query_time_type);
351 return qof_query_time_predicate (pd->how, pdata->options,
361 if (pd1->options != pd2->options)
373 pdata->pd.type_name = query_time_type;
375 pdata->options = options;
386 if (pdata->pd.type_name != query_time_type)
393 time_to_string (gpointer
object,
QofParam * getter)
397 ((query_time_getter) getter->param_getfcn) (object, getter);
406 numeric_match_predicate (gpointer
object,
QofParam * getter,
413 VERIFY_PREDICATE (query_numeric_type);
416 ((query_numeric_getter) getter->param_getfcn) (object, getter);
418 switch (pdata->options)
420 case QOF_NUMERIC_MATCH_CREDIT:
424 case QOF_NUMERIC_MATCH_DEBIT:
434 if (pd->how == QOF_COMPARE_EQUAL || pd->how == QOF_COMPARE_NEQ)
451 return (compare < 0);
452 case QOF_COMPARE_LTE:
453 return (compare <= 0);
454 case QOF_COMPARE_EQUAL:
457 return (compare > 0);
458 case QOF_COMPARE_GTE:
459 return (compare >= 0);
460 case QOF_COMPARE_NEQ:
463 PWARN (
"bad match type: %d", pd->how);
469 numeric_compare_func (gpointer a, gpointer b,
470 gint options __attribute__ ((unused)),
QofParam * getter)
474 g_return_val_if_fail (a && b && getter
475 && getter->param_getfcn, COMPARE_ERROR);
477 va = ((query_numeric_getter) getter->param_getfcn) (a, getter);
478 vb = ((query_numeric_getter) getter->param_getfcn) (b, getter);
487 VERIFY_PDATA (query_numeric_type);
495 VERIFY_PDATA_R (query_numeric_type);
496 return qof_query_numeric_predicate (pd->how, pdata->options,
506 if (pd1->options != pd2->options)
517 pdata->pd.type_name = query_numeric_type;
519 pdata->options = options;
520 pdata->amount = value;
525 numeric_to_string (gpointer
object,
QofParam * getter)
528 num = ((query_numeric_getter) getter->param_getfcn) (object, getter);
534 debcred_to_string (gpointer
object,
QofParam * getter)
537 num = ((query_numeric_getter) getter->param_getfcn) (object, getter);
545 guid_match_predicate (gpointer
object,
QofParam * getter,
549 GList *node, *o_list;
550 const GUID *guid = NULL;
552 VERIFY_PREDICATE (query_guid_type);
554 switch (pdata->options)
563 for (node = pdata->guids; node; node = node->next)
566 for (o_list =
object; o_list; o_list = o_list->next)
569 ((query_guid_getter) getter->param_getfcn) (o_list->
599 ((query_glist_getter) getter->param_getfcn) (object, getter);
601 for (node = o_list; node; node = node->next)
606 for (node2 = pdata->guids; node2; node2 = node2->next)
617 g_list_free (o_list);
631 guid = ((query_guid_getter) getter->param_getfcn) (object, getter);
632 for (node = pdata->guids; node; node = node->next)
639 switch (pdata->options)
643 return (node != NULL);
645 case QOF_GUID_MATCH_NONE:
647 return (node == NULL);
649 case QOF_GUID_MATCH_NULL:
650 return (guid == NULL);
653 PWARN (
"bad match type");
663 VERIFY_PDATA (query_guid_type);
664 for (node = pdata->guids; node; node = node->next)
666 guid_free (node->data);
668 g_list_free (pdata->guids);
676 VERIFY_PDATA_R (query_guid_type);
677 return qof_query_guid_predicate (pdata->options, pdata->guids);
685 GList *l1 = pd1->guids, *l2 = pd2->guids;
687 if (pd1->options != pd2->options)
689 if (g_list_length (l1) != g_list_length (l2))
691 for (; l1; l1 = l1->next, l2 = l2->next)
700 qof_query_guid_predicate (
QofGuidMatch options, GList * guid_list)
705 if (NULL == guid_list)
709 pdata->pd.how = QOF_COMPARE_EQUAL;
710 pdata->pd.type_name = query_guid_type;
711 pdata->options = options;
713 pdata->guids = g_list_copy (guid_list);
714 for (node = pdata->guids; node; node = node->next)
717 *guid = *((
GUID *) node->data);
727 int32_match_predicate (gpointer
object,
QofParam * getter,
733 VERIFY_PREDICATE (query_int32_type);
735 val = ((query_int32_getter) getter->param_getfcn) (object, getter);
740 return (val < pdata->val);
741 case QOF_COMPARE_LTE:
742 return (val <= pdata->val);
743 case QOF_COMPARE_EQUAL:
744 return (val == pdata->val);
746 return (val > pdata->val);
747 case QOF_COMPARE_GTE:
748 return (val >= pdata->val);
749 case QOF_COMPARE_NEQ:
750 return (val != pdata->val);
752 PWARN (
"bad match type: %d", pd->how);
758 int32_compare_func (gpointer a, gpointer b,
759 gint options __attribute__ ((unused)),
763 g_return_val_if_fail (a && b && getter
764 && getter->param_getfcn, COMPARE_ERROR);
766 v1 = ((query_int32_getter) getter->param_getfcn) (a, getter);
767 v2 = ((query_int32_getter) getter->param_getfcn) (b, getter);
780 VERIFY_PDATA (query_int32_type);
788 VERIFY_PDATA_R (query_int32_type);
789 return qof_query_int32_predicate (pd->how, pdata->val);
798 return (pd1->val == pd2->val);
805 pdata->pd.type_name = query_int32_type;
812 int32_to_string (gpointer
object,
QofParam * getter)
815 ((query_int32_getter) getter->param_getfcn) (object, getter);
817 return g_strdup_printf (
"%d", num);
824 int64_match_predicate (gpointer
object,
QofParam * getter,
830 VERIFY_PREDICATE (query_int64_type);
832 val = ((query_int64_getter) getter->param_getfcn) (object, getter);
837 return (val < pdata->val);
838 case QOF_COMPARE_LTE:
839 return (val <= pdata->val);
840 case QOF_COMPARE_EQUAL:
841 return (val == pdata->val);
843 return (val > pdata->val);
844 case QOF_COMPARE_GTE:
845 return (val >= pdata->val);
846 case QOF_COMPARE_NEQ:
847 return (val != pdata->val);
849 PWARN (
"bad match type: %d", pd->how);
855 int64_compare_func (gpointer a, gpointer b,
856 gint options __attribute__ ((unused)),
QofParam * getter)
859 g_return_val_if_fail (a && b && getter
860 && getter->param_getfcn, COMPARE_ERROR);
862 v1 = ((query_int64_getter) getter->param_getfcn) (a, getter);
863 v2 = ((query_int64_getter) getter->param_getfcn) (b, getter);
876 VERIFY_PDATA (query_int64_type);
884 VERIFY_PDATA_R (query_int64_type);
885 return qof_query_int64_predicate (pd->how, pdata->val);
894 return (pd1->val == pd2->val);
901 pdata->pd.type_name = query_int64_type;
908 int64_to_string (gpointer
object,
QofParam * getter)
911 ((query_int64_getter) getter->param_getfcn) (object, getter);
913 return g_strdup_printf (
"%" G_GINT64_FORMAT, num);
920 double_match_predicate (gpointer
object,
QofParam * getter,
926 VERIFY_PREDICATE (query_double_type);
928 val = ((query_double_getter) getter->param_getfcn) (object, getter);
933 return (val < pdata->val);
934 case QOF_COMPARE_LTE:
935 return (val <= pdata->val);
936 case QOF_COMPARE_EQUAL:
937 return (val == pdata->val);
939 return (val > pdata->val);
940 case QOF_COMPARE_GTE:
941 return (val >= pdata->val);
942 case QOF_COMPARE_NEQ:
943 return (val != pdata->val);
945 PWARN (
"bad match type: %d", pd->how);
951 double_compare_func (gpointer a, gpointer b,
952 gint options __attribute__ ((unused)),
QofParam * getter)
955 g_return_val_if_fail (a && b && getter
956 && getter->param_getfcn, COMPARE_ERROR);
958 v1 = ((query_double_getter) getter->param_getfcn) (a, getter);
959 v2 = ((query_double_getter) getter->param_getfcn) (b, getter);
972 VERIFY_PDATA (query_double_type);
980 VERIFY_PDATA_R (query_double_type);
981 return qof_query_double_predicate (pd->how, pdata->val);
990 return (pd1->val == pd2->val);
997 pdata->pd.type_name = query_double_type;
1004 double_to_string (gpointer
object,
QofParam * getter)
1007 ((query_double_getter) getter->param_getfcn) (object, getter);
1009 return g_strdup_printf (
"%f", num);
1015 boolean_match_predicate (gpointer
object,
QofParam * getter,
1021 VERIFY_PREDICATE (query_boolean_type);
1023 val = ((query_boolean_getter) getter->param_getfcn) (object, getter);
1027 case QOF_COMPARE_EQUAL:
1028 return (val == pdata->val);
1029 case QOF_COMPARE_NEQ:
1030 return (val != pdata->val);
1032 PWARN (
"bad match type: %d", pd->how);
1038 boolean_compare_func (gpointer a, gpointer b,
1039 gint options __attribute__ ((unused)),
QofParam * getter)
1042 g_return_val_if_fail (a && b && getter
1043 && getter->param_getfcn, COMPARE_ERROR);
1044 va = ((query_boolean_getter) getter->param_getfcn) (a, getter);
1045 vb = ((query_boolean_getter) getter->param_getfcn) (b, getter);
1057 VERIFY_PDATA (query_boolean_type);
1065 VERIFY_PDATA_R (query_boolean_type);
1066 return qof_query_boolean_predicate (pd->how, pdata->val);
1075 return (pd1->val == pd2->val);
1082 g_return_val_if_fail (how == QOF_COMPARE_EQUAL
1083 || how == QOF_COMPARE_NEQ, NULL);
1086 pdata->pd.type_name = query_boolean_type;
1087 pdata->pd.how = how;
1093 boolean_to_string (gpointer
object,
QofParam * getter)
1096 ((query_boolean_getter) getter->param_getfcn) (object, getter);
1098 return g_strdup_printf (
"%s", (num ?
"X" :
""));
1104 char_match_predicate (gpointer
object,
QofParam * getter,
1110 VERIFY_PREDICATE (query_char_type);
1112 c = ((query_char_getter) getter->param_getfcn) (object, getter);
1114 switch (pdata->options)
1116 case QOF_CHAR_MATCH_ANY:
1117 if (strchr (pdata->char_list, c))
1120 case QOF_CHAR_MATCH_NONE:
1121 if (!strchr (pdata->char_list, c))
1125 PWARN (
"bad match type");
1131 char_compare_func (gpointer a, gpointer b,
1132 gint options __attribute__ ((unused)),
QofParam * getter)
1135 g_return_val_if_fail (a && b && getter
1136 && getter->param_getfcn, COMPARE_ERROR);
1137 va = ((query_char_getter) getter->param_getfcn) (a, getter);
1138 vb = ((query_char_getter) getter->param_getfcn) (b, getter);
1146 VERIFY_PDATA (query_char_type);
1147 g_free (pdata->char_list);
1155 VERIFY_PDATA_R (query_char_type);
1156 return qof_query_char_predicate (pdata->options, pdata->char_list);
1165 if (pd1->options != pd2->options)
1167 return (
safe_strcmp (pd1->char_list, pd2->char_list) == 0);
1171 qof_query_char_predicate (
QofCharMatch options,
const char *chars)
1174 g_return_val_if_fail (chars, NULL);
1176 pdata->pd.type_name = query_char_type;
1177 pdata->pd.how = QOF_COMPARE_EQUAL;
1178 pdata->options = options;
1179 pdata->char_list = g_strdup (chars);
1184 char_to_string (gpointer
object,
QofParam * getter)
1186 char num = ((query_char_getter) getter->param_getfcn) (object, getter);
1188 return g_strdup_printf (
"%c", num);
1194 kvp_match_predicate (gpointer
object,
QofParam * getter,
1202 VERIFY_PREDICATE (query_kvp_type);
1204 kvp = ((query_kvp_getter) getter->param_getfcn) (object, getter);
1212 if (kvp_value_get_type (value) != kvp_value_get_type (pdata->value))
1219 case QOF_COMPARE_LT:
1220 return (compare < 0);
1221 case QOF_COMPARE_LTE:
1222 return (compare <= 0);
1223 case QOF_COMPARE_EQUAL:
1224 return (compare == 0);
1225 case QOF_COMPARE_GTE:
1226 return (compare >= 0);
1227 case QOF_COMPARE_GT:
1228 return (compare > 0);
1229 case QOF_COMPARE_NEQ:
1230 return (compare != 0);
1232 PWARN (
"bad match type: %d", pd->how);
1243 VERIFY_PDATA (query_kvp_type);
1245 for (node = pdata->path; node; node = node->next)
1247 g_free (node->data);
1250 g_slist_free (pdata->path);
1258 VERIFY_PDATA_R (query_kvp_type);
1272 for (; n1 && n2; n1 = n1->next, n2 = n2->next)
1286 GSList * path,
const KvpValue * value)
1291 g_return_val_if_fail (path && value, NULL);
1294 pdata->pd.type_name = query_kvp_type;
1295 pdata->pd.how = how;
1297 pdata->path = g_slist_copy (path);
1298 for (node = pdata->path; node; node = node->next)
1299 node->data = g_strdup (node->data);
1306 const char *path,
const KvpValue * value)
1309 GSList *spath = NULL;
1315 str = g_strdup (path);
1324 spath = g_slist_append (spath, p);
1325 p = strchr (p,
'/');
1342 collect_match_predicate (gpointer
object,
QofParam * getter,
1347 GList *node, *node2, *o_list;
1351 VERIFY_PREDICATE (query_collect_type);
1352 coll = ((query_collect_getter) getter->param_getfcn) (object, getter);
1354 switch (pdata->options)
1358 for (node = pdata->guids; node; node = node->next)
1360 for (o_list =
object; o_list; o_list = o_list->next)
1362 guid = ((query_guid_getter) getter->param_getfcn)
1363 (o_list->data, getter);
1379 ((query_glist_getter) getter->param_getfcn) (object,
1381 for (node = o_list; node; node = node->next)
1383 for (node2 = pdata->guids; node2; node2 = node2->next)
1395 g_list_free (o_list);
1401 ((query_guid_getter) getter->param_getfcn) (object,
1403 for (node = pdata->guids; node; node = node->next)
1411 switch (pdata->options)
1416 return (node != NULL);
1419 case QOF_GUID_MATCH_NONE:
1422 return (node == NULL);
1425 case QOF_GUID_MATCH_NULL:
1427 return (guid == NULL);
1432 PWARN (
"bad match type");
1441 collect_compare_func (gpointer a, gpointer b,
1442 gint options __attribute__ ((unused)),
1448 c1 = ((query_collect_getter) getter->param_getfcn) (a, getter);
1449 c2 = ((query_collect_getter) getter->param_getfcn) (b, getter);
1462 VERIFY_PDATA (query_collect_type);
1463 for (node = pdata->guids; node; node = node->next)
1465 guid_free (node->data);
1468 g_list_free (pdata->guids);
1477 VERIFY_PDATA_R (query_collect_type);
1478 return qof_query_collect_predicate (pdata->options, pdata->coll);
1499 query_collect_cb (
QofEntity * ent, gpointer user_data)
1507 pdata->guids = g_list_append (pdata->guids, guid);
1515 g_return_val_if_fail (coll, NULL);
1517 pdata->pd.type_name = query_collect_type;
1518 pdata->options = options;
1520 if (NULL == pdata->guids)
1530 choice_match_predicate (gpointer
object,
QofParam * getter,
1534 GList *node, *o_list;
1535 const GUID *guid = NULL;
1537 VERIFY_PREDICATE (query_choice_type);
1539 switch (pdata->options)
1548 for (node = pdata->guids; node; node = node->next)
1551 for (o_list =
object; o_list; o_list = o_list->next)
1554 ((query_choice_getter) getter->param_getfcn) (o_list->
1579 ((query_glist_getter) getter->param_getfcn) (object, getter);
1581 for (node = o_list; node; node = node->next)
1585 for (node2 = pdata->guids; node2; node2 = node2->next)
1595 g_list_free (o_list);
1606 ((query_choice_getter) getter->param_getfcn) (object, getter);
1607 for (node = pdata->guids; node; node = node->next)
1614 switch (pdata->options)
1618 return (node != NULL);
1620 case QOF_GUID_MATCH_NONE:
1622 return (node == NULL);
1624 case QOF_GUID_MATCH_NULL:
1625 return (guid == NULL);
1628 PWARN (
"bad match type");
1638 VERIFY_PDATA (query_choice_type);
1639 for (node = pdata->guids; node; node = node->next)
1641 guid_free (node->data);
1643 g_list_free (pdata->guids);
1651 VERIFY_PDATA_R (query_choice_type);
1652 return qof_query_choice_predicate (pdata->options, pdata->guids);
1660 GList *l1 = pd1->guids, *l2 = pd2->guids;
1662 if (pd1->options != pd2->options)
1664 if (g_list_length (l1) != g_list_length (l2))
1666 for (; l1; l1 = l1->next, l2 = l2->next)
1675 qof_query_choice_predicate (
QofGuidMatch options, GList * guid_list)
1680 if (NULL == guid_list)
1684 pdata->pd.how = QOF_COMPARE_EQUAL;
1685 pdata->pd.type_name = query_choice_type;
1686 pdata->options = options;
1688 pdata->guids = g_list_copy (guid_list);
1689 for (node = pdata->guids; node; node = node->next)
1692 *guid = *((
GUID *) node->data);
1712 qof_query_register_core_object (
QofType core_name,
1713 QofQueryPredicateFunc pred,
1714 QofCompareFunc comp,
1715 QueryPredicateCopyFunc copy,
1716 QueryPredDataFree pd_free,
1717 QueryToString toString, QueryPredicateEqual pred_equal)
1719 g_return_if_fail (core_name);
1720 g_return_if_fail (*core_name !=
'\0');
1723 g_hash_table_insert (predTable, (
char *) core_name, pred);
1726 g_hash_table_insert (cmpTable, (
char *) core_name, comp);
1729 g_hash_table_insert (copyTable, (
char *) core_name, copy);
1732 g_hash_table_insert (freeTable, (
char *) core_name, pd_free);
1735 g_hash_table_insert (toStringTable, (
char *) core_name, toString);
1738 g_hash_table_insert (predEqualTable, (
char *) core_name,
1743 #ifndef QOF_DISABLE_DEPRECATED
1752 if (options == QOF_DATE_MATCH_DAY)
1754 ta = timespecCanonicalDayTime (ta);
1755 tb = timespecCanonicalDayTime (tb);
1758 if (ta.tv_sec < tb.tv_sec)
1760 if (ta.tv_sec > tb.tv_sec)
1763 if (ta.tv_nsec < tb.tv_nsec)
1765 if (ta.tv_nsec > tb.tv_nsec)
1772 date_match_predicate (gpointer
object,
QofParam *getter,
1779 VERIFY_PREDICATE (query_date_type);
1781 objtime = ((query_date_getter)getter->param_getfcn) (object, getter);
1782 compare = date_compare (objtime, pdata->date, pdata->options);
1785 case QOF_COMPARE_LT:
1786 return (compare < 0);
1787 case QOF_COMPARE_LTE:
1788 return (compare <= 0);
1789 case QOF_COMPARE_EQUAL:
1790 return (compare == 0);
1791 case QOF_COMPARE_GT:
1792 return (compare > 0);
1793 case QOF_COMPARE_GTE:
1794 return (compare >= 0);
1795 case QOF_COMPARE_NEQ:
1796 return (compare != 0);
1798 PWARN (
"bad match type: %d", pd->how);
1804 date_compare_func (gpointer a, gpointer b, gint options,
QofParam * getter)
1808 g_return_val_if_fail (a && b && getter
1809 && getter->param_getfcn, COMPARE_ERROR);
1811 ta = ((query_date_getter) getter->param_getfcn) (a, getter);
1812 tb = ((query_date_getter) getter->param_getfcn) (b, getter);
1814 return date_compare (ta, tb, options);
1822 VERIFY_PDATA (query_date_type);
1832 VERIFY_PDATA_R (query_date_type);
1843 if (pd1->options != pd2->options)
return FALSE;
1844 return timespec_equal (&(pd1->date), &(pd2->date));
1854 pdata->pd.type_name = query_date_type;
1855 pdata->pd.how = how;
1856 pdata->options = options;
1866 if (pdata->pd.type_name != query_date_type)
1868 *date = pdata->date;
1873 date_to_string (gpointer
object,
QofParam * getter)
1876 ((query_date_getter) getter->param_getfcn) (object, getter);
1878 if (ts.tv_sec || ts.tv_nsec)
1879 return g_strdup (gnc_print_date (ts));
1884 #endif // QOF_DISABLE_DEPRECATED QOF_TYPE_DATE
1893 QofQueryPredicateFunc pred;
1894 QofCompareFunc comp;
1895 QueryPredicateCopyFunc copy;
1896 QueryPredDataFree pd_free;
1897 QueryToString toString;
1898 QueryPredicateEqual pred_equal;
1902 QOF_TYPE_STRING, string_match_predicate, string_compare_func,
1903 string_copy_predicate, string_free_pdata,
1904 string_to_string, string_predicate_equal},
1905 #ifndef QOF_DISABLE_DEPRECATED
1908 date_copy_predicate, date_free_pdata, date_to_string,
1909 date_predicate_equal},
1912 QOF_TYPE_TIME, time_match_predicate, time_compare_func,
1913 time_copy_predicate, time_free_pdata, time_to_string,
1914 time_predicate_equal},
1916 QOF_TYPE_DEBCRED, numeric_match_predicate,
1917 numeric_compare_func, numeric_copy_predicate,
1918 numeric_free_pdata, debcred_to_string,
1919 numeric_predicate_equal},
1921 QOF_TYPE_NUMERIC, numeric_match_predicate,
1922 numeric_compare_func, numeric_copy_predicate,
1923 numeric_free_pdata, numeric_to_string,
1924 numeric_predicate_equal},
1926 QOF_TYPE_GUID, guid_match_predicate, NULL,
1927 guid_copy_predicate, guid_free_pdata, NULL,
1928 guid_predicate_equal},
1930 QOF_TYPE_INT32, int32_match_predicate, int32_compare_func,
1931 int32_copy_predicate, int32_free_pdata,
1932 int32_to_string, int32_predicate_equal},
1934 QOF_TYPE_INT64, int64_match_predicate, int64_compare_func,
1935 int64_copy_predicate, int64_free_pdata,
1936 int64_to_string, int64_predicate_equal},
1938 QOF_TYPE_DOUBLE, double_match_predicate, double_compare_func,
1939 double_copy_predicate, double_free_pdata,
1940 double_to_string, double_predicate_equal},
1942 QOF_TYPE_BOOLEAN, boolean_match_predicate,
1943 boolean_compare_func, boolean_copy_predicate,
1944 boolean_free_pdata, boolean_to_string,
1945 boolean_predicate_equal},
1947 QOF_TYPE_CHAR, char_match_predicate, char_compare_func,
1948 char_copy_predicate, char_free_pdata, char_to_string,
1949 char_predicate_equal},
1951 QOF_TYPE_KVP, kvp_match_predicate, NULL, kvp_copy_predicate,
1952 kvp_free_pdata, NULL, kvp_predicate_equal},
1955 collect_compare_func, collect_copy_predicate,
1956 collect_free_pdata, NULL, collect_predicate_equal},
1959 choice_copy_predicate, choice_free_pdata, NULL,
1960 choice_predicate_equal},};
1963 for (i = 0; i < (
sizeof (knownTypes) /
sizeof (*knownTypes)); i++)
1965 qof_query_register_core_object (knownTypes[i].name,
1969 knownTypes[i].pd_free,
1970 knownTypes[i].toString, knownTypes[i].pred_equal);
1974 static QueryPredicateCopyFunc
1975 qof_query_copy_predicate (
QofType type)
1977 QueryPredicateCopyFunc rc;
1978 g_return_val_if_fail (type, NULL);
1979 rc = g_hash_table_lookup (copyTable, type);
1983 static QueryPredDataFree
1984 qof_query_predicate_free (
QofType type)
1986 g_return_val_if_fail (type, NULL);
1987 return g_hash_table_lookup (freeTable, type);
1994 qof_query_core_init (
void)
2002 predTable = g_hash_table_new (g_str_hash, g_str_equal);
2003 cmpTable = g_hash_table_new (g_str_hash, g_str_equal);
2004 copyTable = g_hash_table_new (g_str_hash, g_str_equal);
2005 freeTable = g_hash_table_new (g_str_hash, g_str_equal);
2006 toStringTable = g_hash_table_new (g_str_hash, g_str_equal);
2007 predEqualTable = g_hash_table_new (g_str_hash, g_str_equal);
2013 qof_query_core_shutdown (
void)
2017 initialized = FALSE;
2019 g_hash_table_destroy (predTable);
2020 g_hash_table_destroy (cmpTable);
2021 g_hash_table_destroy (copyTable);
2022 g_hash_table_destroy (freeTable);
2023 g_hash_table_destroy (toStringTable);
2024 g_hash_table_destroy (predEqualTable);
2027 QofQueryPredicateFunc
2028 qof_query_core_get_predicate (
QofType type)
2030 g_return_val_if_fail (type, NULL);
2031 return g_hash_table_lookup (predTable, type);
2035 qof_query_core_get_compare (
QofType type)
2037 g_return_val_if_fail (type, NULL);
2038 return g_hash_table_lookup (cmpTable, type);
2044 QueryPredDataFree free_fcn;
2046 g_return_if_fail (pdata);
2047 g_return_if_fail (pdata->type_name);
2049 free_fcn = qof_query_predicate_free (pdata->type_name);
2056 QueryPredicateCopyFunc copy;
2058 g_return_val_if_fail (pdata, NULL);
2059 g_return_val_if_fail (pdata->type_name, NULL);
2061 copy = qof_query_copy_predicate (pdata->type_name);
2062 return (copy (pdata));
2069 QueryToString toString;
2071 g_return_val_if_fail (type, NULL);
2072 g_return_val_if_fail (
object, NULL);
2073 g_return_val_if_fail (getter, NULL);
2075 toString = g_hash_table_lookup (toStringTable, type);
2076 g_return_val_if_fail (toString, NULL);
2078 return toString (
object, getter);
2085 QueryPredicateEqual pred_equal;
2092 if (p1->how != p2->how)
2097 pred_equal = g_hash_table_lookup (predEqualTable, p1->type_name);
2098 g_return_val_if_fail (pred_equal, FALSE);
2100 return pred_equal (p1, p2);