Fix get_filter_query 97/283197/2
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 20 Oct 2022 05:34:32 +0000 (14:34 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Thu, 20 Oct 2022 07:10:17 +0000 (16:10 +0900)
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 <ilho159.kim@samsung.com>
src/server/appinfo_internal.cc
src/server/pkginfo_internal.c

index c8ce2ef..488e623 100644 (file)
@@ -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<char*>(calloc(1, size));
   if (*query == nullptr)
index cb46059..d2c5a8a 100644 (file)
@@ -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)