File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -60,10 +60,14 @@ class MySQLCRUDRowReader<K : CodingKey>: KeyedDecodingContainerProtocol {
6060 return Int ( i)
6161 case let i as Int32 :
6262 return Int ( i)
63+ case let i as Int16 :
64+ return Int ( i)
65+ case let i as Int8 :
66+ return Int ( i)
6367 case let i as Int :
6468 return i
6569 default :
66- throw MySQLCRUDError ( " Could not convert \( String ( describing: a) ) into an Int. " )
70+ throw MySQLCRUDError ( " Could not convert \( String ( describing: a) ) into an Int for key: \( key . stringValue ) " )
6771 }
6872 }
6973 func decode( _ type: Int8 . Type , forKey key: Key ) throws -> Int8 {
@@ -83,10 +87,16 @@ class MySQLCRUDRowReader<K : CodingKey>: KeyedDecodingContainerProtocol {
8387 switch a {
8488 case let i as UInt64 :
8589 return UInt ( i)
90+ case let i as UInt32 :
91+ return UInt ( i)
92+ case let i as UInt16 :
93+ return UInt ( i)
94+ case let i as UInt8 :
95+ return UInt ( i)
8696 case let i as UInt :
8797 return i
8898 default :
89- throw MySQLCRUDError ( " Could not convert \( String ( describing: a) ) into an UInt. " )
99+ throw MySQLCRUDError ( " Could not convert \( String ( describing: a) ) into an UInt for key: \( key . stringValue ) " )
90100 }
91101 }
92102 func decode( _ type: UInt8 . Type , forKey key: Key ) throws -> UInt8 {
Original file line number Diff line number Diff line change @@ -1676,6 +1676,25 @@ class PerfectMySQLTests: XCTestCase {
16761676 XCTFail ( " \( error) " )
16771677 }
16781678 }
1679+
1680+ func testIntConversion( ) {
1681+ do {
1682+ let db = try getTestDB ( )
1683+ struct IntTest : Codable {
1684+ let id : Int
1685+ }
1686+ try db. sql ( " CREATE TABLE IntTest(id tinyint PRIMARY KEY) " )
1687+ let table = db. table ( IntTest . self)
1688+ let inserted = IntTest ( id: 1 )
1689+ try table. insert ( inserted)
1690+ guard let selected = try db. table ( IntTest . self) . where ( \IntTest . id == 1 ) . first ( ) else {
1691+ return XCTFail ( " Unable to find IntTest. " )
1692+ }
1693+ XCTAssertEqual ( selected. id, inserted. id)
1694+ } catch {
1695+ XCTFail ( " \( error) " )
1696+ }
1697+ }
16791698
16801699 func testBespokeSQL( ) {
16811700 do {
You can’t perform that action at this time.
0 commit comments