Skip to content

Commit e3c81cc

Browse files
authored
Merge pull request #2169 from thedolphin/master
Switch from ExecParams to Exec in ValidateConnectTargetSessionAttrs
2 parents b9e2b20 + 4b7e994 commit e3c81cc

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

pgconn/config.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -861,12 +861,12 @@ func makeConnectTimeoutDialFunc(timeout time.Duration) DialFunc {
861861
// ValidateConnectTargetSessionAttrsReadWrite is a ValidateConnectFunc that implements libpq compatible
862862
// target_session_attrs=read-write.
863863
func ValidateConnectTargetSessionAttrsReadWrite(ctx context.Context, pgConn *PgConn) error {
864-
result := pgConn.ExecParams(ctx, "show transaction_read_only", nil, nil, nil, nil).Read()
865-
if result.Err != nil {
866-
return result.Err
864+
result, err := pgConn.Exec(ctx, "show transaction_read_only").ReadAll()
865+
if err != nil {
866+
return err
867867
}
868868

869-
if string(result.Rows[0][0]) == "on" {
869+
if string(result[0].Rows[0][0]) == "on" {
870870
return errors.New("read only connection")
871871
}
872872

@@ -876,12 +876,12 @@ func ValidateConnectTargetSessionAttrsReadWrite(ctx context.Context, pgConn *PgC
876876
// ValidateConnectTargetSessionAttrsReadOnly is a ValidateConnectFunc that implements libpq compatible
877877
// target_session_attrs=read-only.
878878
func ValidateConnectTargetSessionAttrsReadOnly(ctx context.Context, pgConn *PgConn) error {
879-
result := pgConn.ExecParams(ctx, "show transaction_read_only", nil, nil, nil, nil).Read()
880-
if result.Err != nil {
881-
return result.Err
879+
result, err := pgConn.Exec(ctx, "show transaction_read_only").ReadAll()
880+
if err != nil {
881+
return err
882882
}
883883

884-
if string(result.Rows[0][0]) != "on" {
884+
if string(result[0].Rows[0][0]) != "on" {
885885
return errors.New("connection is not read only")
886886
}
887887

@@ -891,12 +891,12 @@ func ValidateConnectTargetSessionAttrsReadOnly(ctx context.Context, pgConn *PgCo
891891
// ValidateConnectTargetSessionAttrsStandby is a ValidateConnectFunc that implements libpq compatible
892892
// target_session_attrs=standby.
893893
func ValidateConnectTargetSessionAttrsStandby(ctx context.Context, pgConn *PgConn) error {
894-
result := pgConn.ExecParams(ctx, "select pg_is_in_recovery()", nil, nil, nil, nil).Read()
895-
if result.Err != nil {
896-
return result.Err
894+
result, err := pgConn.Exec(ctx, "select pg_is_in_recovery()").ReadAll()
895+
if err != nil {
896+
return err
897897
}
898898

899-
if string(result.Rows[0][0]) != "t" {
899+
if string(result[0].Rows[0][0]) != "t" {
900900
return errors.New("server is not in hot standby mode")
901901
}
902902

@@ -906,12 +906,12 @@ func ValidateConnectTargetSessionAttrsStandby(ctx context.Context, pgConn *PgCon
906906
// ValidateConnectTargetSessionAttrsPrimary is a ValidateConnectFunc that implements libpq compatible
907907
// target_session_attrs=primary.
908908
func ValidateConnectTargetSessionAttrsPrimary(ctx context.Context, pgConn *PgConn) error {
909-
result := pgConn.ExecParams(ctx, "select pg_is_in_recovery()", nil, nil, nil, nil).Read()
910-
if result.Err != nil {
911-
return result.Err
909+
result, err := pgConn.Exec(ctx, "select pg_is_in_recovery()").ReadAll()
910+
if err != nil {
911+
return err
912912
}
913913

914-
if string(result.Rows[0][0]) == "t" {
914+
if string(result[0].Rows[0][0]) == "t" {
915915
return errors.New("server is in standby mode")
916916
}
917917

@@ -921,12 +921,12 @@ func ValidateConnectTargetSessionAttrsPrimary(ctx context.Context, pgConn *PgCon
921921
// ValidateConnectTargetSessionAttrsPreferStandby is a ValidateConnectFunc that implements libpq compatible
922922
// target_session_attrs=prefer-standby.
923923
func ValidateConnectTargetSessionAttrsPreferStandby(ctx context.Context, pgConn *PgConn) error {
924-
result := pgConn.ExecParams(ctx, "select pg_is_in_recovery()", nil, nil, nil, nil).Read()
925-
if result.Err != nil {
926-
return result.Err
924+
result, err := pgConn.Exec(ctx, "select pg_is_in_recovery()").ReadAll()
925+
if err != nil {
926+
return err
927927
}
928928

929-
if string(result.Rows[0][0]) != "t" {
929+
if string(result[0].Rows[0][0]) != "t" {
930930
return &NotPreferredError{err: errors.New("server is not in hot standby mode")}
931931
}
932932

0 commit comments

Comments
 (0)