MCPcopy Create free account
hub / github.com/dolthub/doltgresql / RunShowSyntax

Function RunShowSyntax

postgres/parser/parser/show_syntax.go:42–79  ·  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

40// be triggered. Instead, the caller can pass a reportErr closure to
41// capture errors instead. May be nil.
42func RunShowSyntax(
43 ctx context.Context,
44 stmt string,
45 report func(ctx context.Context, field, msg string),
46 reportErr func(ctx context.Context, err error),
47) {
48 stmts, err := Parse(stmt)
49 if err != nil {
50 if reportErr != nil {
51 reportErr(ctx, err)
52 }
53
54 pqErr := pgerror.Flatten(err)
55 report(ctx, "error", pqErr.Message)
56 report(ctx, "code", pqErr.Code)
57 if pqErr.Source != nil {
58 if pqErr.Source.File != "" {
59 report(ctx, "file", pqErr.Source.File)
60 }
61 if pqErr.Source.Line > 0 {
62 report(ctx, "line", fmt.Sprintf("%d", pqErr.Source.Line))
63 }
64 if pqErr.Source.Function != "" {
65 report(ctx, "function", pqErr.Source.Function)
66 }
67 }
68 if pqErr.Detail != "" {
69 report(ctx, "detail", pqErr.Detail)
70 }
71 if pqErr.Hint != "" {
72 report(ctx, "hint", pqErr.Hint)
73 }
74 } else {
75 for i := range stmts {
76 report(ctx, "sql", tree.AsStringWithFlags(stmts[i].AST, tree.FmtParsable))
77 }
78 }
79}

Callers

nothing calls this directly

Calls 3

FlattenFunction · 0.92
AsStringWithFlagsFunction · 0.92
ParseFunction · 0.70

Tested by

no test coverage detected