I want to replace the string "?" with a different array values in the order using javascript
SELECT "x0"."NAME", "x0"."DOB", "x0"."SEX", "x0"."CATEGORY"
FROM "PERSON" "x0"
WHERE ((("x0"."NAME" <> ?) AND ("x0"."NAME" = ?)) AND ("x0"."NAME" < ?))
I want to replace the string "?" with a different array values in the order using javascript
SELECT "x0"."NAME", "x0"."DOB", "x0"."SEX", "x0"."CATEGORY"
FROM "PERSON" "x0"
WHERE ((("x0"."NAME" <> ?) AND ("x0"."NAME" = ?)) AND ("x0"."NAME" < ?))
One possible solution is this:
var query = 'SELECT "x0"."NAME", "x0"."DOB", "x0"."SEX", "x0"."CATEGORY"' +
'FROM "PERSON" "x0"' +
'WHERE ((("x0"."NAME" <> ?) AND ("x0"."NAME" = ?)) AND
("x0"."NAME" < ?))';
var names = ['borr', 'odin', 'thor'];
for (var i = 0; i < names.length; i++) {
query = query.replace(/\?/, '"' + names[i] + '"');
}
console.log(query)
https://jsfiddle.net/0twfrdxz/
However, this will open up your application to SQL Injection. It would probably be better to give the query named parameters and generate the statement on the server after you sanitize the inputs. That being said, the above should work for testing.