github.com/dolthub/go-mysql-server@v0.18.0/sql/analyzer/autocommit.go (about) 1 // Copyright 2022 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package analyzer 16 17 import ( 18 "github.com/dolthub/go-mysql-server/sql" 19 "github.com/dolthub/go-mysql-server/sql/plan" 20 "github.com/dolthub/go-mysql-server/sql/transform" 21 ) 22 23 // addAutocommitNode wraps each query with a TransactionCommittingNode. 24 func addAutocommitNode(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scope, sel RuleSelector) (sql.Node, transform.TreeIdentity, error) { 25 if !n.Resolved() { 26 return n, transform.SameTree, nil 27 } 28 29 // TODO: This is a bit of a hack. Need to figure out better relationship between new transaction node and warnings. 30 if hasShowWarningsNode(n) { 31 return n, transform.SameTree, nil 32 } 33 34 return plan.NewTransactionCommittingNode(n), transform.NewTree, nil 35 } 36 37 func hasShowWarningsNode(n sql.Node) bool { 38 var ret bool 39 transform.Inspect(n, func(n sql.Node) bool { 40 if _, ok := n.(plan.ShowWarnings); ok { 41 ret = true 42 return false 43 } 44 45 return true 46 }) 47 48 return ret 49 }