From 0ec66c69a7d7b86eca8cf0bdd462c047682142ed Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 10 Apr 2013 17:21:42 +0200 Subject: [PATCH] Allow sql queries to end with a semicolon. Closes #90 --- NEWS.md | 1 + app/controllers/app.js | 3 +++ test/acceptance/export/kml.js | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/NEWS.md b/NEWS.md index fdfa3a05..b4fec7ad 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ 1.3.8 ----- * Make using SET or querying system catalogues harder +* Allow sql queries to end with a semicolon (#90) 1.3.7 ----- diff --git a/app/controllers/app.js b/app/controllers/app.js index cbff7f80..94dd375e 100755 --- a/app/controllers/app.js +++ b/app/controllers/app.js @@ -502,6 +502,9 @@ function toOGR(dbname, user_id, gcol, sql, skipfields, out_format, out_filename, var columns = []; + // Drop ending semicolon (ogr doens't like it) + sql = sql.replace(/;\s*$/, ''); + Step ( function fetchColumns() { diff --git a/test/acceptance/export/kml.js b/test/acceptance/export/kml.js index 94a001de..d6caa215 100644 --- a/test/acceptance/export/kml.js +++ b/test/acceptance/export/kml.js @@ -176,4 +176,21 @@ test('GET /api/v1/sql as kml with no rows', function(done){ }); }); +// See https://github.com/Vizzuality/CartoDB-SQL-API/issues/90 +test('GET /api/v1/sql as kml with ending semicolon', function(done){ + assert.response(app, { + url: '/api/v1/sql?' + querystring.stringify({ + q: 'SELECT true WHERE false;', + format: 'kml' + }), + headers: {host: 'vizzuality.cartodb.com'}, + method: 'GET' + },{ }, function(res){ + assert.equal(res.statusCode, 200, res.body); + var body = '\n\nsql_statement\n\n'; + assert.equal(res.body, body); + done(); + }); +}); + });