PerfectlySoft / Perfect-MySQL

A stand-alone Swift wrapper around the MySQL client library, enabling access to MySQL servers.
https://www.perfect.org
Apache License 2.0
128 stars 61 forks source link

Added Int32 decoding #43

Closed timotheeduran closed 5 years ago

timotheeduran commented 6 years ago

Swift documentation says

On 32-bit platforms, Int is the same size as Int32, and on 64-bit platforms, Int is the same size as Int64.

The actual code in the Int decode method is

switch a {
case let i as Int64:
    return Int(i)
case let i as Int:
    return i
default:
    throw MySQLCRUDError("Could not convert \(String(describing: a)) into an Int.")
}

When working on a 64-bit platform, the two first switch cases are equivalent and if a: Int32, an exception will be thrown.

The pull request adds a case for a: Int32 to ensure correct behavior when receiving a 32-bit Int on a 64-bit machine.