MCPcopy Create free account
hub / github.com/bytebase/bytebase / GetStatementsForChecks

Method GetStatementsForChecks

backend/component/sheet/sheet.go:63–88  ·  view source on GitHub ↗

GetStatementsForChecks gets the unified Statements (with both text and AST) with caching. This is the new unified API that returns complete ParsedStatement objects. Use this for new code that needs both text and AST information.

(dbType storepb.Engine, statement string)

Source from the content-addressed store, hash-verified

61// This is the new unified API that returns complete ParsedStatement objects.
62// Use this for new code that needs both text and AST information.
63func (sm *Manager) GetStatementsForChecks(dbType storepb.Engine, statement string) ([]base.ParsedStatement, []*storepb.Advice) {
64 var result *StatementResult
65 h := xxh3.HashString(statement)
66 key := astHashKey{hash: h, engine: dbType}
67 sm.Lock()
68 if v, ok := sm.statementCache.Get(key); ok {
69 result = v
70 } else {
71 result = &StatementResult{}
72 sm.statementCache.Add(key, result)
73 }
74 sm.Unlock()
75
76 result.Lock()
77 defer result.Unlock()
78 if result.statements != nil || result.advices != nil {
79 return result.statements, result.advices
80 }
81 statements, err := base.ParseStatements(dbType, statement)
82 if err != nil {
83 result.advices = convertErrorToAdvice(err)
84 } else {
85 result.statements = statements
86 }
87 return result.statements, result.advices
88}
89
90func convertErrorToAdvice(err error) []*storepb.Advice {
91 if syntaxErr, ok := err.(*base.SyntaxError); ok {

Callers 9

TestWalkThroughFunction · 0.95
TestWalkThroughFunction · 0.95
TestWalkThroughFunction · 0.95
SQLReviewCheckFunction · 0.80
RunForTargetMethod · 0.80
GetSQLSummaryReportFunction · 0.80
checkReleaseVersionedMethod · 0.80

Calls 3

ParseStatementsFunction · 0.92
convertErrorToAdviceFunction · 0.85
GetMethod · 0.80

Tested by 4

TestWalkThroughFunction · 0.76
TestWalkThroughFunction · 0.76
TestWalkThroughFunction · 0.76