validateInlineSQL validates inline SQL passed as a command argument. Uses the fast-path Validate() which skips full AST construction (#274).
(cmd *cobra.Command, sql string)
| 300 | // validateInlineSQL validates inline SQL passed as a command argument. |
| 301 | // Uses the fast-path Validate() which skips full AST construction (#274). |
| 302 | func validateInlineSQL(cmd *cobra.Command, sql string) error { |
| 303 | var err error |
| 304 | if validateDialect != "" { |
| 305 | err = parser.ValidateWithDialect(sql, keywords.SQLDialect(validateDialect)) |
| 306 | } else { |
| 307 | err = parser.Validate(sql) |
| 308 | } |
| 309 | if err != nil { |
| 310 | if !validateQuiet { |
| 311 | fmt.Fprintf(cmd.ErrOrStderr(), "❌ Invalid SQL: %v\n", err) |
| 312 | } |
| 313 | return fmt.Errorf("validation failed: %w", err) |
| 314 | } |
| 315 | |
| 316 | if sql == "" { |
| 317 | if !validateQuiet { |
| 318 | fmt.Fprintln(cmd.OutOrStdout(), "✅ Empty input (no statements)") |
| 319 | } |
| 320 | return nil |
| 321 | } |
| 322 | |
| 323 | if !validateQuiet { |
| 324 | fmt.Fprintln(cmd.OutOrStdout(), "✅ Valid SQL") |
| 325 | } |
| 326 | return nil |
| 327 | } |
| 328 | |
| 329 | func init() { |
| 330 | rootCmd.AddCommand(validateCmd) |
no test coverage detected