【问题标题】:Express-Server receives wrong data from MYSQL-databaseExpress-Server 从 MYSQL-database 接收到错误的数据
【发布时间】:2019-07-26 23:48:15
【问题描述】:

我将 express 与 mySQL 数据库一起使用,我想使用 select 语句检索数据。

connection.query('select * from table1', function(err, rows, fields){console.log(rows)}

数据库中的列如下所示:

id, name, producer

数据库中的id是:

100000001200000001

在我收到的 console.log 中:

{id: 10000000120000000, name: "Tim", producer: "Tims"}

如您所见,“1”在 JSON 对象中丢失了。

我不知道问题可能是什么......

【问题讨论】:

  • 数据库中是bigint...

标签: javascript mysql node.js json express


【解决方案1】:

您的整数在 Javascript 中高于 MAX_SAFE_INTEGER。 您应该使用BigInt(int) 来正确获取它。

您肯定想查看此页面:https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/BigInt

【讨论】:

  • 谢谢,但我无法通过将其后缀转换为 BigInt 来获得“1”。
  • 你不能把它作为一个数字(BigInt 会在末尾放一个 n),但你可以把它作为一个字符串。例如:id: '' + BigInt(100000001200000001)
猜你喜欢
  • 1970-01-01
  • 2021-12-13
  • 2021-12-24
  • 2013-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-24
  • 2017-02-01
相关资源
最近更新 更多