0

我在 MySQL 中有一个数据库,其中我的表的一列是布尔值:

`eligibilityDate` tinyint(1) NOT NULL

数据通过以下函数从我的 iOS Swift 应用程序到达:

let postParams = "action=save_report&id_fish=\(Reporting.fishId)&fish_name=\(Reporting.fishName)&detectedSize=\(Reporting.detectedSize)&eligibilitySize=\(Reporting.eligibilitySize)&eligibilityDate=\(Reporting.eligibilityDate)&origin=\(Reporting.origin)&production=\(Reporting.production)&townReport=\(Reporting.townReport)"

request.HTTPBody = postParams.dataUsingEncoding(NSUTF8StringEncoding)

我猜 Bool 变量eligibilityDateeligibilitySize从真/假转换为“真”/“假”。无论如何,似乎“真实”值在 MySQL 中被保存为 0 ......为什么?哪个是正确的方法?

更新

一个可能的解决方案可能是这样的:

let postParams = "action=save_report&id_fish=\(Reporting.fishId)&fish_name=\(Reporting.fishName)&detectedSize=\(Reporting.detectedSize)&eligibilitySize=\(Reporting.eligibilitySize ? 1 : 0)&eligibilityDate=\(Reporting.eligibilityDate ? 1 : 0)&origin=\(Reporting.origin)&production=\(Reporting.production)&townReport=\(Reporting.townReport)"

4

0 回答 0