Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numeric with leading zero fractional #68

Merged
merged 3 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/PostgreSQL/Data/PostgreSQLData+String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ extension String: PostgreSQLDataConvertible {
if offset < metadata.weight.bigEndian + 1 {
integer += string
} else {
fractional += string
// Leading zeros matter with fractional
fractional += fractional.count == 0 ? String(repeating: "0", count: 4 - string.count) + string : string
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/PostgreSQLTests/PostgreSQLConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class PostgreSQLConnectionTests: XCTestCase {
params += Int16(1) // smallint
params += Int32(2) // integer
params += Int64(3) // bigint
params += String("123456789.123456789") // decimal
params += String("123456789.0123456789") // decimal
params += Double(5) // numeric
params += Float(6) // real
params += Double(7) // double
Expand All @@ -238,7 +238,7 @@ class PostgreSQLConnectionTests: XCTestCase {
try XCTAssertEqual(row.firstValue(forColumn: "smallint")?.decode(Int16.self), 1)
try XCTAssertEqual(row.firstValue(forColumn: "integer")?.decode(Int32.self), 2)
try XCTAssertEqual(row.firstValue(forColumn: "bigint")?.decode(Int64.self), 3)
try XCTAssertEqual(row.firstValue(forColumn: "decimal")?.decode(String.self), "123456789.123456789")
try XCTAssertEqual(row.firstValue(forColumn: "decimal")?.decode(String.self), "123456789.0123456789")
try XCTAssertEqual(row.firstValue(forColumn: "real")?.decode(Float.self), 6)
try XCTAssertEqual(row.firstValue(forColumn: "double")?.decode(Double.self), 7)
try XCTAssertEqual(row.firstValue(forColumn: "varchar")?.decode(String.self), "8")
Expand Down