#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 media_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 media_modified_time FROM '%q' WHERE media_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(bool is_direct, 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;
_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,
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,
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_insert_item_query_list, &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 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, \
- media_file_name_pinyin=%Q, media_title_pinyin=%Q, media_album_pinyin=%Q, media_artist_pinyin=%Q, media_album_artist_pinyin=%Q, media_genre_pinyin=%Q, media_composer_pinyin=%Q, media_copyright_pinyin=%Q, media_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_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(bool is_direct, 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 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, \
+ 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;",
- storage_id,
+ MEDIA_SVC_DB_TABLE_MEDIA,
content_info->size,
content_info->modified_time,
content_info->thumbnail_path,
/* Scanner use only batch insert */
if (is_direct) {
media_svc_sec_debug("Query [%s]", sql);
- _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &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);
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'", 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 media_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);
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_delete_item_by_path(const char *storage_id, const char *path, 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 media_path='%q';", storage_id, path);
+ sql = sqlite3_mprintf("DELETE FROM %q WHERE media_path=%Q;", MEDIA_SVC_DB_TABLE_MEDIA, path);
ret = _media_svc_sql_query(sql, uid);
SQLITE3_SAFE_FREE(sql);
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 media_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_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 media_thumbnail_path=%Q WHERE media_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 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;",
- 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 media_path = '%q';", dst_storage_id, org_storage_id, dest_path);
- char *remove = sqlite3_mprintf("DELETE FROM '%q' WHERE media_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 _media_svc_list_query_do(media_svc_query_type_e query_type, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
/* For multiples of 200, empty requests are possible */
switch (query_type) {
if (g_media_svc_update_list == NULL || g_list_length(g_media_svc_update_list) == 0)
return MS_MEDIA_ERR_NONE;
- if (g_list_length(g_media_svc_update_list) == 1) {
- sql = (char *)g_list_nth_data(g_media_svc_update_list, 0);
- if (STRING_VALID(sql)) {
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- }
- _media_svc_sql_query_release(&g_media_svc_update_list);
-
- return ret;
- }
-
- ret = _media_svc_sql_begin_trans(uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
ret = _media_svc_sql_query_list(&g_media_svc_update_list, uid);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Failed to request queries");
-
- ret = _media_svc_sql_end_trans(uid);
- break;
- case MEDIA_SVC_QUERY_SET_ITEM_VALIDITY:
- ret = _media_svc_sql_query_list_direct(&g_media_svc_item_validity_query_list, uid);
break;
- case MEDIA_SVC_QUERY_INSERT_ITEM:
- ret = _media_svc_sql_query_list_direct(&g_media_svc_insert_item_query_list, uid);
- break;
- case MEDIA_SVC_QUERY_UPDATE_ITEM:
- ret = _media_svc_sql_query_list_direct(&g_media_svc_update_item_query_list, uid);
+ 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 ret;
}
-int _media_svc_get_noti_info(sqlite3 *handle, const char *storage_id, const char *path, 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;
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");
- sql = sqlite3_mprintf("SELECT media_id, media_type, media_mime_type FROM '%q' WHERE media_path=%Q", storage_id, path);
+ 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);
media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step() failed [%d]", ret);