adjust the regex to exclude brackets not behaving as expected. req.send to send the sql back as text

This commit is contained in:
Paul Trowbridge 2020-11-17 08:42:35 -05:00
parent 90d62a2bb0
commit 663e5d3de5

View File

@ -51,6 +51,15 @@ server.get('/baseline', bodyParser.json(), function(req, res) {
var sql = ""; var sql = "";
var path = './route_sql/baseline.sql'; var path = './route_sql/baseline.sql';
var args = [];
var app_baseline_from_date = '2020-06-01';
//app_baseline_to_date
//app_first_forecast_date
//app_openorder_cutoff
//app_openstatus_code
//app_plug_fromdate
//app_plug_todate
fs.readFile(path, 'utf8', function(err, data) { fs.readFile(path, 'utf8', function(err, data) {
if (!err) { if (!err) {
@ -73,14 +82,15 @@ server.get('/baseline', bodyParser.json(), function(req, res) {
var callback = function(arg) { var callback = function(arg) {
sql = arg; sql = arg;
console.log(new Date().toISOString() + "-------------------------get scenario:------------------------------") console.log(new Date().toISOString() + "-------------------------baseline build-----------------------------")
console.log(req.body); console.log(req.body);
//parse the where clause into the main sql statement //parse the where clause into the main sql statement
//sql = sql.replace(new RegExp("where_clause", 'g'), w) //sql = sql.replace(new RegExp("where_clause", 'g'), w)
sql = sql.replace(new RegExp("[app_baseline_from_date]",'g'), "$1"); sql = sql.replace(new RegExp("app_baseline_from_date"), app_baseline_from_date);
args.push(req.body.app_baseline_from_date); args.push(req.body.app_baseline_from_date);
//execute the sql and send the result //execute the sql and send the result
console.log(sql); console.log(sql);
res.send(sql);
//Postgres.FirstRow(sql, [], res) //Postgres.FirstRow(sql, [], res)
}; };
}) })