MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / RunShowSyntax

Function RunShowSyntax

pkg/sql/parser/show_syntax.go:28–65  ·  view source on GitHub ↗

RunShowSyntax analyzes the syntax and reports its structure as data for the client. Even an error is reported as data. Since errors won't propagate to the client as an error, but as a result, the usual code path to capture and record errors will not be triggered. Instead, the caller can pass a repo

(
	ctx context.Context,
	stmt string,
	report func(ctx context.Context, field, msg string),
	reportErr func(ctx context.Context, err error),
)

Source from the content-addressed store, hash-verified

26// be triggered. Instead, the caller can pass a reportErr closure to
27// capture errors instead. May be nil.
28func RunShowSyntax(
29 ctx context.Context,
30 stmt string,
31 report func(ctx context.Context, field, msg string),
32 reportErr func(ctx context.Context, err error),
33) {
34 stmts, err := Parse(stmt)
35 if err != nil {
36 if reportErr != nil {
37 reportErr(ctx, err)
38 }
39
40 pqErr := pgerror.Flatten(err)
41 report(ctx, "error", pqErr.Message)
42 report(ctx, "code", pqErr.Code)
43 if pqErr.Source != nil {
44 if pqErr.Source.File != "" {
45 report(ctx, "file", pqErr.Source.File)
46 }
47 if pqErr.Source.Line > 0 {
48 report(ctx, "line", fmt.Sprintf("%d", pqErr.Source.Line))
49 }
50 if pqErr.Source.Function != "" {
51 report(ctx, "function", pqErr.Source.Function)
52 }
53 }
54 if pqErr.Detail != "" {
55 report(ctx, "detail", pqErr.Detail)
56 }
57 if pqErr.Hint != "" {
58 report(ctx, "hint", pqErr.Hint)
59 }
60 } else {
61 for i := range stmts {
62 report(ctx, "sql", tree.AsStringWithFlags(stmts[i].AST, tree.FmtParsable))
63 }
64 }
65}

Callers

nothing calls this directly

Calls 3

FlattenFunction · 0.92
AsStringWithFlagsFunction · 0.92
ParseFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…