Skip to content
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
20 changes: 10 additions & 10 deletions Sources/PostgresNIO/Connection/PostgresClient+Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ private final class PostgresParameterizedQuery: PostgresRequest {
case .parseComplete:
return []
case .parameterDescription:
// let params = try PostgresMessage.ParameterDescription(message: message)
// if params.dataTypes.count != binds.count {
// self.logger!.warning("Expected parameters count (\(params.dataTypes.count)) does not equal binds count (\(binds.count))")
// } else {
// for (i, item) in zip(params.dataTypes, binds).enumerated() {
// if item.0 != item.1.type {
// self.logger!.warning("bind $\(i + 1) type (\(item.1.type)) does not match expected parameter type (\(item.0))")
// }
// }
// }
let params = try PostgresMessage.ParameterDescription(message: message)
if params.dataTypes.count != self.binds.count {
self.logger!.warning("Expected parameters count (\(params.dataTypes.count)) does not equal binds count (\(binds.count))")
} else {
for (i, item) in zip(params.dataTypes, self.binds).enumerated() {
if item.0 != item.1.type {
self.logger!.warning("bind $\(i + 1) type (\(item.1.type)) does not match expected parameter type (\(item.0))")
}
}
}
return []
case .commandComplete:
return []
Expand Down
17 changes: 17 additions & 0 deletions Tests/PostgresNIOTests/NIOPostgresTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,23 @@ final class NIOPostgresTests: XCTestCase {
XCTAssertEqual(rows[0].column("languages")?.array(of: String.self), ["en"])
XCTAssertEqual(rows[0].column("currencies")?.array(of: String.self), ["USD", "DKK"])
}

func testBindDate() throws {
// https://github.com/vapor/postgres-nio/issues/53
let date = Date(timeIntervalSince1970: 1571425782)
let query = """
SELECT $1::json as "date"
"""
let conn = try PostgresConnection.test(on: eventLoop).wait()
defer { try! conn.close().wait() }
do {
_ = try conn.query(query, [.init(date: date)]).wait()
XCTFail("should have failed")
} catch PostgresError.server(let error) {
XCTAssertEqual(error.fields[.routine], "report_invalid_encoding")
}

}

// MARK: Performance

Expand Down
1 change: 1 addition & 0 deletions Tests/PostgresNIOTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extension NIOPostgresTests {
// to regenerate.
static let __allTests__NIOPostgresTests = [
("testAverageLengthNumeric", testAverageLengthNumeric),
("testBindDate", testBindDate),
("testBindInteger", testBindInteger),
("testBoolSerialize", testBoolSerialize),
("testBytesSerialize", testBytesSerialize),
Expand Down