github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/util/sqlexec/restricted_sql_executor.go (about) 1 // Copyright 2015 PingCAP, 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package sqlexec 15 16 import ( 17 "github.com/insionng/yougam/libraries/pingcap/tidb/ast" 18 "github.com/insionng/yougam/libraries/pingcap/tidb/context" 19 ) 20 21 // RestrictedSQLExecutor is an interface provides executing restricted sql statement. 22 // Why we need this interface? 23 // When we execute some management statements, we need to operate system tables. 24 // For example when executing create user statement, we need to check if the user already 25 // exists in the mysql.User table and insert a new row if not exists. In this case, we need 26 // a convenience way to manipulate system tables. The most simple way is executing sql statement. 27 // In order to execute sql statement in stmts package, we add this interface to solve dependence problem. 28 // And in the same time, we do not want this interface becomes a general way to run sql statement. 29 // We hope this could be used with some restrictions such as only allowing system tables as target, 30 // do not allowing recursion call. 31 // For more information please refer to the comments in session.ExecRestrictedSQL(). 32 // This is implemented in session.go. 33 type RestrictedSQLExecutor interface { 34 // ExecRestrictedSQL run sql statement in ctx with some restriction. 35 ExecRestrictedSQL(ctx context.Context, sql string) (ast.RecordSet, error) 36 }