#include "pkgmgrinfo_private.h"
#include "pkgmgr_parser.h"
-#define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
- "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
- "ON package_app_info.app_id=package_app_localized_info.app_id " \
- "and package_app_localized_info.app_locale='%s' " \
- "LEFT OUTER JOIN package_app_app_svc " \
- "ON package_app_info.app_id=package_app_app_svc.app_id " \
- "LEFT OUTER JOIN package_app_app_category " \
- "ON package_app_info.app_id=package_app_app_category.app_id where "
-
static bool _get_bool_value(const char *str)
{
if (str == NULL)
return PMINFO_R_OK;
}
-static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
-{
- int *p = (int*)data;
- *p = atoi(coltxt[0]);
- _LOGE("count value is %d\n", *p);
- return 0;
-}
-
API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
{
- retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
- retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
- char *locale = NULL;
- char *condition = NULL;
- char *error_message = NULL;
- char query[MAX_QUERY_LEN] = {'\0'};
- char where[MAX_QUERY_LEN] = {'\0'};
- GSList *list;
- int ret = 0;
+ int ret;
+ GList *list = NULL;
- pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
- /*Get current locale*/
- locale = _get_system_locale();
- if (locale == NULL) {
- _LOGE("manifest locale is NULL\n");
- return PMINFO_R_ERROR;
+ if (handle == NULL || count == NULL) {
+ _LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
}
- ret = __open_manifest_db(uid, true);
- if (ret == -1) {
- _LOGE("Fail to open manifest DB\n");
- free(locale);
+ ret = _appinfo_get_filtered_list(handle, uid, &list);
+ if (ret != PMINFO_R_OK)
return PMINFO_R_ERROR;
- }
- /*Start constructing query*/
- snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
+ *count = g_list_length(list);
- /*Get where clause*/
- for (list = filter->list; list; list = g_slist_next(list)) {
- __get_filter_condition(list->data, &condition);
- if (condition) {
- strncat(where, condition, sizeof(where) - strlen(where) -1);
- where[sizeof(where) - 1] = '\0';
- free(condition);
- condition = NULL;
- }
- if (g_slist_next(list)) {
- strncat(where, " and ", sizeof(where) - strlen(where) - 1);
- where[sizeof(where) - 1] = '\0';
- }
- }
- if (strlen(where) > 0) {
- strncat(query, where, sizeof(query) - strlen(query) - 1);
- query[sizeof(query) - 1] = '\0';
- }
+ g_list_free_full(list, free);
- /*Execute Query*/
- if (SQLITE_OK !=
- sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
- _LOGE("Don't execute query = %s error message = %s\n", query,
- error_message);
- sqlite3_free(error_message);
- ret = PMINFO_R_ERROR;
- *count = 0;
- goto err;
- }
- ret = PMINFO_R_OK;
-err:
- if (locale) {
- free(locale);
- locale = NULL;
- }
- __close_manifest_db();
- return ret;
+ return PMINFO_R_OK;
}
API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
#include "pkgmgr_parser_db.h"
#include "pkgmgr_parser_internal.h"
-#define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
- "from package_info LEFT OUTER JOIN package_localized_info " \
- "ON package_info.package=package_localized_info.package " \
- "and package_localized_info.package_locale='%s' where "
-
-
static int _pkginfo_get_pkginfo(const char *pkgid, uid_t uid,
pkgmgr_pkginfo_x **pkginfo);
static char *_get_filtered_query(const char *query_raw,
return -1;
}
-static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
-{
- int *p = (int*)data;
- *p = atoi(coltxt[0]);
- _LOGE("count value is %d\n", *p);
- return 0;
-}
-
static void __destroy_each_node(gpointer data, gpointer user_data)
{
ret_if(data == NULL);
API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
{
- retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
- retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
- char *locale = NULL;
- char *condition = NULL;
- char *error_message = NULL;
- char query[MAX_QUERY_LEN] = {'\0'};
- char where[MAX_QUERY_LEN] = {'\0'};
- GSList *list;
- int ret = 0;
+ int ret;
+ GList *list = NULL;
- pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
- filter->uid = uid;
- /*Get current locale*/
- locale = _get_system_locale();
- if (locale == NULL) {
- _LOGE("manifest locale is NULL\n");
- return PMINFO_R_ERROR;
+ if (handle == NULL || count == NULL) {
+ _LOGE("invalid parameter");
+ return PMINFO_R_EINVAL;
}
- ret = __open_manifest_db(uid, true);
- if (ret == -1) {
- _LOGE("Fail to open manifest DB\n");
- free(locale);
+ ret = _pkginfo_get_filtered_list((pkgmgrinfo_filter_x *)handle, uid, &list);
+ if (ret != PMINFO_R_OK)
return PMINFO_R_ERROR;
- }
- /*Start constructing query*/
- snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
+ *count = g_list_length(list);
- /*Get where clause*/
- for (list = filter->list; list; list = g_slist_next(list)) {
- __get_filter_condition(list->data, &condition);
- if (condition) {
- strncat(where, condition, sizeof(where) - strlen(where) -1);
- where[sizeof(where) - 1] = '\0';
- free(condition);
- condition = NULL;
- }
- if (g_slist_next(list)) {
- strncat(where, " and ", sizeof(where) - strlen(where) - 1);
- where[sizeof(where) - 1] = '\0';
- }
- }
- if (strlen(where) > 0) {
- strncat(query, where, sizeof(query) - strlen(query) - 1);
- query[sizeof(query) - 1] = '\0';
- }
+ g_list_free_full(list, free);
- /*Execute Query*/
- if (SQLITE_OK !=
- sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
- _LOGE("Don't execute query = %s error message = %s\n", query,
- error_message);
- sqlite3_free(error_message);
- ret = PMINFO_R_ERROR;
- *count = 0;
- goto err;
- }
- ret = PMINFO_R_OK;
-err:
- if (locale) {
- free(locale);
- locale = NULL;
- }
- __close_manifest_db();
- return ret;
+ return PMINFO_R_OK;
}
API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)