Change to row id instead of uuid for manageability.
Change-Id: I3ac10086173be81d2eb3f2b015f5e8003c9d7281
Signed-off-by: minje.ahn <minje.ahn@samsung.com>
__add_column_info(&column_list[DB_LIST_MEDIA], "media_size", DB_TYPE_INT, "DEFAULT 0", false, false, true);
__add_column_info(&column_list[DB_LIST_MEDIA], "media_added_time", DB_TYPE_INT, "DEFAULT 0", false, false, true);
__add_column_info(&column_list[DB_LIST_MEDIA], "media_modified_time", DB_TYPE_INT, "DEFAULT 0", false, false, true);
- __add_column_info(&column_list[DB_LIST_MEDIA], "folder_id", DB_TYPE_TEXT, "NOT NULL", false, false, false);
+ __add_column_info(&column_list[DB_LIST_MEDIA], "folder_id", DB_TYPE_INT, "DEFAULT 0", false, false, false);
__add_column_info(&column_list[DB_LIST_MEDIA], "media_thumbnail_path", DB_TYPE_TEXT, NULL, false, false, true);
__add_column_info(&column_list[DB_LIST_MEDIA], "media_title", DB_TYPE_TEXT, NULL, false, false, true);
__add_column_info(&column_list[DB_LIST_MEDIA], "album_id", DB_TYPE_INT, "DEFAULT 0", false, false, false);
__add_column_info(&column_list[DB_LIST_MEDIA], "media_360", DB_TYPE_INT, "DEFAULT 0", false, false, true);
/*folder*/
- __add_column_info(&column_list[DB_LIST_FOLDER], "folder_id", DB_TYPE_TEXT, "PRIMARY KEY", false, false, false);
+ __add_column_info(&column_list[DB_LIST_FOLDER], "folder_id", DB_TYPE_INT, "PRIMARY KEY AUTOINCREMENT", false, false, false);
__add_column_info(&column_list[DB_LIST_FOLDER], "folder_path", DB_TYPE_TEXT, "NOT NULL", true, false, false);
__add_column_info(&column_list[DB_LIST_FOLDER], "folder_name", DB_TYPE_TEXT, "NOT NULL", false, false, false);
__add_column_info(&column_list[DB_LIST_FOLDER], "folder_modified_time", DB_TYPE_INT, "DEFAULT 0", false, false, false);
#include "media-svc-util.h"
#include "media-svc-db-utils.h"
-static int __media_svc_get_folder_id(sqlite3 *handle, const char *path, char *folder_id)
+static int __media_svc_get_folder_id(sqlite3 *handle, const char *path, long long int *folder_id)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step failed [%d]", ret);
- SAFE_STRLCPY(folder_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
+ *folder_id = sqlite3_column_int64(sql_stmt, 0);
SQLITE3_FINALIZE(sql_stmt);
return ret;
}
-static int __media_svc_append_folder(bool is_direct, const char *storage_id, ms_user_storage_type_e storage_type, const char *folder_id, const char *folder_path, uid_t uid)
+static int __media_svc_append_folder(bool is_direct, const char *storage_id, ms_user_storage_type_e storage_type, const char *folder_path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
char *folder_name = NULL;
if (_media_svc_check_pinyin_support())
_media_svc_get_pinyin_str(folder_name, &folder_name_pinyin);
/* Sometime SQLITE3 returns NO_RECORD, so need to consider conflict case.. */
- char *sql = sqlite3_mprintf("INSERT OR IGNORE INTO %q (folder_id, folder_path, folder_name, storage_uuid, folder_storage_type, folder_modified_time, folder_name_pinyin) VALUES (%Q, %Q, %Q, %Q, '%d', '%d', %Q);",
- DB_TABLE_FOLDER, folder_id, folder_path, folder_name, storage_id, storage_type, folder_modified_date, folder_name_pinyin);
+ char *sql = sqlite3_mprintf("INSERT OR IGNORE INTO %q (folder_path, folder_name, storage_uuid, folder_storage_type, folder_modified_time, folder_name_pinyin) VALUES (%Q, %Q, %Q, '%d', '%d', %Q);",
+ DB_TABLE_FOLDER, folder_path, folder_name, storage_id, storage_type, folder_modified_date, folder_name_pinyin);
if (is_direct)
ret = _media_svc_sql_query_direct(sql, uid);
return ret;
}
-static int __media_svc_get_and_append_parent_folder(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, char *folder_id, uid_t uid)
+static int __media_svc_append_parent_folder(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
unsigned int next_pos = 0;
char *next = NULL;
char *dir_path = NULL;
const char *token = "/";
- char *folder_uuid = NULL;
char *internal_path = NULL;
if (storage_type == MS_USER_STORAGE_INTERNAL) {
ret = _media_svc_check_folder_by_path(handle, dir_path);
if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
- g_free(folder_uuid);
- folder_uuid = _media_info_generate_uuid();
- if (folder_uuid == NULL) {
- media_svc_error("Invalid UUID");
- g_free(dir_path);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- ret = __media_svc_append_folder(is_direct, storage_id, storage_type, folder_uuid, dir_path, uid);
+ ret = __media_svc_append_folder(is_direct, storage_id, storage_type, dir_path, uid);
if (ret != MS_MEDIA_ERR_NONE)
media_svc_error("__media_svc_append_folder is failed");
else
- media_svc_sec_debug("Append new folder path[%s] uuid[%s]", dir_path, folder_uuid);
+ media_svc_sec_debug("Append new folder path[%s]", dir_path);
}
g_free(dir_path);
} while (next);
- if (STRING_VALID(folder_uuid)) {
- SAFE_STRLCPY(folder_id, folder_uuid, MEDIA_SVC_UUID_SIZE + 1);
- g_free(folder_uuid);
- } else {
- media_svc_error("Fail to get folder_uuid");
- return MS_MEDIA_ERR_INTERNAL;
- }
-
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, char *folder_id, uid_t uid)
+int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, long long int *folder_id, uid_t uid)
{
char *dir_path = NULL;
int ret = MS_MEDIA_ERR_NONE;
dir_path = g_path_get_dirname(path);
ret = __media_svc_get_folder_id(handle, dir_path, folder_id);
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- ret = __media_svc_get_and_append_parent_folder(handle, is_direct, storage_id, dir_path, storage_type, folder_id, uid);
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+ ret = __media_svc_append_parent_folder(handle, is_direct, storage_id, dir_path, storage_type, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("__media_svc_append_parent_folder failed");
+ goto FINALIZE;
+ }
+ ret = __media_svc_get_folder_id(handle, dir_path, folder_id);
+ }
+FINALIZE:
g_free(dir_path);
return ret;
}
-int _media_svc_get_and_append_folder_id_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, uid_t uid)
+int _media_svc_append_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char folder_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
ret = _media_svc_check_folder_by_path(handle, path);
if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- ret = __media_svc_get_and_append_parent_folder(handle, true, storage_id, path, storage_type, folder_id, uid);
+ ret = __media_svc_append_parent_folder(handle, true, storage_id, path, storage_type, uid);
else
ret = _media_svc_set_folder_validity(true, path, 1, false, uid);
_media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
}
- char *sql = sqlite3_mprintf("INSERT INTO %q(%q) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %Q, \
+ char *sql = sqlite3_mprintf("INSERT INTO %q(%q) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %lld, \
%Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, \
%d, %d, %d, %d, %d, %.6f, %.6f, %.6f, %Q, %.6f, %d, %Q, %d, %d, %Q, %d, \
%d, %d, %d, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %d);",
content_info->size,
content_info->added_time,
content_info->modified_time,
- content_info->folder_uuid, /* 1st line */
+ content_info->folder_id, /* 1st line */
content_info->thumbnail_path,
content_info->media_meta.title,
content_info->album_id,
media_svc_debug("Query length is over %d byte.. So, remake query using only basic information..", MEDIA_SVC_QUERY_LEN_MAX - 1);
SQLITE3_SAFE_FREE(sql);
- sql = sqlite3_mprintf("INSERT INTO %q(%q) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %Q, %Q, %d, %d, %d, %d, %d, %d, %Q, %Q, %d);",
+ sql = sqlite3_mprintf("INSERT INTO %q(%q) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %lld, %Q, %d, %d, %d, %d, %d, %d, %Q, %Q, %d);",
DB_TABLE_MEDIA, db_fields_basic,
content_info->media_uuid,
content_info->path,
content_info->size,
content_info->added_time,
content_info->modified_time,
- content_info->folder_uuid,
+ content_info->folder_id,
content_info->thumbnail_path,
content_info->album_id,
content_info->is_drm,
return ret;
}
-int _media_svc_update_item_by_path(const char *src_path, const char *dst_storage_id, ms_user_storage_type_e dest_storage, const char *dest_path, const char *file_name, int modified_time, const char *folder_uuid, uid_t uid)
+int _media_svc_update_item_by_path(const char *src_path, const char *dst_storage_id, ms_user_storage_type_e dest_storage, const char *dest_path, const char *file_name, int modified_time, long long int folder_id, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char *query = sqlite3_mprintf("UPDATE %q SET media_path=%Q, media_display_name=%Q, media_modified_time=%d, folder_id=%Q, media_storage_type=%d, storage_uuid='%q' WHERE media_path=%Q;",
- DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_uuid, dest_storage, dst_storage_id, src_path);
+ char *query = sqlite3_mprintf("UPDATE %q SET media_path=%Q, media_display_name=%Q, media_modified_time=%d, folder_id=%lld, media_storage_type=%d, storage_uuid='%q' WHERE media_path=%Q;",
+ DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_id, dest_storage, dst_storage_id, src_path);
ret = _media_svc_sql_query(query, uid);
SQLITE3_SAFE_FREE(query);
"text/x-iMelody"
};
-char *_media_info_generate_uuid(void)
+static char *__media_info_generate_uuid(void)
{
uuid_t uuid_value;
char uuid_unparsed[37];
content_info->storage_type = storage_type;
time(&content_info->added_time);
- content_info->media_uuid = _media_info_generate_uuid();
+ content_info->media_uuid = __media_info_generate_uuid();
media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
content_info->file_name = g_path_get_basename(path);
g_free(content_info->path);
g_free(content_info->file_name);
g_free(content_info->mime_type);
- g_free(content_info->folder_uuid);
g_free(content_info->thumbnail_path);
g_free(content_info->storage_uuid);
int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
+ long long int folder_id = 0;
media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
/*Set or Get folder id*/
- ret = _media_svc_get_and_append_folder_id_by_path(handle, true, storage_id, path, storage_type, folder_uuid, uid);
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, true, storage_id, path, storage_type, &folder_id, uid);
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
- content_info.folder_uuid = g_strdup(folder_uuid);
- media_svc_retv_del_if(content_info.folder_uuid == NULL, MS_MEDIA_ERR_INTERNAL, &content_info);
+ content_info.folder_id = folder_id;
+ media_svc_retv_del_if(content_info.folder_id <= 0, MS_MEDIA_ERR_INTERNAL, &content_info);
ret = _media_svc_insert_item_with_data(true, &content_info, true, uid);
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
+ long long int folder_id = 0;
media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
/*Set or Get folder id*/
- ret = _media_svc_get_and_append_folder_id_by_path(handle, false, storage_id, path, storage_type, folder_uuid, uid);
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, false, storage_id, path, storage_type, &folder_id, uid);
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
- content_info.folder_uuid = g_strdup(folder_uuid);
- media_svc_retv_del_if(content_info.folder_uuid == NULL, MS_MEDIA_ERR_INTERNAL, &content_info);
+ content_info.folder_id = folder_id;
+ media_svc_retv_del_if(content_info.folder_id <= 0, MS_MEDIA_ERR_INTERNAL, &content_info);
/* Extracting thumbnail */
if (content_info.thumbnail_path == NULL) {
char *file_name = NULL;
char *folder_path = NULL;
int modified_time = 0;
- char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
+ long long int folder_id = 0;
char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
char dst_stg_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
ms_user_storage_type_e org_stg_type = MS_USER_STORAGE_INTERNAL;
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/*check and update folder*/
- ret = _media_svc_get_and_append_folder_id_by_path(handle, false, dst_stg_id, dest_path, dst_stg_type, folder_uuid, uid);
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, false, dst_stg_id, dest_path, dst_stg_type, &folder_id, uid);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/*get filename*/
_media_svc_remove_file(old_thumb_path);
/*move item*/
- ret = _media_svc_update_item_by_path(src_path, dst_stg_id, dst_stg_type, dest_path, file_name, modified_time, folder_uuid, uid);
+ ret = _media_svc_update_item_by_path(src_path, dst_stg_id, dst_stg_type, dest_path, file_name, modified_time, folder_id, uid);
g_free(file_name);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
- return _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, uid);
+ return _media_svc_append_by_folder_path(handle, storage_id, path, storage_type, uid);
}
int media_svc_set_folder_validity(const char *start_path, int validity, bool is_recursive, uid_t uid)
#include <media-util.h>
int _media_svc_update_folder_modified_time(const char *folder_path, uid_t uid);
-int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, char *folder_id, uid_t uid);
-int _media_svc_get_and_append_folder_id_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, uid_t uid);
+int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, long long int *folder_id, uid_t uid);
+int _media_svc_append_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, uid_t uid);
int _media_svc_set_folder_validity(bool is_direct, const char *start_path, int validity, bool is_recursive, uid_t uid);
int _media_svc_check_folder_by_path(sqlite3 *handle, const char *path);
int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path);
int _media_svc_delete_item_by_path(const char *path, uid_t uid);
int _media_svc_update_item_validity(const char *path, int validity, bool stack_query, uid_t uid);
-int _media_svc_update_item_by_path(const char *src_path, const char *dst_storage_id, ms_user_storage_type_e dest_storage, const char *dest_path, const char *file_name, int modified_time, const char *folder_uuid, uid_t uid);
+int _media_svc_update_item_by_path(const char *src_path, const char *dst_storage_id, ms_user_storage_type_e dest_storage, const char *dest_path, const char *file_name, int modified_time, long long int folder_id, uid_t uid);
int _media_svc_list_query_do(media_svc_query_type_e query_type, uid_t uid);
int _media_svc_update_thumbnail_path(const char *path, const char *thumb_path, uid_t uid);
int _media_svc_get_noti_info(sqlite3 *handle, const char *path, media_svc_noti_item **item);
time_t added_time; /**< added time, time_t */
time_t modified_time; /**< modified time, time_t */
time_t timeline; /**< timeline of media, time_t */
- char *folder_uuid; /**< Unique ID of folder */
+ long long int folder_id; /**< Unique ID of folder */
int album_id; /**< Unique ID of album */
char *thumbnail_path; /**< Thumbnail image file path */
int is_drm; /**< is_drm. o or 1 */
MEDIA_SVC_SEARCH_TYPE_DB,
} media_svc_search_type_e;
-char * _media_info_generate_uuid(void);
void _media_svc_remove_file(const char *path);
int _media_svc_get_thumbnail_path(char *thumb_path, const char *pathname, const char *img_format, uid_t uid);
int _media_svc_get_file_time(const char *full_path);