int media_svc_connect(MediaSvcHandle **handle, uid_t uid, bool need_write);
int media_svc_disconnect(MediaSvcHandle *handle);
+int media_svc_cleanup_db(MediaSvcHandle *handle, uid_t uid);
int media_svc_get_user_version(MediaSvcHandle *handle, int *user_version);
int media_svc_create_table(uid_t uid);
int media_svc_check_item_exist_by_path(MediaSvcHandle *handle, const char *storage_id, const char *path);
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
+int cleanup_db(void *handle, uid_t uid, char **err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if (handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_cleanup_db(handle, uid);
+ if (ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
int check_item_exist(void *handle, const char *storage_id, const char *file_path, bool *modified, char **err_msg)
{
int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
return MS_MEDIA_ERR_NONE;
}
+int _media_svc_do_cleanup(sqlite3 *db_handle, uid_t uid)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ GList *sql_list = NULL;
+ int item_cnt = 0;
+ int idx = 0;
+ /*Make one query to drop table, delete folder, delete storage.. And only for external USB storage */
+ char *sql = sqlite3_mprintf("select 'DROP TABLE ''' || storage_uuid || ''';DELETE FROM folder WHERE storage_uuid = ''' || storage_uuid || ''';DELETE FROM storage WHERE storage_uuid = ''' || storage_uuid || ''';' from storage where validity = 0 AND storage_type=2;");
+
+ ret = _media_svc_sql_prepare_to_step_simple(db_handle, sql, &sql_stmt);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("error when get user_version.");
+ return ret;
+ }
+
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
+ if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0)))
+ sql_list = g_list_append(sql_list, strdup((char *)sqlite3_column_text(sql_stmt, 0)));
+ }
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ if ((sql_list != NULL) && (g_list_length(sql_list) > 0)) {
+ item_cnt = g_list_length(sql_list);
+
+ for (idx = 0; idx < item_cnt; idx++) {
+ char *query = NULL;
+ query = g_list_nth_data(sql_list, idx);
+
+ if (STRING_VALID(query)) {
+ sql = sqlite3_mprintf("%s", query);
+ _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+ SAFE_FREE(query);
+ }
+ }
+ g_list_free(sql_list);
+ }
+
+ /*Rebuild index*/
+ sql = sqlite3_mprintf("VACUUM;");
+ _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt)
{
int err = -1;
return ret;
}
+int media_svc_cleanup_db(MediaSvcHandle *handle, uid_t uid)
+{
+ MediaDBHandle *db_handle = (MediaDBHandle *)handle;
+
+ media_svc_debug_fenter();
+
+ media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
+
+ return _media_svc_do_cleanup(db_handle, uid);
+}
+
int media_svc_get_user_version(MediaSvcHandle *handle, int *user_version)
{
sqlite3 *db_handle = (sqlite3 *)handle;
if (no_thumb) {
update_item_sql = sqlite3_mprintf("UPDATE '%q' SET path='%q' WHERE media_uuid='%q'", storage_id, replaced_path, media_uuid);
} else {
-#if 0
- if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)
- update_item_sql = sqlite3_mprintf("UPDATE '%q' SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", storage_id, replaced_path, media_new_thumb_path, media_uuid);
- else
- update_item_sql = sqlite3_mprintf("UPDATE '%q' SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", storage_id, replaced_path, media_thumb_path, media_uuid);
-#else
update_item_sql = sqlite3_mprintf("UPDATE '%q' SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", storage_id, replaced_path, media_new_thumb_path, media_uuid);
-#endif
}
ret = media_db_request_update_db_batch(update_item_sql, uid);
return _media_svc_get_media_type(path, mediatype);
}
-
int _media_svc_update_media_view(sqlite3 *db_handle, uid_t uid);
int _media_svc_sql_query(const char *sql_str, uid_t uid);
int _media_svc_get_user_version(sqlite3 *db_handle, int *user_version);
+int _media_svc_do_cleanup(sqlite3 *db_handle, uid_t uid);
int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt);
int _media_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt);
int _media_svc_sql_begin_trans(uid_t uid);