Reputation: 416
I'm attempting to filter some results using azure mobile service scripts but i'm getting this error in the log.The parameters I pass to this function are also shown.
ERROR Error in script '/table/Restaurant.read.js'. Error: Invalid callback options passed to 'query'. Callback options must be an object with at least one 'success' or 'error' property of type 'function' or a systemProperties property of type 'Array'. [external code] at read (:7:11) at :1:6 [external code]
Here's my code
function read(query, user, request) {
var location=request.parameters.Location;
var category=request.parameters.Category;
console.log("location is"+location);
console.log("category is"+category);
var sql="SELECT * from restaurant where Location=? AND Category=?";
mssql.query(sql,[location],[category],{success:function(results){request.respond(statusCodes.Ok,results);}});
}
Upvotes: 0
Views: 58
Reputation: 87218
The parameters to the query need to be passed as a single array, instead of an array per parameter. If you change your query from
mssql.query(sql, [location], [category], {
success: function(results) { request.respond(statusCodes.Ok, results); }
});
to
mssql.query(sql, [location, category], {
success: function(results) { request.respond(statusCodes.OK, results); }
});
It should work. As a side note, you should use statusCodes.OK
instead of statusCodes.Ok
("OK" all in caps).
Upvotes: 1