setPgSessionVar will set the session variable to the value provided for pg. And reply with the CommandComplete and ParameterStatus messages.
(name string, value any, useDefault bool, tag string)
| 87 | // setPgSessionVar will set the session variable to the value provided for pg. |
| 88 | // And reply with the CommandComplete and ParameterStatus messages. |
| 89 | func (h *ConnectionHandler) setPgSessionVar(name string, value any, useDefault bool, tag string) (bool, error) { |
| 90 | sysVar, _, ok := sql.SystemVariables.GetGlobal(name) |
| 91 | if !ok { |
| 92 | return false, fmt.Errorf("error: %s variable was not found", name) |
| 93 | } |
| 94 | ctx, err := h.duckHandler.NewContext(context.Background(), h.mysqlConn, "") |
| 95 | if err != nil { |
| 96 | return false, err |
| 97 | } |
| 98 | if useDefault { |
| 99 | value = sysVar.GetDefault() |
| 100 | } |
| 101 | err = sysVar.GetSessionScope().SetValue(ctx, name, value) |
| 102 | if err != nil { |
| 103 | return false, err |
| 104 | } |
| 105 | v, err := sysVar.GetSessionScope().GetValue(ctx, name, sql.Collation_Default) |
| 106 | if err != nil { |
| 107 | return false, fmt.Errorf("error: %s variable was not found, err: %w", name, err) |
| 108 | } |
| 109 | // Sent CommandComplete message |
| 110 | err = h.send(makeCommandComplete(tag, 0)) |
| 111 | if err != nil { |
| 112 | return true, err |
| 113 | } |
| 114 | // Sent ParameterStatus message |
| 115 | if err := h.send(&pgproto3.ParameterStatus{ |
| 116 | Name: name, |
| 117 | Value: fmt.Sprintf("%v", v), |
| 118 | }); err != nil { |
| 119 | return true, err |
| 120 | } |
| 121 | return true, nil |
| 122 | } |
| 123 | |
| 124 | type InPlaceHandler struct { |
| 125 | // ShouldBeHandledInPlace is a function that determines if the query should be |
no test coverage detected