{"action":"created","comment":{"url":"https://api.github.com/repos/biocore/qiita/pulls/comments/32079156","id":32079156,"diff_hunk":"@@ -545,99 +436,156 @@ def fetchall_with_types(self, sql, sql_args=None):\n \n         Notes\n         -----\n-        from psycopg2 documentation, only variable values should be bound\n+        From psycopg2 documentation, only variable values should be bound\n         via sql_args, it shouldn't be used to set table or field names. For\n         those elements, ordinary string formatting should be used before\n         running execute.\n         \"\"\"\n         with self._sql_executor(sql, sql_args) as pgcursor:\n             result = pgcursor.fetchall()\n-            types = {desc[0]: self.TYPE_CODES[desc[1]]\n-                     for desc in pgcursor.description}\n \n-        return result, types\n+        return result\n \n-    def fetchone_with_types(self, sql, sql_args=None):\n-        \"\"\"Executes a fetchone SQL query with column information\n+    def _check_queue_exists(self, queue_name):\n+        if queue_name not in self.queues:\n+            raise KeyError(\"Queue %s does not exist\" % queue_name)\n+\n+    def create_queue(self, queue_name):\n+        \"\"\"Add a new queue to the connection\n \n         Parameters\n         ----------\n-        sql : str\n-            The SQL query\n-        sql_args : tuple or list, optional\n-            The arguments for the SQL query\n-\n-        Returns\n-        -------\n-        Tuple\n-            The results of the fetchone query\n-        dict\n-            dictionary in the form of {column: type}\n+        queue_name : str\n+            Name of the new queue\n \n         Raises\n         ------\n-        QiitaDBExecutionError\n-            if there is some error executing the SQL query\n-\n-        Notes\n-        -----\n-        from psycopg2 documentation, only variable values should be bound\n-        via sql_args, it shouldn't be used to set table or field names. For\n-        those elements, ordinary string formatting should be used before\n-        running execute.\n+        KeyError\n+            Queue name already exists\n         \"\"\"\n-        with self._sql_executor(sql, sql_args) as pgcursor:\n-            result = pgcursor.fetchone()\n-            types = {desc[0]: self.TYPE_CODES[desc[1]]\n-                     for desc in pgcursor.description}\n+        if queue_name in self.queues:\n+            raise KeyError(\"Queue %s already exists\" % queue_name)\n \n-        return result, types\n+        self.queues[queue_name] = []\n \n-    def execute(self, sql, sql_args=None):\n-        \"\"\" Executes an SQL query with no results\n+    def list_queues(self):\n+        \"\"\"Returns list of all queue names currently in handler\n+\n+        Returns\n+        -------\n+        list\n+            names of queues in handler\n+        \"\"\"\n+        return self.queues.keys()\n+\n+    def add_to_queue(self, queue, sql, sql_args=None, many=False):\n+        \"\"\"Add an sql command to the end of a queue\n \n         Parameters\n         ----------\n+        queue : str\n+            name of queue adding to\n         sql : str\n-            The SQL query\n-        sql_args : tuple or list, optional\n-            The arguments for the SQL query\n+            sql command to run\n+        sql_args : list, tuple or dict, optional\n+            the arguments to fill sql command with\n+        many : bool, optional\n+            Whether or not this should be treated as an executemany command.\n+            Default False\n \n         Raises\n         ------\n-        QiitaDBExecutionError\n-            if there is some error executing the SQL query\n+        KeyError\n+            queue does not exist\n \n-        Note: from psycopg2 documentation, only variable values should be bound\n-            via sql_args, it shouldn't be used to set table or field names. For\n-            those elements, ordinary string formatting should be used before\n-            running execute.\n+        Notes\n+        -----\n+        Queues are executed in FIFO order\n         \"\"\"\n-        with self._sql_executor(sql, sql_args):\n-            pass\n+        if not many:\n+            sql_args = [sql_args]\n \n-    def executemany(self, sql, sql_args_list):\n-        \"\"\" Executes an executemany SQL query with no results\n+        for args in sql_args:\n+            self._check_sql_args(args)\n+            self.queues[queue].append((sql, args))\n+\n+    def _rollback_raise_error(self, queue, sql, sql_args, e):\n+        self._connection.rollback()\n+        # wipe out queue since it has an error in it\n+        del self.queues[queue]\n+        raise QiitaDBExecutionError(\n+            (\"\\nError running SQL query in queue %s: %s\\nARGS: %s\\nError: %s\"\n+             % (queue, sql, str(sql_args), e)))\n+\n+    def execute_queue(self, queue):\n+        \"\"\"Executes all sql in a queue in a single transaction block\n \n         Parameters\n         ----------\n-        sql : str\n-            The SQL query\n-        sql_args : list of tuples\n-            The arguments for the SQL query\n+        queue : str\n+            Name of queue to execute\n \n-        Raises\n-        ------\n-        QiitaDBExecutionError\n-            If there is some error executing the SQL query\n+        Notes\n+        -----\n+        Does not support executemany command. Instead, enter the multiple\n+        SQL commands as multiple entries in the queue.\n \n-        Note: from psycopg2 documentation, only variable values should be bound\n-            via sql_args, it shouldn't be used to set table or field names. For\n-            those elements, ordinary string formatting should be used before\n-            running execute.\n+        Queues are executed in FIFO order\n         \"\"\"\n-        with self._sql_executor(sql, sql_args_list, True):\n-            pass\n+        self._check_queue_exists(queue)\n+\n+        with self.get_postgres_cursor() as cur:","path":"qiita_db/sql_connection.py","position":511,"original_position":511,"commit_id":"4b7da373e77c8c38894014347211c6491c39c948","original_commit_id":"4b7da373e77c8c38894014347211c6491c39c948","user":{"login":"ElDeveloper","id":375307,"avatar_url":"https://avatars.githubusercontent.com/u/375307?v=3","gravatar_id":"","url":"https://api.github.com/users/ElDeveloper","html_url":"https://github.com/ElDeveloper","followers_url":"https://api.github.com/users/ElDeveloper/followers","following_url":"https://api.github.com/users/ElDeveloper/following{/other_user}","gists_url":"https://api.github.com/users/ElDeveloper/gists{/gist_id}","starred_url":"https://api.github.com/users/ElDeveloper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ElDeveloper/subscriptions","organizations_url":"https://api.github.com/users/ElDeveloper/orgs","repos_url":"https://api.github.com/users/ElDeveloper/repos","events_url":"https://api.github.com/users/ElDeveloper/events{/privacy}","received_events_url":"https://api.github.com/users/ElDeveloper/received_events","type":"User","site_admin":false},"body":"This is a rather complex block, are we sure that it cannot be decomposed/restructured in any other way?","created_at":"2015-06-10T00:28:03Z","updated_at":"2015-06-10T00:28:03Z","html_url":"https://github.com/biocore/qiita/pull/1252#discussion_r32079156","pull_request_url":"https://api.github.com/repos/biocore/qiita/pulls/1252","_links":{"self":{"href":"https://api.github.com/repos/biocore/qiita/pulls/comments/32079156"},"html":{"href":"https://github.com/biocore/qiita/pull/1252#discussion_r32079156"},"pull_request":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1252"}}},"pull_request":{"url":"https://api.github.com/repos/biocore/qiita/pulls/1252","id":37286161,"html_url":"https://github.com/biocore/qiita/pull/1252","diff_url":"https://github.com/biocore/qiita/pull/1252.diff","patch_url":"https://github.com/biocore/qiita/pull/1252.patch","issue_url":"https://api.github.com/repos/biocore/qiita/issues/1252","number":1252,"state":"open","locked":false,"title":"Merging code from glowing dangerzone - BLOCKS DEVELOPMENT - please review","user":{"login":"josenavas","id":2501478,"avatar_url":"https://avatars.githubusercontent.com/u/2501478?v=3","gravatar_id":"","url":"https://api.github.com/users/josenavas","html_url":"https://github.com/josenavas","followers_url":"https://api.github.com/users/josenavas/followers","following_url":"https://api.github.com/users/josenavas/following{/other_user}","gists_url":"https://api.github.com/users/josenavas/gists{/gist_id}","starred_url":"https://api.github.com/users/josenavas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josenavas/subscriptions","organizations_url":"https://api.github.com/users/josenavas/orgs","repos_url":"https://api.github.com/users/josenavas/repos","events_url":"https://api.github.com/users/josenavas/events{/privacy}","received_events_url":"https://api.github.com/users/josenavas/received_events","type":"User","site_admin":false},"body":"This PR is merging the code from glowing dangerzone.\r\n\r\nThe code in SQLConnectionHandler was a bit hard to follow in some cases because there was no logical structure on the code. I've moved some functions around and github make a fair good job here, it looks like it only had a problem with the `execute_queue` function.\r\n\r\nThe functions `fetchone_with_types` and `fetchall_with_types` have been removed. They're not used anywhere and nobody knows why they're there.\r\n\r\nI've rewritten some of the tests and added a BUNCH of new tests, that is one of the reasons why it shows so many changes.\r\n\r\nOnce this is merged, I will start implementing all the actual improvements to the SQLConnectionHandler that will require changes in the code base - but that will be done in a different branch.\r\n\r\nAs a reminder, all this changes are needed to get the portal types in place.","created_at":"2015-06-09T18:50:14Z","updated_at":"2015-06-10T00:28:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bb4ef3ef3dfd59537cc4eddb17abeb2039c4be53","assignee":null,"milestone":{"url":"https://api.github.com/repos/biocore/qiita/milestones/8","html_url":"https://github.com/biocore/qiita/milestones/Alpha%200.2","labels_url":"https://api.github.com/repos/biocore/qiita/milestones/8/labels","id":1049807,"number":8,"title":"Alpha 0.2","description":"","creator":{"login":"josenavas","id":2501478,"avatar_url":"https://avatars.githubusercontent.com/u/2501478?v=3","gravatar_id":"","url":"https://api.github.com/users/josenavas","html_url":"https://github.com/josenavas","followers_url":"https://api.github.com/users/josenavas/followers","following_url":"https://api.github.com/users/josenavas/following{/other_user}","gists_url":"https://api.github.com/users/josenavas/gists{/gist_id}","starred_url":"https://api.github.com/users/josenavas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josenavas/subscriptions","organizations_url":"https://api.github.com/users/josenavas/orgs","repos_url":"https://api.github.com/users/josenavas/repos","events_url":"https://api.github.com/users/josenavas/events{/privacy}","received_events_url":"https://api.github.com/users/josenavas/received_events","type":"User","site_admin":false},"open_issues":70,"closed_issues":50,"state":"open","created_at":"2015-04-02T04:52:07Z","updated_at":"2015-06-09T18:50:14Z","due_on":"2015-07-03T07:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/biocore/qiita/pulls/1252/commits","review_comments_url":"https://api.github.com/repos/biocore/qiita/pulls/1252/comments","review_comment_url":"https://api.github.com/repos/biocore/qiita/pulls/comments{/number}","comments_url":"https://api.github.com/repos/biocore/qiita/issues/1252/comments","statuses_url":"https://api.github.com/repos/biocore/qiita/statuses/4b7da373e77c8c38894014347211c6491c39c948","head":{"label":"josenavas:merging-code-from-glowing-dangerzone","ref":"merging-code-from-glowing-dangerzone","sha":"4b7da373e77c8c38894014347211c6491c39c948","user":{"login":"josenavas","id":2501478,"avatar_url":"https://avatars.githubusercontent.com/u/2501478?v=3","gravatar_id":"","url":"https://api.github.com/users/josenavas","html_url":"https://github.com/josenavas","followers_url":"https://api.github.com/users/josenavas/followers","following_url":"https://api.github.com/users/josenavas/following{/other_user}","gists_url":"https://api.github.com/users/josenavas/gists{/gist_id}","starred_url":"https://api.github.com/users/josenavas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josenavas/subscriptions","organizations_url":"https://api.github.com/users/josenavas/orgs","repos_url":"https://api.github.com/users/josenavas/repos","events_url":"https://api.github.com/users/josenavas/events{/privacy}","received_events_url":"https://api.github.com/users/josenavas/received_events","type":"User","site_admin":false},"repo":{"id":13527677,"name":"QiiTa","full_name":"josenavas/QiiTa","owner":{"login":"josenavas","id":2501478,"avatar_url":"https://avatars.githubusercontent.com/u/2501478?v=3","gravatar_id":"","url":"https://api.github.com/users/josenavas","html_url":"https://github.com/josenavas","followers_url":"https://api.github.com/users/josenavas/followers","following_url":"https://api.github.com/users/josenavas/following{/other_user}","gists_url":"https://api.github.com/users/josenavas/gists{/gist_id}","starred_url":"https://api.github.com/users/josenavas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josenavas/subscriptions","organizations_url":"https://api.github.com/users/josenavas/orgs","repos_url":"https://api.github.com/users/josenavas/repos","events_url":"https://api.github.com/users/josenavas/events{/privacy}","received_events_url":"https://api.github.com/users/josenavas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/josenavas/QiiTa","description":"QiiTa databasing effort","fork":true,"url":"https://api.github.com/repos/josenavas/QiiTa","forks_url":"https://api.github.com/repos/josenavas/QiiTa/forks","keys_url":"https://api.github.com/repos/josenavas/QiiTa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/josenavas/QiiTa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/josenavas/QiiTa/teams","hooks_url":"https://api.github.com/repos/josenavas/QiiTa/hooks","issue_events_url":"https://api.github.com/repos/josenavas/QiiTa/issues/events{/number}","events_url":"https://api.github.com/repos/josenavas/QiiTa/events","assignees_url":"https://api.github.com/repos/josenavas/QiiTa/assignees{/user}","branches_url":"https://api.github.com/repos/josenavas/QiiTa/branches{/branch}","tags_url":"https://api.github.com/repos/josenavas/QiiTa/tags","blobs_url":"https://api.github.com/repos/josenavas/QiiTa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/josenavas/QiiTa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/josenavas/QiiTa/git/refs{/sha}","trees_url":"https://api.github.com/repos/josenavas/QiiTa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/josenavas/QiiTa/statuses/{sha}","languages_url":"https://api.github.com/repos/josenavas/QiiTa/languages","stargazers_url":"https://api.github.com/repos/josenavas/QiiTa/stargazers","contributors_url":"https://api.github.com/repos/josenavas/QiiTa/contributors","subscribers_url":"https://api.github.com/repos/josenavas/QiiTa/subscribers","subscription_url":"https://api.github.com/repos/josenavas/QiiTa/subscription","commits_url":"https://api.github.com/repos/josenavas/QiiTa/commits{/sha}","git_commits_url":"https://api.github.com/repos/josenavas/QiiTa/git/commits{/sha}","comments_url":"https://api.github.com/repos/josenavas/QiiTa/comments{/number}","issue_comment_url":"https://api.github.com/repos/josenavas/QiiTa/issues/comments{/number}","contents_url":"https://api.github.com/repos/josenavas/QiiTa/contents/{+path}","compare_url":"https://api.github.com/repos/josenavas/QiiTa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/josenavas/QiiTa/merges","archive_url":"https://api.github.com/repos/josenavas/QiiTa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/josenavas/QiiTa/downloads","issues_url":"https://api.github.com/repos/josenavas/QiiTa/issues{/number}","pulls_url":"https://api.github.com/repos/josenavas/QiiTa/pulls{/number}","milestones_url":"https://api.github.com/repos/josenavas/QiiTa/milestones{/number}","notifications_url":"https://api.github.com/repos/josenavas/QiiTa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/josenavas/QiiTa/labels{/name}","releases_url":"https://api.github.com/repos/josenavas/QiiTa/releases{/id}","created_at":"2013-10-12T19:29:32Z","updated_at":"2015-05-05T22:50:05Z","pushed_at":"2015-06-09T20:17:31Z","git_url":"git://github.com/josenavas/QiiTa.git","ssh_url":"git@github.com:josenavas/QiiTa.git","clone_url":"https://github.com/josenavas/QiiTa.git","svn_url":"https://github.com/josenavas/QiiTa","homepage":null,"size":125124,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"biocore:master","ref":"master","sha":"4be3077e220b79fef411ffb833af38abb68b147f","user":{"login":"biocore","id":6241857,"avatar_url":"https://avatars.githubusercontent.com/u/6241857?v=3","gravatar_id":"","url":"https://api.github.com/users/biocore","html_url":"https://github.com/biocore","followers_url":"https://api.github.com/users/biocore/followers","following_url":"https://api.github.com/users/biocore/following{/other_user}","gists_url":"https://api.github.com/users/biocore/gists{/gist_id}","starred_url":"https://api.github.com/users/biocore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocore/subscriptions","organizations_url":"https://api.github.com/users/biocore/orgs","repos_url":"https://api.github.com/users/biocore/repos","events_url":"https://api.github.com/users/biocore/events{/privacy}","received_events_url":"https://api.github.com/users/biocore/received_events","type":"Organization","site_admin":false},"repo":{"id":13131245,"name":"qiita","full_name":"biocore/qiita","owner":{"login":"biocore","id":6241857,"avatar_url":"https://avatars.githubusercontent.com/u/6241857?v=3","gravatar_id":"","url":"https://api.github.com/users/biocore","html_url":"https://github.com/biocore","followers_url":"https://api.github.com/users/biocore/followers","following_url":"https://api.github.com/users/biocore/following{/other_user}","gists_url":"https://api.github.com/users/biocore/gists{/gist_id}","starred_url":"https://api.github.com/users/biocore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocore/subscriptions","organizations_url":"https://api.github.com/users/biocore/orgs","repos_url":"https://api.github.com/users/biocore/repos","events_url":"https://api.github.com/users/biocore/events{/privacy}","received_events_url":"https://api.github.com/users/biocore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/biocore/qiita","description":"Qiita - A QIIME databasing effort","fork":false,"url":"https://api.github.com/repos/biocore/qiita","forks_url":"https://api.github.com/repos/biocore/qiita/forks","keys_url":"https://api.github.com/repos/biocore/qiita/keys{/key_id}","collaborators_url":"https://api.github.com/repos/biocore/qiita/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/biocore/qiita/teams","hooks_url":"https://api.github.com/repos/biocore/qiita/hooks","issue_events_url":"https://api.github.com/repos/biocore/qiita/issues/events{/number}","events_url":"https://api.github.com/repos/biocore/qiita/events","assignees_url":"https://api.github.com/repos/biocore/qiita/assignees{/user}","branches_url":"https://api.github.com/repos/biocore/qiita/branches{/branch}","tags_url":"https://api.github.com/repos/biocore/qiita/tags","blobs_url":"https://api.github.com/repos/biocore/qiita/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/biocore/qiita/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/biocore/qiita/git/refs{/sha}","trees_url":"https://api.github.com/repos/biocore/qiita/git/trees{/sha}","statuses_url":"https://api.github.com/repos/biocore/qiita/statuses/{sha}","languages_url":"https://api.github.com/repos/biocore/qiita/languages","stargazers_url":"https://api.github.com/repos/biocore/qiita/stargazers","contributors_url":"https://api.github.com/repos/biocore/qiita/contributors","subscribers_url":"https://api.github.com/repos/biocore/qiita/subscribers","subscription_url":"https://api.github.com/repos/biocore/qiita/subscription","commits_url":"https://api.github.com/repos/biocore/qiita/commits{/sha}","git_commits_url":"https://api.github.com/repos/biocore/qiita/git/commits{/sha}","comments_url":"https://api.github.com/repos/biocore/qiita/comments{/number}","issue_comment_url":"https://api.github.com/repos/biocore/qiita/issues/comments{/number}","contents_url":"https://api.github.com/repos/biocore/qiita/contents/{+path}","compare_url":"https://api.github.com/repos/biocore/qiita/compare/{base}...{head}","merges_url":"https://api.github.com/repos/biocore/qiita/merges","archive_url":"https://api.github.com/repos/biocore/qiita/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/biocore/qiita/downloads","issues_url":"https://api.github.com/repos/biocore/qiita/issues{/number}","pulls_url":"https://api.github.com/repos/biocore/qiita/pulls{/number}","milestones_url":"https://api.github.com/repos/biocore/qiita/milestones{/number}","notifications_url":"https://api.github.com/repos/biocore/qiita/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/biocore/qiita/labels{/name}","releases_url":"https://api.github.com/repos/biocore/qiita/releases{/id}","created_at":"2013-09-26T18:50:43Z","updated_at":"2015-05-10T01:08:02Z","pushed_at":"2015-06-09T20:17:31Z","git_url":"git://github.com/biocore/qiita.git","ssh_url":"git@github.com:biocore/qiita.git","clone_url":"https://github.com/biocore/qiita.git","svn_url":"https://github.com/biocore/qiita","homepage":"","size":129711,"stargazers_count":19,"watchers_count":19,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"open_issues_count":275,"forks":22,"open_issues":275,"watchers":19,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1252"},"html":{"href":"https://github.com/biocore/qiita/pull/1252"},"issue":{"href":"https://api.github.com/repos/biocore/qiita/issues/1252"},"comments":{"href":"https://api.github.com/repos/biocore/qiita/issues/1252/comments"},"review_comments":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1252/comments"},"review_comment":{"href":"https://api.github.com/repos/biocore/qiita/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/biocore/qiita/pulls/1252/commits"},"statuses":{"href":"https://api.github.com/repos/biocore/qiita/statuses/4b7da373e77c8c38894014347211c6491c39c948"}}}}