{"action":"created","comment":{"url":"https://api.github.com/repos/xbmc/xbmc/pulls/comments/49252307","id":49252307,"diff_hunk":"@@ -1385,6 +1410,67 @@ int CVideoDatabase::AddToTable(const std::string& table, const std::string& firs\n   return -1;\n }\n \n+int CVideoDatabase::UpdateRatings(int mediaId, const char *mediaType, const RatingMap& values, const std::string& defaultRating)\n+{\n+  try\n+  {\n+    if (NULL == m_pDB.get()) return -1;\n+    if (NULL == m_pDS.get()) return -1;\n+\n+    std::string sql = PrepareSQL(\"DELETE FROM rating WHERE media_id=%i AND media_type='%s'\", mediaId, mediaType);\n+    m_pDS->exec(sql);\n+\n+    return AddRatings(mediaId, mediaType, values, defaultRating);\n+  }\n+  catch (...)\n+  {\n+    CLog::Log(LOGERROR, \"%s unable to update ratings of  (%s)\", __FUNCTION__, mediaType);\n+  }\n+  return -1;\n+}\n+\n+int CVideoDatabase::AddRatings(int mediaId, const char *mediaType, const RatingMap& values, const std::string& defaultRating)\n+{\n+  int ratingid = -1;\n+  try\n+  {\n+    if (NULL == m_pDB.get()) return -1;\n+    if (NULL == m_pDS.get()) return -1;\n+\n+    for (const auto& i : values)\n+    {\n+      int id;\n+      std::string strSQL = PrepareSQL(\"SELECT rating_id FROM rating WHERE media_id=%i AND media_type='%s' AND rating_type = '%s'\", mediaId, mediaType, i.first.c_str());\n+      m_pDS->query(strSQL);\n+      if (m_pDS->num_rows() == 0)\n+      {\n+        m_pDS->close();\n+        // doesnt exists, add it\n+        strSQL = PrepareSQL(\"INSERT INTO rating (media_id, media_type, rating_type, rating, votes) VALUES (%i, '%s', '%s', %f, %i)\", mediaId, mediaType, i.first.c_str(), i.second.rating, i.second.votes);\n+        m_pDS->exec(strSQL);\n+        id = (int)m_pDS->lastinsertid();\n+      }\n+      else\n+      {\n+        id = m_pDS->fv(1).get_asInt();\n+        m_pDS->close();\n+        strSQL = PrepareSQL(\"UPDATE rating SET rating.rating = '%.f', rating.votes = %i WHERE rating.media_id = %i\", i.second.rating, i.second.votes, id);","path":"xbmc/video/VideoDatabase.cpp","position":198,"original_position":198,"commit_id":"e03cdf0e91e5318df1113269802b1630ee9d9e18","original_commit_id":"e03cdf0e91e5318df1113269802b1630ee9d9e18","user":{"login":"anaconda","id":497012,"avatar_url":"https://avatars.githubusercontent.com/u/497012?v=3","gravatar_id":"","url":"https://api.github.com/users/anaconda","html_url":"https://github.com/anaconda","followers_url":"https://api.github.com/users/anaconda/followers","following_url":"https://api.github.com/users/anaconda/following{/other_user}","gists_url":"https://api.github.com/users/anaconda/gists{/gist_id}","starred_url":"https://api.github.com/users/anaconda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anaconda/subscriptions","organizations_url":"https://api.github.com/users/anaconda/orgs","repos_url":"https://api.github.com/users/anaconda/repos","events_url":"https://api.github.com/users/anaconda/events{/privacy}","received_events_url":"https://api.github.com/users/anaconda/received_events","type":"User","site_admin":false},"body":"`id = m_pDS->fv(1).get_asInt();` should be `0` not `1`.\r\n\r\nQuery should be:\r\n`strSQL = PrepareSQL(\"UPDATE rating SET rating = '%.f', votes = %i WHERE rating_id = %i\", i.second.rating, i.second.votes, id);`\r\n\r\nThe combination of both typos produces the following errors:\r\n```\r\n00:14:18 2125.637695 T:1724208032   ERROR: SQL: [MyVideos102.db] SQL error or missing database\r\n                                            Query: UPDATE rating SET rating.rating = '0', rating.votes = 0 WHERE rating.media_id = 0\r\n00:14:18 2125.665527 T:1724208032   ERROR: AddRatings (674 - episode) failed\r\n```","created_at":"2016-01-08T23:47:21Z","updated_at":"2016-01-08T23:47:21Z","html_url":"https://github.com/xbmc/xbmc/pull/8080#discussion_r49252307","pull_request_url":"https://api.github.com/repos/xbmc/xbmc/pulls/8080","_links":{"self":{"href":"https://api.github.com/repos/xbmc/xbmc/pulls/comments/49252307"},"html":{"href":"https://github.com/xbmc/xbmc/pull/8080#discussion_r49252307"},"pull_request":{"href":"https://api.github.com/repos/xbmc/xbmc/pulls/8080"}}},"pull_request":{"url":"https://api.github.com/repos/xbmc/xbmc/pulls/8080","id":45458812,"html_url":"https://github.com/xbmc/xbmc/pull/8080","diff_url":"https://github.com/xbmc/xbmc/pull/8080.diff","patch_url":"https://github.com/xbmc/xbmc/pull/8080.patch","issue_url":"https://api.github.com/repos/xbmc/xbmc/issues/8080","number":8080,"state":"closed","locked":false,"title":"Add support for multiple ratings","user":{"login":"phate89","id":1254959,"avatar_url":"https://avatars.githubusercontent.com/u/1254959?v=3","gravatar_id":"","url":"https://api.github.com/users/phate89","html_url":"https://github.com/phate89","followers_url":"https://api.github.com/users/phate89/followers","following_url":"https://api.github.com/users/phate89/following{/other_user}","gists_url":"https://api.github.com/users/phate89/gists{/gist_id}","starred_url":"https://api.github.com/users/phate89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phate89/subscriptions","organizations_url":"https://api.github.com/users/phate89/orgs","repos_url":"https://api.github.com/users/phate89/repos","events_url":"https://api.github.com/users/phate89/events{/privacy}","received_events_url":"https://api.github.com/users/phate89/received_events","type":"User","site_admin":false},"body":"Since https://github.com/xbmc/xbmc/pull/8062 is strictly related to this change I kept working on this so I can have an opinion about my solution.\r\nI moved rating and votes to a separate table (so we can have more than one for every movie) and I added the rating_id of the default vote to the movie table (using the old rating column). In CVideoInfoTag class all the ratings are stored in a map and they're handled by functions..\r\n","created_at":"2015-09-18T22:19:13Z","updated_at":"2016-01-08T23:47:21Z","closed_at":"2016-01-05T22:29:36Z","merged_at":"2016-01-05T22:29:36Z","merge_commit_sha":"26ff3691fe9d062c6f27aaba6c13a3a1a6465804","assignee":null,"milestone":{"url":"https://api.github.com/repos/xbmc/xbmc/milestones/74","html_url":"https://github.com/xbmc/xbmc/milestones/Krypton%2017.0-alpha1","labels_url":"https://api.github.com/repos/xbmc/xbmc/milestones/74/labels","id":1444499,"number":74,"title":"Krypton 17.0-alpha1","description":"","creator":{"login":"MartijnKaijser","id":907436,"avatar_url":"https://avatars.githubusercontent.com/u/907436?v=3","gravatar_id":"","url":"https://api.github.com/users/MartijnKaijser","html_url":"https://github.com/MartijnKaijser","followers_url":"https://api.github.com/users/MartijnKaijser/followers","following_url":"https://api.github.com/users/MartijnKaijser/following{/other_user}","gists_url":"https://api.github.com/users/MartijnKaijser/gists{/gist_id}","starred_url":"https://api.github.com/users/MartijnKaijser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MartijnKaijser/subscriptions","organizations_url":"https://api.github.com/users/MartijnKaijser/orgs","repos_url":"https://api.github.com/users/MartijnKaijser/repos","events_url":"https://api.github.com/users/MartijnKaijser/events{/privacy}","received_events_url":"https://api.github.com/users/MartijnKaijser/received_events","type":"User","site_admin":false},"open_issues":11,"closed_issues":212,"state":"open","created_at":"2015-12-04T16:31:06Z","updated_at":"2016-01-08T23:01:53Z","due_on":"2016-02-28T00:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/xbmc/xbmc/pulls/8080/commits","review_comments_url":"https://api.github.com/repos/xbmc/xbmc/pulls/8080/comments","review_comment_url":"https://api.github.com/repos/xbmc/xbmc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xbmc/xbmc/issues/8080/comments","statuses_url":"https://api.github.com/repos/xbmc/xbmc/statuses/e03cdf0e91e5318df1113269802b1630ee9d9e18","head":{"label":"phate89:multiple_ratings","ref":"multiple_ratings","sha":"e03cdf0e91e5318df1113269802b1630ee9d9e18","user":{"login":"phate89","id":1254959,"avatar_url":"https://avatars.githubusercontent.com/u/1254959?v=3","gravatar_id":"","url":"https://api.github.com/users/phate89","html_url":"https://github.com/phate89","followers_url":"https://api.github.com/users/phate89/followers","following_url":"https://api.github.com/users/phate89/following{/other_user}","gists_url":"https://api.github.com/users/phate89/gists{/gist_id}","starred_url":"https://api.github.com/users/phate89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phate89/subscriptions","organizations_url":"https://api.github.com/users/phate89/orgs","repos_url":"https://api.github.com/users/phate89/repos","events_url":"https://api.github.com/users/phate89/events{/privacy}","received_events_url":"https://api.github.com/users/phate89/received_events","type":"User","site_admin":false},"repo":{"id":25815543,"name":"xbmc","full_name":"phate89/xbmc","owner":{"login":"phate89","id":1254959,"avatar_url":"https://avatars.githubusercontent.com/u/1254959?v=3","gravatar_id":"","url":"https://api.github.com/users/phate89","html_url":"https://github.com/phate89","followers_url":"https://api.github.com/users/phate89/followers","following_url":"https://api.github.com/users/phate89/following{/other_user}","gists_url":"https://api.github.com/users/phate89/gists{/gist_id}","starred_url":"https://api.github.com/users/phate89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phate89/subscriptions","organizations_url":"https://api.github.com/users/phate89/orgs","repos_url":"https://api.github.com/users/phate89/repos","events_url":"https://api.github.com/users/phate89/events{/privacy}","received_events_url":"https://api.github.com/users/phate89/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/phate89/xbmc","description":"XBMC Main Repository","fork":true,"url":"https://api.github.com/repos/phate89/xbmc","forks_url":"https://api.github.com/repos/phate89/xbmc/forks","keys_url":"https://api.github.com/repos/phate89/xbmc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/phate89/xbmc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/phate89/xbmc/teams","hooks_url":"https://api.github.com/repos/phate89/xbmc/hooks","issue_events_url":"https://api.github.com/repos/phate89/xbmc/issues/events{/number}","events_url":"https://api.github.com/repos/phate89/xbmc/events","assignees_url":"https://api.github.com/repos/phate89/xbmc/assignees{/user}","branches_url":"https://api.github.com/repos/phate89/xbmc/branches{/branch}","tags_url":"https://api.github.com/repos/phate89/xbmc/tags","blobs_url":"https://api.github.com/repos/phate89/xbmc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/phate89/xbmc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/phate89/xbmc/git/refs{/sha}","trees_url":"https://api.github.com/repos/phate89/xbmc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/phate89/xbmc/statuses/{sha}","languages_url":"https://api.github.com/repos/phate89/xbmc/languages","stargazers_url":"https://api.github.com/repos/phate89/xbmc/stargazers","contributors_url":"https://api.github.com/repos/phate89/xbmc/contributors","subscribers_url":"https://api.github.com/repos/phate89/xbmc/subscribers","subscription_url":"https://api.github.com/repos/phate89/xbmc/subscription","commits_url":"https://api.github.com/repos/phate89/xbmc/commits{/sha}","git_commits_url":"https://api.github.com/repos/phate89/xbmc/git/commits{/sha}","comments_url":"https://api.github.com/repos/phate89/xbmc/comments{/number}","issue_comment_url":"https://api.github.com/repos/phate89/xbmc/issues/comments{/number}","contents_url":"https://api.github.com/repos/phate89/xbmc/contents/{+path}","compare_url":"https://api.github.com/repos/phate89/xbmc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/phate89/xbmc/merges","archive_url":"https://api.github.com/repos/phate89/xbmc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/phate89/xbmc/downloads","issues_url":"https://api.github.com/repos/phate89/xbmc/issues{/number}","pulls_url":"https://api.github.com/repos/phate89/xbmc/pulls{/number}","milestones_url":"https://api.github.com/repos/phate89/xbmc/milestones{/number}","notifications_url":"https://api.github.com/repos/phate89/xbmc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/phate89/xbmc/labels{/name}","releases_url":"https://api.github.com/repos/phate89/xbmc/releases{/id}","created_at":"2014-10-27T11:20:57Z","updated_at":"2015-05-06T12:58:03Z","pushed_at":"2016-01-08T12:58:48Z","git_url":"git://github.com/phate89/xbmc.git","ssh_url":"git@github.com:phate89/xbmc.git","clone_url":"https://github.com/phate89/xbmc.git","svn_url":"https://github.com/phate89/xbmc","homepage":"http://xbmc.org","size":546950,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"xbmc:master","ref":"master","sha":"b15990426debb9a16faf3d367b9501a93023f43d","user":{"login":"xbmc","id":199122,"avatar_url":"https://avatars.githubusercontent.com/u/199122?v=3","gravatar_id":"","url":"https://api.github.com/users/xbmc","html_url":"https://github.com/xbmc","followers_url":"https://api.github.com/users/xbmc/followers","following_url":"https://api.github.com/users/xbmc/following{/other_user}","gists_url":"https://api.github.com/users/xbmc/gists{/gist_id}","starred_url":"https://api.github.com/users/xbmc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xbmc/subscriptions","organizations_url":"https://api.github.com/users/xbmc/orgs","repos_url":"https://api.github.com/users/xbmc/repos","events_url":"https://api.github.com/users/xbmc/events{/privacy}","received_events_url":"https://api.github.com/users/xbmc/received_events","type":"Organization","site_admin":false},"repo":{"id":1217614,"name":"xbmc","full_name":"xbmc/xbmc","owner":{"login":"xbmc","id":199122,"avatar_url":"https://avatars.githubusercontent.com/u/199122?v=3","gravatar_id":"","url":"https://api.github.com/users/xbmc","html_url":"https://github.com/xbmc","followers_url":"https://api.github.com/users/xbmc/followers","following_url":"https://api.github.com/users/xbmc/following{/other_user}","gists_url":"https://api.github.com/users/xbmc/gists{/gist_id}","starred_url":"https://api.github.com/users/xbmc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xbmc/subscriptions","organizations_url":"https://api.github.com/users/xbmc/orgs","repos_url":"https://api.github.com/users/xbmc/repos","events_url":"https://api.github.com/users/xbmc/events{/privacy}","received_events_url":"https://api.github.com/users/xbmc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xbmc/xbmc","description":"Kodi Main Repository - By using this code you agree with our policy and will follow the GPLv2 license as included","fork":false,"url":"https://api.github.com/repos/xbmc/xbmc","forks_url":"https://api.github.com/repos/xbmc/xbmc/forks","keys_url":"https://api.github.com/repos/xbmc/xbmc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xbmc/xbmc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xbmc/xbmc/teams","hooks_url":"https://api.github.com/repos/xbmc/xbmc/hooks","issue_events_url":"https://api.github.com/repos/xbmc/xbmc/issues/events{/number}","events_url":"https://api.github.com/repos/xbmc/xbmc/events","assignees_url":"https://api.github.com/repos/xbmc/xbmc/assignees{/user}","branches_url":"https://api.github.com/repos/xbmc/xbmc/branches{/branch}","tags_url":"https://api.github.com/repos/xbmc/xbmc/tags","blobs_url":"https://api.github.com/repos/xbmc/xbmc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xbmc/xbmc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xbmc/xbmc/git/refs{/sha}","trees_url":"https://api.github.com/repos/xbmc/xbmc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xbmc/xbmc/statuses/{sha}","languages_url":"https://api.github.com/repos/xbmc/xbmc/languages","stargazers_url":"https://api.github.com/repos/xbmc/xbmc/stargazers","contributors_url":"https://api.github.com/repos/xbmc/xbmc/contributors","subscribers_url":"https://api.github.com/repos/xbmc/xbmc/subscribers","subscription_url":"https://api.github.com/repos/xbmc/xbmc/subscription","commits_url":"https://api.github.com/repos/xbmc/xbmc/commits{/sha}","git_commits_url":"https://api.github.com/repos/xbmc/xbmc/git/commits{/sha}","comments_url":"https://api.github.com/repos/xbmc/xbmc/comments{/number}","issue_comment_url":"https://api.github.com/repos/xbmc/xbmc/issues/comments{/number}","contents_url":"https://api.github.com/repos/xbmc/xbmc/contents/{+path}","compare_url":"https://api.github.com/repos/xbmc/xbmc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xbmc/xbmc/merges","archive_url":"https://api.github.com/repos/xbmc/xbmc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xbmc/xbmc/downloads","issues_url":"https://api.github.com/repos/xbmc/xbmc/issues{/number}","pulls_url":"https://api.github.com/repos/xbmc/xbmc/pulls{/number}","milestones_url":"https://api.github.com/repos/xbmc/xbmc/milestones{/number}","notifications_url":"https://api.github.com/repos/xbmc/xbmc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xbmc/xbmc/labels{/name}","releases_url":"https://api.github.com/repos/xbmc/xbmc/releases{/id}","created_at":"2011-01-03T21:18:51Z","updated_at":"2016-01-08T23:39:15Z","pushed_at":"2016-01-08T23:19:57Z","git_url":"git://github.com/xbmc/xbmc.git","ssh_url":"git@github.com:xbmc/xbmc.git","clone_url":"https://github.com/xbmc/xbmc.git","svn_url":"https://github.com/xbmc/xbmc","homepage":"http://kodi.wiki/view/Official:Trademark_Policy","size":1729049,"stargazers_count":4408,"watchers_count":4408,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3248,"mirror_url":null,"open_issues_count":217,"forks":3248,"open_issues":217,"watchers":4408,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xbmc/xbmc/pulls/8080"},"html":{"href":"https://github.com/xbmc/xbmc/pull/8080"},"issue":{"href":"https://api.github.com/repos/xbmc/xbmc/issues/8080"},"comments":{"href":"https://api.github.com/repos/xbmc/xbmc/issues/8080/comments"},"review_comments":{"href":"https://api.github.com/repos/xbmc/xbmc/pulls/8080/comments"},"review_comment":{"href":"https://api.github.com/repos/xbmc/xbmc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xbmc/xbmc/pulls/8080/commits"},"statuses":{"href":"https://api.github.com/repos/xbmc/xbmc/statuses/e03cdf0e91e5318df1113269802b1630ee9d9e18"}}}}