doParseDTupleFromString does most of the work of ParseDTupleFromString, except the error it returns isn't prettified as a parsing error. The dependsOnContext return value indicates if we had to consult the ParseContext (either for the time or the local timezone).
( ctx ParseContext, s string, t *types.T, )
| 186 | // The dependsOnContext return value indicates if we had to consult the |
| 187 | // ParseContext (either for the time or the local timezone). |
| 188 | func doParseDTupleFromString( |
| 189 | ctx ParseContext, s string, t *types.T, |
| 190 | ) (_ *DTuple, dependsOnContext bool, _ error) { |
| 191 | if t.TupleContents() == nil { |
| 192 | return nil, false, errors.AssertionFailedf("not a tuple type %s", t.SQLStringForError()) |
| 193 | } |
| 194 | if t.Identical(types.AnyTuple) { |
| 195 | return nil, false, unsupportedRecordError |
| 196 | } |
| 197 | parser := tupleParseState{ |
| 198 | s: s, |
| 199 | ctx: ctx, |
| 200 | result: NewDTupleWithLen(t, len(t.TupleContents())), |
| 201 | t: t, |
| 202 | } |
| 203 | |
| 204 | parser.eatWhitespace() |
| 205 | if parser.peek() != '(' { |
| 206 | return nil, false, enclosingRecordError |
| 207 | } |
| 208 | parser.advance() |
| 209 | if parser.peek() != ')' || len(t.TupleContents()) > 0 { |
| 210 | if err := parser.parseElement(); err != nil { |
| 211 | return nil, false, err |
| 212 | } |
| 213 | parser.eatWhitespace() |
| 214 | for parser.peek() == ',' { |
| 215 | parser.advance() |
| 216 | if err := parser.parseElement(); err != nil { |
| 217 | return nil, false, err |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | parser.eatWhitespace() |
| 222 | if parser.eof() { |
| 223 | return nil, false, enclosingRecordError |
| 224 | } |
| 225 | if parser.peek() != ')' { |
| 226 | return nil, false, malformedRecordError |
| 227 | } |
| 228 | if parser.tupleIdx < len(parser.t.TupleContents()) { |
| 229 | return nil, false, errors.WithDetail(malformedRecordError, "Too few columns.") |
| 230 | } |
| 231 | parser.advance() |
| 232 | parser.eatWhitespace() |
| 233 | if !parser.eof() { |
| 234 | return nil, false, extraTextRecordError |
| 235 | } |
| 236 | |
| 237 | return parser.result, parser.dependsOnContext, nil |
| 238 | } |
no test coverage detected
searching dependent graphs…