@@ -31,72 +31,67 @@ internal struct Parameter {
3131 /// The parameter name.
3232 internal let name : String
3333
34- /// The parameter value desired by PostgresClientKit.
35- internal let value : String
34+ /// The parameter values allowed by PostgresClientKit, or `nil` for any value .
35+ internal let allowedValues : [ String ] ?
3636
37- /// Whether PostgresClientKit sets the value of this parameter in creating a `Connection`.
38- internal let isSetWhenConnecting : Bool
39-
40- /// Whether PostgresClientKit checks the value of this parameter when it receives a
41- /// `ParameterStatusResponse`.
42- internal let isCheckedUponParameterStatusResponse : Bool
37+ /// The parameter value set by PostgresClientKit in creating a `Connection`, or `nil` to not
38+ /// set a value.
39+ internal let valueSetWhenConnecting : String ?
4340
4441 /// The parameters of interest to PostgresClientKit.
4542 internal static let values = [
4643
4744 // PostgresClientKit requires strings received from the Postgres server to be UTF8 format.
4845 Parameter ( name: " client_encoding " ,
49- value: " UTF8 " ,
50- isSetWhenConnecting: true ,
51- isCheckedUponParameterStatusResponse: true ) ,
46+ allowedValues: [ " UTF8 " ] ,
47+ valueSetWhenConnecting: " UTF8 " ) ,
5248
5349 // PostgresClientKit requires timestamps, dates, and times received from the Postgres server
5450 // to be ISO-8601 format.
5551 Parameter ( name: " DateStyle " ,
56- value: " ISO, MDY " ,
57- isSetWhenConnecting: true ,
58- isCheckedUponParameterStatusResponse: true ) ,
52+ allowedValues: [ " ISO, MDY " , " ISO, DMY " , " ISO, YMD " ] ,
53+ valueSetWhenConnecting: " ISO, MDY " ) ,
5954
6055 // PostgresClientKit requires timestamps and times received from the Postgres server to be
6156 // in the UTC/GMT time zone.
6257 Parameter ( name: " TimeZone " ,
63- value: " GMT " ,
64- isSetWhenConnecting: true ,
65- isCheckedUponParameterStatusResponse: true ) ,
66-
58+ allowedValues: [ " GMT " ] ,
59+ valueSetWhenConnecting: " GMT " ) ,
60+
6761 // PostgresClientKit requires `bytea` values received from the Postgres server to be hex
6862 // encoded.
6963 Parameter ( name: " bytea_output " ,
70- value: " hex " ,
71- isSetWhenConnecting: true ,
72- isCheckedUponParameterStatusResponse: true ) ,
64+ allowedValues: [ " hex " ] ,
65+ valueSetWhenConnecting: " hex " ) ,
7366 ]
7467
75- /// Checks whether the parameter in the specified `ParameterStatusResponse` is required by
76- /// PostgresClientKit to have a certain value and, if so, whether it has that value .
68+ /// Checks whether the parameter in the specified `ParameterStatusResponse` is constrained by
69+ /// PostgresClientKit to certain values and, if so, whether that constraint is satisfied .
7770 ///
7871 /// - Parameter response: the response to check
79- /// - Throws: `PostgresError.invalidParameterValue` if the parameter does not have the required
72+ /// - Throws: `PostgresError.invalidParameterValue` if the parameter does not have an allowed
8073 /// value
8174 internal static func checkParameterStatusResponse( _ response: ParameterStatusResponse ,
8275 connection: Connection ) throws {
8376
8477 if let parameter = values. first ( where: {
8578 $0. name == response. name
86- && $0. isCheckedUponParameterStatusResponse
87- && $0. value != response. value } ) {
79+ && $0. allowedValues != nil
80+ && !$0. allowedValues!. contains ( response. value) } ) {
81+
82+ let allowedValues = parameter. allowedValues!
8883
8984 connection. log (
9085 . warning,
91- " Invalid value for Postgres parameter (response.name): " +
92- " \( response. value) (must be \( parameter . value ) ); closing connection " )
86+ " Invalid value for Postgres parameter \ ( response. name) : " +
87+ " \( response. value) (allowedValues \( allowedValues ) ); closing connection " )
9388
9489 // The invalid parameter change already ocurred. This connection is toast.
9590 connection. close ( )
9691
9792 throw PostgresError . invalidParameterValue ( name: response. name,
9893 value: response. value,
99- requiredValue : parameter . value )
94+ allowedValues : allowedValues )
10095 }
10196 }
10297}
0 commit comments