|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const serverOptions = require('./../../server-options');
|
|
|
|
|
const { logger } = serverOptions();
|
|
|
|
|
var crypto = require('crypto');
|
|
|
|
|
var step = require('step');
|
|
|
|
|
var fs = require('fs');
|
|
|
|
@ -93,9 +95,13 @@ OgrFormat.prototype.toOGR = function (options, outFormat, outFilename, callback)
|
|
|
|
|
step(
|
|
|
|
|
|
|
|
|
|
function fetchColumns () {
|
|
|
|
|
logger.info({custom: true}, 'Getting dataset columns');
|
|
|
|
|
|
|
|
|
|
var colsql = 'SELECT * FROM (' + sql + ') as _cartodbsqlapi LIMIT 0';
|
|
|
|
|
pg = new PSQL(dbopts);
|
|
|
|
|
pg.query(colsql, this);
|
|
|
|
|
|
|
|
|
|
logger.info({ custom: true, colsql: colsql }, 'Dataset columns query done');
|
|
|
|
|
},
|
|
|
|
|
function findSRS (err, result) {
|
|
|
|
|
if (err) {
|
|
|
|
@ -177,6 +183,8 @@ OgrFormat.prototype.toOGR = function (options, outFormat, outFilename, callback)
|
|
|
|
|
|
|
|
|
|
ogrargs.push('-nln', outLayername);
|
|
|
|
|
|
|
|
|
|
logger.info({ custom: true }, 'Executing ogr2ogr command');
|
|
|
|
|
|
|
|
|
|
// TODO: research if `exec` could fit better than `spawn`
|
|
|
|
|
var child = spawn(ogr2ogr, ogrargs);
|
|
|
|
|
|
|
|
|
@ -226,6 +234,8 @@ OgrFormat.prototype.toOGR = function (options, outFormat, outFilename, callback)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
OgrFormat.prototype.toOGR_SingleFile = function (options, fmt, callback) {
|
|
|
|
|
logger.info({ custom: true }, 'Generating filename');
|
|
|
|
|
|
|
|
|
|
var dbname = options.dbopts.dbname;
|
|
|
|
|
var userId = options.dbopts.user;
|
|
|
|
|
var gcol = options.gcol;
|
|
|
|
@ -246,6 +256,8 @@ OgrFormat.prototype.toOGR_SingleFile = function (options, fmt, callback) {
|
|
|
|
|
var outdirpath = tmpdir + '/sqlapi-' + process.pid + '-' + reqKey;
|
|
|
|
|
var dumpfile = outdirpath + ':cartodb-query.' + ext;
|
|
|
|
|
|
|
|
|
|
logger.info({ custom: true, dumpfile: dumpfile }, 'File name generated');
|
|
|
|
|
|
|
|
|
|
// TODO: following tests:
|
|
|
|
|
// - fetch query with no "the_geom" column
|
|
|
|
|
this.toOGR(options, fmt, dumpfile, callback);
|
|
|
|
|