github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sem/tree/set.go (about) 1 // Copyright 2012, Google Inc. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in licenses/BSD-vitess.txt. 4 5 // Portions of this file are additionally subject to the following 6 // license and copyright. 7 // 8 // Copyright 2015 The Cockroach Authors. 9 // 10 // Use of this software is governed by the Business Source License 11 // included in the file licenses/BSL.txt. 12 // 13 // As of the Change Date specified in that file, in accordance with 14 // the Business Source License, use of this software will be governed 15 // by the Apache License, Version 2.0, included in the file 16 // licenses/APL.txt. 17 18 // This code was derived from https://github.com/youtube/vitess. 19 20 package tree 21 22 // SetVar represents a SET or RESET statement. 23 type SetVar struct { 24 Name string 25 Values Exprs 26 } 27 28 // Format implements the NodeFormatter interface. 29 func (node *SetVar) Format(ctx *FmtCtx) { 30 ctx.WriteString("SET ") 31 if node.Name == "" { 32 ctx.WriteString("ROW (") 33 ctx.FormatNode(&node.Values) 34 ctx.WriteString(")") 35 } else { 36 ctx.WithFlags(ctx.flags & ^FmtAnonymize, func() { 37 // Session var names never contain PII and should be distinguished 38 // for feature tracking purposes. 39 ctx.FormatNameP(&node.Name) 40 }) 41 42 ctx.WriteString(" = ") 43 ctx.FormatNode(&node.Values) 44 } 45 } 46 47 // SetClusterSetting represents a SET CLUSTER SETTING statement. 48 type SetClusterSetting struct { 49 Name string 50 Value Expr 51 } 52 53 // Format implements the NodeFormatter interface. 54 func (node *SetClusterSetting) Format(ctx *FmtCtx) { 55 ctx.WriteString("SET CLUSTER SETTING ") 56 // Cluster setting names never contain PII and should be distinguished 57 // for feature tracking purposes. 58 ctx.WithFlags(ctx.flags & ^FmtAnonymize, func() { 59 ctx.FormatNameP(&node.Name) 60 }) 61 62 ctx.WriteString(" = ") 63 ctx.FormatNode(node.Value) 64 } 65 66 // SetTransaction represents a SET TRANSACTION statement. 67 type SetTransaction struct { 68 Modes TransactionModes 69 } 70 71 // Format implements the NodeFormatter interface. 72 func (node *SetTransaction) Format(ctx *FmtCtx) { 73 ctx.WriteString("SET TRANSACTION") 74 node.Modes.Format(ctx) 75 } 76 77 // SetSessionAuthorizationDefault represents a SET SESSION AUTHORIZATION DEFAULT 78 // statement. This can be extended (and renamed) if we ever support names in the 79 // last position. 80 type SetSessionAuthorizationDefault struct{} 81 82 // Format implements the NodeFormatter interface. 83 func (node *SetSessionAuthorizationDefault) Format(ctx *FmtCtx) { 84 ctx.WriteString("SET SESSION AUTHORIZATION DEFAULT") 85 } 86 87 // SetSessionCharacteristics represents a SET SESSION CHARACTERISTICS AS TRANSACTION statement. 88 type SetSessionCharacteristics struct { 89 Modes TransactionModes 90 } 91 92 // Format implements the NodeFormatter interface. 93 func (node *SetSessionCharacteristics) Format(ctx *FmtCtx) { 94 ctx.WriteString("SET SESSION CHARACTERISTICS AS TRANSACTION") 95 node.Modes.Format(ctx) 96 } 97 98 // SetTracing represents a SET TRACING statement. 99 type SetTracing struct { 100 Values Exprs 101 } 102 103 // Format implements the NodeFormatter interface. 104 func (node *SetTracing) Format(ctx *FmtCtx) { 105 ctx.WriteString("SET TRACING = ") 106 ctx.FormatNode(&node.Values) 107 }