Fix skipfields use with SHP output format. Closes #81
This commit is contained in:
parent
938a87cfe0
commit
d667d64c78
1
NEWS.md
1
NEWS.md
@ -1,5 +1,6 @@
|
||||
1.3.5 (DD/MM/YY)
|
||||
-----
|
||||
* Fix skipfields use with SHP output format (#81)
|
||||
|
||||
1.3.4 (21/01/13)
|
||||
-----
|
||||
|
@ -250,7 +250,7 @@ function handleQuery(req, res) {
|
||||
function packageResults(err, result){
|
||||
if (err) throw err;
|
||||
|
||||
if ( skipfields.length ){
|
||||
if ( result && skipfields.length ){
|
||||
for ( var i=0; i<result.rows.length; ++i ) {
|
||||
for ( var j=0; j<skipfields.length; ++j ) {
|
||||
delete result.rows[i][skipfields[j]];
|
||||
|
@ -194,6 +194,7 @@ test('mixed type geometry', function(done){
|
||||
encoding: 'binary',
|
||||
method: 'GET'
|
||||
},{ }, function(res){
|
||||
assert.deepEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
||||
assert.equal(res.statusCode, 400, res.statusCode + ': ' +res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user