Skip to content

Commit 93e9843

Browse files
authored
binds max (#103)
1 parent a1dbfbc commit 93e9843

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Sources/PostgresNIO/PostgresDatabase+Query.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ private final class PostgresParameterizedQuery: PostgresRequest {
179179
}
180180

181181
func start() throws -> [PostgresMessage] {
182+
guard self.binds.count <= Int16.max else {
183+
throw PostgresError.protocol("Bind count must be <= \(Int16.max).")
184+
}
182185
let parse = PostgresMessage.Parse(
183186
statementName: "",
184187
query: self.query,

Tests/PostgresNIOTests/PostgresNIOTests.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,16 @@ final class PostgresNIOTests: XCTestCase {
904904
XCTAssertEqual(rows.metadata.oid, nil)
905905
XCTAssertEqual(rows.metadata.rows, 0)
906906
}
907-
907+
908+
func testTooManyBinds() throws {
909+
let conn = try PostgresConnection.test(on: eventLoop).wait()
910+
defer { try! conn.close().wait() }
911+
let binds = [PostgresData].init(repeating: .null, count: Int(Int16.max) + 1)
912+
do {
913+
_ = try conn.query("SELECT version()", binds).wait()
914+
XCTFail("Should have failed")
915+
} catch PostgresError.connectionClosed { }
916+
}
908917
}
909918

910919
let isLoggingConfigured: Bool = {

0 commit comments

Comments
 (0)