ParseDBool parses and returns the *DBool Datum value represented by the provided string, or an error if parsing is unsuccessful. See https://github.com/postgres/postgres/blob/90627cf98a8e7d0531789391fd798c9bfcc3bc1a/src/backend/utils/adt/bool.c#L36
(s string)
| 271 | // string, or an error if parsing is unsuccessful. |
| 272 | // See https://github.com/postgres/postgres/blob/90627cf98a8e7d0531789391fd798c9bfcc3bc1a/src/backend/utils/adt/bool.c#L36 |
| 273 | func ParseDBool(s string) (*DBool, error) { |
| 274 | s = strings.TrimSpace(s) |
| 275 | if len(s) >= 1 { |
| 276 | switch s[0] { |
| 277 | case 't', 'T': |
| 278 | if isCaseInsensitivePrefix(s, "true") { |
| 279 | return DBoolTrue, nil |
| 280 | } |
| 281 | case 'f', 'F': |
| 282 | if isCaseInsensitivePrefix(s, "false") { |
| 283 | return DBoolFalse, nil |
| 284 | } |
| 285 | case 'y', 'Y': |
| 286 | if isCaseInsensitivePrefix(s, "yes") { |
| 287 | return DBoolTrue, nil |
| 288 | } |
| 289 | case 'n', 'N': |
| 290 | if isCaseInsensitivePrefix(s, "no") { |
| 291 | return DBoolFalse, nil |
| 292 | } |
| 293 | case '1': |
| 294 | if s == "1" { |
| 295 | return DBoolTrue, nil |
| 296 | } |
| 297 | case '0': |
| 298 | if s == "0" { |
| 299 | return DBoolFalse, nil |
| 300 | } |
| 301 | case 'o', 'O': |
| 302 | // Just 'o' is ambiguous between 'on' and 'off'. |
| 303 | if len(s) > 1 { |
| 304 | if isCaseInsensitivePrefix(s, "on") { |
| 305 | return DBoolTrue, nil |
| 306 | } |
| 307 | if isCaseInsensitivePrefix(s, "off") { |
| 308 | return DBoolFalse, nil |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | return nil, makeParseError(s, types.Bool, pgerror.New(pgcode.InvalidTextRepresentation, "invalid bool value")) |
| 314 | } |
| 315 | |
| 316 | // ParseDByte parses a string representation of hex encoded binary |
| 317 | // data. It supports both the hex format, with "\x" followed by a |
no test coverage detected
searching dependent graphs…