mysql

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Join joinType = iota
	InnerJoin
	CrossJoin
	StraightJoin
	LeftOuterJoin
	RightOuterJoin
	NaturalInnerJoin
	NaturalLeftOuterJoin
	NaturalRightOuterJoin
)

Variables

This section is empty.

Functions

func Completion

func Completion(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) ([]base.Candidate, error)

Completion is the entry point of MySQL code completion.

func DealWithDelimiter

func DealWithDelimiter(statement string) (string, error)

DealWithDelimiter converts the delimiter statement to comment, also converts the following statement's delimiter to semicolon(`;`).

func Diagnose

func Diagnose(_ context.Context, _ base.DiagnoseContext, statement string) ([]base.Diagnostic, error)

func ExtractDelimiter

func ExtractDelimiter(stmt string) (string, error)

ExtractDelimiter extracts the delimiter from the delimiter statement.

func GenerateRestoreSQL

func GenerateRestoreSQL(ctx context.Context, rCtx base.RestoreContext, statement string, backupItem *storepb.PriorBackupDetail_Item) (string, error)

func GetCharSetName

func GetCharSetName(ctx parser.IDataTypeContext) string

GetCharSetName get charset name from DataTypeContext.

func GetCollationName

func GetCollationName(ctx parser.IFieldDefinitionContext) string

GetCollationName get collation name from FieldDefinitionContext.

func GetQuerySpan

func GetQuerySpan(
	ctx context.Context,
	gCtx base.GetQuerySpanContext,
	statement, database, _ string,

	ignoreCaseSensitive bool,
) (*base.QuerySpan, error)

GetQuerySpan returns the query span for the given statement.

func GetStatementTypes

func GetStatementTypes(asts []base.AST) ([]string, error)

func IsAutoIncrement

func IsAutoIncrement(ctx parser.IFieldDefinitionContext) bool

IsAutoIncrement check if this column is auto_increment.

func IsDelimiter

func IsDelimiter(stmt string) bool

IsDelimiter returns true if the statement is a delimiter statement.

func IsTimeType

func IsTimeType(ctx parser.IDataTypeContext) bool

IsTimeType check if the dataType is time type.

func IsTopMySQLRule

func IsTopMySQLRule(ctx *antlr.BaseParserRuleContext) bool

IsTopMySQLRule returns true if the given context is a top-level MySQL rule.

func NormalizeConstraintName

func NormalizeConstraintName(ctx parser.IConstraintNameContext) string

NormalizeMySQLConstraintName normalize the given IConstraintName.

func NormalizeIdentifierListWithParentheses

func NormalizeIdentifierListWithParentheses(ctx parser.IIdentifierListWithParenthesesContext) []string

NormalizeMySQLIdentifierListWithParentheses normalize the given IdentififerListWithparentheses.

func NormalizeIndexName

func NormalizeIndexName(ctx parser.IIndexNameContext) string

NormalizeMySQLIndexName normalize the given IndexName.

func NormalizeIndexRef

func NormalizeIndexRef(ctx parser.IIndexRefContext) (string, string, string)

NormalizeMySQLIndexName normalize the given IndeRef.

func NormalizeKeyList

func NormalizeKeyList(ctx parser.IKeyListContext) []string

NormalizeMySQLKeyList normalize the given keyList.

func NormalizeKeyListVariants

func NormalizeKeyListVariants(ctx parser.IKeyListVariantsContext) []string

NormalizeMySQLKeyListVariants normalize the given keyListVariants.

func NormalizeKeyListWithExpression

func NormalizeKeyListWithExpression(ctx parser.IKeyListWithExpressionContext) []string

NormalizeMySQLKeyListWithExpression normalizes the given keyListWithExpression.

func NormalizeMySQLCharsetName

func NormalizeMySQLCharsetName(ctx parser.ICharsetNameContext) string

NormalizeMySQLCharsetName noamalizes the given charset name.

func NormalizeMySQLCollationName

func NormalizeMySQLCollationName(ctx parser.ICollationNameContext) string

NormalizeMySQLCollationName noamalizes the given collation name.

func NormalizeMySQLColumnInternalRef

func NormalizeMySQLColumnInternalRef(ctx parser.IColumnInternalRefContext) string

NormalizeMySQLColumnInternalRef noamalizes the given columnInternalRef.

func NormalizeMySQLColumnName

func NormalizeMySQLColumnName(ctx parser.IColumnNameContext) (string, string, string)

NormalizeMySQLColumnName normalizes the given column name.

func NormalizeMySQLColumnRef

func NormalizeMySQLColumnRef(ctx parser.IColumnRefContext) (string, string, string)

func NormalizeMySQLDataType

func NormalizeMySQLDataType(ctx parser.IDataTypeContext, compact bool) string

NormalizeMySQLDataType noamalizes the given dataType. campact for tidb parser compatibility. eg: varchar(5). compact is true, return varchar. compact is false, return varchar(5).

func NormalizeMySQLEventName

func NormalizeMySQLEventName(ctx parser.IEventNameContext) (string, string)

NormalizeMySQLEventName normalizes the given event name.

func NormalizeMySQLFieldIdentifier

func NormalizeMySQLFieldIdentifier(ctx parser.IFieldIdentifierContext) (string, string, string)

NormalizeMySQLFieldIdentifier normalizes the given field identifier.

func NormalizeMySQLFunctionName

func NormalizeMySQLFunctionName(ctx parser.IFunctionNameContext) (string, string)

NormalizeMySQLFunctionName normalizes the given function name.

func NormalizeMySQLFunctionRef

func NormalizeMySQLFunctionRef(ctx parser.IFunctionRefContext) (string, string)

NormalizeMySQLFunctionRef normalizes the given function ref.

func NormalizeMySQLIdentifier

func NormalizeMySQLIdentifier(identifier parser.IIdentifierContext) string

NormalizeMySQLIdentifier normalizes the given identifier.

func NormalizeMySQLIdentifierList

func NormalizeMySQLIdentifierList(ctx parser.IIdentifierListContext) []string

NormalizeMySQLIdentifierList normalizes the given identifier list.

func NormalizeMySQLProcedureName

func NormalizeMySQLProcedureName(ctx parser.IProcedureNameContext) (string, string)

NormalizeMySQLProcedureName normalizes the given procedure name.

func NormalizeMySQLProcedureRef

func NormalizeMySQLProcedureRef(ctx parser.IProcedureRefContext) (string, string)

NormalizeMySQLProcedureRef normalizes the given procedure ref.

func NormalizeMySQLPureIdentifier

func NormalizeMySQLPureIdentifier(pureIdentifier parser.IPureIdentifierContext) string

func NormalizeMySQLSchemaName

func NormalizeMySQLSchemaName(ctx parser.ISchemaNameContext) string

NormalizeMySQLSchemaName normalize the given schemaName.

func NormalizeMySQLSchemaRef

func NormalizeMySQLSchemaRef(ctx parser.ISchemaRefContext) string

NormalizeMySQLSchemaRef normalize the given schemaRef.

func NormalizeMySQLSelectAlias

func NormalizeMySQLSelectAlias(selectAlias parser.ISelectAliasContext) string

NormalizeMySQLSelectAlias normalizes the given select alias.

func NormalizeMySQLSignedLiteral

func NormalizeMySQLSignedLiteral(ctx parser.ISignedLiteralContext) string

NormalizeMySQLSignedLiteral normalize the given SignedLiteral.

func NormalizeMySQLTableName

func NormalizeMySQLTableName(ctx parser.ITableNameContext) (string, string)

NormalizeMySQLTableName normalizes the given table name.

func NormalizeMySQLTableRef

func NormalizeMySQLTableRef(ctx parser.ITableRefContext) (string, string)

NormalizeMySQLTableRef normalizes the given table reference.

func NormalizeMySQLTableRefWithWildcard

func NormalizeMySQLTableRefWithWildcard(ctx parser.ITableRefWithWildcardContext) (string, string)

func NormalizeMySQLTextLiteral

func NormalizeMySQLTextLiteral(ctx parser.ITextLiteralContext) string

NormalizeMySQLTextLiteral normalize the given TextStringLiteral.

func NormalizeMySQLTextOrIdentifier

func NormalizeMySQLTextOrIdentifier(ctx parser.ITextOrIdentifierContext) string

NormalizeMySQLTextOrIdentifier normalizes the given TextOrIdentifier.

func NormalizeMySQLTextStringLiteral

func NormalizeMySQLTextStringLiteral(ctx parser.ITextStringLiteralContext) string

NormalizeMySQLTextStringLiteral normalize the given TextStringLiteral.

func NormalizeMySQLTriggerName

func NormalizeMySQLTriggerName(ctx parser.ITriggerNameContext) (string, string)

NormalizeMySQLTriggerName normalizes the given trigger name.

func NormalizeMySQLViewName

func NormalizeMySQLViewName(ctx parser.IViewNameContext) (string, string)

NormalizeMySQLViewName normalizes the given view name.

func NormalizeMySQLViewRef

func NormalizeMySQLViewRef(ctx parser.IViewRefContext) (string, string)

func ParseMySQL

func ParseMySQL(statement string) ([]*base.ParseResult, error)

ParseMySQL parses the given SQL statement and returns the AST.

func RestoreDelimiter

func RestoreDelimiter(statement string) (string, error)

RestoreDelimiter tries to restore the delimiter statement which is commented by DealWithDelimiter,

Assumes the delimiter comment takes up a single line and matches the syntax `-- DELIMITER ?`, also, one delimiter comment MUST only affect one statement, in the other words, the following statement cause UB: -- DELIMITER ; SELECT 1; SELECT 2; -- DELIMITER ;. If the current delimiter is `;`, and meet `-- DELIMITER ;`, we would skip this delimiter comment.

func SplitSQL

func SplitSQL(statement string) ([]base.SingleSQL, error)

SplitSQL splits the given SQL statement into multiple SQL statements.

func TransformDMLToSelect

func TransformDMLToSelect(ctx context.Context, tCtx base.TransformContext, statement string, sourceDatabase string, targetDatabase string, tablePrefix string) ([]base.BackupStatement, error)

Types

type CTETableListener

type CTETableListener struct {
	*mysql.BaseMySQLParserListener
	// contains filtered or unexported fields
}

func (*CTETableListener) EnterCommonTableExpression

func (l *CTETableListener) EnterCommonTableExpression(ctx *mysql.CommonTableExpressionContext)

type Completer

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

func NewStandardCompleter

func NewStandardCompleter(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) *Completer

func NewTrickyCompleter

func NewTrickyCompleter(ctx context.Context, cCtx base.CompletionContext, statement string, caretLine int, caretOffset int) *Completer

type CompletionMap

type CompletionMap map[string]base.Candidate

func (CompletionMap) Insert

func (m CompletionMap) Insert(entry base.Candidate)

type ObjectFlags

type ObjectFlags int
const (
	ObjectFlagsShowSchemas ObjectFlags = 1 << iota
	ObjectFlagsShowTables
	ObjectFlagsShowColumns
	ObjectFlagsShowFirst
	ObjectFlagsShowSecond
)

type SelectAliasListener

type SelectAliasListener struct {
	*mysql.BaseMySQLParserListener
	// contains filtered or unexported fields
}

func (*SelectAliasListener) EnterSelectAlias

func (l *SelectAliasListener) EnterSelectAlias(ctx *mysql.SelectAliasContext)

type StatementInfo

type StatementInfo struct {
	Offset        int
	Statement     string
	Tree          antlr.ParserRuleContext
	Table         *TableReference
	StartPosition *store.Position
	EndPosition   *store.Position
}

func ExtractTables

func ExtractTables(databaseName string, parseResult *base.ParseResult, offset int) ([]StatementInfo, error)

type StatementType

type StatementType int
const (
	StatementTypeUnknown StatementType = iota
	StatementTypeUpdate
	StatementTypeInsert
	StatementTypeDelete
)

type StatementTypeChecker

type StatementTypeChecker struct {
	*mysql.BaseMySQLParserListener

	IsDDL     bool
	IsDML     bool
	IsExplain bool
	Text      string
}

func (*StatementTypeChecker) EnterAlterStatement

func (checker *StatementTypeChecker) EnterAlterStatement(ctx *mysql.AlterStatementContext)

DDL from g4 alterStatement createStatement dropStatement renameTableStatement truncateTableStatement importStatement EnterAlterStatement is called when production alterStatement is entered.

func (*StatementTypeChecker) EnterCallStatement

func (checker *StatementTypeChecker) EnterCallStatement(ctx *mysql.CallStatementContext)

DML EnterCallStatement is called when production callStatement is entered.

func (*StatementTypeChecker) EnterCreateStatement

func (checker *StatementTypeChecker) EnterCreateStatement(ctx *mysql.CreateStatementContext)

EnterCreateStatement is called when production createStatement is entered.

func (*StatementTypeChecker) EnterDeleteStatement

func (checker *StatementTypeChecker) EnterDeleteStatement(ctx *mysql.DeleteStatementContext)

EnterDeleteStatement is called when production deleteStatement is entered.

func (*StatementTypeChecker) EnterDoStatement

func (checker *StatementTypeChecker) EnterDoStatement(ctx *mysql.DoStatementContext)

EnterDoStatement is called when production doStatement is entered.

func (*StatementTypeChecker) EnterDropStatement

func (checker *StatementTypeChecker) EnterDropStatement(ctx *mysql.DropStatementContext)

EnterDropStatement is called when production dropStatement is entered.

func (*StatementTypeChecker) EnterExplainStatement

func (checker *StatementTypeChecker) EnterExplainStatement(ctx *mysql.ExplainStatementContext)

EnterExplainStatement is called when production explainStatement is entered.

func (*StatementTypeChecker) EnterHandlerStatement

func (checker *StatementTypeChecker) EnterHandlerStatement(ctx *mysql.HandlerStatementContext)

EnterHandlerStatement is called when production handlerStatement is entered.

func (*StatementTypeChecker) EnterImportStatement

func (checker *StatementTypeChecker) EnterImportStatement(ctx *mysql.ImportStatementContext)

EnterImportStatement is called when production importStatement is entered.

func (*StatementTypeChecker) EnterInsertStatement

func (checker *StatementTypeChecker) EnterInsertStatement(ctx *mysql.InsertStatementContext)

EnterInsertStatement is called when production insertStatement is entered.

func (*StatementTypeChecker) EnterLoadDataFileTail

func (checker *StatementTypeChecker) EnterLoadDataFileTail(ctx *mysql.LoadDataFileTailContext)

EnterLoadDataFileTail is called when production loadDataFileTail is entered.

func (*StatementTypeChecker) EnterPreparedStatement

func (checker *StatementTypeChecker) EnterPreparedStatement(ctx *mysql.PreparedStatementContext)

EnterPreparedStatement is called when production preparedStatement is entered.

func (*StatementTypeChecker) EnterQuery

func (checker *StatementTypeChecker) EnterQuery(ctx *mysql.QueryContext)

func (*StatementTypeChecker) EnterRenameTableStatement

func (checker *StatementTypeChecker) EnterRenameTableStatement(ctx *mysql.RenameTableStatementContext)

EnterRenameTableStatement is called when production renameTableStatement is entered.

func (*StatementTypeChecker) EnterReplaceStatement

func (checker *StatementTypeChecker) EnterReplaceStatement(ctx *mysql.ReplaceStatementContext)

EnterReplaceStatement is called when production replaceStatement is entered.

func (*StatementTypeChecker) EnterReplicationStatement

func (checker *StatementTypeChecker) EnterReplicationStatement(ctx *mysql.ReplicationStatementContext)

EnterReplicationStatement is called when production replicationStatement is entered.

func (*StatementTypeChecker) EnterSelectStatement

func (checker *StatementTypeChecker) EnterSelectStatement(ctx *mysql.SelectStatementContext)

EnterSelectStatement is called when production selectStatement is entered.

func (*StatementTypeChecker) EnterTransactionOrLockingStatement

func (checker *StatementTypeChecker) EnterTransactionOrLockingStatement(ctx *mysql.TransactionOrLockingStatementContext)

EnterTransactionOrLockingStatement is called when production transactionOrLockingStatement is entered.

func (*StatementTypeChecker) EnterTruncateTableStatement

func (checker *StatementTypeChecker) EnterTruncateTableStatement(ctx *mysql.TruncateTableStatementContext)

EnterTruncateTableStatement is called when production truncateTableStatement is entered.

func (*StatementTypeChecker) EnterUpdateStatement

func (checker *StatementTypeChecker) EnterUpdateStatement(ctx *mysql.UpdateStatementContext)

EnterUpdateStatement is called when production updateStatement is entered.

type TableRefListener

type TableRefListener struct {
	*mysql.BaseMySQLParserListener
	// contains filtered or unexported fields
}

func (*TableRefListener) EnterDerivedTable

func (l *TableRefListener) EnterDerivedTable(ctx *mysql.DerivedTableContext)

func (*TableRefListener) EnterSubquery

func (l *TableRefListener) EnterSubquery(_ *mysql.SubqueryContext)

func (*TableRefListener) ExitSubquery

func (l *TableRefListener) ExitSubquery(_ *mysql.SubqueryContext)

func (*TableRefListener) ExitTableAlias

func (l *TableRefListener) ExitTableAlias(ctx *mysql.TableAliasContext)

func (*TableRefListener) ExitTableRef

func (l *TableRefListener) ExitTableRef(ctx *mysql.TableRefContext)

type TableReference

type TableReference struct {
	Database      string
	Table         string
	Alias         string
	StatementType StatementType
}

Jump to

Keyboard shortcuts

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