Reputation: 990
I have this simple, standard and easy sql query, which I cannot figure out the issue with. It seems okay on looking at it, but cannot figure out the issue... It gives me an error (which you can find below), but first, here's the insert query.
//DB2 CONNECTION FOR ADDING PRODUCTS
var addProducts =
"insert into PRODUCTS ( ITEM, DESCRIPTION, PRICE, SIZES, DIVISION, XS, S, M, L, XL, INTER, EACH_CASE ) VALUES ('" +
req.body.item +
"', '" +
req.body.description +
"', '" +
req.body.price +
"', '" +
allSizes +
"', '" +
req.body.category +
"', '" +
req.body.xs +
"', '" +
req.body.s +
"', '" +
req.body.m +
"', '" +
req.body.l +
"', '" +
req.body.xl +
"', '" +
inter +
"', '" +
each_case +
"' )";
ibmdb.open(req.session.ibmdbconnDash, function (err, conn) {
if (err) return console.log(err + "getting error here 1");
conn.query(addProducts, function (err, rows) {
if (err) {
console.log(err + "getting error here 1");
}
var getProductDetails = "select * from products where ITEM = '" + req.body.item + "'";
ibmdb.open(req.session.ibmdbconnDash, function (err, conn) {
if (err) return console.log(err + "getting error here 2");
conn.query(getProductDetails, function (err, gianluca) {
if (err) {
console.log(err + "getting error here 2");
}
var productAddedValue = ""
console.log(gianluca)
res.render("add-products2", {
page_title: "add-products2",
data: gianluca,
userName: req.session.username,
FN: req.session.firstname,
LN: req.session.lastname,
CO: req.session.company,
productAddedValue: productAddedValue,
});
conn.close(function () {
console.log("closed the function /add-products p2");
});
});
}); it gave me this error:
[Error: [IBM][CLI Driver][DB2/LINUXX8664] SQL0010N The string constant beginning with "' )" does not have an ending string delimiter. SQLSTATE=42603
] {
error: '[node-ibm_db] SQL_ERROR',
sqlcode: -10,
state: '42603'
}
not sure how to fix this! Thanks for the help!
Upvotes: 0
Views: 230
Reputation: 990
Turns out, was a silly error. When i was inserting the data into the db, i was adding a '
in the description column, which was throwing the whole thing off. Thanks everyone 4 the help
Upvotes: 0
Reputation: 2572
assuming you are using nodejs es5 this should work, and is much much cleaner
const addProducts = `insert into PRODUCTS (ITEM, DESCRIPTION, PRICE, SIZES, DIVISION, XS, S, M, L, XL, INTER, EACH_CASE) VALUES ('${req.body.item}', '${req.body.description}', '${req.body.price}', '${allSizes}', '${req.body.category}', '${req.body.xs}', '${req.body.s}', '${req.body.m}', '${req.body.l}', '${req.body.xl}', '${inter}', '${each_case}');`;
Upvotes: 1