From ed6f88147f20ae9a844ae0269161ffe660ac4c66 Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Tue, 12 Mar 2019 17:32:28 -0400 Subject: [PATCH] update sql and route type, successful calls --- index.js | 7 +++---- route_sql/addmonth_vd.sql | 2 +- route_sql/scenario_package.sql | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index e999d50..990414b 100644 --- a/index.js +++ b/index.js @@ -100,7 +100,7 @@ server.get('/scenario_package', bodyParser.json(), function (req, res) { return; } //parse the where clause into the main sql statement - sql = sql.replace("'where_clause'",w) + sql = sql.replace(new RegExp("where_clause",'g'),w) //execute the sql and send the result Postgres.FirstRow(sql,[],res) }; @@ -116,14 +116,14 @@ server.get('/scenario_package', bodyParser.json(), function (req, res) { }) -server.get('/addmonth_v', bodyParser.json(), function (req, res) { +server.post('/addmonth_v', bodyParser.json(), function (req, res) { var sql = ""; var w = ""; var c = 1; var args = []; var path = './route_sql/addmonth_vd.sql'; - + var callback = function(arg){ sql = arg @@ -149,7 +149,6 @@ server.get('/addmonth_v', bodyParser.json(), function (req, res) { sql = sql.replace(new RegExp("scenario = target_scenario",'g'),w); sql = sql.replace(new RegExp("target_increment",'g'),req.body.amount); sql = sql.replace(new RegExp("target_month",'g'),req.body.month); - console.log(sql); //console.log(sql); Postgres.FirstRow(sql,[],res) } diff --git a/route_sql/addmonth_vd.sql b/route_sql/addmonth_vd.sql index acd57bc..7ff5b79 100644 --- a/route_sql/addmonth_vd.sql +++ b/route_sql/addmonth_vd.sql @@ -446,7 +446,7 @@ FROM LEFT OUTER JOIN gld sd ON make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat WHERE - m._month = 'target_month' + m._month = (SELECT _month FROM closest) ) , ins AS ( INSERT INTO rlarp.osm_fcpool SELECT * FROM final RETURNING * diff --git a/route_sql/scenario_package.sql b/route_sql/scenario_package.sql index bdfa070..b08b859 100644 --- a/route_sql/scenario_package.sql +++ b/route_sql/scenario_package.sql @@ -35,7 +35,7 @@ SELECT FROM rlarp.osm_fcpool WHERE - 'where_clause' + where_clause GROUP BY order_season ,order_month