AnalyzeDoBlockOptions checks the list of DO block options for validity, and returns the code string.
(options DoBlockOptions)
| 46 | // AnalyzeDoBlockOptions checks the list of DO block options for validity, and |
| 47 | // returns the code string. |
| 48 | func AnalyzeDoBlockOptions(options DoBlockOptions) (RoutineBodyStr, error) { |
| 49 | var doBody RoutineBodyStr |
| 50 | var lang RoutineLanguage |
| 51 | var foundLanguage, foundBody bool |
| 52 | for _, doOption := range options { |
| 53 | switch t := doOption.(type) { |
| 54 | case RoutineBodyStr: |
| 55 | if foundBody { |
| 56 | return "", pgerror.New(pgcode.Syntax, "conflicting or redundant options") |
| 57 | } |
| 58 | doBody = t |
| 59 | foundBody = true |
| 60 | case RoutineLanguage: |
| 61 | if foundLanguage { |
| 62 | return "", pgerror.New(pgcode.Syntax, "conflicting or redundant options") |
| 63 | } |
| 64 | lang = t |
| 65 | foundLanguage = true |
| 66 | default: |
| 67 | return "", errors.AssertionFailedf("unexpected DO statement option: %v", t) |
| 68 | } |
| 69 | } |
| 70 | if !foundBody { |
| 71 | return "", pgerror.New(pgcode.Syntax, "no inline code specified") |
| 72 | } |
| 73 | switch lang { |
| 74 | case "", RoutineLangPLpgSQL: |
| 75 | // PL/pgSQL is the default, and currently the only supported language. |
| 76 | case RoutineLangSQL: |
| 77 | // Postgres disallows SQL for DO statements. |
| 78 | return "", pgerror.Newf(pgcode.FeatureNotSupported, |
| 79 | "language \"%s\" does not support inline code execution", lang, |
| 80 | ) |
| 81 | default: |
| 82 | return "", pgerror.Newf(pgcode.UndefinedObject, "language \"%s\" does not exist", lang) |
| 83 | } |
| 84 | return doBody, nil |
| 85 | } |
no test coverage detected
searching dependent graphs…