Duplicated playlist(same server name and same playlist name) can't be inserted to DB.
Change-Id: I5db839b695b1fbd83473971b003534aec1192c73
int mc_db_get_pb_action_ability(void *handle, const char *server_name, mc_playback_ability_h *ability);
int _mc_db_get_playlist_count(void *handle, const char *server_name);
int mc_db_get_foreach_playlist(void *handle, const char *server_name, mc_playlist_cb callback, void *user_data);
+gboolean _mc_db_is_playlist_exist(void *handle, const char *server_name, const char *playlist_name);
int mc_db_get_playlist_by_name(void *handle, mc_priv_type_e type, const char *controller_name, const char *playlist_name, mc_playlist_h *playlist);
int _mc_db_get_playlist_item_count(void *handle, const char *server_name, char *playlist_name);
int mc_db_get_playlist_item(void *handle, const char *server_name, char *playlist_name, mc_playlist_item_cb callback, void *user_data);
return MEDIA_CONTROLLER_ERROR_NONE;
}
-int mc_db_get_playlist_by_name(void *handle, mc_priv_type_e type, const char *controller_name, const char *playlist_name, mc_playlist_h *playlist)
+gboolean _mc_db_is_playlist_exist(void *handle, const char *server_name, const char *playlist_name)
{
- int ret = MEDIA_CONTROLLER_ERROR_NONE;
char *sql_str = NULL;
int count = 0;
- mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
- mc_retvm_if(controller_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is NULL");
- mc_retvm_if(playlist_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "playlist_name is NULL");
- mc_retvm_if(playlist == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "playlist is NULL");
+ mc_retvm_if(!handle, FALSE, "Invalid handle");
+ mc_retvm_if(!server_name, FALSE, "Invalid server_name");
+ mc_retvm_if(!playlist_name, FALSE, "Invalid playlist_name");
- sql_str = sqlite3_mprintf("SELECT COUNT(*) FROM '%q' WHERE server_name = %Q AND playlist_name = %Q", MC_DB_TABLE_PLAYLIST, controller_name, playlist_name);
+ sql_str = sqlite3_mprintf("SELECT COUNT(*) FROM '%q' WHERE server_name = %Q AND playlist_name = %Q", MC_DB_TABLE_PLAYLIST, server_name, playlist_name);
mc_retvm_if(!MC_STRING_VALID(sql_str), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "SQL string is null");
count = __mc_db_get_count(handle, sql_str);
SQLITE3_SAFE_FREE(sql_str);
- if (count > 0) {
+ if (count > 0)
+ return TRUE;
+
+ return FALSE;
+}
+
+int mc_db_get_playlist_by_name(void *handle, mc_priv_type_e type, const char *controller_name, const char *playlist_name, mc_playlist_h *playlist)
+{
+ int ret = MEDIA_CONTROLLER_ERROR_NONE;
+ gboolean is_exist = FALSE;
+
+ mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ mc_retvm_if(controller_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "server_name is NULL");
+ mc_retvm_if(playlist_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "playlist_name is NULL");
+ mc_retvm_if(playlist == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "playlist is NULL");
+
+ is_exist = _mc_db_is_playlist_exist(handle, controller_name, playlist_name);
+
+ if (is_exist) {
mc_playlist_s *_playlist = (mc_playlist_s *)calloc(1, sizeof(mc_playlist_s));
if (_playlist != NULL) {
_playlist->type = type;
char *sql_str = NULL;
mc_playlist_item_s *_item = NULL;
mc_playlist_s *_playlist = (mc_playlist_s*)playlist;
+ void* db_handle = NULL;
+ gboolean is_exist = FALSE;
mc_retvm_if(_playlist == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist");
mc_retvm_if(_playlist->playlist_name == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid playlist_name");
}
}
} else {
- sql_str = sqlite3_mprintf("INSERT INTO '%q' (server_name, playlist_name, item_index, %s) VALUES (%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q);",
- MC_DB_TABLE_PLAYLIST, MC_META_LIST, _playlist->server_name, _playlist->playlist_name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ ret = mc_db_connect(&db_handle, getuid(), FALSE);
+ mc_retvm_if(db_handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "fail to mc_db_connect [%d]", ret);
+
+ is_exist = _mc_db_is_playlist_exist(db_handle, _playlist->server_name, _playlist->playlist_name);
+ mc_db_disconnect(db_handle);
+ mc_retvm_if(is_exist, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "playlist already exists");
+
+ sql_str = sqlite3_mprintf("INSERT INTO '%q' (server_name, playlist_name) VALUES (%Q, %Q);", MC_DB_TABLE_PLAYLIST, _playlist->server_name, _playlist->playlist_name);
if (sql_str != NULL)
query_list = g_list_append(query_list, sql_str);