Documentation
¶
Index ¶
- Constants
- Variables
- func LikeToRegexp(likeExpr string) *regexp.Regexp
- func NewBufferedTokenizer(sql *tokenizer.BytesBuffer, sqlDialect dialect.SqlDialect) (tokenizer.Tokenizer, error)
- func NewStringTokenizer(sql string, sqlDialect dialect.SqlDialect) (tokenizer.Tokenizer, error)
- func Parse(sql string, sqlDialect dialect.SqlDialect) (ast.Statement, error)
- func Parse2(sql string, sqlDialect dialect.SqlDialect) (ast.Statement, ast.BindVars, error)
- func ParseExpr(sql string, sqlDialect dialect.SqlDialect) (ast.Expr, error)
- func ParseNext(tokenizer tokenizer.Tokenizer, sqlDialect dialect.SqlDialect) (ast.Statement, error)
- func ParseNextStrictDDL(tokenizer tokenizer.Tokenizer, sqlDialect dialect.SqlDialect) (ast.Statement, error)
- func ParseStrictDDL(sql string, sqlDialect dialect.SqlDialect) (ast.Statement, error)
- func ParseTable(input string) (keyspace, table string, err error)
- func ParseTokenizer(tokenizer tokenizer.Tokenizer, sqlDialect dialect.SqlDialect) (int, error)
- func SplitStatement(blob string, sqlDialect dialect.SqlDialect) (string, string, error)
- func SplitStatementToPieces(blob string, sqlDialect dialect.SqlDialect) (pieces []string, err error)
- func StatementStream(blob io.Reader, sqlDialect dialect.SqlDialect, processor StatementProcessor) error
- func TableFromStatement(sql string, sqlDialect dialect.SqlDialect) (ast.TableName, error)
- func TruncateForLog(query string) string
- func TruncateForUI(query string) string
- type Encodable
- type InsertValues
- type SetNormalizer
- type StatementProcessor
- type TupleEqualityList
Constants ¶
const (
PAGE_SIZE = 512
)
Variables ¶
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)") )
var ErrEmpty = sql_parser_errors.NewErrorf(sql_parser_errors.Code_INVALID_ARGUMENT, sql_parser_errors.EmptyQuery, "query was empty")
ErrEmpty is a sentinel error returned when parsing empty statements.
var (
ErrIncompleteStatement = errors.New("ErrIncompleteStatement")
)
Functions ¶
func LikeToRegexp ¶
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 ¶
NewStringTokenizer creates a new Tokenizer for the sql string.
func Parse2 ¶
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 ParseNext ¶
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 ¶
ParseStrictDDL is the same as Parse except it errors on partially parsed DDL statements.
func ParseTable ¶
ParseTable parses the input as a qualified table name. It handles all valid literal escaping.
func ParseTokenizer ¶
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 ¶
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 ¶
TableFromStatement returns the qualified table name for the query. This works only for select statements.
func TruncateForLog ¶
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 ¶
TruncateForUI is used when displaying queries on various Vitess status pages to keep the pages small enough to load and render properly
Types ¶
type InsertValues ¶
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 ¶
type StatementProcessor ¶
type TupleEqualityList ¶
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.