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 *path, int *count)
+int _media_svc_check_data_by_path(sqlite3 *handle, const char *path)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = 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", MEDIA_SVC_DB_TABLE_MEDIA, path);
+ 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);
-
- *count = sqlite3_column_int(sql_stmt, 0);
-
SQLITE3_FINALIZE(sql_stmt);
- return MS_MEDIA_ERR_NONE;
+ return ret;
}
int _media_svc_get_modified_time(sqlite3 *handle, const char *path, int *modified_time)
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", MEDIA_SVC_DB_TABLE_MEDIA, path);
+ 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);
%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);",
- MEDIA_SVC_DB_TABLE_MEDIA, db_fields,
+ DB_TABLE_MEDIA, db_fields,
content_info->media_uuid,
content_info->path,
content_info->file_name,
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);",
- MEDIA_SVC_DB_TABLE_MEDIA, db_fields_basic,
+ DB_TABLE_MEDIA, db_fields_basic,
content_info->media_uuid,
content_info->path,
content_info->file_name,
int _media_svc_update_meta_with_data(media_svc_content_info_s *content_info)
{
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 */
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;",
- MEDIA_SVC_DB_TABLE_MEDIA,
+ DB_TABLE_MEDIA,
content_info->media_meta.title,
content_info->media_meta.album,
content_info->media_meta.artist,
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,
+ 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,
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_TABLE_MEDIA, path);
+ 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);
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;", MEDIA_SVC_DB_TABLE_MEDIA, path);
+ sql = sqlite3_mprintf("DELETE FROM %q WHERE media_path=%Q;", DB_TABLE_MEDIA, path);
ret = _media_svc_sql_query(sql, uid);
SQLITE3_SAFE_FREE(sql);
media_svc_debug("path=[%s], validity=[%d]", path, validity);
- sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE media_path='%q';", MEDIA_SVC_DB_TABLE_MEDIA, validity, path);
+ sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE media_path='%q';", DB_TABLE_MEDIA, validity, path);
if (!stack_query) {
ret = _media_svc_sql_query_direct(sql, uid);
{
int ret = MS_MEDIA_ERR_NONE;
- char *sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path=%Q WHERE media_path=%Q;", MEDIA_SVC_DB_TABLE_MEDIA, thumb_path, path);
+ char *sql = sqlite3_mprintf("UPDATE %q SET media_thumbnail_path=%Q WHERE media_path=%Q;", DB_TABLE_MEDIA, thumb_path, path);
ret = _media_svc_sql_query(sql, uid);
SQLITE3_SAFE_FREE(sql);
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;",
- MEDIA_SVC_DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_uuid, dest_storage, dst_storage_id, src_path);
+ 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);
/* 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;
ret = _media_svc_sql_query_list(&g_media_svc_update_list, uid);
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;
return ret;
}
-int _media_svc_get_media(sqlite3 *handle, const char *sql, GPtrArray **path_list)
+int _media_svc_get_media(sqlite3 *handle, const char *sql, GList **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);
- }
+
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW)
+ *path_list = g_list_append(*path_list, g_strdup((const char *)sqlite3_column_text(sql_stmt, 0)));
SQLITE3_FINALIZE(sql_stmt);
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", MEDIA_SVC_DB_TABLE_MEDIA, path);
+ 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);
- *item = calloc(1, sizeof(media_svc_noti_item));
- if (*item == NULL) {
- media_svc_error("Allocation failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
+ *item = g_new0(media_svc_noti_item, 1);
(*item)->media_uuid = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
(*item)->media_type = sqlite3_column_int(sql_stmt, 1);