*/
#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <media-util-err.h>
#include "media-svc-media.h"
#include "media-svc-media-folder.h"
-#include "media-svc-error.h"
#include "media-svc-debug.h"
#include "media-svc-util.h"
#include "media-svc-db-utils.h"
#include "media-svc-noti.h"
-typedef struct{
- char thumbnail_path[MEDIA_SVC_PATHNAME_SIZE];
-}media_svc_thumbnailpath_s;
+#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;
-__thread GList *g_media_svc_move_item_query_list = NULL;
+static __thread GList *g_media_svc_scanner_query_list = NULL;
+static __thread GList *g_media_svc_update_list = NULL;
-static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, media_svc_storage_type_e storage_type, int *count);
-static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, media_svc_storage_type_e storage_type,
- int count, media_svc_thumbnailpath_s * thumb_path);
-static int __media_svc_count_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *folder_path, int *count);
-static int __media_svc_get_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *folder_path,
- int count, media_svc_thumbnailpath_s * thumb_path);
-
-static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, media_svc_storage_type_e storage_type, int *count)
+int _media_svc_check_data_by_path(sqlite3 *handle, const char *path)
{
- int ret = MEDIA_INFO_ERROR_NONE;
+ int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE validity=0 AND storage_type=%d AND thumbnail_path IS NOT NULL",
- MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- if (ret != MEDIA_INFO_ERROR_NONE) {
- media_svc_error("error when __media_svc_count_invalid_records_with_thumbnail. err = [%d]", ret);
- return ret;
- }
+ char *sql = NULL;
- *count = sqlite3_column_int(sql_stmt, 0);
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
+ sql = sqlite3_mprintf("SELECT 1 FROM %q WHERE media_path=%Q", 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);
SQLITE3_FINALIZE(sql_stmt);
- return MEDIA_INFO_ERROR_NONE;
-
+ return ret;
}
-static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, media_svc_storage_type_e storage_type,
- int count, media_svc_thumbnailpath_s * thumb_path)
+int _media_svc_get_modified_time(sqlite3 *handle, const char *path, int *modified_time)
{
- int err = -1;
- int idx = 0;
+ int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
- char *sql = sqlite3_mprintf("select thumbnail_path from %s WHERE validity=0 AND storage_type=%d AND thumbnail_path IS NOT NULL",
- MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
-
- media_svc_debug("[SQL query] : %s", sql);
-
- err = sqlite3_prepare_v2(handle, sql, -1, &sql_stmt, NULL);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("prepare error [%s]", sqlite3_errmsg(handle));
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
-
- while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
- _strncpy_safe(thumb_path[idx].thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(thumb_path[idx]));
- //media_svc_debug("thumb_path[%d]=[%s]", idx, thumb_path[idx].thumbnail_path);
- idx++;
- }
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MEDIA_INFO_ERROR_NONE;
-}
-
-static int __media_svc_count_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *folder_path, int *count)
-{
- int ret = MEDIA_INFO_ERROR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE validity=0 AND path LIKE '%q/%%' AND thumbnail_path IS NOT NULL",
- MEDIA_SVC_DB_TABLE_MEDIA, folder_path);
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
+ sql = sqlite3_mprintf("SELECT media_modified_time FROM %q WHERE media_path=%Q", 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);
- if (ret != MEDIA_INFO_ERROR_NONE) {
- media_svc_error("error when __media_svc_count_invalid_folder_records_with_thumbnail. err = [%d]", ret);
- return ret;
- }
-
- *count = sqlite3_column_int(sql_stmt, 0);
+ *modified_time = sqlite3_column_int(sql_stmt, 0);
SQLITE3_FINALIZE(sql_stmt);
- return MEDIA_INFO_ERROR_NONE;
-
+ return MS_MEDIA_ERR_NONE;
}
-static int __media_svc_get_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *folder_path,
- int count, media_svc_thumbnailpath_s * thumb_path)
+int _media_svc_insert_item_with_data(bool is_direct, media_svc_content_info_s *content_info, bool stack_query, uid_t uid)
{
- int err = -1;
- int idx = 0;
- sqlite3_stmt *sql_stmt = NULL;
+ int ret = MS_MEDIA_ERR_NONE;
- char *sql = sqlite3_mprintf("select thumbnail_path from %s WHERE validity=0 AND path LIKE '%q/%%' AND thumbnail_path IS NOT NULL",
- MEDIA_SVC_DB_TABLE_MEDIA, folder_path);
+ 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, \
+ 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";
- media_svc_debug("[SQL query] : %s", sql);
+ 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, media_file_name_pinyin, storage_uuid, media_360";
- err = sqlite3_prepare_v2(handle, sql, -1, &sql_stmt, NULL);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("prepare error [%s]", sqlite3_errmsg(handle));
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
-
- while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
- _strncpy_safe(thumb_path[idx].thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(thumb_path[idx]));
- idx++;
+ /* 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 */
+ 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("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, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %d);",
+ DB_TABLE_MEDIA, db_fields,
+ content_info->media_uuid,
+ content_info->path,
+ content_info->file_name,
+ content_info->media_type,
+ content_info->mime_type,
+ content_info->size,
+ content_info->added_time,
+ content_info->modified_time,
+ content_info->folder_uuid, /* 1st line */
+ content_info->thumbnail_path,
+ content_info->media_meta.title,
+ content_info->album_id,
+ content_info->media_meta.album,
+ content_info->media_meta.artist,
+ content_info->media_meta.album_artist,
+ content_info->media_meta.genre,
+ content_info->media_meta.composer,
+ content_info->media_meta.year,
+ content_info->media_meta.recorded_date,
+ content_info->media_meta.copyright,
+ content_info->media_meta.track_num,
+ content_info->media_meta.description,
+ content_info->favourate, /* 2nd line */
+ content_info->media_meta.bitrate,
+ content_info->media_meta.bitpersample,
+ content_info->media_meta.samplerate,
+ content_info->media_meta.channel,
+ content_info->media_meta.duration,
+ content_info->media_meta.longitude,
+ content_info->media_meta.latitude,
+ content_info->media_meta.altitude,
+ content_info->media_meta.exposure_time,
+ content_info->media_meta.fnumber,
+ content_info->media_meta.iso,
+ content_info->media_meta.model,
+ content_info->media_meta.width,
+ content_info->media_meta.height,
+ content_info->media_meta.datetaken,
+ content_info->media_meta.orientation, /* 3rd line */
+ content_info->media_meta.rating,
+ content_info->is_drm,
+ content_info->storage_type,
+ content_info->timeline,
+ 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->storage_uuid,
+ content_info->media_meta.is_360 /* 4th line */
+ );
+
+ /* Check query length */
+ 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, %Q, %Q, %d);",
+ DB_TABLE_MEDIA, db_fields_basic,
+ content_info->media_uuid,
+ content_info->path,
+ content_info->file_name,
+ content_info->media_type,
+ content_info->mime_type,
+ content_info->size,
+ content_info->added_time,
+ content_info->modified_time,
+ content_info->folder_uuid,
+ content_info->thumbnail_path,
+ content_info->album_id,
+ content_info->favourate,
+ content_info->is_drm,
+ content_info->storage_type,
+ content_info->timeline,
+ content_info->file_name_pinyin,
+ content_info->storage_uuid,
+ content_info->media_meta.is_360
+ );
+ }
+
+ if (!stack_query) {
+ if (is_direct)
+ ret = _media_svc_sql_query_direct(sql, uid);
+ else
+ ret = _media_svc_sql_query(sql, uid);
+
+ SQLITE3_SAFE_FREE(sql);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "failed to insert item");
+ } else {
+ media_svc_sec_debug("Query[%s]", sql);
+ _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
}
- SQLITE3_FINALIZE(sql_stmt);
-
- return MEDIA_INFO_ERROR_NONE;
-}
-
-int _media_svc_count_record_with_path(sqlite3 *handle, const char *path, int *count)
-{
- int ret = MEDIA_INFO_ERROR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
-
- char *sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
-
- *count = sqlite3_column_int(sql_stmt, 0);
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MEDIA_INFO_ERROR_NONE;
+ return MS_MEDIA_ERR_NONE;
}
-int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, int is_burst, bool stack_query)
+int _media_svc_update_meta_with_data(media_svc_content_info_s *content_info)
{
- media_svc_debug("");
- int err = -1;
- char *burst_id = NULL;
-
- 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, genre, composer, year, recorded_date, copyright, track_num, description,\
- bitrate, samplerate, channel, duration, longitude, latitude, altitude, width, height, datetaken, orientation,\
- rating, is_drm, storage_type, burst_id";
+ int ret = MS_MEDIA_ERR_NONE;
+ media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INTERNAL, "content_info is NULL");
/* 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 */
char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
- sqlite3_free(test_sql);
-
- if (is_burst) {
- int burst_id_int = 0;
- err = _media_svc_get_burst_id(handle, &burst_id_int);
- if (err < 0) {
- burst_id = NULL;
- }
-
- if (burst_id_int > 0) {
- media_svc_debug("Burst id : %d", burst_id_int);
- burst_id = sqlite3_mprintf("%d", burst_id_int);
- }
-
- /* Get thumbnail for burst shot */
- char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
- int width = 0;
- int height = 0;
-
- err = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height);
- if (err < 0) {
- media_svc_error("thumbnail_request_from_db failed: %d", err);
- } else {
- media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
- err = __media_svc_malloc_and_strncpy(&(content_info->thumbnail_path), thumb_path);
- if (err < 0) {
- content_info->thumbnail_path = NULL;
- }
- }
-
- if (content_info->media_meta.width <= 0)
- content_info->media_meta.width = width;
-
- if (content_info->media_meta.height <= 0)
- content_info->media_meta.height = height;
- }
-
- char *sql = sqlite3_mprintf("INSERT INTO %s (%s) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %Q, \
- %Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, \
- %d, %d, %d, %d, %.2f, %.2f, %.2f, %d, %d, %Q, %d, \
- %d, %d, %d, %Q);",
- MEDIA_SVC_DB_TABLE_MEDIA, db_fields,
- content_info->media_uuid,
- content_info->path,
- content_info->file_name,
- content_info->media_type,
- content_info->mime_type,
- content_info->size,
- content_info->added_time,
- content_info->modified_time,
- content_info->folder_uuid,
- content_info->thumbnail_path, //
- content_info->media_meta.title,
- content_info->album_id,
- content_info->media_meta.album,
- content_info->media_meta.artist,
- content_info->media_meta.genre,
- content_info->media_meta.composer,
- content_info->media_meta.year,
- content_info->media_meta.recorded_date,
- content_info->media_meta.copyright,
- content_info->media_meta.track_num,
- content_info->media_meta.description, //
- content_info->media_meta.bitrate,
- content_info->media_meta.samplerate,
- content_info->media_meta.channel,
- content_info->media_meta.duration,
- content_info->media_meta.longitude,
- content_info->media_meta.latitude,
- content_info->media_meta.altitude,
- content_info->media_meta.width,
- content_info->media_meta.height,
- content_info->media_meta.datetaken,
- content_info->media_meta.orientation,
- content_info->media_meta.rating,
- content_info->is_drm,
- content_info->storage_type,
- burst_id);
-
- if (burst_id) sqlite3_free(burst_id);
- burst_id = NULL;
-
- if(!stack_query) {
- err = _media_svc_sql_query(handle, sql);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("failed to insert item");
-
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
+ SQLITE3_SAFE_FREE(test_sql);
+
+ 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;",
+ DB_TABLE_MEDIA,
+ content_info->media_meta.title,
+ content_info->media_meta.album,
+ content_info->media_meta.artist,
+ content_info->media_meta.album_artist,
+ content_info->media_meta.genre,
+ content_info->media_meta.composer,
+ content_info->media_meta.copyright,
+ content_info->media_meta.description,
+ content_info->path
+ );
+
+ if (sql != NULL) {
+ media_svc_debug("query[%s]", sql);
+ _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
} else {
- media_svc_debug("query : %s", sql);
- _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
+ media_svc_error("sqlite3_mprintf failed");
+ ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
}
- return MEDIA_INFO_ERROR_NONE;
+ return ret;
}
-int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info)
+int _media_svc_update_item_with_data(bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
{
- int err = -1;
+ int ret = MS_MEDIA_ERR_NONE;
/* 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 */
char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
- sqlite3_free(test_sql);
-
- char *sql = sqlite3_mprintf("UPDATE %s SET \
- size=%lld, modified_time=%d, thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, genre=%Q, \
- composer=%Q, year=%Q, recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, \
- bitrate=%d, samplerate=%d, channel=%d, duration=%d, longitude=%f, latitude=%f, altitude=%f, width=%d, height=%d, datetaken=%Q, \
- orientation=%d WHERE path=%Q",
- MEDIA_SVC_DB_TABLE_MEDIA,
- content_info->size,
- content_info->modified_time,
- content_info->thumbnail_path,
- content_info->media_meta.title,
- content_info->album_id,
- content_info->media_meta.album,
- content_info->media_meta.artist,
- content_info->media_meta.genre,
- content_info->media_meta.composer,
- content_info->media_meta.year,
- content_info->media_meta.recorded_date,
- content_info->media_meta.copyright,
- content_info->media_meta.track_num,
- content_info->media_meta.description,
- content_info->media_meta.bitrate,
- content_info->media_meta.samplerate,
- content_info->media_meta.channel,
- content_info->media_meta.duration,
- content_info->media_meta.longitude,
- content_info->media_meta.latitude,
- content_info->media_meta.altitude,
- content_info->media_meta.width,
- content_info->media_meta.height,
- content_info->media_meta.datetaken,
- content_info->media_meta.orientation,
- content_info->path
- );
-
- err = _media_svc_sql_query(handle, sql);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("failed to update item");
-
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ 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 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, validity=1 WHERE media_path=%Q;",
+ DB_TABLE_MEDIA,
+ content_info->size,
+ content_info->modified_time,
+ content_info->thumbnail_path,
+ content_info->media_meta.title,
+ content_info->album_id,
+ content_info->media_meta.album,
+ content_info->media_meta.artist,
+ content_info->media_meta.album_artist,
+ content_info->media_meta.genre,
+ content_info->media_meta.composer,
+ content_info->media_meta.year,
+ content_info->media_meta.recorded_date,
+ content_info->media_meta.copyright,
+ content_info->media_meta.track_num,
+ content_info->media_meta.description,
+ content_info->media_meta.bitrate,
+ content_info->media_meta.bitpersample,
+ content_info->media_meta.samplerate,
+ content_info->media_meta.channel,
+ content_info->media_meta.duration,
+ content_info->media_meta.longitude,
+ content_info->media_meta.latitude,
+ content_info->media_meta.altitude,
+ content_info->media_meta.exposure_time,
+ content_info->media_meta.fnumber,
+ content_info->media_meta.iso,
+ content_info->media_meta.model,
+ content_info->media_meta.width,
+ content_info->media_meta.height,
+ content_info->media_meta.datetaken,
+ content_info->media_meta.orientation,
+ content_info->path
+ );
+
+ /* 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 MEDIA_INFO_ERROR_NONE;
+ return ret;
}
int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path)
{
- int ret = MEDIA_INFO_ERROR_NONE;
+ int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
- char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM %s WHERE path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
+ sql = sqlite3_mprintf("SELECT media_thumbnail_path FROM %q WHERE media_path='%q'", DB_TABLE_MEDIA, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- if (ret != MEDIA_INFO_ERROR_NONE) {
- if(ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
+ if (ret != MS_MEDIA_ERR_NONE) {
+ if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
media_svc_debug("there is no thumbnail.");
- }
- else {
+ else
media_svc_error("error when _media_svc_get_thumbnail_path_by_path. err = [%d]", ret);
- }
- return ret;
- }
-
- _strncpy_safe(thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_PATHNAME_SIZE);
- SQLITE3_FINALIZE(sql_stmt);
-
- return MEDIA_INFO_ERROR_NONE;
-}
-
-int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *path, int *media_type)
-{
- int ret = MEDIA_INFO_ERROR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
-
- char *sql = sqlite3_mprintf("SELECT media_type FROM %s WHERE path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- if (ret != MEDIA_INFO_ERROR_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);
+ SAFE_STRLCPY(thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_PATHNAME_SIZE);
SQLITE3_FINALIZE(sql_stmt);
- return MEDIA_INFO_ERROR_NONE;
+ return MS_MEDIA_ERR_NONE;
}
-int _media_svc_delete_item_by_path(sqlite3 *handle, const char *path)
+int _media_svc_delete_item_by_path(const char *path, uid_t uid)
{
- int err = -1;
- char *sql = sqlite3_mprintf("DELETE FROM %s WHERE validity=1 AND path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
-
- err = _media_svc_sql_query(handle, sql);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("It failed to delete item (%d)", err);
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = NULL;
- return MEDIA_INFO_ERROR_NONE;
-}
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-int _media_svc_truncate_table(sqlite3 *handle, media_svc_storage_type_e storage_type)
-{
- int err = -1;
- char *sql = sqlite3_mprintf("DELETE FROM %s WHERE storage_type=%d", MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
-
- err = _media_svc_sql_query(handle, sql);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("It failed to truncate table (%d)", err);
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
+ sql = sqlite3_mprintf("DELETE FROM %q WHERE media_path=%Q;", DB_TABLE_MEDIA, path);
- return MEDIA_INFO_ERROR_NONE;
+ 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_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e storage_type)
+int _media_svc_update_item_validity(const char *path, int validity, bool stack_query, uid_t uid)
{
- int idx = 0;
- media_svc_thumbnailpath_s *thumbpath_record = NULL;
- int err = -1;
- int invalid_count = 0;
- int ret = MEDIA_INFO_ERROR_NONE;
-
- ret = __media_svc_count_invalid_records_with_thumbnail(handle, storage_type, &invalid_count);
- media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
-
- media_svc_debug("invalid count: %d\n", invalid_count);
-
- if (invalid_count > 0) {
- thumbpath_record = (media_svc_thumbnailpath_s *)calloc( invalid_count, sizeof(media_svc_thumbnailpath_s));
- if (thumbpath_record == NULL) {
- media_svc_error("fail to memory allocation");
- return MEDIA_INFO_ERROR_OUT_OF_MEMORY;
- }
-
- ret = __media_svc_get_invalid_records_with_thumbnail(handle, storage_type, invalid_count, thumbpath_record);
- if (ret != MEDIA_INFO_ERROR_NONE) {
- media_svc_error("error when get thumbnail record");
- SAFE_FREE(thumbpath_record);
- return ret;
- }
- } else {
- media_svc_debug("There is no item with thumbnail");
- }
-
- char *sql = sqlite3_mprintf("DELETE FROM %s WHERE validity = 0 AND storage_type=%d", MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
- err = _media_svc_sql_query(handle, sql);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("To delete invalid items is failed(%d)", err);
- SAFE_FREE(thumbpath_record);
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
+ int ret = MS_MEDIA_ERR_NONE;
+ char *sql = NULL;
- /*Delete thumbnails*/
- for (idx = 0; idx < invalid_count; idx++) {
- if (strlen(thumbpath_record[idx].thumbnail_path) > 0) {
- if (_media_svc_remove_file(thumbpath_record[idx].thumbnail_path) == FALSE) {
- media_svc_error("fail to remove thumbnail file.");
- //SAFE_FREE(thumbpath_record);
- //return MEDIA_INFO_ERROR_INTERNAL;
- }
- }
- }
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
- SAFE_FREE(thumbpath_record);
+ media_svc_debug("path=[%s], validity=[%d]", path, validity);
- return MEDIA_INFO_ERROR_NONE;
-}
+ sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE media_path='%q';", DB_TABLE_MEDIA, validity, path);
-int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *folder_path)
-{
- int idx = 0;
- media_svc_thumbnailpath_s *thumbpath_record = NULL;
- int err = -1;
- int invalid_count = 0;
- int ret = MEDIA_INFO_ERROR_NONE;
-
- ret = __media_svc_count_invalid_folder_records_with_thumbnail(handle, folder_path, &invalid_count);
- media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
-
- media_svc_debug("invalid count: %d\n", invalid_count);
-
- if (invalid_count > 0) {
- thumbpath_record = (media_svc_thumbnailpath_s *)calloc( invalid_count, sizeof(media_svc_thumbnailpath_s));
- if (thumbpath_record == NULL) {
- media_svc_error("fail to memory allocation");
- return MEDIA_INFO_ERROR_OUT_OF_MEMORY;
- }
-
- ret = __media_svc_get_invalid_folder_records_with_thumbnail(handle, folder_path, invalid_count, thumbpath_record);
- if (ret != MEDIA_INFO_ERROR_NONE) {
- media_svc_error("error when get thumbnail record");
- SAFE_FREE(thumbpath_record);
- return ret;
- }
+ if (!stack_query) {
+ ret = _media_svc_sql_query_direct(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
} else {
- media_svc_debug("There is no item with thumbnail");
- }
-
- char *sql = sqlite3_mprintf("DELETE FROM %s WHERE validity = 0 AND path LIKE '%q/%%'", MEDIA_SVC_DB_TABLE_MEDIA, folder_path);
- err = _media_svc_sql_query(handle, sql);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("To delete invalid items is failed(%d)", err);
- SAFE_FREE(thumbpath_record);
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
-
- /*Delete thumbnails*/
- for (idx = 0; idx < invalid_count; idx++) {
- if (strlen(thumbpath_record[idx].thumbnail_path) > 0) {
- if (_media_svc_remove_file(thumbpath_record[idx].thumbnail_path) == FALSE) {
- media_svc_error("fail to remove thumbnail file [%s].", thumbpath_record[idx].thumbnail_path);
- //SAFE_FREE(thumbpath_record);
- //return MEDIA_INFO_ERROR_INTERNAL;
- }
- }
+ _media_svc_sql_query_add(&g_media_svc_scanner_query_list, &sql);
}
- SAFE_FREE(thumbpath_record);
-
- return MEDIA_INFO_ERROR_NONE;
+ return ret;
}
-
-int _media_svc_update_item_validity(sqlite3 *handle, const char *path, int validity, bool stack_query)
+int _media_svc_update_thumbnail_path(const char *path, const char *thumb_path, uid_t uid)
{
- int err = -1;
+ int ret = MS_MEDIA_ERR_NONE;
- char *sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE path= '%q'", MEDIA_SVC_DB_TABLE_MEDIA, validity, path);
+ char *sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path=%Q WHERE media_path=%Q;", DB_TABLE_MEDIA, thumb_path, path);
- if(!stack_query) {
- err = _media_svc_sql_query(handle, sql);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("To update item as valid is failed(%d)", err);
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
- } else {
- _media_svc_sql_query_add(&g_media_svc_item_validity_query_list, &sql);
- }
+ ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
- return MEDIA_INFO_ERROR_NONE;
+ return ret;
}
-int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *path, const char *thumb_path)
+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 err = -1;
+ int ret = MS_MEDIA_ERR_NONE;
- char *sql = sqlite3_mprintf("UPDATE %s SET thumbnail_path=%Q WHERE path= %Q", MEDIA_SVC_DB_TABLE_MEDIA, thumb_path, path);
+ 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);
- err = _media_svc_sql_query(handle, sql);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("To update thumb path failed(%d)", err);
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
+ ret = _media_svc_sql_query(query, uid);
+ SQLITE3_SAFE_FREE(query);
- return MEDIA_INFO_ERROR_NONE;
+ return ret;
}
-int _media_svc_update_storage_item_validity(sqlite3 *handle, media_svc_storage_type_e storage_type, int validity)
+int _media_svc_list_query_do(media_svc_query_type_e query_type, uid_t uid)
{
- int err = -1;
- char *sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE storage_type=%d", MEDIA_SVC_DB_TABLE_MEDIA, validity, storage_type);
- err = _media_svc_sql_query(handle, sql);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("To update item as valid is failed(%d)", err);
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
-
- return MEDIA_INFO_ERROR_NONE;
-}
+ int ret = MS_MEDIA_ERR_NONE;
-int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity)
-{
- int err = -1;
- int ret = MEDIA_INFO_ERROR_NONE;
- char *sql = NULL;
- char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
- sqlite3_stmt *sql_stmt = NULL;
+ /* For multiples of 200, empty requests are possible */
+ switch (query_type) {
+ case MEDIA_SVC_QUERY_SCANNER:
+ ret = _media_svc_sql_query_list_direct(&g_media_svc_scanner_query_list, uid);
+ break;
+ 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;
- /*Get folder ID*/
- sql = sqlite3_mprintf("SELECT folder_uuid FROM %s WHERE path='%q'", MEDIA_SVC_DB_TABLE_FOLDER, folder_path);
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- if (ret != MEDIA_INFO_ERROR_NONE) {
- media_svc_error("error when get folder_id. err = [%d]", ret);
- return ret;
+ ret = _media_svc_sql_query_list(&g_media_svc_update_list, uid);
+ break;
+ default:
+ media_svc_error("Wrong type[%d]", query_type);
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- _strncpy_safe(folder_uuid, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE+1);
- SQLITE3_FINALIZE(sql_stmt);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Failed to request queries");
- /*Update folder item validity*/
- sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE folder_uuid='%q'", MEDIA_SVC_DB_TABLE_MEDIA, validity, folder_uuid);
- err = _media_svc_sql_query(handle, sql);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("To update folder item as valid is failed(%d)", err);
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
-
- return MEDIA_INFO_ERROR_NONE;
-}
-
-int _media_svc_update_recursive_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity)
-{
- int err = -1;
-
- /*Update folder item validity*/
- char *sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE path LIKE '%q/%%'", MEDIA_SVC_DB_TABLE_MEDIA, validity, folder_path);
- err = _media_svc_sql_query(handle, sql);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("To update recursive folder item validity is failed(%d)", err);
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
-
- return MEDIA_INFO_ERROR_NONE;
+ return MS_MEDIA_ERR_NONE;
}
-int _media_svc_update_item_by_path(sqlite3 *handle, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path,
- const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query)
+int _media_svc_append_query_list(const char *query, uid_t uid)
{
- /* update path, filename, modified_time, folder_uuid, thumbnail_path, */
- /* played_count, last_played_time, last_played_position, favourite, storaget_type*/
+ int ret = MS_MEDIA_ERR_NONE;
- int err = -1;
- char *sql = NULL;
+ media_svc_retvm_if(query == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "query is NULL");
- if(thumb_path != NULL) {
- sql = sqlite3_mprintf("UPDATE %s SET \
- path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, thumbnail_path=%Q, storage_type=%d, \
- played_count=0, last_played_time=0, last_played_position=0 \
- WHERE path=%Q",
- MEDIA_SVC_DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_uuid, thumb_path, dest_storage, src_path);
- } else {
- sql = sqlite3_mprintf("UPDATE %s SET \
- path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, storage_type=%d, \
- played_count=0, last_played_time=0, last_played_position=0 \
- WHERE path=%Q",
- MEDIA_SVC_DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_uuid, dest_storage, src_path);
- }
+ g_media_svc_update_list = g_list_append(g_media_svc_update_list, (gpointer)query);
- if(!stack_query) {
- err = _media_svc_sql_query(handle, sql);
- sqlite3_free(sql);
- if (err != SQLITE_OK) {
- media_svc_error("It failed to update metadata (%d)", err);
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
- } else {
- _media_svc_sql_query_add(&g_media_svc_move_item_query_list, &sql);
- }
-
- return MEDIA_INFO_ERROR_NONE;
-}
-
-int _media_svc_list_query_do(sqlite3 *handle, media_svc_query_type_e query_type)
-{
- int ret = MEDIA_INFO_ERROR_NONE;
-
- ret = _media_svc_sql_begin_trans(handle);
- media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
-
- if (query_type == MEDIA_SVC_QUERY_SET_ITEM_VALIDITY)
- ret = _media_svc_sql_query_list(handle, &g_media_svc_item_validity_query_list);
- else if (query_type == MEDIA_SVC_QUERY_MOVE_ITEM)
- ret = _media_svc_sql_query_list(handle, &g_media_svc_move_item_query_list);
- else if (query_type == MEDIA_SVC_QUERY_INSERT_ITEM)
- ret = _media_svc_sql_query_list(handle, &g_media_svc_insert_item_query_list);
- else
- ret = MEDIA_INFO_ERROR_INVALID_PARAMETER;
-
- if (ret != MEDIA_INFO_ERROR_NONE) {
- media_svc_error("_media_svc_list_query_do failed. start rollback");
- _media_svc_sql_rollback_trans(handle);
- return ret;
- }
-
- ret = _media_svc_sql_end_trans(handle);
- if (ret != MEDIA_INFO_ERROR_NONE) {
- media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback\n");
- _media_svc_sql_rollback_trans(handle);
- return ret;
- }
+ if (g_list_length(g_media_svc_update_list) >= MEDIA_SVC_MAX_COMMIT_SIZE)
+ ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_COMMON, uid);
- return MEDIA_INFO_ERROR_NONE;
+ return ret;
}
-int _media_svc_get_media_id_by_path(sqlite3 *handle, const char *path, char *media_uuid, int max_length)
+int _media_svc_get_media(sqlite3 *handle, const char *sql, GList **path_list)
{
- int ret = MEDIA_INFO_ERROR_NONE;
+ int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT media_uuid FROM %s WHERE validity=1 AND path='%q'",
- MEDIA_SVC_DB_TABLE_MEDIA, path);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- if (ret != MEDIA_INFO_ERROR_NONE) {
- media_svc_error("error when __media_svc_count_invalid_records_with_thumbnail. err = [%d]", ret);
- return ret;
- }
-
- strncpy(media_uuid, (const char*)sqlite3_column_text(sql_stmt, 0), max_length);
- media_uuid[max_length - 1] = '\0';
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MEDIA_INFO_ERROR_NONE;
-}
-int _media_svc_get_burst_id(sqlite3 *handle, int *id)
-{
- int ret = MEDIA_INFO_ERROR_NONE;
- int cur_id = -1;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT max(CAST(burst_id AS INTEGER)) FROM %s", MEDIA_SVC_DB_TABLE_MEDIA);
+ 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(handle, sql, &sql_stmt);
+ 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);
- if (ret != MEDIA_INFO_ERROR_NONE) {
- media_svc_error("error when _media_svc_get_burst_id. err = [%d]", ret);
- return ret;
- }
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW)
+ *path_list = g_list_append(*path_list, g_strdup((const char *)sqlite3_column_text(sql_stmt, 0)));
- cur_id = sqlite3_column_int(sql_stmt, 0);
- *id = ++cur_id;
SQLITE3_FINALIZE(sql_stmt);
- return MEDIA_INFO_ERROR_NONE;
+ return ret;
}
-int _media_svc_get_noti_info(sqlite3 *handle, const char *path, int update_item, media_svc_noti_item **item)
+int _media_svc_get_noti_info(sqlite3 *handle, const char *path, media_svc_noti_item **item)
{
- int ret = MEDIA_INFO_ERROR_NONE;
+ int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- if (item == NULL) {
- media_svc_error("_media_svc_get_noti_info failed");
- return MEDIA_INFO_ERROR_INVALID_PARAMETER;
- }
-
- if (update_item == MS_MEDIA_ITEM_FILE) {
- sql = sqlite3_mprintf("SELECT media_uuid, media_type, mime_type FROM %s", MEDIA_SVC_DB_TABLE_MEDIA);
- } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
- sql = sqlite3_mprintf("SELECT folder_uuid FROM %s", MEDIA_SVC_DB_TABLE_FOLDER);
- } else {
- media_svc_error("_media_svc_get_noti_info failed : update item");
- return MEDIA_INFO_ERROR_INVALID_PARAMETER;
- }
+ media_svc_retvm_if(item == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "item is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ sql = sqlite3_mprintf("SELECT media_id, media_type, media_mime_type FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path);
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);
- if (ret != MEDIA_INFO_ERROR_NONE) {
- media_svc_error("error when _media_svc_get_noti_info. err = [%d]", ret);
- return ret;
- }
-
- *item = calloc(1, sizeof(media_svc_noti_item));
- if (*item == NULL) {
- media_svc_error("_media_svc_get_noti_info failed : calloc");
- return MEDIA_INFO_ERROR_OUT_OF_MEMORY;
- }
-
- if (update_item == MS_MEDIA_ITEM_FILE) {
- if (sqlite3_column_text(sql_stmt, 0))
- (*item)->media_uuid = strdup((const char *)sqlite3_column_text(sql_stmt, 0));
+ *item = g_new0(media_svc_noti_item, 1);
- (*item)->media_type = sqlite3_column_int(sql_stmt, 1);
-
- if (sqlite3_column_text(sql_stmt, 2))
- (*item)->mime_type = strdup((const char *)sqlite3_column_text(sql_stmt, 2));
- } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
- if (sqlite3_column_text(sql_stmt, 0))
- (*item)->media_uuid = 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);
- return MEDIA_INFO_ERROR_NONE;
+ return MS_MEDIA_ERR_NONE;
}
-
-int _media_svc_count_invalid_folder_items(sqlite3 *handle, const char *folder_path, int *count)
-{
- int ret = MEDIA_INFO_ERROR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE validity=0 AND path LIKE '%q/%%'",
- MEDIA_SVC_DB_TABLE_MEDIA, folder_path);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- if (ret != MEDIA_INFO_ERROR_NONE) {
- media_svc_error("error when __media_svc_count_invalid_folder_records_with_thumbnail. err = [%d]", ret);
- return ret;
- }
-
- *count = sqlite3_column_int(sql_stmt, 0);
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MEDIA_INFO_ERROR_NONE;
-}
\ No newline at end of file