{"action":"created","comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/37896998","id":37896998,"diff_hunk":"@@ -49,22 +56,52 @@ func runTerm(cmd *cobra.Command, args []string) {\n \t\t_ = liner.Close()\n \t}()\n \n+\tfmt.Fprint(osStdout, infoMessage)\n+\n+\t// TODO(marc): allow passing statements on the command line,\n+\t// or specifying a flag. This would make testing much simpler.\n+\t// TODO(marc): add test.\n+\tvar stmt string\n \tfor {\n-\t\t// TODO(marc): handle multi-line, this will require ';' terminated statements.\n-\t\tl, err := liner.Prompt(\"> \")\n+\t\tprompt := \"> \"\n+\t\tif len(stmt) != 0 {\n+\t\t\t// We're continuing a statement: indent relative to beginning.\n+\t\t\tprompt = \"    \"\n+\t\t}\n+\n+\t\tl, err := liner.Prompt(prompt)\n \t\tif err != nil {\n \t\t\tif err != io.EOF {\n-\t\t\t\tfmt.Fprintf(os.Stderr, \"Input error: %s\\n\", err)\n+\t\t\t\tfmt.Fprintf(osStderr, \"Input error: %s\\n\", err)\n \t\t\t}\n \t\t\tbreak\n \t\t}\n-\t\tif len(l) == 0 {\n+\n+\t\t// See if we have a semicolon at the end of the line (ignoring\n+\t\t// whitespace after it).\n+\t\ttmpLine := strings.TrimSpace(l)\n+\t\tif len(tmpLine) == 0 {\n+\t\t\tcontinue\n+\t\t}\n+\n+\t\t// Always use the non-trimmed line, we wouldn't want to\n+\t\t// break a statement due to a stripped begin or end space.\n+\t\t// We always insert a space when a newline is generated.\n+\t\t// This means that qualified names cannot be broken up.\n+\t\tstmt += \" \" + l","path":"cli/sql.go","position":null,"original_position":61,"commit_id":"4e48f6266e089d1575c13c3d7a1a4e5986dcb59c","original_commit_id":"dae4c31e64783a20d494df98b88b42577846c827","user":{"login":"MBerhault","id":5901480,"avatar_url":"https://avatars.githubusercontent.com/u/5901480?v=3","gravatar_id":"","url":"https://api.github.com/users/MBerhault","html_url":"https://github.com/MBerhault","followers_url":"https://api.github.com/users/MBerhault/followers","following_url":"https://api.github.com/users/MBerhault/following{/other_user}","gists_url":"https://api.github.com/users/MBerhault/gists{/gist_id}","starred_url":"https://api.github.com/users/MBerhault/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MBerhault/subscriptions","organizations_url":"https://api.github.com/users/MBerhault/orgs","repos_url":"https://api.github.com/users/MBerhault/repos","events_url":"https://api.github.com/users/MBerhault/events{/privacy}","received_events_url":"https://api.github.com/users/MBerhault/received_events","type":"User","site_admin":false},"body":"I'm confused. why would newlines concatenate?","created_at":"2015-08-25T17:56:23Z","updated_at":"2015-08-25T17:56:23Z","html_url":"https://github.com/cockroachdb/cockroach/pull/2259#discussion_r37896998","pull_request_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2259","_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/37896998"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/2259#discussion_r37896998"},"pull_request":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2259"}}},"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2259","id":43313363,"html_url":"https://github.com/cockroachdb/cockroach/pull/2259","diff_url":"https://github.com/cockroachdb/cockroach/pull/2259.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/2259.patch","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/2259","number":2259,"state":"open","locked":false,"title":"Add multi-line support on sql cmdline.","user":{"login":"MBerhault","id":5901480,"avatar_url":"https://avatars.githubusercontent.com/u/5901480?v=3","gravatar_id":"","url":"https://api.github.com/users/MBerhault","html_url":"https://github.com/MBerhault","followers_url":"https://api.github.com/users/MBerhault/followers","following_url":"https://api.github.com/users/MBerhault/following{/other_user}","gists_url":"https://api.github.com/users/MBerhault/gists{/gist_id}","starred_url":"https://api.github.com/users/MBerhault/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MBerhault/subscriptions","organizations_url":"https://api.github.com/users/MBerhault/orgs","repos_url":"https://api.github.com/users/MBerhault/repos","events_url":"https://api.github.com/users/MBerhault/events{/privacy}","received_events_url":"https://api.github.com/users/MBerhault/received_events","type":"User","site_admin":false},"body":"We require consider the statement not finished until we find a\r\nsemicolon at the end of the line (ignore whitespace).\r\n\r\nWe insert a space in-between read lines, otherwise it's a little odd.\r\n\r\nFor example: multi-line statement, followed by history-recall (up-arrow)\r\nfollowed but multi-statement line (the latter already worked).\r\n\r\n```sql\r\n> select *\r\n    from system.namespace\r\n    where id=\r\n    1\r\n    ;\r\n+----------+--------+----+\r\n| parentID |  name  | id |\r\n+----------+--------+----+\r\n| 0        | system | 1  |\r\n+----------+--------+----+\r\n>  select * from system.namespace where id= 1 ;\r\n+----------+--------+----+\r\n| parentID |  name  | id |\r\n+----------+--------+----+\r\n| 0        | system | 1  |\r\n+----------+--------+----+\r\n> set database=system; show tables;\r\n+------------+\r\n|   Table    |\r\n+------------+\r\n| descriptor |\r\n| namespace  |\r\n| users      |\r\n+------------+\r\n>\r\n```","created_at":"2015-08-25T17:27:52Z","updated_at":"2015-08-25T17:56:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ff9e2b8a1c2c9a6f064ffa921c6d146fc361e40e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2259/commits","review_comments_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2259/comments","review_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/2259/comments","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/4e48f6266e089d1575c13c3d7a1a4e5986dcb59c","head":{"label":"cockroachdb:marc/multiline_sql","ref":"marc/multiline_sql","sha":"4e48f6266e089d1575c13c3d7a1a4e5986dcb59c","user":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"repo":{"id":16563587,"name":"cockroach","full_name":"cockroachdb/cockroach","owner":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cockroachdb/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":false,"url":"https://api.github.com/repos/cockroachdb/cockroach","forks_url":"https://api.github.com/repos/cockroachdb/cockroach/forks","keys_url":"https://api.github.com/repos/cockroachdb/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cockroachdb/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cockroachdb/cockroach/teams","hooks_url":"https://api.github.com/repos/cockroachdb/cockroach/hooks","issue_events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/cockroachdb/cockroach/events","assignees_url":"https://api.github.com/repos/cockroachdb/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/cockroachdb/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/cockroachdb/cockroach/tags","blobs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cockroachdb/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/cockroachdb/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/cockroachdb/cockroach/languages","stargazers_url":"https://api.github.com/repos/cockroachdb/cockroach/stargazers","contributors_url":"https://api.github.com/repos/cockroachdb/cockroach/contributors","subscribers_url":"https://api.github.com/repos/cockroachdb/cockroach/subscribers","subscription_url":"https://api.github.com/repos/cockroachdb/cockroach/subscription","commits_url":"https://api.github.com/repos/cockroachdb/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/cockroachdb/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/cockroachdb/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/cockroachdb/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cockroachdb/cockroach/merges","archive_url":"https://api.github.com/repos/cockroachdb/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cockroachdb/cockroach/downloads","issues_url":"https://api.github.com/repos/cockroachdb/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/cockroachdb/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/cockroachdb/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/cockroachdb/cockroach/releases{/id}","created_at":"2014-02-06T00:18:47Z","updated_at":"2015-08-25T14:48:13Z","pushed_at":"2015-08-25T17:54:58Z","git_url":"git://github.com/cockroachdb/cockroach.git","ssh_url":"git@github.com:cockroachdb/cockroach.git","clone_url":"https://github.com/cockroachdb/cockroach.git","svn_url":"https://github.com/cockroachdb/cockroach","homepage":null,"size":51514,"stargazers_count":5044,"watchers_count":5044,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":398,"mirror_url":null,"open_issues_count":159,"forks":398,"open_issues":159,"watchers":5044,"default_branch":"master"}},"base":{"label":"cockroachdb:master","ref":"master","sha":"3b29e7dccefa04a5380438dd014637d80707adc2","user":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"repo":{"id":16563587,"name":"cockroach","full_name":"cockroachdb/cockroach","owner":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cockroachdb/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":false,"url":"https://api.github.com/repos/cockroachdb/cockroach","forks_url":"https://api.github.com/repos/cockroachdb/cockroach/forks","keys_url":"https://api.github.com/repos/cockroachdb/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cockroachdb/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cockroachdb/cockroach/teams","hooks_url":"https://api.github.com/repos/cockroachdb/cockroach/hooks","issue_events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/cockroachdb/cockroach/events","assignees_url":"https://api.github.com/repos/cockroachdb/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/cockroachdb/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/cockroachdb/cockroach/tags","blobs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cockroachdb/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/cockroachdb/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/cockroachdb/cockroach/languages","stargazers_url":"https://api.github.com/repos/cockroachdb/cockroach/stargazers","contributors_url":"https://api.github.com/repos/cockroachdb/cockroach/contributors","subscribers_url":"https://api.github.com/repos/cockroachdb/cockroach/subscribers","subscription_url":"https://api.github.com/repos/cockroachdb/cockroach/subscription","commits_url":"https://api.github.com/repos/cockroachdb/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/cockroachdb/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/cockroachdb/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/cockroachdb/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cockroachdb/cockroach/merges","archive_url":"https://api.github.com/repos/cockroachdb/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cockroachdb/cockroach/downloads","issues_url":"https://api.github.com/repos/cockroachdb/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/cockroachdb/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/cockroachdb/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/cockroachdb/cockroach/releases{/id}","created_at":"2014-02-06T00:18:47Z","updated_at":"2015-08-25T14:48:13Z","pushed_at":"2015-08-25T17:54:58Z","git_url":"git://github.com/cockroachdb/cockroach.git","ssh_url":"git@github.com:cockroachdb/cockroach.git","clone_url":"https://github.com/cockroachdb/cockroach.git","svn_url":"https://github.com/cockroachdb/cockroach","homepage":null,"size":51514,"stargazers_count":5044,"watchers_count":5044,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":398,"mirror_url":null,"open_issues_count":159,"forks":398,"open_issues":159,"watchers":5044,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2259"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/2259"},"issue":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/2259"},"comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/2259/comments"},"review_comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2259/comments"},"review_comment":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2259/commits"},"statuses":{"href":"https://api.github.com/repos/cockroachdb/cockroach/statuses/4e48f6266e089d1575c13c3d7a1a4e5986dcb59c"}}}}