2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2015-09-02 23:09:22 +08:00
|
|
|
require('../helper');
|
|
|
|
|
2016-09-15 02:54:24 +08:00
|
|
|
var server = require('../../app/server')();
|
2015-09-02 23:09:22 +08:00
|
|
|
var assert = require('../support/assert');
|
|
|
|
var qs = require('querystring');
|
|
|
|
|
|
|
|
describe('regressions', function() {
|
|
|
|
|
2015-09-07 23:08:21 +08:00
|
|
|
it('issue #224: tables with . (dot) in name works and can be queried', function(done) {
|
2015-09-02 23:09:22 +08:00
|
|
|
|
|
|
|
function createRequest(sqlQuery) {
|
|
|
|
return {
|
|
|
|
url: '/api/v1/sql?' + qs.stringify({
|
|
|
|
q: sqlQuery,
|
|
|
|
api_key: 1234
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
host: 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var responseOk = {
|
|
|
|
statusCode: 200
|
|
|
|
};
|
|
|
|
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, createRequest('CREATE TABLE "foo.bar" (a int);'), responseOk,
|
2016-09-26 20:42:35 +08:00
|
|
|
function(err) {
|
2015-09-02 23:09:22 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, createRequest('INSERT INTO "foo.bar" (a) values (1), (2)'), responseOk,
|
2016-09-26 20:37:40 +08:00
|
|
|
function(err, res) {
|
2015-09-02 23:09:22 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
var parsedBody = JSON.parse(res.body);
|
|
|
|
assert.equal(parsedBody.total_rows, 2);
|
|
|
|
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, createRequest('SELECT * FROM "foo.bar"'), responseOk,
|
2016-09-26 20:37:40 +08:00
|
|
|
function(err, res) {
|
2015-09-02 23:09:22 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2016-07-11 22:39:12 +08:00
|
|
|
// table should not get a cache channel as it won't get invalidated
|
|
|
|
assert.ok(!res.headers.hasOwnProperty('x-cache-channel'));
|
2015-09-02 23:09:22 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
|
|
|
assert.equal(parsedBody.total_rows, 2);
|
|
|
|
assert.deepEqual(parsedBody.rows, [{ a: 1 }, { a: 2 }]);
|
2016-09-27 00:26:00 +08:00
|
|
|
|
|
|
|
// delete table
|
|
|
|
assert.response(server, createRequest('DROP TABLE "foo.bar"'), responseOk, done);
|
2015-09-02 23:09:22 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|