#define MEDIA_SVC_MAX_COMMIT_SIZE 200
-static __thread GList *g_media_svc_item_validity_query_list = NULL;
-static __thread GList *g_media_svc_insert_item_query_list = NULL;
-static __thread GList *g_media_svc_update_item_query_list = NULL;
+static __thread GList *g_media_svc_scanner_query_list = NULL;
static __thread GList *g_media_svc_update_list = NULL;
-int _media_svc_count_record_with_path(sqlite3 *handle, const char *storage_id, const char *path, int *count)
+int _media_svc_count_record_with_path(sqlite3 *handle, const char *path, int *count)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
- sql = sqlite3_mprintf("SELECT count(*) FROM '%q' WHERE path='%q'", storage_id, path);
+ sql = sqlite3_mprintf("SELECT count(*) FROM %q WHERE media_path=%Q", MEDIA_SVC_DB_TABLE_MEDIA, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_get_modified_time(sqlite3 *handle, const char *storage_id, const char *path, int *modified_time)
+int _media_svc_get_modified_time(sqlite3 *handle, const char *path, int *modified_time)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
- sql = sqlite3_mprintf("SELECT modified_time FROM '%q' WHERE path='%q'", storage_id, path);
+ sql = sqlite3_mprintf("SELECT media_modified_time FROM %q WHERE media_path=%Q", MEDIA_SVC_DB_TABLE_MEDIA, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_insert_item_with_data(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, bool stack_query, uid_t uid)
+int _media_svc_insert_item_with_data(bool is_direct, media_svc_content_info_s *content_info, bool stack_query, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- const char *db_fields = "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, folder_uuid, thumbnail_path, \
- title, album_id, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, description, \
- favourite, bitrate, bitpersample, samplerate, channel, duration, \
- longitude, latitude, altitude, exposure_time, fnumber, iso, model, width, height, datetaken, orientation, rating, is_drm, storage_type, timeline, sync_status, \
- file_name_pinyin, title_pinyin, album_pinyin, artist_pinyin, album_artist_pinyin, genre_pinyin, composer_pinyin, copyright_pinyin, description_pinyin, storage_uuid, is_360";
+ const char *db_fields = "media_id, media_path, media_display_name, media_type, media_mime_type, media_size, media_added_time, media_modified_time, folder_id, media_thumbnail_path, \
+ media_title, album_id, media_album, media_artist, media_album_artist, media_genre, media_composer, media_year, media_recorded_date, media_copyright, media_track_num, media_description, \
+ media_favourite, media_bitrate, media_bitpersample, media_samplerate, media_channel, media_duration, \
+ media_longitude, media_latitude, media_altitude, exposure_time, fnumber, iso, model, media_width, media_height, media_datetaken, media_orientation, media_rating, media_is_drm, media_storage_type, media_timeline, sync_status, \
+ media_file_name_pinyin, media_title_pinyin, media_album_pinyin, media_artist_pinyin, media_album_artist_pinyin, media_genre_pinyin, media_composer_pinyin, media_copyright_pinyin, media_description_pinyin, storage_uuid, media_360";
- const char *db_fields_basic = "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, folder_uuid, thumbnail_path, \
- album_id, favourite, is_drm, storage_type, timeline, sync_status, file_name_pinyin, storage_uuid, is_360";
+ const char *db_fields_basic = "media_id, media_path, media_display_name, media_type, media_mime_type, media_size, media_added_time, media_modified_time, folder_id, media_thumbnail_path, \
+ album_id, media_favourite, media_is_drm, media_storage_type, media_timeline, sync_status, media_file_name_pinyin, storage_uuid, media_360";
/* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
/* This code will be removed when sqlite3_mprintf works clearly */
_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, %Q, \
%Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %d, \
%d, %d, %d, %d, %d, %.6f, %.6f, %.6f, %Q, %.6f, %d, %Q, %d, %d, %Q, %d, \
%d, %d, %d, %d, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %d);",
- content_info->storage_uuid, db_fields,
+ MEDIA_SVC_DB_TABLE_MEDIA, db_fields,
content_info->media_uuid,
content_info->path,
content_info->file_name,
);
/* Check query length */
- if (sql != NULL && strlen(sql) >= (MEDIA_SVC_QUERY_LEN_MAX - 1)) {
+ if (sql != NULL && strlen(sql) >= (MEDIA_SVC_QUERY_LEN_MAX - 1) && is_direct == false) {
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, %d, %d, %Q, %Q, %d);",
- content_info->storage_uuid, db_fields_basic,
+ sql = sqlite3_mprintf("INSERT INTO %q(%q) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %Q, %Q, %d, %d, %d, %d, %d, %d, %d, %d, %Q, %Q, %d);",
+ MEDIA_SVC_DB_TABLE_MEDIA, db_fields_basic,
content_info->media_uuid,
content_info->path,
content_info->file_name,
content_info->sync_status,
content_info->file_name_pinyin,
content_info->storage_uuid,
- content_info->media_meta.is_360 /* 1st line */
+ content_info->media_meta.is_360
);
}
if (!stack_query) {
- ret = _media_svc_sql_query(sql, uid);
+ if (is_direct)
+ ret = _media_svc_sql_query_direct(sql, uid);
+ else
+ ret = _media_svc_sql_query(sql, uid);
+
SQLITE3_SAFE_FREE(sql);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("failed to insert item");
- return ret;
- }
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "failed to insert item");
} else {
- media_svc_debug("query : %s", sql);
- _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
+ media_svc_sec_debug("Query[%s]", sql);
+ _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
}
return MS_MEDIA_ERR_NONE;
char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
SQLITE3_SAFE_FREE(test_sql);
- /*Update Pinyin If Support Pinyin*/
- if (_media_svc_check_pinyin_support()) {
- if (STRING_VALID(content_info->file_name))
- _media_svc_get_pinyin_str(content_info->file_name, &content_info->file_name_pinyin);
- if (STRING_VALID(content_info->media_meta.title))
- _media_svc_get_pinyin_str(content_info->media_meta.title, &content_info->media_meta.title_pinyin);
- if (STRING_VALID(content_info->media_meta.album))
- _media_svc_get_pinyin_str(content_info->media_meta.album, &content_info->media_meta.album_pinyin);
- if (STRING_VALID(content_info->media_meta.artist))
- _media_svc_get_pinyin_str(content_info->media_meta.artist, &content_info->media_meta.artist_pinyin);
- if (STRING_VALID(content_info->media_meta.album_artist))
- _media_svc_get_pinyin_str(content_info->media_meta.album_artist, &content_info->media_meta.album_artist_pinyin);
- if (STRING_VALID(content_info->media_meta.genre))
- _media_svc_get_pinyin_str(content_info->media_meta.genre, &content_info->media_meta.genre_pinyin);
- if (STRING_VALID(content_info->media_meta.composer))
- _media_svc_get_pinyin_str(content_info->media_meta.composer, &content_info->media_meta.composer_pinyin);
- if (STRING_VALID(content_info->media_meta.copyright))
- _media_svc_get_pinyin_str(content_info->media_meta.copyright, &content_info->media_meta.copyright_pinyin);
- if (STRING_VALID(content_info->media_meta.description))
- _media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
- }
-
- char *sql = sqlite3_mprintf("UPDATE '%q' SET title=%Q, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, composer=%Q, copyright=%Q, description=%Q, \
- file_name_pinyin=%Q, title_pinyin=%Q, album_pinyin=%Q, artist_pinyin=%Q, album_artist_pinyin=%Q, genre_pinyin=%Q, composer_pinyin=%Q, copyright_pinyin=%Q, description_pinyin=%Q \
- WHERE path=%Q;",
- content_info->storage_uuid,
+ char *sql = sqlite3_mprintf("UPDATE %q SET media_title=%Q, media_album=%Q, media_artist=%Q, media_album_artist=%Q, media_genre=%Q, media_composer=%Q, media_copyright=%Q, media_description=%Q WHERE media_path=%Q;",
+ MEDIA_SVC_DB_TABLE_MEDIA,
content_info->media_meta.title,
content_info->media_meta.album,
content_info->media_meta.artist,
content_info->media_meta.composer,
content_info->media_meta.copyright,
content_info->media_meta.description,
- content_info->file_name_pinyin,
- content_info->media_meta.title_pinyin,
- content_info->media_meta.album_pinyin,
- content_info->media_meta.artist_pinyin,
- content_info->media_meta.album_artist_pinyin,
- content_info->media_meta.genre_pinyin,
- content_info->media_meta.composer_pinyin,
- content_info->media_meta.copyright_pinyin,
- content_info->media_meta.description_pinyin,
content_info->path
);
if (sql != NULL) {
- media_svc_debug("query : %s", sql);
- _media_svc_sql_query_add(&g_media_svc_update_item_query_list, &sql);
+ media_svc_debug("query[%s]", sql);
+ _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
} else {
media_svc_error("sqlite3_mprintf failed");
ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
return ret;
}
-int _media_svc_update_item_with_data(const char *storage_id, media_svc_content_info_s *content_info, uid_t uid)
+int _media_svc_update_item_with_data(bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
_media_svc_get_pinyin_str(content_info->media_meta.description, &content_info->media_meta.description_pinyin);
}
- char *sql = sqlite3_mprintf("UPDATE '%q' SET size=%lld, modified_time=%d, thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, album_artist=%Q, genre=%Q, \
- composer=%Q, year=%Q, recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d, duration=%d, \
- longitude=%f, latitude=%f, altitude=%f, exposure_time=%Q, fnumber=%f, iso=%d, model=%Q, width=%d, height=%d, datetaken=%Q, orientation=%d WHERE path=%Q;",
- storage_id,
+ char *sql = sqlite3_mprintf("UPDATE %q SET media_size=%lld, media_modified_time=%d, media_thumbnail_path=%Q, media_title=%Q, album_id=%d, media_album=%Q, media_artist=%Q, media_album_artist=%Q, media_genre=%Q, \
+ media_composer=%Q, media_year=%Q, media_recorded_date=%Q, media_copyright=%Q, media_track_num=%Q, media_description=%Q, media_bitrate=%d, media_bitpersample=%d, media_samplerate=%d, media_channel=%d, media_duration=%d, \
+ media_longitude=%f, media_latitude=%f, media_altitude=%f, exposure_time=%Q, fnumber=%f, iso=%d, model=%Q, media_width=%d, media_height=%d, media_datetaken=%Q, media_orientation=%d WHERE media_path=%Q;",
+ MEDIA_SVC_DB_TABLE_MEDIA,
content_info->size,
content_info->modified_time,
content_info->thumbnail_path,
content_info->path
);
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
+ /* Scanner use only batch insert */
+ if (is_direct) {
+ media_svc_sec_debug("Query [%s]", sql);
+ _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
+ } else {
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ }
return ret;
}
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
- sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%q' WHERE path='%q'", MEDIA_SVC_DB_VIEW_MEDIA, path);
+ sql = sqlite3_mprintf("SELECT media_thumbnail_path FROM %q WHERE media_path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *storage_id, const char *path, int *media_type)
+int _media_svc_delete_item_by_path(const char *path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
- sql = sqlite3_mprintf("SELECT media_type FROM '%q' WHERE path='%q'", storage_id, path);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("error when _media_svc_get_media_type_by_path. err = [%d]", ret);
- return ret;
- }
-
- *media_type = sqlite3_column_int(sql_stmt, 0);
+ sql = sqlite3_mprintf("DELETE FROM %q WHERE media_path=%Q;", MEDIA_SVC_DB_TABLE_MEDIA, path);
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_delete_item_by_path(const char *storage_id, const char *path, bool stack_query, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
-
- media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-
- sql = sqlite3_mprintf("DELETE FROM '%q' WHERE path='%q';", storage_id, path);
-
- if (!stack_query) {
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("failed to delete item");
- return ret;
- }
- } else {
- media_svc_debug("query : %s", sql);
- _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
- }
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "failed to delete item");
return ret;
}
-int _media_svc_update_item_validity(const char *storage_id, const char *path, int validity, bool stack_query, uid_t uid)
+int _media_svc_update_item_validity(const char *path, int validity, bool stack_query, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
char *sql = NULL;
- media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
media_svc_debug("path=[%s], validity=[%d]", path, validity);
- sql = sqlite3_mprintf("UPDATE '%q' SET validity=%d WHERE path= '%q';", storage_id, validity, path);
+ sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE media_path='%q';", MEDIA_SVC_DB_TABLE_MEDIA, validity, path);
if (!stack_query) {
- ret = _media_svc_sql_query(sql, uid);
+ ret = _media_svc_sql_query_direct(sql, uid);
SQLITE3_SAFE_FREE(sql);
} else {
- _media_svc_sql_query_add(&g_media_svc_item_validity_query_list, &sql);
+ _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
}
return ret;
}
-int _media_svc_update_thumbnail_path(const char *storage_id, const char *path, const char *thumb_path, uid_t uid)
+int _media_svc_update_thumbnail_path(const char *path, const char *thumb_path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char *sql = sqlite3_mprintf("UPDATE '%q' SET thumbnail_path=%Q WHERE path=%Q;", storage_id, thumb_path, path);
+ char *sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path=%Q WHERE media_path=%Q;", MEDIA_SVC_DB_TABLE_MEDIA, thumb_path, path);
ret = _media_svc_sql_query(sql, uid);
SQLITE3_SAFE_FREE(sql);
return ret;
}
-int _media_svc_update_item_by_path(const char *org_storage_id, 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, const char *folder_uuid, uid_t uid)
{
- /* update path, filename, modified_time, folder_uuid, thumbnail_path, */
-
- /* NOTICE (This operation is abnormal. Modifications should be cautious.)
- 1. Update source to destination info
- 2. Insert destination table
- 3. Remove source info
- */
int ret = MS_MEDIA_ERR_NONE;
- char *update = sqlite3_mprintf("UPDATE '%q' SET path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, storage_type=%d, storage_uuid='%q' WHERE path=%Q;",
- org_storage_id, dest_path, file_name, modified_time, folder_uuid, dest_storage, dst_storage_id, src_path);
- char *insert = sqlite3_mprintf("INSERT OR REPLACE INTO '%q' SELECT * FROM '%q' WHERE path = '%q';", dst_storage_id, org_storage_id, dest_path);
- char *remove = sqlite3_mprintf("DELETE FROM '%q' WHERE path = '%q';", org_storage_id, dest_path);
- char *query = NULL;
- if (strcmp(org_storage_id, dst_storage_id) != 0)
- query = sqlite3_mprintf("%s %s %s", update, insert, remove);
- else
- query = sqlite3_mprintf("%s %s", update, insert);
-
- SQLITE3_SAFE_FREE(update);
- SQLITE3_SAFE_FREE(insert);
- SQLITE3_SAFE_FREE(remove);
+ 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;",
+ MEDIA_SVC_DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_uuid, dest_storage, dst_storage_id, src_path);
ret = _media_svc_sql_query(query, uid);
SQLITE3_SAFE_FREE(query);
int ret = MS_MEDIA_ERR_NONE;
/* For multiples of 200, empty requests are possible */
- if (query_type == MEDIA_SVC_QUERY_UPDATE_COMMON) {
+ switch (query_type) {
+ case MEDIA_SVC_QUERY_UPDATE_COMMON:
if (g_media_svc_update_list == NULL || g_list_length(g_media_svc_update_list) == 0)
return MS_MEDIA_ERR_NONE;
- }
-
- ret = _media_svc_sql_begin_trans(uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- if (query_type == MEDIA_SVC_QUERY_SET_ITEM_VALIDITY)
- ret = _media_svc_sql_query_list(&g_media_svc_item_validity_query_list, uid);
- else if (query_type == MEDIA_SVC_QUERY_INSERT_ITEM)
- ret = _media_svc_sql_query_list(&g_media_svc_insert_item_query_list, uid);
- else if (query_type == MEDIA_SVC_QUERY_UPDATE_ITEM)
- ret = _media_svc_sql_query_list(&g_media_svc_update_item_query_list, uid);
- else if (query_type == MEDIA_SVC_QUERY_INSERT_FOLDER)
- ret = _media_svc_sql_query_list(_media_svc_get_folder_list_ptr(), uid);
- else if (query_type == MEDIA_SVC_QUERY_UPDATE_COMMON)
ret = _media_svc_sql_query_list(&g_media_svc_update_list, uid);
- else
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+ break;
+ case MEDIA_SVC_QUERY_SCANNER:
+ ret = _media_svc_sql_query_list_direct(&g_media_svc_scanner_query_list, uid);
+ break;
+ default:
+ media_svc_error("Wrong type[%d]", query_type);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Failed to request queries");
- ret = _media_svc_sql_end_trans(uid);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Failed to batch insert");
-
return MS_MEDIA_ERR_NONE;
}
return ret;
}
-int _media_svc_get_noti_info(sqlite3 *handle, const char *storage_id, const char *path, int update_item, media_svc_noti_item **item)
+int _media_svc_get_media(sqlite3 *handle, const char *sql, GPtrArray **path_list)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *path = NULL;
+
+ media_svc_retvm_if(!sql, MS_MEDIA_ERR_INVALID_PARAMETER, "query is NULL");
+ media_svc_retvm_if(!path_list, MS_MEDIA_ERR_INVALID_PARAMETER, "array is NULL");
+
+ ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step_simple() failed [%d]", ret);
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
+ path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
+ g_ptr_array_add(*path_list, path);
+ }
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return ret;
+}
+
+int _media_svc_get_noti_info(sqlite3 *handle, const char *path, media_svc_noti_item **item)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- int is_root_dir = FALSE;
media_svc_retvm_if(item == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "item is NULL");
- media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
- if (update_item == MS_MEDIA_ITEM_FILE)
- sql = sqlite3_mprintf("SELECT media_uuid, media_type, mime_type FROM '%q' WHERE path=%Q", storage_id, path);
- else if (update_item == MS_MEDIA_ITEM_DIRECTORY)
- sql = sqlite3_mprintf("SELECT folder_uuid FROM '%q' WHERE path=%Q AND storage_uuid='%q'", MEDIA_SVC_DB_TABLE_FOLDER, path, storage_id);
- else {
- media_svc_error("_media_svc_get_noti_info failed : update item");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
+ sql = sqlite3_mprintf("SELECT media_id, media_type, media_mime_type FROM %q WHERE media_path=%Q", MEDIA_SVC_DB_TABLE_MEDIA, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- if (ret != MS_MEDIA_ERR_NONE) {
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD && update_item == MS_MEDIA_ITEM_DIRECTORY) {
- media_svc_debug("This is root directory of media");
- sql_stmt = NULL;
- is_root_dir = TRUE;
- } else {
- media_svc_error("error when _media_svc_get_noti_info. err = [%d]", ret);
- return ret;
- }
- }
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step() failed [%d]", ret);
*item = calloc(1, sizeof(media_svc_noti_item));
if (*item == NULL) {
- media_svc_error("_media_svc_get_noti_info failed : calloc");
+ media_svc_error("Allocation failed");
return MS_MEDIA_ERR_OUT_OF_MEMORY;
}
- if (update_item == MS_MEDIA_ITEM_FILE) {
- (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
- (*item)->media_type = sqlite3_column_int(sql_stmt, 1);
- (*item)->mime_type = g_strdup((const char *)sqlite3_column_text(sql_stmt, 2));
- } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
- if (is_root_dir)
- (*item)->media_uuid = NULL;
- else
- (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
- }
+ (*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
+ (*item)->media_type = sqlite3_column_int(sql_stmt, 1);
+ (*item)->mime_type = g_strdup((const char *)sqlite3_column_text(sql_stmt, 2));
SQLITE3_FINALIZE(sql_stmt);