IsEmptyQuery checks if a query contains only semicolons, whitespace, and/or SQL comments. PostgreSQL returns EmptyQueryResponse for queries like ";", "-- ping", "/* */", etc.
(query string)
| 6 | // SQL comments. PostgreSQL returns EmptyQueryResponse for queries like ";", |
| 7 | // "-- ping", "/* */", etc. |
| 8 | func IsEmptyQuery(query string) bool { |
| 9 | stripped := StripLeadingComments(query) |
| 10 | for _, r := range stripped { |
| 11 | if r != ';' && r != ' ' && r != '\t' && r != '\n' && r != '\r' { |
| 12 | return false |
| 13 | } |
| 14 | } |
| 15 | return true |
| 16 | } |
| 17 | |
| 18 | // StripLeadingComments removes leading SQL comments from a query. |
| 19 | // Handles both block comments /* ... */ and line comments -- ... |
no test coverage detected