splitStatements splits SQL content by semicolons, respecting comments. This is a simple splitter - not a full tokenizer-aware one.
(content string)
| 100 | // splitStatements splits SQL content by semicolons, respecting comments. |
| 101 | // This is a simple splitter - not a full tokenizer-aware one. |
| 102 | func splitStatements(content string) []string { |
| 103 | var statements []string |
| 104 | var current strings.Builder |
| 105 | lines := strings.Split(content, "\n") |
| 106 | |
| 107 | for _, line := range lines { |
| 108 | trimmed := strings.TrimSpace(line) |
| 109 | // Skip pure comment lines for splitting purposes, but include them in current statement |
| 110 | if strings.HasPrefix(trimmed, "--") { |
| 111 | current.WriteString(line) |
| 112 | current.WriteString("\n") |
| 113 | continue |
| 114 | } |
| 115 | |
| 116 | // Check if line ends with semicolon (simple heuristic) |
| 117 | if strings.HasSuffix(trimmed, ";") { |
| 118 | current.WriteString(strings.TrimSuffix(line, ";")) |
| 119 | stmt := strings.TrimSpace(current.String()) |
| 120 | if stmt != "" && !isOnlyComments(stmt) { |
| 121 | statements = append(statements, stmt) |
| 122 | } |
| 123 | current.Reset() |
| 124 | } else { |
| 125 | current.WriteString(line) |
| 126 | current.WriteString("\n") |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // Handle trailing statement without semicolon |
| 131 | remaining := strings.TrimSpace(current.String()) |
| 132 | if remaining != "" && !isOnlyComments(remaining) { |
| 133 | statements = append(statements, remaining) |
| 134 | } |
| 135 | |
| 136 | return statements |
| 137 | } |
| 138 | |
| 139 | // isOnlyComments returns true if the string contains only comment lines and whitespace. |
| 140 | func isOnlyComments(s string) bool { |
no test coverage detected