parseSQLInternal parses a SQL string and returns statement count and types.
(sql string)
| 102 | |
| 103 | // parseSQLInternal parses a SQL string and returns statement count and types. |
| 104 | func parseSQLInternal(sql string) (map[string]any, error) { |
| 105 | if sql == "" { |
| 106 | return nil, fmt.Errorf("parameter 'sql' is required and must not be empty") |
| 107 | } |
| 108 | |
| 109 | tree, err := gosqlx.Parse(sql) |
| 110 | if err != nil { |
| 111 | return nil, fmt.Errorf("parse failed: %w", err) |
| 112 | } |
| 113 | |
| 114 | stmtTypes := make([]string, 0, len(tree.Statements)) |
| 115 | for _, stmt := range tree.Statements { |
| 116 | stmtTypes = append(stmtTypes, fmt.Sprintf("%T", stmt)) |
| 117 | } |
| 118 | |
| 119 | return map[string]any{ |
| 120 | "statement_count": len(tree.Statements), |
| 121 | "statement_types": stmtTypes, |
| 122 | }, nil |
| 123 | } |
| 124 | |
| 125 | // extractMetadataInternal parses a SQL string and extracts tables, columns, and functions. |
| 126 | func extractMetadataInternal(sql string) (map[string]any, error) { |