2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2015-06-16 23:33:04 +08:00
|
|
|
require('../../helper');
|
|
|
|
|
2019-10-04 00:24:39 +08:00
|
|
|
var server = require('../../../lib/server')();
|
2015-06-01 19:20:51 +08:00
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var sqlite = require('sqlite3');
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
describe('spatialite query', function () {
|
|
|
|
it('returns a valid sqlite database', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2015-06-01 19:20:51 +08:00
|
|
|
url: '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4%20LIMIT%201&format=spatialite',
|
2019-12-24 01:19:08 +08:00
|
|
|
headers: { host: 'vizzuality.cartodb.com' },
|
2015-06-01 19:20:51 +08:00
|
|
|
method: 'GET'
|
2019-12-24 01:19:08 +08:00
|
|
|
}, { }, function (err, res) {
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'application/x-sqlite3; charset=utf-8');
|
2015-06-16 23:33:04 +08:00
|
|
|
var db = new sqlite.Database(':memory:', res.body);
|
2019-12-24 01:19:08 +08:00
|
|
|
var qr = db.get('PRAGMA database_list', function (err) {
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(err, null);
|
2015-06-01 21:16:05 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
assert.notEqual(qr, undefined);
|
2015-06-01 19:20:51 +08:00
|
|
|
});
|
|
|
|
});
|
2015-06-01 21:16:05 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
it('different file name', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2015-06-01 21:16:05 +08:00
|
|
|
url: '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4%20LIMIT%201&format=spatialite&filename=manolo',
|
2019-12-24 01:19:08 +08:00
|
|
|
headers: { host: 'vizzuality.cartodb.com' },
|
2015-06-01 21:16:05 +08:00
|
|
|
method: 'GET'
|
2019-12-24 01:19:08 +08:00
|
|
|
}, { }, function (err, res) {
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(res.headers['content-type'], 'application/x-sqlite3; charset=utf-8');
|
2019-12-24 01:19:08 +08:00
|
|
|
assert.notEqual(res.headers['content-disposition'].indexOf('manolo.sqlite'), -1);
|
2015-06-01 19:20:51 +08:00
|
|
|
done();
|
|
|
|
});
|
2015-06-01 21:16:05 +08:00
|
|
|
});
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
it('gets database schema', function (done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server, {
|
2015-06-01 21:16:05 +08:00
|
|
|
url: '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4%20LIMIT%201&format=spatialite',
|
2019-12-24 01:19:08 +08:00
|
|
|
headers: { host: 'vizzuality.cartodb.com' },
|
2015-06-01 21:16:05 +08:00
|
|
|
method: 'GET'
|
2019-12-24 01:19:08 +08:00
|
|
|
}, { }, function (err, res) {
|
2015-06-16 23:33:04 +08:00
|
|
|
var db = new sqlite.Database(':memory:', res.body);
|
2015-06-01 21:16:05 +08:00
|
|
|
var schemaQuery = "SELECT name, sql FROM sqlite_master WHERE type='table' ORDER BY name";
|
2019-12-24 01:19:08 +08:00
|
|
|
var qr = db.get(schemaQuery, function (err) {
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(err, null);
|
2015-06-01 21:16:05 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
assert.notEqual(qr, undefined);
|
|
|
|
});
|
2015-06-01 19:20:51 +08:00
|
|
|
});
|
|
|
|
});
|