sql_parser

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PAGE_SIZE = 512
)

Variables

View Source
var (
	// TruncateUILen truncate queries in debug UIs to the given length. 0 means unlimited.
	TruncateUILen = flag.Int("sql-max-length-ui", 512, "truncate queries in debug UIs to the given length (default 512)")

	// TruncateErrLen truncate queries in error logs to the given length. 0 means unlimited.
	TruncateErrLen = flag.Int("sql-max-length-errors", 0, "truncate queries in error logs to the given length (default unlimited)")
)

ErrEmpty is a sentinel error returned when parsing empty statements.

View Source
var (
	ErrIncompleteStatement = errors.New("ErrIncompleteStatement")
)

Functions

func LikeToRegexp

func LikeToRegexp(likeExpr string) *regexp.Regexp

LikeToRegexp converts a like sql expression to regular expression

func NewBufferedTokenizer

func NewBufferedTokenizer(sql *tokenizer.BytesBuffer, sqlDialect dialect.SqlDialect) (tokenizer.Tokenizer, error)

New BufferedTokenizer creates a new Tokenizer for the BytesBuffer

func NewStringTokenizer

func NewStringTokenizer(sql string, sqlDialect dialect.SqlDialect) (tokenizer.Tokenizer, error)

NewStringTokenizer creates a new Tokenizer for the sql string.

func Parse

func Parse(sql string, sqlDialect dialect.SqlDialect) (ast.Statement, error)

Parse behaves like Parse2 but does not return a set of bind variables

func Parse2

func Parse2(sql string, sqlDialect dialect.SqlDialect) (ast.Statement, ast.BindVars, error)

Parse2 parses the SQL in full and returns a Statement, which is the AST representation of the query, and a set of BindVars, which are all the bind variables that were found in the original SQL query. If a DDL statement is partially parsed but still contains a syntax error, the error is ignored and the DDL is returned anyway.

func ParseExpr

func ParseExpr(sql string, sqlDialect dialect.SqlDialect) (ast.Expr, error)

ParseExpr parses an expression and transforms it to an AST

func ParseNext

func ParseNext(tokenizer tokenizer.Tokenizer, sqlDialect dialect.SqlDialect) (ast.Statement, error)

ParseNext parses a single SQL statement from the tokenizer returning a Statement which is the AST representation of the query. The tokenizer will always read up to the end of the statement, allowing for the next call to ParseNext to parse any subsequent SQL statements. When there are no more statements to parse, a error of io.EOF is returned.

func ParseNextStrictDDL

func ParseNextStrictDDL(tokenizer tokenizer.Tokenizer, sqlDialect dialect.SqlDialect) (ast.Statement, error)

ParseNextStrictDDL is the same as ParseNext except it errors on partially parsed DDL statements.

func ParseStrictDDL

func ParseStrictDDL(sql string, sqlDialect dialect.SqlDialect) (ast.Statement, error)

ParseStrictDDL is the same as Parse except it errors on partially parsed DDL statements.

func ParseTable

func ParseTable(input string) (keyspace, table string, err error)

ParseTable parses the input as a qualified table name. It handles all valid literal escaping.

func ParseTokenizer

func ParseTokenizer(tokenizer tokenizer.Tokenizer, sqlDialect dialect.SqlDialect) (int, error)

ParseTokenizer is a raw interface to parse from the given tokenizer. This does not used pooled parsers, and should not be used in general.

func SplitStatement

func SplitStatement(blob string, sqlDialect dialect.SqlDialect) (string, string, error)

SplitStatement returns the first sql statement up to either a ; or EOF and the remainder from the given buffer

func SplitStatementToPieces

func SplitStatementToPieces(blob string, sqlDialect dialect.SqlDialect) (pieces []string, err error)

SplitStatementToPieces split raw sql statement that may have multi sql pieces to sql pieces returns the sql pieces blob contains; or error if sql cannot be parsed

func StatementStream

func StatementStream(blob io.Reader, sqlDialect dialect.SqlDialect, processor StatementProcessor) error

StatementStream split input stream into statements and call processor for every statement

func TableFromStatement

func TableFromStatement(sql string, sqlDialect dialect.SqlDialect) (ast.TableName, error)

TableFromStatement returns the qualified table name for the query. This works only for select statements.

func TruncateForLog

func TruncateForLog(query string) string

TruncateForLog is used when displaying queries as part of error logs to avoid overwhelming logging systems with potentially long queries and bind value data.

func TruncateForUI

func TruncateForUI(query string) string

TruncateForUI is used when displaying queries on various Vitess status pages to keep the pages small enough to load and render properly

Types

type Encodable

type Encodable interface {
	EncodeSQL(buf *strings.Builder)
}

Encodable defines the interface for types that can be custom-encoded into SQL.

type InsertValues

type InsertValues [][]sql_types.Value

InsertValues is a custom SQL encoder for the values of an insert statement.

func (InsertValues) EncodeSQL

func (iv InsertValues) EncodeSQL(buf *strings.Builder)

EncodeSQL performs the SQL encoding for InsertValues.

type SetNormalizer

type SetNormalizer struct {
	// contains filtered or unexported fields
}

func (*SetNormalizer) NormalizeSetExpr

func (n *SetNormalizer) NormalizeSetExpr(in *ast.SetExpr) (*ast.SetExpr, error)

type StatementProcessor

type StatementProcessor func(statementText string, statement ast.Statement, parseError error)

type TupleEqualityList

type TupleEqualityList struct {
	Columns []ast.ColIdent
	Rows    [][]sql_types.Value
}

TupleEqualityList is for generating equality constraints for tables that have composite primary keys.

func (*TupleEqualityList) EncodeSQL

func (tpl *TupleEqualityList) EncodeSQL(buf *strings.Builder)

EncodeSQL generates the where clause constraints for the tuple equality.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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