0

I have a DB in MySQL where a column of my table is a boolean:

`eligibilityDate` tinyint(1) NOT NULL

Data arrive from my iOS Swift app through the following functions:

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)

where I guess that Bool variables eligibilityDate and eligibilitySize are converted from true/false to 'true'/'false'. Anyway it seems that 'true' value is saved as 0 in MySQL...why? which is the correct way?

UPDATE

A possible solution could be this:

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)"

SagittariusA
  • 5,289
  • 15
  • 73
  • 127
  • Looks something wrong with request Try first with static value by putting &eligibilityDate=1. since eligibilityDate is tinyint(1) so for any other value from request in not in range (tinyint (1)) than it will insert 0 by deafult – kamlesh.bar Feb 08 '16 at 09:15
  • it seems that with `eligibilityDate='1'` works correctly... I don't understand why with 'true' is converted to 0... – SagittariusA Feb 08 '16 at 09:20
  • 1
    tinyint only accept integer value based on range(1 in your case). so if you pass true it will not convert to 1 but instead it will insert default integer value that is 0. – kamlesh.bar Feb 08 '16 at 09:22
  • well, that is strange because I had done another project where the stored value was `tinyint` and I could freely use type `Bool` in the app...I don't know why it does not work anymore. – SagittariusA Feb 08 '16 at 09:24
  • tinyint: 1 byte, -128 to +127 / 0 to 255 (unsigned) for more info http://stackoverflow.com/questions/2991405/what-is-the-difference-between-tinyint-smallint-mediumint-bigint-and-int-in-m – kamlesh.bar Feb 08 '16 at 09:26
  • this is not of help... – SagittariusA Feb 08 '16 at 09:26

0 Answers0