MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / validateInlineSQL

Function validateInlineSQL

cmd/gosqlx/cmd/validate.go:302–327  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

300// validateInlineSQL validates inline SQL passed as a command argument.
301// Uses the fast-path Validate() which skips full AST construction (#274).
302func 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
329func init() {
330 rootCmd.AddCommand(validateCmd)

Callers 1

validateRunFunction · 0.85

Calls 4

ValidateWithDialectFunction · 0.92
SQLDialectTypeAlias · 0.92
ValidateFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected