{"action":"created","comment":{"url":"https://api.github.com/repos/felixge/node-mysql/pulls/comments/26006474","id":26006474,"diff_hunk":"@@ -255,6 +259,13 @@ Pool.prototype.escapeId = function escapeId(value) {\n   return mysql.escapeId(value, false);\n };\n \n+Pool.prototype.format = function(sql, values) {\n+  if (typeof this.config.connectionConfig.queryFormat == \"function\") {\n+    return this.config.connectionConfig.queryFormat.call(this, sql, values, this.config.connectionConfig.timezone);","path":"lib/Pool.js","position":17,"original_position":17,"commit_id":"3cd3833af4ffc73191e8fb33c1073a93f0613ac7","original_commit_id":"3cd3833af4ffc73191e8fb33c1073a93f0613ac7","user":{"login":"dougwilson","id":67512,"avatar_url":"https://avatars.githubusercontent.com/u/67512?v=3","gravatar_id":"","url":"https://api.github.com/users/dougwilson","html_url":"https://github.com/dougwilson","followers_url":"https://api.github.com/users/dougwilson/followers","following_url":"https://api.github.com/users/dougwilson/following{/other_user}","gists_url":"https://api.github.com/users/dougwilson/gists{/gist_id}","starred_url":"https://api.github.com/users/dougwilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougwilson/subscriptions","organizations_url":"https://api.github.com/users/dougwilson/orgs","repos_url":"https://api.github.com/users/dougwilson/repos","events_url":"https://api.github.com/users/dougwilson/events{/privacy}","received_events_url":"https://api.github.com/users/dougwilson/received_events","type":"User","site_admin":false},"body":"Otherwise there is no need to add a new commit, really. I've already adjusted your commit to make it an instance method (still under your name). The problem right now is backwards compatibility with this function context.","created_at":"2015-03-08T16:19:13Z","updated_at":"2015-03-08T16:19:13Z","html_url":"https://github.com/felixge/node-mysql/pull/991#discussion_r26006474","pull_request_url":"https://api.github.com/repos/felixge/node-mysql/pulls/991","_links":{"self":{"href":"https://api.github.com/repos/felixge/node-mysql/pulls/comments/26006474"},"html":{"href":"https://github.com/felixge/node-mysql/pull/991#discussion_r26006474"},"pull_request":{"href":"https://api.github.com/repos/felixge/node-mysql/pulls/991"}}},"pull_request":{"url":"https://api.github.com/repos/felixge/node-mysql/pulls/991","id":29149027,"html_url":"https://github.com/felixge/node-mysql/pull/991","diff_url":"https://github.com/felixge/node-mysql/pull/991.diff","patch_url":"https://github.com/felixge/node-mysql/pull/991.patch","issue_url":"https://api.github.com/repos/felixge/node-mysql/issues/991","number":991,"state":"open","locked":false,"title":"Get formatted query from Pool.query() method","user":{"login":"surfbuds","id":524493,"avatar_url":"https://avatars.githubusercontent.com/u/524493?v=3","gravatar_id":"","url":"https://api.github.com/users/surfbuds","html_url":"https://github.com/surfbuds","followers_url":"https://api.github.com/users/surfbuds/followers","following_url":"https://api.github.com/users/surfbuds/following{/other_user}","gists_url":"https://api.github.com/users/surfbuds/gists{/gist_id}","starred_url":"https://api.github.com/users/surfbuds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surfbuds/subscriptions","organizations_url":"https://api.github.com/users/surfbuds/orgs","repos_url":"https://api.github.com/users/surfbuds/repos","events_url":"https://api.github.com/users/surfbuds/events{/privacy}","received_events_url":"https://api.github.com/users/surfbuds/received_events","type":"User","site_admin":false},"body":"### Solution to resolve #984\r\n```javascript\r\nvar p= Pool.query(sql,data, function (){});\r\nconsole.log(p.sql); // p.sql is not formatted\r\n```\r\nThis commit changes the behavior of `Pool.query()` method so as to return the **formatted SQL statement** as expected, as in `Connection.query()`.\r\n#### Preventing side effects\r\nSince `Pool.query()` method uses `Connection.query()` internally, `Connection.query()` needs to know if  the SQL statement has already been formatted so as to prevent double formatting and corrupting the query.\r\n\r\nA new Query object property `isFormatted` keeps track of formatting status.\r\n#### Additional method\r\nThe `Pool.prototype.format` method was added to Pool module. Similar to `Connection.prototype.format` method and modified to work inside the Pool class.\r\n\r\n#### Testing with error inducing query\r\n\r\n```sql\r\nSELECT name, rdate FROM contacts WHERE id = 1 OR name = 'John ? J ?'\r\n```\r\n\r\nUsing the `Pool.query` method this query could be passed this way\r\n```javascript\r\nvar columns = ['name', 'rdate'];\r\nvar userId = 1;\r\nvar userName=\"John ? J ?\";\r\nvar sql_query = 'SELECT ?? FROM ?? WHERE id=? OR name=?';\r\n\r\nvar P = pool.query(search, [columns, 'contacts', userId, userName], function(err, rows, fields) {\r\n\t\tif (err) throw err;\r\n\t\t// do whatever\r\n});\r\n```\r\nIn the absence of the `isFormatted` property, if we allow the `Pool.query()` method to format *(escape and replace placeholders)* a query before it is passed to the `Connection.query` method, the latter will try to reformat the query a second time by replacing the `?` inside `'John ? J ?'` with another copy of the same string, resulting in an SQL error.\r\n\r\nThe addition of  the `isFormatted` property to the Query object is crucial for this fix to work. It is `undefined` by default and evaluates to `false` in a boolean operation. Therefore no change was made to the `lib/protocol/sequences/Query.js` file. The property is set after `Connection.createQuery()` method returns a Query object.\r\n\r\n> Note: `Connection.createQuery()`  doesn't return a new Query object if it is passed a Query object, thus conserving the `isFormatted` property if already set.\r\n","created_at":"2015-02-12T02:53:10Z","updated_at":"2015-03-08T16:19:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cba0c62a131ed436f8af10304569a616de56b07a","assignee":{"login":"dougwilson","id":67512,"avatar_url":"https://avatars.githubusercontent.com/u/67512?v=3","gravatar_id":"","url":"https://api.github.com/users/dougwilson","html_url":"https://github.com/dougwilson","followers_url":"https://api.github.com/users/dougwilson/followers","following_url":"https://api.github.com/users/dougwilson/following{/other_user}","gists_url":"https://api.github.com/users/dougwilson/gists{/gist_id}","starred_url":"https://api.github.com/users/dougwilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougwilson/subscriptions","organizations_url":"https://api.github.com/users/dougwilson/orgs","repos_url":"https://api.github.com/users/dougwilson/repos","events_url":"https://api.github.com/users/dougwilson/events{/privacy}","received_events_url":"https://api.github.com/users/dougwilson/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/felixge/node-mysql/milestones/8","html_url":"https://github.com/felixge/node-mysql/milestones/2.6","labels_url":"https://api.github.com/repos/felixge/node-mysql/milestones/8/labels","id":793348,"number":8,"title":"2.6","description":"","creator":{"login":"dougwilson","id":67512,"avatar_url":"https://avatars.githubusercontent.com/u/67512?v=3","gravatar_id":"","url":"https://api.github.com/users/dougwilson","html_url":"https://github.com/dougwilson","followers_url":"https://api.github.com/users/dougwilson/followers","following_url":"https://api.github.com/users/dougwilson/following{/other_user}","gists_url":"https://api.github.com/users/dougwilson/gists{/gist_id}","starred_url":"https://api.github.com/users/dougwilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougwilson/subscriptions","organizations_url":"https://api.github.com/users/dougwilson/orgs","repos_url":"https://api.github.com/users/dougwilson/repos","events_url":"https://api.github.com/users/dougwilson/events{/privacy}","received_events_url":"https://api.github.com/users/dougwilson/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":3,"state":"open","created_at":"2014-09-17T16:37:30Z","updated_at":"2015-03-08T06:45:39Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/felixge/node-mysql/pulls/991/commits","review_comments_url":"https://api.github.com/repos/felixge/node-mysql/pulls/991/comments","review_comment_url":"https://api.github.com/repos/felixge/node-mysql/pulls/comments{/number}","comments_url":"https://api.github.com/repos/felixge/node-mysql/issues/991/comments","statuses_url":"https://api.github.com/repos/felixge/node-mysql/statuses/3cd3833af4ffc73191e8fb33c1073a93f0613ac7","head":{"label":"surfbuds:master","ref":"master","sha":"3cd3833af4ffc73191e8fb33c1073a93f0613ac7","user":{"login":"surfbuds","id":524493,"avatar_url":"https://avatars.githubusercontent.com/u/524493?v=3","gravatar_id":"","url":"https://api.github.com/users/surfbuds","html_url":"https://github.com/surfbuds","followers_url":"https://api.github.com/users/surfbuds/followers","following_url":"https://api.github.com/users/surfbuds/following{/other_user}","gists_url":"https://api.github.com/users/surfbuds/gists{/gist_id}","starred_url":"https://api.github.com/users/surfbuds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surfbuds/subscriptions","organizations_url":"https://api.github.com/users/surfbuds/orgs","repos_url":"https://api.github.com/users/surfbuds/repos","events_url":"https://api.github.com/users/surfbuds/events{/privacy}","received_events_url":"https://api.github.com/users/surfbuds/received_events","type":"User","site_admin":false},"repo":{"id":30499320,"name":"node-mysql","full_name":"surfbuds/node-mysql","owner":{"login":"surfbuds","id":524493,"avatar_url":"https://avatars.githubusercontent.com/u/524493?v=3","gravatar_id":"","url":"https://api.github.com/users/surfbuds","html_url":"https://github.com/surfbuds","followers_url":"https://api.github.com/users/surfbuds/followers","following_url":"https://api.github.com/users/surfbuds/following{/other_user}","gists_url":"https://api.github.com/users/surfbuds/gists{/gist_id}","starred_url":"https://api.github.com/users/surfbuds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surfbuds/subscriptions","organizations_url":"https://api.github.com/users/surfbuds/orgs","repos_url":"https://api.github.com/users/surfbuds/repos","events_url":"https://api.github.com/users/surfbuds/events{/privacy}","received_events_url":"https://api.github.com/users/surfbuds/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/surfbuds/node-mysql","description":"A pure node.js JavaScript Client implementing the MySql protocol.","fork":true,"url":"https://api.github.com/repos/surfbuds/node-mysql","forks_url":"https://api.github.com/repos/surfbuds/node-mysql/forks","keys_url":"https://api.github.com/repos/surfbuds/node-mysql/keys{/key_id}","collaborators_url":"https://api.github.com/repos/surfbuds/node-mysql/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/surfbuds/node-mysql/teams","hooks_url":"https://api.github.com/repos/surfbuds/node-mysql/hooks","issue_events_url":"https://api.github.com/repos/surfbuds/node-mysql/issues/events{/number}","events_url":"https://api.github.com/repos/surfbuds/node-mysql/events","assignees_url":"https://api.github.com/repos/surfbuds/node-mysql/assignees{/user}","branches_url":"https://api.github.com/repos/surfbuds/node-mysql/branches{/branch}","tags_url":"https://api.github.com/repos/surfbuds/node-mysql/tags","blobs_url":"https://api.github.com/repos/surfbuds/node-mysql/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/surfbuds/node-mysql/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/surfbuds/node-mysql/git/refs{/sha}","trees_url":"https://api.github.com/repos/surfbuds/node-mysql/git/trees{/sha}","statuses_url":"https://api.github.com/repos/surfbuds/node-mysql/statuses/{sha}","languages_url":"https://api.github.com/repos/surfbuds/node-mysql/languages","stargazers_url":"https://api.github.com/repos/surfbuds/node-mysql/stargazers","contributors_url":"https://api.github.com/repos/surfbuds/node-mysql/contributors","subscribers_url":"https://api.github.com/repos/surfbuds/node-mysql/subscribers","subscription_url":"https://api.github.com/repos/surfbuds/node-mysql/subscription","commits_url":"https://api.github.com/repos/surfbuds/node-mysql/commits{/sha}","git_commits_url":"https://api.github.com/repos/surfbuds/node-mysql/git/commits{/sha}","comments_url":"https://api.github.com/repos/surfbuds/node-mysql/comments{/number}","issue_comment_url":"https://api.github.com/repos/surfbuds/node-mysql/issues/comments{/number}","contents_url":"https://api.github.com/repos/surfbuds/node-mysql/contents/{+path}","compare_url":"https://api.github.com/repos/surfbuds/node-mysql/compare/{base}...{head}","merges_url":"https://api.github.com/repos/surfbuds/node-mysql/merges","archive_url":"https://api.github.com/repos/surfbuds/node-mysql/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/surfbuds/node-mysql/downloads","issues_url":"https://api.github.com/repos/surfbuds/node-mysql/issues{/number}","pulls_url":"https://api.github.com/repos/surfbuds/node-mysql/pulls{/number}","milestones_url":"https://api.github.com/repos/surfbuds/node-mysql/milestones{/number}","notifications_url":"https://api.github.com/repos/surfbuds/node-mysql/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/surfbuds/node-mysql/labels{/name}","releases_url":"https://api.github.com/repos/surfbuds/node-mysql/releases{/id}","created_at":"2015-02-08T17:38:07Z","updated_at":"2015-02-16T01:02:31Z","pushed_at":"2015-02-16T01:02:29Z","git_url":"git://github.com/surfbuds/node-mysql.git","ssh_url":"git@github.com:surfbuds/node-mysql.git","clone_url":"https://github.com/surfbuds/node-mysql.git","svn_url":"https://github.com/surfbuds/node-mysql","homepage":"","size":2136,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"felixge:master","ref":"master","sha":"6e09a484e437c970d757d0a09c62ac729907af6f","user":{"login":"felixge","id":15000,"avatar_url":"https://avatars.githubusercontent.com/u/15000?v=3","gravatar_id":"","url":"https://api.github.com/users/felixge","html_url":"https://github.com/felixge","followers_url":"https://api.github.com/users/felixge/followers","following_url":"https://api.github.com/users/felixge/following{/other_user}","gists_url":"https://api.github.com/users/felixge/gists{/gist_id}","starred_url":"https://api.github.com/users/felixge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felixge/subscriptions","organizations_url":"https://api.github.com/users/felixge/orgs","repos_url":"https://api.github.com/users/felixge/repos","events_url":"https://api.github.com/users/felixge/events{/privacy}","received_events_url":"https://api.github.com/users/felixge/received_events","type":"User","site_admin":false},"repo":{"id":805461,"name":"node-mysql","full_name":"felixge/node-mysql","owner":{"login":"felixge","id":15000,"avatar_url":"https://avatars.githubusercontent.com/u/15000?v=3","gravatar_id":"","url":"https://api.github.com/users/felixge","html_url":"https://github.com/felixge","followers_url":"https://api.github.com/users/felixge/followers","following_url":"https://api.github.com/users/felixge/following{/other_user}","gists_url":"https://api.github.com/users/felixge/gists{/gist_id}","starred_url":"https://api.github.com/users/felixge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felixge/subscriptions","organizations_url":"https://api.github.com/users/felixge/orgs","repos_url":"https://api.github.com/users/felixge/repos","events_url":"https://api.github.com/users/felixge/events{/privacy}","received_events_url":"https://api.github.com/users/felixge/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/felixge/node-mysql","description":"A pure node.js JavaScript Client implementing the MySql protocol.","fork":false,"url":"https://api.github.com/repos/felixge/node-mysql","forks_url":"https://api.github.com/repos/felixge/node-mysql/forks","keys_url":"https://api.github.com/repos/felixge/node-mysql/keys{/key_id}","collaborators_url":"https://api.github.com/repos/felixge/node-mysql/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/felixge/node-mysql/teams","hooks_url":"https://api.github.com/repos/felixge/node-mysql/hooks","issue_events_url":"https://api.github.com/repos/felixge/node-mysql/issues/events{/number}","events_url":"https://api.github.com/repos/felixge/node-mysql/events","assignees_url":"https://api.github.com/repos/felixge/node-mysql/assignees{/user}","branches_url":"https://api.github.com/repos/felixge/node-mysql/branches{/branch}","tags_url":"https://api.github.com/repos/felixge/node-mysql/tags","blobs_url":"https://api.github.com/repos/felixge/node-mysql/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/felixge/node-mysql/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/felixge/node-mysql/git/refs{/sha}","trees_url":"https://api.github.com/repos/felixge/node-mysql/git/trees{/sha}","statuses_url":"https://api.github.com/repos/felixge/node-mysql/statuses/{sha}","languages_url":"https://api.github.com/repos/felixge/node-mysql/languages","stargazers_url":"https://api.github.com/repos/felixge/node-mysql/stargazers","contributors_url":"https://api.github.com/repos/felixge/node-mysql/contributors","subscribers_url":"https://api.github.com/repos/felixge/node-mysql/subscribers","subscription_url":"https://api.github.com/repos/felixge/node-mysql/subscription","commits_url":"https://api.github.com/repos/felixge/node-mysql/commits{/sha}","git_commits_url":"https://api.github.com/repos/felixge/node-mysql/git/commits{/sha}","comments_url":"https://api.github.com/repos/felixge/node-mysql/comments{/number}","issue_comment_url":"https://api.github.com/repos/felixge/node-mysql/issues/comments{/number}","contents_url":"https://api.github.com/repos/felixge/node-mysql/contents/{+path}","compare_url":"https://api.github.com/repos/felixge/node-mysql/compare/{base}...{head}","merges_url":"https://api.github.com/repos/felixge/node-mysql/merges","archive_url":"https://api.github.com/repos/felixge/node-mysql/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/felixge/node-mysql/downloads","issues_url":"https://api.github.com/repos/felixge/node-mysql/issues{/number}","pulls_url":"https://api.github.com/repos/felixge/node-mysql/pulls{/number}","milestones_url":"https://api.github.com/repos/felixge/node-mysql/milestones{/number}","notifications_url":"https://api.github.com/repos/felixge/node-mysql/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/felixge/node-mysql/labels{/name}","releases_url":"https://api.github.com/repos/felixge/node-mysql/releases{/id}","created_at":"2010-07-29T14:58:13Z","updated_at":"2015-03-08T15:51:43Z","pushed_at":"2015-03-08T06:45:38Z","git_url":"git://github.com/felixge/node-mysql.git","ssh_url":"git@github.com:felixge/node-mysql.git","clone_url":"https://github.com/felixge/node-mysql.git","svn_url":"https://github.com/felixge/node-mysql","homepage":"","size":5466,"stargazers_count":4502,"watchers_count":4502,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":755,"mirror_url":null,"open_issues_count":72,"forks":755,"open_issues":72,"watchers":4502,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/felixge/node-mysql/pulls/991"},"html":{"href":"https://github.com/felixge/node-mysql/pull/991"},"issue":{"href":"https://api.github.com/repos/felixge/node-mysql/issues/991"},"comments":{"href":"https://api.github.com/repos/felixge/node-mysql/issues/991/comments"},"review_comments":{"href":"https://api.github.com/repos/felixge/node-mysql/pulls/991/comments"},"review_comment":{"href":"https://api.github.com/repos/felixge/node-mysql/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/felixge/node-mysql/pulls/991/commits"},"statuses":{"href":"https://api.github.com/repos/felixge/node-mysql/statuses/3cd3833af4ffc73191e8fb33c1073a93f0613ac7"}}}}