From 2459aba2ba7a5a28c5892cef1bc1f0b549e326f4 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 6 Jun 2013 15:24:57 +0200 Subject: [PATCH] Fix windowing support for non-uppercased SELECT queries --- NEWS.md | 4 ++++ app/controllers/app.js | 4 ++-- test/acceptance/app.test.js | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 62d282cb..728638d5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +1.4.1 +----- +* Fix windowing support for non-uppercased SELECT queries + 1.4.0 ----- * Add arraybuffer format diff --git a/app/controllers/app.js b/app/controllers/app.js index 311b3c56..7e764944 100755 --- a/app/controllers/app.js +++ b/app/controllers/app.js @@ -81,8 +81,8 @@ function sanitize_filename(filename) { // TODO:drop, fix in the UI (it's not documented in doc/API) // function window_sql (sql, limit, offset) { - // only window select functions - if (_.isNumber(limit) && _.isNumber(offset) && sql.match(/^\s*SELECT\s/) ) { + // only window select functions (NOTE: "values" will be broken, "with" will be broken) + if (_.isNumber(limit) && _.isNumber(offset) && sql.match(/^\s*SELECT\s/i) ) { return "SELECT * FROM (" + sql + ") AS cdbq_1 LIMIT " + limit + " OFFSET " + offset; } return sql; diff --git a/test/acceptance/app.test.js b/test/acceptance/app.test.js index 816e9a0e..3cc6f243 100644 --- a/test/acceptance/app.test.js +++ b/test/acceptance/app.test.js @@ -163,11 +163,12 @@ function(done){ },{ }, function(res) { assert.equal(res.statusCode, 200, res.body); assert.equal(res.headers['x-cache-channel'], 'cartodb_test_user_1_db:untitle_table_4'); + var parsed = JSON.parse(res.body); + assert.equal(parsed.rows.length, 1); done(); }); }); - test('POST /api/v1/sql with SQL parameter on SELECT only. no database param, just id using headers', function(done){ assert.response(app, { url: '/api/v1/sql',