{"action":"created","comment":{"url":"https://api.github.com/repos/dchao34/root2postgres/pulls/comments/62150591","id":62150591,"diff_hunk":"@@ -0,0 +1,113 @@\n+#include <iostream>\n+#include <string>\n+#include <vector>\n+#include <map>\n+#include <libpq-fe.h>\n+\n+//#include \"Event.h\"\n+#include \"EventInserterPQ.h\"\n+\n+using std::string;\n+\n+EventInserterPQ::EventInserterPQ(std::string db_name_, std::string table_name_, std::map<std::string, std::vector<std::string> > val_name_){\n+\tdb_name = db_name_;\n+\ttable_name = table_name_;\n+\tval_name = val_name_;\n+}\n+\n+EventInserterPQ::~EventInserterPQ(){\n+\t// delete pointers\n+\tPQfinish(conn);\n+\tPQclear(res);\n+}\n+\n+void EventInserterPQ::CreateTable(){\n+\t//if db_name not exist, create it; else do nothing\n+\tconn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, db_name.c_str(), login, pwd);\n+\tif(PQstatus(conn) != CONNECTION_OK)\n+\t\tthrow PQerrorMessage(conn);\n+\telse{\n+\t\tif(val_name.empty())\n+\t\t\tthrow std::invalid_argument(\"Value_size error: val_name cannot be empty\");\n+\t\telse{\n+\t\t\tstd::string command(\"CREATE TABLE IF NOT EXISTS \");\n+\t\t\tcommand += table_name + \"(\";\n+\t\t\tfor(auto const& i : val_name){\n+\t\t\t\tfor(size_t j = 0; j < i.second.size(); ++j){\n+\t\t\t\t\tcommand += i.second[j] + \" \" + i.first + \",\";\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tcommand.pop_back();\n+\t\t\tcommand += \");\";\n+\t\t\tres = PQexec(conn, command.c_str());\n+\t\t\tif(PQresultStatus(res) != PGRES_COMMAND_OK)\n+\t\t\t\tthrow PQresultErrorMessage(res);\n+\t\t}\n+\t}\n+\treturn;\n+}\n+\n+void EventInserterPQ::insert(){\n+\tCreateTable();\n+\t//Define TupleReader class here:\n+\tstd::string command(\"INSERT INTO \");\n+\t\t\tcommand += table_name + \" VALUES (\";\n+\t\t\tfor(auto const& i : val_name){\n+\t\t\t\tfor(size_t j = 0; j < i.second.size(); ++j){\n+\t\t\t\t\tcommand += to_string(tuplereader.get(i.second[j])) + \",\";\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tcommand.pop_back();\n+\t\t\tcommand += \");\";\n+\t\t\tres = PQexec(conn, command.c_str());\n+\t\t\tif(PQresultStatus(res) != PGRES_COMMAND_OK)\n+\t\t\t\tthrow PQresultErrorMessage(res);\n+}\n+\n+template<typename T>\n+std::string to_string(std::vector<T> x){\n+\tstd::string resultstring(\"'{\");\n+\tif(x.size() == 0) return resultstring + \"}'\";\n+\tfor(size_t i = 0; i < x.size(); ++i){\n+\t\tresultstring += to_string(x[i]) + \",\";","path":"src/EventInserterPQ.cpp","position":72,"original_position":72,"commit_id":"0c7ac8bccebac17385fa403cb335174adfbe34ff","original_commit_id":"0c7ac8bccebac17385fa403cb335174adfbe34ff","user":{"login":"dchao34","id":1263706,"avatar_url":"https://avatars.githubusercontent.com/u/1263706?v=3","gravatar_id":"","url":"https://api.github.com/users/dchao34","html_url":"https://github.com/dchao34","followers_url":"https://api.github.com/users/dchao34/followers","following_url":"https://api.github.com/users/dchao34/following{/other_user}","gists_url":"https://api.github.com/users/dchao34/gists{/gist_id}","starred_url":"https://api.github.com/users/dchao34/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dchao34/subscriptions","organizations_url":"https://api.github.com/users/dchao34/orgs","repos_url":"https://api.github.com/users/dchao34/repos","events_url":"https://api.github.com/users/dchao34/events{/privacy}","received_events_url":"https://api.github.com/users/dchao34/received_events","type":"User","site_admin":false},"body":"Recursion if x[i] is a vector? Again... probably not what you want. Easy fix by changing the name of this function. ","created_at":"2016-05-05T05:47:55Z","updated_at":"2016-05-05T05:47:55Z","html_url":"https://github.com/dchao34/root2postgres/pull/4#discussion_r62150591","pull_request_url":"https://api.github.com/repos/dchao34/root2postgres/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/dchao34/root2postgres/pulls/comments/62150591"},"html":{"href":"https://github.com/dchao34/root2postgres/pull/4#discussion_r62150591"},"pull_request":{"href":"https://api.github.com/repos/dchao34/root2postgres/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/dchao34/root2postgres/pulls/4","id":68959103,"html_url":"https://github.com/dchao34/root2postgres/pull/4","diff_url":"https://github.com/dchao34/root2postgres/pull/4.diff","patch_url":"https://github.com/dchao34/root2postgres/pull/4.patch","issue_url":"https://api.github.com/repos/dchao34/root2postgres/issues/4","number":4,"state":"open","locked":false,"title":"add connector and inserter","user":{"login":"yli5","id":16359276,"avatar_url":"https://avatars.githubusercontent.com/u/16359276?v=3","gravatar_id":"","url":"https://api.github.com/users/yli5","html_url":"https://github.com/yli5","followers_url":"https://api.github.com/users/yli5/followers","following_url":"https://api.github.com/users/yli5/following{/other_user}","gists_url":"https://api.github.com/users/yli5/gists{/gist_id}","starred_url":"https://api.github.com/users/yli5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yli5/subscriptions","organizations_url":"https://api.github.com/users/yli5/orgs","repos_url":"https://api.github.com/users/yli5/repos","events_url":"https://api.github.com/users/yli5/events{/privacy}","received_events_url":"https://api.github.com/users/yli5/received_events","type":"User","site_admin":false},"body":"add EventInserterPQ class, which is used to connect with database.","created_at":"2016-05-05T02:16:43Z","updated_at":"2016-05-05T05:47:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f63130c8d734d13d32a7e29ec023fa0931d715c8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dchao34/root2postgres/pulls/4/commits","review_comments_url":"https://api.github.com/repos/dchao34/root2postgres/pulls/4/comments","review_comment_url":"https://api.github.com/repos/dchao34/root2postgres/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dchao34/root2postgres/issues/4/comments","statuses_url":"https://api.github.com/repos/dchao34/root2postgres/statuses/0c7ac8bccebac17385fa403cb335174adfbe34ff","head":{"label":"yli5:master","ref":"master","sha":"0c7ac8bccebac17385fa403cb335174adfbe34ff","user":{"login":"yli5","id":16359276,"avatar_url":"https://avatars.githubusercontent.com/u/16359276?v=3","gravatar_id":"","url":"https://api.github.com/users/yli5","html_url":"https://github.com/yli5","followers_url":"https://api.github.com/users/yli5/followers","following_url":"https://api.github.com/users/yli5/following{/other_user}","gists_url":"https://api.github.com/users/yli5/gists{/gist_id}","starred_url":"https://api.github.com/users/yli5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yli5/subscriptions","organizations_url":"https://api.github.com/users/yli5/orgs","repos_url":"https://api.github.com/users/yli5/repos","events_url":"https://api.github.com/users/yli5/events{/privacy}","received_events_url":"https://api.github.com/users/yli5/received_events","type":"User","site_admin":false},"repo":{"id":58096769,"name":"root2postgres","full_name":"yli5/root2postgres","owner":{"login":"yli5","id":16359276,"avatar_url":"https://avatars.githubusercontent.com/u/16359276?v=3","gravatar_id":"","url":"https://api.github.com/users/yli5","html_url":"https://github.com/yli5","followers_url":"https://api.github.com/users/yli5/followers","following_url":"https://api.github.com/users/yli5/following{/other_user}","gists_url":"https://api.github.com/users/yli5/gists{/gist_id}","starred_url":"https://api.github.com/users/yli5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yli5/subscriptions","organizations_url":"https://api.github.com/users/yli5/orgs","repos_url":"https://api.github.com/users/yli5/repos","events_url":"https://api.github.com/users/yli5/events{/privacy}","received_events_url":"https://api.github.com/users/yli5/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yli5/root2postgres","description":"","fork":true,"url":"https://api.github.com/repos/yli5/root2postgres","forks_url":"https://api.github.com/repos/yli5/root2postgres/forks","keys_url":"https://api.github.com/repos/yli5/root2postgres/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yli5/root2postgres/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yli5/root2postgres/teams","hooks_url":"https://api.github.com/repos/yli5/root2postgres/hooks","issue_events_url":"https://api.github.com/repos/yli5/root2postgres/issues/events{/number}","events_url":"https://api.github.com/repos/yli5/root2postgres/events","assignees_url":"https://api.github.com/repos/yli5/root2postgres/assignees{/user}","branches_url":"https://api.github.com/repos/yli5/root2postgres/branches{/branch}","tags_url":"https://api.github.com/repos/yli5/root2postgres/tags","blobs_url":"https://api.github.com/repos/yli5/root2postgres/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yli5/root2postgres/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yli5/root2postgres/git/refs{/sha}","trees_url":"https://api.github.com/repos/yli5/root2postgres/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yli5/root2postgres/statuses/{sha}","languages_url":"https://api.github.com/repos/yli5/root2postgres/languages","stargazers_url":"https://api.github.com/repos/yli5/root2postgres/stargazers","contributors_url":"https://api.github.com/repos/yli5/root2postgres/contributors","subscribers_url":"https://api.github.com/repos/yli5/root2postgres/subscribers","subscription_url":"https://api.github.com/repos/yli5/root2postgres/subscription","commits_url":"https://api.github.com/repos/yli5/root2postgres/commits{/sha}","git_commits_url":"https://api.github.com/repos/yli5/root2postgres/git/commits{/sha}","comments_url":"https://api.github.com/repos/yli5/root2postgres/comments{/number}","issue_comment_url":"https://api.github.com/repos/yli5/root2postgres/issues/comments{/number}","contents_url":"https://api.github.com/repos/yli5/root2postgres/contents/{+path}","compare_url":"https://api.github.com/repos/yli5/root2postgres/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yli5/root2postgres/merges","archive_url":"https://api.github.com/repos/yli5/root2postgres/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yli5/root2postgres/downloads","issues_url":"https://api.github.com/repos/yli5/root2postgres/issues{/number}","pulls_url":"https://api.github.com/repos/yli5/root2postgres/pulls{/number}","milestones_url":"https://api.github.com/repos/yli5/root2postgres/milestones{/number}","notifications_url":"https://api.github.com/repos/yli5/root2postgres/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yli5/root2postgres/labels{/name}","releases_url":"https://api.github.com/repos/yli5/root2postgres/releases{/id}","deployments_url":"https://api.github.com/repos/yli5/root2postgres/deployments","created_at":"2016-05-05T02:00:13Z","updated_at":"2016-05-05T02:00:14Z","pushed_at":"2016-05-05T02:14:43Z","git_url":"git://github.com/yli5/root2postgres.git","ssh_url":"git@github.com:yli5/root2postgres.git","clone_url":"https://github.com/yli5/root2postgres.git","svn_url":"https://github.com/yli5/root2postgres","homepage":null,"size":10,"stargazers_count":0,"watchers_count":0,"language":"C++","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":"dchao34:master","ref":"master","sha":"ef031db0ab8fa1bfe4214e0b91396497b2a4c310","user":{"login":"dchao34","id":1263706,"avatar_url":"https://avatars.githubusercontent.com/u/1263706?v=3","gravatar_id":"","url":"https://api.github.com/users/dchao34","html_url":"https://github.com/dchao34","followers_url":"https://api.github.com/users/dchao34/followers","following_url":"https://api.github.com/users/dchao34/following{/other_user}","gists_url":"https://api.github.com/users/dchao34/gists{/gist_id}","starred_url":"https://api.github.com/users/dchao34/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dchao34/subscriptions","organizations_url":"https://api.github.com/users/dchao34/orgs","repos_url":"https://api.github.com/users/dchao34/repos","events_url":"https://api.github.com/users/dchao34/events{/privacy}","received_events_url":"https://api.github.com/users/dchao34/received_events","type":"User","site_admin":false},"repo":{"id":57901911,"name":"root2postgres","full_name":"dchao34/root2postgres","owner":{"login":"dchao34","id":1263706,"avatar_url":"https://avatars.githubusercontent.com/u/1263706?v=3","gravatar_id":"","url":"https://api.github.com/users/dchao34","html_url":"https://github.com/dchao34","followers_url":"https://api.github.com/users/dchao34/followers","following_url":"https://api.github.com/users/dchao34/following{/other_user}","gists_url":"https://api.github.com/users/dchao34/gists{/gist_id}","starred_url":"https://api.github.com/users/dchao34/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dchao34/subscriptions","organizations_url":"https://api.github.com/users/dchao34/orgs","repos_url":"https://api.github.com/users/dchao34/repos","events_url":"https://api.github.com/users/dchao34/events{/privacy}","received_events_url":"https://api.github.com/users/dchao34/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dchao34/root2postgres","description":"","fork":false,"url":"https://api.github.com/repos/dchao34/root2postgres","forks_url":"https://api.github.com/repos/dchao34/root2postgres/forks","keys_url":"https://api.github.com/repos/dchao34/root2postgres/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dchao34/root2postgres/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dchao34/root2postgres/teams","hooks_url":"https://api.github.com/repos/dchao34/root2postgres/hooks","issue_events_url":"https://api.github.com/repos/dchao34/root2postgres/issues/events{/number}","events_url":"https://api.github.com/repos/dchao34/root2postgres/events","assignees_url":"https://api.github.com/repos/dchao34/root2postgres/assignees{/user}","branches_url":"https://api.github.com/repos/dchao34/root2postgres/branches{/branch}","tags_url":"https://api.github.com/repos/dchao34/root2postgres/tags","blobs_url":"https://api.github.com/repos/dchao34/root2postgres/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dchao34/root2postgres/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dchao34/root2postgres/git/refs{/sha}","trees_url":"https://api.github.com/repos/dchao34/root2postgres/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dchao34/root2postgres/statuses/{sha}","languages_url":"https://api.github.com/repos/dchao34/root2postgres/languages","stargazers_url":"https://api.github.com/repos/dchao34/root2postgres/stargazers","contributors_url":"https://api.github.com/repos/dchao34/root2postgres/contributors","subscribers_url":"https://api.github.com/repos/dchao34/root2postgres/subscribers","subscription_url":"https://api.github.com/repos/dchao34/root2postgres/subscription","commits_url":"https://api.github.com/repos/dchao34/root2postgres/commits{/sha}","git_commits_url":"https://api.github.com/repos/dchao34/root2postgres/git/commits{/sha}","comments_url":"https://api.github.com/repos/dchao34/root2postgres/comments{/number}","issue_comment_url":"https://api.github.com/repos/dchao34/root2postgres/issues/comments{/number}","contents_url":"https://api.github.com/repos/dchao34/root2postgres/contents/{+path}","compare_url":"https://api.github.com/repos/dchao34/root2postgres/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dchao34/root2postgres/merges","archive_url":"https://api.github.com/repos/dchao34/root2postgres/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dchao34/root2postgres/downloads","issues_url":"https://api.github.com/repos/dchao34/root2postgres/issues{/number}","pulls_url":"https://api.github.com/repos/dchao34/root2postgres/pulls{/number}","milestones_url":"https://api.github.com/repos/dchao34/root2postgres/milestones{/number}","notifications_url":"https://api.github.com/repos/dchao34/root2postgres/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dchao34/root2postgres/labels{/name}","releases_url":"https://api.github.com/repos/dchao34/root2postgres/releases{/id}","deployments_url":"https://api.github.com/repos/dchao34/root2postgres/deployments","created_at":"2016-05-02T15:58:32Z","updated_at":"2016-05-02T16:31:25Z","pushed_at":"2016-05-05T05:19:04Z","git_url":"git://github.com/dchao34/root2postgres.git","ssh_url":"git@github.com:dchao34/root2postgres.git","clone_url":"https://github.com/dchao34/root2postgres.git","svn_url":"https://github.com/dchao34/root2postgres","homepage":null,"size":26,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dchao34/root2postgres/pulls/4"},"html":{"href":"https://github.com/dchao34/root2postgres/pull/4"},"issue":{"href":"https://api.github.com/repos/dchao34/root2postgres/issues/4"},"comments":{"href":"https://api.github.com/repos/dchao34/root2postgres/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/dchao34/root2postgres/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/dchao34/root2postgres/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dchao34/root2postgres/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/dchao34/root2postgres/statuses/0c7ac8bccebac17385fa403cb335174adfbe34ff"}}}}