Mysql returning incorrect bigint result by one, very strange error

旧街凉风 提交于 2019-12-19 06:45:34

问题


I really don't know what is going on here. I have a database table that looks like this:

With this data:

When I run this query SELECT * FROM game WHERE id = 4 in phpmyadmin I get back this result as expected:

But when I make this query on it through a rest api (where gameId = 4)

var query = connection.query("SELECT * FROM game WHERE id = ? ",[game.gameId],function(err,rows){ 

I get this result

Where adminId for some reason has been subtracted by one. I really haven't a clue what is going on. I have tried dropping the table and setting it back up, has anyone experienced this before? Or know what is wrong? It's pretty frustrating! Thanks


回答1:


The maximum integer JavaScript can safely represent is Number.MAX_SAFE_INTEGER, which is 2^53 - 1. Your value is greater than that, which is causing some bits to be lost.

node-mysql has supportBigNumbers and bigNumberStrings options that parse BIGINTs as strings.

var connection = mysql.createConnection({
                            supportBigNumbers: true,
                            bigNumberStrings: true
                 });


来源:https://stackoverflow.com/questions/28759036/mysql-returning-incorrect-bigint-result-by-one-very-strange-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!