fixed last_update in laytergroup response

This commit is contained in:
javi 2013-03-21 11:39:55 +01:00
parent 4e7f92c60d
commit e53122de7e
2 changed files with 10 additions and 7 deletions

View File

@ -82,9 +82,8 @@ module.exports = function(){
};
me.findLastUpdated = function (username, api_key, tableNames, callback) {
var sql = 'SELECT EXTRACT(EPOCH FROM max(updated_at)) FROM CDB_TableMetadata WHERE m.tabname::name = any ({'
+ tableNames.join(',') + '})';
var sql = 'SELECT EXTRACT(EPOCH FROM max(updated_at)) as max FROM CDB_TableMetadata m WHERE m.tabname::name = any (\'{'
+ tableNames.join(',') + '}\')';
// call sql api
me.sqlQuery(username, api_key, sql, function(err, rows){
@ -93,7 +92,11 @@ module.exports = function(){
callback(new Error('could not find last updated timestamp: ' + msg));
return;
}
var last_updated = rows[0].max;
// when the table has not updated_at means it hasn't been changed so a default last_updated is set
var last_updated = 0;
if(rows.length !== 0) {
last_updated = rows[0].max || 0;
}
callback(null, last_updated);
});
};

View File

@ -66,9 +66,9 @@ suite('multilayer', function() {
+ '$windshaft$)'
});
expectedBody.last_updated = JSON.stringify({
'q': 'SELECT EXTRACT(EPOCH FROM max(updated_at)) '
+ 'FROM CDB_TableMetadata WHERE m.tabname::name = any ({'
+ qTables + '})'
'q': 'SELECT EXTRACT(EPOCH FROM max(updated_at)) as max '
+ 'FROM CDB_TableMetadata m WHERE m.tabname::name = any (\'{'
+ qTables + '}\')'
});
if ( expected_token ) {
//assert.equal(parsedBody.layergroupid, expectedBody.layergroupid);