MySQL:为什么'true'保存为0?

时间:2016-02-08 09:08:11

标签: mysql swift post boolean tinyint

我在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从true / false转换为'true'/'false'。 无论如何,似乎'真''值在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)"

0 个答案:

没有答案