Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
813 views
in Technique[技术] by (71.8m points)

node.js - Mysql returning incorrect bigint result by one, very strange error

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

enter image description here

With this data:

enter image description here

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

enter image description here

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

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
                 });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...