选择存储在SQL数据库中的整数,导致整数更改为0
问题描述:
我试图从SQLite3数据库中选择一个整数,并且它导致修改后的整数。我尝试过手动插入数据库,然后通过命令提示符程序选择它,这似乎工作,但通过node.js选择时,它会产生一个整数,开始相同,但完成一些数字修改为0。 下面是代码:选择存储在SQL数据库中的整数,导致整数更改为0
function createMessage(final){
console.log('starting making message')
db.all('SELECT * FROM humblechannel',(err,row) =>{
if(err){
console.log("No Channels Found");
} else{
row.forEach((channel)=>{
console.log(channel.channelID);
client.createMessage(channel.channelID,{
embed : {
color: embedColor,
thumbnail:{
url: "https://i.imgur.com/7Tr9b7e.png",
height: '333',
width: '2000'
},
author : {
icon_url: client.user.staticAvatarURL
},
fields: final,
footer: {
text: `You Can Find More Bundles At https://www.humblebundle.com`
},
timestamp: new Date(),
}
})
})
}
})
}
This is the result of querying through SQLite3
This is the result the code above spits out into the console after doing the above insertion
正如你可以看到,他们显然是不同的。 为什么会发生这种情况?
答
原来我应该已经取得了SQL数据类型为varchar,而不是一个整数,而是一个临时的解决办法是要做到这一点:
SELECT CAST(channelID AS TEXT) AS channelID FROM humblechannel
的channelID导致完全相同的值*而是将其铸造在这种情况下的字符串
是您的原始整数大于Javascripts Number.MAX_SAFE_INTEGER(9007199254740991) –
提示:上面的答案是“是的,我使用的整数大于9007199254740991” –
是的谢谢对于提示大声笑,整数是最大的安全整数公平的位,所以我相信这是问题,谢谢。 – JamTheBean