MCPcopy Create free account
hub / github.com/apecloud/myduckserver / setPgSessionVar

Method setPgSessionVar

pgserver/in_place_handler.go:89–122  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

87// setPgSessionVar will set the session variable to the value provided for pg.
88// And reply with the CommandComplete and ParameterStatus messages.
89func (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
124type InPlaceHandler struct {
125 // ShouldBeHandledInPlace is a function that determines if the query should be

Callers 1

Calls 7

sendMethod · 0.95
makeCommandCompleteFunction · 0.85
GetDefaultMethod · 0.80
GetSessionScopeMethod · 0.80
GetValueMethod · 0.80
NewContextMethod · 0.65
SetValueMethod · 0.45

Tested by

no test coverage detected