MCPcopy Create free account
hub / github.com/apache/cloudberry / appendConnStrVal

Function appendConnStrVal

src/fe_utils/string_utils.c:718–756  ·  view source on GitHub ↗

* Append the given string to the buffer, with suitable quoting for passing * the string as a value in a keyword/value pair in a libpq connection string. */

Source from the content-addressed store, hash-verified

716 * the string as a value in a keyword/value pair in a libpq connection string.
717 */
718void
719appendConnStrVal(PQExpBuffer buf, const char *str)
720{
721 const char *s;
722 bool needquotes;
723
724 /*
725 * If the string is one or more plain ASCII characters, no need to quote
726 * it. This is quite conservative, but better safe than sorry.
727 */
728 needquotes = true;
729 for (s = str; *s; s++)
730 {
731 if (!((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') ||
732 (*s >= '0' && *s <= '9') || *s == '_' || *s == '.'))
733 {
734 needquotes = true;
735 break;
736 }
737 needquotes = false;
738 }
739
740 if (needquotes)
741 {
742 appendPQExpBufferChar(buf, '\'');
743 while (*str)
744 {
745 /* ' and \ must be escaped by to \' and \\ */
746 if (*str == '\'' || *str == '\\')
747 appendPQExpBufferChar(buf, '\\');
748
749 appendPQExpBufferChar(buf, *str);
750 str++;
751 }
752 appendPQExpBufferChar(buf, '\'');
753 }
754 else
755 appendPQExpBufferStr(buf, str);
756}
757
758
759/*

Callers 2

appendPsqlMetaConnectFunction · 0.70
GenerateRecoveryConfigFunction · 0.70

Calls 2

appendPQExpBufferCharFunction · 0.85
appendPQExpBufferStrFunction · 0.85

Tested by

no test coverage detected