I'm having troubles querying a sql server function which requires two datetime params.
If I call it in the Sql managment studio it works but if I execute the SAME code in node it does not work.
I have tried so many ways of doing it but I can't make it work.
Tha mssql version I'm using is: "mssql": "^5.1.0"
The error I always get is:
Conversion failed when converting date and/or time from character string.
One of the sql query is:
SELECT * FROM dbo.Festadisticalb_2017(#inidate,#findate)
I have also tried with CONVERT and CAST without success.
I also tried:
queryreppedidos =
"DECLARE #inidate as date;" +
"SET #inidate = DATEADD(DAY, -500, GETDATE());" +
"DECLARE #findate as date;" +
"SET #findate = GetDate();" +
"SELECT TOP 10 fe.NumeroDocumento, fe.Cant_Pedida, fe.Descripcion, " +
"fe.Observacion, fe.Pedido_LB, fe.Referencia, fe.Responsable, " +
"fe.OC_Cliente, fe.Cliente, fe.Linea, fe.Valor_Pedido, fe.Transito_Total, " +
"fe.Orden_Fabrica, fe.Proveedor, fe.Importacion, " +
"fe.Stock, fe.Terceros, fe.Pendientes, fe.Transito, fe.PorComprar, fe.Estado, " +
"fe.Asesor FROM dbo.Festadisticalb_2017(#inidate,#findate) fe " +
"WHERE fe.Responsable = 'SRR';";
The thing is: How to correctly write the datetime input params in order to successfully query a function using mssql in nodejs?
Thanks for your support. Have a great day.
Related
I am developing a small program using Electron JS and I use SQLite as a database engine with the help of sqlite3 module in Node JS. On the click event of a button in the program I update the database using UPDATE FROM statement. However, when I run the program and click the button, I get the following error:
Error: SQLITE_ERROR: near "FROM": syntax error
--> in Database#run('\n' +
' UPDATE StorageProducts\n' +
'SET quantity = StorageProducts.quantity - innerquery.q2 * innerquery.c\n' +
'FROM(select SP.quantity as q1, RP.quantity as q2, PHS.consumes as c, SP.product_name as product_name\n' +
' FROM StorageProducts SP\n' +
' INNER JOIN ProductHasStorage PHS on SP.product_name = PHS.storage_name\n' +
' INNER JOIN ReceiptProduct RP on PHS.product_name = RP.product_name\n' +
'WHERE receipt_id = 2) AS innerquery\n' +
'WHERE StorageProducts.product_name = innerquery.product_name\n' +
' ', [ 2 ], [Function])
Here is the statement I am trying to run using db.run():
update StorageProducts
set quantity = StorageProducts.quantity - innerquery.q2 * innerquery.c
from(select SP.quantity as q1, RP.quantity as q2, PHS.consumes as c, SP.product_name as product_name
from StorageProducts SP
inner join ProductHasStorage PHS on SP.product_name = PHS.storage_name
inner join ReceiptProduct RP on PHS.product_name = RP.product_name
where receipt_id = 1) as innerquery
where StorageProducts.product_name = innerquery.product_name
Another thing is that when I executed the very same statement in an external databases tool -DataGrip-, It worked fine and updated the table as expected!
I set up an API where on client side user can calculate a route between to points. However, I have trouble with the psql query, which works in postgres but when I use the same query in node JS I got an error.
I am using nodeJS, Express and Postgres. If I run the query below in pgAdmin4, I get the expected output.
SELECT b.gid, b.the_geom, b.cost_s, b.length_m FROM pgr_dijkstra('SELECT gid::bigint as id, source::bigint,
target::bigint, cost_s::double precision as cost,
reverse_cost_s::double precision as reverse_cost FROM ways
WHERE the_geom && ST_Expand((SELECT ST_Collect(the_geom)
FROM ways_vertices_pgr WHERE id IN(589143, 581050)), 0.01)',
589143, 581050) a LEFT JOIN ways b ON (a.edge = b.gid);
But when I use the same query in Node Js (see below), I get an error message saying error: syntax error at or near "&&". What am I doing wrong?
const start = parseInt(request.params.start)
const end = parseInt(request.params.end)
const sql2 =
"SELECT b.gid, b.the_geom, b.cost_s, b.length_m FROM pgr_dijkstra('SELECT gid::bigint as id, source::bigint,"+
"target::bigint, cost_s::double precision as cost," +
"reverse_cost_s::double precision as reverse_cost FROM ways" +
"WHERE the_geom && ST_Expand((SELECT ST_Collect(the_geom)" +
"FROM ways_vertices_pgr WHERE id IN(" + start + "," + end + ")), 0.01)'," +
start + "," + end + ") a LEFT JOIN ways b ON (a.edge = b.gid);"
Got the answer. Instead of start and end I used arguments using the syntax $1...and added the data type of the arguments. In my case ineteger
SELECT b.gid, b.the_geom, b.cost_s, b.length_m FROM pgr_dijkstra('SELECT gid::bigint as id, source::bigint,
target::bigint, cost_s::double precision as cost,
reverse_cost_s::double precision as reverse_cost FROM ways
WHERE the_geom && ST_Expand((SELECT ST_Collect(the_geom)
FROM ways_vertices_pgr WHERE id IN(' || $1::integer || ',' || $2::integer ||')), 0.01)',
$1::integer, $2::integer) a LEFT JOIN ways b ON (a.edge = b.gid);
I use the Jenkins CLI to create reports every week for the jobs over the week.
def deployOnK8sJob = Jenkins.instance.getItemByFullName('<JOB>')
def jobBuilds=deployOnK8sJob.getBuilds().byTimestamp(System.currentTimeMillis()-numberOfHoursBack*60*60*1000, System.currentTimeMillis())
println build.number + " " + build.actions[0].parameters[0].value + " " + build.actions[0].parameters[1].value + " " + build.timestamp.format("dd/MM/yyyy HH:mm:ss.SSS") + " " + build.result + " " + build.actions[0].parameters[3].value + " " + build.actions[0].parameters[4].value
This works fine for me. But if there was a build failure and anyone triggered the job again using the Rebuild Plugin, build.actions[0].parameters[x] are not available.
I have a groovy script that collects these reports.
I think that when using the Rebuild Plugin, build.actions[0].parameters[x] are not available because in this case build.actions[0] is not from class ParametersAction but from class CauseAction as the exception you get says.
So, I would recommend to use build.getAction(ParametersAction.class) in stead of build.actions[0].
I am using Node JS . I am a beginner. I use OrientJS to connect orientdb from Node JS. I want to run several db.query() method in parallel. This queries are formed by reading a large text file using line-by-line module.
For example,
var queryForGeoUpdate = 'update (' +
'\nselect from (' +
"\n select expand(outE('GeoAgentSummary')) " +
'\n from Agent ' +
'\n where name = "' + name + '" and number = \'' + number + "' and type = '" + type + "'" +
"\n) where in.name = '" + Geo + "'" +
'\n) increment _' + FiscalYear + ' = ' + TMSSalesAllocatedBookingsNet + 'f, _' +
FiscalPeriodID + ' = ' + TMSSalesAllocatedBookingsNet +
'f, _' + FiscalQuarterID + ' = ' + TMSSalesAllocatedBookingsNet + 'f'
// console.log(queryForGeoUpdate)
db.query(queryForGeoUpdate) // query and db call for Country ends here
like db.query(queryForGeoUpdate) there are seven queries like db.query(queryForRegionUpdate) and so on...
if I run it asynchronously "process out of memory occurrs". If I run it synchronously it takes too much time. How can I solve it within very less time..
Any help is appreciated..
I am not familiar with the DB you are using. If you are sure the DB works "correctly" and the calls you make are correct (e.g. if there isn't a way to make you queries much smaller) you could try running with:
node --max_old_space_size="memmory in MB, try something large like 8192" app.js
It seems rather strange that a DB query would run out of memory thought... I always assumed queries are, generally speaking,a lot more CPU intensive and require relatively little memory.
For these sort of large queries you might also try spawning separate processes:
https://nodejs.org/api/child_process.html
I have some code running fine locally but i am getting an error when i run it remotely.
I am unable to debug remotely obviously - but from the error I know it has to with some DateTime Logic (belongs to my code).
I am looking for a comprehensive way to find what's different between my machine and this remote server - and that could affect DateTime logic.
I know Locale - 1/ is there a way to know what is affected by Locale?
2/ Any other local settings that could be different between a local machine and a server?
Thanks
I looked at the FirstDayOfWeek and MinimaldaysinFirstWeek
when I run the following code:
Calendar c1 = new GregorianCalendar();
System.out.println(Locale.getDefault() + ": " + c1.getFirstDayOfWeek() + " " + c1.getMinimalDaysInFirstWeek());
Locale.setDefault(Locale.getDefault());
Calendar c = new GregorianCalendar();
System.out.println(Locale.getDefault() + ": " + c.getFirstDayOfWeek() + " " + c.getMinimalDaysInFirstWeek());
I got the following output.... It makes no sense...
en_US: 2 4
en_US: 1 1