NewPlaceholder allocates a Placeholder.
(name string)
| 874 | |
| 875 | // NewPlaceholder allocates a Placeholder. |
| 876 | func NewPlaceholder(name string) (*Placeholder, error) { |
| 877 | uval, err := strconv.ParseUint(name, 10, 64) |
| 878 | if err != nil { |
| 879 | return nil, err |
| 880 | } |
| 881 | // The string is the number that follows $ which is a 1-based index ($1, $2, |
| 882 | // etc), while PlaceholderIdx is 0-based. |
| 883 | if uval == 0 || uval > MaxPlaceholderIdx+1 { |
| 884 | return nil, pgerror.Newf( |
| 885 | pgcode.NumericValueOutOfRange, |
| 886 | "placeholder index must be between 1 and %d", MaxPlaceholderIdx+1, |
| 887 | ) |
| 888 | } |
| 889 | return &Placeholder{Idx: PlaceholderIdx(uval - 1)}, nil |
| 890 | } |
| 891 | |
| 892 | // Format implements the NodeFormatter interface. |
| 893 | func (node *Placeholder) Format(ctx *FmtCtx) { |
no test coverage detected