I am using mysql database with Nodejs.(我正在使用带有Nodejs的mysql数据库。)
I am running a query like this:(我正在运行这样的查询:)
rows = await pool.query(`Select partID,stageID,locationID,QuantityAfter, QuantityChange, rowDeleted from InventoryTransactions
where partID = ${item.partID} and stageID = ${item.stageID} and locationID = ${item.locationID} and orderID = ${orderID}
order by transactionID desc`)
if(rows[0].rowDeleted != 1){ //This means that the quantity in the inventory table and inv trans table is not the same
console.log(`=====================================`)
console.log(Number(rows[0].QuantityChange))
console.log(Number(rows[0].QuantityChange))
console.log(Number(rows[0].QuantityChange))
await pool.query(`Insert into inventorytransactions(OrderID,PartID,LocationID,StageID,QuantityBefore,QuantityChange,QuantityAfter,ITTTimeStamp,rowDeleted,id)
Values(${orderID},${rows[0].partID},${rows[0].locationID},${rows[0].stageID},${parseInt(rows[0].QuantityAfter)},${-parseInt(rows[0].QuantityChange)},${parseInt(rows[0].QuantityAfter)-parseInt(rows[0].QuantityChange)},'${(new Date ((new Date((new Date(new Date())).toISOString() )).getTime() - ((new Date()).getTimezoneOffset()*60000))).toISOString().slice(0, 19).replace('T', ' ')}',true,${id})`)
console.log(Number(rows[0].QuantityChange))
console.log(Number(rows[0].QuantityChange))
console.log(Number(rows[0].QuantityChange))
console.log(`Update inventory set Quantity = quantity - ${Number(rows[0].QuantityChange)} where partID =${rows[0].partID} and stageID = ${rows[0].stageID} and locationID = ${rows[0].locationID}`)
await pool.query(`Update inventory set Quantity = quantity - ${Number(rows[0].QuantityChange)} where partID =${rows[0].partID} and stageID = ${rows[0].stageID} and locationID = ${rows[0].locationID} `)
console.log(`=====================================`)
}
The reason I have so many console.log
is because I have encountered a very weird bug.(我有这么多console.log
的原因是因为我遇到了一个非常奇怪的错误。)
All of the values of rows[0].QuantityChange)
should be the same.(rows[0].QuantityChange)
所有值都应该相同。)
But my console shows:(但是我的控制台显示:)
====================================
4
4
4
425
NaN
NaN
NaN
Update inventory set Quantity = quantity - NaN where partID =12462 and stageID = 1 and locationID = 1
{ Error: ER_BAD_FIELD_ERROR: Unknown column 'NaN' in 'field list'
I know 425 is the value of ${id}
variable which can be found at the end of the insert sql statement.(我知道425是${id}
变量的值,可以在插入sql语句的末尾找到它。)
Which makes no sense to me.(这对我来说毫无意义。) What makes even less sense is how are the the bottom values are undefined or NAN(更没有意义的是底值如何未定义或NAN)
ask by jedu translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…