* Append the given string to the buffer, with suitable quoting for passing * the string as a value, in a keyword/pair value in a libpq connection * string */
| 425 | * string |
| 426 | */ |
| 427 | void |
| 428 | appendConnStrVal(PQExpBuffer buf, const char *str) |
| 429 | { |
| 430 | const char *s; |
| 431 | bool needquotes; |
| 432 | |
| 433 | /* |
| 434 | * If the string is one or more plain ASCII characters, no need to quote |
| 435 | * it. This is quite conservative, but better safe than sorry. |
| 436 | */ |
| 437 | needquotes = true; |
| 438 | for (s = str; *s; s++) |
| 439 | { |
| 440 | if (!((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') || |
| 441 | (*s >= '0' && *s <= '9') || *s == '_' || *s == '.')) |
| 442 | { |
| 443 | needquotes = true; |
| 444 | break; |
| 445 | } |
| 446 | needquotes = false; |
| 447 | } |
| 448 | |
| 449 | if (needquotes) |
| 450 | { |
| 451 | appendPQExpBufferChar(buf, '\''); |
| 452 | while (*str) |
| 453 | { |
| 454 | /* ' and \ must be escaped by to \' and \\ */ |
| 455 | if (*str == '\'' || *str == '\\') |
| 456 | appendPQExpBufferChar(buf, '\\'); |
| 457 | |
| 458 | appendPQExpBufferChar(buf, *str); |
| 459 | str++; |
| 460 | } |
| 461 | appendPQExpBufferChar(buf, '\''); |
| 462 | } |
| 463 | else |
| 464 | appendPQExpBufferStr(buf, str); |
| 465 | } |
| 466 | |
| 467 | |
| 468 | /* |
no test coverage detected