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,
1749 QofQueryPredicateFunc pred;
1750 QofCompareFunc comp;
1751 QueryPredicateCopyFunc copy;
1752 QueryPredDataFree pd_free;
1753 QueryToString toString;
1754 QueryPredicateEqual pred_equal;
1758 QOF_TYPE_STRING, string_match_predicate, string_compare_func,
1759 string_copy_predicate, string_free_pdata,
1760 string_to_string, string_predicate_equal},
1762 QOF_TYPE_TIME, time_match_predicate, time_compare_func,
1763 time_copy_predicate, time_free_pdata, time_to_string,
1764 time_predicate_equal},
1766 QOF_TYPE_DEBCRED, numeric_match_predicate,
1767 numeric_compare_func, numeric_copy_predicate,
1768 numeric_free_pdata, debcred_to_string,
1769 numeric_predicate_equal},
1771 QOF_TYPE_NUMERIC, numeric_match_predicate,
1772 numeric_compare_func, numeric_copy_predicate,
1773 numeric_free_pdata, numeric_to_string,
1774 numeric_predicate_equal},
1776 QOF_TYPE_GUID, guid_match_predicate, NULL,
1777 guid_copy_predicate, guid_free_pdata, NULL,
1778 guid_predicate_equal},
1780 QOF_TYPE_INT32, int32_match_predicate, int32_compare_func,
1781 int32_copy_predicate, int32_free_pdata,
1782 int32_to_string, int32_predicate_equal},
1784 QOF_TYPE_INT64, int64_match_predicate, int64_compare_func,
1785 int64_copy_predicate, int64_free_pdata,
1786 int64_to_string, int64_predicate_equal},
1788 QOF_TYPE_DOUBLE, double_match_predicate, double_compare_func,
1789 double_copy_predicate, double_free_pdata,
1790 double_to_string, double_predicate_equal},
1792 QOF_TYPE_BOOLEAN, boolean_match_predicate,
1793 boolean_compare_func, boolean_copy_predicate,
1794 boolean_free_pdata, boolean_to_string,
1795 boolean_predicate_equal},
1797 QOF_TYPE_CHAR, char_match_predicate, char_compare_func,
1798 char_copy_predicate, char_free_pdata, char_to_string,
1799 char_predicate_equal},
1801 QOF_TYPE_KVP, kvp_match_predicate, NULL, kvp_copy_predicate,
1802 kvp_free_pdata, NULL, kvp_predicate_equal},
1805 collect_compare_func, collect_copy_predicate,
1806 collect_free_pdata, NULL, collect_predicate_equal},
1809 choice_copy_predicate, choice_free_pdata, NULL,
1810 choice_predicate_equal},};
1813 for (i = 0; i < (
sizeof (knownTypes) /
sizeof (*knownTypes)); i++)
1815 qof_query_register_core_object (knownTypes[i].name,
1819 knownTypes[i].pd_free,
1820 knownTypes[i].toString, knownTypes[i].pred_equal);
1824 static QueryPredicateCopyFunc
1825 qof_query_copy_predicate (
QofType type)
1827 QueryPredicateCopyFunc rc;
1828 g_return_val_if_fail (type, NULL);
1829 rc = g_hash_table_lookup (copyTable, type);
1833 static QueryPredDataFree
1834 qof_query_predicate_free (
QofType type)
1836 g_return_val_if_fail (type, NULL);
1837 return g_hash_table_lookup (freeTable, type);
1844 qof_query_core_init (
void)
1852 predTable = g_hash_table_new (g_str_hash, g_str_equal);
1853 cmpTable = g_hash_table_new (g_str_hash, g_str_equal);
1854 copyTable = g_hash_table_new (g_str_hash, g_str_equal);
1855 freeTable = g_hash_table_new (g_str_hash, g_str_equal);
1856 toStringTable = g_hash_table_new (g_str_hash, g_str_equal);
1857 predEqualTable = g_hash_table_new (g_str_hash, g_str_equal);
1863 qof_query_core_shutdown (
void)
1867 initialized = FALSE;
1869 g_hash_table_destroy (predTable);
1870 g_hash_table_destroy (cmpTable);
1871 g_hash_table_destroy (copyTable);
1872 g_hash_table_destroy (freeTable);
1873 g_hash_table_destroy (toStringTable);
1874 g_hash_table_destroy (predEqualTable);
1877 QofQueryPredicateFunc
1878 qof_query_core_get_predicate (
QofType type)
1880 g_return_val_if_fail (type, NULL);
1881 return g_hash_table_lookup (predTable, type);
1885 qof_query_core_get_compare (
QofType type)
1887 g_return_val_if_fail (type, NULL);
1888 return g_hash_table_lookup (cmpTable, type);
1894 QueryPredDataFree free_fcn;
1896 g_return_if_fail (pdata);
1897 g_return_if_fail (pdata->type_name);
1899 free_fcn = qof_query_predicate_free (pdata->type_name);
1906 QueryPredicateCopyFunc copy;
1908 g_return_val_if_fail (pdata, NULL);
1909 g_return_val_if_fail (pdata->type_name, NULL);
1911 copy = qof_query_copy_predicate (pdata->type_name);
1912 return (copy (pdata));
1919 QueryToString toString;
1921 g_return_val_if_fail (type, NULL);
1922 g_return_val_if_fail (
object, NULL);
1923 g_return_val_if_fail (getter, NULL);
1925 toString = g_hash_table_lookup (toStringTable, type);
1926 g_return_val_if_fail (toString, NULL);
1928 return toString (
object, getter);
1935 QueryPredicateEqual pred_equal;
1942 if (p1->how != p2->how)
1947 pred_equal = g_hash_table_lookup (predEqualTable, p1->type_name);
1948 g_return_val_if_fail (pred_equal, FALSE);
1950 return pred_equal (p1, p2);
gboolean guid_equal(const GUID *guid_1, const GUID *guid_2)
#define QOF_DATE_FORMAT_UTC
QOF UTC format, xsd:date compatible. QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ".
gint qof_collection_compare(QofCollection *target, QofCollection *merge)
Compare two secondary collections.
QofQueryPredData * qof_query_kvp_predicate_path(QofQueryCompare how, const gchar *path, const KvpValue *value)
#define QOF_TYPE_COLLECT
secondary collections are used for one-to-many references between entities and are implemented using ...
gint qof_numeric_compare(QofNumeric a, QofNumeric b)
struct _QofNumeric QofNumeric
A rational-number type.
QofDate * qof_date_from_qtime(const QofTime *qt)
void qof_query_core_predicate_free(QofQueryPredData *pdata)
struct _KvpFrame KvpFrame
gint safe_strcasecmp(const gchar *da, const gchar *db)
gchar * qof_date_print(const QofDate *date, QofDateFormat df)
Convert a QofDate to a timestamp according to the specified date format.
gboolean qof_time_set_day_start(QofTime *qt)
set the given QofTime to the first second of that day.
gboolean qof_numeric_equal(QofNumeric a, QofNumeric b)
Full range replacement for struct tm.
struct QofCollection_s QofCollection
struct _KvpValue KvpValue
QofNumeric qof_numeric_abs(QofNumeric a)
KvpValue * kvp_value_copy(const KvpValue *value)
void qof_collection_foreach(QofCollection *col, QofEntityForeachCB cb_func, gpointer user_data)
gint qof_time_cmp(const QofTime *ta, const QofTime *tb)
static QofNumeric qof_numeric_create(gint64 num, gint64 denom)
QofQueryPredData * qof_query_core_predicate_copy(QofQueryPredData *pdata)
gboolean qof_time_equal(const QofTime *ta, const QofTime *tb)
QofNumeric qof_numeric_sub(QofNumeric a, QofNumeric b, gint64 denom, gint how)
gchar * qof_numeric_to_string(QofNumeric n)
gboolean qof_query_time_predicate_get_time(QofQueryPredData *pd, QofTime *qt)
gboolean qof_numeric_negative_p(QofNumeric a)
#define PWARN(format, args...)
struct QofTime64 QofTime
Use a 64-bit signed int QofTime.
void qof_collection_destroy(QofCollection *col)
const GUID * qof_entity_get_guid(QofEntity *ent)
gboolean qof_numeric_positive_p(QofNumeric a)
gchar * qof_query_core_to_string(QofType type, gpointer object, QofParam *getter)
gint safe_strcmp(const gchar *da, const gchar *db)
QofQueryPredData * qof_query_kvp_predicate(QofQueryCompare how, GSList *path, const KvpValue *value)
void kvp_value_delete(KvpValue *value)
KvpValue * kvp_frame_get_slot_path_gslist(KvpFrame *frame, GSList *key_path)
#define QOF_TYPE_CHOICE
Identify an object as containing a choice.
gint kvp_value_compare(const KvpValue *kva, const KvpValue *kvb)
const gchar * QofLogModule