MySQL in Node.js returning incorrect values

28 Views Asked by At

I'm trying to write a bot for Discord which I host with Node.js. When I try to get a user id from a database by searching for the person's name I do get a result, however the id is always a bit off. For example the code

sql.query('SELECT userID FROM users WHERE name="Max"', function(error, result, fields){
    console.log(result);
});

returns [ RowDataPacket { userID: 434776574123048960 } ] while the actual userID should be 434776574123048990.

I've also tried other users and found that the difference between the returned and the actual value does vary between the different users but is consistent for each user. Inputting the SQL code directly into the mysql application does return the correct values.

Edit: Apparently js integers are a bit inaccurate after a certain length. Changing the userID type to varchar solved the issue.

0

There are 0 best solutions below