Documentation
¶
Index ¶
- func ConvertStmt(ops *[]*InterpreterOperation, stack *InterpreterStack, stmt ast.Statement) error
- type InterpreterCondition
- type InterpreterCursor
- type InterpreterExpr
- type InterpreterHandler
- type InterpreterNode
- type InterpreterOperation
- type InterpreterScopeDetails
- type InterpreterStack
- func (is *InterpreterStack) Details() *InterpreterScopeDetails
- func (is *InterpreterStack) GetCondition(name string) *InterpreterCondition
- func (is *InterpreterStack) GetCursor(name string) *InterpreterCursor
- func (is *InterpreterStack) GetDatabase() string
- func (is *InterpreterStack) GetLabel(name string) int
- func (is *InterpreterStack) GetVariable(name string) *InterpreterVariable
- func (is *InterpreterStack) ListHandlers() []*InterpreterHandler
- func (is *InterpreterStack) ListVariables() map[string]struct{}
- func (is *InterpreterStack) NewCondition(name string, sqlState string, mysqlErrCode int64)
- func (is *InterpreterStack) NewCursor(name string, selStmt ast.SelectStatement)
- func (is *InterpreterStack) NewHandler(cond ast.DeclareHandlerConditionValue, action ast.DeclareHandlerAction, ...)
- func (is *InterpreterStack) NewLabel(name string, index int)
- func (is *InterpreterStack) NewVariable(name string, typ sql.Type)
- func (is *InterpreterStack) NewVariableAlias(alias string, variable *InterpreterVariable)
- func (is *InterpreterStack) NewVariableWithValue(name string, typ sql.Type, val any)
- func (is *InterpreterStack) PopScope(ctx *sql.Context)
- func (is *InterpreterStack) PushScope()
- func (is *InterpreterStack) SetDatabase(db string)
- func (is *InterpreterStack) SetVariable(name string, val any) error
- type InterpreterVariable
- type OpCode
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertStmt ¶
func ConvertStmt(ops *[]*InterpreterOperation, stack *InterpreterStack, stmt ast.Statement) error
Types ¶
type InterpreterCondition ¶
InterpreterCondition is a declare condition with custom SQLState and ErrorCode.
type InterpreterCursor ¶
type InterpreterCursor struct { SelectStmt ast.SelectStatement RowIter sql.RowIter Schema sql.Schema }
InterpreterCursor is a declare cursor.
type InterpreterExpr ¶
type InterpreterExpr interface {
SetStatementRunner(ctx *sql.Context, runner sql.StatementRunner) sql.Expression
}
InterpreterExpr is an interface that implements an interpreter. These are typically used for functions (which may be implemented as a set of operations that are interpreted during runtime).
type InterpreterHandler ¶
type InterpreterHandler struct { Condition ast.DeclareHandlerConditionValue Action ast.DeclareHandlerAction Statement ast.Statement Counter int // This is used to track the current position in the stack for the handler }
InterpreterHandler is a declare handler that specifies an Action during an error Condition.
type InterpreterNode ¶
type InterpreterNode interface { GetAsOf() sql.Expression GetRunner() sql.StatementRunner GetStatements() []*InterpreterOperation SetStatementRunner(ctx *sql.Context, runner sql.StatementRunner) sql.Node SetSchema(sch sql.Schema) }
InterpreterNode is an interface that implements an interpreter. These are typically used for functions (which may be implemented as a set of operations that are interpreted during runtime).
type InterpreterOperation ¶
type InterpreterOperation struct { OpCode OpCode PrimaryData ast.Statement // This will represent the "main" data, such as the query for PERFORM, expression for IF, etc. SecondaryData []string // This represents auxiliary data, such as bindings, strictness, etc. Target string // This is the variable that will store the results (if applicable) Index int // This is the index that should be set for operations that move the function counter Error error // This is the error that should be returned for OpCode_Exception }
InterpreterOperation is an operation that will be performed by the interpreter.
type InterpreterScopeDetails ¶
type InterpreterScopeDetails struct {
// contains filtered or unexported fields
}
InterpreterScopeDetails contains all the details that are relevant to a particular scope.
type InterpreterStack ¶
type InterpreterStack struct {
// contains filtered or unexported fields
}
InterpreterStack represents the working information that an interpreter will use during execution. It is not exactly the same as a stack in the traditional programming sense, but rather is a loose abstraction that serves the same general purpose.
func Call ¶
func Call(ctx *sql.Context, iNode InterpreterNode) (sql.RowIter, *InterpreterStack, error)
Call runs the contained operations on the given runner.
func NewInterpreterStack ¶
func NewInterpreterStack() *InterpreterStack
NewInterpreterStack creates a new InterpreterStack.
func (*InterpreterStack) Details ¶
func (is *InterpreterStack) Details() *InterpreterScopeDetails
Details returns the details for the current scope.
func (*InterpreterStack) GetCondition ¶
func (is *InterpreterStack) GetCondition(name string) *InterpreterCondition
GetCondition traverses the stack (starting from the top) to find a condition with a matching name. Returns nil if no variable was found.
func (*InterpreterStack) GetCursor ¶
func (is *InterpreterStack) GetCursor(name string) *InterpreterCursor
GetCursor traverses the stack (starting from the top) to find a condition with a matching name. Returns nil if no variable was found.
func (*InterpreterStack) GetDatabase ¶
func (is *InterpreterStack) GetDatabase() string
GetDatabase returns the current database for this scope.
func (*InterpreterStack) GetLabel ¶
func (is *InterpreterStack) GetLabel(name string) int
GetLabel traverses the stack (starting from the top) to find a label with a matching name. Returns -1 if no variable was found.
func (*InterpreterStack) GetVariable ¶
func (is *InterpreterStack) GetVariable(name string) *InterpreterVariable
GetVariable traverses the stack (starting from the top) to find a variable with a matching name. Returns nil if no variable was found.
func (*InterpreterStack) ListHandlers ¶
func (is *InterpreterStack) ListHandlers() []*InterpreterHandler
ListHandlers returns a map with the names of all handlers.
func (*InterpreterStack) ListVariables ¶
func (is *InterpreterStack) ListVariables() map[string]struct{}
ListVariables returns a map with the names of all variables.
func (*InterpreterStack) NewCondition ¶
func (is *InterpreterStack) NewCondition(name string, sqlState string, mysqlErrCode int64)
NewCondition creates a new condition in the current scope.
func (*InterpreterStack) NewCursor ¶
func (is *InterpreterStack) NewCursor(name string, selStmt ast.SelectStatement)
NewCursor creates a new cursor in the current scope.
func (*InterpreterStack) NewHandler ¶
func (is *InterpreterStack) NewHandler(cond ast.DeclareHandlerConditionValue, action ast.DeclareHandlerAction, stmt ast.Statement, counter int)
NewHandler creates a new handler in the current scope.
func (*InterpreterStack) NewLabel ¶
func (is *InterpreterStack) NewLabel(name string, index int)
NewLabel creates a new label in the current scope.
func (*InterpreterStack) NewVariable ¶
func (is *InterpreterStack) NewVariable(name string, typ sql.Type)
NewVariable creates a new variable in the current scope. If a variable with the same name exists in a previous scope, then that variable will be shadowed until the current scope exits.
func (*InterpreterStack) NewVariableAlias ¶
func (is *InterpreterStack) NewVariableAlias(alias string, variable *InterpreterVariable)
NewVariableAlias creates a new variable alias, named |alias|, in the current frame of this stack, pointing to the specified |variable|.
func (*InterpreterStack) NewVariableWithValue ¶
func (is *InterpreterStack) NewVariableWithValue(name string, typ sql.Type, val any)
NewVariableWithValue creates a new variable in the current scope, setting its initial value to the one given.
func (*InterpreterStack) PopScope ¶
func (is *InterpreterStack) PopScope(ctx *sql.Context)
PopScope removes the current scope.
func (*InterpreterStack) PushScope ¶
func (is *InterpreterStack) PushScope()
PushScope creates a new scope.
func (*InterpreterStack) SetDatabase ¶
func (is *InterpreterStack) SetDatabase(db string)
SetDatabase sets the current database for this scope.
func (*InterpreterStack) SetVariable ¶
func (is *InterpreterStack) SetVariable(name string, val any) error
SetVariable sets the first variable found, with a matching name, to the value given. This does not ensure that the value matches the expectations of the type, so it should be validated before this is called. Returns an error if the variable cannot be found.
type InterpreterVariable ¶
InterpreterVariable is a variable that lives on the stack.
func (*InterpreterVariable) ToAST ¶
func (iv *InterpreterVariable) ToAST() ast.Expr
type OpCode ¶
type OpCode uint16
OpCode is the internal representation queries run by Stored Procedures.
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack is a generic stack.
func (*Stack[T]) Peek ¶
func (s *Stack[T]) Peek() (value T)
Peek returns the top value on the stack without removing it.
func (*Stack[T]) PeekDepth ¶
PeekDepth returns the n-th value from the top. PeekDepth(0) is equivalent to the standard Peek().
func (*Stack[T]) PeekReference ¶
func (s *Stack[T]) PeekReference() *T
PeekReference returns a reference to the top value on the stack without removing it.