Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use POST method to send queries (may be very long)

  • Loading branch information...
commit fee948324a22b2b27a1ca617f351371cbe664ab3 1 parent 2161eb1
@strk strk authored
Showing with 16 additions and 2 deletions.
  1. +16 −2 tools/cdbsql
View
18 tools/cdbsql
@@ -145,10 +145,18 @@ if ( ! sql ) {
function processQuery(sql, callback)
{
+
+ var post_data = 'q=' + encodeURIComponent(sql);
+
var opt = {
host: hostname,
port: port,
- path: '/api/v' + api_version + '/sql?q=' + encodeURIComponent(sql) + '&format=' + encodeURIComponent(format)
+ path: '/api/v' + api_version + '/sql?format=' + encodeURIComponent(format),
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ 'Content-Length': post_data.length
+ }
};
if ( typeof(api_key) != 'undefined' ) opt.path += '&api_key=' + api_key;
@@ -158,7 +166,7 @@ function processQuery(sql, callback)
var request = 'http://' + opt.host + ':' + opt.port + opt.path;
//console.log("Sending request:", request);
- http.get(opt, function(res) {
+ var req = http.request(opt, function(res) {
//console.log("Response status: " + res.statusCode);
res.on('data', function(chunk) {
body += chunk;
@@ -167,6 +175,9 @@ function processQuery(sql, callback)
res.on('end', function() {
console.log("Request:", request);
+ var sqlprint = sql.length > 100 ? sql.substring(0, 100) + ' ... [truncated ' + (sql.length-100) + ' bytes]' : sql;
+ sqlprint = sqlprint.split('\n').join(' ');
+ console.log("Query:", sqlprint);
console.log("Response status: " + res.statusCode);
console.log('Response body:');
console.dir(body);
@@ -179,4 +190,7 @@ function processQuery(sql, callback)
if ( callback ) callback();
});
+ req.write(post_data);
+ req.end();
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.