mirror of https://github.com/jackc/pgx.git
Rename runtime params to parameter status
parent
b63370e5d5
commit
44de49ffa1
22
base/conn.go
22
base/conn.go
|
@ -103,12 +103,12 @@ func (cc *ConnConfig) assignDefaults() error {
|
|||
|
||||
// PgConn is a low-level PostgreSQL connection handle. It is not safe for concurrent usage.
|
||||
type PgConn struct {
|
||||
NetConn net.Conn // the underlying TCP or unix domain socket connection
|
||||
PID uint32 // backend pid
|
||||
SecretKey uint32 // key to use to send a cancel query message to the server
|
||||
RuntimeParams map[string]string // parameters that have been reported by the server
|
||||
TxStatus byte
|
||||
Frontend *pgproto3.Frontend
|
||||
NetConn net.Conn // the underlying TCP or unix domain socket connection
|
||||
PID uint32 // backend pid
|
||||
SecretKey uint32 // key to use to send a cancel query message to the server
|
||||
parameterStatuses map[string]string // parameters that have been reported by the server
|
||||
TxStatus byte
|
||||
Frontend *pgproto3.Frontend
|
||||
|
||||
Config ConnConfig
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ func Connect(cc ConnConfig) (*PgConn, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
pgConn.RuntimeParams = make(map[string]string)
|
||||
pgConn.parameterStatuses = make(map[string]string)
|
||||
|
||||
if cc.TLSConfig != nil {
|
||||
if err := pgConn.startTLS(cc.TLSConfig); err != nil {
|
||||
|
@ -260,8 +260,14 @@ func (pgConn *PgConn) ReceiveMessage() (pgproto3.BackendMessage, error) {
|
|||
case *pgproto3.ReadyForQuery:
|
||||
pgConn.TxStatus = msg.TxStatus
|
||||
case *pgproto3.ParameterStatus:
|
||||
pgConn.RuntimeParams[msg.Name] = msg.Value
|
||||
pgConn.parameterStatuses[msg.Name] = msg.Value
|
||||
}
|
||||
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
// ParameterStatus returns the value of a parameter reported by the server (e.g.
|
||||
// server_version). Returns an empty string for unknown parameters.
|
||||
func (pgConn *PgConn) ParameterStatus(key string) string {
|
||||
return pgConn.parameterStatuses[key]
|
||||
}
|
||||
|
|
4
conn.go
4
conn.go
|
@ -933,8 +933,10 @@ func configTLS(args configTLSArgs, cc *ConnConfig) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// ParameterStatus returns the value of a parameter reported by the server (e.g.
|
||||
// server_version). Returns an empty string for unknown parameters.
|
||||
func (c *Conn) ParameterStatus(key string) string {
|
||||
return c.pgConn.RuntimeParams[key]
|
||||
return c.pgConn.ParameterStatus(key)
|
||||
}
|
||||
|
||||
// Prepare creates a prepared statement with name and sql. sql can contain placeholders
|
||||
|
|
4
query.go
4
query.go
|
@ -519,11 +519,11 @@ func (c *Conn) readUntilRowDescription() ([]FieldDescription, error) {
|
|||
}
|
||||
|
||||
func (c *Conn) sanitizeAndSendSimpleQuery(sql string, args ...interface{}) (err error) {
|
||||
if c.pgConn.RuntimeParams["standard_conforming_strings"] != "on" {
|
||||
if c.pgConn.ParameterStatus("standard_conforming_strings") != "on" {
|
||||
return errors.New("simple protocol queries must be run with standard_conforming_strings=on")
|
||||
}
|
||||
|
||||
if c.pgConn.RuntimeParams["client_encoding"] != "UTF8" {
|
||||
if c.pgConn.ParameterStatus("client_encoding") != "UTF8" {
|
||||
return errors.New("simple protocol queries must be run with client_encoding=UTF8")
|
||||
}
|
||||
|
||||
|
|
4
v4.md
4
v4.md
|
@ -34,8 +34,8 @@ Minor Potential Changes:
|
|||
|
||||
## Changes
|
||||
|
||||
`base.Conn` now contains core PostgreSQL connection functionality.
|
||||
`base.PgConn` now contains core PostgreSQL connection functionality.
|
||||
|
||||
### Incompatible Changes
|
||||
|
||||
* `RuntimeParams` removed from `pgx.Conn` and added to `base.Conn`
|
||||
* `RuntimeParams` `pgx.Conn`. Server reported status can now be queried with the `ParameterStatus` method. The rename aligns with the PostgreSQL protocol and standard libpq naming. Access via a method instead of direct access to the map protects against outside modification.
|
||||
|
|
Loading…
Reference in New Issue