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)
| 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. |
| 63 | func (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 | |
| 90 | func convertErrorToAdvice(err error) []*storepb.Advice { |
| 91 | if syntaxErr, ok := err.(*base.SyntaxError); ok { |