From 615470bfe11b0a8dd11ed45a0e99cf7cad42dd1a Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Thu, 20 Oct 2022 14:34:32 +0900 Subject: [PATCH] Fix get_filter_query Because the query related to the JOIN_LOCALIZED_INFO flag is located in front of the entire query the order of the bind parameters should be adjusted Change-Id: Ib65b11eda6e33343d80d55c9920caf47094d2f13 Signed-off-by: Ilho Kim --- src/server/appinfo_internal.cc | 6 ++++-- src/server/pkginfo_internal.c | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/server/appinfo_internal.cc b/src/server/appinfo_internal.cc index c8ce2ef..488e623 100644 --- a/src/server/appinfo_internal.cc +++ b/src/server/appinfo_internal.cc @@ -382,6 +382,7 @@ int _get_filtered_query(pkgmgrinfo_filter_x* filter, const char* locale, char* condition = nullptr; char buf[MAX_QUERY_LEN] = {'\0'}; char tmp_query[MAX_QUERY_LEN] = {'\0'}; + GList* tmp_params = NULL; GSList* list; if (!filter) @@ -399,7 +400,7 @@ int _get_filtered_query(pkgmgrinfo_filter_x* filter, const char* locale, for (list = filter->list; list; list = list->next) { joined |= __get_filter_condition(list->data, - uid, &condition, bind_params); + uid, &condition, &tmp_params); if (condition == nullptr) continue; @@ -414,7 +415,7 @@ int _get_filtered_query(pkgmgrinfo_filter_x* filter, const char* locale, strncat(buf, " AND (", sizeof(buf) - strlen(buf) - 1); for (list = filter->list_metadata; list; list = list->next) { joined |= __get_metadata_filter_condition(list->data, - &condition, bind_params); + &condition, &tmp_params); if (condition == nullptr) continue; strncat(buf, condition, sizeof(buf) - strlen(buf) - 1); @@ -444,6 +445,7 @@ int _get_filtered_query(pkgmgrinfo_filter_x* filter, const char* locale, strncat(tmp_query, join_privilege, sizeof(tmp_query) - strlen(tmp_query) - 1); + *bind_params = g_list_concat(*bind_params, tmp_params); size = strlen(tmp_query) + strlen(buf) + 1; *query = static_cast(calloc(1, size)); if (*query == nullptr) diff --git a/src/server/pkginfo_internal.c b/src/server/pkginfo_internal.c index cb46059..d2c5a8a 100644 --- a/src/server/pkginfo_internal.c +++ b/src/server/pkginfo_internal.c @@ -74,6 +74,7 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter, char buf[MAX_QUERY_LEN] = { '\0' }; char buf2[MAX_QUERY_LEN] = { '\0' }; char *condition = NULL; + GList *tmp_params = NULL; GSList *list = NULL; if (!filter) @@ -88,7 +89,7 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter, snprintf(buf, sizeof(buf), "%s", " WHERE 1=1 "); for (list = filter->list; list; list = list->next) { joined |= __get_filter_condition(list->data, uid, &condition, - bind_params); + &tmp_params); if (condition == NULL) continue; @@ -111,6 +112,7 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter, strncat(buf2, join_res_info, sizeof(buf2) - strlen(buf2) - 1); + *bind_params = g_list_concat(*bind_params, tmp_params); size = strlen(buf2) + strlen(buf) + 1; *query = (char *)calloc(1, size); if (*query == NULL) -- 2.7.4