github.com/matrixorigin/matrixone@v1.2.0/pkg/frontend/back_self_handle.go (about) 1 // Copyright 2024 Matrix Origin 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 frontend 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/common/moerr" 19 "github.com/matrixorigin/matrixone/pkg/sql/parsers/tree" 20 ) 21 22 func execInFrontendInBack(backSes *backSession, 23 execCtx *ExecCtx) (err error) { 24 //check transaction states 25 switch st := execCtx.stmt.(type) { 26 case *tree.BeginTransaction: 27 case *tree.CommitTransaction: 28 case *tree.RollbackTransaction: 29 case *tree.Use: 30 err = handleChangeDB(backSes, execCtx, st.Name.Compare()) 31 if err != nil { 32 return 33 } 34 case *tree.CreateDatabase: 35 err = inputNameIsInvalid(execCtx.reqCtx, string(st.Name)) 36 if err != nil { 37 return 38 } 39 if st.SubscriptionOption != nil && backSes.tenant != nil && !backSes.tenant.IsAdminRole() { 40 err = moerr.NewInternalError(execCtx.reqCtx, "only admin can create subscription") 41 return 42 } 43 st.Sql = execCtx.sqlOfStmt 44 case *tree.DropDatabase: 45 err = inputNameIsInvalid(execCtx.reqCtx, string(st.Name)) 46 if err != nil { 47 return 48 } 49 // if the droped database is the same as the one in use, database must be reseted to empty. 50 if string(st.Name) == backSes.GetDatabaseName() { 51 backSes.SetDatabaseName("") 52 } 53 case *tree.Grant: 54 switch st.Typ { 55 case tree.GrantTypeRole: 56 if err = handleGrantRole(backSes, execCtx, &st.GrantRole); err != nil { 57 return 58 } 59 case tree.GrantTypePrivilege: 60 if err = handleGrantPrivilege(backSes, execCtx, &st.GrantPrivilege); err != nil { 61 return 62 } 63 } 64 case *tree.Revoke: 65 switch st.Typ { 66 case tree.RevokeTypeRole: 67 if err = handleRevokeRole(backSes, execCtx, &st.RevokeRole); err != nil { 68 return 69 } 70 case tree.RevokeTypePrivilege: 71 if err = handleRevokePrivilege(backSes, execCtx, &st.RevokePrivilege); err != nil { 72 return 73 } 74 } 75 case *tree.EmptyStmt: 76 if err = handleEmptyStmt(backSes, execCtx, st); err != nil { 77 return 78 } 79 default: 80 return moerr.NewInternalError(execCtx.reqCtx, "backExec does not support %s", execCtx.sqlOfStmt) 81 } 82 return 83 }