我在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变量eligibilityDate
和eligibilitySize
从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)"