mirror of https://github.com/jackc/pgx.git
Use buffered exec
parent
c33441674f
commit
d229219039
|
@ -467,27 +467,14 @@ func makeConnectTimeoutDialFunc(s string) (DialFunc, error) {
|
||||||
// AfterConnectTargetSessionAttrsReadWrite is an AfterConnectFunc that implements libpq compatible
|
// AfterConnectTargetSessionAttrsReadWrite is an AfterConnectFunc that implements libpq compatible
|
||||||
// target_session_attrs=read-write.
|
// target_session_attrs=read-write.
|
||||||
func AfterConnectTargetSessionAttrsReadWrite(pgConn *PgConn) error {
|
func AfterConnectTargetSessionAttrsReadWrite(pgConn *PgConn) error {
|
||||||
pgConn.SendExec("show transaction_read_only")
|
result, err := pgConn.Exec("show transaction_read_only")
|
||||||
err := pgConn.Flush()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
result := pgConn.GetResult()
|
if string(result.Rows[0][0]) == "on" {
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
rowFound := result.NextRow()
|
|
||||||
if !rowFound {
|
|
||||||
return errors.New("show transaction_read_only failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
if string(result.Values()[0]) == "on" {
|
|
||||||
return errors.New("read only connection")
|
return errors.New("read only connection")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = result.Close()
|
return nil
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue