After lots of google-fu, I figured out a way to query the ancient sybase database to start building a rest api for a mobile app I'm working on using node-odbc (https://github.com/markdirish/node-odbc/blob/master/README.md#callprocedurecatalog-schema-name-parameters-callback).
I have managed to successfully query with a select statement, but would prefer not to do that for security purposes. when I try to use a stored procedure I'm getting a weird response. I need a sanity check here and figure out what I'm missing.
an example stored procedure I tried is a simple sp with one parameter to check for an email address using an account number (this is a fake sp of course, but formated the same way):
"DB"."spGetEmail"(@acctnum varchar(50) )
the docs show this:
const odbc = require('odbc');
odbc.connect(${process.env.CONNECTION_STRING}
, (error, connection) => {
connection.callProcedure(null, null, 'MY_PROC', [undefined], (error, result) => {
if (error) { console.error(error) } // handle
// result contains an array of results, and has a parameters
property to access parameters returned by the procedure.
console.log(result);
});
});
I interpreted it to look like this:
odbc.connect(${process.env.CONNECTION_STRING}, (error, connection) => {
connection.callProcedure(null, "DB", "spGetEmail", [123456], (error, result) => {
if (error) { console.error(error) } // handle
// result contains an array of results, and has a parameters
property to access parameters returned by the procedure.
console.log(result);
});
});
then I get this:
[Error: [odbc] The number of parameters the procedure expects and and the number of passed parameters is not equal] { odbcErrors: [] } undefined Segmentation fault
seems straight forward, that I'm missing some parameters, but I KNOW that I'm not. The dang sp takes one parameter!
What am I missing here??
[SOLVED] I'm not sure if the built in .callProcedure() method is broken or just not suited to Sybase16, but I found a way around it in case it's helpful to anyone in the future. Instead of using the callProcedure() method, do this: