Fix skipfields use with SHP output format. Closes #81

This commit is contained in:
Sandro Santilli 2013-02-13 13:02:37 +01:00
parent 938a87cfe0
commit d667d64c78
3 changed files with 29 additions and 1 deletions

View File

@ -1,5 +1,6 @@
1.3.5 (DD/MM/YY) 1.3.5 (DD/MM/YY)
----- -----
* Fix skipfields use with SHP output format (#81)
1.3.4 (21/01/13) 1.3.4 (21/01/13)
----- -----

View File

@ -250,7 +250,7 @@ function handleQuery(req, res) {
function packageResults(err, result){ function packageResults(err, result){
if (err) throw err; if (err) throw err;
if ( skipfields.length ){ if ( result && skipfields.length ){
for ( var i=0; i<result.rows.length; ++i ) { for ( var i=0; i<result.rows.length; ++i ) {
for ( var j=0; j<skipfields.length; ++j ) { for ( var j=0; j<skipfields.length; ++j ) {
delete result.rows[i][skipfields[j]]; delete result.rows[i][skipfields[j]];

View File

@ -194,6 +194,7 @@ test('mixed type geometry', function(done){
encoding: 'binary', encoding: 'binary',
method: 'GET' method: 'GET'
},{ }, function(res){ },{ }, function(res){
assert.deepEqual(res.headers['content-type'], 'application/json; charset=utf-8');
assert.equal(res.statusCode, 400, res.statusCode + ': ' +res.body); assert.equal(res.statusCode, 400, res.statusCode + ': ' +res.body);
var parsedBody = JSON.parse(res.body); var parsedBody = JSON.parse(res.body);
var expectedBody = {"error":["ERROR 1: Attempt to write non-point (LINESTRING) geometry to point shapefile."]} var expectedBody = {"error":["ERROR 1: Attempt to write non-point (LINESTRING) geometry to point shapefile."]}
@ -202,5 +203,31 @@ test('mixed type geometry', function(done){
}); });
}); });
test('skipfields controls fields included in SHP output', function(done){
var query = querystring.stringify({
q: "SELECT 111 as skipme, 222 as keepme, 'POINT(0 0)'::geometry as g",
format: 'shp',
skipfields: 'skipme',
filename: 'myshape'
});
assert.response(app, {
url: '/api/v1/sql?' + query,
headers: {host: 'vizzuality.cartodb.com'},
encoding: 'binary',
method: 'GET'
},{ }, function(res){
assert.equal(res.statusCode, 200, res.body);
var tmpfile = '/tmp/myshape.zip';
var err = fs.writeFileSync(tmpfile, res.body, 'binary');
if (err) { done(err); return }
var zf = new zipfile.ZipFile(tmpfile);
var buffer = zf.readFileSync('myshape.dbf');
fs.unlinkSync(tmpfile);
var strings = buffer.toString();
assert.ok(!/skipme/.exec(strings), "Could not skip 'skipme' field:\n" + strings);
done();
});
});
}); });