I'm using node and calling a stored procedure in MariaDB. The stored procedure has 3 out parameters. If I call perform the following query in HeidiSQL it works without problem:
CALL weekFromDate('syberdyne', '2016/01/23', #dtSOW, #siWeek, #siYear);
SELECT #dtSOW, #siWeek, #siYear;
However if I execute the exact same query in node/javascript I get an error:
MySQL, Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT #dtSOW, #siWeek, #siYear' at line 1
What is the correct way to access 'out' parameters in node/Javascript?
Solved, by modifying the connection routine in node.js and adding the parameter:
multipleStatements:true
Related
I am trying to create a test to verify that when I send a request to add a provider, that value is stored in the database.
The test is sending the request, the provider is created, but when I am trying to add the assertions to check the values in the database, I can't.
let providerBd = await functions.getProvider(addProviderRequest.senderID);
console.log(providerBd);
expect(providerBd.razonsocial).to.equal(testCase.provider.senderAdminName);
Code
First I am logging the object with the value obtained in the DB. But the test fails because the value that it gets is undefined and I am expected 'Proveedor Mocha' in razonsocial.
Output
Thanks in advance!
My error is in this line:
expect(providerBd.razonsocial).to.equal(testCase.provider.senderAdminName);
It should be:
expect(providerBd[0].razonsocial).to.equal(testCase.provider.senderAdminName);
Now works :)
I'm trying to retrieve a content from the specific ical url using ical npm.
I'm testing this code on the client side. There are a few icals that I've managed to fetch. But this one and several others I didn't.
It works great on POSTMAN.
My code is:
const ical = require('ical');
ical.fromURL('https://admin.vrbo.com/icalendar/5d19afbfbf144218a3c76eacf76267c6.ics', {mode: 'cors'}, (err, data) => {
console.log(err)
});
The error I get:
Error: Invalid value for opts.mode
at new push../node_modules/stream-http/lib/request.js.module.exports (request.js:58)
at Object.push../node_modules/stream-http/index.js.http.request (index.js:30)
at Object.push../node_modules/https-browserify/index.js.https.request (index.js:13)
at Request.push../node_modules/request/request.js.Request.start (request.js:829)
at Request.push../node_modules/request/request.js.Request.end (request.js:1639)
at end (request.js:628)
at request.js:644
at run (setImmediate.js:48)
at runIfPresent (setImmediate.js:83)
at onGlobalMessage (setImmediate.js:125)
Pleas tell me what I'm doing wrong and how to make this code work.
I think the issue here is, that you are trying to pass an invalid option ({mode: 'cors'}). ical.fromURL(...) will pass the options argument as it is to request (See Line 8). I've checked the source of request, but did not find any option with the name mode (Maybe you are mixing it up with the Fetch API, because there is an option called mode), so in my opinion, that is also the reason, why you are getting the error (But I'm not sure why it worked out for you, to fetch some other calendars). You can check the full list of possible options by yourself.
I run a query on Facebook Graph API Explorer successfully but when I run the same query on Google Apps Script with UrlFetchApp I get an Error - Invalid argument. The query is this:
https: //graph.facebook.com/v4.0/act_1015703131******/insights?fields=spend&level=account&date_preset=yesterday&filtering=[{field:campaign.name,operator:CONTAIN,value:perf},{field:adset.name,operator:NOT_CONTAIN,value:rmk}]&access_token=********
When I run the same query without filtering it works as expected!
Json Result:
EDIT:
I tried to encode the filtering parameters and it throws a new error:
Request failed for https://graph.facebook.com returned code 400. Truncated server response: {"error":{"message":"(#100) param filtering must be an array.","type":"OAuthException","code":100,"fbtrace_id":"AMw2vkaHXbuiVSQuSNg28yZ"}} (use muteHttpExceptions option to examine full response)
What is causing the problem exactly since the error doesn't give any specific description?
First put your filtering value into an array:
var fbCallFiltering = [{'field':'campaign.name','operator':'CONTAIN','value':'perf'},{'field':'adset.name','operator':'NOT_CONTAIN','value':'rmk'}];
Then use JSON.stringify()
var fbCallFilteringString = encodeURIComponent(JSON.stringify(fbCallFiltering));
Finally use the fbCallFilteringString variable in the URL you use to make the UrlFetchApp call after the &filtering=.
This should work.
I want to use some argument a few times in same query. How can I do this without duplication of this argument?
This works, but we have to use this argument twice
connection.query('SELECT ? FROM ?', [usr, usr],...)
I tried this, but it doesn't work (syntax error):
connection.query('SET #param = users; SELECT #param FROM #param',...)
For make it work, you have to do to things:
Enable multiple statement queries
var connection = mysql.createConnection({multipleStatements: true});
To keep your variables between queries, many times, you must use MySQL transactions.
connection.query('start transaction;set #param=?;select #param;commit',[use])
Read more:
node-mysql
Transaction in node-mysql
Transaction in MySQL
I'm using the NodeJS package MSSQL (https://npmjs.org/package/mssql#cfg-node-tds) to connect to a MS SQL database and perform UPDATE queries.
I understand that if an UPDATE query ends up not affecting any rows, it will still return as a success event. I would like to handle the success event differently if zero rows were affected since this is not the intended outcome of the query.
After doing some research, I found that when performing SQL queries, you can use ##ROWCOUNT to get the number of affected rows, but I've yet to figure out how to use this with the MSSQL Node package.
Has anyone used this Node package and and handled UPDATE queries the way I am trying to?
Thanks!
Okay, right from the link your provided, the node package can call stored procedures.
Either create the logic on the JS side or the TSQL side.
Since I am a DBA/Developer by trade, lets create a SP to perform the update an return the number of rows effected.
I am using the adventure works sample database.
-- use sample db
use AdventureWorks2012;
go
-- sample select
select *
from [Person].[Person]
where lastname = 'Walters';
go
-- stored procedure
create procedure usp_Update_First_Name (#id int, #first varchar(50))
as
begin
update [Person].[Person]
set [FirstName] = #first
where [BusinessEntityID] = #id;
return(##rowcount);
end
go
-- make a call
declare #ret int;
exec #ret = usp_Update_First_Name #id = 4, #first = 'Robert';
print #ret;
This call returns the following output.
(1 row(s) affected)
1
In the JS code, do action A if #ret = 0 or action B if #ret > 0.