procedures

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2025 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

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

type InterpreterCondition struct {
	SQLState     string
	MySQLErrCode int64
}

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.

func Parse

func Parse(stmt ast.Statement) ([]*InterpreterOperation, error)

Parse takes the ast.Statement and converts it series of OpCodes.

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

Call runs the contained operations on the given runner.

func NewInterpreterStack

func NewInterpreterStack() *InterpreterStack

NewInterpreterStack creates a new InterpreterStack.

func (*InterpreterStack) Details

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

type InterpreterVariable struct {
	Type       sql.Type
	Value      any
	HasBeenSet bool
}

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.

const (
	OpCode_Select OpCode = iota
	OpCode_Declare
	OpCode_Signal
	OpCode_Open
	OpCode_Fetch
	OpCode_Close
	OpCode_Set
	OpCode_Call
	OpCode_If
	OpCode_Goto
	OpCode_Execute
	OpCode_Exception
	OpCode_Return
	OpCode_ScopeBegin
	OpCode_ScopeEnd
)

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

Stack is a generic stack.

func NewStack

func NewStack[T any]() *Stack[T]

NewStack creates a new, empty stack.

func (*Stack[T]) Empty

func (s *Stack[T]) Empty() bool

Empty returns whether the stack is empty.

func (*Stack[T]) Len

func (s *Stack[T]) Len() int

Len returns the size of the 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

func (s *Stack[T]) PeekDepth(depth int) (value T)

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.

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (value T)

Pop returns the top value on the stack while also removing it from the stack.

func (*Stack[T]) Push

func (s *Stack[T]) Push(value T)

Push adds the given value to the stack.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL